1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 19:33:27 +08:00

some fixes

This commit is contained in:
2025-11-15 22:48:35 +08:00
parent 269cc3b801
commit 556493b2b6
2 changed files with 92 additions and 6 deletions

View File

@@ -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;

View File

@@ -53,6 +53,92 @@ public static class PlanetPatch
private class TerraformAnyway : PatchImpl<TerraformAnyway>
{
[HarmonyTranspiler]
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.DetermineReforms))]
private static IEnumerable<CodeInstruction> BuildTool_BlueprintPaste_DetermineReforms_Patch(IEnumerable<CodeInstruction> 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<CodeInstruction> BuildTool_Reform_RemoveBasePit_Patch(IEnumerable<CodeInstruction> 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<CodeInstruction> UIRemoveBasePitButton_OnRemoveButtonClick_Patch(IEnumerable<CodeInstruction> 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<CodeInstruction> BuildTool_Reform_ReformAction_Patch(IEnumerable<CodeInstruction> 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();
}