Skip to content

Hooks and code

Same ideas as tweaks, from Lua.

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")')

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.

createMid runs before an instruction, with the registers in cpu.

hooks.createMid(target, function(hook, cpu)
cpu.rax = 999
end):enable()

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 })

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) end
local size = code.instructionLength(target)

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().

Hook callbacks run on whatever game thread called the function. Keep them short, since the game waits for them.

Made with ♥ by Asgard