mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Add GlueModuleAutoRegister + FUN_LOAD_GLUE_SCRIPT_FUNCTIONS hook
Module-self-registration pattern for the glue Lua state, mirroring the existing in-game ModuleAutoRegister. Modules opt in with a file-scope GlueModuleAutoRegister; the hook on FUN_0046ABB0 (master glue init, single caller, 35-byte linear function) fires their callbacks after the engine finishes registering its own 109 glue functions onto the freshly-created glue state. Prior attempt hooked the inner FUN_0046DDF0 60-fn batch trampoline and crashed on Octo, likely from sibling-DLL collision on a small target. The linear caller is larger and less obvious; no crash, hook fires cleanly on initial launch and every world->glue return.
This commit is contained in:
@@ -88,6 +88,17 @@ void RegisterGlobalFunction(const char *name, CFunction func) {
|
||||
fn(name, func);
|
||||
}
|
||||
|
||||
// Aliased to the same engine entry; the engine reads VAR_LUA_STATE
|
||||
// internally to decide which state to write to, and the glue hook
|
||||
// runs while that pointer is set to the glue state. Wrapped as a
|
||||
// named function (rather than `using RegisterGlueFunction = ...`) so
|
||||
// callers express intent at the call site.
|
||||
void RegisterGlueFunction(const char *name, CFunction func) {
|
||||
auto fn = reinterpret_cast<FrameScript_RegisterFunction_t>(
|
||||
Offsets::FUN_FRAMESCRIPT_REGISTER_FUNCTION);
|
||||
fn(name, func);
|
||||
}
|
||||
|
||||
void RegisterFrameMethods(void *context, const FrameMethodEntry *table, int count) {
|
||||
auto fn = reinterpret_cast<RegisterFrameMethods_t>(Offsets::FUN_REGISTER_FRAME_METHODS);
|
||||
fn(table, count, context);
|
||||
@@ -167,6 +178,7 @@ void SetGlobalNumber(void *L, const char *name, double value) {
|
||||
|
||||
namespace {
|
||||
ModuleAutoRegister *g_moduleHead = nullptr;
|
||||
GlueModuleAutoRegister *g_glueModuleHead = nullptr;
|
||||
HookAutoRegister *g_hookHead = nullptr;
|
||||
} // namespace
|
||||
|
||||
@@ -179,6 +191,16 @@ void RunModuleRegistrations() {
|
||||
node->fn();
|
||||
}
|
||||
|
||||
GlueModuleAutoRegister::GlueModuleAutoRegister(Fn f)
|
||||
: fn(f), next(g_glueModuleHead) {
|
||||
g_glueModuleHead = this;
|
||||
}
|
||||
|
||||
void RunGlueModuleRegistrations() {
|
||||
for (auto *node = g_glueModuleHead; node != nullptr; node = node->next)
|
||||
node->fn();
|
||||
}
|
||||
|
||||
HookAutoRegister::HookAutoRegister(uintptr_t target, void *hook, void **original)
|
||||
: target(target), hook(hook), original(original), next(g_hookHead) {
|
||||
g_hookHead = this;
|
||||
|
||||
Reference in New Issue
Block a user