Преглед на файлове

Fix console not showing on Windows if stdout is not set

ghorsington преди 4 години
родител
ревизия
ebc63c09ec
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  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