Rename pre_start to post load and introduce pre_load event

This commit is contained in:
momo5502 2022-11-09 20:19:08 +01:00
parent c974e12731
commit 9a7b72dcd5
10 changed files with 50 additions and 11 deletions

View File

@ -698,7 +698,7 @@ namespace arxan
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void pre_start() override void post_load() override
{ {
auto* dll_characteristics = &utils::nt::library().get_optional_header()->DllCharacteristics; auto* dll_characteristics = &utils::nt::library().get_optional_header()->DllCharacteristics;
utils::hook::set<WORD>(dll_characteristics, *dll_characteristics | IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE); utils::hook::set<WORD>(dll_characteristics, *dll_characteristics | IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE);

View File

@ -456,7 +456,7 @@ namespace demonware
tcp_servers.create<umbrella_server>("prod.umbrella.demonware.net"); tcp_servers.create<umbrella_server>("prod.umbrella.demonware.net");
} }
void pre_start() override void post_load() override
{ {
register_hook("send", io::send_stub); register_hook("send", io::send_stub);
register_hook("recv", io::recv_stub); register_hook("recv", io::recv_stub);

View File

@ -202,7 +202,7 @@ namespace exception
SetUnhandledExceptionFilter(exception_filter); SetUnhandledExceptionFilter(exception_filter);
} }
void pre_start() override void post_load() override
{ {
const utils::nt::library ntdll("ntdll.dll"); const utils::nt::library ntdll("ntdll.dll");
auto* set_filter = ntdll.get_proc<void(*)(LPTOP_LEVEL_EXCEPTION_FILTER)>("RtlSetUnhandledExceptionFilter"); auto* set_filter = ntdll.get_proc<void(*)(LPTOP_LEVEL_EXCEPTION_FILTER)>("RtlSetUnhandledExceptionFilter");

View File

@ -32,7 +32,7 @@ namespace icon
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void pre_start() override void post_load() override
{ {
load_icon_a_hook.create(LoadIconA, load_icon_a_stub); load_icon_a_hook.create(LoadIconA, load_icon_a_stub);
} }

View File

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

View File

@ -188,7 +188,7 @@ namespace steam_proxy
class component final : public component_interface class component final : public component_interface
{ {
public: public:
void pre_start() override void post_load() override
{ {
load_client(); load_client();
perform_cleanup_if_needed(); perform_cleanup_if_needed();

View File

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

View File

@ -15,7 +15,7 @@ void component_loader::register_component(std::unique_ptr<component_interface>&&
}); });
} }
bool component_loader::pre_start() bool component_loader::pre_load()
{ {
static auto res = [] static auto res = []
{ {
@ -25,7 +25,36 @@ bool component_loader::pre_start()
{ {
for (const auto& component_ : get_components()) for (const auto& component_ : get_components())
{ {
component_->pre_start(); component_->pre_load();
}
}
catch (premature_shutdown_trigger&)
{
return false;
}
catch (const std::exception& e)
{
MessageBoxA(nullptr, e.what(), "Error", MB_ICONERROR);
return false;
}
return true;
}();
return res;
}
bool component_loader::post_load()
{
static auto res = []
{
clean();
try
{
for (const auto& component_ : get_components())
{
component_->post_load();
} }
} }
catch (premature_shutdown_trigger&) catch (premature_shutdown_trigger&)

View File

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

View File

@ -157,6 +157,11 @@ namespace
{ {
remove_crash_file(); remove_crash_file();
if (!component_loader::pre_load())
{
return 1;
}
entry_point = load_process("BlackOps3.exe"); entry_point = load_process("BlackOps3.exe");
if (!entry_point) if (!entry_point)
{ {
@ -165,7 +170,7 @@ namespace
patch_imports(); patch_imports();
if (!component_loader::pre_start()) if (!component_loader::post_load())
{ {
return 1; return 1;
} }