Augment.Hook
Augment.Hook is the main module for gameplay hooks.
Loading#
Indexing by symbol name#
Augment.Hook is a proxy table. A flat symbol name returns a HookBuilder.
Symbol names:
- Use the C++ flat name:
"ClassName::methodName". ::is allowed. Template args and return types are omitted.- In TypeScript types,
::becomes_on theHookmodule (Hook.ClassName_methodName).
HookBuilder methods#
All methods return the builder itself, so calls can be chained.
:before(fn)#
Registers fn to run before the original function. If fn sets ctx.cancelled = true, the original is skipped.
:after(fn)#
Registers fn to run after the original function (or after a replace hook).
:replace(fn)#
Registers fn to run instead of the original function. The original is not called.
:once()#
Modifies the builder so registered hooks fire only on the first call, then are ignored.
Overload disambiguation#
When a symbol is ambiguous (multiple overloads exist), indexing Hook returns a special handle. Calling :before, :after, or :replace on it directly raises an error.
Disambiguate with :sig(signature). Do not use :at(file). File-based picks are brittle across builds and refactors. Look up the correct overload on Game Hooks and match its parameter list.
:sig(signature)#
Select the overload by its parameter types:
HookCtx fields#
The ctx argument passed to every hook callback has the following fields. Exact parameter names and types depend on the hooked function.
| Field | Type | Available in | Description |
|---|---|---|---|
ctx.self | struct proxy / nil | before, after, replace | this pointer for C++ methods only. Always nil for free functions. Use ctx.<paramName> instead (such as ctx.i_this) |
ctx.cancelled | boolean | before | Set true to skip the original call |
ctx.ret | scalar / struct proxy | after | Return value, write to change what the caller receives |
ctx.<paramName> | scalar / struct proxy / NativePtr | before, replace | Each parameter by its source name. For free functions this is the only way to access the receiver |
ctx.__fields | string[] | before, after, replace | Returns a sorted list of all valid field names on ctx. Useful for debugging unknown struct layouts |
Opaque pointer parameters#
When a parameter is declared as a struct pointer but the hook manifest has no field list for that view type, ctx.<paramName> returns the raw NativePtr instead of a field proxy.
Use Hook.readCString for char const*, or Augment.Mixin memory helpers when you need to read/write bytes at an offset. If you expected a field proxy, print ctx.__fields. When the view is opaque, the parameter will not expose nested keys.
Free functions vs methods#
For C++ methods, ctx.self is the this pointer. For free functions (such as daNi_Execute(ni_class* i_this, ...)), ctx.self is always nil. Access the actor through the named parameter instead:
If you're unsure what parameters are available, print ctx.__fields:
Reading a scalar parameter#
Reading a struct parameter#
Hook.readCString(value, maxLen?)#
Some parameters are exposed as NativePtr (for example char const* stage names). Use Hook.readCString to read them as a Luau string:
If value is already a string, it is returned unchanged. See also Courage.Hooks.readStageName.
Hook.View(structName, ptr)#
Creates a struct view proxy over a raw native pointer ptr (lightuserdata or NativePtr). This is the same proxy mechanism used automatically for ctx.self and struct hook parameters.
Typed hooks in TypeScript#
In TypeScript, hook symbols appear as properties of the Augment.Hook module. Each property is a HookBuilder<TCtx> where TCtx is the generated context interface for that function.
See the TypeScript guide for the full workflow.
Debugging hook mistakes#
Wrong ctx field names throw ctx has no field '...' and print a valid: list. Look up the symbol on Game Hooks, print ctx.__fields, or read Debugging.