Hooking
Functions for intercepting, modifying, and managing function behavior. These allow you to replace functions with custom implementations while preserving access to the originals.
hookfunction
Hooks a Lua or C function, replacing it with a custom implementation. Returns the original function.
Aliases: hookfunc, replaceclosure
hookfunction(to_hook: function, hook: function) -> function| Parameter | Type | Description |
|---|---|---|
to_hook | function | The function to hook |
hook | function | The replacement function |
Returns: The original (unhooked) function.
Example
local old_print = hookfunction(print, function(...)
old_print("[HOOKED]", ...)
end)
print("Hello") --> [HOOKED] Hellohookmetamethod
Hooks a metamethod on an object's metatable. This is a convenience wrapper equivalent to hookfunction(getrawmetatable(object)[metamethod], hook).
hookmetamethod(object: Instance | table, metamethod: string, hook: function) -> function| Parameter | Type | Description |
|---|---|---|
object | Instance | table | The object whose metatable to hook |
metamethod | string | The metamethod name (e.g., "__index", "__namecall") |
hook | function | The replacement function |
Returns: The original metamethod function.
Example
local old_namecall
old_namecall = hookmetamethod(game, "__namecall", newcclosure(function(self, ...)
local method = getnamecallmethod()
if method == "Kick" then
return -- Block kick
end
return old_namecall(self, ...)
end))newcclosure
Wraps a Lua closure in a C closure. Useful for hooking C functions that validate their caller.
newcclosure(closure: function, name: string?) -> function| Parameter | Type | Default | Description |
|---|---|---|---|
closure | function | — | The Lua closure to wrap |
name | string? | nil | Optional name for the closure |
Example
local wrapped = newcclosure(function()
return "I'm a C closure now"
end)
print(iscclosure(wrapped)) --> trueclonefunction
Creates an independent clone of a function.
Aliases: clonefunc
clonefunction(func: function) -> function| Parameter | Type | Description |
|---|---|---|
func | function | The function to clone |
Example
local original = print
local cloned = clonefunction(print)
hookfunction(print, function() end) -- hook original
cloned("This still works!") --> This still works!restorefunction
Restores a hooked function to its original implementation.
Aliases: restorefunc
restorefunction(func: function) -> void| Parameter | Type | Description |
|---|---|---|
func | function | The hooked function to restore |
Example
local old = hookfunction(print, function() end)
print("test") --> (nothing)
restorefunction(print)
print("test") --> testisfunctionhooked
Returns true if the given function is currently hooked.
isfunctionhooked(func: function) -> booleanExample
hookfunction(print, function() end)
print(isfunctionhooked(print)) --> true
restorefunction(print)
print(isfunctionhooked(print)) --> falsesetstackhidden
Hides or unhides a function or stack level from the callstack. Useful for preventing detection in hooks.
setstackhidden(target: function | number, hidden: boolean?) -> void| Parameter | Type | Default | Description |
|---|---|---|---|
target | function | number | — | The closure or stack level to hide |
hidden | boolean? | true | Whether to hide (true) or unhide (false) |
Example
local hook = newcclosure(function(...)
-- This function won't appear in callstack
end)
setstackhidden(hook, true)Closure Type Checks
iscclosure
Returns true if the given function is a C closure.
iscclosure(func: function) -> booleanislclosure
Returns true if the given function is a Lua closure.
islclosure(func: function) -> booleanisnewcclosure
Returns true if the given function was created with newcclosure.
isnewcclosure(func: function) -> booleanisexecutorclosure
Returns true if the given function belongs to the executor (Volcano).
Aliases: isefunction, isourfunction, isourclosure, isvolcanofunction, checkclosure
isexecutorclosure(func: function) -> booleanExample
print(iscclosure(print)) --> true
print(islclosure(function() end)) --> true
print(isexecutorclosure(hookfunction)) --> true
local wrapped = newcclosure(function() end)
print(isnewcclosure(wrapped)) --> true