mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Add PreventClose option
Allows console implementations to prevent consoles from being closed which can cause accidental game closes
This commit is contained in:
1 parent
c88f838878
commit
1b6537b2a1
5 files changed
+42
No files matched your search
@@ -81,6 +81,9 @@ namespace BepInEx
|
||||
uint codepage = ConfigConsoleShiftJis.Value ? SHIFT_JIS_CP : (uint)Encoding.UTF8.CodePage;
|
||||
|
||||
Driver.CreateConsole(codepage);
|
||||
|
||||
if (ConfigPreventClose.Value)
|
||||
Driver.PreventClose();
|
||||
}
|
||||
|
||||
public static void DetachConsole()
|
||||
@@ -113,6 +116,11 @@ namespace BepInEx
|
||||
"Logging.Console", "Enabled",
|
||||
false,
|
||||
"Enables showing a console for log output.");
|
||||
|
||||
public static readonly ConfigEntry<bool> ConfigPreventClose = ConfigFile.CoreConfig.Bind(
|
||||
"Logging.Console", "PreventClose",
|
||||
false,
|
||||
"If enabled, will prevent closing the console (either by deleting the close button or in other platform-specific way).");
|
||||
|
||||
public static readonly ConfigEntry<bool> ConfigConsoleShiftJis = ConfigFile.CoreConfig.Bind(
|
||||
"Logging.Console", "ShiftJisEncoding",
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace BepInEx
|
||||
bool ConsoleActive { get; }
|
||||
bool ConsoleIsExternal { get; }
|
||||
|
||||
void PreventClose();
|
||||
|
||||
void Initialize(bool alreadyActive);
|
||||
|
||||
// Apparently Windows code-pages work in Mono.
|
||||
@@ -22,5 +24,7 @@ namespace BepInEx
|
||||
void SetConsoleColor(ConsoleColor color);
|
||||
|
||||
void SetConsoleTitle(string title);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ namespace BepInEx.Unix
|
||||
|
||||
public TtyInfo TtyInfo { get; private set; }
|
||||
|
||||
public void PreventClose()
|
||||
{
|
||||
// Not supported by all distros
|
||||
}
|
||||
|
||||
public void Initialize(bool alreadyActive)
|
||||
{
|
||||
// Console is always considered active on Unix
|
||||
|
||||
@@ -46,6 +46,17 @@ namespace UnityInjector.ConsoleUtil
|
||||
IsAttached = true;
|
||||
}
|
||||
|
||||
public static void PreventClose()
|
||||
{
|
||||
if (!IsAttached)
|
||||
return;
|
||||
|
||||
var hwnd = GetConsoleWindow();
|
||||
var hmenu = GetSystemMenu(hwnd, false);
|
||||
if (hmenu != IntPtr.Zero)
|
||||
DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
|
||||
}
|
||||
|
||||
public static string Title
|
||||
{
|
||||
set
|
||||
@@ -126,5 +137,14 @@ namespace UnityInjector.ConsoleUtil
|
||||
|
||||
[DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool SetConsoleTitle(string title);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
|
||||
|
||||
const UInt32 SC_CLOSE = 0xF060;
|
||||
const UInt32 MF_BYCOMMAND = 0x00000000;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,11 @@ namespace BepInEx
|
||||
public bool ConsoleActive { get; private set; }
|
||||
public bool ConsoleIsExternal => true;
|
||||
|
||||
public void PreventClose()
|
||||
{
|
||||
ConsoleWindow.PreventClose();
|
||||
}
|
||||
|
||||
public void Initialize(bool alreadyActive)
|
||||
{
|
||||
ConsoleActive = alreadyActive;
|
||||
|
||||
Reference in new issue
Block a user