Harmony
Harmony copied to clipboard
IL Compile Error when using PrefixFactory to provide a non-static Prefix method (Mono)
trafficstars
I want GUI_ItemManager_Stash__Init_Prefix to be non-static so I can reference the _controller object in my class.
If i set GUI_ItemManager_Stash__Init_Prefix to be static, everything works fine.
public void addHarmonyHooks()
{
MoreQOD.Instance.HarmonyInstance.Patch(
typeof(GUI_ItemManager_Stash).GetMethod(nameof(GUI_ItemManager_Stash.Init), AccessTools.all, null,
new[] { typeof(Profile) }, null),
new HarmonyMethod(typeof(StashSort).GetMethod(nameof(PrefixFactory), AccessTools.all)));
}
private static MethodInfo PrefixFactory(MethodBase original)
{
return typeof(StashSort).GetMethod(nameof(GUI_ItemManager_Stash__Init_Prefix), AccessTools.all);
}
private void GUI_ItemManager_Stash__Init_Prefix(Profile profile, ItemController_Stash ____controller)
{
MelonLogger.Msg("GUI_ItemManager_Stash__Init_Prefix");
MoreQOD.Instance.StashSort.controller = ____controller;
}
[11:00:54.971] [MoreQOD] [ERROR] HarmonyLib.HarmonyException: IL Compile Error (unknown location) ---> HarmonyLib.HarmonyException: IL Compile Error (unknown location) ---> System.InvalidProgramException: Invalid IL code in (wrapper dynamic-method) Death.Run.UserInterface.Items.GUI_ItemManager_Stash:DMD<Death.Run.
UserInterface.Items.GUI_ItemManager_Stash::Init> (Death.Run.UserInterface.Items.GUI_ItemManager_Stash,Death.App.Profile): IL_000e: call 0x00000003
at (wrapper managed-to-native) System.RuntimeMethodHandle.GetFunctionPointer(intptr)
at System.RuntimeMethodHandle.GetFunctionPointer () [0x00000] in <9aad1b3a47484d63ba2b3985692d80e9>:0
at MonoMod.RuntimeDetour.Platforms.DetourRuntimeILPlatform.GetFunctionPointer (System.Reflection.MethodBase method, System.RuntimeMethodHandle handle) [0x00000] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.Platforms.DetourRuntimeILPlatform.GetNativeStart (System.Reflection.MethodBase method) [0x0004d] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.DetourHelper.GetNativeStart (System.Reflection.MethodBase method) [0x00005] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.Detour._TopApply () [0x00025] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.Detour._RefreshChain (System.Reflection.MethodBase method) [0x00149] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.Detour.Apply () [0x00053] in <4e2760c7517c4ea79c633d67e84b319f>:0
at MonoMod.RuntimeDetour.Detour..ctor (System.Reflection.MethodBase from, System.Reflection.MethodBase to, MonoMod.RuntimeDetour.DetourConfig& config) [0x002e1] in <4e2760c7517c4ea79c633d67e84b319f>:0
at (wrapper dynamic-method) MonoMod.RuntimeDetour.ILHook+Context.DMD<MonoMod.RuntimeDetour.ILHook+Context::Refresh>(MonoMod.RuntimeDetour.ILHook/Context)
at (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition.Trampoline<MonoMod.RuntimeDetour.ILHook+Context::Refresh>?-694816200(object)
at HarmonyLib.Internal.RuntimeFixes.StackTraceFixes.OnILChainRefresh (System.Object self) [0x00000] in <474744d65d8e460fa08cd5fd82b5d65f>:0
at MonoMod.RuntimeDetour.ILHook.Apply () [0x00059] in <4e2760c7517c4ea79c633d67e84b319f>:0
at HarmonyLib.Public.Patching.ManagedMethodPatcher.DetourTo (System.Reflection.MethodBase replacement) [0x00047] in <474744d65d8e460fa08cd5fd82b5d65f>:0
--- End of inner exception stack trace ---
at HarmonyLib.Public.Patching.ManagedMethodPatcher.DetourTo (System.Reflection.MethodBase replacement) [0x0005f] in <474744d65d8e460fa08cd5fd82b5d65f>:0
at HarmonyLib.PatchFunctions.UpdateWrapper (System.Reflection.MethodBase original, HarmonyLib.PatchInfo patchInfo) [0x00033] in <474744d65d8e460fa08cd5fd82b5d65f>:0
--- End of inner exception stack trace ---
at HarmonyLib.PatchFunctions.UpdateWrapper (System.Reflection.MethodBase original, HarmonyLib.PatchInfo patchInfo) [0x0005d] in <474744d65d8e460fa08cd5fd82b5d65f>:0
at (wrapper dynamic-method) HarmonyLib.PatchProcessor.DMD<HarmonyLib.PatchProcessor::Patch>(HarmonyLib.PatchProcessor)
at HarmonyLib.Harmony.Patch (System.Reflection.MethodBase original, HarmonyLib.HarmonyMethod prefix, HarmonyLib.HarmonyMethod postfix, HarmonyLib.HarmonyMethod transpiler, HarmonyLib.HarmonyMethod finalizer, HarmonyLib.HarmonyMethod ilmanipulator) [0x00031] in <474744d65d8e460fa08cd5fd82b5d65f>:0
at MoreQOD.StashSort.addHarmonyHooks () [0x00056] in <3842b99c11174eca964c125b33e11d08>:0
at MoreQOD.MoreQOD.addFeatures () [0x00056] in <3842b99c11174eca964c125b33e11d08>:0