Pārlūkot izejas kodu

Change BepInEx settings to use new wrap overloads

ManlyMarco 5 gadi atpakaļ
vecāks
revīzija
4711b1e5fa

+ 9 - 12
BepInEx.Preloader/Patching/AssemblyPatcher.cs

@@ -278,22 +278,19 @@ namespace BepInEx.Preloader.Patching
 		#region Config
 
 		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.",
-			false);
+			"Preloader", "DumpAssemblies",
+			false,
+			new ConfigDescription("If enabled, BepInEx will save patched assemblies into BepInEx/DumpedAssemblies.\nThis can be used by developers to inspect and debug preloader patchers."));
 
 		private static readonly ConfigWrapper<bool> ConfigLoadDumpedAssemblies = ConfigFile.CoreConfig.Wrap(
-			"Preloader",
-			"LoadDumpedAssemblies",
-			"If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory.\nThis can be used to be able to load patched assemblies into debuggers like dnSpy.\nIf set to true, will override DumpAssemblies.",
-			false);
+			"Preloader", "LoadDumpedAssemblies",
+			false,
+			new ConfigDescription("If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory.\nThis can be used to be able to load patched assemblies into debuggers like dnSpy.\nIf set to true, will override DumpAssemblies."));
 
 		private static readonly ConfigWrapper<bool> ConfigBreakBeforeLoadAssemblies = ConfigFile.CoreConfig.Wrap(
-			"Preloader",
-			"BreakBeforeLoadAssemblies",
-			"If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies.\nThis can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded.",
-			false);
+			"Preloader", "BreakBeforeLoadAssemblies",
+			false,
+			new ConfigDescription("If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies.\nThis can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded."));
 
 		#endregion
 	}

+ 23 - 30
BepInEx.Preloader/Preloader.cs

@@ -234,42 +234,35 @@ namespace BepInEx.Preloader
 
 		#region Config
 
-		private static readonly ConfigWrapper<string> ConfigEntrypointAssembly = ConfigFile.CoreConfig.Wrap(
-			"Preloader.Entrypoint",
-			"Assembly",
-			"The local filename of the assembly to target.",
-			IsPostUnity2017 ? "UnityEngine.CoreModule.dll" : "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<string> ConfigEntrypointAssembly = ConfigFile.CoreConfig.Wrap<string>(
+			"Preloader.Entrypoint", "Assembly",
+			IsPostUnity2017 ? "UnityEngine.CoreModule.dll" : "UnityEngine.dll",
+			new ConfigDescription("The local filename of the assembly to target."));
+
+		private static readonly ConfigWrapper<string> ConfigEntrypointType = ConfigFile.CoreConfig.Wrap<string>(
+			"Preloader.Entrypoint", "Type",
+			"Application",
+			new ConfigDescription("The name of the type in the entrypoint assembly to search for the entrypoint method."));
+
+		private static readonly ConfigWrapper<string> ConfigEntrypointMethod = ConfigFile.CoreConfig.Wrap<string>(
+			"Preloader.Entrypoint", "Method",
+			".cctor",
+			new ConfigDescription("The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from."));
 
 		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);
+			"Preloader", "ApplyRuntimePatches",
+			true,
+			new ConfigDescription("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."));
 
 		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.",
-			!Utility.CLRSupportsDynamicAssemblies);
+			"Preloader", "ShimHarmonySupport",
+			!Utility.CLRSupportsDynamicAssemblies,
+			new ConfigDescription("If enabled, basic Harmony functionality is patched to use MonoMod's RuntimeDetour instead.\nTry using this if Harmony does not work in a game."));
 
 		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);
+			"Logging", "PreloaderConsoleOutRedirection",
+			true,
+			new ConfigDescription("Redirects text from Console.Out during preloader patch loading to the BepInEx logging system."));
 
 		#endregion
 	}

+ 8 - 4
BepInEx/Bootstrap/Chainloader.cs

@@ -2,13 +2,11 @@
 using BepInEx.Logging;
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Text;
 using System.Text.RegularExpressions;
-using BepInEx.Contract;
 using Mono.Cecil;
 using UnityEngine;
 using UnityInjector.ConsoleUtil;
@@ -304,9 +302,15 @@ namespace BepInEx.Bootstrap
 
 		#region Config
 
-		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 readonly ConfigWrapper<string> ConfigPluginsDirectory = ConfigFile.CoreConfig.Wrap<string>(
+			"Paths", "PluginsDirectory",
+			"plugins",
+			new ConfigDescription("The relative directory to the BepInEx folder where plugins are loaded."));
 
-		private static readonly ConfigWrapper<bool> ConfigUnityLogging = ConfigFile.CoreConfig.Wrap("Logging", "UnityLogListening", "Enables showing unity log messages in the BepInEx logging system.", true);
+		private static readonly ConfigWrapper<bool> ConfigUnityLogging = ConfigFile.CoreConfig.Wrap(
+			"Logging", "UnityLogListening",
+			true,
+			new ConfigDescription("Enables showing unity log messages in the BepInEx logging system."));
 
 		#endregion
 	}

+ 4 - 5
BepInEx/Bootstrap/TypeLoader.cs

@@ -257,11 +257,10 @@ namespace BepInEx.Bootstrap
 
 		#region Config
 
-		private static ConfigWrapper<bool> EnableAssemblyCache = ConfigFile.CoreConfig.Wrap(
-			"Caching", 
-			"EnableAssemblyCache", 
-			"Enable/disable assembly metadata cache\nEnabling this will speed up discovery of plugins and patchers by caching the metadata of all types BepInEx discovers.", 
-			true);
+		private static readonly ConfigWrapper<bool> EnableAssemblyCache = ConfigFile.CoreConfig.Wrap(
+			"Caching", "EnableAssemblyCache", 
+			true, 
+			new ConfigDescription("Enable/disable assembly metadata cache\nEnabling this will speed up discovery of plugins and patchers by caching the metadata of all types BepInEx discovers."));
 
 		#endregion
 	}

+ 7 - 9
BepInEx/ConsoleUtil/ConsoleWindow.cs

@@ -14,16 +14,14 @@ namespace UnityInjector.ConsoleUtil
 	internal class ConsoleWindow
 	{
 		public static readonly ConfigWrapper<bool> ConfigConsoleEnabled = ConfigFile.CoreConfig.Wrap(
-			"Logging.Console",
-			"Enabled",
-			"Enables showing a console for log output.",
-			false);
+			"Logging.Console", "Enabled",
+			false,
+			new ConfigDescription("Enables showing a console for log output."));
 
 		public 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);
+			"Logging.Console", "ShiftJisEncoding",
+			false,
+			new ConfigDescription("If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding."));
 
 		public static bool IsAttached { get; private set; }
 		private static IntPtr _cOut;
@@ -106,7 +104,7 @@ namespace UnityInjector.ConsoleUtil
 
 		[DllImport("user32.dll")]
 		[return: MarshalAs(UnmanagedType.Bool)]
-		static extern bool SetForegroundWindow(IntPtr hWnd);
+		private static extern bool SetForegroundWindow(IntPtr hWnd);
 
 		[DllImport("kernel32.dll", SetLastError = true)]
 		private static extern bool AllocConsole();

+ 0 - 1
BepInEx/Contract/BaseUnityPlugin.cs

@@ -1,6 +1,5 @@
 using BepInEx.Bootstrap;
 using BepInEx.Configuration;
-using BepInEx.Contract;
 using BepInEx.Logging;
 using UnityEngine;
 

+ 5 - 8
BepInEx/Logging/ConsoleLogListener.cs

@@ -9,11 +9,9 @@ namespace BepInEx.Logging
 	/// </summary>
 	public class ConsoleLogListener : ILogListener
 	{
-		protected LogLevel DisplayedLogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), ConfigConsoleDisplayedLevel.Value, true);
-
 		public void LogEvent(object sender, LogEventArgs eventArgs)
 		{
-			if (eventArgs.Level.GetHighestLevel() > DisplayedLogLevel)
+			if (eventArgs.Level.GetHighestLevel() > ConfigConsoleDisplayedLevel.Value)
 				return;
 
 			string log = $"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}\r\n";
@@ -25,10 +23,9 @@ namespace BepInEx.Logging
 
 		public void Dispose() { }
 
-		private static readonly ConfigWrapper<string> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
-			"Logging.Console",
-			"DisplayedLogLevel",
-			"Only displays the specified log level and above in the console output.",
-			"Info");
+		private static readonly ConfigWrapper<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
+			"Logging.Console","DisplayedLogLevel",
+			LogLevel.Info,
+			new ConfigDescription("Only displays the specified log level and above in the console output."));
 	}
 }

+ 12 - 18
BepInEx/Logging/DiskLogListener.cs

@@ -1,5 +1,4 @@
-using System;
-using System.IO;
+using System.IO;
 using System.Text;
 using System.Threading;
 using BepInEx.Configuration;
@@ -11,8 +10,6 @@ namespace BepInEx.Logging
 	/// </summary>
 	public class DiskLogListener : ILogListener
 	{
-		protected LogLevel DisplayedLogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), ConfigConsoleDisplayedLevel.Value, true);
-
 		protected TextWriter LogWriter { get; set; }
 
 		protected Timer FlushTimer { get; set; }
@@ -49,7 +46,7 @@ namespace BepInEx.Logging
 			if (!ConfigWriteUnityLog.Value && eventArgs.Source is UnityLogSource)
 				return;
 
-			if (eventArgs.Level.GetHighestLevel() > DisplayedLogLevel)
+			if (eventArgs.Level.GetHighestLevel() > ConfigConsoleDisplayedLevel.Value)
 				return;
 
 			LogWriter.WriteLine($"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}");
@@ -67,22 +64,19 @@ namespace BepInEx.Logging
 			Dispose();
 		}
 
-		private static readonly ConfigWrapper<string> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
-			"Logging.Disk",
-			"DisplayedLogLevel",
-			"Only displays the specified log level and above in the console output.",
-			"Info");
+		private static readonly ConfigWrapper<LogLevel> ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap(
+			"Logging.Disk", "DisplayedLogLevel",
+			LogLevel.Info,
+			new ConfigDescription("Only displays the specified log level and above in the console output."));
 
 		private static readonly ConfigWrapper<bool> ConfigWriteUnityLog = ConfigFile.CoreConfig.Wrap(
-			"Logging.Disk",
-			"WriteUnityLog",
-			"Include unity log messages in log file output.",
-			false);
+			"Logging.Disk", "WriteUnityLog",
+			false,
+			new ConfigDescription("Include unity log messages in log file output."));
 
 		private static readonly ConfigWrapper<bool> ConfigAppendLog = ConfigFile.CoreConfig.Wrap(
-			"Logging.Disk",
-			"AppendLog",
-			"Appends to the log file instead of overwriting, on game startup.",
-			false);
+			"Logging.Disk", "AppendLog",
+			false,
+			new ConfigDescription("Appends to the log file instead of overwriting, on game startup."));
 	}
 }