From 2a1b648f024a0dcac8c2853541e513f379e4a370 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Wed, 7 May 2025 17:43:26 +0700 Subject: [PATCH] fix compiler injection patch matching --- .../Patches/ModAssemblyLoadContextPatches.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CringeLauncher/Patches/ModAssemblyLoadContextPatches.cs b/CringeLauncher/Patches/ModAssemblyLoadContextPatches.cs index b844e0b..3769f81 100644 --- a/CringeLauncher/Patches/ModAssemblyLoadContextPatches.cs +++ b/CringeLauncher/Patches/ModAssemblyLoadContextPatches.cs @@ -26,25 +26,24 @@ public static class ModAssemblyLoadContextPatches var load1Method = AccessTools.DeclaredMethod(typeof(Assembly), nameof(Assembly.Load), [typeof(byte[]), typeof(byte[])]); var load2Method = AccessTools.DeclaredMethod(typeof(Assembly), nameof(Assembly.Load), [typeof(byte[])]); - matcher.SearchForward(i => i.Calls(load1Method)) + return matcher.SearchForward(i => i.Calls(load1Method)) .InsertAndAdvance(new(OpCodes.Ldarg_0), CodeInstruction.LoadField(original.DeclaringType, "target")) .SetInstruction(CodeInstruction.CallClosure((byte[] assembly, byte[] symbols, MyApiTarget target) => { if (target is not MyApiTarget.Mod) return Assembly.Load(assembly, symbols); ArgumentNullException.ThrowIfNull(_currentSessionContext, "No session context"); return _currentSessionContext.LoadFromStream(new MemoryStream(assembly), new MemoryStream(symbols)); - })); - - matcher.SearchForward(i => i.Calls(load2Method)) + })) + .Start() + .SearchForward(i => i.Calls(load2Method)) .InsertAndAdvance(new(OpCodes.Ldarg_0), CodeInstruction.LoadField(original.DeclaringType, "target")) .SetInstruction(CodeInstruction.CallClosure((byte[] assembly, MyApiTarget target) => { if (target is not MyApiTarget.Mod) return Assembly.Load(assembly); ArgumentNullException.ThrowIfNull(_currentSessionContext, "No session context"); return _currentSessionContext.LoadFromStream(new MemoryStream(assembly)); - })); - - return matcher.Instructions(); + })) + .Instructions(); } [HarmonyPatch(typeof(MyScriptManager), "Compile")]