From 556493b2b60d6e9aed7a3472d852edf9a6dc5d48 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sat, 15 Nov 2025 22:48:35 +0800 Subject: [PATCH] some fixes --- CheatEnabler/Patches/GamePatch.cs | 4 +- CheatEnabler/Patches/PlanetPatch.cs | 94 +++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/CheatEnabler/Patches/GamePatch.cs b/CheatEnabler/Patches/GamePatch.cs index 6daaee9..cee8154 100644 --- a/CheatEnabler/Patches/GamePatch.cs +++ b/CheatEnabler/Patches/GamePatch.cs @@ -140,7 +140,7 @@ public static class GamePatch var pos = matcher.Pos; /* Remove Shift+F4 part of the method */ matcher.Start().RemoveInstructions(pos).MatchForward(false, - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GameMain), "get_sandboxToolsEnabled")), + new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(GameMain), nameof(GameMain.sandboxToolsEnabled))), new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Ceq) ); @@ -297,7 +297,7 @@ public static class GamePatch matcher.MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UITechNode), nameof(UITechNode.tree))), - new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(UITechTree), "get_selected")) + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(UITechTree), nameof(UITechTree.selected))) ); var labels = matcher.Labels; matcher.Labels = null; diff --git a/CheatEnabler/Patches/PlanetPatch.cs b/CheatEnabler/Patches/PlanetPatch.cs index 805f6fa..aadb198 100644 --- a/CheatEnabler/Patches/PlanetPatch.cs +++ b/CheatEnabler/Patches/PlanetPatch.cs @@ -53,6 +53,92 @@ public static class PlanetPatch private class TerraformAnyway : PatchImpl { + [HarmonyTranspiler] + [HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.DetermineReforms))] + private static IEnumerable BuildTool_BlueprintPaste_DetermineReforms_Patch(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.player))), + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.sandCount))), + new CodeMatch(ci => ci.IsStloc()) + ).Advance(4).MatchForward(false, + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(OpCodes.Conv_I8), + new CodeMatch(ci => ci.opcode == OpCodes.Bge || ci.opcode == OpCodes.Bge_S) + ); + var labels = matcher.Labels; + matcher.Labels = null; + matcher.RemoveInstructions(3); + matcher.Labels.AddRange(labels); + matcher.Opcode = OpCodes.Br; + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.RemoveBasePit))] + private static IEnumerable BuildTool_Reform_RemoveBasePit_Patch(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildTool_Reform), nameof(BuildTool_Reform.circlePointCount))), + new CodeMatch(ci => ci.opcode == OpCodes.Blt || ci.opcode == OpCodes.Blt_S) + ).RemoveInstructions(2).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I4_0) + ).MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.player))), + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.sandCount))), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(OpCodes.Conv_I8), + new CodeMatch(OpCodes.Sub) + ).Advance(6).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I8, 0L), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), nameof(Math.Max), [typeof(long), typeof(long)])) + ); + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIRemoveBasePitButton), nameof(UIRemoveBasePitButton.OnRemoveButtonClick))] + [HarmonyPatch(typeof(UIRemoveBasePitButton), nameof(UIRemoveBasePitButton._OnUpdate))] + private static IEnumerable UIRemoveBasePitButton_OnRemoveButtonClick_Patch(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIRemoveBasePitButton), nameof(UIRemoveBasePitButton.pointCount))), + new CodeMatch(OpCodes.Sub), + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(OpCodes.Clt) + ); + if (matcher.IsValid) + { + matcher.RemoveInstructions(2).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I4_0) + ); + } + else + { + matcher.Start(); + } + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIRemoveBasePitButton), nameof(UIRemoveBasePitButton.player))), + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.sandCount))), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(OpCodes.Conv_I8), + new CodeMatch(OpCodes.Sub) + ).Advance(6).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I8, 0L), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), nameof(Math.Max), [typeof(long), typeof(long)])) + ); + return matcher.InstructionEnumeration(); + } + [HarmonyTranspiler] [HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))] private static IEnumerable BuildTool_Reform_ReformAction_Patch(IEnumerable instructions, ILGenerator generator) @@ -65,13 +151,13 @@ public static class PlanetPatch ).RemoveInstructions(2).InsertAndAdvance( new CodeInstruction(OpCodes.Ldc_I4_0) ).MatchForward(false, - new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(Player), "get_sandCount")) + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.sandCount))) ).Advance(1).MatchForward(false, - new CodeMatch(OpCodes.Conv_I8), - new CodeMatch(OpCodes.Sub) + new CodeMatch(OpCodes.Conv_I8), + new CodeMatch(OpCodes.Sub) ).Advance(2).InsertAndAdvance( new CodeInstruction(OpCodes.Ldc_I8, 0L), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), "Max", [typeof(long), typeof(long)])) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), nameof(Math.Max), [typeof(long), typeof(long)])) ); return matcher.InstructionEnumeration(); }