Parcourir la source

Fix console not showing on Windows if stdout is not set

ghorsington il y a 4 ans
Parent
commit
ebc63c09ec
1 fichiers modifiés avec 3 ajouts et 1 suppressions
  1. 3 1
      BepInEx/Console/Windows/WindowsConsoleDriver.cs

+ 3 - 1
BepInEx/Console/Windows/WindowsConsoleDriver.cs

@@ -26,8 +26,10 @@ namespace BepInEx
 		{
 			ConsoleWindow.Attach();
 
+			// If stdout exists, write to it, otherwise make it the same as console out
 			// Not sure if this is needed? Does the original Console.Out still work?
-			var originalOutStream = new FileStream(new SafeFileHandle(ConsoleWindow.OriginalStdoutHandle, false), FileAccess.Write);
+			var stdout = ConsoleWindow.OriginalStdoutHandle != IntPtr.Zero ? ConsoleWindow.OriginalStdoutHandle : ConsoleWindow.ConsoleOutHandle;
+			var originalOutStream = new FileStream(new SafeFileHandle(stdout, false), FileAccess.Write);
 			StandardOut = new StreamWriter(originalOutStream, new UTF8Encoding(false))
 			{
 				AutoFlush = true