Skip to content

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

lua
hookfunction(to_hook: function, hook: function) -> function
ParameterTypeDescription
to_hookfunctionThe function to hook
hookfunctionThe replacement function

Returns: The original (unhooked) function.

Example

lua
local old_print = hookfunction(print, function(...)
    old_print("[HOOKED]", ...)
end)

print("Hello") --> [HOOKED] Hello

hookmetamethod

Hooks a metamethod on an object's metatable. This is a convenience wrapper equivalent to hookfunction(getrawmetatable(object)[metamethod], hook).

lua
hookmetamethod(object: Instance | table, metamethod: string, hook: function) -> function
ParameterTypeDescription
objectInstance | tableThe object whose metatable to hook
metamethodstringThe metamethod name (e.g., "__index", "__namecall")
hookfunctionThe replacement function

Returns: The original metamethod function.

Example

lua
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.

lua
newcclosure(closure: function, name: string?) -> function
ParameterTypeDefaultDescription
closurefunctionThe Lua closure to wrap
namestring?nilOptional name for the closure

Example

lua
local wrapped = newcclosure(function()
    return "I'm a C closure now"
end)

print(iscclosure(wrapped)) --> true

clonefunction

Creates an independent clone of a function.

Aliases: clonefunc

lua
clonefunction(func: function) -> function
ParameterTypeDescription
funcfunctionThe function to clone

Example

lua
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

lua
restorefunction(func: function) -> void
ParameterTypeDescription
funcfunctionThe hooked function to restore

Example

lua
local old = hookfunction(print, function() end)
print("test") --> (nothing)

restorefunction(print)
print("test") --> test

isfunctionhooked

Returns true if the given function is currently hooked.

lua
isfunctionhooked(func: function) -> boolean

Example

lua
hookfunction(print, function() end)
print(isfunctionhooked(print)) --> true

restorefunction(print)
print(isfunctionhooked(print)) --> false

setstackhidden

Hides or unhides a function or stack level from the callstack. Useful for preventing detection in hooks.

lua
setstackhidden(target: function | number, hidden: boolean?) -> void
ParameterTypeDefaultDescription
targetfunction | numberThe closure or stack level to hide
hiddenboolean?trueWhether to hide (true) or unhide (false)

Example

lua
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.

lua
iscclosure(func: function) -> boolean

islclosure

Returns true if the given function is a Lua closure.

lua
islclosure(func: function) -> boolean

isnewcclosure

Returns true if the given function was created with newcclosure.

lua
isnewcclosure(func: function) -> boolean

isexecutorclosure

Returns true if the given function belongs to the executor (Volcano).

Aliases: isefunction, isourfunction, isourclosure, isvolcanofunction, checkclosure

lua
isexecutorclosure(func: function) -> boolean

Example

lua
print(iscclosure(print))           --> true
print(islclosure(function() end))  --> true
print(isexecutorclosure(hookfunction)) --> true

local wrapped = newcclosure(function() end)
print(isnewcclosure(wrapped)) --> true