BepInEx/BepInEx.Utility

Failed to patch static void UnityEngine.GUILayoutUtility::Begin() for OptimizeIMGUI

RandomGuyJCI opened this issue · 1 comments

When I installed the OptimizeIMGUI plugin in Rhythm Doctor, BepInEx sent an error and the plugin couldn't be patched.

  • BepInEx version: 5.4.21 (x86)
  • Game: Rhythm Doctor v0.11.6
  • Unity version: 2021.3.6f1

Full error log:

[Info   :   BepInEx] Loading [Optimize IMGUI GC allocations 1.0]
Fallback handler could not load library C:/Program Files (x86)/Steam/steamapps/common/Rhythm Doctor/Rhythm Doctor_Data/MonoBleedingEdge/data-16811CC0.dll
[Error  :  HarmonyX] Failed to patch static void UnityEngine.GUILayoutUtility::Begin(int instanceID): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MethodAccessException: Method `HarmonyXInterop.TranspilerInterop.ApplyTranspiler(System.Reflection.MethodInfo,System.Collections.Generic.IEnumerable`1<HarmonyLib.CodeInstruction>,System.Reflection.Emit.ILGenerator,System.Reflection.MethodBase)' is inaccessible from method `DMD<>?-839127053.TranspilerWrapper<BepInEx.OptimizeIMGUI+Hooks::FixOnguiGarbageDump>(System.Collections.Generic.IEnumerable`1<HarmonyLib.CodeInstruction>,System.Reflection.Emit.ILGenerator,System.Reflection.MethodBase)'
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
  at DMD<>?-839127053.TranspilerWrapper<BepInEx.OptimizeIMGUI+Hooks::FixOnguiGarbageDump> (System.Collections.Generic.IEnumerable`1[T] , System.Reflection.Emit.ILGenerator , System.Reflection.MethodBase ) [0x0000a] in <fd914e7fd4294a509c6e118a98684276>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
  at HarmonyLib.Internal.Patching.ILManipulator.ApplyTranspilers (System.Reflection.Emit.ILGenerator il, System.Reflection.MethodBase original, System.Func`2[T,TResult] getLocal, System.Func`1[TResult] defineLabel) [0x00093] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Internal.Patching.ILManipulator.WriteTo (Mono.Cecil.Cil.MethodBody body, System.Reflection.MethodBase original) [0x00066] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.WriteTranspilers () [0x00084] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.WriteImpl () [0x0002b] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
MethodAccessException: Method `HarmonyXInterop.TranspilerInterop.ApplyTranspiler(System.Reflection.MethodInfo,System.Collections.Generic.IEnumerable`1<HarmonyLib.CodeInstruction>,System.Reflection.Emit.ILGenerator,System.Reflection.MethodBase)' is inaccessible from method `DMD<>?-839127053.TranspilerWrapper<BepInEx.OptimizeIMGUI+Hooks::FixOnguiGarbageDump>(System.Collections.Generic.IEnumerable`1<HarmonyLib.CodeInstruction>,System.Reflection.Emit.ILGenerator,System.Reflection.MethodBase)'
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
  at DMD<>?-839127053.TranspilerWrapper<BepInEx.OptimizeIMGUI+Hooks::FixOnguiGarbageDump> (System.Collections.Generic.IEnumerable`1[T] , System.Reflection.Emit.ILGenerator , System.Reflection.MethodBase ) [0x0000a] in <fd914e7fd4294a509c6e118a98684276>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <e40e5a8f982c4b618a930d29f9bd091c>:0 
  at HarmonyLib.Internal.Patching.ILManipulator.ApplyTranspilers (System.Reflection.Emit.ILGenerator il, System.Reflection.MethodBase original, System.Func`2[T,TResult] getLocal, System.Func`1[TResult] defineLabel) [0x00093] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Internal.Patching.ILManipulator.WriteTo (Mono.Cecil.Cil.MethodBody body, System.Reflection.MethodBase original) [0x00066] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.WriteTranspilers () [0x00084] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.WriteImpl () [0x0002b] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
Rethrow as HarmonyException: IL Compile Error (unknown location)
  at HarmonyLib.Public.Patching.HarmonyManipulator.WriteImpl () [0x00378] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.Process (MonoMod.Cil.ILContext ilContext, System.Reflection.MethodBase originalMethod) [0x00042] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.Manipulate (System.Reflection.MethodBase original, HarmonyLib.PatchInfo patchInfo, MonoMod.Cil.ILContext ctx) [0x00006] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.HarmonyManipulator.Manipulate (System.Reflection.MethodBase original, MonoMod.Cil.ILContext ctx) [0x00007] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyLib.Public.Patching.ManagedMethodPatcher.Manipulator (MonoMod.Cil.ILContext ctx) [0x00012] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at MonoMod.Cil.ILContext.Invoke (MonoMod.Cil.ILContext+Manipulator manip) [0x00087] in <6733e342b5b549bba815373898724469>:0 
  at MonoMod.RuntimeDetour.ILHook+Context.InvokeManipulator (Mono.Cecil.MethodDefinition def, MonoMod.Cil.ILContext+Manipulator cb) [0x00012] 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>?860763720(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 
Rethrow as HarmonyException: IL Compile Error (unknown location)
  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 
Rethrow as HarmonyException: IL Compile Error (unknown location)
  at HarmonyLib.PatchFunctions.UpdateWrapper (System.Reflection.MethodBase original, HarmonyLib.PatchInfo patchInfo) [0x0005d] in <474744d65d8e460fa08cd5fd82b5d65f>:0 
  at HarmonyXInterop.HarmonyInterop.ApplyPatch (System.Reflection.MethodBase target, HarmonyXInterop.PatchInfoWrapper add, HarmonyXInterop.PatchInfoWrapper remove) [0x00096] in <6f91f4d0d9ac41feb7f307a416c33caa>:0 
  at HarmonyLib.Internal.MethodPatcher.Apply () [0x000f1] in <b82efbe2c5b74e3c987a02289921fc46>:0 
  at HarmonyLib.PatchProcessor.Patch () [0x00155] in <b82efbe2c5b74e3c987a02289921fc46>:0 
  at HarmonyLib.Harmony.PatchAll (System.Type type) [0x002a5] in <b82efbe2c5b74e3c987a02289921fc46>:0 
  at HarmonyLib.Harmony.CreateAndPatchAll (System.Type type, System.String harmonyInstanceId) [0x0001e] in <b82efbe2c5b74e3c987a02289921fc46>:0 
  at BepInEx.OptimizeIMGUI.Awake () [0x0000b] in <a11d3c6d58be4fbb980eaf2e50544d56>:0 
UnityEngine.GameObject:Internal_AddComponentWithType(GameObject, Type)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
UnityEngine.Application:.cctor()

This plugin doesn't work in all games, this looks to be one of them. Simply remove it, it's most likely not necessary.