Skip to content

Patch or inject?

Both change the game’s code. The difference is what happens to the instruction that’s already there.

  • @patch says “replace this code with mine.”
  • @inject says “run my code first, then carry on.”

The instruction at the address is gone, and yours runs instead.

@patch game.exe+0x1A2B3C expect "sub eax, edx"
nop

By default it replaces one instruction. To replace more, give a size like (8) or an expect that covers several.

@patch game.exe+0x1A2B3C expect "sub eax, edx; mov [rbx+0x98], eax"
mov [rbx+0x98], eax

It has to replace whole instructions. Shorter code gets padded with nops, and longer code is moved somewhere with room for it.

Always use expect. It checks the code is what you think before touching it, so a game update makes the tweak fail safely instead of crashing.

Your code runs, then the original instruction runs as normal.

@inject game.exe+0x1A2B3C
mov eax, [rbx+0x98]

That one sets eax to your current health just before the game writes it back. So the write changes nothing, and you don’t take damage.

Inject is the safer pick when you only want to nudge a value, since the game’s own code still does its thing. It doesn’t take expect or a size.

Either one can be script. Put @js or @lua on the first line and you get cpu with the registers.

@data
[Toggle] bool god = 1
@inject game.exe+0x1A2B3C
@js
if (data.god) cpu.rax = 999
@inject game.exe+0x1A2B3C
@lua
if data.god then cpu.rax = 999 end

Script is easier for logic like that, but slower than asm. That only matters for code the game runs thousands of times a frame.

Both get two built-in names, original and resume. They decide where the game carries on after your code.

  • original is the old code, as it was.
  • resume is just past it.

In asm, jump to them. In JS or Lua, call original() or resume() and it goes there once your code returns.

Runs off the end original resume
@patch Carries on after the replaced code Runs the old code instead of yours Same as running off the end
@inject Runs the instruction, then carries on Same as running off the end Skips the instruction

So running off the end does what you’d expect. A patch replaces the code and an inject goes before it. Reach for the other one when you only sometimes want that.

@hook swaps a function for JS or Lua. Call original to run the real one.

@hook sig("40 53 48 83 EC 20") as i32 (i32 damage)
return original(damage * 2)
You want to Use
Stop something from happening @patch with nop
Change a value before the game uses it @inject
Swap an instruction for a different one @patch
Change a function’s arguments or result @hook

Made with ♥ by Asgard