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)
{
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<NTSTATUS>(process_handle, exit_status);
}

View File

@ -4,7 +4,6 @@
#include "resource.hpp"
#include "game/game.hpp"
#include "scheduler.hpp"
#include <utils/thread.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)
{
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))
{

View File

@ -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);
}

View File

@ -2,6 +2,7 @@
#include "game.hpp"
#include <utils/flags.hpp>
#include <utils/finally.hpp>
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 = []

View File

@ -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;

View File

@ -3,6 +3,8 @@
#include <utils/nt.hpp>
#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;
}

View File

@ -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;
}
}

View File

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

View File

@ -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);

View File

@ -4,6 +4,7 @@
#include <utils/concurrency.hpp>
#include <utils/progress_ui.hpp>
#include <game/game.hpp>
namespace updater
{
@ -19,7 +20,7 @@ namespace updater
std::vector<file_info> downloaded_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 done_update() override;

View File

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

View File

@ -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;