Hooks reference
This page describes how Augment.Hook intercepts game functions.
Execution model#
When you register a hook on a symbol, Augment builds a chain for that function:
caller invokes Foo::bar(...)
↓
[before hooks], priority ascending, skip original if ctx.cancelled = true
↓
original Foo::bar (may be skipped)
↓
[after hooks], priority ascending
↓
return to caller
A replace hook runs instead of the original:
Hook phases#
| Phase | When it runs | Can cancel? | Typical use |
|---|---|---|---|
before | Before the original | Yes, set ctx.cancelled = true | Change arguments, skip the call |
after | After the original | No | Change the return value |
replace | Instead of the original | N/A | Replace the function |
HookCtx#
Every hook callback gets a ctx table. Shape depends on the hooked function.
| Field | Type | Description |
|---|---|---|
ctx.self | struct proxy | this for methods. nil for free functions. |
ctx.cancelled | boolean | Set true in a before hook to skip the original. |
ctx.ret | depends | Return value. Readable in after, writable to change what the caller gets. |
| Named params | depends | Each argument by source name, e.g. ctx.speed. |
Struct views#
Struct fields (including ctx.self) are view proxies. Read and write fields by name:
Warning
Do not assign to a struct field slot like ctx.self. Write scalar fields on the proxy instead.
ctx only exposes names listed for that function. Invalid keys throw (ctx has no field '...'). See Debugging.
HookBuilder#
Augment.Hook["Symbol"] returns a HookBuilder. Chain phases on one builder:
.once(), fire once only#
Overload disambiguation#
If "Foo::bar" has multiple overloads, Hook["Foo::bar"] returns an ambiguous handle. Calling :before, :after, or :replace on it errors and lists matches.
Pick one with :sig(args). Do not use :at(file). Source-file picks break when code moves or the symbol map is regenerated. Use Game Hooks to find the parameter list you need.
:sig(args), pick by parameter types#
The signature string matches each overload's parameter list.
Priorities#
Augment.Mixin.register accepts a priority. Lower numbers run first in the same phase. Default is 0.
Augment.Hook always uses priority 0. Use Augment.Mixin when you need ordering.
Tags#
Optional debug labels on Mixin.register: