Browse Source

Fix console colors for .NET games

Bepis 4 years ago
parent
commit
572194dc90
2 changed files with 24 additions and 2 deletions
  1. 22 0
      BepInEx.Core/ConsoleManager.cs
  2. 2 2
      BepInEx.Core/Logging/ConsoleLogListener.cs

+ 22 - 0
BepInEx.Core/ConsoleManager.cs

@@ -2,6 +2,7 @@
 using System.IO;
 using System.Text;
 using BepInEx.Configuration;
+using BepInEx.ConsoleUtil;
 using UnityInjector.ConsoleUtil;
 
 namespace BepInEx
@@ -85,6 +86,27 @@ namespace BepInEx
 			}
 		}
 
+		public static void SetConsoleColor(ConsoleColor color)
+		{
+			if (!ConsoleActive)
+				throw new InvalidOperationException("Console is not currently active");
+
+			switch (Environment.OSVersion.Platform)
+			{
+				case PlatformID.Win32NT:
+				{
+					Kon.ForegroundColor = color;
+					break;
+				}
+				default:
+				{
+					break;
+				}
+			}
+
+			Console.ForegroundColor = color;
+		}
+
 		public static void ForceSetActive(bool value)
 		{
 			ConsoleActive = value;

+ 2 - 2
BepInEx.Core/Logging/ConsoleLogListener.cs

@@ -16,9 +16,9 @@ namespace BepInEx.Logging
 
 			string log = $"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}\r\n";
 
-			Kon.ForegroundColor = eventArgs.Level.GetConsoleColor();
+			ConsoleManager.SetConsoleColor(eventArgs.Level.GetConsoleColor());
 			Console.Write(log);
-			Kon.ForegroundColor = ConsoleColor.Gray;
+			ConsoleManager.SetConsoleColor(ConsoleColor.Gray);
 		}
 
 		public void Dispose() { }