diff --git a/MechaDronesTweaks/MechaDronesTweaks.cs b/MechaDronesTweaks/MechaDronesTweaks.cs index 1a9271d..9e374f1 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.cs +++ b/MechaDronesTweaks/MechaDronesTweaks.cs @@ -58,6 +58,17 @@ public class MechaDronesTweaksPlugin : BaseUnityPlugin MechaDronesTweaks.EnergyMultiplier, new ConfigDescription("Energy consumption multiplier for mecha drones", new AcceptableValueRange(0f, 1f))).Value; + MechaDronesTweaks.removeBuildRangeLimit = Config.Bind("MechaBuild", "RemoveBuildRangeLimit", + MechaDronesTweaks.removeBuildRangeLimit, + "Remove limit for build range and maximum count of drag building belts/buildings\nNote: this does not affect range limit for mecha drones' action") + .Value; + MechaDronesTweaks.largerAreaForUpgradeAndDismantle = Config.Bind("MechaBuild", + "LargerAreaForUpgradeAndDismantle", MechaDronesTweaks.largerAreaForUpgradeAndDismantle, + "Increase maximum area size for upgrade and dismantle to 31x31 (from 11x11)").Value; + MechaDronesTweaks.largerAreaForTerraform = Config.Bind("MechaBuild", "LargerAreaForTerraform", + MechaDronesTweaks.largerAreaForTerraform, + "Increase maximum area size for terraform to 30x30 (from 10x10)\nNote: this may impact game performance while using large area") + .Value; _harmony.PatchAll(typeof(MechaDronesTweaks)); } @@ -71,6 +82,9 @@ public static class MechaDronesTweaks public static float FixedSpeed = 300f; public static float SpeedMultiplier = 4f; public static float EnergyMultiplier = 0.1f; + public static bool removeBuildRangeLimit = true; + public static bool largerAreaForUpgradeAndDismantle = true; + public static bool largerAreaForTerraform = true; [HarmonyTranspiler, HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")] private static IEnumerable UITechTreeRefreshDataValueText_Transpiler( @@ -157,92 +171,102 @@ public static class MechaDronesTweaks [HarmonyTranspiler, HarmonyPatch(typeof(MechaDrone), "Update")] private static IEnumerable MechaDroneUpdate_Transpiler(IEnumerable instructions) { - var ilist = instructions.ToList(); - for (var i = 0; i < ilist.Count; i++) + if (!UseFixedSpeed && Math.Abs(SpeedMultiplier - 1.0f) < 0.01f) { - var instr = ilist[i]; - if (instr.opcode == OpCodes.Ldarg_0) + foreach (var instr in instructions) { - var instrNext = ilist[i + 1]; - if (instrNext.opcode == OpCodes.Ldfld && - instrNext.OperandIs(AccessTools.Field(typeof(MechaDrone), "speed"))) + yield return instr; + } + } + else + { + var ilist = instructions.ToList(); + for (var i = 0; i < ilist.Count; i++) + { + var instr = ilist[i]; + if (instr.opcode == OpCodes.Ldarg_0) { - if (UseFixedSpeed) + var instrNext = ilist[i + 1]; + if (instrNext.opcode == OpCodes.Ldfld && + instrNext.OperandIs(AccessTools.Field(typeof(MechaDrone), "speed"))) { - var newInstr = new CodeInstruction(instr) + if (UseFixedSpeed) { - opcode = OpCodes.Ldc_R4, - operand = FixedSpeed - }; - yield return newInstr; - } - else - { - yield return instr; - yield return instrNext; - yield return new CodeInstruction(OpCodes.Ldc_R4, SpeedMultiplier); - yield return new CodeInstruction(OpCodes.Mul); - } - - i++; - continue; - } - - if (instrNext.opcode == OpCodes.Ldc_R4) - { - if (instrNext.OperandIs(0f)) - { - var instrNext2 = ilist[i + 2]; - if (instrNext2.opcode == OpCodes.Stfld && - instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) - { - ilist[i + 3].labels = instr.labels; - i += 2; - continue; + var newInstr = new CodeInstruction(instr) + { + opcode = OpCodes.Ldc_R4, + operand = FixedSpeed + }; + yield return newInstr; } - } - else if (instrNext.OperandIs(1f)) - { - var instrNext2 = ilist[i + 2]; - if (instrNext2.opcode == OpCodes.Stfld && - instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) + else { - instrNext.operand = 0f; yield return instr; yield return instrNext; - yield return instrNext2; - i += 2; - continue; + yield return new CodeInstruction(OpCodes.Ldc_R4, SpeedMultiplier); + yield return new CodeInstruction(OpCodes.Mul); } - } - } - } - else if (instr.opcode == OpCodes.Ldc_R4) - { - if (instr.OperandIs(0.5f)) - { - if (UseFixedSpeed) - { - if (FixedSpeed > 75f) - { - instr.operand = 0.5f * FixedSpeed / 75f; - } - } - else - { - instr.operand = 0.5f * SpeedMultiplier; - } - } - else if (instr.OperandIs(3f)) - { - if (RemoveSpeedLimitForStage1) - { - instr.operand = 10000f; - } - } - } - yield return instr; + i++; + continue; + } + + if (instrNext.opcode == OpCodes.Ldc_R4) + { + if (instrNext.OperandIs(0f)) + { + var instrNext2 = ilist[i + 2]; + if (instrNext2.opcode == OpCodes.Stfld && + instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) + { + ilist[i + 3].labels = instr.labels; + i += 2; + continue; + } + } + else if (instrNext.OperandIs(1f)) + { + var instrNext2 = ilist[i + 2]; + if (instrNext2.opcode == OpCodes.Stfld && + instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) + { + instrNext.operand = 0f; + yield return instr; + yield return instrNext; + yield return instrNext2; + i += 2; + continue; + } + } + } + } + else if (instr.opcode == OpCodes.Ldc_R4) + { + if (instr.OperandIs(0.5f)) + { + if (UseFixedSpeed) + { + if (FixedSpeed > 75f) + { + instr.operand = 0.5f * FixedSpeed / 75f; + } + } + else + { + instr.operand = 0.5f * SpeedMultiplier; + } + } + else if (instr.OperandIs(3f)) + { + if (RemoveSpeedLimitForStage1) + { + instr.operand = 10000f; + } + } + } + + yield return instr; + } } } @@ -252,91 +276,140 @@ public static class MechaDronesTweaks private static IEnumerable BuildTools_CursorSizePatch_Transpiler( IEnumerable instructions) { - foreach (var instr in instructions) + if (!largerAreaForUpgradeAndDismantle) { - if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(11)) - { - yield return new CodeInstruction(OpCodes.Ldc_I4_S, 31); - } - else + foreach (var instr in instructions) { yield return instr; } } + else + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(11)) + { + yield return new CodeInstruction(OpCodes.Ldc_I4_S, 31); + } + else + { + yield return instr; + } + } + } } [HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))] private static IEnumerable BuildTool_Reform_ReformAction_Transpiler( IEnumerable instructions) { - var ilist = instructions.ToList(); - for (var i = 0; i < ilist.Count; i++) + if (!largerAreaForTerraform) { - var instr = ilist[i]; - if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(10) && - (ilist[i - 1].opcode == OpCodes.Ldfld && - ilist[i - 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize")) - || - ilist[i + 1].opcode == OpCodes.Stfld && - ilist[i + 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize"))) - ) - { - yield return new CodeInstruction(OpCodes.Ldc_I4_S, 30); - } - else + foreach (var instr in instructions) { yield return instr; } } + else + { + var ilist = instructions.ToList(); + for (var i = 0; i < ilist.Count; i++) + { + var instr = ilist[i]; + if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(10) && + (ilist[i - 1].opcode == OpCodes.Ldfld && + ilist[i - 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize")) + || + ilist[i + 1].opcode == OpCodes.Stfld && + ilist[i + 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize"))) + ) + { + yield return new CodeInstruction(OpCodes.Ldc_I4_S, 30); + } + else + { + yield return instr; + } + } + } } - - + [HarmonyTranspiler, HarmonyPatch(typeof(ConnGizmoGraph), MethodType.Constructor)] private static IEnumerable ConnGizmoGraph_Constructor_Transpiler( IEnumerable instructions) { - foreach (var instr in instructions) + if (!removeBuildRangeLimit) { - if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256)) - { - yield return new CodeInstruction(OpCodes.Ldc_I4, 2048); - } - else + foreach (var instr in instructions) { yield return instr; } } + else + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256)) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, 2048); + } + else + { + yield return instr; + } + } + } } [HarmonyTranspiler, HarmonyPatch(typeof(ConnGizmoGraph), nameof(ConnGizmoGraph.SetPointCount))] private static IEnumerable ConnGizmoGraph_SetPointCount_Transpiler( IEnumerable instructions) { - foreach (var instr in instructions) + if (!removeBuildRangeLimit) { - if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256)) - { - yield return new CodeInstruction(OpCodes.Ldc_I4, 2048); - } - else + foreach (var instr in instructions) { yield return instr; } } + else + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256)) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, 2048); + } + else + { + yield return instr; + } + } + } } [HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path._OnInit))] private static IEnumerable BuildTool_Path__OnInit_Transpiler( IEnumerable instructions) { - foreach (var instr in instructions) + if (!removeBuildRangeLimit) { - if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(160)) + foreach (var instr in instructions) { - instr.operand = 2048; + yield return instr; } + } + else + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(160)) + { + instr.operand = 2048; + } - yield return instr; + yield return instr; + } } } @@ -344,17 +417,27 @@ public static class MechaDronesTweaks private static IEnumerable BuildTool_Click__OnInit_Transpiler( IEnumerable instructions) { - foreach (var instr in instructions) + if (!removeBuildRangeLimit) { - if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(15)) - { - yield return new CodeInstruction(OpCodes.Ldc_I4, 512); - } - else + foreach (var instr in instructions) { yield return instr; } } + else + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(15)) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, 512); + } + else + { + yield return instr; + } + } + } } [HarmonyTranspiler] @@ -367,82 +450,94 @@ public static class MechaDronesTweaks [HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))] [HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DetermineMoreChainTargets))] [HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DeterminePreviews))] - private static IEnumerable BuildAreaElimination_Transpiler( + private static IEnumerable BuildAreaLimitRemoval_Transpiler( IEnumerable instructions) { - /* Patch (player.mecha.buildArea * player.mecha.buildArea) to 100000000 */ - var ilist = instructions.ToList(); - var count = ilist.Count - 8; - int i; - for (i = 0; i < count; i++) + if (!removeBuildRangeLimit) { - var found = false; - while (true) + foreach (var instr in instructions) { - var instr = ilist[i + 1]; - if (instr.opcode != OpCodes.Call || - !instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player"))) + yield return instr; + } + } + else + { + /* Patch (player.mecha.buildArea * player.mecha.buildArea) to 100000000 */ + var ilist = instructions.ToList(); + var count = ilist.Count - 8; + int i; + for (i = 0; i < count; i++) + { + var found = false; + while (true) { + var instr = ilist[i + 1]; + if (instr.opcode != OpCodes.Call || + !instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player"))) + { + break; + } + + instr = ilist[i + 2]; + if (instr.opcode != OpCodes.Callvirt || + !instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha"))) + { + break; + } + + instr = ilist[i + 3]; + if (instr.opcode != OpCodes.Ldfld || + !instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea"))) + { + break; + } + + instr = ilist[i + 5]; + if (instr.opcode != OpCodes.Call || + !instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player"))) + { + break; + } + + instr = ilist[i + 6]; + if (instr.opcode != OpCodes.Callvirt || + !instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha"))) + { + break; + } + + instr = ilist[i + 7]; + if (instr.opcode != OpCodes.Ldfld || + !instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea"))) + { + break; + } + + instr = ilist[i + 8]; + if (instr.opcode != OpCodes.Mul) + { + break; + } + + found = true; + yield return new CodeInstruction(OpCodes.Ldc_R4, 100000000.0f); break; } - instr = ilist[i + 2]; - if (instr.opcode != OpCodes.Callvirt || - !instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha"))) + if (found) { - break; + i += 8; } - - instr = ilist[i + 3]; - if (instr.opcode != OpCodes.Ldfld || !instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea"))) + else { - break; + yield return ilist[i]; } - - instr = ilist[i + 5]; - if (instr.opcode != OpCodes.Call || - !instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player"))) - { - break; - } - - instr = ilist[i + 6]; - if (instr.opcode != OpCodes.Callvirt || - !instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha"))) - { - break; - } - - instr = ilist[i + 7]; - if (instr.opcode != OpCodes.Ldfld || !instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea"))) - { - break; - } - - instr = ilist[i + 8]; - if (instr.opcode != OpCodes.Mul) - { - break; - } - - found = true; - yield return new CodeInstruction(OpCodes.Ldc_R4, 100000000.0f); - break; } - if (found) - { - i += 8; - } - else + for (; i < ilist.Count; i++) { yield return ilist[i]; } } - - for (; i < ilist.Count; i++) - { - yield return ilist[i]; - } } } \ No newline at end of file diff --git a/MechaDronesTweaks/MechaDronesTweaks.csproj b/MechaDronesTweaks/MechaDronesTweaks.csproj index 24d045d..bc516fc 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.csproj +++ b/MechaDronesTweaks/MechaDronesTweaks.csproj @@ -5,7 +5,7 @@ MechaDronesTweaks org.soardev.mechadronestweaks DSP MOD - MechaDronesTweaks - 1.0.0 + 1.1.0 true latest diff --git a/MechaDronesTweaks/README.md b/MechaDronesTweaks/README.md index 2763add..fecea26 100644 --- a/MechaDronesTweaks/README.md +++ b/MechaDronesTweaks/README.md @@ -9,28 +9,42 @@ * All values are patched in memory but written to game-saves so that you can play with normal mecha drone parameters while disabling this MOD. * You can take benefit from this MOD on any game-saves after enabling this MOD. * Config entries: - * `UseFixedSpeed` [Default Value: false]: - * If enabled: Use `FixedSpeed` for mecha drones, which makes related Upgrades not used any more. - * If disabled: Use `SpeedMultiplier` for mecha drones. - * `SkipStage1` [Default Value: false]: Skip mecha drones' 1st stage (flying away from mecha in ~1/3 speed for several frames). - * `RemoveSpeedLimitForStage1` [Default Value: true]: Remove speed limit for 1st stage (has a speed limit @ ~10m/s originally). - * `FixedSpeed` [Default Value: 300]: Fixed flying speed for mecha drones. - * `SpeedMultiplier` [Default Value: 4]: Speed multiplier for mecha drones. - * `EnergyMultiplier` [Default Value: 0.1]: Energy consumption multiplier for mecha drones. + * `[MechaDrones]` + * `UseFixedSpeed` [Default Value: false]: + * If enabled: Use `FixedSpeed` for mecha drones, which makes related Upgrades not used any more. + * If disabled: Use `SpeedMultiplier` for mecha drones. + * `SkipStage1` [Default Value: false]: Skip mecha drones' 1st stage (flying away from mecha in ~1/3 speed for several frames). + * `RemoveSpeedLimitForStage1` [Default Value: true]: Remove speed limit for 1st stage (has a speed limit @ ~10m/s originally). + * `FixedSpeed` [Default Value: 300]: Fixed flying speed for mecha drones. + * `SpeedMultiplier` [Default Value: 4]: Speed multiplier for mecha drones. + * `EnergyMultiplier` [Default Value: 0.1]: Energy consumption multiplier for mecha drones. + * `[MechaBuild]` + * `RemoveBuildRangeLimit` [Default Value: true]: Remove limit for build range and maximum count of drag building belts/buildings. + * Note: this does not affect range limit for mecha drones' action + * `LargerAreaForUpgradeAndDismantle` [Default Value: true]: Increase maximum area size for upgrade and dismantle to 31x31 (from 11x11). + * `LargerAreaForTerraform` [Default Value: true]: Increase maximum area size for terraform to 30x30 (from 10x10). + * Note: this may impact game performance while using large area. * Note: This MOD will disable `FastDrones` if the MOD is installed, to avoid conflict in functions. ## 使用说明 * 功能参考 [FastDrones](https://dsp.thunderstore.io/package/dkoppstein/FastDrones/),但主要对IL代码进行Patch因此消耗更少的CPU,尤其在大规模建造比如放置蓝图的时候可以大大减少卡顿。 * 不影响当前游戏存档: - * 所有修改参数都在内存中Patch不会写入存档,禁用此MOD后可恢复正常建设机参数。 - * 启用本MOD后可以在已经游玩的游戏存档上享受参数的改动。 + * 所有修改参数都在内存中Patch不会写入存档,禁用此MOD后可恢复正常建设机参数。 + * 启用本MOD后可以在已经游玩的游戏存档上享受参数的改动。 * 设置选项: + * `[MechaDrones]` * `UseFixedSpeed` [默认值: false]: - * 启用: 使用 `FixedSpeed`,固定速度,这将覆盖对应机甲建设机速度的升级数值。 - * 禁用: 使用 `SpeedMultiplier` + * 启用: 使用 `FixedSpeed`,固定速度,这将覆盖对应机甲建设机速度的升级数值。 + * 禁用: 使用 `SpeedMultiplier` * `SkipStage1` [默认值: false]: 跳过建设机起飞的第一阶段(以大约1/3速度从机甲身上飞出,持续若干帧). * `RemoveSpeedLimitForStage1` [默认值: true]: 移除第一阶段的速度限制 (原本大约有10m/s的限制). * `FixedSpeed` [默认值: 300]: 固定速度。 * `SpeedMultiplier` [默认值: 4]: 速度倍数。 * `EnergyMultiplier` [默认值: 0.1]: 能量消耗倍数。 + * `[MechaBuild]` + * `RemoveBuildRangeLimit` [默认值: true]: 解除摆放建筑距离和拖放建筑/传送带数量的限制。 + * 注意: 并不会解除建设机行动的距离限制。 + * `LargerAreaForUpgradeAndDismantle` [默认值: true]: 提升区域升级和拆除建筑的最大区域至31x31 (之前是11x11)。 + * `LargerAreaForTerraform` [默认值: true]: 提升区域铺设地地基的最大区域至30x30 (之前是10x10)。 + * 注意: 使用较大的区域可能对游戏实时性能有影响。 * 说明: 如果安装了`FastDrones`本MOD会将其禁用避免功能冲突。 diff --git a/MechaDronesTweaks/package/manifest.json b/MechaDronesTweaks/package/manifest.json index 372d88d..e93ccf1 100644 --- a/MechaDronesTweaks/package/manifest.json +++ b/MechaDronesTweaks/package/manifest.json @@ -1,8 +1,8 @@ { "name": "MechaDronesTweaks", - "version_number": "1.0.0", + "version_number": "1.1.0", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/MechaDronesTweaks", - "description": "Some tweaks for mecha drones(Successor to FastDrones MOD) / 机甲建设机调整(FastDrones MOD的后继者)", + "description": "Some tweaks for mecha drones and build functions(Successor to FastDrones MOD) / 机甲建设机和建设功能调整(FastDrones MOD的后继者)", "dependencies": [ "xiaoye97-BepInEx-5.4.17" ]