Skip to content

x.1sav.cheats.mgba

Owner: these specifications, under a reserved name · Applies to: a state’s state part · Status: normative schema, optional to carry

mGBA keeps the player’s cheat list inside each state it takes. This key carries that list, so a consumer rebuilding mGBA’s file can put it back.

The list is mGBA’s, but mGBA writes no bundles, so nobody holding io.mgba will mint a key for it. These specifications take a name in the x tree instead.

; ============================================================================
; x.1sav.cheats.mgba - the cheats mGBA keeps in a state
;
; An extension key for the Universal Saves Format, defined by these
; specifications under a name reserved in the Vendor Names registry. The cheat
; list is mGBA's, but mGBA writes no bundles, so nobody would ever mint this
; key under its own domain.
;
; The root here is the value carried under the key, not a bundle. A bundle
; validates against the format's own schema whatever this holds, since an
; extension value is `any` there; this file is what makes the shape checkable.
; ============================================================================
; In mGBA's order. An empty list is absent: mGBA reads an empty cheat section
; as no section at all, and leaves the player's cheats alone either way.
cheats = [+ cheat-set]
; Every key defaults to absence. A set mGBA wrote with no name, switched on,
; with no directives and no codes is an empty map, and still a set.
cheat-set = {
? 0 => tstr .ne "", ; name - what follows "#"
? 1 => true, ; disabled - the set is switched off
? 2 => [+ tstr], ; directives - what follows "!", such as "PARv3 raw"
? 3 => [+ tstr], ; codes - one per line, as mGBA kept them
}

mGBA groups codes into sets. A set has a name, can be switched off, and holds the codes the player entered, one per line. Directives tell mGBA how to read a set’s codes. For the GBA they are GSAv1, GSAv1 raw, PARv3 and PARv3 raw, and the Game Boy has none.

The order of the sets is mGBA’s, and it matters. Each set starts from where the one before it left off, its code type included. Moving a set can change how mGBA reads its codes.

mGBA stores the list as the text of its .cheats files. It writes each set as these lines, in this order:

  1. !disabled on a line of its own, when the set is switched off.
  2. Each directive after a !, one per line.
  3. #, a space and the name.
  4. The codes, one per line.

A producer reads that text into the sets above. A consumer rebuilding mGBA’s state file writes the sets back the same way, as the file’s cheat section. The text need not come back byte for byte, as long as mGBA reads the same sets.

mGBA writes the list into every state by default. It reads the list back only when its setting to load cheats from a state is on, which by default it is not. When it is, loading the state replaces the player’s cheats with these.

The list changes nothing in the core’s data, which loads the same with or without it. A cheat that was on when the state was taken has already changed the memory the state holds. The list decides only which cheats stay on afterwards.

The state part of a state whose source names the mgba app. A producer MUST NOT put it on any other part, or on any header. mGBA’s libretro core keeps no cheats in its states, so a state taken in RetroArch never carries this key.

The list sits on the part because mGBA loads it with the core’s data. A consumer that lifts the in-game save out of the state leaves the list behind. The game wrote the save, and the cheats are the player’s.

Only when mGBA’s file holds a cheat section with at least one set in it. An empty section is the same as none to mGBA, so the key is absent for both.