MEMORY
Hook
Redirects execution at an address to a Lua callback.
Syntax
local hookId = ONYX.Memory.Hook(address, signature, callback)Parameters
address(integer) — Target function address.signature(string) — Same format as Call: "<return><args>".callback(function) — Called on every invocation with getarg, setarg and call closures.
Return(s)
integer — hook slot id (0-31) used with Unhook.
Behavior
- Callback receives three closures: get(argIndex) reads an argument, set(argIndex, value) modifies it before the original runs, call() invokes the original with the current arguments.
- Return nil (or nothing) to let the original run normally; return a value to skip the original and return that value instead.
- Maximum 32 simultaneous hooks per environment, all removed when the environment is destroyed.
Example(s)
local hookId = ONYX.Memory.Hook(address, "l:pif", function(get, set, call)
local arg1 = get(1)
set(1, arg1 + 2)
return call()
end)