From d1afc6ed0733b22bc77136c07ef86dbc5aef108b Mon Sep 17 00:00:00 2001 From: Stjepan Bakrac Date: Tue, 24 Oct 2017 14:34:50 +0200 Subject: [PATCH] Added hiding feature for --hide --- xiloader/console.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++ xiloader/console.h | 19 +++++++++++++++ xiloader/main.cpp | 10 ++++++++ 3 files changed, 85 insertions(+) diff --git a/xiloader/console.cpp b/xiloader/console.cpp index d1138e1..4bcb29a 100644 --- a/xiloader/console.cpp +++ b/xiloader/console.cpp @@ -23,8 +23,11 @@ This file is part of DarkStar-server source code. #include "console.h" +#include + /* Global Externs */ extern CRITICAL_SECTION g_CriticalSection; +extern bool g_Hide; namespace xiloader { @@ -134,4 +137,57 @@ namespace xiloader LeaveCriticalSection(&g_CriticalSection); } + /** + * @brief Shows or hides the console based on the provided argument. + * + * @param visible "true" to show the console, "false" to hide it. + */ + void console::visible(bool visible) + { + if (!g_Hide) + return; + + HWND console = GetConsoleWindow(); + + // Adjust the task bar + ITaskbarList* taskbar = nullptr; + HRESULT hr = CoCreateInstance( + CLSID_TaskbarList, + nullptr, + CLSCTX_INPROC_SERVER, + IID_ITaskbarList, + reinterpret_cast(&taskbar)); + if (SUCCEEDED(hr)) + { + if (visible) + { + taskbar->AddTab(console); + } + else + { + taskbar->DeleteTab(console); + } + taskbar->Release(); + } + + // Adjust the window's visibility + ShowWindow(console, visible ? SW_SHOW : SW_HIDE); + } + + /** + * @brief Hides the console window. + */ + void console::hide() + { + visible(false); + } + + /** + * @brief Shows the console window. + */ + void console::show() + { + visible(true); + } + }; // namespace xiloader diff --git a/xiloader/console.h b/xiloader/console.h index c585467..adbea04 100644 --- a/xiloader/console.h +++ b/xiloader/console.h @@ -101,6 +101,15 @@ namespace xiloader */ class console { + private: + + /** + * @brief Shows or hides the console based on the provided argument. + * + * @param visible "true" to show the console, "false" to hide it. + */ + static void visible(bool visible); + public: /** @@ -119,6 +128,16 @@ namespace xiloader * @param ... The arguments to fill the format. */ static void output(const xiloader::color::colors& c, const char* format, ...); + + /** + * @brief Hides the console window. + */ + static void hide(); + + /** + * @brief Shows the console window. + */ + static void show(); }; }; // namespace xiloader diff --git a/xiloader/main.cpp b/xiloader/main.cpp index 137d296..2f9b1cd 100644 --- a/xiloader/main.cpp +++ b/xiloader/main.cpp @@ -35,6 +35,7 @@ std::string g_Username = ""; // The username being logged in with. std::string g_Password = ""; // The password being logged in with. char* g_CharacterList = NULL; // Pointer to the character list data being sent from the server. bool g_IsRunning = false; // Flag to determine if the network threads should hault. +bool g_Hide = false; // Determines whether or not to hide the console window after FFXI starts. CRITICAL_SECTION g_CriticalSection; // Critical section object to prevent console logging issues from threads. /* Hairpin Fix Variables */ @@ -294,6 +295,13 @@ int __cdecl main(int argc, char* argv[]) continue; } + /* Hide Argument */ + if (!_strnicmp(argv[x], "--hide", 6)) + { + g_Hide = true; + continue; + } + xiloader::console::output(xiloader::color::warning, "Found unknown command argument: %s", argv[x]); } @@ -368,7 +376,9 @@ int __cdecl main(int argc, char* argv[]) { /* Attempt to start Final Fantasy.. */ IUnknown* message = NULL; + xiloader::console::hide(); ffxi->GameStart(polcore, &message); + xiloader::console::show(); ffxi->Release(); }