Skip to main content
Hook a function by address.
The callback runs on the calling thread. Lua execution is serialized across threads. Callback errors are logged instead of propagating into the game.

hooks.Add

Installs an inline hook at address. Returns the original function as a callable FFI pointer of the same type. The callback must match the function type. On x64, __fastcall is suitable for all calling conventions.

hooks.Remove

Removes a hook by its target address. Restores the original function bytes. Unknown addresses are ignored silently. Hooks are matched only by address. Do not remove a hook from inside its own detour.

Calling the original

hooks.Add returns the original function as a typed FFI pointer. Call it like any other function:
Omit the call to replace the original function.

Lifecycle

  • hooks.Add is load-time only, same as events.On
  • Detours are uninstalled when a script is unloaded or disabled
  • Maximum 32 hooks per script
  • Cannot hook the address of a function inside Starline’s own module
  • The FFI callback stays alive until the hook is removed

Low-level API

For advanced use, the raw primitives are available:
hooks.Create takes two raw addresses and returns the trampoline address. Null, duplicate, and protected targets error. Installation failure returns nil, error. hooks.Add is built on top of these and handles FFI callback creation, type casting, and GC anchoring for you.