mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Fix console on wine
This commit is contained in:
1 parent
266a2c87db
commit
1315427acd
2 files changed
+21
-25
No files matched your search
@@ -54,17 +54,19 @@ internal class ConsoleWindow
|
||||
if (OriginalStdoutHandle == IntPtr.Zero)
|
||||
OriginalStdoutHandle = GetStdHandle(-11);
|
||||
|
||||
// Store Current Window
|
||||
var currWnd = getForeground();
|
||||
|
||||
var cur = GetConsoleWindow();
|
||||
|
||||
//Check for existing console before allocating
|
||||
if (GetConsoleWindow() == IntPtr.Zero)
|
||||
if (cur == IntPtr.Zero)
|
||||
{
|
||||
// Store Current Window
|
||||
var currWnd = getForeground();
|
||||
|
||||
if (!AllocConsole())
|
||||
throw new Exception("AllocConsole() failed");
|
||||
// Restore Foreground
|
||||
setForeground(currWnd);
|
||||
|
||||
// Restore Foreground
|
||||
setForeground(currWnd);
|
||||
}
|
||||
|
||||
ConsoleOutHandle = CreateFile("CONOUT$", 0x80000000 | 0x40000000, 2, IntPtr.Zero, 3, 0, IntPtr.Zero);
|
||||
Kon.conOut = ConsoleOutHandle;
|
||||
|
||||
@@ -70,7 +70,7 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
|
||||
public void Initialize(bool alreadyActive, bool useManagedEncoder)
|
||||
{
|
||||
ConsoleActive = alreadyActive || TryCheckConsoleExists();
|
||||
ConsoleActive = alreadyActive;
|
||||
this.useManagedEncoder = useManagedEncoder;
|
||||
|
||||
if (ConsoleActive)
|
||||
@@ -119,6 +119,11 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
AutoFlush = true
|
||||
};
|
||||
ConsoleActive = true;
|
||||
|
||||
if (ReflectionHelper.IsCore)
|
||||
{
|
||||
Console.SetOut(ConsoleOut);
|
||||
}
|
||||
}
|
||||
|
||||
public void PreventClose() => ConsoleWindow.PreventClose();
|
||||
@@ -141,27 +146,16 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
|
||||
public void SetConsoleTitle(string title) => ConsoleWindow.Title = title;
|
||||
|
||||
private bool TryCheckConsoleExists()
|
||||
private static Stream OpenFileStream(IntPtr handle)
|
||||
{
|
||||
try
|
||||
if (ReflectionHelper.IsCore)
|
||||
{
|
||||
return ConsoleWidth != 0 && ConsoleHeight != 0;
|
||||
var windowsConsoleStreamType = Type.GetType("System.ConsolePal+WindowsConsoleStream, System.Console", true);
|
||||
var constructor = AccessTools.Constructor(windowsConsoleStreamType,
|
||||
new[] { typeof(IntPtr), typeof(FileAccess), typeof(bool) });
|
||||
return (Stream)constructor.Invoke(new object[] { handle, FileAccess.Write, true });
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
//System.IO.IOException: The handle is invalid.
|
||||
// at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean & succeeded)
|
||||
//at System.ConsolePal.get_WindowWidth()
|
||||
//at System.Console.get_WindowWidth()
|
||||
//at BepInEx.WindowsConsoleDriver.get_ConsoleWidth()
|
||||
//at BepInEx.WindowsConsoleDriver.Initialize(Boolean alreadyActive)
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static FileStream OpenFileStream(IntPtr handle)
|
||||
{
|
||||
var fileHandle = new SafeFileHandle(handle, false);
|
||||
var ctorParams = AccessTools.ActualParameters(FileStreamCtor,
|
||||
new object[]
|
||||
|
||||
Reference in new issue
Block a user