SX OS Cheat Hacker Guide

Game_Over

Staff member
Top TX Brass
Dec 2, 2010
5,265
138
127.0.0.1
1. Introduction

This small guide attempts to shed some light on finding your own cheat codes
for Switch games using the SX OS Cheat finder as well as detailing the specifics
about the SX OS Cheat Code Format.

2. Address Space Layout Randomization

The Nintendo Switch Operating System (Horizon OS) implements Address Space
Layout Randomization (from here on ASLR) for every process. What this means
is that the absolute base address of for example a game's executable or a
game's heap memory are not fixed in stone. SX OS does *not* disable this ASLR
as it would effectively make your console less secure. The downside of this is
that you as a cheat hunter will need to keep this in mind when finding cheats,
but we've tried our best to encapsulate/hide these details at a high level.

When working with pointers in the SX OS Cheat Engine you can have three different
type of pointers:
* MAIN - memory addresses/pointers relative to the game's NSO executable
* HEAP - memory addresses/pointers relative to the start of the game's heap
* BASE - memory addresses/pointers that are neither part of MAIN/HEAP,
they are displayed a relative to the address space base (usually 0x8000000)

Throughout the SX OS Cheat finder every memory address is thus displayed as:
[MAIN+xxxx], [HEAP+xxxx], [BASE+xxxx]

When writing actual cheat codes you need to specify what kind of address you are
reading/writing from, we support reading/writing from/to both MAIN and HEAP memory.

Remember that having cheat codes which write to a magic HEAP address are most of
the time not very stable/reliable cheat codes, because the layout of the HEAP is
not always fully deterministic and often times depends on how someone navigates
through a game. In these cases it is better to study the game logic more and find
pointers (or pointers to pointers, etc.) until you traced back to an address that
resides in MAIN (a pointer in BSS or RO for example). At the end of this guide
you will find a small case study of how the included codes for
"Mega Man Legacy Collection" work.

3. SX OS Cheat Code Format

SX OS Cheat Codes are loosely inspired by older cheat engines such as Action Replay.
While old Action Replay cheat codes usually had a fixed width per code, some code
types in the SX OS cheat engine can have a different length.

Cheat codes are placed inside the sxos folder on your microSD card. In order
for SX OS to pick up your cheat codes they need to be correctly placed in the
right subfolders. This subfolder format works like this:
/sxos/titles/<titleID>/cheats/<buildID>.txt

Where titleID is the titleID of the game and buildID are the first 8bytes of the
game's build ID formatted as ascii hexadecimals. Both the titleID and buildID for
a running game are displayed below the SXOS logo when you navigate to the cheats
tab in the SX OS Menu. The buildID is needed to properly deal with different
versions of the same game, which might lead to incompatibilities for cheat codes.
When SX OS detects you have cheats on your SD cards for the currently running game
but the buildID mismatches, it offers you to copy over the cheats from the other
buildID to the one of the version you are currently running, if you want to
experiment with (or fix) the compatibility of certain cheat codes.

A basic cheat code definition will look like this:

[Infinite Health]
11111111 22222222
11111111 22222222
11111111 22222222

Where 'Infinite Health' is the displayed name of the code and the lines containing
'11111111 22222222' are all the codes that belong to this cheat.

The cheat engine supports up to 16 'scratch' registers which can be used for
arbitrary purposes like stashing offsets or memory locations.

There is one special type of code. The "master code" which is not defined by
enclosing the name in '[' and ']' but using '{' and '}' instead. The master code
cannot be disabled and is executed before any other (enabled) cheat code. These
exists to avoid duplication in multiple cheats which share certain characteristics.
An example of master code usage can be seen in the case study for the
"Mega Man Legacy Collection" cheats you will find further down in this guide.

Below is an overview of the various code types currently implemented in the SX
OS Cheat Engine.

# Code Type 0: Write to memory

0TMR00AA AAAAAAAA YYYYYYYY (YYYYYYYY)

T = width of write (1/2/4/8)
M = memory type (0 = main nso, 1 = heap)
R = register to be added as offset
A = address relative to (M)

With code type 0 you can do a write to memory.

# Code Type 1: Conditional statements

1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY)

T = width of comparison value (1/2/4/8)
M = memory type (0 = main nso, 1 = heap)
C = Condition to use for comparison
A = Address relative to (M)
Y = Value to compare against

# Code Type 2: End of conditional statement

20000000

This code type terminates an conditional block (Code type 3 or 8)

# Code Type 3: Looping

300R0000 VVVVVVVV

R = Register to use for loop counter
V = Loop count

310R0000

This code type is used at the end of the loop, use the same R value as
for the start of the loop.

# Code Type 4: Load register with value

400R0000 VVVVVVVV VVVVVVVV

This code type will load one of the registers with a specific value

R = Register to be filled
V = Value to be put in register

# Code Type 5: Load register with value from memory

5TMRI0AA AAAAAAAA

T = Width of value to be loaded from memory (1/2/4/8)
M = memory type (0 = main nso, 1 = heap)
R = Load from register index
I = Load from register flag, set to 1 to load from register R instead of address A
A = Address relative to (M)

# Code Type 6: Store value to memory address from register

6T0RIor0 VVVVVVVV VVVVVVVV

T = Width of value to be stored to memory
R = Register index containing the memory address
I = Increment register flag, set to 1 to increment the register by T after storing
o = add additional offset from register 'r'
r = offset register index
V = value to be stored to memory

# Code Type 7: Apply arithmic operation to register

7T0RC000 VVVVVVVV

T = Width of value (1/2/4/8)
R = Register index to apply arithmic operation to
C = Arithmic operation to apply:
0 = addition, 1 = subtraction, 2 = multiplication, 3 = shift left, 4 = shift right
V = Value to be used during arithmic operation

# Code Type 8: Check for buttons being pressed

8kkkkkkk

k = keypad value to check against. the hex values for the various keys are:

0000001 - A
0000002 - B
0000004 - X
0000008 - Y
0000010 - Left Stick Pressed
0000020 - Right Stick Pressed
0000040 - L
0000080 - R
0000100 - ZL
0000200 - ZR
0000400 - Plus
0000800 - Minus
0001000 - Left
0002000 - Up
0004000 - Right
0008000 - Down
0010000 - Left Stick Left
0020000 - Left Stick Up
0040000 - Left Stick Right
0080000 - Left Stick Down
0100000 - Right Stick Left
0200000 - Right Stick Up
0400000 - Right Stick Right
0800000 - Right Stick Down
1000000 - SL
2000000 - SR

Multiple button values can be combined by OR'ing them together. For example
A+B becomes 0000003, and A+B+X+Y becomes 000000f.

This code type otherwise behaves the same as the conditional code type 1.

4. Using the Cheat Finder in SX OS

SX OS Comes with a cheat searcher functionality that will help you in identifying
the memory locations you need in order to write your own cheat codes. You start
by launching a game, when you reach a point in the game where you want to start
searching for cheats you hit the home button, and navigate to the album viewer (SX OS Menu).

You can start a cheat search by navigating to "Cheat Searcher" in the cheat tab of the
SX OS menu. You will be prompted to pick what kind of value you want to start
a cheat search for. If you dont know the answer you can try to approximate it. Lets say
you want to hunt down the memory location of your in-game coins, and you know
that you can accumulate over 1000 coins, you know for sure the data type you are
looking for is gonna be bigger than 8-bit. This takes some experimentation and
expertise to get used to.

Once you select the data type a memory dump for the running game will be created
on your microSD card. This initial memory dump will take a while, it is advised
to use a fast microSD card with enough free space. If you are looking for a
specific/exact value, you can now select "Next Search" and pick "Exact Value",
here you can enter the exact value you're looking for (in hexadecimal). Once the
comparison is done it will tell you how many candidate memory locations it found
and whether they are few enough to manually explore.

If there's too many candidates left, you simply exit the SX OS Rom Menu and go
back to the game. Try to grab/lose some coins (or whatever item you're trying
to cheat) and head back into the SX OS menu's cheat tab, pick "Next Search" and
specify the condition. This can be "exact value" again if you know the value
you're looking for, or simply "less than" if you know you just lost some of the
desired item/stats. Keep iterating the searches until the cheat searcher tells
you there's few enough candidate memory locations left for you to start
exploring manually.

Manually exploring memory location candidates can be done by going to "View candidates"
in the cheats menu. When you select a candidate from the list you will be brought
to the builtin hex editor where you can change the values at these memory locations.
Once you change a value you can go back to the game and see if your change had
any/the desired effect to help in concluding whether you found the right memory
location.

5. Case Study of "Mega Man: Legacy Collection" cheat codes.

Currently we only provide a single example of working cheat codes. We would love
to spend all of our time on finding more cheats, but we have different priorities. ;-)

The cheats we found are a slightly interesting example though of the various code
types the SX OS Cheat Engine currently offers.

Mega Man: Legacy Collection is a collection of old Mega Man games originally
released for the NES back in the day. The switch "port" of these games is actually
a NES emulator in disguise. The meat of our Mega Man cheat codes hinges on the
"master code" which finds the virtual NES' memory start address, from there we
can apply any RAM patches to the NES memory as we wish. Let's have a look at how
this works.

The full master code looks like this:

-- 8< ------------------------
{Master Code}
580f0000 00d3a2a0
580f1000 038cb840
580f1000 00000008
780f0000 0000000f
-- 8< ------------------------
The usage of '{' and '}' indicates that this is a master code, eg. a code that
cannot be disabled and is always ran at the start of your cheat code list.

Lets break down the master code line by line:
580f0000 00d3a2a0

Code type 5 is 'Load register with value from memory', here we load a 8 byte (64bit)
value, relative from MAIN (0) into register 'f' (15). The offset from the start of
MAIN is 0xd3a2a0.

In pseudocode this would be something like:

register_f = read64(MAIN + 0xd3a2a0)

The next line reads:
580f1000 038cb840

This one is very similar to the first code, but notice how we have an '1' there.
if you look this up in the SX OS Code Format description above you can see this
is the 'Load from register flag'. If set to '1' we will take the address from the
register specified in the register index field rather than a memory location
relative from MAIN or HEAP. In pseudocode this would be:

register_f = read64(register_f + 0x38cb840)

The following line '580f1000 00000008' is more of the same, this time reading
the next pointer from offset 8, or in pseudocode:

register_f = read64(register_f + 0x8)

Then finally we we end with '780f0000 0000000f'. Which uses code type 7 to do
some basic arithmic to the memory location in register f. In pseudo code this
would be:

register_f = register_f + 15

So in essence all the "master code" does is follow a bunch of pointers and
eventually end up with a pointer in register F that holds the start of the virtual
NES' memory. This register f value can then be used in any cheat codes that need
to write/read from the virtual NES' memory in order to give Mega Man exciting
super powers! ;-)

Let's have a quick look at one of the game specific cheat codes for Mega Man 1:

[MM1 Infinite Health]
400e0000 00000000 0000006a
610f01e0 00000000 0000001c

The first line '400e0000 00000000 0000006a' is using code type #4 to load a
register with a specific value. In this case we load register E with value 0x6a.
0x6a is the RAM offset for Mega Man's health.

The following line '610f01e0 00000000 0000001c' is using code type #6, which
is "Store value to memory address from register" to write to this location.

Here we say write a 1 byte (8bit) value to the address: register_f + register_e.
The value to be written is 0x1c, the maximum value Mega Man's health can have
in Mega Man 1.

6. Closing Words

We hope this guide outlines the possibilities of the cheat engine and the
need for decent master codes a bit. We are looking forward to many community
contributions with new cheat codes and of course suggestions for improving our
cheat code finder and engine.

Yours Sincerely,

Team Xecuter -- Rocking the switch in 2018 and beyond!



 
Last edited:
  • Like
Reactions: nofeloniesyet

optantic

VIP Member
May 2, 2010
543
48
# Code Type 1: Conditional statements

1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY)

T = width of comparison value (1/2/4/8)
M = memory type (0 = main nso, 1 = heap)
C = Condition to use for comparison
A = Address relative to (M)
Y = Value to compare against

What are the values for C? (equal,less than, greater than)
 

Memeangler

Noob Account
Sep 22, 2018
5
0
when team matrix and sciresm says they will have cheat codes but takes forever then team xecuter does it before them, lol
 

AnalogMan

Junior Member
Jun 1, 2018
21
3
Is there a way to load a memory address directly to a register? As in, I want to make a loop that takes an address, writes to it, then increases it by 0x230 each loop. I can see how to write to an address directly, I see you can store the value of an address to a register and that to perform any arithmetic, the value needs to be assigned a register, but I don't see how to direct say "register f = MAIN+0x3cfa320".

I want to so something like this:
Code:
???????? ????????               // F = MAIN+0x026583C0
300e0000 00000018               // Loop register E 24 times
640f0000 00000000 00000063      // Write 4 byte value 0x63 to [F]
780f0000 00000230               // Increase F by 0x230
310E0000                        // End loop E
04000000 265B844 00000063       // Write 4 byte value 0x63 to MAIN+265B844
What would be the missing code or is it not doable?
 
Last edited:

Game_Over

Staff member
Top TX Brass
Dec 2, 2010
5,265
138
127.0.0.1
Is there a way to load a memory address directly to a register? As in, I want to make a loop that takes an address, writes to it, then increases it by 0x10 each loop. I can see how to write to an address directly, I see you can store the value of an address to a register and that to perform any arithmetic, the value needs to be assigned a register, but I don't see how to direct say "register f = MAIN+0x3cfa320".

I want to so something like this:
Code:
???????? ????????               // F = MAIN+0x026583C0
300e0000 00000018               // Loop register E 24 times
640f0000 00000000 00000063      // Write 4 byte value 0x63 to [F]
780f0000 00000230               // Increase F by 0x230
310E0000                        // End loop E
04000000 265B844 00000063       // Write 4 byte value 0x63 to MAIN+265B844
What would be the missing code or is it not doable?
Wish I could answer this for you. I sent this question up the chain toward the developers. I will let you know if I get a response to this. It may possibly be something that requires an update.
 

optantic

VIP Member
May 2, 2010
543
48
It would be nice if TX could update the cheat guide with examples for each codetype and don't forget to add the values for use on C
C = Condition to use for comparison
 
  • Like
Reactions: matias3ds

Game_Over

Staff member
Top TX Brass
Dec 2, 2010
5,265
138
127.0.0.1
Last edited:

AnalogMan

Junior Member
Jun 1, 2018
21
3
What are the possible C values for code type 1? I can't make any conditional codes without knowing what the C values are.
 

optantic

VIP Member
May 2, 2010
543
48
how you been? I have not touch that stuff in few years and no plans to do it for switch.
doing good here, I also haven't touch Xbox360 for a few years , hope making cheats on Switch will get easier in the near future, we need better tools to search for pointer in pointer
 

A7mag3ddon

Noob Account
Jul 2, 2005
8
3
uk
Could someone possibly help with a code i found?

it is [HEAP+0x9411ad20] (0x5)

What i want is to write a 7 to that address all the time so would it be this...

[Infinite Health]
400e0000 00000000 00000007
610f01e0 00000000 9411ad20

Or can i use code type 1 to write directly to that address, and if yes what would said code look like ?
 
Last edited:

optantic

VIP Member
May 2, 2010
543
48
Could someone possibly help with a code i found?

it is [HEAP+0x9411ad20] (0x5)

What i want is to write a 7 to that address all the time so would it be this...

[Infinite Health]
400e0000 00000000 00000007
610f01e0 00000000 9411ad20

Or can i use code type 1 to write directly to that address, and if yes what would said code look like ?
if it is a static address then you could use: Code Type 0: Write to memory
011000000 9411ad20 00000007
but that address looks like it could be dynamic as address found in HEAP mostly are dynamic
 

masagrator

Noob Account
Sep 13, 2018
1
0
  • Ability to add cheats using the UI
    Identifying memory locations for cheats using just the console is nice, but previously there was no way of adding an actual cheat-code for a location you found to the cheat code library. This has been addressed, and there is now an interface for doing this directly from our menu.
Where exactly is this option to save cheats? I found one value and there is no option for saving.
 

AnalogMan

Junior Member
Jun 1, 2018
21
3
Conditional ending code 20000000 doesn't seem to end conditional. If using two button detection conditionals in a single code, the second one never triggers. If using a button conditional with more code following after, the additional code is never executed. If you place code above a button conditional, then both the pre-code and conditional work, implying the 20000000 code type isn't working as intended.
 

optantic

VIP Member
May 2, 2010
543
48
Conditional ending code 20000000 doesn't seem to end conditional. If using two button detection conditionals in a single code, the second one never triggers. If using a button conditional with more code following after, the additional code is never executed. If you place code above a button conditional, then both the pre-code and conditional work, implying the 20000000 code type isn't working as intended.
I have reported that since 2.1, seems cheat related stuff is a super low priority even when it comes to just copy and paste https://team-xecuter.com/forums/threads/155273-Request-C-values-for-comparison-use?p=1074447&viewfull=1#post1074447