/// <summary> /// Allocates a console window for use by BepInEx safely. /// </summary> public static void AllocateConsole() { if (!ConsoleWindow.ConfigConsoleEnabled.Value) { return; } try { ConsoleWindow.Attach(); var encoding = (uint)Encoding.UTF8.CodePage; if (ConsoleWindow.ConfigConsoleShiftJis.Value) { encoding = 932; } ConsoleEncoding.ConsoleCodePage = encoding; Console.OutputEncoding = ConsoleEncoding.GetEncoding(encoding); } catch (Exception ex) { Logger.LogError("Failed to allocate console!"); Logger.LogError(ex); } }
/// <summary> /// Allocates a console window for use by BepInEx safely. /// </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) { return; } try { ConsoleWindow.Attach(); var encoding = (uint)Encoding.UTF8.CodePage; if (shiftjis) { encoding = 932; } ConsoleEncoding.ConsoleCodePage = encoding; Console.OutputEncoding = ConsoleEncoding.GetEncoding(encoding); } catch (Exception ex) { Logger.LogError("Failed to allocate console!"); Logger.LogError(ex); } }
public void SetConsoleEncoding(uint codepage) { // Make sure of ConsoleEncoding helper class because on some Monos // Encoding.GetEncoding throws NotImplementedException on most codepages ConsoleEncoding.ConsoleCodePage = codepage; Console.OutputEncoding = ConsoleEncoding.GetEncoding(codepage); }
/// <summary> /// Initializes BepInEx to be able to start the chainloader. /// </summary> public static void Initialize(string gameExePath, bool startConsole = true) { 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 (ConsoleWindow.ConfigConsoleEnabled.Value && startConsole) { ConsoleWindow.Attach(); Logger.Listeners.Add(new ConsoleLogListener()); } // Fix for standard output getting overwritten by UnityLogger if (ConsoleWindow.StandardOut != null) { Console.SetOut(ConsoleWindow.StandardOut); var encoding = ConsoleWindow.ConfigConsoleShiftJis.Value ? 932 : (uint)Encoding.UTF8.CodePage; ConsoleEncoding.ConsoleCodePage = encoding; Console.OutputEncoding = ConsoleEncoding.GetEncoding(encoding); } 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()); } Logger.LogMessage("Chainloader ready"); _initialized = true; }
/// <summary> /// Initializes BepInEx to be able to start the chainloader. /// </summary> public static void Initialize(string containerExePath, bool startConsole = true) { if (_initialized) { return; } //Set vitals Paths.SetExecutablePath(containerExePath); Paths.SetPluginPath(ConfigPluginsDirectory.Value); //Start logging if (ConsoleWindow.ConfigConsoleEnabled.Value && startConsole) { ConsoleWindow.Attach(); Logger.Listeners.Add(new ConsoleLogListener()); } //Fix for standard output getting overwritten by UnityLogger if (ConsoleWindow.StandardOut != null) { Console.SetOut(ConsoleWindow.StandardOut); var encoding = ConsoleWindow.ConfigConsoleShiftJis.Value ? 932 : (uint)Encoding.UTF8.CodePage; ConsoleEncoding.ConsoleCodePage = encoding; Console.OutputEncoding = ConsoleEncoding.GetEncoding(encoding); } Logger.Listeners.Add(new UnityLogListener()); Logger.Listeners.Add(new DiskLogListener()); if (!TraceLogSource.IsListening) { Logger.Sources.Add(TraceLogSource.CreateSource()); } if (ConfigUnityLogging.Value) { Logger.Sources.Add(new UnityLogSource()); } Logger.LogMessage("Chainloader ready"); _initialized = true; }
/// <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 (ConsoleWindow.ConfigConsoleEnabled.Value && startConsole) { ConsoleWindow.Attach(); Logger.Listeners.Add(new ConsoleLogListener()); } // Fix for standard output getting overwritten by UnityLogger if (ConsoleWindow.StandardOut != null) { Console.SetOut(ConsoleWindow.StandardOut); var encoding = ConsoleWindow.ConfigConsoleShiftJis.Value ? 932 : (uint)Encoding.UTF8.CodePage; ConsoleEncoding.ConsoleCodePage = encoding; Console.OutputEncoding = ConsoleEncoding.GetEncoding(encoding); } 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) { preloaderLogSource.Log(preloaderLogEvent.Level, $"[{preloaderLogEvent.Source.SourceName,10}] {preloaderLogEvent.Data}"); } Logger.Sources.Remove(preloaderLogSource); } if (logListener != null) { Logger.Listeners.Add(logListener); } Logger.LogMessage("Chainloader ready"); _initialized = true; }