hooknative tier
Lua callbacks on native functions; return nil to run the original, hooks die when their script unloads.
Functions
hook.vtable
hook.vtable(instance, index, abi, ret [, argtypes], callback) -> handle| Name | Type | Description |
|---|---|---|
| instance | integer | Object whose vtable is patched. |
| index | integer | 0-based slot, 0 to 1023. |
| abi | string | Usually "thiscall" for virtuals. |
| ret | string | Return type string. |
| argtypesoptional | table | this first for thiscall. Default {}. |
| callback | function | Returns nil or a replacement value. |
Swaps a vtable slot, catching virtual calls on every object sharing it.
Returns see fields
- Raises on a bad, empty or already hooked slot, or past 64 hooks.
- Unhook restores the slot only if it still holds this hook.
hook.detour
hook.detour(addr, abi, ret [, argtypes], callback) -> handle| Name | Type | Description |
|---|---|---|
| addr | integer | Real start of the function. |
| abi | string | "cdecl", "stdcall" or "thiscall". |
| ret | string | Return type string. |
| argtypesoptional | table | Default {}. |
| callback | function | Returns nil or a replacement value. |
Patches the function's entry with a jump, catching every caller.
Returns see fields
- addr must be a real function start; short functions or early branches fail.
- Raises if not executable, already detoured, or past 64 hooks.
hook.unhook_all
hook.unhook_all()Removes this script's hooks; other scripts keep theirs.
hook.count
hook.count() -> integerLive hooks across all scripts; the limit is 64.
handle:call
handle:call(...) -> value| Name | Type | Description |
|---|---|---|
| ... | any | Declared arguments, this included. |
Calls the un-hooked original, so a callback can alter its result.
Returns original's return value
Raises "hook: this hook is no longer active" after unhook.
handle:unhook
handle:unhook()Removes the hook; safe twice and from its own callback.
Fields
| Name | Type | Description |
|---|---|---|
| handle.active | boolean | true while installed. |
| handle.original | integer | Original slot or trampoline; 0 once unhooked. |
| handle.address | integer | Hooked slot or function; 0 once unhooked. |
| callback return | nil | value | nil runs the original; other values replace it. |
| callback rules | | Game thread, ~50 ms budget; errors run the original. |