From 7a54a77946cece2ea2a1c76198d5a7b36d5605b5 Mon Sep 17 00:00:00 2001 From: ghorsington Date: Sat, 14 May 2022 23:36:26 +0300 Subject: [PATCH] BepInEx.IL2CPP: Remove old MonoExtensions --- BepInEx.IL2CPP/Hook/FastNativeDetour.cs | 7 ++----- BepInEx.IL2CPP/IL2CPPChainloader.cs | 3 +-- BepInEx.IL2CPP/MonoExtensions.cs | 21 --------------------- 3 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 BepInEx.IL2CPP/MonoExtensions.cs diff --git a/BepInEx.IL2CPP/Hook/FastNativeDetour.cs b/BepInEx.IL2CPP/Hook/FastNativeDetour.cs index 3edcc0d..b2ba35b 100644 --- a/BepInEx.IL2CPP/Hook/FastNativeDetour.cs +++ b/BepInEx.IL2CPP/Hook/FastNativeDetour.cs @@ -163,12 +163,9 @@ public class FastNativeDetour : IDetour public static FastNativeDetour CreateAndApply(IntPtr from, T to, - out T original, - CallingConvention? callingConvention = null) where T : Delegate + out T original) where T : Delegate { - var toPtr = callingConvention != null - ? MonoExtensions.GetFunctionPointerForDelegate(to, callingConvention.Value) - : Marshal.GetFunctionPointerForDelegate(to); + var toPtr = Marshal.GetFunctionPointerForDelegate(to); var result = new FastNativeDetour(from, toPtr); original = result.GenerateTrampoline(); result.Apply(); diff --git a/BepInEx.IL2CPP/IL2CPPChainloader.cs b/BepInEx.IL2CPP/IL2CPPChainloader.cs index 6529dc1..cbf80c1 100644 --- a/BepInEx.IL2CPP/IL2CPPChainloader.cs +++ b/BepInEx.IL2CPP/IL2CPPChainloader.cs @@ -77,8 +77,7 @@ public class IL2CPPChainloader : BaseChainloader gameAssemblyModule.BaseAddress.TryGetFunction("il2cpp_runtime_invoke", out var runtimeInvokePtr); PreloaderLogger.Log.Log(LogLevel.Debug, $"Runtime invoke pointer: 0x{runtimeInvokePtr.ToInt64():X}"); RuntimeInvokeDetour = - FastNativeDetour.CreateAndApply(runtimeInvokePtr, OnInvokeMethod, out originalInvoke, - CallingConvention.Cdecl); + FastNativeDetour.CreateAndApply(runtimeInvokePtr, OnInvokeMethod, out originalInvoke); PreloaderLogger.Log.Log(LogLevel.Debug, "Runtime invoke patched"); } diff --git a/BepInEx.IL2CPP/MonoExtensions.cs b/BepInEx.IL2CPP/MonoExtensions.cs deleted file mode 100644 index 69ba35d..0000000 --- a/BepInEx.IL2CPP/MonoExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace BepInEx; - -/// -/// Contains unofficial extensions to the underlying Mono runtime. -/// -public static class MonoExtensions -{ - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern IntPtr GetFunctionPointerForDelegateInternal2(Delegate d, CallingConvention conv); - - public static IntPtr GetFunctionPointerForDelegate(Delegate d, CallingConvention conv) - { - if (d == null) throw new ArgumentNullException(nameof(d)); - - return GetFunctionPointerForDelegateInternal2(d, conv); - } -}