Bladeren bron

Fix stdout not being written to Unity log when console is enabled
Rebase of a404365

Bepis 4 jaren geleden
bovenliggende
commit
25887324b7
1 gewijzigde bestanden met toevoegingen van 12 en 0 verwijderingen
  1. 12 0
      BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs

+ 12 - 0
BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs

@@ -7,6 +7,15 @@ using HarmonyLib;
 
 namespace BepInEx.Preloader.Core.RuntimeFixes
 {
+	/*
+	 * By default, setting Console.Out removes the previous listener
+	 * This can be a problem in Unity because it installs its own TextWriter while BepInEx needs to install it
+	 * one too for the console. This runtime fix collects all Console.Out setters and aggregates them into a single
+	 * text writer.
+	 *
+	 * This allows to both fix the old problem with log overwriting and problem with writing stdout when console is
+	 * enabled.
+	 */
 	public static class ConsoleSetOutFix
 	{
 		private static AggregatedTextWriter aggregatedTextWriter;
@@ -22,6 +31,9 @@ namespace BepInEx.Preloader.Core.RuntimeFixes
 		[HarmonyPrefix]
 		private static bool OnSetOut(TextWriter newOut)
 		{
+			if (newOut == TextWriter.Null)
+				return false;
+
 			aggregatedTextWriter.Add(newOut);
 			return false;
 		}