Browse Source

Implement missing mscorlib console title property

Bepis 6 years ago
parent
commit
0aad00cadc

+ 2 - 1
BepInEx/Bootstrap/Chainloader.cs

@@ -7,6 +7,7 @@ using System.Linq;
 using System.Reflection;
 using BepInEx.Logging;
 using UnityEngine;
+using UnityInjector.ConsoleUtil;
 using UnityLogWriter = BepInEx.Logging.UnityLogWriter;
 
 namespace BepInEx.Bootstrap
@@ -52,7 +53,7 @@ namespace BepInEx.Bootstrap
                 Logger.SetLogger(unityLogWriter);
 
 			    string consoleTile = $"BepInEx {Assembly.GetExecutingAssembly().GetName().Version} - {Application.productName}";
-			    Console.Title = consoleTile;
+			    ConsoleWindow.Title = consoleTile;
                 
 				Logger.Log(LogLevel.Message, "Chainloader started");
 

+ 3 - 2
BepInEx/Bootstrap/Preloader.cs

@@ -9,6 +9,7 @@ using BepInEx.Common;
 using BepInEx.Logging;
 using Mono.Cecil;
 using Mono.Cecil.Cil;
+using UnityInjector.ConsoleUtil;
 using MethodAttributes = Mono.Cecil.MethodAttributes;
 
 namespace BepInEx.Bootstrap
@@ -98,15 +99,15 @@ namespace BepInEx.Bootstrap
             {
                 AppDomain.CurrentDomain.AssemblyResolve += LocalResolve;
                 ExecutablePath = args[0];
-                
+
                 AllocateConsole();
 
                 PreloaderLog = new PreloaderLogWriter(TryGetConfigBool("preloader-logconsole", "false"));
                 PreloaderLog.Enabled = true;
 
                 string consoleTile = $"BepInEx {Assembly.GetExecutingAssembly().GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
-                Console.Title = consoleTile;
 
+                ConsoleWindow.Title = consoleTile;
 
                 Logger.SetLogger(PreloaderLog);
                 

+ 23 - 0
BepInEx/ConsoleUtil/ConsoleWindow.cs

@@ -43,6 +43,26 @@ namespace UnityInjector.ConsoleUtil
             _attached = true;
         }
 
+        public static string Title
+        {
+            set
+            {
+                if (value == null)
+                {
+                    throw new ArgumentNullException(nameof(value));
+                }
+                if (value.Length > 24500)
+                {
+                    throw new InvalidOperationException("Console title too long");
+                }
+
+                if (!SetConsoleTitle(value))
+                {
+                    throw new InvalidOperationException("Console title invalid");
+                }
+            }
+        }
+
         public static void Detach()
         {
             if (!_attached)
@@ -104,5 +124,8 @@ namespace UnityInjector.ConsoleUtil
 
         [DllImport("kernel32.dll", SetLastError = true)]
         private static extern bool SetStdHandle(int nStdHandle, IntPtr hConsoleOutput);
+        
+        [DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Auto, SetLastError = true)]
+        private static extern bool SetConsoleTitle(string title);
     }
 }