Browse Source

Add config option for disabling harmony runtime patchers

Bepis 5 years ago
parent
commit
8ed78d9d54

+ 1 - 1
BepInEx.Preloader/Patching/AssemblyPatcher.cs

@@ -176,7 +176,7 @@ namespace BepInEx.Preloader.Patching
 
 		#region Config
 
-		private static ConfigWrapper<bool> ConfigDumpAssemblies = ConfigFile.CoreConfig.Wrap(
+		private static readonly ConfigWrapper<bool> ConfigDumpAssemblies = ConfigFile.CoreConfig.Wrap(
 			"Preloader",
 			"DumpAssemblies",
 			"If enabled, BepInEx will save patched assemblies into BepInEx/DumpedAssemblies.\nThis can be used by developers to inspect and debug preloader patchers.",

+ 44 - 54
BepInEx.Preloader/Preloader.cs

@@ -30,11 +30,10 @@ namespace BepInEx.Preloader
 		{
 			try
 			{
-				InitConfig();
-
 				AllocateConsole();
 
-				UnityPatches.Apply();
+				if (ConfigApplyRuntimePatches.Value)
+					UnityPatches.Apply();
 
 				Logger.Sources.Add(TraceLogSource.CreateSource());
 
@@ -42,7 +41,7 @@ namespace BepInEx.Preloader
 
 				Logger.Listeners.Add(PreloaderLog);
 
-
+				
 				string consoleTile = $"BepInEx {typeof(Paths).Assembly.GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
 
 				ConsoleWindow.Title = consoleTile;
@@ -316,56 +315,47 @@ namespace BepInEx.Preloader
 
 		#region Config
 
-		private static ConfigWrapper<string> ConfigEntrypointAssembly;
-
-		private static ConfigWrapper<string> ConfigEntrypointType;
-
-		private static ConfigWrapper<string> ConfigEntrypointMethod;
-
-		private static ConfigWrapper<bool> ConfigPreloaderCOutLogging;
-
-		private static ConfigWrapper<bool> ConfigConsoleEnabled;
-
-		private static ConfigWrapper<bool> ConfigConsoleShiftJis;
-
-		private static void InitConfig()
-		{
-			ConfigEntrypointAssembly = ConfigFile.CoreConfig.Wrap(
-				"Preloader.Entrypoint",
-				"Assembly",
-				"The local filename of the assembly to target.",
-				"UnityEngine.dll");
-
-			ConfigEntrypointType = ConfigFile.CoreConfig.Wrap(
-				"Preloader.Entrypoint",
-				"Type",
-				"The name of the type in the entrypoint assembly to search for the entrypoint method.",
-				"Application");
-
-			ConfigEntrypointMethod = ConfigFile.CoreConfig.Wrap(
-				"Preloader.Entrypoint",
-				"Method",
-				"The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.",
-				".cctor");
-
-			ConfigPreloaderCOutLogging = ConfigFile.CoreConfig.Wrap(
-				"Logging",
-				"PreloaderConsoleOutRedirection",
-				"Redirects text from Console.Out during preloader patch loading to the BepInEx logging system.",
-				true);
-
-			ConfigConsoleEnabled = ConfigFile.CoreConfig.Wrap(
-				"Logging.Console",
-				"Enabled",
-				"Enables showing a console for log output.",
-				false);
-
-			ConfigConsoleShiftJis = ConfigFile.CoreConfig.Wrap(
-				"Logging.Console",
-				"ShiftJisEncoding",
-				"If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding.",
-				false);
-		}
+		private static readonly ConfigWrapper<string> ConfigEntrypointAssembly = ConfigFile.CoreConfig.Wrap(
+			"Preloader.Entrypoint",
+			"Assembly",
+			"The local filename of the assembly to target.",
+			"UnityEngine.dll");
+
+		private static readonly ConfigWrapper<string> ConfigEntrypointType = ConfigFile.CoreConfig.Wrap(
+			"Preloader.Entrypoint",
+			"Type",
+			"The name of the type in the entrypoint assembly to search for the entrypoint method.",
+			"Application");
+
+		private static readonly ConfigWrapper<string> ConfigEntrypointMethod = ConfigFile.CoreConfig.Wrap(
+			"Preloader.Entrypoint",
+			"Method",
+			"The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.",
+			".cctor");
+
+		private static readonly ConfigWrapper<bool> ConfigApplyRuntimePatches = ConfigFile.CoreConfig.Wrap(
+			"Preloader",
+			"ApplyRuntimePatches",
+			"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);
+
+		private static readonly ConfigWrapper<bool> ConfigPreloaderCOutLogging = ConfigFile.CoreConfig.Wrap(
+			"Logging",
+			"PreloaderConsoleOutRedirection",
+			"Redirects text from Console.Out during preloader patch loading to the BepInEx logging system.",
+			true);
+
+		private static readonly ConfigWrapper<bool> ConfigConsoleEnabled = ConfigFile.CoreConfig.Wrap(
+			"Logging.Console",
+			"Enabled",
+			"Enables showing a console for log output.",
+			false);
+
+		private static readonly ConfigWrapper<bool> ConfigConsoleShiftJis = ConfigFile.CoreConfig.Wrap(
+			"Logging.Console",
+			"ShiftJisEncoding",
+			"If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding.",
+			false);
 
 		#endregion
 	}

+ 1 - 1
BepInEx.Preloader/RuntimeFixes/UnityPatches.cs

@@ -43,7 +43,7 @@ namespace BepInEx.Preloader.RuntimeFixes
 #if UNITY_2018
 /*
  * DESC: Workaround for Trace class not working because of missing .config file
- * AFFECTS: Unity 2018+
+ * AFFECTS: Unity 2018+ (not .NET Standard / MonoBleedingEdge runtimes)
  */
 		[HarmonyPostfix, HarmonyPatch(typeof(AppDomain), nameof(AppDomain.SetupInformation), MethodType.Getter)]
 		public static void GetExeConfigName(AppDomainSetup __result)

+ 2 - 2
BepInEx/Bootstrap/Chainloader.cs

@@ -192,13 +192,13 @@ namespace BepInEx.Bootstrap
 
 		#region Config
 
-		private static ConfigWrapper<string> ConfigPluginsDirectory = ConfigFile.CoreConfig.Wrap(
+		private static readonly ConfigWrapper<string> ConfigPluginsDirectory = ConfigFile.CoreConfig.Wrap(
 				"Paths",
 				"PluginsDirectory",
 				"The relative directory to the BepInEx folder where plugins are loaded.",
 				"plugins");
 
-		private static ConfigWrapper<bool> ConfigUnityLogging = ConfigFile.CoreConfig.Wrap(
+		private static readonly ConfigWrapper<bool> ConfigUnityLogging = ConfigFile.CoreConfig.Wrap(
 				"Logging",
 				"UnityLogListening",
 				"Enables showing unity log messages in the BepInEx logging system.",

+ 1 - 1
BepInEx/Logging/ConsoleLogListener.cs

@@ -25,7 +25,7 @@ namespace BepInEx.Logging
 
 		public void Dispose() { }
 
-		private static ConfigWrapper<string> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
+		private static readonly ConfigWrapper<string> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
 			"Logging.Console",
 			"DisplayedLogLevel",
 			"Only displays the specified log level and above in the console output.",