From 8eab31946d4f04d63eb9948e22604f439ac4c604 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 16 May 2023 17:59:56 +0200 Subject: [PATCH] Don't show message boxes in headless mode --- src/client/component/arxan.cpp | 5 ++--- src/client/component/console.cpp | 15 ++++----------- src/client/component/exception.cpp | 2 +- src/client/game/game.cpp | 19 +++++++++++++++++++ src/client/game/game.hpp | 4 ++++ src/client/loader/component_loader.cpp | 10 ++++++---- src/client/main.cpp | 5 ++--- src/client/steam/steam.cpp | 2 -- src/client/updater/updater_ui.cpp | 2 +- src/client/updater/updater_ui.hpp | 3 ++- src/common/utils/progress_ui.cpp | 24 +++++++----------------- src/common/utils/progress_ui.hpp | 2 +- 12 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/client/component/arxan.cpp b/src/client/component/arxan.cpp index a5249b0e..e7926813 100644 --- a/src/client/component/arxan.cpp +++ b/src/client/component/arxan.cpp @@ -569,8 +569,7 @@ namespace arxan if (!context) { - MessageBoxA(nullptr, utils::string::va("No frame offset for: %llX", handler_address), "Error", - MB_ICONERROR); + game::show_error(utils::string::va("No frame offset for: %llX", handler_address)); TerminateProcess(GetCurrentProcess(), 0xBAD); return current_checksum; } @@ -807,7 +806,7 @@ namespace arxan NTSTATUS zw_terminate_process_stub(const HANDLE process_handle, const NTSTATUS exit_status) { - MessageBoxA(nullptr, "TERMINATING", nullptr, 0); + game::show_error("TERMINATING"); return zw_terminate_process_hook.invoke(process_handle, exit_status); } diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 584bbd5d..3410ccc7 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -4,7 +4,6 @@ #include "resource.hpp" #include "game/game.hpp" -#include "scheduler.hpp" #include #include @@ -53,15 +52,9 @@ namespace console }); } - bool is_headless() - { - static const auto headless = utils::flags::has_flag("headless"); - return headless; - } - void print_message_to_console(const char* message) { - if (is_headless()) + if (game::is_headless()) { fputs(message, stdout); return; @@ -133,7 +126,7 @@ namespace console void sys_create_console_stub(const HINSTANCE h_instance) { - if (is_headless()) + if (game::is_headless()) { return; } @@ -238,7 +231,7 @@ namespace console void set_title(const std::string& title) { - if (is_headless()) + if (game::is_headless()) { SetConsoleTitleA(title.data()); } @@ -252,7 +245,7 @@ namespace console { component() { - if (is_headless()) + if (game::is_headless()) { if (!AttachConsole(ATTACH_PARENT_PROCESS)) { diff --git a/src/client/component/exception.cpp b/src/client/component/exception.cpp index 98c4e7f9..36a8ad7e 100644 --- a/src/client/component/exception.cpp +++ b/src/client/component/exception.cpp @@ -76,7 +76,7 @@ namespace exception utils::thread::suspend_other_threads(); show_mouse_cursor(); - MessageBoxA(nullptr, error_str.data(), "BOIII ERROR", MB_ICONERROR); + game::show_error(error_str.data(), "BOIII ERROR"); TerminateProcess(GetCurrentProcess(), exception_data.code); } diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index bcd52d81..a8cfdb0e 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -2,6 +2,7 @@ #include "game.hpp" +#include #include namespace game @@ -49,6 +50,24 @@ namespace game return server; } + bool is_headless() + { + static const auto headless = utils::flags::has_flag("headless"); + return headless; + } + + void show_error(const std::string& text, const std::string& title) + { + if(is_headless()) + { + puts(text.data()); + } + else + { + MessageBoxA(nullptr, text.data(), title.data(), MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + } + } + std::filesystem::path get_appdata_path() { static const auto appdata_path = [] diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 1e7c80f2..5ee17230 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -16,6 +16,10 @@ namespace game bool is_client(); bool is_legacy_client(); + bool is_headless(); + + void show_error(const std::string& text, const std::string& title = "Error"); + inline size_t relocate(const size_t val) { if (!val) return 0; diff --git a/src/client/loader/component_loader.cpp b/src/client/loader/component_loader.cpp index 3b1471ef..2dda3687 100644 --- a/src/client/loader/component_loader.cpp +++ b/src/client/loader/component_loader.cpp @@ -3,6 +3,8 @@ #include +#include "game/game.hpp" + namespace component_loader { namespace @@ -72,7 +74,7 @@ namespace component_loader } catch (const std::exception& e) { - MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + game::show_error(e.what()); return false; } @@ -99,7 +101,7 @@ namespace component_loader } catch (const std::exception& e) { - MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + game::show_error(e.what()); return false; } @@ -122,7 +124,7 @@ namespace component_loader } catch (const std::exception& e) { - MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + game::show_error(e.what()); return false; } @@ -148,7 +150,7 @@ namespace component_loader } catch (const std::exception& e) { - MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + game::show_error(e.what()); return false; } diff --git a/src/client/main.cpp b/src/client/main.cpp index f7e1f799..233a0c3a 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -47,8 +47,7 @@ namespace const std::string steam_path = steam::SteamAPI_GetSteamInstallPath(); if (steam_path.empty() || !::utils::io::file_exists(steam_path + "/steam.exe")) { - MessageBoxA(nullptr, "Steam must be installed for the game to run. Please install Steam!", "Error", - MB_ICONERROR); + game::show_error("Steam must be installed for the game to run. Please install Steam!"); ShellExecuteA(nullptr, "open", "https://store.steampowered.com/about/", nullptr, nullptr, SW_SHOWNORMAL); TerminateProcess(GetCurrentProcess(), 1); } @@ -348,7 +347,7 @@ int main() } catch (std::exception& e) { - MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); + game::show_error(e.what()); return 1; } } diff --git a/src/client/steam/steam.cpp b/src/client/steam/steam.cpp index 1777ec2c..2ec028d1 100644 --- a/src/client/steam/steam.cpp +++ b/src/client/steam/steam.cpp @@ -206,8 +206,6 @@ namespace steam return &c; } - - MessageBoxA(0, interfacename, __FUNCTION__, 0); return nullptr; } diff --git a/src/client/updater/updater_ui.cpp b/src/client/updater/updater_ui.cpp index 2d3a2296..02d46615 100644 --- a/src/client/updater/updater_ui.cpp +++ b/src/client/updater/updater_ui.cpp @@ -18,7 +18,7 @@ namespace updater this->downloaded_files_.clear(); this->downloading_files_.clear(); - this->progress_ui_ = {true}; + this->progress_ui_ = {game::is_headless()}; this->progress_ui_.set_title("BOIII Updater"); this->progress_ui_.show(false); diff --git a/src/client/updater/updater_ui.hpp b/src/client/updater/updater_ui.hpp index a0afabb9..8692fb83 100644 --- a/src/client/updater/updater_ui.hpp +++ b/src/client/updater/updater_ui.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace updater { @@ -19,7 +20,7 @@ namespace updater std::vector downloaded_files_{}; std::unordered_map> downloading_files_{}; - utils::progress_ui progress_ui_{true}; + utils::progress_ui progress_ui_{game::is_headless()}; void update_files(const std::vector& files) override; void done_update() override; diff --git a/src/common/utils/progress_ui.cpp b/src/common/utils/progress_ui.cpp index 09b4a894..2728687b 100644 --- a/src/common/utils/progress_ui.cpp +++ b/src/common/utils/progress_ui.cpp @@ -4,27 +4,17 @@ namespace utils { - progress_ui::progress_ui(const bool allow_failure) + progress_ui::progress_ui(const bool headless) { - try + if (headless) { - if(utils::nt::is_wine()) - { - throw std::runtime_error{ "Disabled on wine" }; - } - - this->dialog_ = utils::com::create_progress_dialog(); - if (!this->dialog_) - { - throw std::runtime_error{"Failed to create dialog"}; - } + return; } - catch (...) + + this->dialog_ = com::create_progress_dialog(); + if (!this->dialog_) { - if (!allow_failure) - { - throw; - } + throw std::runtime_error{"Failed to create dialog"}; } } diff --git a/src/common/utils/progress_ui.hpp b/src/common/utils/progress_ui.hpp index 20112809..283368cc 100644 --- a/src/common/utils/progress_ui.hpp +++ b/src/common/utils/progress_ui.hpp @@ -7,7 +7,7 @@ namespace utils class progress_ui { public: - progress_ui(bool allow_failure); + progress_ui(bool headless); ~progress_ui(); void show(bool marquee, HWND parent = nullptr) const;