Patch or inject?
Both change the game’s code. The difference is what happens to the instruction that’s already there.
@patchsays “replace this code with mine.”@injectsays “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" nopBy 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], eaxIt 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.
Inject
Section titled “Inject”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.
In JS or Lua
Section titled “In JS or Lua”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 endScript is easier for logic like that, but slower than asm. That only matters for code the game runs thousands of times a frame.
Where it goes next
Section titled “Where it goes next”Both get two built-in names, original and resume. They decide where the game carries on after your code.
originalis the old code, as it was.resumeis 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.
Whole functions
Section titled “Whole functions”@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)Which one?
Section titled “Which one?”| 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
