1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-05 03:42:20 +08:00

Work in progress

This commit is contained in:
2023-07-29 22:12:19 +08:00
parent f79a3f1201
commit 414b811e7e
4 changed files with 80 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Threading;
using BepInEx;
using HarmonyLib;
@@ -267,5 +268,43 @@ public class LabOptPatch : BaseUnityPlugin
);
return matcher.InstructionEnumeration();
}
// Change locks on PlanetFactory.InsertInto()
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlanetFactory), nameof(PlanetFactory.InsertInto))]
private static IEnumerable<CodeInstruction> PlanetFactory_InsertInto_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
/* Remove following codes:
465 0427 ldarg.0
466 0428 ldfld class Mutex[] PlanetFactory::entityMutexs
467 042D ldarg.1
468 042E ldelem.ref
469 042F stloc.s V_10 (10)
470 0431 ldc.i4.0
471 0432 stloc.s V_11 (11)
472 0434 ldloc.s V_10 (10)
473 0436 ldloca.s V_11 (11)
474 0438 call void [netstandard]System.Threading.Monitor::Enter(object, bool&)
*/
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EntityData), nameof(EntityData.labId)))
).Advance(1).MatchForward(false,
new CodeMatch(OpCodes.Ret)
).Advance(1);
var labels = matcher.Instruction.labels;
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
new CodeInstruction(OpCodes.Ldloc_S, 5),
new CodeInstruction(OpCodes.Ldarg_3),
new CodeInstruction(OpCodes.Ldarg_S, 4),
new CodeInstruction(OpCodes.Ldarg_S, 5),
new CodeInstruction(OpCodes.Ldarg_S, 6),
new CodeInstruction(OpCodes.Ldloc_1),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.InsertIntoLab))),
new CodeInstruction(OpCodes.Ret)
);
matcher.Instruction.labels.Clear();
return matcher.InstructionEnumeration();
}
}