mirror of
https://github.com/JezuzLizard/T4SP-Server-Plugin.git
synced 2025-04-19 13:12:53 +00:00
Add scr init callback
This commit is contained in:
parent
fc336c490a
commit
7e87e04413
@ -1,5 +1,6 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "clientscript_public.hpp"
|
||||
#include <component/scheduler.hpp>
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4244)
|
||||
@ -4701,6 +4702,10 @@ namespace codsrc
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_InitSystem(game::scriptInstance_t inst)
|
||||
{
|
||||
// our additions
|
||||
scheduler::exec_pre_scr_init_funcs(inst);
|
||||
//
|
||||
|
||||
assert(!game::gScrVarPub[inst].timeArrayId);
|
||||
|
||||
//assert(!game::gScrVarPub[inst].ext_threadcount);
|
||||
@ -4726,6 +4731,10 @@ namespace codsrc
|
||||
assert(!game::gScrVarPub[inst].freeEntList);
|
||||
|
||||
game::g_script_error_level[inst] = -1;
|
||||
|
||||
// our additions
|
||||
scheduler::exec_post_scr_init_funcs(inst);
|
||||
//
|
||||
}
|
||||
|
||||
//Restored function
|
||||
|
@ -124,6 +124,45 @@ namespace scheduler
|
||||
com_init_hook.invoke<void>();
|
||||
on_post_init_hook();
|
||||
}
|
||||
|
||||
std::vector<std::function<void(game::scriptInstance_t)>> pre_scr_init_funcs;
|
||||
std::vector<std::function<void(game::scriptInstance_t)>> post_scr_init_funcs;
|
||||
|
||||
utils::hook::detour pre_scr_init_system_hook;
|
||||
utils::hook::detour post_scr_init_system_hook;
|
||||
|
||||
void* pre_scr_init_system_original;
|
||||
void* post_scr_init_system_original;
|
||||
|
||||
NAKED void pre_scr_init_system_stub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
pushad;
|
||||
push eax;
|
||||
call exec_pre_scr_init_funcs;
|
||||
add esp, 4;
|
||||
popad;
|
||||
|
||||
push pre_scr_init_system_original;
|
||||
ret;
|
||||
}
|
||||
}
|
||||
|
||||
NAKED void post_scr_init_system_stub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
pushad;
|
||||
push eax;
|
||||
call exec_post_scr_init_funcs;
|
||||
add esp, 4;
|
||||
popad;
|
||||
|
||||
push post_scr_init_system_original;
|
||||
ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void schedule(const std::function<bool()>& callback, const pipeline type,
|
||||
@ -171,6 +210,32 @@ namespace scheduler
|
||||
}
|
||||
}
|
||||
|
||||
void on_pre_scr_init_system(const std::function<void(game::scriptInstance_t)>& callback)
|
||||
{
|
||||
pre_scr_init_funcs.push_back(callback);
|
||||
}
|
||||
|
||||
void on_post_scr_init_system(const std::function<void(game::scriptInstance_t)>& callback)
|
||||
{
|
||||
post_scr_init_funcs.push_back(callback);
|
||||
}
|
||||
|
||||
void exec_pre_scr_init_funcs(game::scriptInstance_t inst)
|
||||
{
|
||||
for (const auto& func : pre_scr_init_funcs)
|
||||
{
|
||||
func(inst);
|
||||
}
|
||||
}
|
||||
|
||||
void exec_post_scr_init_funcs(game::scriptInstance_t inst)
|
||||
{
|
||||
for (const auto& func : post_scr_init_funcs)
|
||||
{
|
||||
func(inst);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -188,6 +253,12 @@ namespace scheduler
|
||||
com_init_hook.create(SELECT(0x0, 0x59D710), com_init_stub);
|
||||
utils::hook::call(SELECT(0x0, 0x503B5D), execute_server);
|
||||
utils::hook::call(SELECT(0x0, 0x59DCFD), execute_main);
|
||||
|
||||
// for when we dont use decomp
|
||||
pre_scr_init_system_hook.create(0x699865, pre_scr_init_system_stub);
|
||||
pre_scr_init_system_original = pre_scr_init_system_hook.get_original();
|
||||
post_scr_init_system_hook.create(0x699924, post_scr_init_system_stub);
|
||||
post_scr_init_system_original = post_scr_init_system_hook.get_original();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -21,4 +21,9 @@ namespace scheduler
|
||||
std::chrono::milliseconds delay = 0ms);
|
||||
|
||||
void on_init(const std::function<void()>& callback);
|
||||
|
||||
void on_pre_scr_init_system(const std::function<void(game::scriptInstance_t)>& callback);
|
||||
void on_post_scr_init_system(const std::function<void(game::scriptInstance_t)>& callback);
|
||||
void exec_pre_scr_init_funcs(game::scriptInstance_t inst);
|
||||
void exec_post_scr_init_funcs(game::scriptInstance_t inst);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user