From 80df6b37274fceaf165097517256b8e03e2119e7 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Mon, 25 Sep 2023 15:44:19 +0800 Subject: [PATCH] minor fix for Mods compatibility --- CheatEnabler/FactoryPatch.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CheatEnabler/FactoryPatch.cs b/CheatEnabler/FactoryPatch.cs index 736d3f8..17e8476 100644 --- a/CheatEnabler/FactoryPatch.cs +++ b/CheatEnabler/FactoryPatch.cs @@ -370,8 +370,17 @@ public static class FactoryPatch { var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GC), nameof(GC.Collect))) + new CodeMatch(OpCodes.Ret) ); + if (matcher.IsInvalid) + { + CheatEnabler.Logger.LogWarning($"Failed to patch CreatePrebuilds"); + return matcher.InstructionEnumeration(); + } + + matcher.Advance(-1); + if (matcher.Opcode != OpCodes.Nop && (matcher.Opcode != OpCodes.Call || !matcher.Instruction.OperandIs(AccessTools.Method(typeof(GC), nameof(GC.Collect))))) + return matcher.InstructionEnumeration(); var labels = matcher.Labels; matcher.Labels = null; matcher.Insert(