From 741faf0c452576a140340e48190139486ba03ded Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Mon, 3 Jul 2023 21:17:41 +0800 Subject: [PATCH] Work in progress: more mecha build functions --- MechaDronesTweaks/MechaDronesTweaks.cs | 93 +++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/MechaDronesTweaks/MechaDronesTweaks.cs b/MechaDronesTweaks/MechaDronesTweaks.cs index ae4e48c..2778f3d 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.cs +++ b/MechaDronesTweaks/MechaDronesTweaks.cs @@ -39,7 +39,7 @@ public class MechaDronesTweaksPlugin : BaseUnityPlugin "Use fixed speed for mecha drones").Value; MechaDronesTweaks.SkipStage1 = Config.Bind("MechaDrones", "SkipStage1", MechaDronesTweaks.SkipStage1, - "Skip mecha drones' 1st stage (flying away from mecha in ~1/3 speed for several frames)").Value; + "Skip 1st stage of working mecha drones (flying away from mecha in ~1/3 speed for several frames)").Value; MechaDronesTweaks.RemoveSpeedLimitForStage1 = Config.Bind("MechaDrones", "RemoveSpeedLimitForStage1", MechaDronesTweaks.RemoveSpeedLimitForStage1, "Remove speed limit for 1st stage (has a speed limit @ ~10m/s originally)").Value; @@ -54,6 +54,10 @@ public class MechaDronesTweaksPlugin : BaseUnityPlugin MechaDronesTweaks.EnergyMultiplier, new ConfigDescription("Energy consumption multiplier for mecha drones", new AcceptableValueRange(0f, 1f))).Value; + MechaDronesTweaks.EnergyMultiplier = Config.Bind("MechaDrones", "EnergyMultiplier", + MechaDronesTweaks.EnergyMultiplier, + new ConfigDescription("Energy consumption multiplier for mecha drones", + new AcceptableValueRange(0f, 1f))).Value; _harmony.PatchAll(typeof(MechaDronesTweaks)); } @@ -232,4 +236,91 @@ public static class MechaDronesTweaks yield return instr; } } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))] + [HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))] + [HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DetermineMoreChainTargets))] + [HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DeterminePreviews))] + [HarmonyPatch(typeof(BuildTool_Inserter), nameof(BuildTool_Inserter.CheckBuildConditions))] + [HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.CheckBuildConditions))] + [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(IEnumerable instructions) + { + 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; + } + + if (found) + { + i += 8; + } + else + { + yield return ilist[i]; + } + } + + for (; i < ilist.Count; i++) + { + yield return ilist[i]; + } + } } \ No newline at end of file