コード例 #1
0
ファイル: BaseChainloader.cs プロジェクト: hanabi1224/BepInEx
        protected virtual void InitializeLoggers()
        {
            if (ConsoleManager.ConfigConsoleEnabled.Value && !ConsoleManager.ConsoleActive)
            {
                ConsoleManager.CreateConsole();
            }

            if (ConsoleManager.ConsoleActive)
            {
                if (!Logger.Listeners.Any(x => x is ConsoleLogListener))
                {
                    Logger.Listeners.Add(new ConsoleLogListener());
                }

                ConsoleManager.SetConsoleTitle(ConsoleTitle);
            }

            if (ConfigDiskLogging.Value)
            {
                Logger.Listeners.Add(new DiskLogListener("LogOutput.log", ConfigDiskLoggingDisplayedLevel.Value, ConfigDiskAppend.Value, ConfigDiskLoggingInstantFlushing.Value, ConfigDiskLoggingFileLimit.Value));
            }

            if (!TraceLogSource.IsListening)
            {
                Logger.Sources.Add(TraceLogSource.CreateSource());
            }

            if (!Logger.Sources.Any(x => x is HarmonyLogSource))
            {
                Logger.Sources.Add(new HarmonyLogSource());
            }
        }
コード例 #2
0
ファイル: Preloader.cs プロジェクト: hanabi1224/BepInEx
        public static void Run()
        {
            try
            {
                ConsoleManager.Initialize(false);

                PreloaderLog = new PreloaderConsoleListener();
                Logger.Listeners.Add(PreloaderLog);



                if (ConsoleManager.ConfigConsoleEnabled.Value)
                {
                    ConsoleManager.CreateConsole();
                    Logger.Listeners.Add(new ConsoleLogListener());
                }

                ChainloaderLogHelper.PrintLogInfo(Log);

                Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}");

                Log.LogDebug($"Game executable path: {Paths.ExecutablePath}");
                Log.LogDebug($"Unhollowed assembly directory: {IL2CPPUnhollowedPath}");
                Log.LogDebug($"BepInEx root path: {Paths.BepInExRootPath}");



                UnhollowerLog = Logger.CreateLogSource("Unhollower");
                UnhollowerBaseLib.LogSupport.InfoHandler    += UnhollowerLog.LogInfo;
                UnhollowerBaseLib.LogSupport.WarningHandler += UnhollowerLog.LogWarning;
                UnhollowerBaseLib.LogSupport.TraceHandler   += UnhollowerLog.LogDebug;
                UnhollowerBaseLib.LogSupport.ErrorHandler   += UnhollowerLog.LogError;


                if (ProxyAssemblyGenerator.CheckIfGenerationRequired())
                {
                    ProxyAssemblyGenerator.GenerateAssemblies();
                }


                Logger.Listeners.Remove(PreloaderLog);



                Chainloader = new IL2CPPChainloader();

                Chainloader.Initialize();
            }
            catch (Exception ex)
            {
                Log.LogFatal(ex);

                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes BepInEx to be able to start the chainloader.
        /// </summary>
        public static void Initialize(string gameExePath, bool startConsole = true, ICollection <LogEventArgs> preloaderLogEvents = null)
        {
            if (_initialized)
            {
                return;
            }

            ThreadingHelper.Initialize();

            // Set vitals
            if (gameExePath != null)
            {
                // Checking for null allows a more advanced initialization workflow, where the Paths class has been initialized before calling Chainloader.Initialize
                // This is used by Preloader to use environment variables, for example
                Paths.SetExecutablePath(gameExePath);
            }

            // Start logging
            if (ConsoleManager.ConfigConsoleEnabled.Value && startConsole)
            {
                ConsoleManager.CreateConsole();
                Logger.Listeners.Add(new ConsoleLogListener());
            }

            Logger.InitializeInternalLoggers();

            if (ConfigDiskLogging.Value)
            {
                Logger.Listeners.Add(new DiskLogListener("LogOutput.log", ConfigDiskConsoleDisplayedLevel.Value, ConfigDiskAppend.Value, ConfigDiskWriteUnityLog.Value));
            }

            if (!TraceLogSource.IsListening)
            {
                Logger.Sources.Add(TraceLogSource.CreateSource());
            }

            ReplayPreloaderLogs(preloaderLogEvents);

            // Add Unity log source only after replaying to prevent duplication in console
            if (ConfigUnityLogging.Value)
            {
                Logger.Sources.Add(new UnityLogSource());
            }
            Logger.Listeners.Add(new UnityLogListener());

            if (Utility.CurrentOs == Platform.Linux)
            {
                Logger.LogInfo($"Detected Unity version: v{Application.unityVersion}");
            }

            Logger.LogMessage("Chainloader ready");

            _initialized = true;
        }
コード例 #4
0
        /// <summary>
        ///     Allocates a console window for use by BepInEx safely.
        /// </summary>
        public static void AllocateConsole()
        {
            if (!ConsoleManager.ConsoleEnabled)
            {
                return;
            }

            try
            {
                ConsoleManager.CreateConsole();
            }
            catch (Exception ex)
            {
                Log.LogError("Failed to allocate console!");
                Log.LogError(ex);
            }
        }
コード例 #5
0
ファイル: Preloader.cs プロジェクト: yuemenglong/BepInEx
        /// <summary>
        ///     Allocates a console window for use by BepInEx safely.
        /// </summary>
        public static void AllocateConsole()
        {
            if (!ConsoleManager.ConfigConsoleEnabled.Value)
            {
                return;
            }

            try
            {
                ConsoleManager.CreateConsole();
                ConsoleManager.SetConsoleEncoding();
            }
            catch (Exception ex)
            {
                Logger.LogError("Failed to allocate console!");
                Logger.LogError(ex);
            }
        }
コード例 #6
0
        internal static void PreloaderMain()
        {
            ConsoleManager.Initialize(false, false);

            ConsoleManager.CreateConsole();

            Logger.Listeners.Add(new ConsoleLogListener());

            try
            {
                NetCorePreloader.Start();
            }
            catch (Exception ex)
            {
                PreloaderLogger.Log.Log(LogLevel.Fatal, "Unhandled exception");
                PreloaderLogger.Log.Log(LogLevel.Fatal, ex);
            }
        }
コード例 #7
0
        /// <summary>
        ///     Allocates a console window for use by BepInEx safely.
        /// </summary>
        public static void AllocateConsole()
        {
            if (!ConsoleManager.ConfigConsoleEnabled.Value)
            {
                return;
            }

            try
            {
                ConsoleManager.CreateConsole();
                Logger.Listeners.Add(new ConsoleLogListener());
            }
            catch (Exception ex)
            {
                Logger.LogError("Failed to allocate console!");
                Logger.LogError(ex);
            }
        }
コード例 #8
0
ファイル: Preloader.cs プロジェクト: seyfullahaktas/BepInEx
        public static void Run()
        {
            try
            {
                ConsoleManager.Initialize(false);

                PreloaderLog = new PreloaderConsoleListener();
                Logger.Listeners.Add(PreloaderLog);


                if (ConsoleManager.ConfigConsoleEnabled.Value)
                {
                    ConsoleManager.CreateConsole();
                    Logger.Listeners.Add(new ConsoleLogListener());
                }

                ChainloaderLogHelper.PrintLogInfo(Log);

                Log.LogDebug($"Game executable path: {Paths.ExecutablePath}");
                Log.LogDebug($"Unhollowed assembly directory: {IL2CPPUnhollowedPath}");
                Log.LogDebug($"BepInEx root path: {Paths.BepInExRootPath}");

                UnhollowerLog              = Logger.CreateLogSource("Unhollower");
                LogSupport.InfoHandler    += UnhollowerLog.LogInfo;
                LogSupport.WarningHandler += UnhollowerLog.LogWarning;
                LogSupport.TraceHandler   += UnhollowerLog.LogDebug;
                LogSupport.ErrorHandler   += UnhollowerLog.LogError;


                if (ProxyAssemblyGenerator.CheckIfGenerationRequired())
                {
                    ProxyAssemblyGenerator.GenerateAssemblies();
                }


                InitializeUnityVersion();


                using (var assemblyPatcher = new AssemblyPatcher())
                {
                    assemblyPatcher.AddPatchersFromDirectory(Paths.PatcherPluginPath);

                    Log.LogInfo($"{assemblyPatcher.PatcherPlugins.Count} patcher plugin{(assemblyPatcher.PatcherPlugins.Count == 1 ? "" : "s")} loaded");

                    assemblyPatcher.LoadAssemblyDirectories(IL2CPPUnhollowedPath);

                    Log.LogInfo($"{assemblyPatcher.PatcherPlugins.Count} assemblies discovered");

                    assemblyPatcher.PatchAndLoad();
                }


                Logger.Listeners.Remove(PreloaderLog);


                Chainloader = new IL2CPPChainloader();

                Chainloader.Initialize();
            }
            catch (Exception ex)
            {
                Log.LogFatal(ex);

                throw;
            }
        }
コード例 #9
0
        /// <summary>
        /// Initializes BepInEx to be able to start the chainloader.
        /// </summary>
        public static void Initialize(string gameExePath, bool startConsole = true, ICollection <LogEventArgs> preloaderLogEvents = null)
        {
            if (_initialized)
            {
                return;
            }

            ThreadingHelper.Initialize();

            // Set vitals
            if (gameExePath != null)
            {
                // Checking for null allows a more advanced initialization workflow, where the Paths class has been initialized before calling Chainloader.Initialize
                // This is used by Preloader to use environment variables, for example
                Paths.SetExecutablePath(gameExePath);
            }

            // Start logging
            if (ConsoleManager.ConfigConsoleEnabled.Value && startConsole)
            {
                ConsoleManager.CreateConsole();
                Logger.Listeners.Add(new ConsoleLogListener());
            }

            // Fix for standard output getting overwritten by UnityLogger
            if (ConsoleManager.ConsoleActive)
            {
                ConsoleManager.SetConsoleStreams();
                ConsoleManager.SetConsoleEncoding();
            }

            Logger.InitializeInternalLoggers();
            Logger.Listeners.Add(new UnityLogListener());

            if (ConfigDiskLogging.Value)
            {
                Logger.Listeners.Add(new DiskLogListener("LogOutput.log", ConfigDiskConsoleDisplayedLevel.Value, ConfigDiskAppend.Value, ConfigDiskWriteUnityLog.Value));
            }

            if (!TraceLogSource.IsListening)
            {
                Logger.Sources.Add(TraceLogSource.CreateSource());
            }

            if (ConfigUnityLogging.Value)
            {
                Logger.Sources.Add(new UnityLogSource());
            }


            // Temporarily disable the console log listener as we replay the preloader logs
            var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);

            if (logListener != null)
            {
                Logger.Listeners.Remove(logListener);
            }

            // Write preloader log events if there are any, including the original log source name
            if (preloaderLogEvents != null)
            {
                var preloaderLogSource = Logger.CreateLogSource("Preloader");

                foreach (var preloaderLogEvent in preloaderLogEvents)
                {
                    Logger.InternalLogEvent(preloaderLogSource, preloaderLogEvent);
                }

                Logger.Sources.Remove(preloaderLogSource);
            }

            if (logListener != null)
            {
                Logger.Listeners.Add(logListener);
            }

            if (Utility.CurrentOs == Platform.Linux)
            {
                Logger.LogInfo($"Detected Unity version: v{Application.unityVersion}");
            }

            Logger.LogMessage("Chainloader ready");

            _initialized = true;
        }