Skip to content

Save Functions

SpiredMoth edited this page Feb 20, 2020 · 13 revisions

Value Access

int sav_get_value(enum SAV_Field field, ...);

enum SAV_Field
{
    SAV_OT_NAME,
    SAV_TID,
    SAV_SID,
    SAV_GENDER,
    SAV_COUNTRY,
    SAV_SUBREGION,
    SAV_REGION,
    SAV_LANGUAGE,
    SAV_MONEY,
    SAV_BP,
    SAV_HOURS,
    SAV_MINUTES,
    SAV_SECONDS,
    SAV_ITEM
};

// example usage
char *otName = (char *)sav_get_value(SAV_OT_NAME);
int tid = sav_get_value(SAV_OT_TID);
int firstMedicine = sav_get_value(SAV_ITEM, Medicine, 0);

Used to get values out of the currently loaded save. Most fields will not require even a second argument. See below for what fields are available. Notable caveats and arguments are:

  • SAV_OT_NAME: Returns a UTF-8 formatted string that must be manually freed. Cast to char* to use it properly
  • SAV_TID and SAV_SID: Both return the 5-digit format
  • SAV_ITEM: Requires an enum Pouch (see General Enums and Structs: Pouch) and a slot number. Returns the item ID of the specified slot

Wonder Cards

int sav_wcx_free_slot();

Gets the first empty Wonder Card slot, or, if all are filled, the maximum index.

void sav_inject_wcx(char* data, enum Generation type, int slot, int alternateFormat);

Injects a wonder card.

  • data should be a pointer to the Wonder Card data in the correct format for the generation. If the Wonder Card data passed in is not in the correct format, issues will occur.
  • slot refers to which Wonder Card slot it should be injected to, though GEN_LGPE does not store Wonder Cards, and, as such, this argument does not affect it.
  • alternateFormat is a boolean that refers to the format of the data passed in, based on the value of enum Generation type as follows:
    • GEN_FOUR: if true, data is interpreted as a WC4 (meaning that the internal Pokémon data is decrypted). Otherwise, data will be interpreted as a PGT.
    • GEN_FIVE: ignored
    • GEN_SIX: if true, data is interpreted as a WC6FULL. Otherwise, data will be interpreted as a WC6
    • GEN_SEVEN: if true, data is interpreted as a WC7FULL. Otherwise, data will be interpreted as a WC7
    • GEN_LGPE: if true, data is interpreted as a WB7FULL. Otherwise, data will be interpreted as a WB7

Strings

char* sav_get_string(unsigned int offset, unsigned int codepoints);

Used to get a UTF-8 encoded string from an arbitrary offset in the save, stopping at the null terminator.

  • codepoints is the character limit, including the null terminator.
  • Returned string must be manually freed.
void sav_set_string(char* string, unsigned int offset, unsigned int codepoints);

Used to write a UTF-8 string to an arbitrary offset in the save, and overwrites unnecessary bytes with 0. codepoints is the character limit, including the null terminator.

Box Data Encryption

void sav_box_decrypt();
void sav_box_encrypt();

IMPORTANT: These should always be used as a pair and always in this order. Mixing them or not using them in pairs will produce unpredictable results.

Any edits you aim to make should be done after calling sav_box_decrypt and before calling sav_box_encrypt.