Skip to content

Environment Info Functions

SpiredMoth edited this page Jul 24, 2023 · 9 revisions

Save Info

Gen 4 save files store 2 sets of save data (current and backup), broken up into 3 blocks apiece and the blocks can be mixed up within the file. A Gen 4 save file could look like the following:

  • Save data 1 (starting at 0x0): backup general block, current storage block, backup HoF block
  • Save data 2 (starting at 0x40000): current general block, backup storage block, current HoF block
int sav_sbo();
int sav_gbo();

// example usage
int ofs = sav_gbo() + 0x0;

These are only needed for Gen 4 (DP, PT, HGSS).

The return values of sav_gbo and sav_sbo point you the proper portion of the file containing the current version of the general and storage blocks respectively.

A value of 0 is returned if used on a Gen 3 or a Gen 5+ save, meaning they'll have no adverse effect on setting offsets on other games.

Save Limitations

int sav_get_max(enum SAV_MaxField field, ...);

enum SAV_MaxField {
    MAX_SLOTS,
    MAX_BOXES,
    MAX_WONDER_CARDS,
    MAX_FORM,
    MAX_IN_POUCH
};

// example usage
int totalBoxSlots = sav_get_max(MAX_SLOTS);
int pikachuForms = sav_get_max(MAX_FORM, 25);
int maxMedicine = sav_get_max(MAX_IN_POUCH, Medicine);

Used to get max values associated with the currently loaded save. Most fields will not require a second argument. Notable caveats and arguments are:

  • MAX_FORM: Requires a species number as an argument
  • MAX_IN_POUCH: Returns the maximum amount of items for the save. Requires an enum Pouch (see General Enums and Structs: Pouch).
int sav_check_value(enum SAV_CheckValue field, int value);

enum SAV_CheckValue {
    SAV_VALUE_SPECIES,
    SAV_VALUE_MOVE,
    SAV_VALUE_ITEM,
    SAV_VALUE_ABILITY,
    SAV_VALUE_BALL
};

// example usage
int isPikachuAvailable = sav_check_value(SAV_VALUE_SPECIES, 25);
int isMasterBallAvailable = sav_check_value(SAV_VALUE_ITEM, 1);

Used to test whether certain values are valid for the loaded save.

  • Returns 1 if it is available, 0 if not.
  • What to use for value depends on what you use for field:
    • SAV_VALUE_SPECIES: use Pokémon's National dex number
    • SAV_VALUE_MOVE: get the move's line number in this list (Eng) and subtract 1
    • SAV_VALUE_ITEM: get the item's line number in this list (Eng) and subtract 1
    • SAV_VALUE_ABILITY: get the ability's line number in this list (Eng) and subtract 1
    • SAV_VALUE_BALL: use the ball's line number in this list (Eng)
  • 0 should not be used for value. While it is valid for some fields, in those cases it corresponds to "none" which is pointless to check for being valid.
int max_pp(enum Generation gen, int move, int ppUps);

Check the maximum legal PP of a move.

  • enum Generation gen: Generation of game to check move's PP
  • int move: Move's index number. You can get a move's index from the line number in this list (Eng) that the move is found on and subtract 1
  • int ppUps: Number of PP Ups to account for

Bank Info

int bank_get_size();

Returns the number of 30-slot boxes in the currently active bank.