Volt

oth.hook

Secure alternative to hookfunction for C functions. Hooks are executed on separate threads.

Syntax

oth.hook(target: function, hook: function) -> function

Parameters

ParameterTypeDescription
targetfunctionThe C function to hook
hookfunctionThe replacement function

Returns

TypeDescription
functionA reference to the original function

Description

oth.hook replaces the target C function with your hook function. Unlike hookfunction, hooks are executed on separate threads, providing better isolation and safety. The function returns a reference to the original, allowing you to call it from within your hook.

Example

-- Hook a C function
local originalFunc = oth.hook(someCFunction, function(...)
    print("Hooked call:", ...)
    return originalFunc(...)
end)

-- Call the original
originalFunc("test")

Thread Safety

local originalPrint = oth.hook(print, function(...)
    -- This runs on a separate thread
    if oth.is_hook_thread() then
        print("[HOOK THREAD]", ...)
    end
    return originalPrint(...)
end)

Notes

  • Only works with C functions (not Luau closures)
  • Hooks execute on separate threads for better isolation
  • Use oth.is_hook_thread() to detect hook context
  • The returned original can be called to bypass the hook
  • Remove hooks with oth.unhook

On this page