Exemplo n.º 1
0
        private void Init()
        {
            try
            {
                var methodField = UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(Original);

                if (methodField == null)
                {
                    throw new Exception($"No IL2CPP equivalent found for {Original.FullDescription()}. The target might have been automatically generated by Unhollower (e.g. field accessor).");
                }

                // Get the native MethodInfo struct for the target method
                originalNativeMethodInfo = (Il2CppMethodInfo *)(IntPtr)methodField.GetValue(null);

                // Create a trampoline from the original target method

                var trampolinePtr = DetourGenerator.CreateTrampolineFromFunction(originalNativeMethodInfo->methodPointer, out _, out _);

                // Create a modified native MethodInfo struct to point towards the trampoline

                modifiedNativeMethodInfo = (Il2CppMethodInfo *)Marshal.AllocHGlobal(Marshal.SizeOf <Il2CppMethodInfo>());
                Marshal.StructureToPtr(*originalNativeMethodInfo, (IntPtr)modifiedNativeMethodInfo, false);

                modifiedNativeMethodInfo->methodPointer = trampolinePtr;
                isValid = true;
            }
            catch (Exception e)
            {
                DetourLogger.LogWarning($"Failed to init IL2CPP patch backend for {Original.FullDescription()}, using normal patch handlers: {e.Message}");
            }
        }
Exemplo n.º 2
0
 public INativeMethodInfoStruct Wrap(Il2CppMethodInfo *methodPointer)
 {
     if ((IntPtr)methodPointer == IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new NativeMethodInfoStructWrapper((IntPtr)methodPointer));
     }
 }
 private static IntPtr StaticVoidIntPtrInvoker(IntPtr methodPointer, Il2CppMethodInfo *methodInfo, IntPtr obj, IntPtr *args)
 {
     Marshal.GetDelegateForFunctionPointer <VoidCtorDelegate>(methodPointer)(obj);
     return(IntPtr.Zero);
 }
 public INativeMethodInfoStruct Wrap(Il2CppMethodInfo *methodPointer)
 {
     return(new NativeMethodInfoStructWrapper((IntPtr)methodPointer));
 }