From 4711b1e5fa35bb847c4252286f666d70370b440c Mon Sep 17 00:00:00 2001 From: ManlyMarco Date: Sat, 17 Aug 2019 01:03:16 +0200 Subject: [PATCH] Change BepInEx settings to use new wrap overloads --- BepInEx.Preloader/Patching/AssemblyPatcher.cs | 21 ++++---- BepInEx.Preloader/Preloader.cs | 49 ++++++++----------- BepInEx/Bootstrap/Chainloader.cs | 12 +++-- BepInEx/Bootstrap/TypeLoader.cs | 9 ++-- BepInEx/ConsoleUtil/ConsoleWindow.cs | 16 +++--- BepInEx/Contract/BaseUnityPlugin.cs | 1 - BepInEx/Logging/ConsoleLogListener.cs | 13 ++--- BepInEx/Logging/DiskLogListener.cs | 30 +++++------- 8 files changed, 66 insertions(+), 85 deletions(-) diff --git a/BepInEx.Preloader/Patching/AssemblyPatcher.cs b/BepInEx.Preloader/Patching/AssemblyPatcher.cs index e01aa5f..2bf55c1 100644 --- a/BepInEx.Preloader/Patching/AssemblyPatcher.cs +++ b/BepInEx.Preloader/Patching/AssemblyPatcher.cs @@ -278,22 +278,19 @@ namespace BepInEx.Preloader.Patching #region Config private static readonly ConfigWrapper 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 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 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 } diff --git a/BepInEx.Preloader/Preloader.cs b/BepInEx.Preloader/Preloader.cs index fd90677..77ca461 100644 --- a/BepInEx.Preloader/Preloader.cs +++ b/BepInEx.Preloader/Preloader.cs @@ -234,42 +234,35 @@ namespace BepInEx.Preloader #region Config - private static readonly ConfigWrapper 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 ConfigEntrypointAssembly = ConfigFile.CoreConfig.Wrap( + "Preloader.Entrypoint", "Assembly", + IsPostUnity2017 ? "UnityEngine.CoreModule.dll" : "UnityEngine.dll", + new ConfigDescription("The local filename of the assembly to target.")); - private static readonly ConfigWrapper 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 ConfigEntrypointType = ConfigFile.CoreConfig.Wrap( + "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 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 ConfigEntrypointMethod = ConfigFile.CoreConfig.Wrap( + "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 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 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 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 } diff --git a/BepInEx/Bootstrap/Chainloader.cs b/BepInEx/Bootstrap/Chainloader.cs index d877cc1..73e532e 100644 --- a/BepInEx/Bootstrap/Chainloader.cs +++ b/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 ConfigPluginsDirectory = ConfigFile.CoreConfig.Wrap("Paths", "PluginsDirectory", "The relative directory to the BepInEx folder where plugins are loaded.", "plugins"); + private static readonly ConfigWrapper ConfigPluginsDirectory = ConfigFile.CoreConfig.Wrap( + "Paths", "PluginsDirectory", + "plugins", + new ConfigDescription("The relative directory to the BepInEx folder where plugins are loaded.")); - private static readonly ConfigWrapper ConfigUnityLogging = ConfigFile.CoreConfig.Wrap("Logging", "UnityLogListening", "Enables showing unity log messages in the BepInEx logging system.", true); + private static readonly ConfigWrapper ConfigUnityLogging = ConfigFile.CoreConfig.Wrap( + "Logging", "UnityLogListening", + true, + new ConfigDescription("Enables showing unity log messages in the BepInEx logging system.")); #endregion } diff --git a/BepInEx/Bootstrap/TypeLoader.cs b/BepInEx/Bootstrap/TypeLoader.cs index 6bec362..214cd64 100644 --- a/BepInEx/Bootstrap/TypeLoader.cs +++ b/BepInEx/Bootstrap/TypeLoader.cs @@ -257,11 +257,10 @@ namespace BepInEx.Bootstrap #region Config - private static ConfigWrapper 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 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 } diff --git a/BepInEx/ConsoleUtil/ConsoleWindow.cs b/BepInEx/ConsoleUtil/ConsoleWindow.cs index 9c9e9b6..f583006 100644 --- a/BepInEx/ConsoleUtil/ConsoleWindow.cs +++ b/BepInEx/ConsoleUtil/ConsoleWindow.cs @@ -14,16 +14,14 @@ namespace UnityInjector.ConsoleUtil internal class ConsoleWindow { public static readonly ConfigWrapper 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 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(); diff --git a/BepInEx/Contract/BaseUnityPlugin.cs b/BepInEx/Contract/BaseUnityPlugin.cs index 7a74859..7fd51e9 100644 --- a/BepInEx/Contract/BaseUnityPlugin.cs +++ b/BepInEx/Contract/BaseUnityPlugin.cs @@ -1,6 +1,5 @@ using BepInEx.Bootstrap; using BepInEx.Configuration; -using BepInEx.Contract; using BepInEx.Logging; using UnityEngine; diff --git a/BepInEx/Logging/ConsoleLogListener.cs b/BepInEx/Logging/ConsoleLogListener.cs index ee9d9c2..50d292e 100644 --- a/BepInEx/Logging/ConsoleLogListener.cs +++ b/BepInEx/Logging/ConsoleLogListener.cs @@ -9,11 +9,9 @@ namespace BepInEx.Logging /// 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 ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap( - "Logging.Console", - "DisplayedLogLevel", - "Only displays the specified log level and above in the console output.", - "Info"); + private static readonly ConfigWrapper ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap( + "Logging.Console","DisplayedLogLevel", + LogLevel.Info, + new ConfigDescription("Only displays the specified log level and above in the console output.")); } } \ No newline at end of file diff --git a/BepInEx/Logging/DiskLogListener.cs b/BepInEx/Logging/DiskLogListener.cs index e2b94cd..f57cab4 100644 --- a/BepInEx/Logging/DiskLogListener.cs +++ b/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 /// 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 ConfigConsoleDisplayedLevel = ConfigFile.CoreConfig.Wrap( - "Logging.Disk", - "DisplayedLogLevel", - "Only displays the specified log level and above in the console output.", - "Info"); + private static readonly ConfigWrapper 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 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 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.")); } } \ No newline at end of file