Preloader.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Diagnostics;
  3. using BepInEx.Logging;
  4. using BepInEx.Preloader.Core;
  5. using BepInEx.Preloader.Core.Logging;
  6. namespace BepInEx.IL2CPP
  7. {
  8. public static class Preloader
  9. {
  10. public static string IL2CPPUnhollowedPath { get; internal set; }
  11. private static PreloaderConsoleListener PreloaderLog { get; set; }
  12. internal static ManualLogSource Log => PreloaderLogger.Log;
  13. internal static ManualLogSource UnhollowerLog { get; set; }
  14. public static IL2CPPChainloader Chainloader { get; private set; }
  15. public static void Run()
  16. {
  17. try
  18. {
  19. PreloaderLog = new PreloaderConsoleListener(true);
  20. Logger.Listeners.Add(PreloaderLog);
  21. if (ConsoleManager.ConfigConsoleEnabled.Value && !ConsoleManager.ConsoleActive)
  22. {
  23. ConsoleManager.CreateConsole();
  24. Logger.Listeners.Add(new ConsoleLogListener());
  25. }
  26. BasicLogInfo.PrintLogInfo(Log);
  27. Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}");
  28. Log.LogDebug($"Game executable path: {Paths.ExecutablePath}");
  29. Log.LogDebug($"Unhollowed assembly directory: {IL2CPPUnhollowedPath}");
  30. Log.LogDebug($"BepInEx root path: {Paths.BepInExRootPath}");
  31. UnhollowerLog = Logger.CreateLogSource("Unhollower");
  32. UnhollowerBaseLib.LogSupport.InfoHandler += UnhollowerLog.LogInfo;
  33. UnhollowerBaseLib.LogSupport.WarningHandler += UnhollowerLog.LogWarning;
  34. UnhollowerBaseLib.LogSupport.TraceHandler += UnhollowerLog.LogDebug;
  35. UnhollowerBaseLib.LogSupport.ErrorHandler += UnhollowerLog.LogError;
  36. if (ProxyAssemblyGenerator.CheckIfGenerationRequired())
  37. ProxyAssemblyGenerator.GenerateAssemblies();
  38. Logger.Listeners.Remove(PreloaderLog);
  39. Chainloader = new IL2CPPChainloader();
  40. Chainloader.Initialize();
  41. }
  42. catch (Exception ex)
  43. {
  44. Log.LogFatal(ex);
  45. throw;
  46. }
  47. }
  48. }
  49. }