From 08dfb0aa80668b80c4a31bd064f5f2d729e5b7f6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 18 Aug 2017 13:49:00 -0400 Subject: Started working on serializing pokemon data The GBA program now sends serialized data about the first pokemon in the player's party over to the Wii. This data doesn't yet include all of the information that we will eventually want. It does, however, not transfer any private data, specifically IVs, EVs, and the personality value. It does this by deriving the public information (stats, nature, gender, shiny) before sending the pokemon over. Because of this, lookup tables for things such as base stats were needed, and given that these are large tables, it was easier to use the tables already existent in the game's ROM. Thus, the addresses of the three lookup tables that are now used are necessary for each ROM that this tool supports. I derived the addresses for version 1 of English Pokemon LeafGreen by dumping my own copy and searching through it with a text editor. Thus, at the current time, that cartridge is the only one that is supported. I will supplement this soon with addresses for the other four gen 3 carts that I have, but that will still not provide a very large amount of coverage. I have not yet decided how to address this issue. There is one current bug with the serialized data: the Wii doesn't seem to see the original trainer ID. Will fix. --- gba/source/gamedata.h | 191 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 187 insertions(+), 4 deletions(-) (limited to 'gba/source/gamedata.h') diff --git a/gba/source/gamedata.h b/gba/source/gamedata.h index 4d0a2a9..247626a 100644 --- a/gba/source/gamedata.h +++ b/gba/source/gamedata.h @@ -21,9 +21,192 @@ #define LANG_JAPAN ((*(u8*)(0x80000AF)) == 'J') -bool initSaveData( - pSaveBlock1* SaveBlock1, - pSaveBlock2* SaveBlock2, - pSaveBlock3* SaveBlock3); +typedef const u32 (*ExperienceTables)[101]; + +struct GameData { + pSaveBlock1 SaveBlock1; + pSaveBlock2 SaveBlock2; + pSaveBlock3 SaveBlock3; + struct BaseStats* baseStats; + ExperienceTables expTables; + const u16* natOrder; +}; + +bool initSaveData(struct GameData* gameData); + +/** + * Decrypts the substructures of a Pokémon structure, so they can be viewed or + * modified easily. + * + * Remember to call EncryptPokemon() afterwards. + * + * @param pkm The Pokémon to decrypt the substructures of. + */ +void DecryptPokemon(struct Pokemon* pkm); + +/** + * Decrypts the substructures of a core Pokémon structure, so they can be viewed + * or modified easily. + * + * Used by DecryptPokemon(). + * + * Remember to call EncryptPokemon() afterwards. + * + * @param pkm The BoxPokemon to decrypt the substructures of. + */ +void DecryptBoxPokemon(struct BoxPokemon* pkm); + +/** + * Encrypts the substructures of a Pokémon structure, and fixes the checksum. + * + * Must be used after DecryptPokemon() has been called, otherwise the Pokémon + * you decrypted and forgot to re-encrypt will become a Bad Egg. + * + * @param pkm The Pokémon to encrypt the substructures and fix + * the checksum of. + */ +void EncryptPokemon(struct Pokemon* pkm); + +/** + * Encrypts the substructures of a core Pokémon structure, and fixes the + * checksum. + * + * Must be used after DecryptBoxPokemon() has been called, otherwise the Pokémon + * you decrypted and forgot to re-encrypt will become a Bad Egg. + * + * @param pkm The BoxPokemon to encrypt the substructures and fix the checksum + * of. + */ +void EncryptBoxPokemon(struct BoxPokemon* pkm); + +/** + * Gets a substructure of a Pokémon structure. + * + * Call DecryptPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokemon to get a substructure of. + * @param substructId The substructure to get. + * + * @return The substructure. + */ +union PokemonSubstruct* GetPokemonSubstruct(struct Pokemon* pkm,u8 substructId); + +/** + * Gets a substructure of a core Pokémon structure. + * + * Call DecryptBoxPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokemon to get a substructure of. + * @param substructId The substructure to get. + * + * @return The substructure. + */ +union PokemonSubstruct* GetBoxPokemonSubstruct( + struct BoxPokemon* pkm, + u8 substructId); + +/** + * Gets the checksum of a core Pokémon structure. + * + * @param pkm The BoxPokemon to calculate the checksum of. + * + * @return The checksum. + */ +u16 CalculateBoxPokemonChecksum(struct BoxPokemon* pkm); + +/** + * Fixes the checksum of a core Pokémon structure. + * + * @param pkm The BoxPokemon to fix the checksum of. + */ +void FixBoxPokemonChecksum(struct BoxPokemon* pkm); + +/** + * Gets the zeroth substructure ("Growth") of a Pokémon structure. + * + * Call DecryptPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokémon to get a substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct0* GetPokemonSubstruct0(struct Pokemon* pkm); + +/** + * Gets the zeroth substructure ("Growth") of a core Pokémon structure. + * + * Call DecryptBoxPokemon() first or the substructure data will be encrypted. + * + * @param pkm The BoxPokemon to get the substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct0* GetBoxPokemonSubstruct0(struct BoxPokemon* pkm); + +/** + * Gets the first substructure ("Attacks") of a Pokémon structure. + * + * Call DecryptPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokémon to get a substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct1* GetPokemonSubstruct1(struct Pokemon* pkm); + +/** + * Gets the first substructure ("Attacks") of a core Pokémon structure. + * + * Call DecryptBoxPokemon() first or the substructure data will be encrypted. + * + * @param pkm The BoxPokemon to get the substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct1* GetBoxPokemonSubstruct1(struct BoxPokemon* pkm); + +/** + * Gets the second substructure ("EVs & Condition") of a Pokémon structure. + * + * Call DecryptPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokémon to get a substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct2* GetPokemonSubstruct2(struct Pokemon* pkm); + +/** + * Gets the second substructure ("EVs & Condition") of a core Pokémon structure. + * + * Call DecryptBoxPokemon() first or the substructure data will be encrypted. + * + * @param pkm The BoxPokemon to get the substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct2* GetBoxPokemonSubstruct2(struct BoxPokemon* pkm); + +/** + * Gets the third substructure ("Miscellaneous") of a Pokémon structure. + * + * Call DecryptPokemon() first or the substructure data will be encrypted. + * + * @param pkm The Pokémon to get a substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct3* GetPokemonSubstruct3(struct Pokemon* pkm); + +/** + * Gets the third substructure ("Miscellaneous") of a core Pokémon structure. + * + * Call DecryptBoxPokemon() first or the substructure data will be encrypted. + * + * @param pkm The BoxPokemon to get the substructure of. + * + * @return The substructure. + */ +struct PokemonSubstruct3* GetBoxPokemonSubstruct3(struct BoxPokemon* pkm); #endif -- cgit 1.4.1