Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to patch Constructor #87

Open
krulci opened this issue Apr 25, 2023 · 1 comment
Open

Unable to patch Constructor #87

krulci opened this issue Apr 25, 2023 · 1 comment
Labels
harmony Related to method patching

Comments

@krulci
Copy link
Contributor

krulci commented Apr 25, 2023

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 ds5678 added the harmony Related to method patching label Jul 15, 2024
@ds5678
Copy link
Collaborator

ds5678 commented Jul 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
harmony Related to method patching
Projects
None yet
Development

No branches or pull requests

2 participants