Code view referenceBack to the designer
controlstatementaddressnumberrow value

The designer's code view

The Blocks tab has a Blocks/Code switch. Code shows the selected row as plain statements you can read and edit. Apply (or Ctrl+Enter) turns the text back into the row's blocks, and Ctrl+Z undoes it. If a line cannot be read, nothing changes: the message names the line and the line is selected.

The code and the blocks are the same thing. Edit either one; the other follows.

for slot = 0 to 20
    u = ptr[main+0x82d938] + slot * 0x200
    if u8[u + 1] != 0xff and (u8[u + 5] & 0x30) == 0 then
        u16[u + 0x30] = u16[u + 0x32]
    end
end

That is FFT's Infinite HP: for each of the 21 battle slots, work out where the unit is, and if the slot is in use and the unit is on our team, set its HP to its max HP.

Memory

type[address] is the value of that type at that address. On the left of = it writes, anywhere else it reads.

u16[main+0x40] = 999
u32[main+0x44] = u32[main+0x44] + 100
typesizeholds
u8 u16 u32 u641, 2, 4, 8 byteswhole numbers, 0 and up
s8 s16 s32 s641, 2, 4, 8 byteswhole numbers that can be negative
f32 f644, 8 bytesdecimals (most game speeds and multipliers are f32)
ptr8 bytesan address

freeze keeps a value written. dmnt rewrites it continuously until the row is switched off.

freeze u32[heap+0x5a3c10] = 99

Addresses

written asmeans
main+0x1234offset into the game's code and data (moves with ASLR, handled for you)
heap+0x1234offset into the heap
alias+0x10, aslr+0x10offsets into those regions, rarely needed
0x7100001234a fixed address
[main+0x10]+0x8read the pointer at main+0x10, then add 8
[[main+0x10]+0x30]+0x8a pointer chain: read, add 0x30, read again, add 8
ptr[main+0x10] + 0x8the same as [main+0x10]+0x8
u + 0x30any expression works as an address
@namea shared address set up under Shared addresses
scan("1F 20 03 D5 ?? ?? 00 94")+0x8where that byte pattern is found in main, plus 8
scan("4D 41 50", heap)the same, searched in the heap

Square brackets mean "read the pointer stored here". Cheat Engine pointer chains map straight across: base main+0x2b63708, offsets 0x30, 0x8, 0xd4 becomes

u32[[[[main+0x2b63708]+0x30]+0x8]+0xd4] = 0x446d8000

If a pointer in the chain is 0 (a menu is closed, no battle is loaded), the read fails and the row stops with a message instead of writing somewhere random. Check it first when that is expected (see Examples).

Numbers and names

Numbers: 25, 0x19, -3, 2.5. The view prints counts and amounts in decimal and offsets, masks and large values in hex. You can type either.

Names hold a value for the rest of the block they are set in:

table = ptr[main+0x82d938]
unit = table + 5 * 0x200
u16[unit + 0x30] = 999

The first name = ... makes the name; later ones change it. let name = ... makes a new one with the same name inside a loop or if, leaving the outer one alone. You only need let when you mean that.

Built-in names:

nameis
valuethe number the row's slider or number box is set to, or the dropdown option picked (first option is 0)
main, heapwhere those regions start
sreg[0x7f]one of dmnt's 128 static registers (0x0 to 0x7f); keep values between rows, and are shared with .txt cheats, so use high ones
held(zl + r)true while all those buttons are held

Buttons for held(...): a b x y l r zl zr l3 r3 plus minus up down left right, and stick directions lstick_left lstick_up lstick_right lstick_down, rstick_left rstick_up rstick_right rstick_down.

In a dropdown with an Off option first, Off switches the row off; value is 0 for the first real option.

Operators

+ - * /arithmetic
== != < <= > >=comparisons, true or false
= <>also accepted in a condition, for == and !=
and orcombine conditions
& | ^bitwise and, or, xor (flags packed into a byte)
<< >>shift bits left, right
~flip every bit: x & ~0x08 clears bit 0x08
( )group

Bitwise operators bind tighter than comparisons. The view adds brackets next to a comparison anyway, so (flags & 0x30) == 0 reads the way it runs.

and checks both sides every time. Use nested ifs when the second check reads memory that only exists if the first is true:

table = ptr[main+0x82d938]
if table != 0 then
    if u8[table + 1] != 0xff then
        u16[table + 0x30] = 999
    end
end

Arithmetic is done at the width of what it works on: u8[x] + 1 is 8-bit and wraps from 255 to 0. A width written as u32( ... ) forces one. You mostly see it in cheats imported from .txt files, whose registers are 64-bit but whose adds are 32-bit:

r1 = 0
r1 = u32(r1 + 4)

Statements

statementdoes
u16[addr] = vwrite
freeze u16[addr] = vkeep written until the row is off
name = v, let name = vset a name
sreg[0x7f] = vset a static register
if c then ... else if c then ... else ... endconditions
for i = 0 to 20 ... endcount (always from 0)
repeat 5 times ... endrepeat
while c ... endloop while true
show v, show a out of b, show text at addr up to 16readouts
log vwrite a value to the trace (Debug)
pause the game, resume the gamestop the game while several writes land
patch ...change the game's code or data, undone when the row is off
hook addr ... endrun code when the game reaches an instruction

end closes if, for, repeat, while, hook and the block forms of patch. Indentation is only for reading. // starts a comment.

if value == 0 then
    u8[main+0x500] = 1         // easy
else if value == 1 then
    u8[main+0x500] = 2         // normal
else
    u8[main+0x500] = 3         // hard
end

Readouts

A readout row (Value, Pair, Text) shows what its body shows.

show u32[[main+0x2b63708]+0x30]
show u16[main+0x1030] out of u16[main+0x1032]
show text at heap+0xae9dd118 up to 16

Start a readout with show 0 when its checks can fail, so it shows 0 rather than whatever was left over.

Notifications

Notifications are opt-in feedback for an action or hotkey cheat. Add the notification after the writes, inside the same button and game-state checks. It is queued only when the complete VM call succeeds; a failed call discards its notifications. If a condition can skip the action, place its notification inside that condition too.

if held(zr) then
    u32[heap+0x100] = 80085
    notify "Changed"
end
notify "{name} has been changed" name at heap+0x400 up to 32

Only the literal {name} placeholder is replaced. The name binding points to NUL-terminated UTF-8 text; the byte limit is 1 through 64. Messages are bounded to 256 UTF-8 bytes. Static messages need no name binding.

The Designer's Notification section sits beside the hotkey settings. Check Show notification, enter a message and optional name binding, then Apply. Clearing the checkbox removes it. The shortcut preserves an existing notification's conditions; complex controls with several notifications or an ambiguous action are edited through their behavior blocks or code.

Notification controls run in the overlay, including their timers; keep it open, hidden or pinned. Closing it or opening another overlay stops those controls. The background helper cannot read controller buttons or display toasts. A hotkey notification is shown once per press; release the buttons to allow another one. An existing pack gains no automatic notifications: add them to its source and rebuild it. Use an updated overlay to display them; older overlays ignore the tagged TRACE instructions. Notifications belong to the trainer and do not change a game's separate Atmosphere cheat generator.

Loops

for slot = 0 to 20
    u16[ptr[main+0x82d938] + slot * 0x200 + 0x30] = 999
end
at = ptr[main+0x4a0010] + 0x100
repeat 20 times
    u16[at] = 99
    at = at + 2
end
node = ptr[main+0x123450]
while node != 0
    u32[node + 0x10] = 99
    node = ptr[node + 0x8]
end

A loop that never ends uses up the row's instruction budget and the row is switched off with a message, so a mistake cannot hang the game.

Patches

You can start from the game's instructions: load the matching main in Game setup, then choose Browse disassembly. The offline Disassembly view needs no console connection. Select an instruction to add a comment, function label or bookmark. Right-click it to create a code hook or an instruction patch and assign it to a new or existing trainer control. Hooks show editable assembly in the inspector; instruction patches also offer assembly editing. Raw patch bytes are under advanced details.

The editable project saves research notes, function labels, bookmarks and source, plus the main's hash and build ID. Keep the matching main alongside the project or reload it in Game setup. The binary and full disassembly are not duplicated in the project; instructions are decoded from the matching binary. Annotations from another image are kept but do not get applied to different instructions automatically.

Save project preserves unfinished Assembly, Script and hook-dialog drafts. Build applies valid edits before generating the pack; invalid edits stop generation and stay available to correct. Escape closes the hook dialog without discarding its draft.

For a new instruction hook, use the designer's automatic cave workflow: add a Toggle, Slider or Dropdown, choose Instruction hook (automatic cave) under Behavior, then load the matching game's main when asked. Enter the instruction you want to replace. The project keeps the assembly source. Building the pack calculates placement in available executable padding, accounts for other patches, and generates the hook branch and return. You do not enter the cave's placement address.

In the Assembly template field, use local labels and b back:

{original}
b finished
finished:
b back

{original} inserts the displaced instruction. b back returns after it. These tokens belong to the hook assembly editor. The Script view's raw patch ... with code form below uses explicit addresses and does not allocate cave space. It remains useful for existing imported cheats and advanced edits.

Preview the allocation, then Save hook. The inspector shows editable assembly; generated patch details are a preview. Building recalculates the placement from source, so preview addresses can change. Saving does not install it into the running game. If no verified executable padding fits, the designer refuses the hook. Captured pointers require separate verified writable padding; executable cave memory is not writable by game code.

A patch changes bytes in the game's code or data. The bytes it replaced are kept, so switching the row off puts them back, and a patch refuses a game build it was not made for.

One instruction:

patch main+0x70d04 to: mov w0, #2   // was: mov w0, #1

Several instructions, usually a code cave in the slack after the code:

patch main+0x656fe0 with code
    ldr x23, [x24]
    cbz x23, #0x656ff8
    ldrb w23, [x23, #5]
    and w23, w23, #0x30
    cbnz w23, #0x656ff8
    mov w0, wzr
    adrp x23, #0x831000
    b #0x347f6c
end
patch main+0x347f68 to: b #0x656fe0   // was: adrp x23, #0x831000

Bytes that are data, not code:

patch main+0x656ea4 to bytes 03000000
patch main+0x656cfc with bytes
    0b0040b96b05005108c0a072
    ff7f0039
end

Branch targets are absolute addresses in main (b #0x656fe0), the way the disassembly shows them. Put the cave before the branch that jumps to it, as above: the game may reach the branch the moment it is written.

The original bytes come from the game image the project has loaded. Without one, a patch keeps the original bytes of the patch it replaced in the same place; a new patch with neither cannot be undone.

Hooks

A hook runs statements every time the game reaches an instruction, with the game's registers available by name: x0-x30 (64-bit), w0-w30 (the same registers, 32-bit), s0-s31 and d0-d31 (floats), lr, fp, and sp (read only).

hook main+0x33b790
    if w11 > 0 then
        w11 = w11 * 2
    end
end

skip the hooked instruction continues after the instruction without running it, after you have set the register it would have set:

hook main+0x3a1f00
    w0 = 0
    skip the hooked instruction
end

Body, Opens at, Range

A row has up to three parts, picked above the code:

How often the body runs, the control type and its range are set in Properties, not in the code.

Limits

Examples

Step-by-step walkthroughs of real trainer rows, one for each kind of cheat (readout, pointer edit, instruction patch, code cave, shared cave, several cheats on one cave, multiplier, slider, editor, hotkey, loop), are at the end of the page the designer serves at /code-view and in its Examples tab. They come from src/nxc/designer/walkthroughs.py.

Addresses starting main+0x82d938, main+0x70d04, main+0x656... and main+0x33b7... are FFT's (Enhanced 1.5.1); the rest are placeholders.

Set a value once

An action row (mode action). Gold sits at the end of a pointer chain.

u32[[[main+0x2b63708]+0x30]+0x4c] = 9999999

Keep a value topped up

A toggle that runs every 100 ms.

hp = [[main+0x2b63708]+0x30]+0x10
if u32[hp] < u32[hp + 4] then
    u32[hp] = u32[hp + 4]
end

Only when it is safe to write

The chain only exists in a battle. Checking the first pointer keeps the row quiet outside one.

battle = ptr[main+0x2b63708]
if battle != 0 then
    party = ptr[battle + 0x30]
    if party != 0 then
        u32[party + 0x10] = 999
    end
end

A slider that edits a stat

Body:

u8[[main+0x82d938]+0x29] = value

Opens at:

show u8[[main+0x82d938]+0x29]

A number box for a large amount

Body of a Number row, range 0 to 9999999 in Properties:

u32[[[main+0x2b63708]+0x30]+0x4c] = value

A dropdown of settings

Options Normal, Fast, Very fast:

if value == 0 then
    f32[main+0x1c40a0] = 1.0
else if value == 1 then
    f32[main+0x1c40a0] = 2.0
else
    f32[main+0x1c40a0] = 4.0
end

A dropdown that patches code, with Off

FFT's Game Speed, options 2x, 3x, 5x, 10x with Off first. Each option patches the same two instructions. Switching from one option to another puts the game's instruction back first, because a patch only applies over the bytes it expects; Off undoes whichever is in place.

if u32[main+0x70d04] == 0x52800040 then
    u32[main+0x70d04] = 0x52800020
end
if u32[main+0x70d04] == 0x52800060 then
    u32[main+0x70d04] = 0x52800020
end
if value == 0 then
    patch main+0x70d04 to: mov w0, #2   // was: mov w0, #1
else if value == 1 then
    patch main+0x70d04 to: mov w0, #3   // was: mov w0, #1
end

Hold buttons to do something

A toggle every 150 ms. The overlay shows the buttons on the row, and it works with the overlay closed.

if held(r3 + y) then
    for slot = 0 to 20
        u = ptr[main+0x82d938] + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 5] & 0x30) != 0 then
            u16[u + 0x30] = 1
        end
    end
end
if held(zl + r) then
    xp = [[main+0x2b63708]+0x30]+0x20
    u32[xp] = u32[xp] + 1000
end

Flags packed into a byte

Turn bit 0x08 on, turn it off, flip it:

flags = u8[main+0x6000]
u8[main+0x6000] = flags | 0x08
flags = u8[main+0x6000]
u8[main+0x6000] = flags & ~0x08
u8[main+0x6000] = u8[main+0x6000] ^ 0x08

A team stored in bits 4-5 (0x00, 0x10, 0x20, 0x30), as FFT's Team dropdown writes it:

team = 0
if value == 0 then
    team = 0
else if value == 1 then
    team = 0x10
else if value == 2 then
    team = 0x20
else
    team = 0x30
end
flags = u8[main+0x6005]
u8[main+0x6005] = flags - (flags & 0x30) + team

Two rows sharing a choice

A picker stores which unit is picked in a static register; the editor rows read it. Picker body (a slider):

found = 0
result = 0
for slot = 0 to 20
    u = ptr[main+0x82d938] + slot * 0x200
    if u8[u + 1] != 0xff then
        if found == value then
            result = slot
        end
        found = found + 1
    end
end
sreg[0x7f] = result

Picker Range, so the slider offers only the units in this battle:

n = 0
for slot = 0 to 20
    u = ptr[main+0x82d938] + slot * 0x200
    if u8[u + 1] != 0xff then
        n = n + 1
    end
end
show n - 1

An editor row using the pick:

table = ptr[main+0x82d938]
if table != 0 then
    if sreg[0x7f] < 21 then
        unit = table + sreg[0x7f] * 0x200
        if u8[unit + 1] != 0xff then
            u16[unit + 0x30] = value
        end
    end
end

Its Opens at:

show 0
table = ptr[main+0x82d938]
if table != 0 then
    if sreg[0x7f] < 21 then
        unit = table + sreg[0x7f] * 0x200
        if u8[unit + 1] != 0xff then
            show u16[unit + 0x30]
        end
    end
end

A name readout

show 0
if sreg[0x7f] < 21 then
    show text at heap + (0xae9dd118 + sreg[0x7f] * 0x1c0) up to 16
end

A whole array

99 of every item in a 96-slot table of u8 counts:

items = ptr[main+0x1059b00]
for i = 0 to 95
    u8[items + i] = 99
end

A pattern instead of an offset

When an address moves between game versions, find it by the bytes around it:

u32[scan("E0 03 1F 2A ?? ?? ?? 94 F3 03 00 AA")+0x10] = 1

Several writes that must land together

pause the game
u32[main+0x7000] = 1
u32[main+0x7004] = 1
u32[main+0x7008] = 1
resume the game

A code cave with a branch to it

Perfect Dodge in FFT: the cave decides, the branch sends the game there. The cave goes first so the game never jumps into empty slack.

patch main+0x656fe0 with code
    ldr x23, [x24]
    cbz x23, #0x656ff8
    ldrb w23, [x23, #5]
    and w23, w23, #0x30
    cbnz w23, #0x656ff8
    mov w0, wzr
    adrp x23, #0x831000
    b #0x347f6c
end
patch main+0x347f68 to: b #0x656fe0   // was: adrp x23, #0x831000

A value the cave reads

The cave in the master row reads a multiplier from a word in slack; the dropdown only writes that word (0 means off, so the stored value is the multiplier plus one):

if value == 0 then
    patch main+0x656ea4 to bytes 01000000
else if value == 1 then
    patch main+0x656ea4 to bytes 03000000
else if value == 2 then
    patch main+0x656ea4 to bytes 04000000
end

Change a register instead of patching

A hook runs before the instruction it is on. FFT loads the HP damage into w11 at main+0x33b790, so hooking the instruction after it sees the loaded value and can change it before the game uses it:

hook main+0x33b794
    if w11 > 0 then
        w11 = w11 * 2
        if w11 > 9999 then
            w11 = 9999
        end
    end
end

Make a check always pass by setting what it returns and skipping it:

hook main+0x3a1f00
    w0 = 1
    skip the hooked instruction
end

Floats in a hook

hook main+0x1b55fe4
    s14 = s14 * 1.5
end

Step by step

One real trainer row for each kind of cheat, from finding it to the finished row. The same walkthroughs are in the designer's Examples tab, with a button that adds the row.

Readout: Show a value: Mira

A row that only reads: the overlay shows the party's mira and refreshes it twice a second. From Trails in the Sky 2nd Chapter, row “Mira”.

  1. Memory search: search u32 for the mira you have. Spend or earn some, search again for the new amount, repeat until one address is left.

  2. The address is in the heap and moves when the game restarts. Pointers: run a pointer search on it. Pick a chain that starts in main and survives a restart: here main+0x879628, then +0x20b648.

  3. Designer: add a Readout. In the Behavior editor's Script view, write what it shows. The brackets read the pointer at main+0x879628; +0x20b648 is where mira sits in what it points at.

    show u32[[main+0x879628]+0x20b648]
  4. Properties: choose Repeat on a timer, every 500 ms. Player preview shows the control; Build and install, and the overlay shows the number.

Finished, Body:

show u32[[main+0x879628]+0x20b648]

Pointer edit: Type a value: Set mira

A Number row: press A, type an amount on the keypad, and it is written through the pointer chain found for the readout. From Trails in the Sky 2nd Chapter, row “Set mira”.

  1. Start from the Mira readout: the chain is already found and checked.

  2. Designer: add a Number. Properties: choose When pressed or changed (it writes once each time you enter a value), range 0 to 9,999,999, which is the game's own cap.

  3. Behavior editor, Script, Actions: write the typed value to the same place.

    u32[[main+0x879628]+0x20b648] = value
  4. Behavior editor, Script, Starting value: show the current amount, so the keypad starts on it.

    show u32[[main+0x879628]+0x20b648]

Finished, Body:

u32[[main+0x879628]+0x20b648] = value

Finished, Opens at:

show u32[[main+0x879628]+0x20b648]

Values over the game's cap are clamped by the game the next time it adds mira, so the range stops there.

Flag for built-in code: Switch a cheat the IPS adds: Inf. HP

The FINAL FANTASY pixel remasters ship their cheats as an IPS patch that adds code to the game. Each cheat in it checks a flag word; the trainer row only sets the flag. From FINAL FANTASY, row “Inf. HP”.

  1. The IPS (installed with the cheats) adds the code. Every feature tests its own u32 flag in a block of words at main+0x293ef98 and does nothing while it is 0.

  2. A hidden always-on row ("IPS patch required...") writes 0 to every flag word each tick. That is what switches a feature off again: when its row stops writing 1, the next tick clears it.

    u64[main+0x293ef98] = 0
    u64[main+0x293efa0] = 0
    // ... one line per 8 bytes of flags
  3. The feature row is a toggle that writes its flag. Because the hidden row clears it, the overlay does not mark it one-way.

    u32[main+0x293ef9c] = 1

Finished, Body:

u32[main+0x293ef9c] = 1

Without the IPS installed the flag does nothing. The hidden row's name says so on purpose.

Instruction patch: Change one instruction: Infinite Air Jumps

An air jump is only allowed while the player has air jumps left. The instruction that loads that count is replaced with one that always loads 1. From Castlevania - Belmont's Curse Demo, row “Infinite Air Jumps”.

The published row writes the word 0x52800028 to main+0x20ffe88 as a plain write; this is the same bytes as a patch, which the designer would also turn it into.

  1. The check is JumpFeature.CanStart: an air jump needs availableAirJumps (+0x64 in the player's jump state) above 0. To find a check like it: Memory search for the count (it drops after an air jump, resets on landing), then a read watch on it in Disassembly / Debugger while jumping.

  2. The read is at main+0x20ffe88: ldr w8, [x21, #0x64]. Whatever lands in w8 is what the check compares.

  3. Load a constant the check accepts instead. Script: patch the instruction. The original is kept, so switching the row off puts it back.

    patch main+0x20ffe88 to: mov w8, #1   // was: ldr w8, [x21, #0x64]
  4. Properties: choose When switched on (written when switched on, undone when switched off).

Finished, Body:

patch main+0x20ffe88 to: mov w8, #1   // was: ldr w8, [x21, #0x64]

Instruction patch: Several instructions in one row: Always move

Four stores mark a unit as having moved. Making all four store zero means moving never uses up the turn. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Always move (moving does not end the turn)”.

  1. Find the field: in a battle, watch the unit record while a unit moves. unit+0x1b9 goes from 0 to 1.

  2. Debugger: a write watch on it, then move, wait and re-enter the menu. Four different instructions write it.

  3. Each one stores a register; make each store wzr (always zero) instead. One row, four patches: they are switched on and off together.

    patch main+0x353e74 to: strb wzr, [x20, #0x1b9]   // was: strb w27, [x20, #0x1b9]
    patch main+0x3543d0 to: strb wzr, [x8]   // was: strb w9, [x8]
    patch main+0x3544b4 to: strb wzr, [x0, #0x1b9]   // was: strb w8, [x0, #0x1b9]
    patch main+0x364a60 to: strb wzr, [x19, #0x1b9]   // was: strb w10, [x19, #0x1b9]

Finished, Body:

patch main+0x353e74 to: strb wzr, [x20, #0x1b9]
patch main+0x3543d0 to: strb wzr, [x8]
patch main+0x3544b4 to: strb wzr, [x0, #0x1b9]
patch main+0x364a60 to: strb wzr, [x19, #0x1b9]

Code cave: Add new code: Perfect Dodge

After the first evasion roll, new code makes the result a dodge when the defender is on our team, and leaves the game's roll otherwise. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Perfect Dodge (friendly units)”.

  1. Find the evasion roll: main+0x347f64 calls it and the result comes back in w0. The next instruction, at main+0x347f68 (adrp x23), is the hook; there x24 points at the defender pointer.

  2. One instruction cannot do this, so the new code goes in a cave: free space after the game's code (Code caves shows how much there is). FFT has 1,696 bytes at main+0x656960.

  3. Write the cave: load the defender, check its team bits (0x30 at +5; 0 is ours). Ours: set w0 to 0, which the game takes as a dodge. Either way, redo the adrp the branch replaced and go back. x23 is free to use because that adrp reloads it.

    patch main+0x656fe0 with code
        ldr x23, [x24]
        cbz x23, #0x656ff8
        ldrb w23, [x23, #5]
        and w23, w23, #0x30
        cbnz w23, #0x656ff8
        mov w0, wzr
        adrp x23, #0x831000
        b #0x347f6c
    end
  4. Then send the game there: replace the instruction at the hook with a branch to the cave. The cave comes first in the row so the game never jumps into empty space.

    patch main+0x347f68 to: b #0x656fe0   // was: adrp x23, #0x831000
  5. Properties: choose When switched on. Off restores both patches, branch first.

Finished, Body:

patch main+0x656fe0 with code
    ldr x23, [x24]
    cbz x23, #0x656ff8
    ldrb w23, [x23, #5]
    and w23, w23, #0x30
    cbnz w23, #0x656ff8
    mov w0, wzr
    adrp x23, #0x831000
    b #0x347f6c
end
patch main+0x347f68 to: b #0x656fe0

Shared code cave: One cave, several rows: Damage Dealt

The damage cave is installed once by the hidden master row and reads two multipliers from a pair of words. Damage Dealt and Damage Taken are separate dropdowns that only write their word. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Damage Dealt Multiplier”.

  1. Find the one place all HP damage goes through: main+0x33b790 loads it (ldrsh w11, [x8, #6]). Hooking the consumer covers every damage source at once.

  2. Write the cave in the master row (always on, hidden): replay the load, pick the dealt or taken word by the target's team, multiply, cap at 9999, store it back. A word of 0 means that ladder is off, so it keeps the multiplier plus one.

    patch main+0x656e58 with code
        ldrsh w11, [x8, #6]
        // ... picks the word at 0x656ea4 (dealt) or 0x656ea8 (taken)
        b #0x33b794
    end
    patch main+0x33b790 to: b #0x656e58
  3. Each dropdown writes its word. Options 0x, 2x, 3x, 5x, 10x, 99x store 1, 3, 4, 6, 11 and 100. Off first: Off puts the word back to 0 and the cave does nothing.

  4. Switching option: the first lines put the word back to 0 if it holds another option's value, so the new patch finds the bytes it expects.

    if u32[main+0x656ea4] == 3 then
        u32[main+0x656ea4] = 0
    end
    if value == 1 then
        patch main+0x656ea4 to bytes 03000000
    end

Finished, Body:

if u32[main+0x656ea4] == 1 then
    u32[main+0x656ea4] = 0
end
if u32[main+0x656ea4] == 3 then
    u32[main+0x656ea4] = 0
end
if u32[main+0x656ea4] == 4 then
    u32[main+0x656ea4] = 0
end
if u32[main+0x656ea4] == 6 then
    u32[main+0x656ea4] = 0
end
if u32[main+0x656ea4] == 11 then
    u32[main+0x656ea4] = 0
end
if u32[main+0x656ea4] == 100 then
    u32[main+0x656ea4] = 0
end
if value == 0 then
    patch main+0x656ea4 to bytes 01000000
end
if value == 1 then
    patch main+0x656ea4 to bytes 03000000
end
if value == 2 then
    patch main+0x656ea4 to bytes 04000000
end
if value == 3 then
    patch main+0x656ea4 to bytes 06000000
end
if value == 4 then
    patch main+0x656ea4 to bytes 0b000000
end
if value == 5 then
    patch main+0x656ea4 to bytes 64000000
end

The dropdown does nothing without the master row's cave.

Several cheats, one cave: Six cheats become one dropdown: JP Multiplier

The cheat file had JP gain 0x, 2x, 3x, 5x, 10x and 99x: six entries with the same cave, differing in two instructions. The trainer has one dropdown. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “JP Multiplier”.

  1. Compare the six cheats: the hook branches and most of the cave are identical; only the words at 0x656d98/0x656d9c and 0x656da4/0x656da8 differ (the multiply).

  2. Identical parts become patches that every option shares. They are applied once and lifted on Off.

    patch main+0x656d94 to: lsr w25, w28, #2
    patch main+0x656da0 to: b #0x367334
    patch main+0x656dac with code
        mov w1, w24
        b #0x367770
    end
  3. The differing words are written per option. They sit inside the cave, so they can go straight from one option to the next; once the branches are lifted nothing runs them.

    if value == 1 then
        u32[main+0x656d98] = 0x531f7b39   // lsl w25, w25, #1
        u32[main+0x656da4] = 0x531f7b18   // lsl w24, w24, #1
    end
  4. The branches into the cave come last, so the cave is complete before the game can reach it.

    patch main+0x367330 to: b #0x656d94   // was: lsr w25, w28, #2
    patch main+0x36776c to: b #0x656da4   // was: mov w1, w24
  5. Properties: Dropdown with Off first, When switched on, options 0x 2x 3x 5x 10x 99x. In trainer.py, ladder() builds this from the cheat file's six entries.

Finished, Body:

patch main+0x656d94 to: lsr w25, w28, #2
patch main+0x656da0 to: b #0x367334
patch main+0x656dac with code
    mov w1, w24
    b #0x367770
end
if value == 0 then
    u32[main+0x656d98] = 0x2a1f03f9
    u32[main+0x656d9c] = 0xd503201f
    u32[main+0x656da4] = 0x2a1f03f8
    u32[main+0x656da8] = 0xd503201f
end
if value == 1 then
    u32[main+0x656d98] = 0x531f7b39
    u32[main+0x656d9c] = 0xd503201f
    u32[main+0x656da4] = 0x531f7b18
    u32[main+0x656da8] = 0xd503201f
end
if value == 2 then
    u32[main+0x656d98] = 0xb190739
    u32[main+0x656d9c] = 0xd503201f
    u32[main+0x656da4] = 0xb180718
    u32[main+0x656da8] = 0xd503201f
end
if value == 3 then
    u32[main+0x656d98] = 0xb190b39
    u32[main+0x656d9c] = 0xd503201f
    u32[main+0x656da4] = 0xb180b18
    u32[main+0x656da8] = 0xd503201f
end
if value == 4 then
    u32[main+0x656d98] = 0x531f7b39
    u32[main+0x656d9c] = 0xb190b39
    u32[main+0x656da4] = 0x531f7b18
    u32[main+0x656da8] = 0xb180b18
end
if value == 5 then
    u32[main+0x656d98] = 0xb190739
    u32[main+0x656d9c] = 0xb191739
    u32[main+0x656da4] = 0xb180718
    u32[main+0x656da8] = 0xb181718
end
patch main+0x367330 to: b #0x656d94
patch main+0x36776c to: b #0x656da4

Multiplier: A multiplier in one instruction: Money Multiplier

The game adds earned units with adds w8, w1, w8. Shifting the earned amount left by 1, 2 or 3 before adding gives 2x, 4x or 8x. From No Man's Sky, row “Money Multiplier”.

The published row is the older folded form: Off is the first option and writes the game's word back. This is the same instruction words with Off-first, as the FFT ladders do it.

  1. The add is at main+0x3fb368: adds w8, w1, w8, the amount being credited (w1) plus the balance (w8). The cheat file finds it by signature. To find one like it: Memory search for the balance, earn some, then a write watch on it; the add is just before the store.

  2. ARM can shift one operand for free: adds w8, w8, w1, lsl #1 adds twice the amount. lsl #2 is 4x, lsl #3 is 8x.

  3. A Dropdown with Off first, When switched on. Each option patches the same instruction, so switching first puts the game's own instruction back if another option's is there.

    if value == 0 then
        patch main+0x3fb368 to: adds w8, w8, w1, lsl #1
    end

Finished, Body:

if u32[main+0x3fb368] == 0x2b010508 then
    u32[main+0x3fb368] = 0x2b080028
end
if u32[main+0x3fb368] == 0x2b010908 then
    u32[main+0x3fb368] = 0x2b080028
end
if u32[main+0x3fb368] == 0x2b010d08 then
    u32[main+0x3fb368] = 0x2b080028
end
if value == 0 then
    patch main+0x3fb368 to: adds w8, w8, w1, lsl #1
end
if value == 1 then
    patch main+0x3fb368 to: adds w8, w8, w1, lsl #2
end
if value == 2 then
    patch main+0x3fb368 to: adds w8, w8, w1, lsl #3
end

Slider: A slider that starts where the game is: Brave

Sets the edited unit's Brave. It opens on the unit's current Brave, so nudging it adjusts rather than overwrites. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Brave”.

  1. Find the field in the unit record: Brave is at +0x2b, with the battle's starting copy at +0x2a. Both are written, or the status screen and the engine disagree.

  2. Designer: add a Slider, range 0 to 100, When pressed or changed.

  3. Actions: find the unit being edited (see the editor walkthrough), then write both copies.

    unit = ptr[main+0x82d938] + sreg[0x7f] * 0x200
    u8[unit + 0x2b] = value
    u8[unit + 0x2a] = value
  4. Starting value: show 0 first, so a failed check opens the slider at 0 rather than at whatever was left over; then show the real value.

Finished, Body:

table = ptr[main+0x82d938]
if table != 0 then
    if sreg[0x7f] < 21 then
        unit = table + sreg[0x7f] * 0x200
        if u8[unit + 1] != 0xff and (u8[unit + 0x29] > 0 and u16[unit + 0x32] > 0) then
            u8[unit + 0x2b] = value
            u8[unit + 0x2a] = value
        end
    end
end

Finished, Opens at:

show 0
table = ptr[main+0x82d938]
if table != 0 then
    if sreg[0x7f] < 21 then
        unit = table + sreg[0x7f] * 0x200
        if u8[unit + 1] != 0xff and (u8[unit + 0x29] > 0 and u16[unit + 0x32] > 0) then
            show u8[unit + 0x2b]
        end
    end
end

Editor: A unit editor: pick a unit, then edit it

A slider picks one of the units in this battle. The pick goes in a static register that every editor row reads. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Editing unit”.

  1. The battle's units are 21 records of 0x200 bytes. A pointer to them is at main+0x82d938; byte +1 is 0xff for an empty slot.

  2. Picker, Computed limits: count the units actually here, so the slider offers only those.

    n = 0
    for slot = 0 to 20
        u = ptr[main+0x82d938] + slot * 0x200
        if u8[u + 1] != 0xff then
            n = n + 1
        end
    end
    show n - 1
  3. Picker, Actions: turn "the Nth unit here" into its real slot and keep it in sreg[0x7f] (a high register, so .txt cheats using low ones do not collide).

  4. Picker, Starting value: the reverse, so it opens on the unit being edited.

  5. Every editor row starts the same way: find the table, check the register is a real slot, check the slot is in use. Then it reads or writes unit + offset.

    table = ptr[main+0x82d938]
    if table != 0 then
        if sreg[0x7f] < 21 then
            unit = table + sreg[0x7f] * 0x200
            if u8[unit + 1] != 0xff then
                u16[unit + 0x30] = value
            end
        end
    end
  6. Add a Readout (Text) for the unit's name and a Pair for HP out of max HP, so you can see who is being edited.

Finished, Body:

found = 0
result = 21
battle_table = ptr[main+0x82d938]
if battle_table != 0 then
    for slot = 0 to 20
        u = battle_table + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 0x29] > 0 and u16[u + 0x32] > 0) then
            if found == value then
                result = slot
            end
            found = found + 1
        end
    end
end
sreg[0x7f] = result

Finished, Opens at:

found = 0
result = 0
resolved_slot = 21
battle_table = ptr[main+0x82d938]
if battle_table != 0 then
    for slot = 0 to 20
        u = battle_table + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 0x29] > 0 and u16[u + 0x32] > 0) then
            if found == 0 then
                resolved_slot = slot
            end
            if slot == sreg[0x7f] then
                result = found
                resolved_slot = slot
            end
            found = found + 1
        end
    end
end
sreg[0x7f] = resolved_slot
show result

Finished, Range:

n = 0
battle_table = ptr[main+0x82d938]
if battle_table != 0 then
    for slot = 0 to 20
        u = battle_table + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 0x29] > 0 and u16[u + 0x32] > 0) then
            n = n + 1
        end
    end
end
show n - 1

Static registers are shared with any .txt cheat running for the title and survive between launches, which is why every editor checks the slot before using it.

Hotkey: Do something when buttons are pressed: Add 1000 XP

Holding R+ZR adds 1000 XP once. A static register remembers the buttons were already down, so holding them does not keep adding. From The Witcher 3 - Wild Hunt Complete Edition, row “Add 1000 XP (R+ZR)”.

The published row is imported from the cheat file and walks the chain twice in registers r11 and r13. This is the same reads and write with the chain written once.

  1. Find XP: Memory search, gain some, search again. Pointers gives a long chain from main+0x3f66ef0.

  2. A toggle row that checks the buttons every tick. held(r + zr) is true while both are down.

  3. Only on the press, not every tick: sreg[0x5] is 1 while the buttons are held, and the add only happens when it was 0.

    if held(r + zr) then
        if sreg[0x5] == 0 then
            // add
        end
        sreg[0x5] = 1
    else
        sreg[0x5] = 0
    end

Finished, Body:

if held(r + zr) then
    if sreg[0x5] == 0 then
        xp = [[[[[[[[main+0x3f66ef0]+0x28]+0x8]+0x1b0]+0x40]+0x40]+0x20]+0x18]+0x8
        u32[xp] = u32[xp] + 1000
    end
    sreg[0x5] = 1
else
    sreg[0x5] = 0
end

Loop over records: Every unit at once: Infinite HP

Every 100 ms, each of our units in the battle gets HP set to max HP. From FINAL FANTASY TACTICS - The Ivalice Chronicles, row “Infinite HP (your units)”.

  1. The unit table: 21 records of 0x200 bytes behind the pointer at main+0x82d938. HP at +0x30, max HP at +0x32, team in bits 0x30 of +5 (0 is ours), +1 is 0xff when empty.

  2. Loop over the slots, work out each record's address once.

    for slot = 0 to 20
        u = ptr[main+0x82d938] + slot * 0x200
    end
  3. Only occupied slots on our team: in use and team bits zero. Then copy max HP into HP.

    for slot = 0 to 20
        u = ptr[main+0x82d938] + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 5] & 0x30) == 0 then
            u16[u + 0x30] = u16[u + 0x32]
        end
    end
  4. Properties: choose Repeat on a timer, every 100 ms. Switching it off just stops topping up.

Finished, Body:

if ptr[main+0x82d938] != 0 then
    for slot = 0 to 20
        u = ptr[main+0x82d938] + slot * 0x200
        if u8[u + 1] != 0xff and (u8[u + 0x29] > 0 and u16[u + 0x32] > 0) and (u8[u + 5] & 0x30) == 0 then
            u16[u + 0x30] = u16[u + 0x32]
        end
    end
end