|
@@ -5,6 +5,7 @@ using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
|
+using BepInEx.Configuration;
|
|
|
using BepInEx.Logging;
|
|
|
using BepInEx.Preloader.Patching;
|
|
|
using BepInEx.Preloader.RuntimeFixes;
|
|
@@ -31,15 +32,16 @@ namespace BepInEx.Preloader
|
|
|
{
|
|
|
AllocateConsole();
|
|
|
|
|
|
- UnityPatches.Apply();
|
|
|
+ if (ConfigApplyRuntimePatches.Value)
|
|
|
+ UnityPatches.Apply();
|
|
|
|
|
|
Logger.Sources.Add(TraceLogSource.CreateSource());
|
|
|
|
|
|
- PreloaderLog = new PreloaderConsoleListener(Utility.SafeParseBool(Config.GetEntry("preloader-logconsole", "false", "BepInEx")));
|
|
|
+ PreloaderLog = new PreloaderConsoleListener(ConfigPreloaderCOutLogging.Value);
|
|
|
|
|
|
Logger.Listeners.Add(PreloaderLog);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
string consoleTile = $"BepInEx {typeof(Paths).Assembly.GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
|
|
|
|
|
|
ConsoleWindow.Title = consoleTile;
|
|
@@ -65,10 +67,9 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
Logger.LogMessage("Preloader started");
|
|
|
|
|
|
- string entrypointAssembly = Config.GetEntry("entrypoint-assembly", "UnityEngine.dll", "Preloader");
|
|
|
|
|
|
AssemblyPatcher.AddPatcher(new PatcherPlugin
|
|
|
- { TargetDLLs = new[] { entrypointAssembly },
|
|
|
+ { TargetDLLs = new[] { ConfigEntrypointAssembly.Value },
|
|
|
Patcher = PatchEntrypoint,
|
|
|
Name = "BepInEx.Chainloader"
|
|
|
});
|
|
@@ -77,10 +78,13 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
Logger.LogInfo($"{AssemblyPatcher.PatcherPlugins.Count} patcher plugin(s) loaded");
|
|
|
|
|
|
+
|
|
|
AssemblyPatcher.PatchAndLoad(Paths.ManagedPath);
|
|
|
|
|
|
+
|
|
|
AssemblyPatcher.DisposePatchers();
|
|
|
|
|
|
+
|
|
|
Logger.LogMessage("Preloader finished");
|
|
|
|
|
|
Logger.Listeners.Remove(PreloaderLog);
|
|
@@ -218,8 +222,8 @@ namespace BepInEx.Preloader
|
|
|
if (assembly.MainModule.AssemblyReferences.Any(x => x.Name.Contains("BepInEx")))
|
|
|
throw new Exception("BepInEx has been detected to be patched! Please unpatch before using a patchless variant!");
|
|
|
|
|
|
- string entrypointType = Config.GetEntry("entrypoint-type", "Application", "Preloader");
|
|
|
- string entrypointMethod = Config.GetEntry("entrypoint-method", ".cctor", "Preloader");
|
|
|
+ string entrypointType = ConfigEntrypointType.Value;
|
|
|
+ string entrypointMethod = ConfigEntrypointMethod.Value;
|
|
|
|
|
|
bool isCctor = entrypointMethod.IsNullOrWhiteSpace() || entrypointMethod == ".cctor";
|
|
|
|
|
@@ -274,14 +278,14 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
var ins = il.Body.Instructions.First();
|
|
|
|
|
|
- il.InsertBefore(ins, il.Create(OpCodes.Ldstr, Paths.ExecutablePath)); //containerExePath
|
|
|
il.InsertBefore(ins,
|
|
|
- il.Create(OpCodes
|
|
|
- .Ldc_I4_0)); //startConsole (always false, we already load the console in Preloader)
|
|
|
+ il.Create(OpCodes.Ldstr, Paths.ExecutablePath)); //containerExePath
|
|
|
il.InsertBefore(ins,
|
|
|
- il.Create(OpCodes.Call,
|
|
|
- initMethod)); //Chainloader.Initialize(string containerExePath, bool startConsole = true)
|
|
|
- il.InsertBefore(ins, il.Create(OpCodes.Call, startMethod));
|
|
|
+ il.Create(OpCodes.Ldc_I4_0)); //startConsole (always false, we already load the console in Preloader)
|
|
|
+ il.InsertBefore(ins,
|
|
|
+ il.Create(OpCodes.Call, initMethod)); //Chainloader.Initialize(string containerExePath, bool startConsole = true)
|
|
|
+ il.InsertBefore(ins,
|
|
|
+ il.Create(OpCodes.Call, startMethod));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -291,10 +295,7 @@ namespace BepInEx.Preloader
|
|
|
/// </summary>
|
|
|
public static void AllocateConsole()
|
|
|
{
|
|
|
- bool console = Utility.SafeParseBool(Config.GetEntry("console", "false", "BepInEx"));
|
|
|
- bool shiftjis = Utility.SafeParseBool(Config.GetEntry("console-shiftjis", "false", "BepInEx"));
|
|
|
-
|
|
|
- if (!console)
|
|
|
+ if (!ConfigConsoleEnabled.Value)
|
|
|
return;
|
|
|
|
|
|
try
|
|
@@ -303,7 +304,7 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
var encoding = (uint)Encoding.UTF8.CodePage;
|
|
|
|
|
|
- if (shiftjis)
|
|
|
+ if (ConfigConsoleShiftJis.Value)
|
|
|
encoding = 932;
|
|
|
|
|
|
ConsoleEncoding.ConsoleCodePage = encoding;
|
|
@@ -315,5 +316,51 @@ namespace BepInEx.Preloader
|
|
|
Logger.LogError(ex);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ #region Config
|
|
|
+
|
|
|
+ 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
|
|
|
}
|
|
|
}
|