BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
206 stars 66 forks source link

Unable to patch Constructor #87

Open krulci opened 1 year ago

krulci commented 1 year ago
using HarmonyLib;
using System;

namespace _Elements
{
    [HarmonyPatch(typeof(Elements.BaseReceiveParam), MethodType.Constructor, new Type[] { typeof(LitJson.JsonData) })]
    public class _BaseReceiveParam
    {        
        [HarmonyPostfix]
        public static void BaseReceiveParam()
        {
            int stage = 0;
            Console.WriteLine("test");
        }
    }
}
[Warning:Il2CppInterop] Failed to init IL2CPP patch backend for void Elements.BaseReceiveParam::.ctor(LitJson.JsonData _json), using normal patch handlers: Derived classes must provide an implementation.
[Info   :  HarmonyX] Patching void Elements.BaseReceiveParam::.ctor(LitJson.JsonData _json) with 0 prefixes, 1 postfixes, 0 transpilers, 0 finalizers
1 postfixes:
* static void _Elements._BaseReceiveParam::BaseReceiveParam()

[Info   :  HarmonyX] Running ILHook manipulator on void Elements.BaseReceiveParam::.ctor(LitJson.JsonData _json)
[Info   :  HarmonyX] Writing postfixes
[Debug  :  HarmonyX] Generated patch (System.Void DMD<Elements.BaseReceiveParam::.ctor>?48268995::Elements.BaseReceiveParam::.ctor(Elements.BaseReceiveParam,LitJson.JsonData)):
.locals init (
    System.IntPtr V_0
    System.IntPtr* V_1
    System.IntPtr V_2
    System.Boolean V_3
)
IL_0000: ldarg.0
IL_0001: ldsfld System.IntPtr Il2CppInterop.Runtime.Il2CppClassPointerStore`1<Elements.BaseReceiveParam>::NativeClassPtr
IL_0006: call System.IntPtr Il2CppInterop.Runtime.IL2CPP::il2cpp_object_new(System.IntPtr)
IL_000b: call System.Void Elements.BaseReceiveParam::.ctor(System.IntPtr)
IL_0010: ldc.i4.1
IL_0011: conv.u
IL_0012: sizeof System.IntPtr
IL_0018: mul.ovf.un
IL_0019: localloc
IL_001b: stloc V_1
IL_001f: ldloc V_1
IL_0023: ldarg _json
IL_0027: call System.IntPtr Il2CppInterop.Runtime.IL2CPP::Il2CppObjectBaseToPtr(Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase)
IL_002c: stind.i
IL_002d: ldsfld System.IntPtr Elements.BaseReceiveParam::NativeMethodInfoPtr__ctor_Public_Void_JsonData_0
IL_0032: ldarg this
IL_0036: call System.IntPtr Il2CppInterop.Runtime.IL2CPP::Il2CppObjectBaseToPtrNotNull(Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase)
IL_003b: ldloc V_1
IL_003f: ldloca V_0
IL_0043: call System.IntPtr Il2CppInterop.Runtime.IL2CPP::il2cpp_runtime_invoke(System.IntPtr,System.IntPtr,System.Void**,System.IntPtr&)
IL_0048: stloc V_2
IL_004c: ldloc V_0
IL_0050: call System.Void Il2CppInterop.Runtime.Il2CppException::RaiseExceptionIfNecessary(System.IntPtr)
IL_0055: br IL_005a
IL_005a: ldc.i4.1
IL_005b: stloc V_3
IL_005f: call System.Void _Elements._BaseReceiveParam::BaseReceiveParam()
IL_0064: ret
ds5678 commented 3 months ago

It would be helpful if you attached a debugger and set a break point in Il2CppDetourMethodPatcher.Init(). I'd like to see the stack trace on that exception.