Small fixes

This commit is contained in:
momo5502 2022-05-29 16:46:49 +02:00
parent cf889c402a
commit 7e616dd0ce
7 changed files with 90 additions and 51 deletions

View File

@ -572,7 +572,7 @@ namespace arxan
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void post_load() override void pre_start() override
{ {
hide_being_debugged(); hide_being_debugged();
scheduler::loop(hide_being_debugged, scheduler::pipeline::async); scheduler::loop(hide_being_debugged, scheduler::pipeline::async);
@ -608,11 +608,11 @@ namespace arxan
void post_unpack() override void post_unpack() override
{ {
patch_check_type_1_direct(); /*patch_check_type_1_direct();
patch_check_type_1_indirect(); patch_check_type_1_indirect();
patch_check_type_2(); patch_check_type_2();
patch_check_type_4(); patch_check_type_4();
patch_check_type_5(); patch_check_type_5();*/
} }
void pre_destroy() override void pre_destroy() override

View File

@ -150,7 +150,7 @@ namespace scheduler
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void post_load() override void pre_start() override
{ {
thread = utils::thread::create_named_thread("Async Scheduler", []() thread = utils::thread::create_named_thread("Async Scheduler", []()
{ {

View File

@ -13,15 +13,29 @@ namespace splash
const auto self = utils::nt::library::get_by_address(load_splash_image); const auto self = utils::nt::library::get_by_address(load_splash_image);
return LoadImageA(self, MAKEINTRESOURCE(IMAGE_SPLASH), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); 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<BOOL(WINAPI*)(DPI_AWARENESS_CONTEXT)>(
"SetProcessDpiAwarenessContext")
: nullptr;
if (set_dpi)
{
set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
}
} }
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void post_load() override component()
{ {
image_ = load_splash_image(); image_ = load_splash_image();
enable_dpi_awareness();
this->show(); this->show();
} }

View File

@ -5,7 +5,7 @@ class component_interface
public: public:
virtual ~component_interface() = default; virtual ~component_interface() = default;
virtual void post_load() virtual void pre_start()
{ {
} }

View File

@ -8,51 +8,89 @@ void component_loader::register_component(std::unique_ptr<component_interface>&&
get_components().push_back(std::move(component_)); get_components().push_back(std::move(component_));
} }
bool component_loader::post_load() bool component_loader::pre_start()
{ {
static auto handled = false; static auto res = []
if (handled) return true; {
handled = true;
clean(); clean();
try try
{ {
for (const auto& component_ : get_components()) for (const auto& component_ : get_components())
{ {
component_->post_load(); component_->pre_start();
} }
} }
catch (premature_shutdown_trigger&) catch (premature_shutdown_trigger&)
{ {
return false; return false;
} }
catch (const std::exception& e)
{
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR);
return false;
}
return true; return true;
}();
return res;
} }
void component_loader::post_unpack() void component_loader::post_unpack()
{ {
static auto handled = false; static auto res = []
if (handled) return; {
handled = true; clean();
try
{
for (const auto& component_ : get_components()) for (const auto& component_ : get_components())
{ {
component_->post_unpack(); 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() void component_loader::pre_destroy()
{ {
static auto handled = false; static auto res = []
if (handled) return; {
handled = true; clean();
try
{
for (const auto& component_ : get_components()) for (const auto& component_ : get_components())
{ {
component_->pre_destroy(); component_->pre_destroy();
} }
}
catch (const std::exception& e)
{
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR);
return false;
}
return true;
}();
if (!res)
{
TerminateProcess(GetCurrentProcess(), 1);
}
} }
void component_loader::clean() void component_loader::clean()

View File

@ -40,7 +40,7 @@ public:
static void register_component(std::unique_ptr<component_interface>&& component); static void register_component(std::unique_ptr<component_interface>&& component);
static bool post_load(); static bool pre_start();
static void post_unpack(); static void post_unpack();
static void pre_destroy(); static void pre_destroy();
static void clean(); static void clean();

View File

@ -62,19 +62,6 @@ namespace
utils::hook::set(game.get_iat_entry("kernel32.dll", "ExitProcess"), exit_hook); 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<BOOL(WINAPI*)(DPI_AWARENESS_CONTEXT)>(
"SetProcessDpiAwarenessContext")
: nullptr;
if (set_dpi)
{
set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
}
bool run() bool run()
{ {
srand(uint32_t(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId())); srand(uint32_t(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId()));
@ -91,10 +78,9 @@ namespace
try try
{ {
enable_dpi_awareness();
patch_imports(); patch_imports();
if (!component_loader::post_load()) if (!component_loader::pre_start())
{ {
return false; return false;
} }
@ -219,6 +205,7 @@ BOOL WINAPI DllMain(HINSTANCE, const DWORD reason, LPVOID)
{ {
patch_entry_point(); patch_entry_point();
} }
return TRUE; return TRUE;
} }