pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.15k stars 485 forks source link

Hook exception: System.Exception: Cannot get result from void method System.Void #595

Closed yangboyd closed 6 months ago

yangboyd commented 6 months ago

Windows .Net 4.7 32bit Harmony 2

Hook a constructor, get exception.

hook exception: System.Exception: Cannot get result from void method System.Void loader.ILReader::.ctor(System.Reflection.MethodBase method, System.Byte[] code) 在 HarmonyLib.MethodPatcher.EmitCallParameter(MethodInfo patch, Dictionary2 variables, LocalBuilder runOriginalVariable, Boolean allowFirsParamPassthrough, LocalBuilder& tmpObjectVar, List1 tmpBoxVars) 在 HarmonyLib.MethodPatcher.<>c__DisplayClass35_0.b__0(MethodInfo fix) 在 HarmonyLib.CollectionExtensions.Do[T](IEnumerable1 sequence, Action1 action) 在 HarmonyLib.MethodPatcher.AddPrefixes(Dictionary2 variables, LocalBuilder runOriginalVariable) 在 HarmonyLib.MethodPatcher.CreateReplacement(Dictionary2& finalInstructions) 在 HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo) 在 HarmonyLib.PatchProcessor.Patch() 在 HarmonyLib.Harmony.Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler, HarmonyMethod finalizer)

yangboyd commented 6 months ago

Debug Log:

Patch: System.Void loader.ILReader::.ctor(System.Reflection.MethodBase method, System.Byte[] code)

Replacement: static System.Void loader.ILReader::loader.ILReader..ctor_Patch1(loader.ILReader this, System.Reflection.MethodBase method, System.Byte[] code)

IL_0000: ldc.i4 0 IL_0005: stloc 1 (System.Boolean) IL_0009: ldc.i4.1 IL_000A: stloc 1 (System.Boolean) IL_000E: ldloc 1 (System.Boolean) IL_0012: brfalse => Label1

yangboyd commented 6 months ago

Refer #574 Use AccessTools.GetDeclaredConstructors()