From 7e616dd0ce6b1d66d3292d97ccd8eb861787af2e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 29 May 2022 16:46:49 +0200 Subject: [PATCH] Small fixes --- src/client/component/arxan.cpp | 6 +- src/client/component/scheduler.cpp | 2 +- src/client/component/splash.cpp | 16 +++- src/client/loader/component_interface.hpp | 2 +- src/client/loader/component_loader.cpp | 94 ++++++++++++++++------- src/client/loader/component_loader.hpp | 4 +- src/client/main.cpp | 17 +--- 7 files changed, 90 insertions(+), 51 deletions(-) diff --git a/src/client/component/arxan.cpp b/src/client/component/arxan.cpp index 7cef4f74..ea894414 100644 --- a/src/client/component/arxan.cpp +++ b/src/client/component/arxan.cpp @@ -572,7 +572,7 @@ namespace arxan class component final : public component_interface { public: - void post_load() override + void pre_start() override { hide_being_debugged(); scheduler::loop(hide_being_debugged, scheduler::pipeline::async); @@ -608,11 +608,11 @@ namespace arxan void post_unpack() override { - patch_check_type_1_direct(); + /*patch_check_type_1_direct(); patch_check_type_1_indirect(); patch_check_type_2(); patch_check_type_4(); - patch_check_type_5(); + patch_check_type_5();*/ } void pre_destroy() override diff --git a/src/client/component/scheduler.cpp b/src/client/component/scheduler.cpp index 5aa6642e..47bda262 100644 --- a/src/client/component/scheduler.cpp +++ b/src/client/component/scheduler.cpp @@ -150,7 +150,7 @@ namespace scheduler class component final : public component_interface { public: - void post_load() override + void pre_start() override { thread = utils::thread::create_named_thread("Async Scheduler", []() { diff --git a/src/client/component/splash.cpp b/src/client/component/splash.cpp index 33de875b..a6fee292 100644 --- a/src/client/component/splash.cpp +++ b/src/client/component/splash.cpp @@ -13,15 +13,29 @@ namespace splash const auto self = utils::nt::library::get_by_address(load_splash_image); return LoadImageA(self, MAKEINTRESOURCE(IMAGE_SPLASH), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); } + + void enable_dpi_awareness() + { + const utils::nt::library user32{ "user32.dll" }; + const auto set_dpi = user32 + ? user32.get_proc( + "SetProcessDpiAwarenessContext") + : nullptr; + if (set_dpi) + { + set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + } + } } class component final : public component_interface { public: - void post_load() override + component() { image_ = load_splash_image(); + enable_dpi_awareness(); this->show(); } diff --git a/src/client/loader/component_interface.hpp b/src/client/loader/component_interface.hpp index 0478824e..43642a10 100644 --- a/src/client/loader/component_interface.hpp +++ b/src/client/loader/component_interface.hpp @@ -5,7 +5,7 @@ class component_interface public: virtual ~component_interface() = default; - virtual void post_load() + virtual void pre_start() { } diff --git a/src/client/loader/component_loader.cpp b/src/client/loader/component_loader.cpp index cac3c198..0bba4f4d 100644 --- a/src/client/loader/component_loader.cpp +++ b/src/client/loader/component_loader.cpp @@ -8,50 +8,88 @@ void component_loader::register_component(std::unique_ptr&& get_components().push_back(std::move(component_)); } -bool component_loader::post_load() +bool component_loader::pre_start() { - static auto handled = false; - if (handled) return true; - handled = true; - - clean(); - - try + static auto res = [] { - for (const auto& component_ : get_components()) + clean(); + + try { - component_->post_load(); + for (const auto& component_ : get_components()) + { + component_->pre_start(); + } + } + catch (premature_shutdown_trigger&) + { + return false; + } + catch (const std::exception& e) + { + MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR); + return false; } - } - catch (premature_shutdown_trigger&) - { - return false; - } - return true; + return true; + }(); + + return res; } void component_loader::post_unpack() { - static auto handled = false; - if (handled) return; - handled = true; - - for (const auto& component_ : get_components()) + static auto res = [] { - component_->post_unpack(); + clean(); + + try + { + for (const auto& component_ : get_components()) + { + component_->post_unpack(); + } + } + catch (const std::exception& e) + { + MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR); + return false; + } + + return true; + }(); + + if (!res) + { + TerminateProcess(GetCurrentProcess(), 1); } } void component_loader::pre_destroy() { - static auto handled = false; - if (handled) return; - handled = true; - - for (const auto& component_ : get_components()) + static auto res = [] { - component_->pre_destroy(); + clean(); + + try + { + for (const auto& component_ : get_components()) + { + component_->pre_destroy(); + } + } + catch (const std::exception& e) + { + MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR); + return false; + } + + return true; + }(); + + if (!res) + { + TerminateProcess(GetCurrentProcess(), 1); } } diff --git a/src/client/loader/component_loader.hpp b/src/client/loader/component_loader.hpp index 5d8ac64a..d7bce797 100644 --- a/src/client/loader/component_loader.hpp +++ b/src/client/loader/component_loader.hpp @@ -39,8 +39,8 @@ public: } static void register_component(std::unique_ptr&& component); - - static bool post_load(); + + static bool pre_start(); static void post_unpack(); static void pre_destroy(); static void clean(); diff --git a/src/client/main.cpp b/src/client/main.cpp index ded1eddc..f2278bf4 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -62,19 +62,6 @@ namespace utils::hook::set(game.get_iat_entry("kernel32.dll", "ExitProcess"), exit_hook); } - void enable_dpi_awareness() - { - const utils::nt::library user32{"user32.dll"}; - const auto set_dpi = user32 - ? user32.get_proc( - "SetProcessDpiAwarenessContext") - : nullptr; - if (set_dpi) - { - set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); - } - } - bool run() { srand(uint32_t(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId())); @@ -91,10 +78,9 @@ namespace try { - enable_dpi_awareness(); patch_imports(); - if (!component_loader::post_load()) + if (!component_loader::pre_start()) { return false; } @@ -219,6 +205,7 @@ BOOL WINAPI DllMain(HINSTANCE, const DWORD reason, LPVOID) { patch_entry_point(); } + return TRUE; }