Preloader.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. ConsoleManager.Initialize(false);
  20. PreloaderLog = new PreloaderConsoleListener();
  21. Logger.Listeners.Add(PreloaderLog);
  22. if (ConsoleManager.ConfigConsoleEnabled.Value)
  23. {
  24. ConsoleManager.CreateConsole();
  25. Logger.Listeners.Add(new ConsoleLogListener());
  26. }
  27. ChainloaderLogHelper.PrintLogInfo(Log);
  28. Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}");
  29. Log.LogDebug($"Game executable path: {Paths.ExecutablePath}");
  30. Log.LogDebug($"Unhollowed assembly directory: {IL2CPPUnhollowedPath}");
  31. Log.LogDebug($"BepInEx root path: {Paths.BepInExRootPath}");
  32. UnhollowerLog = Logger.CreateLogSource("Unhollower");
  33. UnhollowerBaseLib.LogSupport.InfoHandler += UnhollowerLog.LogInfo;
  34. UnhollowerBaseLib.LogSupport.WarningHandler += UnhollowerLog.LogWarning;
  35. UnhollowerBaseLib.LogSupport.TraceHandler += UnhollowerLog.LogDebug;
  36. UnhollowerBaseLib.LogSupport.ErrorHandler += UnhollowerLog.LogError;
  37. if (ProxyAssemblyGenerator.CheckIfGenerationRequired())
  38. ProxyAssemblyGenerator.GenerateAssemblies();
  39. Logger.Listeners.Remove(PreloaderLog);
  40. Chainloader = new IL2CPPChainloader();
  41. Chainloader.Initialize();
  42. }
  43. catch (Exception ex)
  44. {
  45. Log.LogFatal(ex);
  46. throw;
  47. }
  48. }
  49. }
  50. }