xhookLua
Game

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
NameTypeDescription
instanceintegerObject whose vtable is patched.
indexinteger0-based slot, 0 to 1023.
abistringUsually "thiscall" for virtuals.
retstringReturn type string.
argtypesoptionaltablethis first for thiscall. Default {}.
callbackfunctionReturns 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
NameTypeDescription
addrintegerReal start of the function.
abistring"cdecl", "stdcall" or "thiscall".
retstringReturn type string.
argtypesoptionaltableDefault {}.
callbackfunctionReturns 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() -> integer

Live hooks across all scripts; the limit is 64.

handle:call

handle:call(...) -> value
NameTypeDescription
...anyDeclared 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

NameTypeDescription
handle.activebooleantrue while installed.
handle.originalintegerOriginal slot or trampoline; 0 once unhooked.
handle.addressintegerHooked slot or function; 0 once unhooked.
callback returnnil | valuenil runs the original; other values replace it.
callback rulesGame thread, ~50 ms budget; errors run the original.
hook ยท Lua API ยท xhook