Hooks and code
Same ideas as tweaks, from Lua.
Finding things
Section titled “Finding things”addresses.resolve takes the same address text tweaks do.
local wraith = require("wraith")local addresses, hooks, code = wraith.addresses, wraith.hooks, wraith.code
local take_damage = addresses.resolve('sig("40 53 48 83 EC 20")')Hook a function
Section titled “Hook a function”Give it the function’s signature, where it is, and your replacement. Your function gets the hook first, then the arguments. hook:original calls the real one.
local hook = hooks.createFn("i32 (i32 damage)", take_damage, function(hook, damage) return hook:original(damage // 2)end)hook:enable()Hooks start off. Call enable() once it’s set up.
Hook an instruction
Section titled “Hook an instruction”createMid runs before an instruction, with the registers in cpu.
hooks.createMid(target, function(hook, cpu) cpu.rax = 999end):enable()Patch and inject
Section titled “Patch and inject”Asm, like in a tweak.
code.patch(target, "nop", { expect = "mov [rbx+0x98], eax", enabled = true })code.inject(target, "mov eax, [rbx+0x98]", { enabled = true })Read the code
Section titled “Read the code”code.disassemble gives the instructions at an address, with their bytes and text. It stops at memory it can’t read.
for _, i in ipairs(code.disassemble(target, 5)) do print(i.address, i.text) endlocal size = code.instructionLength(target)Breakpoints
Section titled “Breakpoints”code.breakpoint calls back each time an instruction’s about to run, using one of the CPU’s four debug registers. The game doesn’t stop, and the callback runs at the start of the next frame with a copy of the registers. To change them, use createMid.
code.breakpoint(target, function(hit) print("ran on thread", hit.thread, hit.cpu.rcx) end) :next(function(bp) breakpoint = bp end)Stop it with breakpoint:stop().
Threads
Section titled “Threads”Hook callbacks run on whatever game thread called the function. Keep them short, since the game waits for them.
Made with ♥ by Asgard
