Hooks and code
Same ideas as tweaks, from code.
Finding things
Section titled “Finding things”addresses.resolve takes the same address text tweaks do.
import { addresses } from "wraith";
const takeDamage = addresses.resolve('sig("40 53 48 83 EC 20")');const player = addresses.resolve("[game.exe+0x2F00A0] + 0x10");Hook a function
Section titled “Hook a function”Give it the function’s signature, where it is, and your replacement. this.original calls the real one.
import { hooks } from "wraith";
const hook = hooks.createFn("i32 (i32 damage)", takeDamage, function (damage) { return this.original(Math.floor(damage / 2));});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, (cpu) => { cpu.rax = 999;}).enable();Patch and inject
Section titled “Patch and inject”Asm, like in a tweak.
import { code } from "wraith";
code.patch(target, "nop", { expect: "mov [rbx+0x98], eax", enabled: true });code.inject(target, "mov eax, [rbx+0x98]", { enabled: true });code.asm lets you drop values into asm. Addresses and numbers go in as hex.
code.inject(target, code.asm`mov dword ptr [${player}], 100`, { 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 (const i of code.disassemble(target, 5)) log.info(i.address, i.text);const 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.
const bp = await code.breakpoint(target, (hit) => log.info("ran on thread", hit.thread, hit.cpu.rcx));await bp.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
