docs/features/cheats.md
Atmosphère supports Action-Replay style cheat codes, with cheats loaded off of the SD card.
By default, Atmosphère will do the following when deciding whether to attach to a new application process:
pm and loader.cheat_enable_key./atmosphere/contents/<program_id>/cheats/<build_id>.txt, where build_id is the hexadecimal representation of the first 8 bytes of the application's main executable's build id.
This behavior ensures that cheat codes are only loaded when the user would want them to.
In cases where dmnt has not activated the cheat manager, but the user wants to make it do so anyway, the cheat manager's service API provides a ForceOpenCheatProcess command that homebrew can use. This command will cause the cheat manager to try to force itself to attach to the process.
In cases where dmnt has activated the cheat manager, but the user wants to use an alternate debugger, the cheat manager's service API provides a ForceCloseCheatProcess command that homebrew can use. This command will cause the cheat manager to detach itself from the process.
By default, all cheat codes listed in the loaded .txt file will be toggled on. This is configurable by the user by editing the atmosphere!dmnt_cheats_enabled_by_default system setting.
Users may use homebrew programs to toggle cheats on and off at runtime via the cheat manager's service API.
Atmosphère manages cheat code through the execution of a small, custom virtual machine. Care has been taken to ensure that Atmosphère's cheat code format is fully backwards compatible with the pre-existing cheat code format, though new features have been added and bugs in the pre-existing cheat code applier have been fixed. Here is a short summary of the changes from the pre-existing format:
The following provides documentation of the instruction format for the virtual machine used to manage cheat codes.
Typically, instruction type is encoded in the upper nybble of the first instruction u32.
Code type 0x0 allows writing a static value to a memory address.
0TMR00AA AAAAAAAA VVVVVVVV (VVVVVVVV)
Code type 0x1 performs a comparison of the contents of memory to a static value.
If the condition is not met, all instructions until the appropriate End or Else conditional block terminator are skipped.
1TMCXrAA AAAAAAAA VVVVVVVV (VVVVVVVV)
Code type 0x2 marks the end of a conditional block (started by Code Type 0x1 or Code Type 0x8).
When an Else is executed, all instructions until the appropriate End conditional block terminator are skipped.
2X000000
Code type 0x3 allows for iterating in a loop a fixed number of times.
300R0000 VVVVVVVV
310R0000
Code type 0x4 allows setting a register to a constant value.
400R0000 VVVVVVVV VVVVVVVV
Code type 0x5 allows loading a value from memory into a register, either using a fixed address or by dereferencing the destination register.
5TMR00AA AAAAAAAA
5T0R10AA AAAAAAAA
5T0R2SAA AAAAAAAA
5TMR3SAA AAAAAAAA
Code type 0x6 allows writing a fixed value to a memory address specified by a register.
6T0RIor0 VVVVVVVV VVVVVVVV
Code type 0x7 allows performing arithmetic on registers.
However, it has been deprecated by Code type 0x9, and is only kept for backwards compatibility.
7T0RC000 VVVVVVVV
Code type 0x8 enters or skips a conditional block based on whether a key combination is pressed.
8kkkkkkk
Note that for multiple button combinations, the bitmasks should be ORd together.
Note: This is the direct output of hidKeysDown().
Code type 0x9 allows performing arithmetic on registers.
9TCRS0s0
9TCRS100 VVVVVVVV (VVVVVVVV)
Code type 0xA allows writing a register to memory.
ATSRIOxa (aaaaaaaa)
Code Type 0xB is currently reserved for future use.
Code Types 0xC-0xF signal to the VM to treat the upper two nybbles of the first dword as instruction type, instead of just the upper nybble.
This reserves an additional 64 opcodes for future use.
Code type 0xC0 performs a comparison of the contents of a register and another value. This code support multiple operand types, see below.
If the condition is not met, all instructions until the appropriate conditional block terminator are skipped.
C0TcSX##
C0TcS0Ma aaaaaaaa
C0TcS1Mr
C0TcS2Ra aaaaaaaa
C0TcS3Rr
C0TcS400 VVVVVVVV (VVVVVVVV)
C0TcS5X0
Code type 0xC1 performs saving or restoring of registers.
C10D0Sx0
Code type 0xC2 performs saving or restoring of multiple registers using a bitmask.
C2x0XXXX
Code type 0xC3 reads or writes a static register with a given register.
C3000XXx
Code type 0xC4 enters or skips a conditional block based on whether a key combination is pressed.
C4r00000 kkkkkkkk kkkkkkkk
hidKeysDown().Note that for multiple button combinations, the bitmasks should be OR'd together.
Note: This is the direct output of hidKeysDown().
Code Type 0xF0 signals to the VM to treat the upper three nybbles of the first dword as instruction type, instead of just the upper nybble.
This reserves an additional 16 opcodes for future use.
Code type 0xFF0 pauses the current process.
FF0?????
Code type 0xFF1 resumes the current process.
FF1?????
Code type 0xFFF writes a debug log to the SD card under the folder /atmosphere/cheat_vm_logs/.
FFFTIX##
FFFTI0Ma aaaaaaaa
FFFTI1Mr
FFFTI2Ra aaaaaaaa
FFFTI3Rr
FFFTI4X0