Skip to content

Hooks

Hooks on the game’s code. Handlers run on the game thread that hit them, which waits. All put back when the plugin goes.

enable(): void
disable(): void
destroy(): void
original(): number
resume(): number

Fails with HookError.

Fails with HookError.

Puts the code back for good, waiting for calls in flight. Fine to call twice.

A function hook’s original, or a mid hook’s covered instructions, which carry on after.

Where a mid hook’s code carries on, like jmp resume. 0 for function hooks.

Get it with Api.hooks().

mid(target: number | bigint, options: import("salamander").Given<Wraith.Hooks.MidOptions>, handler: Wraith.Hooks.MidHandler): Wraith.Hook
detour(target: number | bigint, signature: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hook
detourSlot(slot: number | bigint, signature: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hook
named(name: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hook
context(): number
caller(): number
detourNative(target: number | bigint, detour: number | bigint, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hook
detourSlotNative(slot: number | bigint, detour: number | bigint, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hook
nativeHookCalls(): Wraith.Hooks.NativeCalls

Runs handler with the registers just before the code at target runs.

Fails with HookError. Uses Hooks.MidOptions, Hooks.MidHandler, Hook.

Sends calls at target to handler, a fn value of signature’s type, like [Thiscall] fn i32 (usize self, f32 amount). Scripts make one with salamander.fn.

Fails with HookError. Uses Hook.Options, Hook.

The same for the function pointer at slot, which gets swapped.

Fails with HookError. Uses Hook.Options, Hook.

A function or method the plugin’s schemas declare, like Player.heal, typed as declared. A [Virtual(n)] one swaps its slot in the struct’s [VirtualTable].

Fails with HookError. Uses Hook.Options, Hook.

The context of the hook whose handler’s running on this thread, or 0.

Where a native detour’s function was called from. Read it before anything that could enter a hook.

Sends calls at target to the native function at detour, which finds its hook through nativeCalls.

Fails with HookError. Uses Hook.Options, Hook.

The same for the function pointer at slot.

Fails with HookError. Uses Hook.Options, Hook.

Uses Hooks.NativeCalls.

What can go wrong, besides Cancelled, Unsupported and Gone.

Code Error
1 AlreadyHooked Someone else hooked it already
2 FunctionTooSmall
3 TargetModified It changed since it was looked at
4 UnexpectedBytes Not what expect said was there
5 InvalidSignature A signature that doesn’t parse, or can’t cross
6 WrongHandler A handler that isn’t a fn value of the signature’s type
7 InvalidPattern An expect that doesn’t parse
8 SplitsInstruction A size that ends inside an instruction
9 NotFound Not declared in the plugin’s schemas, or not found in the game
10 Failed

A struct, 0x18 bytes, aligned to 8.

Offset Field Type
0x0 context usize For the handler to read with context()
0x8 disabled bool Starts off rather than on
0xc stack_slots u32 A native detour’s stack arg slots, past any in registers, when stack_known. Else it’s passed as many as a hook can.
0x10 stack_known bool
context: number
disabled: boolean
stack_slots: number
stack_known: boolean

What a native detour’s enter gives, see Hooks.NativeCalls.

A struct, 0x20 bytes, aligned to 8.

Offset Field Type
0x0 hook usize The hook’s object data, for its Hook
0x8 original usize The original function, to call on
0x10 context usize
0x18 entered bool False while it’s being destroyed: just call original, and don’t leave.
hook: number
original: number
context: number
entered: boolean

A struct, 0x30 bytes, aligned to 8.

Offset Field Type
0x0 replace bool Replaces code there, so returning carries on after it. Else it runs before the instruction.
0x4 size u32 Bytes replaced, ending between instructions. 0 is what expect covers, or the one instruction.
0x8 expect string Bytes like 89 83 ?? ?? or asm like cmp ecx, eax that must be there. Empty skips the check.
0x18 disabled bool Starts off rather than on
0x20 names []Addresses.Name Before the address list’s, for expect
replace: boolean
size: number
expect: string
disabled: boolean
names: Array<Wraith.Addresses.Name>

Changes to the registers go back into the thread.

Wraith.Hooks.MidHandler

C functions for native detours, which bypass the plugin’s owner since a hook can be hit during unload. enter is fn () Hook.Call, called first; leave is fn (usize hook), called if it entered.

A struct, 0x10 bytes, aligned to 8.

Offset Field Type
0x0 enter usize
0x8 leave usize
enter: number
leave: number

Made with ♥ by Asgard