Pārlūkot izejas kodu

Add check for additional broken mono implementation of xterm

Bepis 4 gadi atpakaļ
vecāks
revīzija
8091b93219

+ 2 - 1
BepInEx.Preloader/RuntimeFixes/XTermFix.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection.Emit;
+using BepInEx.Unix;
 using HarmonyLib;
 using MonoMod.RuntimeDetour;
 using MonoMod.RuntimeDetour.Platforms;
@@ -16,7 +17,7 @@ namespace BepInEx.Preloader.RuntimeFixes
 			if (Utility.CurrentOs == Platform.Windows)
 				return;
 
-			if (typeof(Console).Assembly.GetType("System.ConsoleDriver") == null)
+			if (!LinuxConsoleDriver.UseMonoTtyDriver)
 			{
 				// Mono version is too old, use our own TTY implementation instead
 				return;

+ 14 - 4
BepInEx/Console/Unix/LinuxConsoleDriver.cs

@@ -1,6 +1,5 @@
 using System;
 using System.IO;
-using System.Text;
 using BepInEx.Logging;
 using HarmonyLib;
 using UnityInjector.ConsoleUtil;
@@ -9,13 +8,26 @@ namespace BepInEx.Unix
 {
 	internal class LinuxConsoleDriver : IConsoleDriver
 	{
+		public static bool UseMonoTtyDriver { get; }
+
+		static LinuxConsoleDriver()
+		{
+			UseMonoTtyDriver = false;
+
+			var consoleDriverType = typeof(Console).Assembly.GetType("System.ConsoleDriver");
+
+			if (consoleDriverType != null)
+			{
+				UseMonoTtyDriver = AccessTools.Method(consoleDriverType, "MangleParameters") == null;
+			}
+		}
+
 		public TextWriter StandardOut { get; private set; }
 		public TextWriter ConsoleOut { get; private set;  }
 
 		public bool ConsoleActive { get; private set; }
 		public bool ConsoleIsExternal => false;
 
-		public bool UseMonoTtyDriver { get; private set; }
 		public bool StdoutRedirected { get; private set; }
 
 		public TtyInfo TtyInfo { get; private set; }
@@ -24,8 +36,6 @@ namespace BepInEx.Unix
 		{
 			// Console is always considered active on Unix
 			ConsoleActive = true;
-			
-			UseMonoTtyDriver = typeof(Console).Assembly.GetType("System.ConsoleDriver") != null;
 
 			StdoutRedirected = UnixStreamHelper.isatty(1) != 1;