Don't show message boxes in headless mode

This commit is contained in:
momo5502 2023-05-16 17:59:56 +02:00
parent 636dce392f
commit 8eab31946d
12 changed files with 49 additions and 44 deletions

View File

@ -569,8 +569,7 @@ namespace arxan
if (!context) if (!context)
{ {
MessageBoxA(nullptr, utils::string::va("No frame offset for: %llX", handler_address), "Error", game::show_error(utils::string::va("No frame offset for: %llX", handler_address));
MB_ICONERROR);
TerminateProcess(GetCurrentProcess(), 0xBAD); TerminateProcess(GetCurrentProcess(), 0xBAD);
return current_checksum; return current_checksum;
} }
@ -807,7 +806,7 @@ namespace arxan
NTSTATUS zw_terminate_process_stub(const HANDLE process_handle, const NTSTATUS exit_status) 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<NTSTATUS>(process_handle, exit_status); return zw_terminate_process_hook.invoke<NTSTATUS>(process_handle, exit_status);
} }

View File

@ -4,7 +4,6 @@
#include "resource.hpp" #include "resource.hpp"
#include "game/game.hpp" #include "game/game.hpp"
#include "scheduler.hpp"
#include <utils/thread.hpp> #include <utils/thread.hpp>
#include <utils/hook.hpp> #include <utils/hook.hpp>
@ -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) void print_message_to_console(const char* message)
{ {
if (is_headless()) if (game::is_headless())
{ {
fputs(message, stdout); fputs(message, stdout);
return; return;
@ -133,7 +126,7 @@ namespace console
void sys_create_console_stub(const HINSTANCE h_instance) void sys_create_console_stub(const HINSTANCE h_instance)
{ {
if (is_headless()) if (game::is_headless())
{ {
return; return;
} }
@ -238,7 +231,7 @@ namespace console
void set_title(const std::string& title) void set_title(const std::string& title)
{ {
if (is_headless()) if (game::is_headless())
{ {
SetConsoleTitleA(title.data()); SetConsoleTitleA(title.data());
} }
@ -252,7 +245,7 @@ namespace console
{ {
component() component()
{ {
if (is_headless()) if (game::is_headless())
{ {
if (!AttachConsole(ATTACH_PARENT_PROCESS)) if (!AttachConsole(ATTACH_PARENT_PROCESS))
{ {

View File

@ -76,7 +76,7 @@ namespace exception
utils::thread::suspend_other_threads(); utils::thread::suspend_other_threads();
show_mouse_cursor(); 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); TerminateProcess(GetCurrentProcess(), exception_data.code);
} }

View File

@ -2,6 +2,7 @@
#include "game.hpp" #include "game.hpp"
#include <utils/flags.hpp>
#include <utils/finally.hpp> #include <utils/finally.hpp>
namespace game namespace game
@ -49,6 +50,24 @@ namespace game
return server; 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() std::filesystem::path get_appdata_path()
{ {
static const auto appdata_path = [] static const auto appdata_path = []

View File

@ -16,6 +16,10 @@ namespace game
bool is_client(); bool is_client();
bool is_legacy_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) inline size_t relocate(const size_t val)
{ {
if (!val) return 0; if (!val) return 0;

View File

@ -3,6 +3,8 @@
#include <utils/nt.hpp> #include <utils/nt.hpp>
#include "game/game.hpp"
namespace component_loader namespace component_loader
{ {
namespace namespace
@ -72,7 +74,7 @@ namespace component_loader
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); game::show_error(e.what());
return false; return false;
} }
@ -99,7 +101,7 @@ namespace component_loader
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); game::show_error(e.what());
return false; return false;
} }
@ -122,7 +124,7 @@ namespace component_loader
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); game::show_error(e.what());
return false; return false;
} }
@ -148,7 +150,7 @@ namespace component_loader
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); game::show_error(e.what());
return false; return false;
} }

View File

@ -47,8 +47,7 @@ namespace
const std::string steam_path = steam::SteamAPI_GetSteamInstallPath(); const std::string steam_path = steam::SteamAPI_GetSteamInstallPath();
if (steam_path.empty() || !::utils::io::file_exists(steam_path + "/steam.exe")) 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", game::show_error("Steam must be installed for the game to run. Please install Steam!");
MB_ICONERROR);
ShellExecuteA(nullptr, "open", "https://store.steampowered.com/about/", nullptr, nullptr, SW_SHOWNORMAL); ShellExecuteA(nullptr, "open", "https://store.steampowered.com/about/", nullptr, nullptr, SW_SHOWNORMAL);
TerminateProcess(GetCurrentProcess(), 1); TerminateProcess(GetCurrentProcess(), 1);
} }
@ -348,7 +347,7 @@ int main()
} }
catch (std::exception& e) catch (std::exception& e)
{ {
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); game::show_error(e.what());
return 1; return 1;
} }
} }

View File

@ -206,8 +206,6 @@ namespace steam
return &c; return &c;
} }
MessageBoxA(0, interfacename, __FUNCTION__, 0);
return nullptr; return nullptr;
} }

View File

@ -18,7 +18,7 @@ namespace updater
this->downloaded_files_.clear(); this->downloaded_files_.clear();
this->downloading_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_.set_title("BOIII Updater");
this->progress_ui_.show(false); this->progress_ui_.show(false);

View File

@ -4,6 +4,7 @@
#include <utils/concurrency.hpp> #include <utils/concurrency.hpp>
#include <utils/progress_ui.hpp> #include <utils/progress_ui.hpp>
#include <game/game.hpp>
namespace updater namespace updater
{ {
@ -19,7 +20,7 @@ namespace updater
std::vector<file_info> downloaded_files_{}; std::vector<file_info> downloaded_files_{};
std::unordered_map<std::string, std::pair<size_t, size_t>> downloading_files_{}; std::unordered_map<std::string, std::pair<size_t, size_t>> downloading_files_{};
utils::progress_ui progress_ui_{true}; utils::progress_ui progress_ui_{game::is_headless()};
void update_files(const std::vector<file_info>& files) override; void update_files(const std::vector<file_info>& files) override;
void done_update() override; void done_update() override;

View File

@ -4,27 +4,17 @@
namespace utils 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()) return;
{
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"};
}
} }
catch (...)
this->dialog_ = com::create_progress_dialog();
if (!this->dialog_)
{ {
if (!allow_failure) throw std::runtime_error{"Failed to create dialog"};
{
throw;
}
} }
} }

View File

@ -7,7 +7,7 @@ namespace utils
class progress_ui class progress_ui
{ {
public: public:
progress_ui(bool allow_failure); progress_ui(bool headless);
~progress_ui(); ~progress_ui();
void show(bool marquee, HWND parent = nullptr) const; void show(bool marquee, HWND parent = nullptr) const;