浏览代码

Add config to enable MonoMod's HarmonyDetourBridge

ghorsington 6 年之前
父节点
当前提交
7790807dc3
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      BepInEx.Preloader/Preloader.cs

+ 11 - 2
BepInEx.Preloader/Preloader.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
-using System.Reflection;
 using System.Text;
 using System.Text;
 using BepInEx.Configuration;
 using BepInEx.Configuration;
 using BepInEx.Logging;
 using BepInEx.Logging;
@@ -11,6 +10,7 @@ using BepInEx.Preloader.Patching;
 using BepInEx.Preloader.RuntimeFixes;
 using BepInEx.Preloader.RuntimeFixes;
 using Mono.Cecil;
 using Mono.Cecil;
 using Mono.Cecil.Cil;
 using Mono.Cecil.Cil;
+using MonoMod.RuntimeDetour;
 using UnityInjector.ConsoleUtil;
 using UnityInjector.ConsoleUtil;
 using MethodAttributes = Mono.Cecil.MethodAttributes;
 using MethodAttributes = Mono.Cecil.MethodAttributes;
 
 
@@ -46,6 +46,9 @@ namespace BepInEx.Preloader
 			{
 			{
 				AllocateConsole();
 				AllocateConsole();
 
 
+				if (ConfigShimHarmony.Value)
+					HarmonyDetourBridge.Init();
+
 				if (ConfigApplyRuntimePatches.Value)
 				if (ConfigApplyRuntimePatches.Value)
 					UnityPatches.Apply();
 					UnityPatches.Apply();
 
 
@@ -249,7 +252,13 @@ namespace BepInEx.Preloader
 			"Enables or disables runtime patches.\nThis should always be true, unless you cannot start the game due to a Harmony related issue (such as running .NET Standard runtime) or you know what you're doing.",
 			"Enables or disables runtime patches.\nThis should always be true, unless you cannot start the game due to a Harmony related issue (such as running .NET Standard runtime) or you know what you're doing.",
 			true);
 			true);
 
 
-		private static readonly ConfigWrapper<bool> ConfigPreloaderCOutLogging = ConfigFile.CoreConfig.Wrap(
+		private static readonly ConfigWrapper<bool> ConfigShimHarmony = ConfigFile.CoreConfig.Wrap(
+			"Preloader",
+			"ShimHarmonySupport",
+			"If enabled, basic Harmony functionality is patched to use MonoMod's RuntimeDetour instead.\nTry using this if Harmony does not work in a game.",
+			false);
+
+        private static readonly ConfigWrapper<bool> ConfigPreloaderCOutLogging = ConfigFile.CoreConfig.Wrap(
 			"Logging",
 			"Logging",
 			"PreloaderConsoleOutRedirection",
 			"PreloaderConsoleOutRedirection",
 			"Redirects text from Console.Out during preloader patch loading to the BepInEx logging system.",
 			"Redirects text from Console.Out during preloader patch loading to the BepInEx logging system.",