|
@@ -5,6 +5,7 @@ using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
+using BepInEx.Configuration;
|
|
using BepInEx.Logging;
|
|
using BepInEx.Logging;
|
|
using BepInEx.Preloader.Patching;
|
|
using BepInEx.Preloader.Patching;
|
|
using BepInEx.Preloader.RuntimeFixes;
|
|
using BepInEx.Preloader.RuntimeFixes;
|
|
@@ -29,13 +30,15 @@ namespace BepInEx.Preloader
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
|
|
+ InitConfig();
|
|
|
|
+
|
|
AllocateConsole();
|
|
AllocateConsole();
|
|
|
|
|
|
UnityPatches.Apply();
|
|
UnityPatches.Apply();
|
|
|
|
|
|
Logger.Sources.Add(TraceLogSource.CreateSource());
|
|
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);
|
|
Logger.Listeners.Add(PreloaderLog);
|
|
|
|
|
|
@@ -65,18 +68,21 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
Logger.LogMessage("Preloader started");
|
|
Logger.LogMessage("Preloader started");
|
|
|
|
|
|
- string entrypointAssembly = Config.GetEntry("entrypoint-assembly", "UnityEngine.dll", "Preloader");
|
|
|
|
|
|
|
|
AssemblyPatcher.AddPatcher(new PatcherPlugin
|
|
AssemblyPatcher.AddPatcher(new PatcherPlugin
|
|
- { TargetDLLs = new[] { entrypointAssembly }, Patcher = PatchEntrypoint });
|
|
|
|
|
|
+ { TargetDLLs = new[] { ConfigEntrypointAssembly.Value }, Patcher = PatchEntrypoint });
|
|
|
|
+
|
|
AssemblyPatcher.AddPatchersFromDirectory(Paths.PatcherPluginPath, GetPatcherMethods);
|
|
AssemblyPatcher.AddPatchersFromDirectory(Paths.PatcherPluginPath, GetPatcherMethods);
|
|
|
|
|
|
Logger.LogInfo($"{AssemblyPatcher.PatcherPlugins.Count} patcher plugin(s) loaded");
|
|
Logger.LogInfo($"{AssemblyPatcher.PatcherPlugins.Count} patcher plugin(s) loaded");
|
|
|
|
|
|
|
|
+
|
|
AssemblyPatcher.PatchAndLoad(Paths.ManagedPath);
|
|
AssemblyPatcher.PatchAndLoad(Paths.ManagedPath);
|
|
|
|
|
|
|
|
+
|
|
AssemblyPatcher.DisposePatchers();
|
|
AssemblyPatcher.DisposePatchers();
|
|
|
|
|
|
|
|
+
|
|
Logger.LogMessage("Preloader finished");
|
|
Logger.LogMessage("Preloader finished");
|
|
|
|
|
|
Logger.Listeners.Remove(PreloaderLog);
|
|
Logger.Listeners.Remove(PreloaderLog);
|
|
@@ -213,8 +219,8 @@ namespace BepInEx.Preloader
|
|
if (assembly.MainModule.AssemblyReferences.Any(x => x.Name.Contains("BepInEx")))
|
|
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!");
|
|
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";
|
|
bool isCctor = entrypointMethod.IsNullOrWhiteSpace() || entrypointMethod == ".cctor";
|
|
|
|
|
|
@@ -269,14 +275,14 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
var ins = il.Body.Instructions.First();
|
|
var ins = il.Body.Instructions.First();
|
|
|
|
|
|
- il.InsertBefore(ins, il.Create(OpCodes.Ldstr, Paths.ExecutablePath)); //containerExePath
|
|
|
|
il.InsertBefore(ins,
|
|
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.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));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -286,10 +292,7 @@ namespace BepInEx.Preloader
|
|
/// </summary>
|
|
/// </summary>
|
|
public static void AllocateConsole()
|
|
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;
|
|
return;
|
|
|
|
|
|
try
|
|
try
|
|
@@ -298,7 +301,7 @@ namespace BepInEx.Preloader
|
|
|
|
|
|
var encoding = (uint)Encoding.UTF8.CodePage;
|
|
var encoding = (uint)Encoding.UTF8.CodePage;
|
|
|
|
|
|
- if (shiftjis)
|
|
|
|
|
|
+ if (ConfigConsoleShiftJis.Value)
|
|
encoding = 932;
|
|
encoding = 932;
|
|
|
|
|
|
ConsoleEncoding.ConsoleCodePage = encoding;
|
|
ConsoleEncoding.ConsoleCodePage = encoding;
|
|
@@ -310,5 +313,60 @@ namespace BepInEx.Preloader
|
|
Logger.LogError(ex);
|
|
Logger.LogError(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
}
|
|
}
|
|
}
|
|
}
|