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(): voiddisable(): voiddestroy(): voidoriginal(): numberresume(): numberenable()disable()destroy()original(): integerresume(): integervoid Enable()void Disable()void Destroy()nuint Original()nuint Resume()sal::Result<void, Wraith::HookError> enable() constsal::Result<void, Wraith::HookError> disable() constvoid destroy() constuintptr_t original() constuintptr_t resume() constpub fn enable(&self) -> Result<(), wraith::HookError>pub fn disable(&self) -> Result<(), wraith::HookError>pub fn destroy(&self)pub fn original(&self) -> usizepub fn resume(&self) -> usizefn enable(self: Wraith.Hook) (Wraith.HookError || rt.Failure)!voidfn disable(self: Wraith.Hook) (Wraith.HookError || rt.Failure)!voidfn destroy(self: Wraith.Hook) voidfn original(self: Wraith.Hook) usizefn @"resume"(self: Wraith.Hook) usizeuint32_t Wraith_Hook_enable(Wraith_Hook self)uint32_t Wraith_Hook_disable(Wraith_Hook self)void Wraith_Hook_destroy(Wraith_Hook self)uintptr_t Wraith_Hook_original(Wraith_Hook self)uintptr_t Wraith_Hook_resume(Wraith_Hook self)enable
Section titled “enable”Fails with HookError.
disable
Section titled “disable”Fails with HookError.
destroy
Section titled “destroy”Puts the code back for good, waiting for calls in flight. Fine to call twice.
original
Section titled “original”A function hook’s original, or a mid hook’s covered instructions, which carry on after.
resume
Section titled “resume”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.Hookdetour(target: number | bigint, signature: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.HookdetourSlot(slot: number | bigint, signature: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hooknamed(name: string, handler: object | null, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.Hookcontext(): numbercaller(): numberdetourNative(target: number | bigint, detour: number | bigint, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.HookdetourSlotNative(slot: number | bigint, detour: number | bigint, options: import("salamander").Given<Wraith.Hook.Options>): Wraith.HooknativeHookCalls(): Wraith.Hooks.NativeCallsmid(target: integer, options: Wraith.Hooks.MidOptions, handler: Wraith.Hooks.MidHandler): Wraith.Hookdetour(target: integer, signature: string, handler: any, options: Wraith.Hook.Options): Wraith.HookdetourSlot(slot: integer, signature: string, handler: any, options: Wraith.Hook.Options): Wraith.Hooknamed(name: string, handler: any, options: Wraith.Hook.Options): Wraith.Hookcontext(): integercaller(): integerdetourNative(target: integer, detour: integer, options: Wraith.Hook.Options): Wraith.HookdetourSlotNative(slot: integer, detour: integer, options: Wraith.Hook.Options): Wraith.HooknativeHookCalls(): Wraith.Hooks.NativeCallsWraith.Hook? Mid(nuint target, Wraith.Hooks.MidOptions options, Wraith.Hooks.MidHandler? handler)Wraith.Hook? Detour(nuint target, string signature, Salamander.AnyObject handler, Wraith.Hook.Options options)Wraith.Hook? DetourSlot(nuint slot, string signature, Salamander.AnyObject handler, Wraith.Hook.Options options)Wraith.Hook? Named(string name, Salamander.AnyObject handler, Wraith.Hook.Options options)nuint Context()nuint Caller()Wraith.Hook? DetourNative(nuint target, nuint detour, Wraith.Hook.Options options)Wraith.Hook? DetourSlotNative(nuint slot, nuint detour, Wraith.Hook.Options options)Wraith.Hooks.NativeCalls NativeHookCalls()sal::Result<Wraith::Hook, Wraith::HookError> mid(uintptr_t target, Wraith::Hooks_MidOptions options, Wraith::Hooks_MidHandler handler) constsal::Result<Wraith::Hook, Wraith::HookError> detour(uintptr_t target, std::string_view signature, sal::Object handler, Wraith::Hook_Options options) constsal::Result<Wraith::Hook, Wraith::HookError> detourSlot(uintptr_t slot, std::string_view signature, sal::Object handler, Wraith::Hook_Options options) constsal::Result<Wraith::Hook, Wraith::HookError> named(std::string_view name, sal::Object handler, Wraith::Hook_Options options) constuintptr_t context() constuintptr_t caller() constsal::Result<Wraith::Hook, Wraith::HookError> detourNative(uintptr_t target, uintptr_t detour, Wraith::Hook_Options options) constsal::Result<Wraith::Hook, Wraith::HookError> detourSlotNative(uintptr_t slot, uintptr_t detour, Wraith::Hook_Options options) constWraith::Hooks_NativeCalls nativeHookCalls() constpub fn mid(&self, target: usize, options: wraith::HooksMidOptions, handler: wraith::HooksMidHandler) -> Result<wraith::Hook, wraith::HookError>pub fn detour(&self, target: usize, signature: &str, handler: salamander::Object, options: wraith::HookOptions) -> Result<wraith::Hook, wraith::HookError>pub fn detour_slot(&self, slot: usize, signature: &str, handler: salamander::Object, options: wraith::HookOptions) -> Result<wraith::Hook, wraith::HookError>pub fn named(&self, name: &str, handler: salamander::Object, options: wraith::HookOptions) -> Result<wraith::Hook, wraith::HookError>pub fn context(&self) -> usizepub fn caller(&self) -> usizepub fn detour_native(&self, target: usize, detour: usize, options: wraith::HookOptions) -> Result<wraith::Hook, wraith::HookError>pub fn detour_slot_native(&self, slot: usize, detour: usize, options: wraith::HookOptions) -> Result<wraith::Hook, wraith::HookError>pub fn native_hook_calls(&self) -> wraith::HooksNativeCallsfn mid(self: Wraith.Hooks, target: usize, options: Wraith.Hooks.MidOptions, handler: Wraith.Hooks.MidHandler) (Wraith.HookError || rt.Failure)!Wraith.Hookfn detour(self: Wraith.Hooks, target: usize, signature: []const u8, handler: rt.AnyObject, options: Wraith.Hook.Options) (Wraith.HookError || rt.Failure)!Wraith.Hookfn detourSlot(self: Wraith.Hooks, slot: usize, signature: []const u8, handler: rt.AnyObject, options: Wraith.Hook.Options) (Wraith.HookError || rt.Failure)!Wraith.Hookfn named(self: Wraith.Hooks, name: []const u8, handler: rt.AnyObject, options: Wraith.Hook.Options) (Wraith.HookError || rt.Failure)!Wraith.Hookfn context(self: Wraith.Hooks) usizefn caller(self: Wraith.Hooks) usizefn detourNative(self: Wraith.Hooks, target: usize, detour: usize, options: Wraith.Hook.Options) (Wraith.HookError || rt.Failure)!Wraith.Hookfn detourSlotNative(self: Wraith.Hooks, slot: usize, detour: usize, options: Wraith.Hook.Options) (Wraith.HookError || rt.Failure)!Wraith.Hookfn nativeHookCalls(self: Wraith.Hooks) Wraith.Hooks.NativeCallsuint32_t Wraith_Hooks_mid(Wraith_Hooks self, uintptr_t target, Wraith_Hooks_MidOptions options, Wraith_Hooks_MidHandler handler, Wraith_Hook *out)uint32_t Wraith_Hooks_detour(Wraith_Hooks self, uintptr_t target, sal_string signature, sal_object handler, Wraith_Hook_Options options, Wraith_Hook *out)uint32_t Wraith_Hooks_detourSlot(Wraith_Hooks self, uintptr_t slot, sal_string signature, sal_object handler, Wraith_Hook_Options options, Wraith_Hook *out)uint32_t Wraith_Hooks_named(Wraith_Hooks self, sal_string name, sal_object handler, Wraith_Hook_Options options, Wraith_Hook *out)uintptr_t Wraith_Hooks_context(Wraith_Hooks self)uintptr_t Wraith_Hooks_caller(Wraith_Hooks self)uint32_t Wraith_Hooks_detourNative(Wraith_Hooks self, uintptr_t target, uintptr_t detour, Wraith_Hook_Options options, Wraith_Hook *out)uint32_t Wraith_Hooks_detourSlotNative(Wraith_Hooks self, uintptr_t slot, uintptr_t detour, Wraith_Hook_Options options, Wraith_Hook *out)Wraith_Hooks_NativeCalls Wraith_Hooks_nativeHookCalls(Wraith_Hooks self)Runs handler with the registers just before the code at target runs.
Fails with HookError. Uses Hooks.MidOptions, Hooks.MidHandler, Hook.
detour
Section titled “detour”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.
detourSlot
Section titled “detourSlot”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.
context
Section titled “context”The context of the hook whose handler’s running on this thread, or 0.
caller
Section titled “caller”Where a native detour’s function was called from. Read it before anything that could enter a hook.
detourNative
Section titled “detourNative”Sends calls at target to the native function at detour, which finds its hook through nativeCalls.
Fails with HookError. Uses Hook.Options, Hook.
detourSlotNative
Section titled “detourSlotNative”The same for the function pointer at slot.
Fails with HookError. Uses Hook.Options, Hook.
nativeHookCalls
Section titled “nativeHookCalls”Uses Hooks.NativeCalls.
HookError
Section titled “HookError”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 |
Hook.Options
Section titled “Hook.Options”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: numberdisabled: booleanstack_slots: numberstack_known: booleancontext: integerdisabled: booleanstack_slots: integerstack_known: booleannuint ContextSalamander.Bool Disableduint StackSlotsSalamander.Bool StackKnownuintptr_t contextbool disableduint32_t stack_slotsbool stack_knownpub context: usizepub disabled: boolpub stack_slots: u32pub stack_known: boolcontext: usizedisabled: boolstack_slots: u32stack_known: booluintptr_t contextbool disableduint32_t stack_slotsbool stack_knownHook.Call
Section titled “Hook.Call”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: numberoriginal: numbercontext: numberentered: booleanhook: integeroriginal: integercontext: integerentered: booleannuint Hooknuint Originalnuint ContextSalamander.Bool Entereduintptr_t hookuintptr_t originaluintptr_t contextbool enteredpub hook: usizepub original: usizepub context: usizepub entered: boolhook: usizeoriginal: usizecontext: usizeentered: booluintptr_t hookuintptr_t originaluintptr_t contextbool enteredHooks.MidOptions
Section titled “Hooks.MidOptions”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: booleansize: numberexpect: stringdisabled: booleannames: Array<Wraith.Addresses.Name>replace: booleansize: integerexpect: stringdisabled: booleannames: (Wraith.Addresses.Name)[]bool Replaceuint Sizestring Expectbool DisabledWraith.Addresses.Name[] Namesbool replaceuint32_t sizesal::String expectbool disabledsal::Slice<Wraith::Addresses_Name> namespub replace: boolpub size: u32pub expect: salamander::Strpub disabled: boolpub names: salamander::Slice<wraith::AddressesName>replace: boolsize: u32expect: []const u8disabled: boolnames: []const Wraith.Addresses.Namebool replaceuint32_t sizesal_string expectbool disabledSlice_Wraith_Addresses_Name namesHooks.MidHandler
Section titled “Hooks.MidHandler”Changes to the registers go back into the thread.
Wraith.Hooks.MidHandlerWraith.Hooks.MidHandlerWraith.Hooks.MidHandlerWraith::Hooks_MidHandlerwraith::HooksMidHandlerWraith.Hooks.MidHandlerWraith_Hooks_MidHandlerHooks.NativeCalls
Section titled “Hooks.NativeCalls”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: numberleave: numberenter: integerleave: integernuint Enternuint Leaveuintptr_t enteruintptr_t leavepub enter: usizepub leave: usizeenter: usizeleave: usizeuintptr_t enteruintptr_t leavewraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
