From b2662fb8a5ffb9473bbf693dbfb4e1a0859eb2f2 Mon Sep 17 00:00:00 2001 From: Bepis <36346617+bbepis@users.noreply.github.com> Date: Thu, 17 Sep 2020 02:19:27 +1000 Subject: [PATCH] Implement IL2CPP support in HarmonyX --- BepInEx.Core/BepInEx.Core.csproj | 22 +- BepInEx.Core/packages.config | 4 - BepInEx.IL2CPP/BepInEx.IL2CPP.csproj | 42 +-- BepInEx.IL2CPP/Hook/DetourGenerator.cs | 22 ++ .../Hook/IL2CPPDetourMethodPatcher.cs | 337 ++++++++++++++++++ BepInEx.IL2CPP/IL2CPPChainloader.cs | 69 ++-- BepInEx.IL2CPP/MonoExtensions.cs | 1 + BepInEx.IL2CPP/Preloader.cs | 4 - BepInEx.IL2CPP/packages.config | 7 - .../BepInEx.NetLauncher.csproj | 32 +- .../RuntimeFixes/AssemblyFix.cs | 3 +- BepInEx.NetLauncher/packages.config | 7 - .../BepInEx.Preloader.Core.csproj | 6 +- .../BepInEx.Preloader.Unity.csproj | 33 +- .../RuntimeFixes/UnityPatches.cs | 5 +- BepInEx.Preloader.Unity/packages.config | 7 - BepInEx.Unity/BepInEx.Unity.csproj | 16 +- BepInEx.Unity/packages.config | 7 - BepInEx.sln | 13 - submodules/BepInEx.Harmony | 1 - 20 files changed, 427 insertions(+), 211 deletions(-) delete mode 100644 BepInEx.Core/packages.config create mode 100644 BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs delete mode 100644 BepInEx.IL2CPP/packages.config delete mode 100644 BepInEx.NetLauncher/packages.config delete mode 100644 BepInEx.Preloader.Unity/packages.config delete mode 100644 BepInEx.Unity/packages.config delete mode 160000 submodules/BepInEx.Harmony diff --git a/BepInEx.Core/BepInEx.Core.csproj b/BepInEx.Core/BepInEx.Core.csproj index 0990484..7755933 100644 --- a/BepInEx.Core/BepInEx.Core.csproj +++ b/BepInEx.Core/BepInEx.Core.csproj @@ -39,18 +39,6 @@ true - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Mdb.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Pdb.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Rocks.dll - @@ -91,13 +79,9 @@ - - {54161cfe-ff42-4dde-b161-3a49545db5cd} - BepInEx.Harmony - - - - + + 0.10.4 + \ No newline at end of file diff --git a/BepInEx.Core/packages.config b/BepInEx.Core/packages.config deleted file mode 100644 index 791f6c3..0000000 --- a/BepInEx.Core/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/BepInEx.IL2CPP/BepInEx.IL2CPP.csproj b/BepInEx.IL2CPP/BepInEx.IL2CPP.csproj index a645db1..0117d84 100644 --- a/BepInEx.IL2CPP/BepInEx.IL2CPP.csproj +++ b/BepInEx.IL2CPP/BepInEx.IL2CPP.csproj @@ -25,40 +25,20 @@ true - pdbonly + portable true ..\bin\il2cpp\ TRACE prompt 4 true + true - - ..\packages\Iced.1.6.0\lib\net45\Iced.dll - ..\lib\Il2Cppmscorlib.dll False - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Mdb.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Pdb.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Rocks.dll - - - ..\packages\MonoMod.RuntimeDetour.20.5.21.5\lib\net40\MonoMod.RuntimeDetour.dll - - - ..\packages\MonoMod.Utils.20.5.21.5\lib\net40\MonoMod.Utils.dll - @@ -80,6 +60,7 @@ + @@ -96,15 +77,20 @@ {15f8bc38-a761-4f93-8903-1b531ac5d9f9} BepInEx.Preloader.Core - - {54161cfe-ff42-4dde-b161-3a49545db5cd} - BepInEx.Harmony - - - + + + 2.1.0-beta + + + 1.6.0 + + + 20.5.21.5 + + \ No newline at end of file diff --git a/BepInEx.IL2CPP/Hook/DetourGenerator.cs b/BepInEx.IL2CPP/Hook/DetourGenerator.cs index 08056d6..78cdcf5 100644 --- a/BepInEx.IL2CPP/Hook/DetourGenerator.cs +++ b/BepInEx.IL2CPP/Hook/DetourGenerator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using BepInEx.Logging; using Iced.Intel; +using MonoMod.RuntimeDetour; namespace BepInEx.IL2CPP { @@ -58,6 +59,27 @@ namespace BepInEx.IL2CPP Marshal.WriteByte(functionPtr + i, 0x90); } + public static IntPtr CreateTrampolineFromFunction(IntPtr originalFuncPointer, out int trampolineLength, out int jmpLength) + { + byte[] instructionBuffer = new byte[32]; + Marshal.Copy(originalFuncPointer, instructionBuffer, 0, 32); + + var trampolinePtr = DetourHelper.Native.MemAlloc(80); + + DetourHelper.Native.MakeWritable(trampolinePtr, 80); + + var arch = IntPtr.Size == 8 ? Architecture.X64 : Architecture.X86; + + int minimumTrampolineLength = GetDetourLength(arch); + + CreateTrampolineFromFunction(instructionBuffer, originalFuncPointer, trampolinePtr, minimumTrampolineLength, arch, out trampolineLength, out jmpLength); + + DetourHelper.Native.MakeExecutable(originalFuncPointer, 32); + DetourHelper.Native.MakeExecutable(trampolinePtr, (uint)trampolineLength); + + return trampolinePtr; + } + /// /// Reads assembly from (at least bytes), and writes it to plus a jmp to continue execution. /// diff --git a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs new file mode 100644 index 0000000..61319c5 --- /dev/null +++ b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs @@ -0,0 +1,337 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.InteropServices; +using BepInEx.Logging; +using HarmonyLib; +using HarmonyLib.Public.Patching; +using MonoMod.Cil; +using MonoMod.RuntimeDetour; +using MonoMod.Utils; +using UnhollowerBaseLib; +using UnhollowerBaseLib.Runtime; + +namespace BepInEx.IL2CPP.Hook +{ + public unsafe class IL2CPPDetourMethodPatcher : MethodPatcher + { + private static readonly MethodInfo IL2CPPToManagedStringMethodInfo + = AccessTools.Method(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.Il2CppStringToManaged)); + + private static readonly MethodInfo ManagedToIL2CPPStringMethodInfo + = AccessTools.Method(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.ManagedStringToIl2Cpp)); + + private static readonly MethodInfo ObjectBaseToPtrMethodInfo + = AccessTools.Method(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.Il2CppObjectBaseToPtr)); + + + private static readonly ManualLogSource DetourLogger = Logger.CreateLogSource("Detour"); + + private FastNativeDetour nativeDetour; + + private Il2CppMethodInfo* originalNativeMethodInfo; + private Il2CppMethodInfo* modifiedNativeMethodInfo; + + /// + /// Constructs a new instance of method patcher. + /// + /// + public IL2CPPDetourMethodPatcher(MethodBase original) : base(original) + { + Init(); + } + + private void Init() + { + // Get the native MethodInfo struct for the target method + + originalNativeMethodInfo = (Il2CppMethodInfo*) + (IntPtr)UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(Original).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()); + Marshal.StructureToPtr(*originalNativeMethodInfo, (IntPtr)modifiedNativeMethodInfo, false); + + modifiedNativeMethodInfo->methodPointer = trampolinePtr; + } + + /// + public override DynamicMethodDefinition PrepareOriginal() + { + return null; + } + + /// + public override MethodBase DetourTo(MethodBase replacement) + { + // Unpatch an existing detour if it exists + + nativeDetour?.Dispose(); + + // Generate a new DMD of the modified unhollowed method, and apply harmony patches to it + + var copiedDmd = CopyOriginal(); + + HarmonyManipulator.Manipulate(copiedDmd.OriginalMethod, copiedDmd.OriginalMethod.GetPatchInfo(), new ILContext(copiedDmd.Definition)); + + + // Generate the MethodInfo instances + + var managedHookedMethod = copiedDmd.Generate(); + var unmanagedTrampolineMethod = GenerateNativeToManagedTrampoline(managedHookedMethod).Generate(); + + + // Apply a detour from the unmanaged implementation to the patched harmony method + + var unmanagedDelegateType = DelegateTypeFactory.instance.CreateDelegateType(unmanagedTrampolineMethod.ReturnType, + unmanagedTrampolineMethod.GetParameters().Select(x => x.ParameterType).ToArray()); + + + var detourPtr = MonoExtensions.GetFunctionPointerForDelegate(unmanagedTrampolineMethod.CreateDelegate(unmanagedDelegateType), + CallingConvention.Cdecl); + + nativeDetour = new FastNativeDetour(originalNativeMethodInfo->methodPointer, detourPtr); + + nativeDetour.Apply(); + + // TODO: Add an ILHook for the original unhollowed method to go directly to managedHookedMethod + // Right now it goes through three times as much interop conversion as it needs to, when being called from managed side + + return managedHookedMethod; + } + + /// + public override DynamicMethodDefinition CopyOriginal() + { + var dmd = new DynamicMethodDefinition(Original); + dmd.Definition.Name = "UnhollowedWrapper_" + dmd.Definition.Name; + + var cursor = new ILCursor(new ILContext(dmd.Definition)); + + + // Remove il2cpp_object_get_virtual_method + + bool foundVirtMethodCall = false; + + if (cursor.TryGotoNext(x => x.MatchLdarg(0), + x => x.MatchCall(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.Il2CppObjectBaseToPtr)), + x => x.MatchLdsfld(out _), + x => x.MatchCall(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.il2cpp_object_get_virtual_method)))) + { + cursor.RemoveRange(4); + + foundVirtMethodCall = true; + } + + // Replace original IL2CPPMethodInfo pointer with a modified one that points to the trampoline + + if (!foundVirtMethodCall) + { + cursor.Goto(0) + .GotoNext(x => x.MatchLdsfld(UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(Original))) + .Remove(); + } + + cursor + .Emit(Mono.Cecil.Cil.OpCodes.Ldc_I8, ((IntPtr)modifiedNativeMethodInfo).ToInt64()) + .Emit(Mono.Cecil.Cil.OpCodes.Conv_I); + + return dmd; + } + + /// + /// A handler for that checks if a method doesn't have a body + /// (e.g. it's icall or marked with ) and thus can be patched with + /// . + /// + /// Not used + /// Patch resolver arguments + /// + public static void TryResolve(object sender, PatchManager.PatcherResolverEventArgs args) + { + if (args.Original.DeclaringType?.IsSubclassOf(typeof(Il2CppObjectBase)) == true) + args.MethodPatcher = new IL2CPPDetourMethodPatcher(args.Original); + } + + private DynamicMethodDefinition GenerateNativeToManagedTrampoline(MethodInfo targetManagedMethodInfo) + { + // managedParams are the unhollower types used on the managed side + // unmanagedParams are IntPtr references that are used by IL2CPP compiled assembly + + var managedParams = targetManagedMethodInfo.GetParameters().Select(x => x.ParameterType).ToArray(); + var unmanagedParams = managedParams.Select(ConvertManagedTypeToIL2CPPType).ToArray(); + + var managedReturnType = AccessTools.GetReturnedType(targetManagedMethodInfo); + var unmanagedReturnType = ConvertManagedTypeToIL2CPPType(managedReturnType); + + var dmd = new DynamicMethodDefinition("(il2cpp -> managed) " + targetManagedMethodInfo.Name, + unmanagedReturnType, + unmanagedParams + ); + + var il = dmd.GetILGenerator(); + + il.BeginExceptionBlock(); + + + // Declare a list of variables to dereference back to the original pointers. + // This is required due to the needed unhollower type conversions, so we can't directly pass some addresses as byref types + + LocalBuilder[] indirectVariables = new LocalBuilder[managedParams.Length]; + + for (int i = 0; i < managedParams.Length; ++i) + { + il.Emit(OpCodes.Ldarg_S, i); + EmitConvertArgumentToManaged(il, managedParams[i], out indirectVariables[i]); + } + + // Run the managed method + + il.Emit(OpCodes.Call, targetManagedMethodInfo); + + + // Store the managed return type temporarily (if there was one) + + LocalBuilder managedReturnVariable = null; + + if (managedReturnType != typeof(void)) + { + managedReturnVariable = il.DeclareLocal(managedReturnType); + il.Emit(OpCodes.Stloc, managedReturnVariable); + } + + + // Convert any managed byref values into their relevant IL2CPP types, and then store the values into their relevant dereferenced pointers + + for (int i = 0; i < managedParams.Length; ++i) + { + if (indirectVariables[i] == null) + continue; + + il.Emit(OpCodes.Ldarg_S, i); + il.Emit(OpCodes.Ldloc, indirectVariables[i]); + + EmitConvertManagedTypeToIL2CPP(il, managedParams[i].GetElementType()); + + il.Emit(OpCodes.Stind_I); + } + + // Handle any lingering exceptions + + il.BeginCatchBlock(typeof(Exception)); + + il.Emit(OpCodes.Call, AccessTools.Method(typeof(IL2CPPDetourMethodPatcher), nameof(ReportException))); + + il.EndExceptionBlock(); + + // Convert the return value back to an IL2CPP friendly type (if there was a return value), and then return + + if (managedReturnVariable != null) + { + il.Emit(OpCodes.Ldloc, managedReturnVariable); + EmitConvertManagedTypeToIL2CPP(il, managedReturnType); + } + + il.Emit(OpCodes.Ret); + + return dmd; + } + + private static void ReportException(Exception ex) + { + DetourLogger.LogError(ex.ToString()); + } + + private static Type ConvertManagedTypeToIL2CPPType(Type managedType) + { + if (managedType.IsByRef) + { + Type directType = managedType.GetElementType(); + if (directType == typeof(string) || directType.IsSubclassOf(typeof(Il2CppObjectBase))) + { + return typeof(IntPtr*); + } + } + else if (managedType == typeof(string) || managedType.IsSubclassOf(typeof(Il2CppObjectBase))) + { + return typeof(IntPtr); + } + + return managedType; + } + + private static void EmitConvertManagedTypeToIL2CPP(ILGenerator il, Type returnType) + { + if (returnType == typeof(string)) + { + il.Emit(OpCodes.Call, ManagedToIL2CPPStringMethodInfo); + } + else if (!returnType.IsValueType && returnType.IsSubclassOf(typeof(Il2CppObjectBase))) + { + il.Emit(OpCodes.Call, ObjectBaseToPtrMethodInfo); + } + } + + private static void EmitConvertArgumentToManaged(ILGenerator il, Type managedParamType, out LocalBuilder variable) + { + variable = null; + + if (managedParamType.IsValueType) // don't need to convert blittable types + return; + + void EmitCreateIl2CppObject() + { + Label endLabel = il.DefineLabel(); + Label notNullLabel = il.DefineLabel(); + + il.Emit(OpCodes.Dup); + il.Emit(OpCodes.Brtrue_S, notNullLabel); + + il.Emit(OpCodes.Pop); + il.Emit(OpCodes.Ldnull); + il.Emit(OpCodes.Br_S, endLabel); + + il.MarkLabel(notNullLabel); + il.Emit(OpCodes.Newobj, AccessTools.DeclaredConstructor(managedParamType, new[] { typeof(IntPtr) })); + + il.MarkLabel(endLabel); + } + + void HandleTypeConversion(Type originalType) + { + if (originalType == typeof(string)) + { + il.Emit(OpCodes.Call, IL2CPPToManagedStringMethodInfo); + } + else if (originalType.IsSubclassOf(typeof(Il2CppObjectBase))) + { + EmitCreateIl2CppObject(); + } + } + + if (managedParamType.IsByRef) + { + Type directType = managedParamType.GetElementType(); + + variable = il.DeclareLocal(directType); + + il.Emit(OpCodes.Ldind_I); + + HandleTypeConversion(directType); + + il.Emit(OpCodes.Stloc, variable); + il.Emit(OpCodes.Ldloca, variable); + } + else + { + HandleTypeConversion(managedParamType); + } + } + } +} \ No newline at end of file diff --git a/BepInEx.IL2CPP/IL2CPPChainloader.cs b/BepInEx.IL2CPP/IL2CPPChainloader.cs index 81876d0..1c73e02 100644 --- a/BepInEx.IL2CPP/IL2CPPChainloader.cs +++ b/BepInEx.IL2CPP/IL2CPPChainloader.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; @@ -9,10 +8,12 @@ using BepInEx.IL2CPP.Hook; using BepInEx.Logging; using BepInEx.Preloader.Core; using BepInEx.Preloader.Core.Logging; +using HarmonyLib.Public.Patching; using UnhollowerBaseLib.Runtime; using UnhollowerRuntimeLib; using UnityEngine; using Logger = BepInEx.Logging.Logger; +using BaseUnityEngine = UnityEngine; namespace BepInEx.IL2CPP { @@ -25,30 +26,32 @@ namespace BepInEx.IL2CPP UnityLogSource.LogInfo(logLine.Trim()); } - -// public const CallingConvention ArchConvention = -//#if X64 -// CallingConvention.Stdcall; -//#else -// CallingConvention.Cdecl; -//#endif - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate IntPtr RuntimeInvokeDetour(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate IntPtr RuntimeInvokeDetourDelegate(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc); [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); - private static RuntimeInvokeDetour originalInvoke; + private static RuntimeInvokeDetourDelegate originalInvoke; private static readonly ManualLogSource unhollowerLogSource = Logger.CreateLogSource("Unhollower"); + private static FastNativeDetour RuntimeInvokeDetour { get; set; } + + private static IL2CPPChainloader Instance { get; set; } + public override unsafe void Initialize(string gameExePath = null) { - base.Initialize(gameExePath); + PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve; - UnityVersionHandler.Initialize(2019, 2, 17); + base.Initialize(gameExePath); + Instance = this; + + var version = //Version.Parse(Application.unityVersion); + Version.Parse(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion); + + UnityVersionHandler.Initialize(version.Major, version.Minor, version.Revision); // One or the other here for Unhollower to work correctly @@ -72,54 +75,49 @@ namespace BepInEx.IL2CPP PreloaderLogger.Log.LogDebug($"Runtime invoke pointer: 0x{functionPtr.ToInt64():X}"); - var invokeDetour = new FastNativeDetour(functionPtr, Marshal.GetFunctionPointerForDelegate(new RuntimeInvokeDetour(OnInvokeMethod))); + RuntimeInvokeDetour = new FastNativeDetour(functionPtr, + MonoExtensions.GetFunctionPointerForDelegate(new RuntimeInvokeDetourDelegate(OnInvokeMethod), CallingConvention.Cdecl)); - invokeDetour.Apply(unhollowerLogSource); + RuntimeInvokeDetour.Apply(); - originalInvoke = invokeDetour.GenerateTrampoline(); + originalInvoke = RuntimeInvokeDetour.GenerateTrampoline(); + + PreloaderLogger.Log.LogDebug("Runtime invoke patched"); } - private static bool HasSet = false; - private static HashSet recordedNames = new HashSet(); private static IntPtr OnInvokeMethod(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc) { string methodName = Marshal.PtrToStringAnsi(UnhollowerBaseLib.IL2CPP.il2cpp_method_get_name(method)); - IntPtr methodClass = UnhollowerBaseLib.IL2CPP.il2cpp_method_get_class(method); - string methodClassName = Marshal.PtrToStringAnsi(UnhollowerBaseLib.IL2CPP.il2cpp_class_get_name(methodClass)); - string methodClassNamespace = Marshal.PtrToStringAnsi(UnhollowerBaseLib.IL2CPP.il2cpp_class_get_namespace(methodClass)); - string methodFullName = $"{methodClassNamespace}.{methodClassName}::{methodName}"; + bool unhook = false; - if (!HasSet && methodName == "Internal_ActiveSceneChanged") + if (methodName == "Internal_ActiveSceneChanged") { try { - Application.s_LogCallbackHandler = new Action(UnityLogCallback); + //Application.s_LogCallbackHandler = new Action(UnityLogCallback); - UnityLogSource.LogMessage($"callback set - {methodName}"); + //Application.CallLogCallback("test from OnInvokeMethod", "", LogType.Log, true); - Application.CallLogCallback("test from OnInvokeMethod", "", LogType.Log, true); + unhook = true; + + Instance.Execute(); } catch (Exception ex) { UnityLogSource.LogError(ex); } - - HasSet = true; } var result = originalInvoke(method, obj, parameters, exc); - //UnityLogSource.LogDebug(methodName + " => " + result.ToString("X")); - - if (!recordedNames.Contains(methodFullName)) + if (unhook) { - UnityLogSource.LogDebug(methodFullName + " => " + result.ToString("X")); + RuntimeInvokeDetour.Dispose(); - lock (recordedNames) - recordedNames.Add(methodFullName); + PreloaderLogger.Log.LogDebug("Runtime invoke unpatched"); } return result; @@ -135,7 +133,6 @@ namespace BepInEx.IL2CPP Logger.Sources.Add(UnityLogSource); - UnhollowerBaseLib.LogSupport.InfoHandler += unhollowerLogSource.LogInfo; UnhollowerBaseLib.LogSupport.WarningHandler += unhollowerLogSource.LogWarning; UnhollowerBaseLib.LogSupport.TraceHandler += unhollowerLogSource.LogDebug; diff --git a/BepInEx.IL2CPP/MonoExtensions.cs b/BepInEx.IL2CPP/MonoExtensions.cs index a590f01..d068e6f 100644 --- a/BepInEx.IL2CPP/MonoExtensions.cs +++ b/BepInEx.IL2CPP/MonoExtensions.cs @@ -18,6 +18,7 @@ namespace BepInEx { throw new ArgumentNullException("d"); } + return GetFunctionPointerForDelegateInternal2(d, conv); } } diff --git a/BepInEx.IL2CPP/Preloader.cs b/BepInEx.IL2CPP/Preloader.cs index 6ac1d42..f7ecf3d 100644 --- a/BepInEx.IL2CPP/Preloader.cs +++ b/BepInEx.IL2CPP/Preloader.cs @@ -30,8 +30,6 @@ namespace BepInEx.IL2CPP Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}"); - //Log.LogInfo($"CLR runtime version: {Environment.Version}"); - //Log.LogInfo($"Supports SRE: {Utility.CLRSupportsDynamicAssemblies}"); Log.LogDebug($"Game executable path: {Paths.ExecutablePath}"); Log.LogDebug($"Unhollowed assembly directory: {IL2CPPUnhollowedPath}"); @@ -43,8 +41,6 @@ namespace BepInEx.IL2CPP Chainloader = new IL2CPPChainloader(); Chainloader.Initialize(); - - Chainloader.Execute(); } catch (Exception ex) { diff --git a/BepInEx.IL2CPP/packages.config b/BepInEx.IL2CPP/packages.config deleted file mode 100644 index 64bafbf..0000000 --- a/BepInEx.IL2CPP/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/BepInEx.NetLauncher/BepInEx.NetLauncher.csproj b/BepInEx.NetLauncher/BepInEx.NetLauncher.csproj index 26bb3c3..e42dbc0 100644 --- a/BepInEx.NetLauncher/BepInEx.NetLauncher.csproj +++ b/BepInEx.NetLauncher/BepInEx.NetLauncher.csproj @@ -37,27 +37,6 @@ - - ..\packages\HarmonyX.2.0.6\lib\net40\0Harmony.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Mdb.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Pdb.dll - - - ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Rocks.dll - - - ..\packages\MonoMod.RuntimeDetour.20.5.21.5\lib\net40\MonoMod.RuntimeDetour.dll - - - ..\packages\MonoMod.Utils.20.5.21.5\lib\net40\MonoMod.Utils.dll - @@ -72,7 +51,6 @@ - @@ -83,11 +61,11 @@ {15f8bc38-a761-4f93-8903-1b531ac5d9f9} BepInEx.Preloader.Core - - {54161cfe-ff42-4dde-b161-3a49545db5cd} - BepInEx.Harmony - - + + + 2.1.0-beta + + \ No newline at end of file diff --git a/BepInEx.NetLauncher/RuntimeFixes/AssemblyFix.cs b/BepInEx.NetLauncher/RuntimeFixes/AssemblyFix.cs index 0b45250..5da672c 100644 --- a/BepInEx.NetLauncher/RuntimeFixes/AssemblyFix.cs +++ b/BepInEx.NetLauncher/RuntimeFixes/AssemblyFix.cs @@ -1,5 +1,4 @@ using System.Reflection; -using BepInEx.Harmony; using HarmonyLib; namespace BepInEx.NetLauncher.RuntimeFixes @@ -11,7 +10,7 @@ namespace BepInEx.NetLauncher.RuntimeFixes public static void Execute(Assembly entryAssembly) { EntryAssembly = entryAssembly; - HarmonyWrapper.PatchAll(typeof(AssemblyFix), "bepinex.assemblyfix"); + Harmony.CreateAndPatchAll(typeof(AssemblyFix), "bepinex.assemblyfix"); } [HarmonyPrefix, HarmonyPatch(typeof(Assembly), nameof(Assembly.GetEntryAssembly))] diff --git a/BepInEx.NetLauncher/packages.config b/BepInEx.NetLauncher/packages.config deleted file mode 100644 index cc87aeb..0000000 --- a/BepInEx.NetLauncher/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/BepInEx.Preloader.Core/BepInEx.Preloader.Core.csproj b/BepInEx.Preloader.Core/BepInEx.Preloader.Core.csproj index c1911b5..75be41f 100644 --- a/BepInEx.Preloader.Core/BepInEx.Preloader.Core.csproj +++ b/BepInEx.Preloader.Core/BepInEx.Preloader.Core.csproj @@ -49,14 +49,10 @@ {4ffba620-f5ed-47f9-b90c-dad1316fd9b9} BepInEx.Core - - {54161cfe-ff42-4dde-b161-3a49545db5cd} - BepInEx.Harmony - - 2.0.6 + 2.1.0-beta 0.10.4 diff --git a/BepInEx.Preloader.Unity/BepInEx.Preloader.Unity.csproj b/BepInEx.Preloader.Unity/BepInEx.Preloader.Unity.csproj index 19d0d7d..7284654 100644 --- a/BepInEx.Preloader.Unity/BepInEx.Preloader.Unity.csproj +++ b/BepInEx.Preloader.Unity/BepInEx.Preloader.Unity.csproj @@ -32,27 +32,6 @@ ..\bin\BepInEx.Preloader.Unity.xml - - ..\packages\HarmonyX.2.0.6\lib\net35\0Harmony.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Mdb.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Pdb.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Rocks.dll - - - ..\packages\MonoMod.RuntimeDetour.20.5.21.5\lib\net35\MonoMod.RuntimeDetour.dll - - - ..\packages\MonoMod.Utils.20.5.21.5\lib\net35\MonoMod.Utils.dll - @@ -64,9 +43,6 @@ - - - {4ffba620-f5ed-47f9-b90c-dad1316fd9b9} @@ -76,10 +52,11 @@ {15f8bc38-a761-4f93-8903-1b531ac5d9f9} BepInEx.Preloader.Core - - {54161cfe-ff42-4dde-b161-3a49545db5cd} - BepInEx.Harmony - + + + + 2.1.0-beta + \ No newline at end of file diff --git a/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs b/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs index 4f26828..f34289b 100644 --- a/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs +++ b/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using BepInEx.Harmony; using HarmonyLib; namespace BepInEx.Preloader.RuntimeFixes @@ -14,8 +13,8 @@ namespace BepInEx.Preloader.RuntimeFixes public static void Apply() { - HarmonyInstance = HarmonyWrapper.PatchAll(typeof(UnityPatches)); - + HarmonyInstance = Harmony.CreateAndPatchAll(typeof(UnityPatches)); + try { TraceFix.ApplyFix(); diff --git a/BepInEx.Preloader.Unity/packages.config b/BepInEx.Preloader.Unity/packages.config deleted file mode 100644 index a680a92..0000000 --- a/BepInEx.Preloader.Unity/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/BepInEx.Unity/BepInEx.Unity.csproj b/BepInEx.Unity/BepInEx.Unity.csproj index 8f8f1a1..373cb04 100644 --- a/BepInEx.Unity/BepInEx.Unity.csproj +++ b/BepInEx.Unity/BepInEx.Unity.csproj @@ -32,18 +32,6 @@ ..\bin\BepInEx.Unity.xml - - ..\packages\HarmonyX.2.0.6\lib\net35\0Harmony.dll - - - ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll - - - ..\packages\MonoMod.RuntimeDetour.20.5.21.5\lib\net35\MonoMod.RuntimeDetour.dll - - - ..\packages\MonoMod.Utils.20.5.21.5\lib\net35\MonoMod.Utils.dll - @@ -77,7 +65,9 @@ - + + 2.1.0-beta + \ No newline at end of file diff --git a/BepInEx.Unity/packages.config b/BepInEx.Unity/packages.config deleted file mode 100644 index a680a92..0000000 --- a/BepInEx.Unity/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/BepInEx.sln b/BepInEx.sln index b7430eb..de66106 100644 --- a/BepInEx.sln +++ b/BepInEx.sln @@ -11,10 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Patcher", "BepInEx. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Bootstrap", "BepInEx.Bootstrap\BepInEx.Bootstrap.csproj", "{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Submodules", "Submodules", "{BAC58F7E-AAD8-4D0C-9490-9765ACBBA6FB}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Harmony", "submodules\BepInEx.Harmony\BepInEx.Harmony\BepInEx.Harmony.csproj", "{54161CFE-FF42-4DDE-B161-3A49545DB5CD}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Patcher", "Patcher", "{A9071994-3533-4C1B-89DC-D817B676AB41}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInExTests", "BepInExTests\BepInExTests.csproj", "{E7CD429A-D057-48E3-8C51-E5C934E8E07B}" @@ -60,14 +56,6 @@ Global {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release_Unity|Any CPU.ActiveCfg = Release|Any CPU {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|Any CPU.Build.0 = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release_NetFramework|Any CPU.ActiveCfg = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release_NetFramework|Any CPU.Build.0 = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release_Unity|Any CPU.ActiveCfg = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release_Unity|Any CPU.Build.0 = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {54161CFE-FF42-4DDE-B161-3A49545DB5CD}.Release|Any CPU.Build.0 = Release|Any CPU {E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Debug|Any CPU.ActiveCfg = Debug|x86 {E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Debug|Any CPU.Build.0 = Debug|x86 {E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Release_NetFramework|Any CPU.ActiveCfg = Release|x86 @@ -125,7 +113,6 @@ Global GlobalSection(NestedProjects) = preSolution {DC89F18B-235B-4C01-AB31-AF40DCE5C4C7} = {A9071994-3533-4C1B-89DC-D817B676AB41} {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB} = {A9071994-3533-4C1B-89DC-D817B676AB41} - {54161CFE-FF42-4DDE-B161-3A49545DB5CD} = {BAC58F7E-AAD8-4D0C-9490-9765ACBBA6FB} {EAE9FAE6-8011-45A3-8B6E-0C7F14210533} = {6E2DD21E-0854-4F4A-B925-D90E0016D03D} {D404C973-441D-48ED-B266-C21320BA0D87} = {6E2DD21E-0854-4F4A-B925-D90E0016D03D} {490B052B-7F23-4052-AD04-613856618901} = {6EC98884-A3DC-4828-85EF-5F10F7519429} diff --git a/submodules/BepInEx.Harmony b/submodules/BepInEx.Harmony deleted file mode 160000 index dae8295..0000000 --- a/submodules/BepInEx.Harmony +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dae82954004248028d38a43e72b42037efca0a80