Cheat Code Mods - X-Hax/SADXModdingGuide GitHub Wiki

Cheat Codes is an easy way to make simple hacks, with either CheatEngine, IDA Pro or Ghidra knowledge, you can edit whatever you want in the code. For example if you find the "Rings" variable address, you can easily force the ring count to 999 every frame.

Cheat Codes are not only restricted to simple hacks, they can become much more complex but it makes them more complicated to work with than DLL mods. The Chao World Extended mod for SA2 is almost entirely made of cheat codes for example.

To use Cheat Codes, you need to set up your mod if you haven't already. In your mod folder, create an empty text file with the .lst extension in your mod folder. Then open your mod.ini to add the following line:

Codes=Codes.lst (or whatever you named it)

Adding a code/patch

To add a code or a path, add the first line below to your lst file:

[Code/Patch] NAME (Required)
// Example 1: Code "Something" Required
// Example 2: Patch "Something"

Notes:

  • A code means that your cheat code will run every frame.
  • A patch means that your cheat code will only run once at start up.
  • The name is what shows up in the Mod Manager "codes" tab.
  • Required means that the code will be enabled as soon as your mod is enabled in the list. It will not be shown in the "Codes" tab of the Mod Loader.
  • If you don't set "Required", your cheat code will be checkable in the "Codes" tab of the Mod Loader.

Writing the cheat code

Once you've defined your cheat code, you can go to the next line and start writing it. You will need some programming knowledge to use this at the best of its capacity, but I will try to be understandable.

Format

The basic code format is the following:

[opcode] [address] [value]

Notes:

  • To get a list of opcodes, see the documentation.
  • If you don't know where to start with addresses, see the RAM editing page on sonicretro.
  • Put the address to the value you want to edit in [address] (far left column), find the opcode of what you want to do in the documentation for the type of your value (1 byte = 8; 2 bytes = 16; 4 bytes = 32 or float) and put it in [opcode], then put the value for the opcode in [value]. See examples below!

Starting with examples

Example 1: Simple

Code "Always Max Rings"
write16 03B0F0E4 999

If you write this, save your lst file and launch the game with your mod (and the code) enabled, the ring count will be forced to 999 every frame (if it's a code, not a patch.)

Let's see what this line means:

  • write16 means that it will write to 2 bytes. This is because the Rings variable in SADX is a 2 bytes (a "short" or "Sint16" in c++).
  • 03B0F0E4 is the hexadecimal address of the Rings variable
  • 999 is the 2-byte values that is going to be written at the provided address.

Example 2: Simple (float)

Code "Upward Gravity"
writefloat 03B0F0FC 1.0

If you write this the gravity will be reversed. It has to be a code because Gravity is reset by the game several times.

  • writefloat means that the edited value is a (single precision) floating point value (with a comma)
  • 03B0F0FC is the hexadecimal address of the up gravity direction.
  • 1.0 is a float value that we will be writing, 1.0 for up gravity means upward.

Example 3: Condition 1

More complex, if we write the lines below, the player will only get 999 rings if it has 0 rings.

Code "Add 999 Rings when without rings"
ifeq16 03B0F0E4 0
write16 03B0F0E4 999
endif
  • ifeq16 means that we are making a condition (if value at address is value)
  • 03B0F0E4 is the Ring address
  • 0 is the value that we are checking
  • write16 03B0F0E4 999 is if the result of the condition is true (set 999 rings)
  • So in english: "If the ring count is 0, set it to 999"

Example 4: Condition 2

This increments the score until it reaches 9999.

Code "Add 1 point every frame"
ifltu32 03B0F14C 9999
add32 03B0F14C 1
endif

Notes:

  • ifltu32 means "if value is inferior to3 (9999 here)
  • 03B0F14C is the level score.

More Examples

See the Mod Loader's Cheat Code file for more examples.