Metatable

Read and patch raw metatables, toggle table read-only state, and read or rewrite the namecall target while inside a hook.

Overview

Every Roblox instance shares one metatable, and it's locked read-only. Unlock it and you control every property read, property write and method call in the game.

__namecall is the big one. Roblox compiles object:Method(args) into one namecall instead of an index and then a call, so one hook there sees every method call, including FireServer and InvokeServer.

The usual namecall hook
local metatable = getrawmetatable(game)
local wasReadOnly = isreadonly(metatable)
setreadonly(metatable, false)

local old = metatable.__namecall
metatable.__namecall = newcclosure(function(self, ...)
    if getnamecallmethod() == "FireServer" and not checkcaller() then
        print("fired:", self:GetFullName(), ...)
    end
    return old(self, ...)
end)

setreadonly(metatable, wasReadOnly)

hookmetamethod does the unlock, swap and relock in one call, and it's what you should actually use. The manual version above is just worth reading once so you know what it's doing.

Namecall

Raw metatables

Read-only state

Metamethods

Which metamethod fires on which operation. These are just notes, not functions you call.