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
{
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

View File

@ -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", []()
{

View File

@ -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<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
{
public:
void post_load() override
component()
{
image_ = load_splash_image();
enable_dpi_awareness();
this->show();
}

View File

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

View File

@ -8,50 +8,88 @@ void component_loader::register_component(std::unique_ptr<component_interface>&&
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);
}
}

View File

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

View File

@ -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<BOOL(WINAPI*)(DPI_AWARENESS_CONTEXT)>(
"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;
}