mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 12:53:34 +08:00
WIP
This commit is contained in:
38
CheatEnabler/TerraformPatch.cs
Normal file
38
CheatEnabler/TerraformPatch.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CheatEnabler;
|
||||
public static class TerraformPatch
|
||||
{
|
||||
public static ConfigEntry<bool> Enabled;
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_patch = Harmony.CreateAndPatchAll(typeof(TerraformPatch));
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
if (_patch == null) return;
|
||||
_patch.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(Player), "get_sandCount"))
|
||||
).Advance(3).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldc_I4_0),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), "Max", new[] { typeof(int), typeof(int) }))
|
||||
).Advance(1).RemoveInstructions(3);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user