public void Test() { Type typeA = typeof(PrivateTestA); Type typeB = typeof(PrivateTestB); MethodInfo miAPrivateFunc = typeA.GetMethod("InnerFuncTest", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo miBReplace = typeB.GetMethod("FuncReplace"); MethodInfo miBProxy = typeB.GetMethod("Proxy"); MethodHooker hooker = new MethodHooker(miAPrivateFunc, miBReplace, miBProxy); hooker.Install(); PrivateTestA privateTestA = new PrivateTestA(); privateTestA.FuncTest(); }
public static void Proxy(PrivateTestA a, object innerClass, short innerEnum) { Debug.Log("something"); }
/// <summary> /// 替换函数,参数类型只要"兼容"就可以,兼容的定义是引用类型可以使用任意引用类型替代,值类型保证 size 一致就可以 /// </summary> /// <param name="a"></param> /// <param name="innerClass"></param> /// <param name="innerEnum"></param> public static void FuncReplace(PrivateTestA a, object innerClass, short innerEnum) { Debug.Log("PrivateTestB.FuncReplace called"); innerEnum += 1; Proxy(a, innerClass, innerEnum); }