From cb72778a258afa48ad53080c0fe88e00fb31cc6a Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 14 Apr 2024 19:39:52 +0200 Subject: [PATCH] Core: allow launching dedicated server without terminal window The terminal window isn't always necessary, especially on Linux systems. In fact, it causes issues on some Wine environments. Allow user to disable it with -noconsole. This option only exists on the dedicated server. The client builds have the console disabled by default, and can enable them with -wconsole. --- r5dev/core/dllmain.cpp | 12 ++++++++---- r5dev/sdklauncher/basepanel.cpp | 7 +++++++ r5dev/windows/console.cpp | 14 ++++++++++---- r5dev/windows/console.h | 4 ++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 5415390a..819030ac 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -30,7 +30,9 @@ bool g_bSdkInitCallInitiated = false; bool g_bSdkShutdownCallInitiated = false; bool g_bSdkShutdownInitiatedFromConsoleHandler = false; -HMODULE s_hModuleHandle = NULL; + +static bool s_bConsoleInitialized = false; +static HMODULE s_hModuleHandle = NULL; //############################################################################# // UTILITY @@ -116,9 +118,11 @@ void SDK_Init() #ifndef DEDICATED if (CommandLine()->CheckParm("-wconsole")) -#endif // !DEDICATED +#else + if (!CommandLine()->CheckParm("-noconsole")) +#endif // !DEDICATED { - Console_Init(bAnsiColor); + s_bConsoleInitialized = Console_Init(bAnsiColor); } SpdLog_Init(bAnsiColor); @@ -186,7 +190,7 @@ void SDK_Shutdown() // If the shutdown was initiated from the console window itself, don't // shutdown the console as it would otherwise deadlock in FreeConsole! - if (!g_bSdkShutdownInitiatedFromConsoleHandler) + if (s_bConsoleInitialized && !g_bSdkShutdownInitiatedFromConsoleHandler) Console_Shutdown(); g_bSdkInitialized = false; diff --git a/r5dev/sdklauncher/basepanel.cpp b/r5dev/sdklauncher/basepanel.cpp index dae046c5..e145a917 100644 --- a/r5dev/sdklauncher/basepanel.cpp +++ b/r5dev/sdklauncher/basepanel.cpp @@ -109,6 +109,11 @@ void CSurface::Init() this->m_ConsoleToggle->SetSize({ 110, 18 }); this->m_ConsoleToggle->SetLocation({ 290, 7 }); this->m_ConsoleToggle->SetTabIndex(0); +#ifdef DEDI_LAUNCHER + this->m_ConsoleToggle->SetChecked(true); +#else // For client builds, don't show the console by default + this->m_ConsoleToggle->SetChecked(false); +#endif // DEDI_LAUNCHER this->m_ConsoleToggle->SetText("Show console"); this->m_ConsoleToggle->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left); this->m_GameGroupExt->AddControl(this->m_ConsoleToggle); @@ -968,6 +973,8 @@ void CSurface::AppendConsoleParameters(string& svParameters) { if (this->m_ConsoleToggle->Checked()) AppendParameterInternal(svParameters, "-wconsole"); + else + AppendParameterInternal(svParameters, "-noconsole"); if (this->m_ColorConsoleToggle->Checked()) AppendParameterInternal(svParameters, "-ansicolor"); diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index a0008c46..3324fd0c 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -77,8 +77,9 @@ void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color) //----------------------------------------------------------------------------- // Purpose: terminal window setup // Input : bAnsiColor - +// Output : true on success, false otherwise //----------------------------------------------------------------------------- -void Console_Init(const bool bAnsiColor) +bool Console_Init(const bool bAnsiColor) { #ifndef _TOOLS /////////////////////////////////////////////////////////////////////////// @@ -89,7 +90,7 @@ void Console_Init(const bool bAnsiColor) snprintf(szBuf, sizeof(szBuf), "Failed to create console window! [%s]\n", std::system_category().message(static_cast(::GetLastError())).c_str()); OutputDebugStringA(szBuf); - return; + return false; } //-- Set the window title @@ -133,12 +134,15 @@ void Console_Init(const bool bAnsiColor) #ifndef _TOOLS SetConsoleCtrlHandler(ConsoleHandlerRoutine, true); #endif // !_TOOLS + + return true; } //----------------------------------------------------------------------------- // Purpose: terminal window shutdown +// Output : true on success, false otherwise //----------------------------------------------------------------------------- -void Console_Shutdown() +bool Console_Shutdown() { /////////////////////////////////////////////////////////////////////////// // Destroy the console window @@ -148,8 +152,10 @@ void Console_Shutdown() snprintf(szBuf, sizeof(szBuf), "Failed to destroy console window! [%s]\n", std::system_category().message(static_cast(::GetLastError())).c_str()); OutputDebugStringA(szBuf); - return; + return false; } + + return true; } #ifndef _TOOLS diff --git a/r5dev/windows/console.h b/r5dev/windows/console.h index 6a0e4d41..bd7c6559 100644 --- a/r5dev/windows/console.h +++ b/r5dev/windows/console.h @@ -3,5 +3,5 @@ void SetConsoleBackgroundColor(COLORREF color); void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color); -void Console_Init(const bool bAnsiColor); -void Console_Shutdown(); +bool Console_Init(const bool bAnsiColor); +bool Console_Shutdown();