From 6cb04b9b50b461069178d2bb08a09192bbee0acb Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Wed, 25 Dec 2024 14:46:06 -0500 Subject: [PATCH 1/7] Document pokedex_data.c unk_0202631 -> pokedex_data This is the file that manages all form data encountered, including genders and languages. --- include/pokedex_data.h | 53 ++ include/unk_0202631C.h | 53 -- platinum.us/main.lsf | 2 +- src/battle/ov16_0223B140.c | 8 +- src/battle/ov16_0223DF00.c | 10 +- src/field_battle_data_transfer.c | 24 +- src/field_menu.c | 10 +- src/game_records.c | 4 +- src/meson.build | 2 +- src/overlay005/ov5_021F6454.c | 4 +- src/overlay005/ov5_021F77A8.c | 6 +- src/overlay005/save_info_window.c | 8 +- src/overlay006/ov6_02240C9C.c | 8 +- src/overlay006/ov6_02242984.c | 4 +- src/overlay006/ov6_02246A30.c | 10 +- src/overlay021/ov21_021D0D80.c | 4 +- src/overlay021/pokedex_sort.c | 40 +- src/overlay023/ov23_0223E140.c | 4 +- src/overlay023/ov23_022521F0.c | 4 +- src/overlay028/ov28_022561C0.c | 8 +- src/overlay062/ov62_02237D24.c | 10 +- src/overlay062/ov62_02241204.c | 10 +- src/overlay065/ov65_0222DCE0.c | 6 +- src/overlay066/ov66_0222DDF0.c | 6 +- src/overlay094/ov94_022414B8.c | 10 +- src/overlay097/ov97_0222AE60.c | 10 +- src/overlay097/ov97_0222C174.c | 6 +- src/overlay118/ov118_021D0D80.c | 4 +- src/pokedex_data.c | 1240 ++++++++++++++++++++++++++++ src/savedata/save_table.c | 4 +- src/scrcmd.c | 60 +- src/scrcmd_system_flags.c | 10 +- src/unk_0202631C.c | 1283 ----------------------------- src/unk_0202F180.c | 6 +- src/unk_0202F1D4.c | 4 +- src/unk_0203D1B8.c | 8 +- src/unk_02046C7C.c | 4 +- src/unk_0204AEE8.c | 6 +- src/unk_0204C500.c | 4 +- src/unk_02052C6C.c | 4 +- src/unk_020683F4.c | 4 +- src/unk_0206CCB0.c | 48 +- src/unk_02071D40.c | 6 +- src/unk_0207A274.c | 6 +- src/unk_0207AE68.c | 6 +- src/unk_020933F8.c | 6 +- src/unk_0209747C.c | 4 +- src/unk_020998EC.c | 4 +- 48 files changed, 1501 insertions(+), 1544 deletions(-) create mode 100644 include/pokedex_data.h delete mode 100644 include/unk_0202631C.h create mode 100644 src/pokedex_data.c delete mode 100644 src/unk_0202631C.c diff --git a/include/pokedex_data.h b/include/pokedex_data.h new file mode 100644 index 0000000000..08a81c28fc --- /dev/null +++ b/include/pokedex_data.h @@ -0,0 +1,53 @@ +#ifndef POKEPLATINUM_POKEDEX_DATA_H +#define POKEPLATINUM_POKEDEX_DATA_H + +#include "struct_decls/pokedexdata_decl.h" + +#include "pokemon.h" +#include "savedata.h" + +int PokedexData_SaveSize(void); +PokedexData *PokedexData_Alloc(u32 heapID); +void PokedexData_Copy(const PokedexData *src, PokedexData *dest); +void PokedexData_Init(PokedexData *pokedexData); +u16 PokedexData_CountCaught_National(const PokedexData *pokedexData); +u16 PokedexData_CountSeen_National(const PokedexData *pokedexData); +u16 PokedexData_CountSeen(const PokedexData *pokedexData); +u16 PokedexData_CountCaught_Local(const PokedexData *pokedexData); +u16 PokedexData_CountSeen_Local(const PokedexData *pokedexData); +BOOL PokedexData_NationalDexCompleted(const PokedexData *pokedexData); +BOOL PokedexData_LocalDexCompleted(const PokedexData *pokedexData); +u16 PokedexData_NumCaught_National(const PokedexData *pokedexData); +u16 PokedexData_NumCaught_Local(const PokedexData *pokedexData); +BOOL PokedexData_HasCaughtSpecies(const PokedexData *pokedexData, u16 species); +BOOL PokedexData_HasSeenSpecies(const PokedexData *pokedexData, u16 species); +u32 PokedexData_GetForm_Spinda(const PokedexData *pokedexData, u8 formIndex); +u32 PokedexData_DisplayedGender(const PokedexData *pokedexData, u16 species, int displaySecondary); +u32 PokedexData_GetForm_Unown(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Unown(const PokedexData *pokedexData); +u32 PokedexData_GetForm_Shellos(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Shellos(const PokedexData *pokedexData); +u32 PokedexData_GetForm_Gastrodon(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Gastrodon(const PokedexData *pokedexData); +u32 PokedexData_GetForm_Burmy(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Burmy(const PokedexData *pokedexData); +u32 PokedexData_GetForm_Wormadam(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Wormadam(const PokedexData *pokedexData); +u32 PokedexData_GetForm_Deoxys(const PokedexData *pokedexData, int formIndex); +u32 PokedexData_NumFormsSeen_Deoxys(const PokedexData *pokedexData); +void PokedexData_CaptureEntry(PokedexData *pokedexData, Pokemon *pokemon); +void PokedexData_TradeEntry(PokedexData *pokedexData, Pokemon *pokemon); +void PokedexData_ObtainNationalDex(PokedexData *pokedexData); +BOOL PokedexData_IsNationalDexObtained(const PokedexData *pokedexData); +BOOL PokedexData_CanDetectForms(const PokedexData *pokedexData); +void PokedexData_TurnOnFormDetection(PokedexData *pokedexData); +BOOL PokedexData_IsLanguageObtained(const PokedexData *pokedexData, u16 species, u32 languageIndex); +void PokedexData_TurnOnLanguageDetection(PokedexData *pokedexData); +BOOL PokedexData_CanDetectLanguages(const PokedexData *pokedexData); +BOOL PokedexData_IsObtained(const PokedexData *pokedexData); +void PokedexData_ObtainPokedex(PokedexData *pokedexData); +PokedexData *SaveData_PokedexData(SaveData *saveData); +u32 PokedexData_GetDisplayForm(const PokedexData *pokedexData, int species, int formIndex); +u32 PokedexData_NumFormsSeen(const PokedexData *pokedexData, int species); + +#endif // POKEPLATINUM_POKEDEX_DATA_H diff --git a/include/unk_0202631C.h b/include/unk_0202631C.h deleted file mode 100644 index 0253fcdfec..0000000000 --- a/include/unk_0202631C.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef POKEPLATINUM_UNK_0202631C_H -#define POKEPLATINUM_UNK_0202631C_H - -#include "struct_decls/pokedexdata_decl.h" - -#include "pokemon.h" -#include "savedata.h" - -int Pokedex_SaveSize(void); -PokedexData *sub_02026324(u32 param0); -void Pokedex_Copy(const PokedexData *src, PokedexData *dest); -void Pokedex_Init(PokedexData *param0); -u16 sub_02026DD0(const PokedexData *param0); -u16 Pokedex_CountSeenNational(const PokedexData *pokedex); -u16 Pokedex_CountSeen(const PokedexData *pokedex); -u16 sub_02026E64(const PokedexData *param0); -u16 Pokedex_CountSeenSinnoh(const PokedexData *pokedex); -BOOL sub_02026EF4(const PokedexData *param0); -BOOL sub_02026F0C(const PokedexData *param0); -u16 sub_02026F20(const PokedexData *param0); -u16 sub_02026F58(const PokedexData *param0); -BOOL Pokedex_HasCaughtSpecies(const PokedexData *pokedex, u16 species); -BOOL Pokedex_HasSeenSpecies(const PokedexData *pokedex, u16 species); -u32 sub_0202702C(const PokedexData *param0, u8 param1); -u32 sub_02027058(const PokedexData *param0, u16 param1, int param2); -u32 sub_020270AC(const PokedexData *param0, int param1); -u32 sub_020270DC(const PokedexData *param0); -u32 sub_020270F8(const PokedexData *param0, int param1); -u32 sub_02027130(const PokedexData *param0); -u32 sub_02027154(const PokedexData *param0, int param1); -u32 sub_0202718C(const PokedexData *param0); -u32 sub_020271B0(const PokedexData *param0, int param1); -u32 sub_020271E8(const PokedexData *param0); -u32 sub_02027208(const PokedexData *param0, int param1); -u32 sub_02027240(const PokedexData *param0); -u32 sub_02027264(const PokedexData *param0, int param1); -u32 sub_02027288(const PokedexData *param0); -void sub_020272A4(PokedexData *param0, Pokemon *param1); -void sub_0202736C(PokedexData *param0, Pokemon *param1); -void sub_02027454(PokedexData *param0); -BOOL Pokedex_IsNationalDexObtained(const PokedexData *pokedex); -BOOL sub_02027494(const PokedexData *param0); -void sub_020274B0(PokedexData *param0); -BOOL sub_020274D0(const PokedexData *param0, u16 param1, u32 param2); -void sub_02027508(PokedexData *param0); -BOOL sub_02027514(const PokedexData *param0); -BOOL Pokedex_IsObtained(const PokedexData *pokedex); -void Pokedex_FlagObtained(PokedexData *param0); -PokedexData *SaveData_Pokedex(SaveData *saveData); -u32 sub_0202756C(const PokedexData *param0, int param1, int param2); -u32 sub_020276C8(const PokedexData *param0, int param1); - -#endif // POKEPLATINUM_UNK_0202631C_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index 102ddbbe4f..21f75a748c 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -109,7 +109,7 @@ Static main Object main.nef.p/src_unk_0202602C.c.o Object main.nef.p/src_unk_02026150.c.o Object main.nef.p/src_unk_020261E4.c.o - Object main.nef.p/src_unk_0202631C.c.o + Object main.nef.p/src_pokedex_data.c.o Object main.nef.p/src_savedata_misc.c.o Object main.nef.p/src_game_options.c.o Object main.nef.p/src_berry_patches.c.o diff --git a/src/battle/ov16_0223B140.c b/src/battle/ov16_0223B140.c index 9b72a0b86c..d69d3ec24c 100644 --- a/src/battle/ov16_0223B140.c +++ b/src/battle/ov16_0223B140.c @@ -56,6 +56,7 @@ #include "overlay_manager.h" #include "palette.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "render_text.h" #include "render_window.h" @@ -80,7 +81,6 @@ #include "unk_0201E3D8.h" #include "unk_0202419C.h" #include "unk_02024220.h" -#include "unk_0202631C.h" #include "unk_0202F1D4.h" #include "unk_02033200.h" #include "unk_020363E8.h" @@ -731,7 +731,7 @@ static void ov16_0223BCB4(OverlayManager *param0) sub_02015760(v0->unk_1AC); Bag_Copy(v0->unk_58, v1->bag); Heap_FreeToHeap(v0->unk_58); - Pokedex_Copy(v0->pokedex, v1->pokedex); + PokedexData_Copy(v0->pokedex, v1->pokedex); Heap_FreeToHeap(v0->pokedex); v1->pcBoxes = v0->pcBoxes; @@ -1084,8 +1084,8 @@ static void ov16_0223C2C0(BattleSystem *param0, FieldBattleDTO *param1) param0->unk_58 = Bag_New(5); Bag_Copy(param1->bag, param0->unk_58); - param0->pokedex = sub_02026324(5); - Pokedex_Copy(param1->pokedex, param0->pokedex); + param0->pokedex = PokedexData_Alloc(5); + PokedexData_Copy(param1->pokedex, param0->pokedex); param0->pcBoxes = param1->pcBoxes; param0->unk_1B0 = param1->options; diff --git a/src/battle/ov16_0223DF00.c b/src/battle/ov16_0223DF00.c index 177da54b91..5e8832a640 100644 --- a/src/battle/ov16_0223DF00.c +++ b/src/battle/ov16_0223DF00.c @@ -57,6 +57,7 @@ #include "message.h" #include "palette.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "render_text.h" @@ -69,7 +70,6 @@ #include "unk_02005474.h" #include "unk_0200F174.h" #include "unk_02014A84.h" -#include "unk_0202631C.h" #include "unk_0202F1D4.h" #include "unk_0206CCB0.h" @@ -1690,12 +1690,12 @@ void BattleSystem_DexFlagSeen(BattleSystem *param0, int param1) if ((param0->battleType & (0x4 | 0x80)) == 0) { if ((v0 & 0x1) || (param0->battleType == (0x2 | 0x8 | 0x40)) || (param0->battleType == ((0x2 | 0x1) | 0x8 | 0x40))) { - sub_020272A4(param0->pokedex, v1); + PokedexData_CaptureEntry(param0->pokedex, v1); } } if (((v0 & 0x1) == 0) && (Pokemon_GetValue(v1, MON_DATA_SPECIES_EGG, NULL) == 412)) { - sub_0202736C(param0->pokedex, v1); + PokedexData_TradeEntry(param0->pokedex, v1); } } @@ -1714,7 +1714,7 @@ void ov16_0223F9A0(BattleSystem *param0, int param1) v2 = BattleContext_Get(param0, param0->battleCtx, 2, param1); v1 = BattleSystem_PartyPokemon(param0, param1, v2); - sub_0202736C(param0->pokedex, v1); + PokedexData_TradeEntry(param0->pokedex, v1); } } } @@ -1722,7 +1722,7 @@ void ov16_0223F9A0(BattleSystem *param0, int param1) BOOL BattleSystem_CaughtSpecies(BattleSystem *battleSys, int species) { - return Pokedex_HasCaughtSpecies(battleSys->pokedex, species); + return PokedexData_HasCaughtSpecies(battleSys->pokedex, species); } void Battle_SetDefaultBlend(void) diff --git a/src/field_battle_data_transfer.c b/src/field_battle_data_transfer.c index 46c525fe43..635861e582 100644 --- a/src/field_battle_data_transfer.c +++ b/src/field_battle_data_transfer.c @@ -39,6 +39,7 @@ #include "message.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "rtc.h" @@ -49,7 +50,6 @@ #include "system_flags.h" #include "trainer_info.h" #include "unk_0202602C.h" -#include "unk_0202631C.h" #include "unk_02027F84.h" #include "unk_0202C858.h" #include "unk_0202CC64.h" @@ -105,7 +105,7 @@ FieldBattleDTO *FieldBattleDTO_New(enum HeapId heapID, u32 battleType) } dto->bag = Bag_New(heapID); - dto->pokedex = sub_02026324(heapID); + dto->pokedex = PokedexData_Alloc(heapID); dto->options = Options_New(heapID); dto->unk_10C = sub_0206D140(heapID); dto->bagCursor = NULL; @@ -243,7 +243,7 @@ void FieldBattleDTO_InitFromGameState(FieldBattleDTO *dto, const FieldSystem *fi TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(save); Party *party = Party_GetFromSavedata(save); Bag *bag = SaveData_GetBag(save); - PokedexData *pokedex = SaveData_Pokedex(save); + PokedexData *pokedex = SaveData_PokedexData(save); ChatotCry *chatotCry = GetChatotCryDataFromSave(save); Options *options = SaveData_Options(save); FieldOverworldState *fieldOverworldState = SaveData_GetFieldOverworldState(save); @@ -262,7 +262,7 @@ void FieldBattleDTO_InitFromGameState(FieldBattleDTO *dto, const FieldSystem *fi FieldBattleDTO_CopyTrainerInfoToBattler(dto, trainerInfo, BATTLER_PLAYER_SLOT_1); FieldBattleDTO_CopyPartyToBattler(dto, party, BATTLER_PLAYER_SLOT_1); Bag_Copy(bag, dto->bag); - Pokedex_Copy(pokedex, dto->pokedex); + PokedexData_Copy(pokedex, dto->pokedex); Options_Copy(options, dto->options); FieldBattleDTO_CopyChatotCryToBattler(dto, chatotCry, BATTLER_PLAYER_SLOT_1); @@ -296,7 +296,7 @@ void FieldBattleDTO_InitWithNormalizedMonLevels(FieldBattleDTO *dto, const Field TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(fieldSystem->saveData); Party *party = Party_GetFromSavedata(fieldSystem->saveData); Bag *bag = SaveData_GetBag(fieldSystem->saveData); - PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); ChatotCry *chatotCry = GetChatotCryDataFromSave(fieldSystem->saveData); Options *options = SaveData_Options(fieldSystem->saveData); @@ -321,7 +321,7 @@ void FieldBattleDTO_InitWithNormalizedMonLevels(FieldBattleDTO *dto, const Field Heap_FreeToHeap(mon); Bag_Copy(bag, dto->bag); - Pokedex_Copy(pokedex, dto->pokedex); + PokedexData_Copy(pokedex, dto->pokedex); Options_Copy(options, dto->options); FieldBattleDTO_CopyChatotCryToBattler(dto, chatotCry, BATTLER_PLAYER_SLOT_1); @@ -344,7 +344,7 @@ void FieldBattleDTO_InitWithPartyOrder(FieldBattleDTO *dto, const FieldSystem *f { TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(fieldSystem->saveData); Bag *bag = SaveData_GetBag(fieldSystem->saveData); - PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); ChatotCry *chatotCry = GetChatotCryDataFromSave(fieldSystem->saveData); Options *options = SaveData_Options(fieldSystem->saveData); const BattleRegulation *regulation = fieldSystem->unk_B0; @@ -387,7 +387,7 @@ void FieldBattleDTO_InitWithPartyOrder(FieldBattleDTO *dto, const FieldSystem *f } Bag_Copy(bag, dto->bag); - Pokedex_Copy(pokedex, dto->pokedex); + PokedexData_Copy(pokedex, dto->pokedex); Options_Copy(options, dto->options); FieldBattleDTO_CopyChatotCryToBattler(dto, chatotCry, BATTLER_PLAYER_SLOT_1); @@ -424,13 +424,13 @@ void FieldBattleDTO_UpdateFieldSystem(const FieldBattleDTO *dto, FieldSystem *fi TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(fieldSystem->saveData); Party *party = Party_GetFromSavedata(fieldSystem->saveData); Bag *bag = SaveData_GetBag(fieldSystem->saveData); - PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); u16 *fieldSysSafariBalls = FieldOverworldState_GetSafariBallCount(SaveData_GetFieldOverworldState(fieldSystem->saveData)); TrainerInfo_Copy(dto->trainerInfo[BATTLER_PLAYER_SLOT_1], trainerInfo); Party_cpy(dto->parties[BATTLER_PLAYER_SLOT_1], party); Bag_Copy(dto->bag, bag); - Pokedex_Copy(dto->pokedex, pokedex); + PokedexData_Copy(dto->pokedex, pokedex); *fieldSysSafariBalls = dto->countSafariBalls; } @@ -440,9 +440,9 @@ void FieldBattleDTO_UpdatePokedex(const FieldBattleDTO *dto, FieldSystem *fieldS TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(fieldSystem->saveData); Party *party = Party_GetFromSavedata(fieldSystem->saveData); Bag *bag = SaveData_GetBag(fieldSystem->saveData); - PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); - Pokedex_Copy(dto->pokedex, pokedex); + PokedexData_Copy(dto->pokedex, pokedex); } static const enum Terrain sTerrainForBackground[] = { diff --git a/src/field_menu.c b/src/field_menu.c index b7546524af..f3957898d6 100644 --- a/src/field_menu.c +++ b/src/field_menu.c @@ -51,6 +51,7 @@ #include "narc.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "render_window.h" @@ -68,7 +69,6 @@ #include "unk_0200C6E4.h" #include "unk_0200F174.h" #include "unk_02014A84.h" -#include "unk_0202631C.h" #include "unk_02028124.h" #include "unk_0202D778.h" #include "unk_02033200.h" @@ -359,7 +359,7 @@ static u32 sub_0203ABD0(FieldSystem *fieldSystem) { u32 v0 = 0; - if (Pokedex_IsObtained(SaveData_Pokedex(fieldSystem->saveData)) == FALSE) { + if (PokedexData_IsObtained(SaveData_PokedexData(fieldSystem->saveData)) == FALSE) { v0 |= 0x1; } @@ -948,7 +948,7 @@ static BOOL FieldMenu_Pokedex(FieldTask *taskMan) fieldSystem = FieldTask_GetFieldSystem(taskMan); menu = FieldTask_GetEnv(taskMan); v2 = Heap_AllocFromHeap(11, sizeof(UnkStruct_ov21_021D0D80)); - v3 = SaveData_Pokedex(fieldSystem->saveData); + v3 = SaveData_PokedexData(fieldSystem->saveData); v4 = SaveData_GetTrainerInfo(fieldSystem->saveData); v5 = SaveData_GetVarsFlags(fieldSystem->saveData); @@ -1929,9 +1929,9 @@ static void FieldMenu_EvolveInit(FieldTask *taskMan) v4 = Party_GetPokemonBySlotIndex(v3, v2->unk_00); if (v2->unk_01 == 0) { - v5 = sub_0207AE68(v3, v4, v2->unk_04, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_Pokedex(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v2->unk_08, 0x1, 73); + v5 = sub_0207AE68(v3, v4, v2->unk_04, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_PokedexData(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v2->unk_08, 0x1, 73); } else { - v5 = sub_0207AE68(v3, v4, v2->unk_04, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_Pokedex(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v2->unk_08, NULL, 73); + v5 = sub_0207AE68(v3, v4, v2->unk_04, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_PokedexData(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v2->unk_08, NULL, 73); } { diff --git a/src/game_records.c b/src/game_records.c index 2b86b58cb9..ea26ec9442 100644 --- a/src/game_records.c +++ b/src/game_records.c @@ -4,7 +4,7 @@ #include "game_records.h" #include "math.h" -#include "unk_0202631C.h" +#include "pokedex_data.h" #define START_ENCODED_RECORDS RECORD_TRAINER_SCORE #define SIZE_ENCODED_RECORDS (sizeof(GameRecords) - sizeof(EncodingSeed) - (START_ENCODED_RECORDS * sizeof(u32))) @@ -409,7 +409,7 @@ u32 GameRecords_GetTrainerScore(GameRecords *records) void GameRecords_IncrementTrainerScoreOnCatch(GameRecords *records, const PokedexData *pokedex, const u16 species) { - if (!Pokedex_HasCaughtSpecies(pokedex, species)) { + if (!PokedexData_HasCaughtSpecies(pokedex, species)) { GameRecords_IncrementTrainerScore(records, TRAINER_SCORE_EVENT_CAUGHT_SPECIES); } } diff --git a/src/meson.build b/src/meson.build index 17f9330bee..1f4ee375d3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -101,7 +101,7 @@ pokeplatinum_c = files( 'unk_0202602C.c', 'unk_02026150.c', 'unk_020261E4.c', - 'unk_0202631C.c', + 'pokedex_data.c', 'savedata_misc.c', 'game_options.c', 'berry_patches.c', diff --git a/src/overlay005/ov5_021F6454.c b/src/overlay005/ov5_021F6454.c index 048e945ae7..82330e9194 100644 --- a/src/overlay005/ov5_021F6454.c +++ b/src/overlay005/ov5_021F6454.c @@ -34,6 +34,7 @@ #include "narc.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokemon.h" #include "render_window.h" #include "savedata_misc.h" @@ -47,7 +48,6 @@ #include "unk_02005474.h" #include "unk_0200F174.h" #include "unk_02020AEC.h" -#include "unk_0202631C.h" #include "unk_0202C858.h" #include "unk_02030880.h" #include "unk_02038F8C.h" @@ -676,7 +676,7 @@ BOOL ScrCmd_304(ScriptContext *param0) v4 = Party_GetPokemonBySlotIndex(v5, v7); Pokemon_SetRotomForm(v4, v10, v8); - sub_0202736C(SaveData_Pokedex(fieldSystem->saveData), v4); + PokedexData_TradeEntry(SaveData_PokedexData(fieldSystem->saveData), v4); return 0; } diff --git a/src/overlay005/ov5_021F77A8.c b/src/overlay005/ov5_021F77A8.c index 25a233c615..1c809ad17a 100644 --- a/src/overlay005/ov5_021F77A8.c +++ b/src/overlay005/ov5_021F77A8.c @@ -20,6 +20,7 @@ #include "list_menu.h" #include "message.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "render_window.h" #include "script_manager.h" @@ -31,7 +32,6 @@ #include "tutor_movesets.h" #include "unk_02005474.h" #include "unk_0200F174.h" -#include "unk_0202631C.h" #include "unk_02054884.h" #include "res/pokemon/tutor_movesets.h" @@ -90,9 +90,9 @@ BOOL ScrCmd_337(ScriptContext *param0) { u16 v0 = FieldSystem_TryGetVar(param0->fieldSystem, ScriptContext_ReadHalfWord(param0)); u16 *v1 = FieldSystem_GetVarPointer(param0->fieldSystem, ScriptContext_ReadHalfWord(param0)); - PokedexData *v2 = SaveData_Pokedex(param0->fieldSystem->saveData); + PokedexData *v2 = SaveData_PokedexData(param0->fieldSystem->saveData); - *v1 = Pokedex_HasSeenSpecies(v2, v0); + *v1 = PokedexData_HasSeenSpecies(v2, v0); return 0; } diff --git a/src/overlay005/save_info_window.c b/src/overlay005/save_info_window.c index 5fe0abdb22..326c866765 100644 --- a/src/overlay005/save_info_window.c +++ b/src/overlay005/save_info_window.c @@ -21,13 +21,13 @@ #include "map_header.h" #include "message_util.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "render_window.h" #include "save_player.h" #include "savedata.h" #include "strbuf.h" #include "text.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_020366A0.h" static void FieldSystem_SaveObjectsAndLocation(FieldSystem *fieldSystem); @@ -51,12 +51,12 @@ static void SaveInfo_SetValues(SaveInfo *saveInfo, const FieldSystem *fieldSyste { SaveData *saveData = fieldSystem->saveData; Location *curLocation = FieldOverworldState_GetPlayerLocation(SaveData_GetFieldOverworldState(saveData)); - PokedexData *pokedex = SaveData_Pokedex(saveData); + PokedexData *pokedex = SaveData_PokedexData(saveData); saveInfo->mapLabelTextID = MapHeader_GetMapLabelTextID(curLocation->mapId); - if (Pokedex_IsObtained(pokedex)) { - saveInfo->pokedexCount = Pokedex_CountSeen(pokedex); + if (PokedexData_IsObtained(pokedex)) { + saveInfo->pokedexCount = PokedexData_CountSeen(pokedex); } else { saveInfo->pokedexCount = 0; } diff --git a/src/overlay006/ov6_02240C9C.c b/src/overlay006/ov6_02240C9C.c index 186c3890fd..35db9c5ea9 100644 --- a/src/overlay006/ov6_02240C9C.c +++ b/src/overlay006/ov6_02240C9C.c @@ -40,6 +40,7 @@ #include "narc.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokemon.h" #include "pokeradar.h" #include "roaming_pokemon.h" @@ -48,7 +49,6 @@ #include "system_flags.h" #include "trainer_data.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_0202D7A8.h" #include "unk_02054884.h" #include "unk_02054D00.h" @@ -325,7 +325,7 @@ BOOL ov6_02240D5C(FieldSystem *fieldSystem) v13[i].minLevel = encounterData->grassEncounters.encounters[i].level; } - BOOL nationalDexObtained = Pokedex_IsNationalDexObtained(SaveData_Pokedex(FieldSystem_GetSaveData(fieldSystem))); + BOOL nationalDexObtained = PokedexData_IsNationalDexObtained(SaveData_PokedexData(FieldSystem_GetSaveData(fieldSystem))); WildEncounters_ReplaceTimedEncounters(encounterData, &v13[2].species, &v13[3].species); WildEncounters_ReplaceRadarEncounters(fieldSystem, encounterData, &v13[0].species, &v13[1].species); @@ -513,7 +513,7 @@ BOOL ov6_022411C8(FieldSystem *fieldSystem, FieldTask *param1) v12[i].minLevel = encounterData->grassEncounters.encounters[i].level; } - BOOL nationalDexObtained = Pokedex_IsNationalDexObtained(SaveData_Pokedex(FieldSystem_GetSaveData(fieldSystem))); + BOOL nationalDexObtained = PokedexData_IsNationalDexObtained(SaveData_PokedexData(FieldSystem_GetSaveData(fieldSystem))); WildEncounters_ReplaceTimedEncounters(encounterData, &v12[2].species, &v12[3].species); WildEncounters_ReplaceRadarEncounters(fieldSystem, encounterData, &v12[0].species, &v12[1].species); @@ -642,7 +642,7 @@ BOOL ov6_022413E4(FieldSystem *fieldSystem, FieldBattleDTO **battleParams) v12[i].minLevel = encounterData->grassEncounters.encounters[i].level; } - BOOL nationalDexObtained = Pokedex_IsNationalDexObtained(SaveData_Pokedex(FieldSystem_GetSaveData(fieldSystem))); + BOOL nationalDexObtained = PokedexData_IsNationalDexObtained(SaveData_PokedexData(FieldSystem_GetSaveData(fieldSystem))); WildEncounters_ReplaceTimedEncounters(encounterData, &v12[2].species, &v12[3].species); WildEncounters_ReplaceRadarEncounters(fieldSystem, encounterData, &v12[0].species, &v12[1].species); diff --git a/src/overlay006/ov6_02242984.c b/src/overlay006/ov6_02242984.c index 862a366753..f463b14120 100644 --- a/src/overlay006/ov6_02242984.c +++ b/src/overlay006/ov6_02242984.c @@ -16,7 +16,7 @@ #include "map_header_data.h" #include "narc.h" #include "player_avatar.h" -#include "unk_0202631C.h" +#include "pokedex_data.h" #include "unk_0202D7A8.h" #include "unk_02039C80.h" @@ -42,7 +42,7 @@ int ov6_02242984(FieldSystem *fieldSystem) v2[i] = encounterData->grassEncounters.encounters[i].species; } - BOOL v1 = Pokedex_IsNationalDexObtained(SaveData_Pokedex(FieldSystem_GetSaveData(fieldSystem))); + BOOL v1 = PokedexData_IsNationalDexObtained(SaveData_PokedexData(FieldSystem_GetSaveData(fieldSystem))); ov6_02242F74(sub_0202D814(sub_0202D834(fieldSystem->saveData), 1), v1, fieldSystem->location->mapId, &v2[6], &v2[7]); WildEncounters_ReplaceTimedEncounters(encounterData, &v2[2], &v2[3]); diff --git a/src/overlay006/ov6_02246A30.c b/src/overlay006/ov6_02246A30.c index f22f66e322..cef25dfafc 100644 --- a/src/overlay006/ov6_02246A30.c +++ b/src/overlay006/ov6_02246A30.c @@ -11,10 +11,10 @@ #include "inlines.h" #include "math.h" +#include "pokedex_data.h" #include "save_player.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "vars_flags.h" typedef BOOL (*UnkStruct_ov6_022494B0)(FieldSystem *); @@ -144,14 +144,14 @@ static BOOL ov6_02246AB0(FieldSystem *fieldSystem) static BOOL ov6_02246AC8(FieldSystem *fieldSystem) { - PokedexData *v0 = SaveData_Pokedex(fieldSystem->saveData); - return sub_02026F0C(v0); + PokedexData *v0 = SaveData_PokedexData(fieldSystem->saveData); + return PokedexData_LocalDexCompleted(v0); } static BOOL ov6_02246AD8(FieldSystem *fieldSystem) { - PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); - return Pokedex_IsObtained(pokedex); + PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); + return PokedexData_IsObtained(pokedex); } static BOOL ov6_02246AE8(FieldSystem *fieldSystem) diff --git a/src/overlay021/ov21_021D0D80.c b/src/overlay021/ov21_021D0D80.c index a638a00a09..8514acf2ea 100644 --- a/src/overlay021/ov21_021D0D80.c +++ b/src/overlay021/ov21_021D0D80.c @@ -55,6 +55,7 @@ #include "heap.h" #include "message.h" #include "overlay_manager.h" +#include "pokedex_data.h" #include "pokedex_data_index.h" #include "pokemon.h" #include "sprite_resource.h" @@ -73,7 +74,6 @@ #include "unk_0201E86C.h" #include "unk_0201F834.h" #include "unk_0202419C.h" -#include "unk_0202631C.h" #include "unk_0209ACBC.h" typedef struct UnkStruct_ov21_021D0F60_t { @@ -136,7 +136,7 @@ int ov21_021D0D80(OverlayManager *param0, int *param1) { u32 v4; - v4 = sub_0202756C(v1->unk_00, 487, 0); + v4 = PokedexData_GetDisplayForm(v1->unk_00, 487, 0); Pokedex_SetupGiratina(v4); } diff --git a/src/overlay021/pokedex_sort.c b/src/overlay021/pokedex_sort.c index 82731c33fa..89012c9688 100644 --- a/src/overlay021/pokedex_sort.c +++ b/src/overlay021/pokedex_sort.c @@ -14,11 +14,11 @@ #include "graphics.h" #include "heap.h" #include "narc.h" +#include "pokedex_data.h" #include "pokedex_data_index.h" #include "pokedex_heightweight.h" #include "strbuf.h" #include "trainer_info.h" -#include "unk_0202631C.h" #define NUMSTATFILES 11 #define BLANKSPACE (NATIONAL_DEX_COUNT + 1) @@ -101,7 +101,7 @@ void PokedexSort_PopulatePokedexStatus(UnkStruct_ov21_021D3320 *param0, UnkStruc param0->dexData = param1->dexData; param0->timeOfDay = param1->timeOfDay; - if (Pokedex_IsNationalDexObtained(param0->dexData)) { + if (PokedexData_IsNationalDexObtained(param0->dexData)) { param0->isNationalDexUnlocked = TRUE; } else { param0->isNationalDexUnlocked = FALSE; @@ -171,7 +171,7 @@ u32 ov21_021D334C(const UnkStruct_ov21_021D3320 *param0, int param1, int param2) { u32 v0; - v0 = sub_02027058(param0->dexData, param1, param2); + v0 = PokedexData_DisplayedGender(param0->dexData, param1, param2); return v0; } @@ -180,7 +180,7 @@ u32 ov21_021D335C(const UnkStruct_ov21_021D3320 *param0, int param1) int v0; GF_ASSERT(param1 < 28); - v0 = sub_020270AC(param0->dexData, param1); + v0 = PokedexData_GetForm_Unown(param0->dexData, param1); return v0; } @@ -190,7 +190,7 @@ u32 ov21_021D3374(const UnkStruct_ov21_021D3320 *param0, int param1) u32 v0; GF_ASSERT(param1 < 2); - v0 = sub_020270F8(param0->dexData, param1); + v0 = PokedexData_GetForm_Shellos(param0->dexData, param1); return v0; } @@ -201,7 +201,7 @@ u32 ov21_021D338C(const UnkStruct_ov21_021D3320 *param0, int param1) GF_ASSERT(param1 < 2); - v0 = sub_02027154(param0->dexData, param1); + v0 = PokedexData_GetForm_Gastrodon(param0->dexData, param1); return v0; } @@ -211,7 +211,7 @@ u32 ov21_021D33A4(const UnkStruct_ov21_021D3320 *param0, int param1) GF_ASSERT(param1 < 3); - v0 = sub_020271B0(param0->dexData, param1); + v0 = PokedexData_GetForm_Burmy(param0->dexData, param1); return v0; } @@ -221,13 +221,13 @@ u32 ov21_021D33BC(const UnkStruct_ov21_021D3320 *param0, int param1) GF_ASSERT(param1 < 3); - v0 = sub_02027208(param0->dexData, param1); + v0 = PokedexData_GetForm_Wormadam(param0->dexData, param1); return v0; } u32 ov21_021D33D4(const UnkStruct_ov21_021D3320 *param0, u32 species) { - return sub_0202756C(param0->dexData, species, 0); + return PokedexData_GetDisplayForm(param0->dexData, species, 0); } u32 ov21_021D33E0(const UnkStruct_ov21_021D3320 *param0, int param1) @@ -243,27 +243,27 @@ u32 ov21_021D33E0(const UnkStruct_ov21_021D3320 *param0, int param1) u32 ov21_021D33F8(const UnkStruct_ov21_021D3320 *param0) { - return sub_0202702C(param0->dexData, 0); + return PokedexData_GetForm_Spinda(param0->dexData, 0); } u32 ov21_021D3404(const UnkStruct_ov21_021D3320 *param0, int param1) { - return sub_02027264(param0->dexData, param1); + return PokedexData_GetForm_Deoxys(param0->dexData, param1); } u32 ov21_021D3410(const UnkStruct_ov21_021D3320 *param0, u32 param1, int param2) { - return sub_0202756C(param0->dexData, param1, param2); + return PokedexData_GetDisplayForm(param0->dexData, param1, param2); } u32 ov21_021D341C(const UnkStruct_ov21_021D3320 *param0, u32 param1) { - return sub_020276C8(param0->dexData, param1); + return PokedexData_NumFormsSeen(param0->dexData, param1); } BOOL PokedexSort_IsNationalUnlocked(const UnkStruct_ov21_021D3320 *param0) { - return Pokedex_IsNationalDexObtained(param0->dexData); + return PokedexData_IsNationalDexObtained(param0->dexData); } void ov21_021D3434(UnkStruct_ov21_021D3320 *param0, u32 param1) @@ -620,16 +620,16 @@ BOOL ov21_021D392C(const UnkStruct_ov21_021D3320 *param0, int param1) { int species = PokedexSort_CurrentSpecies(param0); - if (sub_02027514(param0->dexData) == 0) { + if (PokedexData_CanDetectLanguages(param0->dexData) == 0) { return FALSE; } - return sub_020274D0(param0->dexData, species, param1); + return PokedexData_IsLanguageObtained(param0->dexData, species, param1); } BOOL PokedexSort_CanDetectForms(const UnkStruct_ov21_021D3320 *param0) { - return Pokedex_CanDetectForms(param0->dexData); + return PokedexData_CanDetectForms(param0->dexData); } void ov21_021D3960(UnkStruct_ov21_021D3320 *param0) @@ -658,7 +658,7 @@ static void FilterUnencountered(u16 *encounteredDex, int *caughtStatusLength, co *caughtStatusLength = 0; for (int species = 0; species < pokedexLength; species++) { - if (Pokedex_HasSeenSpecies(dexData, fullDex[species])) { + if (PokedexData_HasSeenSpecies(dexData, fullDex[species])) { encounteredDex[*caughtStatusLength] = fullDex[species]; (*caughtStatusLength)++; } @@ -677,7 +677,7 @@ static void IntersectPokedexes(u16 *resultingPokedex, int *numResulting, const u if (keepUncaught == TRUE) { break; } else { - if (Pokedex_HasCaughtSpecies(dexData, pokedex1[dexIndex1])) { + if (PokedexData_HasCaughtSpecies(dexData, pokedex1[dexIndex1])) { break; } } @@ -696,7 +696,7 @@ static void UpdateCaughtStatus(SortedPokedex *sortedPokedex, const PokedexData * sortedPokedex->caughtStatusLength = 0; for (int dexIndex = 0; dexIndex < caughtStatusLength; dexIndex++) { - if (Pokedex_HasCaughtSpecies(dexData, encounteredPokedex[dexIndex])) { + if (PokedexData_HasCaughtSpecies(dexData, encounteredPokedex[dexIndex])) { sortedPokedex->caughtStatusArray[sortedPokedex->caughtStatusLength].caughtStatus = CS_CAUGHT; } else { sortedPokedex->caughtStatusArray[sortedPokedex->caughtStatusLength].caughtStatus = CS_ENCOUNTERED; diff --git a/src/overlay023/ov23_0223E140.c b/src/overlay023/ov23_0223E140.c index 69804947e9..e41b2b433b 100644 --- a/src/overlay023/ov23_0223E140.c +++ b/src/overlay023/ov23_0223E140.c @@ -41,6 +41,7 @@ #include "math.h" #include "menu.h" #include "narc.h" +#include "pokedex_data.h" #include "render_window.h" #include "save_player.h" #include "savedata.h" @@ -62,7 +63,6 @@ #include "unk_0201DBEC.h" #include "unk_0201E86C.h" #include "unk_0201F834.h" -#include "unk_0202631C.h" #include "unk_0202854C.h" #include "unk_020393C8.h" #include "unk_02039C80.h" @@ -1780,7 +1780,7 @@ static int ov23_0223F970(UnkStruct_ov23_02256EB0 *param0) SaveData *v0 = FieldSystem_GetSaveData(Unk_ov23_02257740->fieldSystem); UndergroundData *v1 = sub_020298B0(v0); BOOL v2 = TrainerInfo_ID(SaveData_GetTrainerInfo(v0)) % 2; - BOOL v3 = Pokedex_IsNationalDexObtained(SaveData_Pokedex(v0)); + BOOL v3 = PokedexData_IsNationalDexObtained(SaveData_PokedexData(v0)); int v4 = 0; if (v3) { diff --git a/src/overlay023/ov23_022521F0.c b/src/overlay023/ov23_022521F0.c index efbf1d5349..a5e935e502 100644 --- a/src/overlay023/ov23_022521F0.c +++ b/src/overlay023/ov23_022521F0.c @@ -27,6 +27,7 @@ #include "map_object.h" #include "menu.h" #include "message.h" +#include "pokedex_data.h" #include "render_window.h" #include "savedata.h" #include "strbuf.h" @@ -36,7 +37,6 @@ #include "sys_task_manager.h" #include "text.h" #include "unk_02005474.h" -#include "unk_0202631C.h" #include "unk_0202854C.h" #include "unk_020573FC.h" @@ -133,7 +133,7 @@ static void ov23_022522F0(UnkStruct_ov23_02250CD4 *param0, int param1) int v1, v2, v3, v4, v5; SaveData *v6 = FieldSystem_GetSaveData(param0->fieldSystem); UndergroundData *v7 = sub_020298B0(v6); - BOOL v8 = Pokedex_IsNationalDexObtained(SaveData_Pokedex(v6)); + BOOL v8 = PokedexData_IsNationalDexObtained(SaveData_PokedexData(v6)); MATH_InitRand16(&v0, sub_02028930(v7) + param1); diff --git a/src/overlay028/ov28_022561C0.c b/src/overlay028/ov28_022561C0.c index cba4ccbffd..da7c8c673f 100644 --- a/src/overlay028/ov28_022561C0.c +++ b/src/overlay028/ov28_022561C0.c @@ -16,11 +16,11 @@ #include "bg_window.h" #include "heap.h" +#include "pokedex_data.h" #include "pokemon.h" #include "sys_task.h" #include "sys_task_manager.h" #include "touch_screen.h" -#include "unk_0202631C.h" typedef struct { u8 unk_00; @@ -635,15 +635,15 @@ static void ov28_02256914(UnkStruct_ov28_02256210 *param0, const UnkStruct_ov28_ PokedexData *v1; u16 v2; - v1 = SaveData_Pokedex(PoketchSystem_GetSaveData(param0->poketchSys)); + v1 = SaveData_PokedexData(PoketchSystem_GetSaveData(param0->poketchSys)); - if (Pokedex_IsNationalDexObtained(v1)) { + if (PokedexData_IsNationalDexObtained(v1)) { v2 = v0; } else { v2 = Pokemon_NationalDexNumber((u16)v0); } - if (v2 > 0 && v2 <= NATIONAL_DEX_COUNT && Pokedex_HasSeenSpecies(v1, v2)) { + if (v2 > 0 && v2 <= NATIONAL_DEX_COUNT && PokedexData_HasSeenSpecies(v1, v2)) { ov25_02254444(v2, 0); } } diff --git a/src/overlay062/ov62_02237D24.c b/src/overlay062/ov62_02237D24.c index 86a579927b..cfae3a8252 100644 --- a/src/overlay062/ov62_02237D24.c +++ b/src/overlay062/ov62_02237D24.c @@ -37,6 +37,7 @@ #include "heap.h" #include "message.h" #include "palette.h" +#include "pokedex_data.h" #include "strbuf.h" #include "string_template.h" #include "text.h" @@ -48,7 +49,6 @@ #include "unk_0201DBEC.h" #include "unk_02023FCC.h" #include "unk_0202419C.h" -#include "unk_0202631C.h" #include "unk_020298BC.h" #include "unk_02030A80.h" #include "unk_0208B284.h" @@ -1472,10 +1472,10 @@ static BOOL ov62_02239984(UnkStruct_0208C06C *param0, int param1) int v7; int v8 = 0; BOOL v9; - PokedexData *v10 = SaveData_Pokedex(param0->unk_830); + PokedexData *v10 = SaveData_PokedexData(param0->unk_830); for (v7 = v3; v7 < v4; v7++) { - v9 = Pokedex_HasSeenSpecies(v10, v1[v7]); + v9 = PokedexData_HasSeenSpecies(v10, v1[v7]); if (v9 == 0) { v1[v7] = 0xFFFF; @@ -1516,12 +1516,12 @@ static void ov62_02239A0C(UnkStruct_0208C06C *param0, int param1) int v5; int v6 = 0; BOOL v7; - PokedexData *v8 = SaveData_Pokedex(param0->unk_830); + PokedexData *v8 = SaveData_PokedexData(param0->unk_830); v4->unk_1D4.unk_00 = 0; for (v5 = v2; v5 < v3; v5++) { - v7 = Pokedex_HasSeenSpecies(v8, v0[v5]); + v7 = PokedexData_HasSeenSpecies(v8, v0[v5]); if (v7 == 0) { v0[v5] = 0xFFFF; diff --git a/src/overlay062/ov62_02241204.c b/src/overlay062/ov62_02241204.c index 83db14ef1c..166582942d 100644 --- a/src/overlay062/ov62_02241204.c +++ b/src/overlay062/ov62_02241204.c @@ -50,7 +50,7 @@ #include "unk_0200F174.h" #include "unk_02012744.h" #include "unk_02023FCC.h" -#include "unk_0202631C.h" +#include "pokedex_data.h" #include "unk_0202F1D4.h" #include "unk_02030A80.h" #include "unk_020393C8.h" @@ -1516,10 +1516,10 @@ static BOOL ov62_02242748 (UnkStruct_0208C06C * param0, int param1) int v7; int v8 = 0; BOOL v9; - PokedexData * v10 = SaveData_Pokedex(param0->unk_830); + PokedexData * v10 = SaveData_PokedexData(param0->unk_830); for (v7 = v3; v7 < v4; v7++) { - v9 = Pokedex_HasSeenSpecies(v10, v1[v7]); + v9 = PokedexData_HasSeenSpecies(v10, v1[v7]); if (v9 == 0) { v1[v7] = 0xFFFF; @@ -1560,12 +1560,12 @@ static void ov62_022427D0 (UnkStruct_0208C06C * param0, int param1) int v5; int v6 = 0; BOOL v7; - PokedexData * v8 = SaveData_Pokedex(param0->unk_830); + PokedexData * v8 = SaveData_PokedexData(param0->unk_830); v4->unk_4C8.unk_00 = 0; for (v5 = v2; v5 < v3; v5++) { - v7 = Pokedex_HasSeenSpecies(v8, v0[v5]); + v7 = PokedexData_HasSeenSpecies(v8, v0[v5]); if (v7 == 0) { v0[v5] = 0xFFFF; diff --git a/src/overlay065/ov65_0222DCE0.c b/src/overlay065/ov65_0222DCE0.c index a271d59d86..8362bc6979 100644 --- a/src/overlay065/ov65_0222DCE0.c +++ b/src/overlay065/ov65_0222DCE0.c @@ -78,7 +78,7 @@ #include "unk_0201E86C.h" #include "unk_0201F834.h" #include "unk_02023FCC.h" -#include "unk_0202631C.h" +#include "pokedex_data.h" #include "unk_0202ACE0.h" #include "unk_0202C858.h" #include "unk_0203061C.h" @@ -1793,7 +1793,7 @@ static int ov65_0222F490 (UnkStruct_ov65_0222EBE0 * param0, int param1) static void ov65_0222F4C4 (UnkStruct_ov65_0222EBE0 * param0, int param1) { TrainerInfo * v0 = SaveData_GetTrainerInfo(param0->unk_160); - PokedexData * v1 = SaveData_Pokedex(param0->unk_160); + PokedexData * v1 = SaveData_PokedexData(param0->unk_160); Party * v2 = Party_GetFromSavedata(param0->unk_160); UnkStruct_0202C878 * v3 = sub_0202C878(param0->unk_160); int v4, v5; @@ -1811,7 +1811,7 @@ static void ov65_0222F4C4 (UnkStruct_ov65_0222EBE0 * param0, int param1) param0->unk_04->unk_00.unk_18 = TrainerInfo_GameCode(v0); param0->unk_04->unk_00.unk_19 = TrainerInfo_RegionCode(v0); - param0->unk_04->unk_00.unk_1A = Pokedex_IsNationalDexObtained(v1); + param0->unk_04->unk_00.unk_1A = PokedexData_IsNationalDexObtained(v1); param0->unk_04->unk_00.unk_1B = 29; ov65_02232E70(param0, param1); diff --git a/src/overlay066/ov66_0222DDF0.c b/src/overlay066/ov66_0222DDF0.c index 7408f5dfbb..6e817ef99d 100644 --- a/src/overlay066/ov66_0222DDF0.c +++ b/src/overlay066/ov66_0222DDF0.c @@ -50,6 +50,7 @@ #include "math.h" #include "message.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "save_player.h" #include "savedata.h" @@ -59,7 +60,6 @@ #include "unk_020041CC.h" #include "unk_02005474.h" #include "unk_02014D38.h" -#include "unk_0202631C.h" #include "unk_0202C858.h" #include "unk_02030EA4.h" #include "unk_0207E060.h" @@ -2316,7 +2316,7 @@ static void ov66_0222F7C8(UnkStruct_ov66_0222F6C4 *param0, SaveData *param1, u32 { v0 = SaveData_GetTrainerInfo(param1); v1 = Party_GetFromSavedata(param1); - v3 = SaveData_Pokedex(param1); + v3 = SaveData_PokedexData(param1); v2 = sub_0202C878(param1); v4 = SaveData_GetGameTime(param1); } @@ -2359,7 +2359,7 @@ static void ov66_0222F7C8(UnkStruct_ov66_0222F6C4 *param0, SaveData *param1, u32 param0->unk_20.unk_3A = ov66_02230C0C(param0->unk_20.unk_3A); param0->unk_20.unk_3C = sub_0202C8C0(v2); param0->unk_20.unk_3E = sub_0202C8C4(v2); - param0->unk_20.unk_3F = Pokedex_IsNationalDexObtained(v3); + param0->unk_20.unk_3F = PokedexData_IsNationalDexObtained(v3); param0->unk_20.unk_40 = TrainerInfo_IsMainStoryCleared(v0); param0->unk_20.unk_41 = 0xff; param0->unk_20.unk_43 = 0; diff --git a/src/overlay094/ov94_022414B8.c b/src/overlay094/ov94_022414B8.c index 512803b570..d6b9836bc8 100644 --- a/src/overlay094/ov94_022414B8.c +++ b/src/overlay094/ov94_022414B8.c @@ -32,6 +32,7 @@ #include "message.h" #include "message_util.h" #include "narc.h" +#include "pokedex_data.h" #include "pokemon.h" #include "render_window.h" #include "strbuf.h" @@ -41,7 +42,6 @@ #include "trainer_info.h" #include "unk_02005474.h" #include "unk_0200F174.h" -#include "unk_0202631C.h" #include "unk_0202C858.h" #include "unk_020393C8.h" @@ -1134,12 +1134,12 @@ static int ov94_02242718(StringList **param0, MessageLoader *param1, MessageLoad for (v0 = 0; v0 < v3; v0++) { if (v4) { - if (Pokedex_HasSeenSpecies(param7, param3[v1 + v0])) { + if (PokedexData_HasSeenSpecies(param7, param3[v1 + v0])) { v2++; } } else { if (param4[param3[v1 + v0]]) { - if (Pokedex_HasSeenSpecies(param7, param3[v1 + v0])) { + if (PokedexData_HasSeenSpecies(param7, param3[v1 + v0])) { v2++; } } @@ -1150,12 +1150,12 @@ static int ov94_02242718(StringList **param0, MessageLoader *param1, MessageLoad for (v0 = 0; v0 < v3; v0++) { if (v4) { - if (Pokedex_HasSeenSpecies(param7, param3[v1 + v0])) { + if (PokedexData_HasSeenSpecies(param7, param3[v1 + v0])) { StringList_AddFromMessageBank(*param0, param1, param3[v1 + v0], param3[v1 + v0]); } } else { if (param4[param3[v1 + v0]]) { - if (Pokedex_HasSeenSpecies(param7, param3[v1 + v0])) { + if (PokedexData_HasSeenSpecies(param7, param3[v1 + v0])) { StringList_AddFromMessageBank(*param0, param1, param3[v1 + v0], param3[v1 + v0]); } } diff --git a/src/overlay097/ov97_0222AE60.c b/src/overlay097/ov97_0222AE60.c index a11125d4e0..dcc776053e 100644 --- a/src/overlay097/ov97_0222AE60.c +++ b/src/overlay097/ov97_0222AE60.c @@ -26,6 +26,7 @@ #include "message_util.h" #include "overlay_manager.h" #include "play_time.h" +#include "pokedex_data.h" #include "render_window.h" #include "save_player.h" #include "savedata.h" @@ -41,7 +42,6 @@ #include "unk_02017728.h" #include "unk_0201DBEC.h" #include "unk_02024358.h" -#include "unk_0202631C.h" #include "unk_0202DAB4.h" #include "unk_020366A0.h" #include "unk_0209A74C.h" @@ -237,7 +237,7 @@ static void ov97_0222AF1C(UnkStruct_0222AE60 *param0) sub_02017B70(v0); - if (Pokedex_IsNationalDexObtained(param0->unk_08) == FALSE) { + if (PokedexData_IsNationalDexObtained(param0->unk_08) == FALSE) { return; } @@ -598,7 +598,7 @@ static BOOL ov97_0222B5C0(void *param0, int param1, UnkStruct_ov97_02237808 *par ov97_0222B53C(param2->unk_10, v5, v4, v7, 19, 16 * 3); if (v6->unk_4C) { - ov97_0222B590(v4, Pokedex_CountSeen(v6->unk_08)); + ov97_0222B590(v4, PokedexData_CountSeen(v6->unk_08)); ov97_0222B53C(param2->unk_10, v5, v4, v7, 18, 16 * 4); } @@ -987,9 +987,9 @@ static int ov97_0222BD70(OverlayManager *param0, int *param1) v0->unk_11C = FX32_ONE * 0; v0->unk_120 = FX32_ONE * 0; v0->unk_0C = SaveData_GetTrainerInfo(v0->unk_04); - v0->unk_08 = SaveData_Pokedex(v0->unk_04); + v0->unk_08 = SaveData_PokedexData(v0->unk_04); v0->playTime = SaveData_GetPlayTime(v0->unk_04); - v0->unk_4C = Pokedex_IsObtained(v0->unk_08); + v0->unk_4C = PokedexData_IsObtained(v0->unk_08); v0->unk_50 = TrainerInfo_BadgeCount(v0->unk_0C); v0->unk_12C = 15; diff --git a/src/overlay097/ov97_0222C174.c b/src/overlay097/ov97_0222C174.c index 2e7f12dd03..3b9ecef9c6 100644 --- a/src/overlay097/ov97_0222C174.c +++ b/src/overlay097/ov97_0222C174.c @@ -29,6 +29,7 @@ #include "message.h" #include "message_util.h" #include "overlay_manager.h" +#include "pokedex_data.h" #include "render_window.h" #include "rtc.h" #include "save_player.h" @@ -39,7 +40,6 @@ #include "trainer_info.h" #include "unk_020041CC.h" #include "unk_02005474.h" -#include "unk_0202631C.h" #include "unk_0202DAB4.h" #include "unk_02033200.h" #include "unk_020393C8.h" @@ -681,7 +681,7 @@ static int ov97_0222C6F8(OverlayManager *param0, int *param1) v0->unk_04 = BgConfig_New(v0->unk_00); v0->unk_08 = ((ApplicationArgs *)OverlayManager_Args(param0))->saveData; v0->unk_10 = SaveData_GetTrainerInfo(v0->unk_08); - v0->unk_0C = SaveData_Pokedex(v0->unk_08); + v0->unk_0C = SaveData_PokedexData(v0->unk_08); v0->unk_14 = SaveData_Options(v0->unk_08); ov97_02237694(v0->unk_00); @@ -707,7 +707,7 @@ static int ov97_0222C78C(OverlayManager *param0, int *param1) case UnkEnum_ov97_0222C78C_00: ov97_0222C254(v0); - if (Pokedex_IsObtained(v0->unk_0C) == FALSE) { + if (PokedexData_IsObtained(v0->unk_0C) == FALSE) { ov97_02237790(1, UnkEnum_ov97_0222C78C_01, param1, UnkEnum_ov97_0222C78C_13); } else { *param1 = UnkEnum_ov97_0222C78C_02; diff --git a/src/overlay118/ov118_021D0D80.c b/src/overlay118/ov118_021D0D80.c index de8e9c051a..ba8507c22d 100644 --- a/src/overlay118/ov118_021D0D80.c +++ b/src/overlay118/ov118_021D0D80.c @@ -15,6 +15,7 @@ #include "heap.h" #include "message.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "spl.h" #include "strbuf.h" @@ -23,7 +24,6 @@ #include "unk_02005474.h" #include "unk_02014000.h" #include "unk_0202419C.h" -#include "unk_0202631C.h" #include "unk_0207E0B8.h" #include "unk_020819DC.h" #include "unk_02082C2C.h" @@ -93,7 +93,7 @@ int ov118_021D0DBC(GameWindowLayout *param0) break; } - sub_0202736C(SaveData_Pokedex(FieldSystem_GetSaveData(param0->unk_5A4->unk_1C)), v1); + PokedexData_TradeEntry(SaveData_PokedexData(FieldSystem_GetSaveData(param0->unk_5A4->unk_1C)), v1); } v0->unk_00++; break; diff --git a/src/pokedex_data.c b/src/pokedex_data.c new file mode 100644 index 0000000000..cdab39a15b --- /dev/null +++ b/src/pokedex_data.c @@ -0,0 +1,1240 @@ +#include "pokedex_data.h" + +#include +#include + +#include "constants/species.h" + +#include "heap.h" +#include "inlines.h" +#include "pokemon.h" +#include "savedata.h" +#include "unk_020986CC.h" + +#define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 +#define MAGIC_NUMBER 3203386110 +#define NUM_MYTHICALS_NATIONAL 11 +#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_MYTHICALS_NATIONAL) +#define UNOWN_COUNT 28 +#define DEOXYS_COUNT 4 +#define ROTOM_COUNT 6 +#define TERMINAL_4BITS 0x7 +#define TERMINAL_BYTE 0xf +#define TERMINAL_U8 0xff +#define TERMINAL_U32 0xffffffff + +typedef struct PokedexData { + u32 magic; + u32 caughtPokemon[DEX_SIZE_U32]; + u32 seenPokemon[DEX_SIZE_U32]; + u32 recordedGenders[2][DEX_SIZE_U32]; + u32 spindaForms; + u8 shellosForms; + u8 gastrodonForms; + u8 burmyForms; + u8 wormadamForms; + u8 unownForms[UNOWN_COUNT]; + u8 recordedLanguages[MAX_SPECIES + 1]; + u8 canDetectForms; + u8 canDetectLanguages; + u8 pokedexObtained; + u8 nationalDexObtained; + u32 rotomForms; + u8 shayminForms; + u8 giratinaForms; +} PokedexData; + +int PokedexData_SaveSize(void) +{ + return sizeof(PokedexData); +} + +PokedexData *PokedexData_Alloc(u32 heapID) +{ + PokedexData *pokedexData = Heap_AllocFromHeap(heapID, sizeof(PokedexData)); + PokedexData_Init(pokedexData); + + return pokedexData; +} + +void PokedexData_Copy(const PokedexData *src, PokedexData *dest) +{ + MI_CpuCopy8(src, dest, sizeof(PokedexData)); +} + +static inline void CheckPokedexIntegrity(const PokedexData *pokedexData) +{ + GF_ASSERT(pokedexData->magic == MAGIC_NUMBER); +} + +static BOOL SpeciesInvalid(u16 species) +{ + if (species == SPECIES_NONE || species > NATIONAL_DEX_COUNT) { + GF_ASSERT(FALSE); + return TRUE; + } else { + return FALSE; + } +} + +static inline BOOL ReadBit_2Forms(const u8 *array, u16 bitIndex) +{ + bitIndex--; + return 0 != (array[bitIndex >> 0x3] & (1 << (bitIndex & 0x7))); +} + +static inline void ActivateBit_2Forms(u8 *array, u16 bitIndex) +{ + bitIndex--; + array[bitIndex >> 0x3] |= 1 << (bitIndex & 0x7); +} + +static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex) +{ + GF_ASSERT(value < 2); + + bitIndex--; + + array[bitIndex >> 0x3] &= ~(1 << (bitIndex & 0x7)); + array[bitIndex >> 0x3] |= value << (bitIndex & 0x7); +} + +static inline u32 ReadBit_3Forms(const u8 *array, u16 bitIndex) +{ + return (array[bitIndex >> 2] >> ((bitIndex & 0x3) * 2)) & 0x3; +} + +static inline void SetBit_3Forms(u8 *array, u8 value, u16 bitIndex) +{ + GF_ASSERT(value < 4); + + array[bitIndex >> 2] &= ~(0x3 << ((bitIndex & 0x3) * 2)); + array[bitIndex >> 2] |= value << ((bitIndex & 0x3) * 2); +} + +static inline void Write_SeenSpecies(PokedexData *pokedexData, u16 species) +{ + ActivateBit_2Forms((u8 *)pokedexData->seenPokemon, species); +} + +static inline void Write_CaughtSpecies(PokedexData *pokedexData, u16 species) +{ + ActivateBit_2Forms((u8 *)pokedexData->caughtPokemon, species); +} + +static void SetBit_Gender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bitIndex) +{ + if (isSeen == FALSE) { + SetBit_2Forms((u8 *)pokedexData->recordedGenders[1], gender, bitIndex); + } + + SetBit_2Forms((u8 *)pokedexData->recordedGenders[isSeen], gender, bitIndex); +} + +static void UpdateGender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bitIndex) +{ + GF_ASSERT(gender <= 2); + + if (gender == GENDER_NONE) { + gender = GENDER_MALE; + } + + SetBit_Gender(pokedexData, gender, isSeen, bitIndex); +} + +static inline BOOL SpeciesSeen(const PokedexData *pokedexData, u16 species) +{ + return ReadBit_2Forms((const u8 *)pokedexData->seenPokemon, species); +} + +static inline BOOL SpeciesCaught(const PokedexData *pokedexData, u16 species) +{ + return ReadBit_2Forms((const u8 *)pokedexData->caughtPokemon, species); +} + +static inline u8 GetGender(const PokedexData *pokedexData, u16 species, u8 bitIndex) +{ + return ReadBit_2Forms((const u8 *)pokedexData->recordedGenders[bitIndex], species); +} + +static inline void SetForm_Spinda(PokedexData *pokedexData, u16 species, u32 personality) +{ + if (species == SPECIES_SPINDA) { + pokedexData->spindaForms = personality; + } +} + +static int NumFormsSeen_Unown(const PokedexData *pokedexData) +{ + int formIndex; + + for (formIndex = 0; formIndex < UNOWN_COUNT; formIndex++) { + if (pokedexData->unownForms[formIndex] == TERMINAL_U8) { + break; + } + } + + return formIndex; +} + +static BOOL UnownFormSeen(const PokedexData *pokedexData, u8 form) +{ + for (int formIndex = 0; formIndex < UNOWN_COUNT; formIndex++) { + if (pokedexData->unownForms[formIndex] == form) { + return TRUE; + } + } + + return FALSE; +} + +static void SetUnownForm(PokedexData *pokedexData, int form) +{ + if (UnownFormSeen(pokedexData, form)) { + return; + } + + int numUnownSeen = NumFormsSeen_Unown(pokedexData); + + if (numUnownSeen < UNOWN_COUNT) { + pokedexData->unownForms[numUnownSeen] = form; + } +} + +static int NumFormsSeen_TwoForms(const PokedexData *pokedexData, u32 species) +{ + GF_ASSERT((species == SPECIES_SHELLOS) || (species == SPECIES_GASTRODON) || (species == SPECIES_SHAYMIN) || (species == SPECIES_GIRATINA)); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return 0; + } + + const u8 *formArray; + switch (species) { + case SPECIES_SHELLOS: + formArray = &pokedexData->shellosForms; + break; + case SPECIES_GASTRODON: + formArray = &pokedexData->gastrodonForms; + break; + case SPECIES_SHAYMIN: + formArray = &pokedexData->shayminForms; + break; + case SPECIES_GIRATINA: + formArray = &pokedexData->giratinaForms; + break; + } + + u32 form_1 = ReadBit_2Forms(formArray, 1); + u32 form_2 = ReadBit_2Forms(formArray, 2); + + if (form_1 == form_2) { + return 1; + } + + return 2; +} + +static BOOL FormSeen_TwoForms(const PokedexData *pokedexData, u32 species, u8 form) +{ + GF_ASSERT((species == SPECIES_SHELLOS) || (species == SPECIES_GASTRODON) || (species == SPECIES_SHAYMIN) || (species == SPECIES_GIRATINA)); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return FALSE; + } + + const u8 *formArray; + switch (species) { + case SPECIES_SHELLOS: + formArray = &pokedexData->shellosForms; + break; + case SPECIES_GASTRODON: + formArray = &pokedexData->gastrodonForms; + break; + case SPECIES_SHAYMIN: + formArray = &pokedexData->shayminForms; + break; + case SPECIES_GIRATINA: + formArray = &pokedexData->giratinaForms; + break; + } + + u32 numFormsSeen = NumFormsSeen_TwoForms(pokedexData, species); + + for (u32 formIndex = 0; formIndex < numFormsSeen; formIndex++) { + u32 currentForm = ReadBit_2Forms(formArray, formIndex + 1); + + if (currentForm == form) { + return TRUE; + } + } + + return FALSE; +} + +static void UpdateForms_TwoForms(PokedexData *pokedexData, u32 species, int form) +{ + GF_ASSERT((species == SPECIES_SHELLOS) || (species == SPECIES_GASTRODON) || (species == SPECIES_SHAYMIN) || (species == SPECIES_GIRATINA)); + + if (FormSeen_TwoForms(pokedexData, species, form)) { + return; + } + + u8 *formArray; + switch (species) { + case SPECIES_SHELLOS: + formArray = &pokedexData->shellosForms; + break; + case SPECIES_GASTRODON: + formArray = &pokedexData->gastrodonForms; + break; + case SPECIES_SHAYMIN: + formArray = &pokedexData->shayminForms; + break; + case SPECIES_GIRATINA: + formArray = &pokedexData->giratinaForms; + break; + } + + int numFormsSeen = NumFormsSeen_TwoForms(pokedexData, species); + + if (numFormsSeen < 2) { + SetBit_2Forms(formArray, form, numFormsSeen + 1); + + if (numFormsSeen == 0) { + SetBit_2Forms(formArray, form, numFormsSeen + 2); + } + } +} + +static int NumFormsSeen_ThreeForms(const PokedexData *pokedexData, u32 species) +{ + GF_ASSERT((species == SPECIES_BURMY) || (species == SPECIES_WORMADAM)); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return 0; + } + + const u8 *formArray; + if (species == SPECIES_BURMY) { + formArray = &pokedexData->burmyForms; + } else { + formArray = &pokedexData->wormadamForms; + } + + int formIndex; + for (formIndex = 0; formIndex < 3; formIndex++) { + u32 currentForm = ReadBit_3Forms(formArray, formIndex); + + if (currentForm == 3) { + break; + } + } + + return formIndex; +} + +static BOOL FormSeen_ThreeForms(const PokedexData *pokedexData, u32 species, u8 form) +{ + GF_ASSERT((species == SPECIES_BURMY) || (species == SPECIES_WORMADAM)); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return FALSE; + } + + const u8 *formArray; + if (species == SPECIES_BURMY) { + formArray = &pokedexData->burmyForms; + } else { + formArray = &pokedexData->wormadamForms; + } + + for (int formIndex = 0; formIndex < 3; formIndex++) { + u32 currentForm = ReadBit_3Forms(formArray, formIndex); + + if (currentForm == form) { + return TRUE; + } + } + + return FALSE; +} + +static void UpdateForms_ThreeForms(PokedexData *pokedexData, u32 species, int form) +{ + GF_ASSERT((species == SPECIES_BURMY) || (species == SPECIES_WORMADAM)); + + if (FormSeen_ThreeForms(pokedexData, species, form)) { + return; + } + + u8 *formArray; + if (species == SPECIES_BURMY) { + formArray = &pokedexData->burmyForms; + } else { + formArray = &pokedexData->wormadamForms; + } + + int numFormsSeen = NumFormsSeen_ThreeForms(pokedexData, species); + + if (numFormsSeen < 3) { + SetBit_3Forms(formArray, form, numFormsSeen); + } +} + +static void WriteBit_Deoxys(u32 *array, u8 value, u8 bitIndex) +{ + u32 bitOffset = (24 + (bitIndex * 4)); + u32 emptyBits = ~(0xf << bitOffset); + + array[DEX_SIZE_U32 - 1] &= emptyBits; + array[DEX_SIZE_U32 - 1] |= (value << bitOffset); +} + +static void UpdateFormArray_Deoxys(PokedexData *pokedexData, u8 form, u8 bitIndex) +{ + // Deoxys forms are currently stored in spare bits in these arrays + // This will want to be changed when modding to avoid overlapping references + + GF_ASSERT(bitIndex < DEOXYS_COUNT); + GF_ASSERT(form <= TERMINAL_BYTE); + + if (bitIndex < 2) { + WriteBit_Deoxys(pokedexData->caughtPokemon, form, bitIndex); + } else { + WriteBit_Deoxys(pokedexData->seenPokemon, form, bitIndex - 2); + } +} + +static inline u32 ReadBit_Deoxys(const u32 *array, u8 bitIndex) +{ + u32 bitOffset = (24 + (bitIndex * 4)); + u32 form = (array[DEX_SIZE_U32 - 1] >> bitOffset) & 0xf; + + return form; +} + +static u32 GetForm_Deoxys(const PokedexData *pokedexData, u8 formIndex) +{ + // Deoxys forms are currently stored in spare bits in these arrays + // This will want to be changed when modding to avoid overlapping references + + u32 form; + if (formIndex < 2) { + form = ReadBit_Deoxys(pokedexData->caughtPokemon, formIndex); + } else { + form = ReadBit_Deoxys(pokedexData->seenPokemon, formIndex - 2); + } + + return form; +} + +static u32 NumFormsSeen_Deoxys(const PokedexData *pokedexData) +{ + int formIndex; + + for (formIndex = 0; formIndex < DEOXYS_COUNT; formIndex++) { + if (GetForm_Deoxys(pokedexData, formIndex) == TERMINAL_BYTE) { + break; + } + } + + return formIndex; +} + +static BOOL FormSeen_Deoxys(const PokedexData *pokedexData, u32 form) +{ + for (int formIndex = 0; formIndex < DEOXYS_COUNT; formIndex++) { + if (GetForm_Deoxys(pokedexData, formIndex) == form) { + return TRUE; + } + } + + return FALSE; +} + +static void UpdateForms_Deoxys(PokedexData *pokedexData, u16 species, Pokemon *pokemon) +{ + u8 form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + + if (species == SPECIES_DEOXYS) { + if (FormSeen_Deoxys(pokedexData, form) == FALSE) { + u32 newIndex = NumFormsSeen_Deoxys(pokedexData); + UpdateFormArray_Deoxys(pokedexData, form, newIndex); + } + } +} + +static void InitDeoxys(PokedexData *pokedexData) +{ + for (int formIndex = 0; formIndex < DEOXYS_COUNT; formIndex++) { + UpdateFormArray_Deoxys(pokedexData, TERMINAL_BYTE, formIndex); + } +} + +static inline u32 ReadBit_Rotom(u32 formArray, u32 formIndex) +{ + return (formArray >> (formIndex * 3)) & 0x7; +} + +static inline void SetBit_Rotom(u32 *formArray, u32 formIndex, u32 form) +{ + GF_ASSERT(form < TERMINAL_4BITS); + + (*formArray) &= ~(0x7 << (formIndex * 3)); + (*formArray) |= (form << (formIndex * 3)); +} + +static int NumFormsSeen_Rotom(const PokedexData *pokedexData, u32 species) +{ + GF_ASSERT(species == SPECIES_ROTOM); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return 0; + } + + u32 form; + int formIndex; + int numFormsSeen = 0; + + for (formIndex = 0; formIndex < ROTOM_COUNT; formIndex++) { + form = ReadBit_Rotom(pokedexData->rotomForms, formIndex); + + if (form != TERMINAL_4BITS) { + numFormsSeen++; + } else { + break; + } + } + + return numFormsSeen; +} + +static BOOL FormSeen_Rotom(const PokedexData *pokedexData, u32 species, u8 form) +{ + GF_ASSERT(species == SPECIES_ROTOM); + + if (PokedexData_HasSeenSpecies(pokedexData, species) == FALSE) { + return FALSE; + } + + int formIndex; + u32 numFormsSeen = NumFormsSeen_Rotom(pokedexData, species); + + for (formIndex = 0; formIndex < numFormsSeen; formIndex++) { + u32 rotomForm = ReadBit_Rotom(pokedexData->rotomForms, formIndex); + + if (rotomForm == form) { + return TRUE; + } + } + + return FALSE; +} + +static void UpdateForms_Rotom(PokedexData *pokedexData, u32 species, int form) +{ + int numFormsSeen; + + GF_ASSERT(species == SPECIES_ROTOM); + + if (FormSeen_Rotom(pokedexData, species, form)) { + return; + } + + numFormsSeen = NumFormsSeen_Rotom(pokedexData, species); + + if (numFormsSeen < ROTOM_COUNT) { + SetBit_Rotom(&pokedexData->rotomForms, numFormsSeen, form); + } +} + +static void UpdateForm(PokedexData *pokedexData, u16 species, Pokemon *pokemon) +{ + int form; + + switch (species) { + case SPECIES_UNOWN: + form = Pokemon_GetForm(pokemon); + SetUnownForm(pokedexData, form); + break; + case SPECIES_BURMY: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_ThreeForms(pokedexData, species, form); + break; + case SPECIES_WORMADAM: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_ThreeForms(pokedexData, species, form); + break; + case SPECIES_SHELLOS: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_TwoForms(pokedexData, species, form); + break; + case SPECIES_GASTRODON: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_TwoForms(pokedexData, species, form); + break; + case SPECIES_DEOXYS: + UpdateForms_Deoxys(pokedexData, species, pokemon); + break; + case SPECIES_SHAYMIN: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_TwoForms(pokedexData, species, form); + break; + case SPECIES_GIRATINA: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_TwoForms(pokedexData, species, form); + break; + case SPECIES_ROTOM: + form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); + UpdateForms_Rotom(pokedexData, species, form); + break; + default: + break; + } +} + +static void UpdateLanguage(PokedexData *pokedexData, u16 species, u32 language) +{ + int bitIndex = species; + int languageIndex = sub_020986CC(language); + + if (languageIndex == 6) { + return; + } + + pokedexData->recordedLanguages[bitIndex] |= 1 << languageIndex; +} + +static u32 GetDisplayGender(const PokedexData *pokedexData, u16 species, int displaySecondary) +{ + u32 defaultGender, secondaryGender; + u32 displayGender; + + if (PokemonPersonalData_GetSpeciesValue(species, MON_DATA_PERSONAL_GENDER) == GENDER_RATIO_NO_GENDER) { + if (displaySecondary == FALSE) { + return GENDER_NONE; + } else { + return -1; + } + } + + defaultGender = GetGender(pokedexData, species, 0); + + if (displaySecondary == TRUE) { + secondaryGender = GetGender(pokedexData, species, 1); + + if (secondaryGender == defaultGender) { + displayGender = -1; + } else { + displayGender = secondaryGender; + } + } else { + displayGender = defaultGender; + } + + return displayGender; +} + +static inline int GetForm_Unown(const PokedexData *pokedexData, int formIndex) +{ + return pokedexData->unownForms[formIndex]; +} + +static int GetForm_TwoForms(const PokedexData *pokedexData, u32 species, int formIndex) +{ + const u8 *formArray; + + GF_ASSERT((species == SPECIES_SHELLOS) || (species == SPECIES_GASTRODON) || (species == SPECIES_SHAYMIN) || (species == SPECIES_GIRATINA)); + GF_ASSERT(formIndex < 2); + + switch (species) { + case SPECIES_SHELLOS: + formArray = &pokedexData->shellosForms; + break; + case SPECIES_GASTRODON: + formArray = &pokedexData->gastrodonForms; + break; + case SPECIES_SHAYMIN: + formArray = &pokedexData->shayminForms; + break; + case SPECIES_GIRATINA: + formArray = &pokedexData->giratinaForms; + break; + } + + return ReadBit_2Forms(formArray, formIndex + 1); +} + +static int GetForm_Rotom(const PokedexData *pokedexData, u32 species, int formIndex) +{ + GF_ASSERT(species == SPECIES_ROTOM); + GF_ASSERT(formIndex < ROTOM_COUNT); + + return ReadBit_Rotom(pokedexData->rotomForms, formIndex); +} + +static int GetForm_3Forms(const PokedexData *pokedexData, u32 species, int formIndex) +{ + const u8 *formArray; + + GF_ASSERT((species == SPECIES_BURMY) || (species == SPECIES_WORMADAM)); + GF_ASSERT(formIndex < 3); + + if (species == SPECIES_BURMY) { + formArray = &pokedexData->burmyForms; + } else { + formArray = &pokedexData->wormadamForms; + } + + return ReadBit_3Forms(formArray, formIndex); +} + +static BOOL CountsForDexCompletion_National(u16 species) +{ + int i; + BOOL included; + static const u16 mythicals[NUM_MYTHICALS_NATIONAL] = { + SPECIES_MEW, + SPECIES_LUGIA, + SPECIES_HO_OH, + SPECIES_CELEBI, + SPECIES_JIRACHI, + SPECIES_DEOXYS, + SPECIES_PHIONE, + SPECIES_MANAPHY, + SPECIES_DARKRAI, + SPECIES_SHAYMIN, + SPECIES_ARCEUS + }; + + included = TRUE; + + for (i = 0; i < NUM_MYTHICALS_NATIONAL; i++) { + if (mythicals[i] == species) { + included = FALSE; + } + } + + return included; +} + +static BOOL CountsForDexCompletion_Local(u16 species) +{ + return TRUE; +} + +void PokedexData_Init(PokedexData *pokedexData) +{ + memset(pokedexData, 0, sizeof(PokedexData)); + + pokedexData->magic = MAGIC_NUMBER; + pokedexData->nationalDexObtained = FALSE; + + memset(pokedexData->unownForms, TERMINAL_U8, sizeof(u8) * UNOWN_COUNT); + + pokedexData->shellosForms = TERMINAL_U8; + pokedexData->gastrodonForms = TERMINAL_U8; + pokedexData->burmyForms = TERMINAL_U8; + pokedexData->wormadamForms = TERMINAL_U8; + pokedexData->rotomForms = TERMINAL_U32; + pokedexData->shayminForms = TERMINAL_U8; + pokedexData->giratinaForms = TERMINAL_U8; + + InitDeoxys(pokedexData); +} + +u16 PokedexData_CountCaught_National(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + + int species; + int caughtCount = 0; + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasCaughtSpecies(pokedexData, species) == TRUE) { + caughtCount++; + } + } + + return caughtCount; +} + +u16 PokedexData_CountSeen_National(const PokedexData *pokedex) +{ + CheckPokedexIntegrity(pokedex); + + int species; + int seenCount = 0; + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasSeenSpecies(pokedex, species) == TRUE) { + seenCount++; + } + } + + return seenCount; +} + +u16 PokedexData_CountSeen(const PokedexData *pokedex) +{ + if (PokedexData_IsNationalDexObtained(pokedex)) { + return PokedexData_CountSeen_National(pokedex); + } + + return PokedexData_CountSeen_Local(pokedex); +} + +u16 PokedexData_CountCaught_Local(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + + int species; + int caughtCount = 0; + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasCaughtSpecies(pokedexData, species) == TRUE) { + if (Pokemon_SinnohDexNumber(species) != 0) { + caughtCount++; + } + } + } + + return caughtCount; +} + +u16 PokedexData_CountSeen_Local(const PokedexData *pokedex) +{ + CheckPokedexIntegrity(pokedex); + + int species; + int seenCount = 0; + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasSeenSpecies(pokedex, species) == TRUE && Pokemon_SinnohDexNumber(species) != 0) { + seenCount++; + } + } + + return seenCount; +} + +BOOL PokedexData_NationalDexCompleted(const PokedexData *pokedexData) +{ + u16 numCaught = PokedexData_NumCaught_National(pokedexData); + + if (numCaught >= NATIONAL_DEX_GOAL) { + return TRUE; + } + + return FALSE; +} + +BOOL PokedexData_LocalDexCompleted(const PokedexData *pokedexData) +{ + u16 numCaught = PokedexData_NumCaught_Local(pokedexData); + + if (numCaught >= LOCAL_DEX_COUNT) { + return TRUE; + } + + return FALSE; +} + +u16 PokedexData_NumCaught_National(const PokedexData *pokedexData) +{ + int species; + u16 numCaught = 0; + + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasCaughtSpecies(pokedexData, species) == TRUE) { + if (CountsForDexCompletion_National(species) == TRUE) { + numCaught++; + } + } + } + + return numCaught; +} + +u16 PokedexData_NumCaught_Local(const PokedexData *pokedexData) +{ + int species; + u16 numCaught = 0; + + for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { + if (PokedexData_HasSeenSpecies(pokedexData, species) == TRUE) { + u32 localDexNum = Pokemon_SinnohDexNumber(species); + + if (localDexNum != 0) { + if (CountsForDexCompletion_Local(species) == TRUE) { + numCaught++; + } + } + } + } + + return numCaught; +} + +BOOL PokedexData_HasCaughtSpecies(const PokedexData *pokedex, u16 species) +{ + CheckPokedexIntegrity(pokedex); + + if (SpeciesInvalid(species)) { + return FALSE; + } + + if (SpeciesCaught(pokedex, species) && SpeciesSeen(pokedex, species)) { + return TRUE; + } else { + return FALSE; + } +} + +BOOL PokedexData_HasSeenSpecies(const PokedexData *pokedex, u16 species) +{ + CheckPokedexIntegrity(pokedex); + + if (SpeciesInvalid(species)) { + return FALSE; + } + + return SpeciesSeen(pokedex, species); +} + +u32 PokedexData_GetForm_Spinda(const PokedexData *pokedexData, u8 formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + u32 form; + switch (formIndex) { + case 0: + form = pokedexData->spindaForms; + break; + default: + GF_ASSERT(FALSE); + break; + } + + return form; +} + +u32 PokedexData_DisplayedGender(const PokedexData *pokedexData, u16 species, int displaySecondary) +{ + CheckPokedexIntegrity(pokedexData); + + if (SpeciesInvalid(species)) { + return -1; + } + + if (!SpeciesSeen(pokedexData, species)) { + return -1; + } + + return GetDisplayGender(pokedexData, species, displaySecondary); +} + +u32 PokedexData_GetForm_Unown(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + if (NumFormsSeen_Unown(pokedexData) <= formIndex) { + return -1; + } + + return GetForm_Unown(pokedexData, formIndex); +} + +u32 PokedexData_NumFormsSeen_Unown(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_Unown(pokedexData); +} + +u32 PokedexData_GetForm_Shellos(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + if (NumFormsSeen_TwoForms(pokedexData, SPECIES_SHELLOS) <= formIndex) { + return -1; + } + + return GetForm_TwoForms(pokedexData, SPECIES_SHELLOS, formIndex); +} + +u32 PokedexData_NumFormsSeen_Shellos(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_TwoForms(pokedexData, SPECIES_SHELLOS); +} + +u32 PokedexData_GetForm_Gastrodon(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + if (NumFormsSeen_TwoForms(pokedexData, SPECIES_GASTRODON) <= formIndex) { + return -1; + } + + return GetForm_TwoForms(pokedexData, SPECIES_GASTRODON, formIndex); +} + +u32 PokedexData_NumFormsSeen_Gastrodon(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_TwoForms(pokedexData, SPECIES_GASTRODON); +} + +u32 PokedexData_GetForm_Burmy(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + if (NumFormsSeen_ThreeForms(pokedexData, SPECIES_BURMY) <= formIndex) { + return -1; + } + + return GetForm_3Forms(pokedexData, SPECIES_BURMY, formIndex); +} + +u32 PokedexData_NumFormsSeen_Burmy(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_ThreeForms(pokedexData, SPECIES_BURMY); +} + +u32 PokedexData_GetForm_Wormadam(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + if (NumFormsSeen_ThreeForms(pokedexData, SPECIES_WORMADAM) <= formIndex) { + return -1; + } + + return GetForm_3Forms(pokedexData, SPECIES_WORMADAM, formIndex); +} + +u32 PokedexData_NumFormsSeen_Wormadam(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_ThreeForms(pokedexData, SPECIES_WORMADAM); +} + +u32 PokedexData_GetForm_Deoxys(const PokedexData *pokedexData, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + return GetForm_Deoxys(pokedexData, formIndex); +} + +u32 PokedexData_NumFormsSeen_Deoxys(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return NumFormsSeen_Deoxys(pokedexData); +} + +void PokedexData_CaptureEntry(PokedexData *pokedexData, Pokemon *pokemon) +{ + u16 species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL); + u32 personality = Pokemon_GetValue(pokemon, MON_DATA_PERSONALITY, NULL); + u32 gender = Pokemon_GetGender(pokemon); + + CheckPokedexIntegrity(pokedexData); + + if (SpeciesInvalid(species)) { + return; + } + + if (!SpeciesSeen(pokedexData, species)) { + SetForm_Spinda(pokedexData, species, personality); + UpdateGender(pokedexData, gender, FALSE, species); + } else { + u32 defaultGender = GetGender(pokedexData, species, 0); + + if (defaultGender != gender) { + UpdateGender(pokedexData, gender, TRUE, species); + } + } + + UpdateForm(pokedexData, species, pokemon); + Write_SeenSpecies(pokedexData, species); +} + +void PokedexData_TradeEntry(PokedexData *pokedexData, Pokemon *pokemon) +{ + u16 species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL); + u32 language = Pokemon_GetValue(pokemon, MON_DATA_LANGUAGE, NULL); + u32 personality = Pokemon_GetValue(pokemon, MON_DATA_PERSONALITY, NULL); + u32 gender = Pokemon_GetGender(pokemon); + + CheckPokedexIntegrity(pokedexData); + + if (SpeciesInvalid(species)) { + return; + } + + if (!SpeciesSeen(pokedexData, species)) { + SetForm_Spinda(pokedexData, species, personality); + UpdateGender(pokedexData, gender, FALSE, species); + } else { + u32 displayedGender = GetGender(pokedexData, species, 0); + + if (displayedGender != gender) { + UpdateGender(pokedexData, gender, TRUE, species); + } + } + + UpdateForm(pokedexData, species, pokemon); + UpdateLanguage(pokedexData, species, language); + + Write_CaughtSpecies(pokedexData, species); + Write_SeenSpecies(pokedexData, species); +} + +void PokedexData_ObtainNationalDex(PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + pokedexData->nationalDexObtained = TRUE; +} + +BOOL PokedexData_IsNationalDexObtained(const PokedexData *pokedex) +{ + CheckPokedexIntegrity(pokedex); + return pokedex->nationalDexObtained; +} + +BOOL PokedexData_CanDetectForms(const PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + return pokedexData->canDetectForms; +} + +void PokedexData_TurnOnFormDetection(PokedexData *pokedexData) +{ + CheckPokedexIntegrity(pokedexData); + pokedexData->canDetectForms = TRUE; +} + +BOOL PokedexData_IsLanguageObtained(const PokedexData *pokedexData, u16 species, u32 languageIndex) +{ + int bitIndex; + + GF_ASSERT(languageIndex < 8); + + CheckPokedexIntegrity(pokedexData); + + bitIndex = species; + languageIndex = sub_020986CC(languageIndex); + + return pokedexData->recordedLanguages[bitIndex] & (1 << languageIndex); +} + +void PokedexData_TurnOnLanguageDetection(PokedexData *pokedexData) +{ + pokedexData->canDetectLanguages = TRUE; +} + +BOOL PokedexData_CanDetectLanguages(const PokedexData *pokedexData) +{ + return pokedexData->canDetectLanguages; +} + +BOOL PokedexData_IsObtained(const PokedexData *pokedex) +{ + CheckPokedexIntegrity(pokedex); + return pokedex->pokedexObtained; +} + +void PokedexData_ObtainPokedex(PokedexData *pokedex) +{ + CheckPokedexIntegrity(pokedex); + pokedex->pokedexObtained = TRUE; +} + +PokedexData *SaveData_PokedexData(SaveData *saveData) +{ + PokedexData *pokedex = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_POKEDEX); + return pokedex; +} + +u32 PokedexData_GetDisplayForm(const PokedexData *pokedexData, int species, int formIndex) +{ + CheckPokedexIntegrity(pokedexData); + + switch (species) { + case SPECIES_UNOWN: + if (formIndex < PokedexData_NumFormsSeen_Unown(pokedexData)) { + return PokedexData_GetForm_Unown(pokedexData, formIndex); + } + break; + case SPECIES_SHELLOS: + if (formIndex < PokedexData_NumFormsSeen_Shellos(pokedexData)) { + return PokedexData_GetForm_Shellos(pokedexData, formIndex); + } + break; + case SPECIES_GASTRODON: + if (formIndex < PokedexData_NumFormsSeen_Gastrodon(pokedexData)) { + return PokedexData_GetForm_Gastrodon(pokedexData, formIndex); + } + break; + case SPECIES_BURMY: + if (formIndex < PokedexData_NumFormsSeen_Burmy(pokedexData)) { + return PokedexData_GetForm_Burmy(pokedexData, formIndex); + } + break; + case SPECIES_WORMADAM: + if (formIndex < PokedexData_NumFormsSeen_Wormadam(pokedexData)) { + return PokedexData_GetForm_Wormadam(pokedexData, formIndex); + } + break; + case SPECIES_DEOXYS: + if (formIndex < PokedexData_NumFormsSeen_Deoxys(pokedexData)) { + return PokedexData_GetForm_Deoxys(pokedexData, formIndex); + } + break; + case SPECIES_SHAYMIN: + if (formIndex < NumFormsSeen_TwoForms(pokedexData, SPECIES_SHAYMIN)) { + return GetForm_TwoForms(pokedexData, SPECIES_SHAYMIN, formIndex); + } + break; + case SPECIES_GIRATINA: + if (formIndex < NumFormsSeen_TwoForms(pokedexData, SPECIES_GIRATINA)) { + return GetForm_TwoForms(pokedexData, SPECIES_GIRATINA, formIndex); + } + break; + case SPECIES_ROTOM: + if (formIndex < NumFormsSeen_Rotom(pokedexData, SPECIES_ROTOM)) { + return GetForm_Rotom(pokedexData, SPECIES_ROTOM, formIndex); + } + break; + default: + break; + } + + return 0; +} + +u32 PokedexData_NumFormsSeen(const PokedexData *pokedex, int species) +{ + CheckPokedexIntegrity(pokedex); + + switch (species) { + case SPECIES_UNOWN: + return PokedexData_NumFormsSeen_Unown(pokedex); + case SPECIES_SHELLOS: + return PokedexData_NumFormsSeen_Shellos(pokedex); + case SPECIES_GASTRODON: + return PokedexData_NumFormsSeen_Gastrodon(pokedex); + case SPECIES_BURMY: + return PokedexData_NumFormsSeen_Burmy(pokedex); + case SPECIES_WORMADAM: + return PokedexData_NumFormsSeen_Wormadam(pokedex); + case SPECIES_DEOXYS: + return PokedexData_NumFormsSeen_Deoxys(pokedex); + case SPECIES_SHAYMIN: + return NumFormsSeen_TwoForms(pokedex, SPECIES_SHAYMIN); + case SPECIES_GIRATINA: + return NumFormsSeen_TwoForms(pokedex, SPECIES_GIRATINA); + case SPECIES_ROTOM: + return NumFormsSeen_Rotom(pokedex, SPECIES_ROTOM); + default: + break; + } + + return 1; +} diff --git a/src/savedata/save_table.c b/src/savedata/save_table.c index 654f702180..11f6a2ee4f 100644 --- a/src/savedata/save_table.c +++ b/src/savedata/save_table.c @@ -9,6 +9,7 @@ #include "journal.h" #include "party.h" #include "poffin.h" +#include "pokedex_data.h" #include "poketch_data.h" #include "record_mixed_rng.h" #include "save_player.h" @@ -18,7 +19,6 @@ #include "unk_02014D38.h" #include "unk_0202602C.h" #include "unk_020261E4.h" -#include "unk_0202631C.h" #include "unk_02027F84.h" #include "unk_02028124.h" #include "unk_0202854C.h" @@ -53,7 +53,7 @@ const SaveTableEntry gSaveTable[] = { { SAVE_TABLE_ENTRY_VARS_FLAGS, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)VarsFlags_SaveSize, (SaveEntryInitFunc)VarsFlags_Init }, { SAVE_TABLE_ENTRY_POKETCH, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)Poketch_SaveSize, (SaveEntryInitFunc)Poketch_Init }, { SAVE_TABLE_ENTRY_FIELD_PLAYER_STATE, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)FieldOverworldState_Size, (SaveEntryInitFunc)FieldOverworldState_Init }, - { SAVE_TABLE_ENTRY_POKEDEX, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)Pokedex_SaveSize, (SaveEntryInitFunc)Pokedex_Init }, + { SAVE_TABLE_ENTRY_POKEDEX, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)PokedexData_SaveSize, (SaveEntryInitFunc)PokedexData_Init }, { SAVE_TABLE_ENTRY_DAYCARE, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)Daycare_SaveSize, (SaveEntryInitFunc)Daycare_Init }, { SAVE_TABLE_ENTRY_PAL_PAD, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)PalPad_SaveSize, (SaveEntryInitFunc)PalPad_Init }, { SAVE_TABLE_ENTRY_MISC, SAVE_BLOCK_ID_NORMAL, (SaveEntrySizeFunc)MiscSaveBlock_SaveSize, (SaveEntryInitFunc)MiscSaveBlock_Init }, diff --git a/src/scrcmd.c b/src/scrcmd.c index d93254ebed..d12589ee01 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -120,6 +120,7 @@ #include "party.h" #include "player_avatar.h" #include "poffin.h" +#include "pokedex_data.h" #include "pokemon.h" #include "pokeradar.h" #include "poketch_data.h" @@ -143,7 +144,6 @@ #include "unk_0200F174.h" #include "unk_02014D38.h" #include "unk_020261E4.h" -#include "unk_0202631C.h" #include "unk_02028124.h" #include "unk_0202854C.h" #include "unk_020298BC.h" @@ -4974,37 +4974,37 @@ static BOOL ScrCmd_11D(ScriptContext *ctx) static BOOL ScrCmd_11E(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); - *v1 = Pokedex_CountSeenSinnoh(v0); + *v1 = PokedexData_CountSeen_Local(v0); return 0; } static BOOL ScrCmd_11F(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); - *v1 = sub_02026E64(v0); + *v1 = PokedexData_CountCaught_Local(v0); return 0; } static BOOL ScrCmd_120(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); - *v1 = Pokedex_CountSeenNational(v0); + *v1 = PokedexData_CountSeen_National(v0); return 0; } static BOOL ScrCmd_121(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); - *v1 = sub_02026DD0(v0); + *v1 = PokedexData_CountCaught_National(v0); return 0; } @@ -5017,17 +5017,17 @@ static BOOL ScrCmd_122(ScriptContext *ctx) static BOOL ScrCmd_123(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); const TrainerInfo *v1 = SaveData_GetTrainerInfo(ctx->fieldSystem->saveData); u8 v2 = ScriptContext_ReadByte(ctx); u16 *v3 = ScriptContext_GetVarPointer(ctx); u16 v4; if (v2 == 0) { - v4 = sub_02026F58(v0); + v4 = PokedexData_NumCaught_Local(v0); *v3 = sub_0205E078(v4, SystemFlag_HandleFirstArrivalToZone(SaveData_GetVarsFlags(ctx->fieldSystem->saveData), HANDLE_FLAG_CHECK, FIRST_ARRIVAL_ETERNA_CITY)); } else { - v4 = sub_02026F20(v0); + v4 = PokedexData_NumCaught_National(v0); *v3 = sub_0205E0E4(v4, TrainerInfo_Gender(v1)); } @@ -6237,12 +6237,12 @@ static BOOL ScrCmd_1D6(ScriptContext *ctx) static BOOL ScrCmd_1E8(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); *v1 = 0; - if (sub_02026F0C(v0) == 1) { + if (PokedexData_LocalDexCompleted(v0) == 1) { *v1 = 1; } @@ -6251,12 +6251,12 @@ static BOOL ScrCmd_1E8(ScriptContext *ctx) static BOOL ScrCmd_1E9(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); *v1 = 0; - if (sub_02026EF4(v0) == 1) { + if (PokedexData_NationalDexCompleted(v0) == 1) { *v1 = 1; } @@ -6465,16 +6465,16 @@ static BOOL ScrCmd_214(ScriptContext *ctx) static BOOL ScrCmd_218(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); u16 v2, v3, v4, v5; - v2 = Pokedex_CountSeenSinnoh(v0); + v2 = PokedexData_CountSeen_Local(v0); v3 = LCRNG_Next() % v2; *v1 = 25; for (v4 = 1, v5 = 0; v4 <= NATIONAL_DEX_COUNT; v4++) { - if (Pokedex_HasSeenSpecies(v0, v4) == TRUE && Pokemon_SinnohDexNumber(v4) != FALSE) { + if (PokedexData_HasSeenSpecies(v0, v4) == TRUE && Pokemon_SinnohDexNumber(v4) != FALSE) { if (v5 == v3) { *v1 = v4; break; @@ -6564,13 +6564,13 @@ static BOOL ScrCmd_22A(ScriptContext *ctx) static BOOL ScrCmd_22B(ScriptContext *ctx) { - sub_02027508(SaveData_Pokedex(ctx->fieldSystem->saveData)); + PokedexData_TurnOnLanguageDetection(SaveData_PokedexData(ctx->fieldSystem->saveData)); return 0; } static BOOL ScrCmd_22C(ScriptContext *ctx) { - Pokedex_TurnOnFormDetection(SaveData_Pokedex(ctx->fieldSystem->saveData)); + PokedexData_TurnOnFormDetection(SaveData_PokedexData(ctx->fieldSystem->saveData)); return 0; } @@ -6582,10 +6582,10 @@ static BOOL ScrCmd_22D(ScriptContext *ctx) *v1 = 0; if (v0 == 1) { - sub_02027454(SaveData_Pokedex(ctx->fieldSystem->saveData)); + PokedexData_ObtainNationalDex(SaveData_PokedexData(ctx->fieldSystem->saveData)); TrainerInfo_GiveNationalDex(SaveData_GetTrainerInfo(ctx->fieldSystem->saveData)); } else if (v0 == 2) { - *v1 = Pokedex_IsNationalDexObtained(SaveData_Pokedex(ctx->fieldSystem->saveData)); + *v1 = PokedexData_IsNationalDexObtained(SaveData_PokedexData(ctx->fieldSystem->saveData)); } else { GF_ASSERT(FALSE); } @@ -6767,12 +6767,12 @@ static BOOL ScrCmd_24D(ScriptContext *ctx) static void sub_020451B4(FieldSystem *fieldSystem, u16 param1) { - PokedexData *v0 = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *v0 = SaveData_PokedexData(fieldSystem->saveData); Pokemon *v1 = Pokemon_New(32); Pokemon_Init(v1); Pokemon_InitWith(v1, param1, 50, 32, FALSE, 0, OTID_NOT_SET, 0); - sub_020272A4(v0, v1); + PokedexData_CaptureEntry(v0, v1); Heap_FreeToHeap(v1); return; @@ -6886,7 +6886,7 @@ static BOOL ScrCmd_263(ScriptContext *ctx) int v3; int v4 = Party_GetCurrentCount(v1); Pokemon *v5; - PokedexData *v6 = SaveData_Pokedex(ctx->fieldSystem->saveData); + PokedexData *v6 = SaveData_PokedexData(ctx->fieldSystem->saveData); for (v2 = 0; v2 < v4; v2++) { v5 = Party_GetPokemonBySlotIndex(v1, v2); @@ -6895,7 +6895,7 @@ static BOOL ScrCmd_263(ScriptContext *ctx) if (v3 == SPECIES_DEOXYS) { Pokemon_SetValue(v5, MON_DATA_FORM, &v0); Pokemon_CalcLevelAndStats(v5); - sub_0202736C(v6, v5); + PokedexData_TradeEntry(v6, v5); } } @@ -7239,10 +7239,10 @@ static BOOL ScrCmd_282(ScriptContext *ctx) static BOOL ScrCmd_284(ScriptContext *ctx) { - const PokedexData *v0 = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *v0 = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *v1 = ScriptContext_GetVarPointer(ctx); - *v1 = sub_020270DC(v0); + *v1 = PokedexData_NumFormsSeen_Unown(v0); return 0; } @@ -8332,7 +8332,7 @@ static BOOL ScrCmd_328(ScriptContext *ctx) v5 = Party_GetPokemonBySlotIndex(v1, v3); if ((Pokemon_GetValue(v5, MON_DATA_IS_EGG, NULL) == 0) && (Pokemon_GetValue(v5, MON_DATA_SPECIES, NULL) == SPECIES_GIRATINA)) { - sub_0202736C(SaveData_Pokedex(fieldSystem->saveData), v5); + PokedexData_TradeEntry(SaveData_PokedexData(fieldSystem->saveData), v5); } } } diff --git a/src/scrcmd_system_flags.c b/src/scrcmd_system_flags.c index fe27bbfe28..60e00bcbb9 100644 --- a/src/scrcmd_system_flags.c +++ b/src/scrcmd_system_flags.c @@ -10,24 +10,24 @@ #include "field_script_context.h" #include "inlines.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "save_player.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "vars_flags.h" BOOL ScrCmd_CheckPokedexAcquired(ScriptContext *ctx) { - const PokedexData *pokedex = SaveData_Pokedex(ctx->fieldSystem->saveData); + const PokedexData *pokedex = SaveData_PokedexData(ctx->fieldSystem->saveData); u16 *destVar = ScriptContext_GetVarPointer(ctx); - *destVar = Pokedex_IsObtained(pokedex); + *destVar = PokedexData_IsObtained(pokedex); return FALSE; } BOOL ScrCmd_GivePokedex(ScriptContext *ctx) { - PokedexData *pokedex = SaveData_Pokedex(ctx->fieldSystem->saveData); - Pokedex_FlagObtained(pokedex); + PokedexData *pokedex = SaveData_PokedexData(ctx->fieldSystem->saveData); + PokedexData_ObtainPokedex(pokedex); return FALSE; } diff --git a/src/unk_0202631C.c b/src/unk_0202631C.c deleted file mode 100644 index 699193005f..0000000000 --- a/src/unk_0202631C.c +++ /dev/null @@ -1,1283 +0,0 @@ -#include "unk_0202631C.h" - -#include -#include - -#include "constants/species.h" - -#include "heap.h" -#include "inlines.h" -#include "pokemon.h" -#include "savedata.h" -#include "unk_020986CC.h" - -// These u32[16] arrays store pokedex seen/caught info as bit flags -// Therefore 32 * 16 = 512 pokedex slots. These need to be bumped up if it's pushed past this number -// ReadBit and WriteBit may need to be changed as well, to handle a larger range of bits - -#define UNOWN_COUNT 28 -#define BYTE_SLOTS 16 - -typedef struct PokedexData { - u32 magic; - u32 caughtPokemon[BYTE_SLOTS]; - u32 seenPokemon[BYTE_SLOTS]; - u32 recordedGenders[2][BYTE_SLOTS]; - u32 unk_104; - u8 unk_108; - u8 unk_109; - u8 unk_10A; - u8 unk_10B; - u8 unk_10C[UNOWN_COUNT]; - u8 recordedLanguages[MAX_SPECIES + 1]; - u8 canDetectForms; - u8 unk_319; - u8 pokedexObtained; - u8 nationalDexObtained; - u32 unk_31C; - u8 unk_320; - u8 unk_321; - u16 unk_322; -} PokedexData; - -int Pokedex_SaveSize(void) -{ - return sizeof(PokedexData); -} - -PokedexData *sub_02026324(u32 param0) -{ - PokedexData *v0; - - v0 = Heap_AllocFromHeap(param0, sizeof(PokedexData)); - Pokedex_Init(v0); - - return v0; -} - -void Pokedex_Copy(const PokedexData *src, PokedexData *dest) -{ - MI_CpuCopy8(src, dest, sizeof(PokedexData)); -} - -static inline void CheckPokedexIntegrity(const PokedexData *param0) -{ - GF_ASSERT(param0->magic == 3203386110); -} - -static BOOL IsSpeciesOutOfBounds(u16 species) -{ - if (species == SPECIES_NONE || species > NATIONAL_DEX_COUNT) { - GF_ASSERT(0); - return TRUE; - } else { - return FALSE; - } -} - -static inline BOOL ReadBit(const u8 *array, u16 bitNumber) -{ - bitNumber--; - return 0 != (array[bitNumber >> 3] & (1 << (bitNumber & 7))); -} - -static inline void WriteBit(u8 *array, u16 bitNumber) -{ - bitNumber--; - array[bitNumber >> 3] |= 1 << (bitNumber & 7); -} - -static inline void inline_02026360(u8 *param0, u8 param1, u16 param2) -{ - GF_ASSERT(param1 < 2); - - param2--; - - param0[param2 >> 3] &= ~(1 << (param2 & 7)); - param0[param2 >> 3] |= param1 << (param2 & 7); -} - -static inline u32 inline_020266F8(const u8 *param0, u16 param1) -{ - return (param0[param1 >> 2] >> ((param1 & 3) * 2)) & 0x3; -} - -static inline void inline_020267B8(u8 *param0, u8 param1, u16 param2) -{ - GF_ASSERT(param1 < 4); - - param0[param2 >> 2] &= ~(0x3 << ((param2 & 3) * 2)); - param0[param2 >> 2] |= param1 << ((param2 & 3) * 2); -} - -static inline void Write_SeenSpecies(PokedexData *param0, u16 species) -{ - WriteBit((u8 *)param0->seenPokemon, species); -} - -static inline void Write_CaughtSpecies(PokedexData *param0, u16 species) -{ - WriteBit((u8 *)param0->caughtPokemon, species); -} - -static void sub_02026360(PokedexData *param0, u8 param1, u8 param2, u16 param3) -{ - if (param2 == 0) { - inline_02026360((u8 *)param0->recordedGenders[1], param1, param3); - } - - inline_02026360((u8 *)param0->recordedGenders[param2], param1, param3); -} - -static void sub_020263D8(PokedexData *param0, u8 param1, u8 param2, u16 param3) -{ - GF_ASSERT(param1 <= 2); - - if (param1 == 2) { - param1 = 0; - } - - sub_02026360(param0, param1, param2, param3); -} - -static inline BOOL CheckSeenMask(const PokedexData *pokedex, u16 species) -{ - return ReadBit((const u8 *)pokedex->seenPokemon, species); -} - -static inline BOOL CheckCaughtMask(const PokedexData *pokedex, u16 species) -{ - return ReadBit((const u8 *)pokedex->caughtPokemon, species); -} - -static inline u8 inline_02026BAC(const PokedexData *param0, u16 param1, u8 param2) -{ - return ReadBit((const u8 *)param0->recordedGenders[param2], param1); -} - -static inline void inline_0202736C_1(PokedexData *param0, u16 param1, u32 param2) -{ - if (param1 == SPECIES_SPINDA) { - param0->unk_104 = param2; - } -} - -static int sub_02026400(const PokedexData *param0) -{ - int v0; - - for (v0 = 0; v0 < UNOWN_COUNT; v0++) { - if (param0->unk_10C[v0] == 0xff) { - break; - } - } - - return v0; -} - -static BOOL sub_02026418(const PokedexData *param0, u8 param1) -{ - int v0; - - for (v0 = 0; v0 < UNOWN_COUNT; v0++) { - if (param0->unk_10C[v0] == param1) { - return 1; - } - } - - return 0; -} - -static void sub_0202643C(PokedexData *param0, int param1) -{ - int v0; - - if (sub_02026418(param0, param1)) { - return; - } - - v0 = sub_02026400(param0); - - if (v0 < UNOWN_COUNT) { - param0->unk_10C[v0] = param1; - } -} - -static int sub_02026464(const PokedexData *param0, u32 param1) -{ - u32 v0; - u32 v1; - const u8 *v2; - - GF_ASSERT((param1 == 422) || (param1 == 423) || (param1 == 492) || (param1 == 487)); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - switch (param1) { - case 422: - v2 = ¶m0->unk_108; - break; - case 423: - v2 = ¶m0->unk_109; - break; - case 492: - v2 = ¶m0->unk_320; - break; - case 487: - v2 = ¶m0->unk_321; - break; - } - - v0 = ReadBit(v2, 1); - v1 = ReadBit(v2, 2); - - if (v0 == v1) { - return 1; - } - - return 2; -} - -static BOOL sub_02026514(const PokedexData *param0, u32 param1, u8 param2) -{ - u32 v0; - u32 v1; - u32 v2; - const u8 *v3; - - GF_ASSERT((param1 == 422) || (param1 == 423) || (param1 == 492) || (param1 == 487)); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - switch (param1) { - case 422: - v3 = ¶m0->unk_108; - break; - case 423: - v3 = ¶m0->unk_109; - break; - case 492: - v3 = ¶m0->unk_320; - break; - case 487: - v3 = ¶m0->unk_321; - break; - } - - v2 = sub_02026464(param0, param1); - - for (v1 = 0; v1 < v2; v1++) { - v0 = ReadBit(v3, v1 + 1); - - if (v0 == param2) { - return 1; - } - } - - return 0; -} - -static void sub_020265E8(PokedexData *param0, u32 param1, int param2) -{ - int v0; - u8 *v1; - - GF_ASSERT((param1 == 422) || (param1 == 423) || (param1 == 492) || (param1 == 487)); - - if (sub_02026514(param0, param1, param2)) { - return; - } - - switch (param1) { - case 422: - v1 = ¶m0->unk_108; - break; - case 423: - v1 = ¶m0->unk_109; - break; - case 492: - v1 = ¶m0->unk_320; - break; - case 487: - v1 = ¶m0->unk_321; - break; - } - - v0 = sub_02026464(param0, param1); - - if (v0 < 2) { - inline_02026360(v1, param2, v0 + 1); - - if (v0 == 0) { - inline_02026360(v1, param2, v0 + 2); - } - } -} - -static int sub_020266F8(const PokedexData *param0, u32 param1) -{ - u32 v0; - int v1; - const u8 *v2; - - GF_ASSERT((param1 == SPECIES_BURMY) || (param1 == SPECIES_WORMADAM)); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - if (param1 == SPECIES_BURMY) { - v2 = ¶m0->unk_10A; - } else { - v2 = ¶m0->unk_10B; - } - - for (v1 = 0; v1 < 3; v1++) { - v0 = inline_020266F8(v2, v1); - - if (v0 == 3) { - break; - } - } - - return v1; -} - -static BOOL sub_02026754(const PokedexData *param0, u32 param1, u8 param2) -{ - u32 v0; - int v1; - const u8 *v2; - - GF_ASSERT((param1 == 412) || (param1 == 413)); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - if (param1 == 412) { - v2 = ¶m0->unk_10A; - } else { - v2 = ¶m0->unk_10B; - } - - for (v1 = 0; v1 < 3; v1++) { - v0 = inline_020266F8(v2, v1); - - if (v0 == param2) { - return 1; - } - } - - return 0; -} - -static void sub_020267B8(PokedexData *param0, u32 param1, int param2) -{ - int v0; - u8 *v1; - - GF_ASSERT((param1 == SPECIES_BURMY) || (param1 == SPECIES_WORMADAM)); - - if (sub_02026754(param0, param1, param2)) { - return; - } - - if (param1 == SPECIES_BURMY) { - v1 = ¶m0->unk_10A; - } else { - v1 = ¶m0->unk_10B; - } - - v0 = sub_020266F8(param0, param1); - - if (v0 < 3) { - inline_020267B8(v1, param2, v0); - } -} - -static void sub_02026834(u32 *param0, u8 param1, u8 param2) -{ - u32 v0 = (24 + (param2 * 4)); - u32 v1 = ~(15 << v0); - - param0[16 - 1] &= v1; - param0[16 - 1] |= (param1 << v0); -} - -static void sub_02026850(PokedexData *param0, u8 param1, u8 param2) -{ - GF_ASSERT(param2 < 4); - GF_ASSERT(param1 <= 15); - - if (param2 < 2) { - sub_02026834(param0->caughtPokemon, param1, param2); - } else { - sub_02026834(param0->seenPokemon, param1, param2 - 2); - } -} - -static inline u32 inline_0202688C(const u32 *param0, u8 param1) -{ - u32 v0 = (24 + (param1 * 4)); - u32 v1 = (param0[16 - 1] >> v0) & 15; - - return v1; -} - -static u32 sub_0202688C(const PokedexData *param0, u8 param1) -{ - u32 v0; - - if (param1 < 2) { - v0 = inline_0202688C(param0->caughtPokemon, param1); - } else { - v0 = inline_0202688C(param0->seenPokemon, param1 - 2); - } - - return v0; -} - -static u32 sub_020268B8(const PokedexData *param0) -{ - int v0; - - for (v0 = 0; v0 < 4; v0++) { - if (sub_0202688C(param0, v0) == 15) { - break; - } - } - - return v0; -} - -static BOOL sub_020268D8(const PokedexData *param0, u32 param1) -{ - int v0; - - for (v0 = 0; v0 < 4; v0++) { - if (sub_0202688C(param0, v0) == param1) { - return 1; - } - } - - return 0; -} - -static void sub_020268FC(PokedexData *param0, u16 param1, Pokemon *param2) -{ - u8 v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - u32 v1; - - if (param1 == SPECIES_DEOXYS) { - if (sub_020268D8(param0, v0) == 0) { - v1 = sub_020268B8(param0); - sub_02026850(param0, v0, v1); - } - } -} - -static void sub_0202693C(PokedexData *param0) -{ - int v0; - - for (v0 = 0; v0 < 4; v0++) { - sub_02026850(param0, 0xf, v0); - } -} - -static inline u32 inline_02026958(u32 param0, u32 param1) -{ - return (param0 >> (param1 * 3)) & 0x7; -} - -static inline void inline_02026A00(u32 *param0, u32 param1, u32 param2) -{ - GF_ASSERT(param2 < 0x7); - - (*param0) &= ~(0x7 << (param1 * 3)); - (*param0) |= (param2 << (param1 * 3)); -} - -static int sub_02026958(const PokedexData *param0, u32 param1) -{ - u32 v0; - int v1, v2; - - GF_ASSERT(param1 == 479); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - v2 = 0; - - for (v1 = 0; v1 < 6; v1++) { - v0 = inline_02026958(param0->unk_31C, v1); - - if (v0 != 0x7) { - v2++; - } else { - break; - } - } - - return v2; -} - -static BOOL sub_020269A4(const PokedexData *param0, u32 param1, u8 param2) -{ - int v0; - u32 v1; - u32 v2; - - GF_ASSERT(param1 == 479); - - if (Pokedex_HasSeenSpecies(param0, param1) == FALSE) { - return 0; - } - - v1 = sub_02026958(param0, param1); - - for (v0 = 0; v0 < v1; v0++) { - v2 = inline_02026958(param0->unk_31C, v0); - - if (v2 == param2) { - return 1; - } - } - - return 0; -} - -static void sub_02026A00(PokedexData *param0, u32 param1, int param2) -{ - int v0; - - GF_ASSERT(param1 == 479); - - if (sub_020269A4(param0, param1, param2)) { - return; - } - - v0 = sub_02026958(param0, param1); - - if (v0 < 6) { - inline_02026A00(¶m0->unk_31C, v0, param2); - } -} - -static void sub_02026A60(PokedexData *param0, u16 param1, Pokemon *param2) -{ - int v0; - - switch (param1) { - case SPECIES_UNOWN: - v0 = Pokemon_GetForm(param2); - sub_0202643C(param0, v0); - break; - case SPECIES_BURMY: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020267B8(param0, param1, v0); - break; - case SPECIES_WORMADAM: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020267B8(param0, param1, v0); - break; - case SPECIES_SHELLOS: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020265E8(param0, param1, v0); - break; - case SPECIES_GASTRODON: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020265E8(param0, param1, v0); - break; - case SPECIES_DEOXYS: - sub_020268FC(param0, param1, param2); - break; - case SPECIES_SHAYMIN: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020265E8(param0, param1, v0); - break; - case SPECIES_GIRATINA: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_020265E8(param0, param1, v0); - break; - case SPECIES_ROTOM: - v0 = Pokemon_GetValue(param2, MON_DATA_FORM, NULL); - sub_02026A00(param0, param1, v0); - break; - default: - break; - } -} - -static void sub_02026B88(PokedexData *param0, u16 param1, u32 param2) -{ - int v0; - int v1; - - v0 = param1; - v1 = sub_020986CC(param2); - - if (v1 == 6) { - return; - } - - param0->recordedLanguages[v0] |= 1 << v1; -} - -static u32 sub_02026BAC(const PokedexData *param0, u16 param1, int param2) -{ - u32 v0, v1; - u32 v2; - - if (PokemonPersonalData_GetSpeciesValue(param1, 18) == 255) { - if (param2 == 0) { - return 2; - } else { - return -1; - } - } - - v0 = inline_02026BAC(param0, param1, 0); - - if (param2 == 1) { - v1 = inline_02026BAC(param0, param1, 1); - - if (v1 == v0) { - v2 = -1; - } else { - v2 = v1; - } - } else { - v2 = v0; - } - - return v2; -} - -static inline int inline_020270AC(const PokedexData *param0, int param1) -{ - return param0->unk_10C[param1]; -} - -static int sub_02026C24(const PokedexData *param0, u32 param1, int param2) -{ - const u8 *v0; - - GF_ASSERT((param1 == 422) || (param1 == 423) || (param1 == 492) || (param1 == 487)); - GF_ASSERT(param2 < 2); - - switch (param1) { - case 422: - v0 = ¶m0->unk_108; - break; - case 423: - v0 = ¶m0->unk_109; - break; - case 492: - v0 = ¶m0->unk_320; - break; - case 487: - v0 = ¶m0->unk_321; - break; - } - - return ReadBit(v0, param2 + 1); -} - -static int sub_02026CCC(const PokedexData *param0, u32 param1, int param2) -{ - GF_ASSERT(param1 == 479); - GF_ASSERT(param2 < 6); - - return inline_02026958(param0->unk_31C, param2); -} - -static int sub_02026CFC(const PokedexData *param0, u32 param1, int param2) -{ - const u8 *v0; - - GF_ASSERT((param1 == 412) || (param1 == 413)); - GF_ASSERT(param2 < 3); - - if (param1 == 412) { - v0 = ¶m0->unk_10A; - } else { - v0 = ¶m0->unk_10B; - } - - return inline_020266F8(v0, param2); -} - -static BOOL sub_02026D44(u16 param0) -{ - int v0; - BOOL v1; - static const u16 v2[11] = { - 0x97, - 0xF9, - 0xFA, - 0xFB, - 0x181, - 0x182, - 0x1E9, - 0x1EA, - 0x1EB, - 0x1EC, - 0x1ED - }; - - v1 = 1; - - for (v0 = 0; v0 < 11; v0++) { - if (v2[v0] == param0) { - v1 = 0; - } - } - - return v1; -} - -static BOOL sub_02026D68(u16 param0) -{ - return 1; -} - -void Pokedex_Init(PokedexData *param0) -{ - memset(param0, 0, sizeof(PokedexData)); - - param0->magic = 3203386110; - param0->nationalDexObtained = FALSE; - - memset(param0->unk_10C, 0xff, sizeof(u8) * UNOWN_COUNT); - - param0->unk_108 = 0xff; - param0->unk_109 = 0xff; - param0->unk_10A = 0xff; - param0->unk_10B = 0xff; - param0->unk_31C = 0xffffffff; - param0->unk_320 = 0xff; - param0->unk_321 = 0xff; - - sub_0202693C(param0); -} - -u16 sub_02026DD0(const PokedexData *param0) -{ - int v0; - int v1; - - CheckPokedexIntegrity(param0); - v1 = 0; - - for (v0 = 1; v0 <= NATIONAL_DEX_COUNT; v0++) { - if (Pokedex_HasCaughtSpecies(param0, v0) == 1) { - v1++; - } - } - - return v1; -} - -u16 Pokedex_CountSeenNational(const PokedexData *pokedex) -{ - int i; - CheckPokedexIntegrity(pokedex); - - int seenCount = 0; - - for (i = 1; i <= NATIONAL_DEX_COUNT; i++) { - if (Pokedex_HasSeenSpecies(pokedex, i) == TRUE) { - seenCount++; - } - } - - return seenCount; -} - -u16 Pokedex_CountSeen(const PokedexData *pokedex) -{ - if (Pokedex_IsNationalDexObtained(pokedex)) { - return Pokedex_CountSeenNational(pokedex); - } - - return Pokedex_CountSeenSinnoh(pokedex); -} - -u16 sub_02026E64(const PokedexData *param0) -{ - int v0; - int v1; - - CheckPokedexIntegrity(param0); - v1 = 0; - - for (v0 = 1; v0 <= NATIONAL_DEX_COUNT; v0++) { - if (Pokedex_HasCaughtSpecies(param0, v0) == 1) { - if (Pokemon_SinnohDexNumber(v0) != 0) { - v1++; - } - } - } - - return v1; -} - -u16 Pokedex_CountSeenSinnoh(const PokedexData *pokedex) -{ - int i; - - CheckPokedexIntegrity(pokedex); - int seenCount = 0; - - for (i = 1; i <= NATIONAL_DEX_COUNT; i++) { - if (Pokedex_HasSeenSpecies(pokedex, i) == TRUE && Pokemon_SinnohDexNumber(i) != 0) { - seenCount++; - } - } - - return seenCount; -} - -BOOL sub_02026EF4(const PokedexData *param0) -{ - u16 v0; - - v0 = sub_02026F20(param0); - - if (v0 >= 482) { - return 1; - } - - return 0; -} - -BOOL sub_02026F0C(const PokedexData *param0) -{ - u16 v0; - - v0 = sub_02026F58(param0); - - if (v0 >= LOCAL_DEX_COUNT) { - return 1; - } - - return 0; -} - -u16 sub_02026F20(const PokedexData *param0) -{ - int v0; - u16 v1; - - v1 = 0; - - for (v0 = 1; v0 <= NATIONAL_DEX_COUNT; v0++) { - if (Pokedex_HasCaughtSpecies(param0, v0) == 1) { - if (sub_02026D44(v0) == 1) { - v1++; - } - } - } - - return v1; -} - -u16 sub_02026F58(const PokedexData *param0) -{ - int v0; - u16 v1; - u32 v2; - - v1 = 0; - - for (v0 = 1; v0 <= NATIONAL_DEX_COUNT; v0++) { - if (Pokedex_HasSeenSpecies(param0, v0) == TRUE) { - v2 = Pokemon_SinnohDexNumber(v0); - - if (v2 != 0) { - if (sub_02026D68(v0) == 1) { - v1++; - } - } - } - } - - return v1; -} - -BOOL Pokedex_HasCaughtSpecies(const PokedexData *pokedex, u16 species) -{ - CheckPokedexIntegrity(pokedex); - - if (IsSpeciesOutOfBounds(species)) { - return FALSE; - } - - if (CheckCaughtMask(pokedex, species) && CheckSeenMask(pokedex, species)) { - return TRUE; - } else { - return FALSE; - } -} - -BOOL Pokedex_HasSeenSpecies(const PokedexData *pokedex, u16 species) -{ - CheckPokedexIntegrity(pokedex); - - if (IsSpeciesOutOfBounds(species)) { - return FALSE; - } - - return CheckSeenMask(pokedex, species); -} - -u32 sub_0202702C(const PokedexData *param0, u8 param1) -{ - u32 v0; - - CheckPokedexIntegrity(param0); - - switch (param1) { - case 0: - v0 = param0->unk_104; - break; - default: - GF_ASSERT(0); - break; - } - - return v0; -} - -u32 sub_02027058(const PokedexData *param0, u16 species, int param2) -{ - CheckPokedexIntegrity(param0); - - if (IsSpeciesOutOfBounds(species)) { - return -1; - } - - if (!CheckSeenMask(param0, species)) { - return -1; - } - - return sub_02026BAC(param0, species, param2); -} - -u32 sub_020270AC(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - - if (sub_02026400(param0) <= param1) { - return -1; - } - - return inline_020270AC(param0, param1); -} - -u32 sub_020270DC(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_02026400(param0); -} - -u32 sub_020270F8(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - - if (sub_02026464(param0, 422) <= param1) { - return -1; - } - - return sub_02026C24(param0, 422, param1); -} - -u32 sub_02027130(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_02026464(param0, 422); -} - -u32 sub_02027154(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - - if (sub_02026464(param0, 423) <= param1) { - return -1; - } - - return sub_02026C24(param0, 423, param1); -} - -u32 sub_0202718C(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_02026464(param0, 423); -} - -u32 sub_020271B0(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - - if (sub_020266F8(param0, 412) <= param1) { - return -1; - } - - return sub_02026CFC(param0, 412, param1); -} - -u32 sub_020271E8(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_020266F8(param0, 412); -} - -u32 sub_02027208(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - - if (sub_020266F8(param0, 413) <= param1) { - return -1; - } - - return sub_02026CFC(param0, 413, param1); -} - -u32 sub_02027240(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_020266F8(param0, 413); -} - -u32 sub_02027264(const PokedexData *param0, int param1) -{ - CheckPokedexIntegrity(param0); - return sub_0202688C(param0, param1); -} - -u32 sub_02027288(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return sub_020268B8(param0); -} - -void sub_020272A4(PokedexData *param0, Pokemon *pokemon) -{ - u16 species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL); - u32 v1 = Pokemon_GetValue(pokemon, MON_DATA_PERSONALITY, NULL); - u32 v2 = Pokemon_GetGender(pokemon); - u32 v3; - - CheckPokedexIntegrity(param0); - - if (IsSpeciesOutOfBounds(species)) { - return; - } - - if (!CheckSeenMask(param0, species)) { - inline_0202736C_1(param0, species, v1); - sub_020263D8(param0, v2, 0, species); - } else { - v3 = inline_02026BAC(param0, species, 0); - - if (v3 != v2) { - sub_020263D8(param0, v2, 1, species); - } - } - - sub_02026A60(param0, species, pokemon); - Write_SeenSpecies(param0, species); -} - -void sub_0202736C(PokedexData *param0, Pokemon *param1) -{ - u16 species = Pokemon_GetValue(param1, MON_DATA_SPECIES, NULL); - u32 v1 = Pokemon_GetValue(param1, MON_DATA_LANGUAGE, NULL); - u32 v2 = Pokemon_GetValue(param1, MON_DATA_PERSONALITY, NULL); - u32 v3 = Pokemon_GetGender(param1); - u32 v4; - - CheckPokedexIntegrity(param0); - - if (IsSpeciesOutOfBounds(species)) { - return; - } - - if (!CheckSeenMask(param0, species)) { - inline_0202736C_1(param0, species, v2); - sub_020263D8(param0, v3, 0, species); - } else { - v4 = inline_02026BAC(param0, species, 0); - - if (v4 != v3) { - sub_020263D8(param0, v3, 1, species); - } - } - - sub_02026A60(param0, species, param1); - sub_02026B88(param0, species, v1); - - Write_CaughtSpecies(param0, species); - Write_SeenSpecies(param0, species); -} - -void sub_02027454(PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - param0->nationalDexObtained = 1; -} - -BOOL Pokedex_IsNationalDexObtained(const PokedexData *pokedex) -{ - CheckPokedexIntegrity(pokedex); - return pokedex->nationalDexObtained; -} - -BOOL Pokedex_CanDetectForms(const PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - return param0->canDetectForms; -} - -void Pokedex_TurnOnFormDetection(PokedexData *param0) -{ - CheckPokedexIntegrity(param0); - param0->canDetectForms = 1; -} - -BOOL sub_020274D0(const PokedexData *param0, u16 species, u32 param2) -{ - int speciesInt; - - GF_ASSERT(param2 < 8); - - CheckPokedexIntegrity(param0); - - speciesInt = species; - param2 = sub_020986CC(param2); - - return param0->recordedLanguages[speciesInt] & (1 << param2); -} - -void sub_02027508(PokedexData *param0) -{ - param0->unk_319 = 1; -} - -BOOL sub_02027514(const PokedexData *param0) -{ - return param0->unk_319; -} - -BOOL Pokedex_IsObtained(const PokedexData *pokedex) -{ - CheckPokedexIntegrity(pokedex); - return pokedex->pokedexObtained; -} - -void Pokedex_FlagObtained(PokedexData *pokedex) -{ - CheckPokedexIntegrity(pokedex); - pokedex->pokedexObtained = TRUE; -} - -PokedexData *SaveData_Pokedex(SaveData *saveData) -{ - PokedexData *pokedex = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_POKEDEX); - return pokedex; -} - -u32 sub_0202756C(const PokedexData *param0, int species, int param2) -{ - CheckPokedexIntegrity(param0); - - switch (species) { - case SPECIES_UNOWN: - if (param2 < sub_020270DC(param0)) { - return sub_020270AC(param0, param2); - } - break; - case SPECIES_SHELLOS: - if (param2 < sub_02027130(param0)) { - return sub_020270F8(param0, param2); - } - break; - case SPECIES_GASTRODON: - if (param2 < sub_0202718C(param0)) { - return sub_02027154(param0, param2); - } - break; - case SPECIES_BURMY: - if (param2 < sub_020271E8(param0)) { - return sub_020271B0(param0, param2); - } - break; - case SPECIES_WORMADAM: - if (param2 < sub_02027240(param0)) { - return sub_02027208(param0, param2); - } - break; - case SPECIES_DEOXYS: - if (param2 < sub_02027288(param0)) { - return sub_02027264(param0, param2); - } - break; - case SPECIES_SHAYMIN: - if (param2 < sub_02026464(param0, SPECIES_SHAYMIN)) { - return sub_02026C24(param0, SPECIES_SHAYMIN, param2); - } - break; - case SPECIES_GIRATINA: - if (param2 < sub_02026464(param0, SPECIES_GIRATINA)) { - return sub_02026C24(param0, SPECIES_GIRATINA, param2); - } - break; - case SPECIES_ROTOM: - if (param2 < sub_02026958(param0, SPECIES_ROTOM)) { - return sub_02026CCC(param0, SPECIES_ROTOM, param2); - } - break; - default: - break; - } - - return 0; -} - -u32 sub_020276C8(const PokedexData *pokedex, int species) -{ - CheckPokedexIntegrity(pokedex); - - switch (species) { - case SPECIES_UNOWN: - return sub_020270DC(pokedex); - case SPECIES_SHELLOS: - return sub_02027130(pokedex); - case SPECIES_GASTRODON: - return sub_0202718C(pokedex); - case SPECIES_BURMY: - return sub_020271E8(pokedex); - case SPECIES_WORMADAM: - return sub_02027240(pokedex); - case SPECIES_DEOXYS: - return sub_02027288(pokedex); - case SPECIES_SHAYMIN: - return sub_02026464(pokedex, 492); - case SPECIES_GIRATINA: - return sub_02026464(pokedex, 487); - case SPECIES_ROTOM: - return sub_02026958(pokedex, 479); - default: - break; - } - - return 1; -} diff --git a/src/unk_0202F180.c b/src/unk_0202F180.c index 2990a4e922..4a55103720 100644 --- a/src/unk_0202F180.c +++ b/src/unk_0202F180.c @@ -6,18 +6,18 @@ #include "struct_decls/pokedexdata_decl.h" #include "game_records.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "savedata.h" -#include "unk_0202631C.h" void sub_0202F180(SaveData *param0, const Pokemon *param1) { if (Pokemon_GetValue((Pokemon *)param1, MON_DATA_IS_EGG, NULL) == 0) { - PokedexData *v0 = SaveData_Pokedex(param0); + PokedexData *v0 = SaveData_PokedexData(param0); GameRecords_IncrementTrainerScoreOnCatch(SaveData_GetGameRecordsPtr(param0), v0, Pokemon_GetValue((Pokemon *)param1, MON_DATA_SPECIES, NULL)); - sub_0202736C(v0, (Pokemon *)param1); + PokedexData_TradeEntry(v0, (Pokemon *)param1); PoketchData_PokemonHistoryEnqueue(SaveData_PoketchData(param0), (const BoxPokemon *)param1); } } diff --git a/src/unk_0202F1D4.c b/src/unk_0202F1D4.c index 2083d72766..2e98d26029 100644 --- a/src/unk_0202F1D4.c +++ b/src/unk_0202F1D4.c @@ -24,6 +24,7 @@ #include "heap.h" #include "math.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "save_player.h" #include "savedata.h" @@ -31,7 +32,6 @@ #include "unk_02006224.h" #include "unk_02017728.h" #include "unk_02026150.h" -#include "unk_0202631C.h" BattleRecording *Unk_021C07A4 = NULL; @@ -561,7 +561,7 @@ void sub_0202FAFC(FieldBattleDTO *param0, SaveData *param1) param0->resultMask = BATTLE_IN_PROGRESS; param0->leveledUpMonsMask = 0; - Pokedex_Copy(SaveData_Pokedex(param1), param0->pokedex); + PokedexData_Copy(SaveData_PokedexData(param1), param0->pokedex); for (v0 = 0; v0 < 4; v0++) { param0->trainerIDs[v0] = v1->unk_00.unk_08[v0]; diff --git a/src/unk_0203D1B8.c b/src/unk_0203D1B8.c index 1be53c4f2f..6fe5d6b3b1 100644 --- a/src/unk_0203D1B8.c +++ b/src/unk_0203D1B8.c @@ -99,6 +99,7 @@ #include "overlay_manager.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "record_mixed_rng.h" @@ -111,7 +112,6 @@ #include "system_flags.h" #include "trainer_info.h" #include "unk_02017498.h" -#include "unk_0202631C.h" #include "unk_02028124.h" #include "unk_020298BC.h" #include "unk_0202ACE0.h" @@ -979,7 +979,7 @@ static void sub_0203DB38(UnkStruct_ov88_0223C370 *param0, FieldSystem *fieldSyst param0->unk_0C = SaveData_SaveTable(fieldSystem->saveData, 9); param0->unk_14 = sub_0202C878(fieldSystem->saveData); param0->unk_18 = SaveData_Options(fieldSystem->saveData); - param0->unk_24 = SaveData_Pokedex(fieldSystem->saveData); + param0->unk_24 = SaveData_PokedexData(fieldSystem->saveData); param0->unk_30 = sub_0207A274(fieldSystem->saveData); param0->unk_10 = fieldSystem->saveData; param0->unk_1C = fieldSystem->journalEntry; @@ -1075,7 +1075,7 @@ BOOL sub_0203DBF0(FieldTask *param0) if ((v4 = sub_02076B94(NULL, v2->unk_04.unk_40, 1, v3, &v5)) != 0) { Heap_Create(3, 26, 0x30000); - v2->unk_60 = sub_0207AE68(NULL, v2->unk_04.unk_40, v4, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_Pokedex(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v5, 0x4, 26); + v2->unk_60 = sub_0207AE68(NULL, v2->unk_04.unk_40, v4, SaveData_Options(fieldSystem->saveData), PokemonSummaryScreen_ShowContestData(fieldSystem->saveData), SaveData_PokedexData(fieldSystem->saveData), SaveData_GetBag(fieldSystem->saveData), SaveData_GetGameRecordsPtr(fieldSystem->saveData), SaveData_PoketchData(fieldSystem->saveData), v5, 0x4, 26); v2->unk_00 = 6; } else { v2->unk_00 = 7; @@ -1366,7 +1366,7 @@ void sub_0203E0FC(FieldSystem *fieldSystem, int param1) v0->unk_04 = SaveData_GetSystemData(fieldSystem->saveData); v0->unk_08 = SaveData_SaveTable(fieldSystem->saveData, 2); v0->unk_0C = SaveData_PCBoxes(fieldSystem->saveData); - v0->unk_10 = SaveData_Pokedex(fieldSystem->saveData); + v0->unk_10 = SaveData_PokedexData(fieldSystem->saveData); v0->unk_14 = sub_0202B370(fieldSystem->saveData); v0->unk_18 = sub_0202C878(fieldSystem->saveData); v0->unk_1C = SaveData_GetTrainerInfo(fieldSystem->saveData); diff --git a/src/unk_02046C7C.c b/src/unk_02046C7C.c index a38f1179a5..0eac6b747c 100644 --- a/src/unk_02046C7C.c +++ b/src/unk_02046C7C.c @@ -12,6 +12,7 @@ #include "inlines.h" #include "map_header.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "save_player.h" #include "script_manager.h" @@ -19,7 +20,6 @@ #include "string_template.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_020298BC.h" #include "unk_0202CC64.h" #include "unk_020933F8.h" @@ -107,7 +107,7 @@ BOOL ScrCmd_0FA(ScriptContext *param0) v8.unk_01 = v4; v8.unk_02 = v6; v8.unk_03 = SystemFlag_CheckGameCompleted(SaveData_GetVarsFlags(param0->fieldSystem->saveData)); - v8.unk_04 = Pokedex_IsNationalDexObtained(SaveData_Pokedex(param0->fieldSystem->saveData)); + v8.unk_04 = PokedexData_IsNationalDexObtained(SaveData_PokedexData(param0->fieldSystem->saveData)); v8.unk_05 = v7; v8.unk_08 = v1; v8.unk_0C = v0; diff --git a/src/unk_0204AEE8.c b/src/unk_0204AEE8.c index a92dd87db8..ee424c1ca1 100644 --- a/src/unk_0204AEE8.c +++ b/src/unk_0204AEE8.c @@ -21,13 +21,13 @@ #include "message.h" #include "narc.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "save_player.h" #include "savedata.h" #include "strbuf.h" #include "string_template.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_0202D05C.h" #include "unk_02049D08.h" @@ -112,7 +112,7 @@ StringTemplate *sub_0204AEE8(SaveData *param0, u16 param1, u16 param2, u8 param3 v2 = Strbuf_Init(12 + 2, 4); v3 = Strbuf_Init(2, 4); - v4 = SaveData_Pokedex(param0); + v4 = SaveData_PokedexData(param0); v6 = MessageLoader_Init(1, 26, 412, 4); v5 = StringTemplate_New(18 + 1, 12 + 2, 4); @@ -121,7 +121,7 @@ StringTemplate *sub_0204AEE8(SaveData *param0, u16 param1, u16 param2, u8 param3 for (v0 = 0; v0 < 18; v0++) { v1 = sub_02078824(v0); - if (Pokedex_HasSeenSpecies(v4, v1)) { + if (PokedexData_HasSeenSpecies(v4, v1)) { MessageLoader_GetStrbuf(v6, v1, v2); StringTemplate_SetStrbuf(v5, (*param4) + 1, v2, param2, param3, GAME_LANGUAGE); (*param4)++; diff --git a/src/unk_0204C500.c b/src/unk_0204C500.c index 751c348b9b..68d807f2f9 100644 --- a/src/unk_0204C500.c +++ b/src/unk_0204C500.c @@ -12,11 +12,11 @@ #include "field_script_context.h" #include "heap.h" #include "inlines.h" +#include "pokedex_data.h" #include "pokemon.h" #include "save_player.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_0202EEC0.h" #include "unk_0202F180.h" #include "unk_020562F8.h" @@ -64,7 +64,7 @@ BOOL ScrCmd_255(ScriptContext *param0) PCBoxes *v1 = SaveData_PCBoxes(param0->fieldSystem->saveData); Pokemon *v2 = Pokemon_New(32); TrainerInfo *v3 = SaveData_GetTrainerInfo(param0->fieldSystem->saveData); - PokedexData *v4 = SaveData_Pokedex(param0->fieldSystem->saveData); + PokedexData *v4 = SaveData_PokedexData(param0->fieldSystem->saveData); BOOL v5; int v6; diff --git a/src/unk_02052C6C.c b/src/unk_02052C6C.c index cc3824b04c..336ff5bb7e 100644 --- a/src/unk_02052C6C.c +++ b/src/unk_02052C6C.c @@ -25,6 +25,7 @@ #include "message.h" #include "message_util.h" #include "party.h" +#include "pokedex_data.h" #include "render_window.h" #include "rtc.h" #include "save_player.h" @@ -35,7 +36,6 @@ #include "trainer_info.h" #include "unk_02005474.h" #include "unk_0200F174.h" -#include "unk_0202631C.h" #include "unk_0202DF8C.h" #include "unk_0203D1B8.h" #include "unk_02054884.h" @@ -192,7 +192,7 @@ void sub_02052E58(FieldTask *param0) v5->unk_04.playTime = SaveData_GetPlayTime(fieldSystem->saveData); v5->unk_10.unk_00 = TrainerInfo_Gender(SaveData_GetTrainerInfo(fieldSystem->saveData)); v5->unk_10.unk_04 = SystemFlag_CheckGameCompleted(v3); - v5->unk_10.unk_08 = SaveData_Pokedex(fieldSystem->saveData); + v5->unk_10.unk_08 = SaveData_PokedexData(fieldSystem->saveData); if (SystemFlag_CheckGameCompleted(v3) == 0) { sub_02055C2C(fieldSystem); diff --git a/src/unk_020683F4.c b/src/unk_020683F4.c index 29b68334d0..e0a751791b 100644 --- a/src/unk_020683F4.c +++ b/src/unk_020683F4.c @@ -42,6 +42,7 @@ #include "map_tile_behavior.h" #include "party.h" #include "player_avatar.h" +#include "pokedex_data.h" #include "pokeradar.h" #include "render_window.h" #include "save_player.h" @@ -49,7 +50,6 @@ #include "strbuf.h" #include "system_flags.h" #include "unk_0200F174.h" -#include "unk_0202631C.h" #include "unk_02028124.h" #include "unk_0203C954.h" #include "unk_0203D1B8.h" @@ -1065,7 +1065,7 @@ static u32 sub_02069130(const UnkStruct_020684D0 *param0) return -1; } - if (Pokedex_IsNationalDexObtained(SaveData_Pokedex(param0->fieldSystem->saveData)) == FALSE) { + if (PokedexData_IsNationalDexObtained(SaveData_PokedexData(param0->fieldSystem->saveData)) == FALSE) { return -1; } diff --git a/src/unk_0206CCB0.c b/src/unk_0206CCB0.c index 05b75c4d37..912f597773 100644 --- a/src/unk_0206CCB0.c +++ b/src/unk_0206CCB0.c @@ -42,6 +42,7 @@ #include "math.h" #include "message.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "record_mixed_rng.h" #include "ribbon.h" @@ -53,7 +54,6 @@ #include "string_template.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_020298BC.h" #include "unk_0202D7A8.h" #include "unk_0202E2CC.h" @@ -770,10 +770,10 @@ static int sub_0206D2E0(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206D320(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { - PokedexData *v0 = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *v0 = SaveData_PokedexData(fieldSystem->saveData); UnkStruct_0206D140 *v1 = ov6_02246498(param1); - return Pokedex_HasSeenSpecies(v0, v1->unk_06); + return PokedexData_HasSeenSpecies(v0, v1->unk_06); } void sub_0206D340(FieldSystem *fieldSystem, BOOL param1, u16 param2, Pokemon *param3) @@ -814,7 +814,7 @@ static BOOL sub_0206D3C0(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param return 1; } - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } static void sub_0206D3E4(FieldSystem *fieldSystem, int param1) @@ -935,7 +935,7 @@ static int sub_0206D5B0(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206D5F0(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { UnkStruct_0206D5B0 *v0 = (UnkStruct_0206D5B0 *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } void sub_0206D60C(FieldSystem *fieldSystem, Pokemon *param1) @@ -961,10 +961,10 @@ static int sub_0206D644(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206D6A8(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { - PokedexData *v0 = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *v0 = SaveData_PokedexData(fieldSystem->saveData); UnkStruct_0206D644 *v1 = (UnkStruct_0206D644 *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(v0, v1->unk_00); + return PokedexData_HasSeenSpecies(v0, v1->unk_00); } void sub_0206D6C8(FieldSystem *fieldSystem, int param1, int param2) @@ -1022,10 +1022,10 @@ static int sub_0206D75C(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206D7A4(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { - PokedexData *v0 = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *v0 = SaveData_PokedexData(fieldSystem->saveData); UnkStruct_0206D75C *v1 = (UnkStruct_0206D75C *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(v0, v1->unk_00); + return PokedexData_HasSeenSpecies(v0, v1->unk_00); } void sub_0206D7C4(FieldSystem *fieldSystem) @@ -1092,7 +1092,7 @@ static BOOL sub_0206D8F0(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param { UnkStruct_0206D8B0 *v0 = (UnkStruct_0206D8B0 *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } void sub_0206D90C(TVBroadcast *fieldSystem, Pokemon *param1, u16 param2) @@ -1171,7 +1171,7 @@ static BOOL sub_0206DA50(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param { UnkStruct_0206D9F4 *v0 = (UnkStruct_0206D9F4 *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } static void sub_0206DA6C(UnkStruct_0206DA6C *param0, const TrainerInfo *param1) @@ -1304,7 +1304,7 @@ static BOOL sub_0206DC3C(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param { UnkStruct_0206DBE8 *v0 = (UnkStruct_0206DBE8 *)ov6_02246498(param1); - if (Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_02) == 0) { + if (PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_02) == 0) { return 0; } @@ -1341,7 +1341,7 @@ static int sub_0206DC9C(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206DD1C(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { UnkStruct_0206DC9C *v0 = (UnkStruct_0206DC9C *)ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } void sub_0206DD38(FieldSystem *fieldSystem, u32 param1, u32 param2, u32 param3) @@ -1682,7 +1682,7 @@ static BOOL sub_0206E248(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param { UnkStruct_0206E1C0 *v0 = ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } void sub_0206E264(FieldSystem *fieldSystem, u16 param1) @@ -1742,7 +1742,7 @@ static int sub_0206E300(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206E37C(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { UnkStruct_0206E300 *v0 = ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00.unk_02); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00.unk_02); } void sub_0206E398(FieldSystem *fieldSystem, u16 param1) @@ -1776,7 +1776,7 @@ static int sub_0206E3C8(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206E3F8(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { UnkStruct_0206E3C8 *v0 = ov6_02246498(param1); - return Pokedex_HasSeenSpecies(SaveData_Pokedex(fieldSystem->saveData), v0->unk_00); + return PokedexData_HasSeenSpecies(SaveData_PokedexData(fieldSystem->saveData), v0->unk_00); } void sub_0206E414(FieldSystem *fieldSystem, u16 param1) @@ -2754,12 +2754,12 @@ static int sub_0206F01C(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr { Strbuf *v0; u16 v1, v2, v3; - const PokedexData *v4 = SaveData_Pokedex(fieldSystem->saveData); + const PokedexData *v4 = SaveData_PokedexData(fieldSystem->saveData); v1 = (LCRNG_Next() % (NATIONAL_DEX_COUNT - 1)) + 1; for (v2 = 1; v2 <= NATIONAL_DEX_COUNT; v2++) { - if (Pokedex_HasSeenSpecies(v4, v1) == TRUE) { + if (PokedexData_HasSeenSpecies(v4, v1) == TRUE) { v3 = v1; break; } @@ -2803,9 +2803,9 @@ static Strbuf *sub_0206F0D8(u16 param0, u32 param1) static BOOL sub_0206F100(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { - const PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + const PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); - if (Pokedex_IsObtained(pokedex) == TRUE) { + if (PokedexData_IsObtained(pokedex) == TRUE) { return TRUE; } else { return FALSE; @@ -2849,7 +2849,7 @@ static int sub_0206F160(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr Pokemon *v3; Party *v4; TrainerInfo *v5 = SaveData_GetTrainerInfo(fieldSystem->saveData); - PokedexData *v6 = SaveData_Pokedex(fieldSystem->saveData); + PokedexData *v6 = SaveData_PokedexData(fieldSystem->saveData); v4 = Party_GetFromSavedata(fieldSystem->saveData); v3 = Party_GetPokemonBySlotIndex(v4, sub_0205E1B4(fieldSystem->saveData)); @@ -2860,7 +2860,7 @@ static int sub_0206F160(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr v1 = (LCRNG_Next() % (NATIONAL_DEX_COUNT - 2) + 1); for (v2 = 1; v2 <= NATIONAL_DEX_COUNT; v2++) { - if (Pokedex_HasSeenSpecies(v6, v1) == TRUE) { + if (PokedexData_HasSeenSpecies(v6, v1) == TRUE) { v0 = sub_0206F0D8(v1, 4); StringTemplate_SetStrbuf(param1, 2, v0, 0, 1, GAME_LANGUAGE); Strbuf_Free(v0); @@ -2881,9 +2881,9 @@ static int sub_0206F160(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr static BOOL sub_0206F260(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param1) { - const PokedexData *pokedex = SaveData_Pokedex(fieldSystem->saveData); + const PokedexData *pokedex = SaveData_PokedexData(fieldSystem->saveData); - if (Pokedex_IsObtained(pokedex) == TRUE) { + if (PokedexData_IsObtained(pokedex) == TRUE) { return TRUE; } else { return FALSE; diff --git a/src/unk_02071D40.c b/src/unk_02071D40.c index 2c9960c265..4789f8f062 100644 --- a/src/unk_02071D40.c +++ b/src/unk_02071D40.c @@ -19,11 +19,11 @@ #include "game_records.h" #include "heap.h" #include "play_time.h" +#include "pokedex_data.h" #include "save_player.h" #include "savedata.h" #include "system_flags.h" #include "trainer_info.h" -#include "unk_0202631C.h" #include "unk_0202854C.h" #include "unk_0202C7FC.h" #include "unk_0203061C.h" @@ -63,7 +63,7 @@ void sub_02071D40(const u8 param0, const u8 param1, const u8 param2, const u8 pa sub_02072014(param0, GAME_VERSION, v3, param2, TrainerInfo_RegionCode(v0), param5); } - sub_02072038(TrainerInfo_ID_LowHalf(v0), TrainerInfo_Gender(v0), TrainerInfo_Name(v0), TrainerInfo_Money(v0), Pokedex_CountSeen(SaveData_Pokedex(fieldSystem->saveData)), Pokedex_IsObtained(SaveData_Pokedex(fieldSystem->saveData)), GameRecords_GetTrainerScore(v1), param5); + sub_02072038(TrainerInfo_ID_LowHalf(v0), TrainerInfo_Gender(v0), TrainerInfo_Name(v0), TrainerInfo_Money(v0), PokedexData_CountSeen(SaveData_PokedexData(fieldSystem->saveData)), PokedexData_IsObtained(SaveData_PokedexData(fieldSystem->saveData)), GameRecords_GetTrainerScore(v1), param5); { RTCDate v4; @@ -140,7 +140,7 @@ u8 sub_02071F28(FieldSystem *fieldSystem) v0++; } - if (sub_02026EF4(SaveData_Pokedex(v1))) { + if (PokedexData_NationalDexCompleted(SaveData_PokedexData(v1))) { v0++; } diff --git a/src/unk_0207A274.c b/src/unk_0207A274.c index 1e5fd45de0..f1391dafa9 100644 --- a/src/unk_0207A274.c +++ b/src/unk_0207A274.c @@ -5,15 +5,15 @@ #include "struct_decls/pokedexdata_decl.h" +#include "pokedex_data.h" #include "pokemon.h" #include "savedata.h" -#include "unk_0202631C.h" u32 sub_0207A274(SaveData *param0) { PokedexData *v0; - v0 = SaveData_Pokedex(param0); + v0 = SaveData_PokedexData(param0); return sub_0207A280(v0); } @@ -21,7 +21,7 @@ u32 sub_0207A280(const PokedexData *param0) { BOOL v0; - v0 = Pokedex_IsNationalDexObtained(param0); + v0 = PokedexData_IsNationalDexObtained(param0); if (v0 == 1) { return 1; diff --git a/src/unk_0207AE68.c b/src/unk_0207AE68.c index 95fa2d8231..eea3f1613e 100644 --- a/src/unk_0207AE68.c +++ b/src/unk_0207AE68.c @@ -35,6 +35,7 @@ #include "overlay_manager.h" #include "palette.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "poketch_data.h" #include "render_text.h" @@ -53,7 +54,6 @@ #include "unk_0201DBEC.h" #include "unk_0202419C.h" #include "unk_02024220.h" -#include "unk_0202631C.h" #include "unk_02028124.h" #include "unk_020393C8.h" #include "unk_0207C63C.h" @@ -409,7 +409,7 @@ static void sub_0207B180(UnkStruct_0207AE68 *param0) case 12: if (Text_IsPrinterActive(param0->unk_65) == 0) { if (--param0->unk_66 == 0) { - sub_0202736C(param0->unk_48, param0->unk_28); + PokedexData_TradeEntry(param0->unk_48, param0->unk_28); GameRecords_IncrementRecordValue(param0->records, RECORD_UNK_012); GameRecords_IncrementTrainerScore(param0->records, TRAINER_SCORE_EVENT_CAUGHT_SPECIES); PoketchData_PokemonHistoryEnqueue(param0->poketchData, Pokemon_GetBoxPokemon(param0->unk_28)); @@ -739,7 +739,7 @@ static void sub_0207C028(UnkStruct_0207AE68 *param0) Pokemon_CalcLevelAndStats(v1); Party_AddPokemon(param0->unk_24, v1); - sub_0202736C(param0->unk_48, v1); + PokedexData_TradeEntry(param0->unk_48, v1); GameRecords_IncrementRecordValue(param0->records, RECORD_UNK_012); GameRecords_IncrementTrainerScore(param0->records, TRAINER_SCORE_EVENT_CAUGHT_SPECIES); PoketchData_PokemonHistoryEnqueue(param0->poketchData, Pokemon_GetBoxPokemon(v1)); diff --git a/src/unk_020933F8.c b/src/unk_020933F8.c index f0d1a85ccd..7920adc45b 100644 --- a/src/unk_020933F8.c +++ b/src/unk_020933F8.c @@ -37,6 +37,7 @@ #include "journal.h" #include "math.h" #include "party.h" +#include "pokedex_data.h" #include "pokemon.h" #include "ribbon.h" #include "rtc.h" @@ -49,7 +50,6 @@ #include "trainer_info.h" #include "unk_02005474.h" #include "unk_0200A9DC.h" -#include "unk_0202631C.h" #include "unk_020298BC.h" #include "unk_0202CC64.h" #include "unk_0202F108.h" @@ -1643,10 +1643,10 @@ void sub_02094C44(UnkStruct_02095C48 *param0, SaveData *param1, u32 param2, Jour int v6; PokedexData *v7; - v7 = SaveData_Pokedex(param0->unk_1970); + v7 = SaveData_PokedexData(param0->unk_1970); for (v6 = param0->unk_00.unk_117; v6 < 4; v6++) { - sub_020272A4(v7, param0->unk_00.unk_00[v6]); + PokedexData_CaptureEntry(v7, param0->unk_00.unk_00[v6]); } } } else { diff --git a/src/unk_0209747C.c b/src/unk_0209747C.c index 0b4d0df9db..864875cc21 100644 --- a/src/unk_0209747C.c +++ b/src/unk_0209747C.c @@ -10,12 +10,12 @@ #include "game_options.h" #include "heap.h" +#include "pokedex_data.h" #include "save_player.h" #include "savedata.h" #include "system_flags.h" #include "unk_02014A84.h" #include "unk_02014D38.h" -#include "unk_0202631C.h" #include "vars_flags.h" struct UnkStruct_0209747C_t { @@ -39,7 +39,7 @@ UnkStruct_0209747C *sub_0209747C(u32 param0, u32 param1, SaveData *param2, u32 p v0->unk_00 = param0; v0->unk_01 = param1; - v0->unk_0C = SaveData_Pokedex(param2); + v0->unk_0C = SaveData_PokedexData(param2); v0->unk_10 = sub_02014EC4(param2); v0->unk_04 = SystemFlag_CheckGameCompleted(SaveData_GetVarsFlags(param2)); v0->unk_05 = 0; diff --git a/src/unk_020998EC.c b/src/unk_020998EC.c index e3f0a36bf0..552ef43238 100644 --- a/src/unk_020998EC.c +++ b/src/unk_020998EC.c @@ -11,9 +11,9 @@ #include "heap.h" #include "inlines.h" +#include "pokedex_data.h" #include "strbuf.h" #include "unk_02014D38.h" -#include "unk_0202631C.h" #include "unk_0209747C.h" static const u16 Unk_020F8420[] = { @@ -3236,7 +3236,7 @@ static u32 sub_02099980(UnkStruct_020998EC *param0, const u16 *param1, u32 param v0 = sub_0209755C(param0->unk_00); for (v1 = 0; v1 < param2; v1++) { - if (Pokedex_HasSeenSpecies(v0, param1[v1])) { + if (PokedexData_HasSeenSpecies(v0, param1[v1])) { inline_02099980(param0, param1[v1]); *param3++ = param1[v1]; v2++; From 5236914493e7654d946f02ed0175cdb0405e7b66 Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:18:21 -0500 Subject: [PATCH 2/7] beefcafe --- src/pokedex_data.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pokedex_data.c b/src/pokedex_data.c index cdab39a15b..3cda0824d1 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -12,7 +12,7 @@ #include "unk_020986CC.h" #define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 -#define MAGIC_NUMBER 3203386110 +#define MAGIC_NUMBER 0xbeefcafe #define NUM_MYTHICALS_NATIONAL 11 #define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_MYTHICALS_NATIONAL) #define UNOWN_COUNT 28 @@ -694,7 +694,7 @@ static BOOL CountsForDexCompletion_National(u16 species) { int i; BOOL included; - static const u16 mythicals[NUM_MYTHICALS_NATIONAL] = { + static const u16 excludedMons[NUM_MYTHICALS_NATIONAL] = { SPECIES_MEW, SPECIES_LUGIA, SPECIES_HO_OH, @@ -711,7 +711,7 @@ static BOOL CountsForDexCompletion_National(u16 species) included = TRUE; for (i = 0; i < NUM_MYTHICALS_NATIONAL; i++) { - if (mythicals[i] == species) { + if (excludedMons[i] == species) { included = FALSE; } } @@ -860,12 +860,9 @@ u16 PokedexData_NumCaught_Local(const PokedexData *pokedexData) for (species = 1; species <= NATIONAL_DEX_COUNT; species++) { if (PokedexData_HasSeenSpecies(pokedexData, species) == TRUE) { - u32 localDexNum = Pokemon_SinnohDexNumber(species); - - if (localDexNum != 0) { - if (CountsForDexCompletion_Local(species) == TRUE) { - numCaught++; - } + if (Pokemon_SinnohDexNumber(species) != 0 + && CountsForDexCompletion_Local(species) == TRUE) { + numCaught++; } } } From 2daced4882cc90ae990adda7d34ef8fce4849a34 Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:39:12 -0500 Subject: [PATCH 3/7] Clarified Names Within PokedexData Forms -> FormsSeen for pokemon with multiple forms --- include/pokedex_data.h | 4 +- src/battle/ov16_0223DF00.c | 6 +- src/overlay005/ov5_021F6454.c | 2 +- src/overlay118/ov118_021D0D80.c | 2 +- src/pokedex_data.c | 110 ++++++++++++++++---------------- src/scrcmd.c | 6 +- src/unk_0202F180.c | 2 +- src/unk_0207AE68.c | 4 +- src/unk_020933F8.c | 2 +- 9 files changed, 68 insertions(+), 70 deletions(-) diff --git a/include/pokedex_data.h b/include/pokedex_data.h index 08a81c28fc..beedad7084 100644 --- a/include/pokedex_data.h +++ b/include/pokedex_data.h @@ -35,8 +35,8 @@ u32 PokedexData_GetForm_Wormadam(const PokedexData *pokedexData, int formIndex); u32 PokedexData_NumFormsSeen_Wormadam(const PokedexData *pokedexData); u32 PokedexData_GetForm_Deoxys(const PokedexData *pokedexData, int formIndex); u32 PokedexData_NumFormsSeen_Deoxys(const PokedexData *pokedexData); -void PokedexData_CaptureEntry(PokedexData *pokedexData, Pokemon *pokemon); -void PokedexData_TradeEntry(PokedexData *pokedexData, Pokemon *pokemon); +void PokedexData_Encounter(PokedexData *pokedexData, Pokemon *pokemon); +void PokedexData_Capture(PokedexData *pokedexData, Pokemon *pokemon); void PokedexData_ObtainNationalDex(PokedexData *pokedexData); BOOL PokedexData_IsNationalDexObtained(const PokedexData *pokedexData); BOOL PokedexData_CanDetectForms(const PokedexData *pokedexData); diff --git a/src/battle/ov16_0223DF00.c b/src/battle/ov16_0223DF00.c index 5e8832a640..3ee0bad8fd 100644 --- a/src/battle/ov16_0223DF00.c +++ b/src/battle/ov16_0223DF00.c @@ -1690,12 +1690,12 @@ void BattleSystem_DexFlagSeen(BattleSystem *param0, int param1) if ((param0->battleType & (0x4 | 0x80)) == 0) { if ((v0 & 0x1) || (param0->battleType == (0x2 | 0x8 | 0x40)) || (param0->battleType == ((0x2 | 0x1) | 0x8 | 0x40))) { - PokedexData_CaptureEntry(param0->pokedex, v1); + PokedexData_Encounter(param0->pokedex, v1); } } if (((v0 & 0x1) == 0) && (Pokemon_GetValue(v1, MON_DATA_SPECIES_EGG, NULL) == 412)) { - PokedexData_TradeEntry(param0->pokedex, v1); + PokedexData_Capture(param0->pokedex, v1); } } @@ -1714,7 +1714,7 @@ void ov16_0223F9A0(BattleSystem *param0, int param1) v2 = BattleContext_Get(param0, param0->battleCtx, 2, param1); v1 = BattleSystem_PartyPokemon(param0, param1, v2); - PokedexData_TradeEntry(param0->pokedex, v1); + PokedexData_Capture(param0->pokedex, v1); } } } diff --git a/src/overlay005/ov5_021F6454.c b/src/overlay005/ov5_021F6454.c index 82330e9194..41d70f257e 100644 --- a/src/overlay005/ov5_021F6454.c +++ b/src/overlay005/ov5_021F6454.c @@ -676,7 +676,7 @@ BOOL ScrCmd_304(ScriptContext *param0) v4 = Party_GetPokemonBySlotIndex(v5, v7); Pokemon_SetRotomForm(v4, v10, v8); - PokedexData_TradeEntry(SaveData_PokedexData(fieldSystem->saveData), v4); + PokedexData_Capture(SaveData_PokedexData(fieldSystem->saveData), v4); return 0; } diff --git a/src/overlay118/ov118_021D0D80.c b/src/overlay118/ov118_021D0D80.c index ba8507c22d..d4f73e26cd 100644 --- a/src/overlay118/ov118_021D0D80.c +++ b/src/overlay118/ov118_021D0D80.c @@ -93,7 +93,7 @@ int ov118_021D0DBC(GameWindowLayout *param0) break; } - PokedexData_TradeEntry(SaveData_PokedexData(FieldSystem_GetSaveData(param0->unk_5A4->unk_1C)), v1); + PokedexData_Capture(SaveData_PokedexData(FieldSystem_GetSaveData(param0->unk_5A4->unk_1C)), v1); } v0->unk_00++; break; diff --git a/src/pokedex_data.c b/src/pokedex_data.c index 3cda0824d1..c6c2446d52 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -28,20 +28,20 @@ typedef struct PokedexData { u32 caughtPokemon[DEX_SIZE_U32]; u32 seenPokemon[DEX_SIZE_U32]; u32 recordedGenders[2][DEX_SIZE_U32]; - u32 spindaForms; - u8 shellosForms; - u8 gastrodonForms; - u8 burmyForms; - u8 wormadamForms; - u8 unownForms[UNOWN_COUNT]; + u32 spindaForm; + u8 shellosFormsSeen; + u8 gastrodonFormsSeen; + u8 burmyFormsSeen; + u8 wormadamFormsSeen; + u8 unownFormsSeen[UNOWN_COUNT]; u8 recordedLanguages[MAX_SPECIES + 1]; u8 canDetectForms; u8 canDetectLanguages; u8 pokedexObtained; u8 nationalDexObtained; - u32 rotomForms; - u8 shayminForms; - u8 giratinaForms; + u32 rotomFormsSeen; + u8 shayminFormsSeen; + u8 giratinaFormsSeen; } PokedexData; int PokedexData_SaveSize(void) @@ -160,7 +160,7 @@ static inline u8 GetGender(const PokedexData *pokedexData, u16 species, u8 bitIn static inline void SetForm_Spinda(PokedexData *pokedexData, u16 species, u32 personality) { if (species == SPECIES_SPINDA) { - pokedexData->spindaForms = personality; + pokedexData->spindaForm = personality; } } @@ -169,7 +169,7 @@ static int NumFormsSeen_Unown(const PokedexData *pokedexData) int formIndex; for (formIndex = 0; formIndex < UNOWN_COUNT; formIndex++) { - if (pokedexData->unownForms[formIndex] == TERMINAL_U8) { + if (pokedexData->unownFormsSeen[formIndex] == TERMINAL_U8) { break; } } @@ -180,7 +180,7 @@ static int NumFormsSeen_Unown(const PokedexData *pokedexData) static BOOL UnownFormSeen(const PokedexData *pokedexData, u8 form) { for (int formIndex = 0; formIndex < UNOWN_COUNT; formIndex++) { - if (pokedexData->unownForms[formIndex] == form) { + if (pokedexData->unownFormsSeen[formIndex] == form) { return TRUE; } } @@ -197,7 +197,7 @@ static void SetUnownForm(PokedexData *pokedexData, int form) int numUnownSeen = NumFormsSeen_Unown(pokedexData); if (numUnownSeen < UNOWN_COUNT) { - pokedexData->unownForms[numUnownSeen] = form; + pokedexData->unownFormsSeen[numUnownSeen] = form; } } @@ -212,16 +212,16 @@ static int NumFormsSeen_TwoForms(const PokedexData *pokedexData, u32 species) const u8 *formArray; switch (species) { case SPECIES_SHELLOS: - formArray = &pokedexData->shellosForms; + formArray = &pokedexData->shellosFormsSeen; break; case SPECIES_GASTRODON: - formArray = &pokedexData->gastrodonForms; + formArray = &pokedexData->gastrodonFormsSeen; break; case SPECIES_SHAYMIN: - formArray = &pokedexData->shayminForms; + formArray = &pokedexData->shayminFormsSeen; break; case SPECIES_GIRATINA: - formArray = &pokedexData->giratinaForms; + formArray = &pokedexData->giratinaFormsSeen; break; } @@ -246,16 +246,16 @@ static BOOL FormSeen_TwoForms(const PokedexData *pokedexData, u32 species, u8 fo const u8 *formArray; switch (species) { case SPECIES_SHELLOS: - formArray = &pokedexData->shellosForms; + formArray = &pokedexData->shellosFormsSeen; break; case SPECIES_GASTRODON: - formArray = &pokedexData->gastrodonForms; + formArray = &pokedexData->gastrodonFormsSeen; break; case SPECIES_SHAYMIN: - formArray = &pokedexData->shayminForms; + formArray = &pokedexData->shayminFormsSeen; break; case SPECIES_GIRATINA: - formArray = &pokedexData->giratinaForms; + formArray = &pokedexData->giratinaFormsSeen; break; } @@ -283,16 +283,16 @@ static void UpdateForms_TwoForms(PokedexData *pokedexData, u32 species, int form u8 *formArray; switch (species) { case SPECIES_SHELLOS: - formArray = &pokedexData->shellosForms; + formArray = &pokedexData->shellosFormsSeen; break; case SPECIES_GASTRODON: - formArray = &pokedexData->gastrodonForms; + formArray = &pokedexData->gastrodonFormsSeen; break; case SPECIES_SHAYMIN: - formArray = &pokedexData->shayminForms; + formArray = &pokedexData->shayminFormsSeen; break; case SPECIES_GIRATINA: - formArray = &pokedexData->giratinaForms; + formArray = &pokedexData->giratinaFormsSeen; break; } @@ -317,9 +317,9 @@ static int NumFormsSeen_ThreeForms(const PokedexData *pokedexData, u32 species) const u8 *formArray; if (species == SPECIES_BURMY) { - formArray = &pokedexData->burmyForms; + formArray = &pokedexData->burmyFormsSeen; } else { - formArray = &pokedexData->wormadamForms; + formArray = &pokedexData->wormadamFormsSeen; } int formIndex; @@ -344,9 +344,9 @@ static BOOL FormSeen_ThreeForms(const PokedexData *pokedexData, u32 species, u8 const u8 *formArray; if (species == SPECIES_BURMY) { - formArray = &pokedexData->burmyForms; + formArray = &pokedexData->burmyFormsSeen; } else { - formArray = &pokedexData->wormadamForms; + formArray = &pokedexData->wormadamFormsSeen; } for (int formIndex = 0; formIndex < 3; formIndex++) { @@ -370,9 +370,9 @@ static void UpdateForms_ThreeForms(PokedexData *pokedexData, u32 species, int fo u8 *formArray; if (species == SPECIES_BURMY) { - formArray = &pokedexData->burmyForms; + formArray = &pokedexData->burmyFormsSeen; } else { - formArray = &pokedexData->wormadamForms; + formArray = &pokedexData->wormadamFormsSeen; } int numFormsSeen = NumFormsSeen_ThreeForms(pokedexData, species); @@ -409,9 +409,7 @@ static void UpdateFormArray_Deoxys(PokedexData *pokedexData, u8 form, u8 bitInde static inline u32 ReadBit_Deoxys(const u32 *array, u8 bitIndex) { u32 bitOffset = (24 + (bitIndex * 4)); - u32 form = (array[DEX_SIZE_U32 - 1] >> bitOffset) & 0xf; - - return form; + return (array[DEX_SIZE_U32 - 1] >> bitOffset) & 0xf; } static u32 GetForm_Deoxys(const PokedexData *pokedexData, u8 formIndex) @@ -498,7 +496,7 @@ static int NumFormsSeen_Rotom(const PokedexData *pokedexData, u32 species) int numFormsSeen = 0; for (formIndex = 0; formIndex < ROTOM_COUNT; formIndex++) { - form = ReadBit_Rotom(pokedexData->rotomForms, formIndex); + form = ReadBit_Rotom(pokedexData->rotomFormsSeen, formIndex); if (form != TERMINAL_4BITS) { numFormsSeen++; @@ -522,7 +520,7 @@ static BOOL FormSeen_Rotom(const PokedexData *pokedexData, u32 species, u8 form) u32 numFormsSeen = NumFormsSeen_Rotom(pokedexData, species); for (formIndex = 0; formIndex < numFormsSeen; formIndex++) { - u32 rotomForm = ReadBit_Rotom(pokedexData->rotomForms, formIndex); + u32 rotomForm = ReadBit_Rotom(pokedexData->rotomFormsSeen, formIndex); if (rotomForm == form) { return TRUE; @@ -545,7 +543,7 @@ static void UpdateForms_Rotom(PokedexData *pokedexData, u32 species, int form) numFormsSeen = NumFormsSeen_Rotom(pokedexData, species); if (numFormsSeen < ROTOM_COUNT) { - SetBit_Rotom(&pokedexData->rotomForms, numFormsSeen, form); + SetBit_Rotom(&pokedexData->rotomFormsSeen, numFormsSeen, form); } } @@ -638,7 +636,7 @@ static u32 GetDisplayGender(const PokedexData *pokedexData, u16 species, int dis static inline int GetForm_Unown(const PokedexData *pokedexData, int formIndex) { - return pokedexData->unownForms[formIndex]; + return pokedexData->unownFormsSeen[formIndex]; } static int GetForm_TwoForms(const PokedexData *pokedexData, u32 species, int formIndex) @@ -650,16 +648,16 @@ static int GetForm_TwoForms(const PokedexData *pokedexData, u32 species, int for switch (species) { case SPECIES_SHELLOS: - formArray = &pokedexData->shellosForms; + formArray = &pokedexData->shellosFormsSeen; break; case SPECIES_GASTRODON: - formArray = &pokedexData->gastrodonForms; + formArray = &pokedexData->gastrodonFormsSeen; break; case SPECIES_SHAYMIN: - formArray = &pokedexData->shayminForms; + formArray = &pokedexData->shayminFormsSeen; break; case SPECIES_GIRATINA: - formArray = &pokedexData->giratinaForms; + formArray = &pokedexData->giratinaFormsSeen; break; } @@ -671,7 +669,7 @@ static int GetForm_Rotom(const PokedexData *pokedexData, u32 species, int formIn GF_ASSERT(species == SPECIES_ROTOM); GF_ASSERT(formIndex < ROTOM_COUNT); - return ReadBit_Rotom(pokedexData->rotomForms, formIndex); + return ReadBit_Rotom(pokedexData->rotomFormsSeen, formIndex); } static int GetForm_3Forms(const PokedexData *pokedexData, u32 species, int formIndex) @@ -682,9 +680,9 @@ static int GetForm_3Forms(const PokedexData *pokedexData, u32 species, int formI GF_ASSERT(formIndex < 3); if (species == SPECIES_BURMY) { - formArray = &pokedexData->burmyForms; + formArray = &pokedexData->burmyFormsSeen; } else { - formArray = &pokedexData->wormadamForms; + formArray = &pokedexData->wormadamFormsSeen; } return ReadBit_3Forms(formArray, formIndex); @@ -731,15 +729,15 @@ void PokedexData_Init(PokedexData *pokedexData) pokedexData->magic = MAGIC_NUMBER; pokedexData->nationalDexObtained = FALSE; - memset(pokedexData->unownForms, TERMINAL_U8, sizeof(u8) * UNOWN_COUNT); + memset(pokedexData->unownFormsSeen, TERMINAL_U8, sizeof(u8) * UNOWN_COUNT); - pokedexData->shellosForms = TERMINAL_U8; - pokedexData->gastrodonForms = TERMINAL_U8; - pokedexData->burmyForms = TERMINAL_U8; - pokedexData->wormadamForms = TERMINAL_U8; - pokedexData->rotomForms = TERMINAL_U32; - pokedexData->shayminForms = TERMINAL_U8; - pokedexData->giratinaForms = TERMINAL_U8; + pokedexData->shellosFormsSeen = TERMINAL_U8; + pokedexData->gastrodonFormsSeen = TERMINAL_U8; + pokedexData->burmyFormsSeen = TERMINAL_U8; + pokedexData->wormadamFormsSeen = TERMINAL_U8; + pokedexData->rotomFormsSeen = TERMINAL_U32; + pokedexData->shayminFormsSeen = TERMINAL_U8; + pokedexData->giratinaFormsSeen = TERMINAL_U8; InitDeoxys(pokedexData); } @@ -903,7 +901,7 @@ u32 PokedexData_GetForm_Spinda(const PokedexData *pokedexData, u8 formIndex) u32 form; switch (formIndex) { case 0: - form = pokedexData->spindaForms; + form = pokedexData->spindaForm; break; default: GF_ASSERT(FALSE); @@ -1025,7 +1023,7 @@ u32 PokedexData_NumFormsSeen_Deoxys(const PokedexData *pokedexData) return NumFormsSeen_Deoxys(pokedexData); } -void PokedexData_CaptureEntry(PokedexData *pokedexData, Pokemon *pokemon) +void PokedexData_Encounter(PokedexData *pokedexData, Pokemon *pokemon) { u16 species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL); u32 personality = Pokemon_GetValue(pokemon, MON_DATA_PERSONALITY, NULL); @@ -1052,7 +1050,7 @@ void PokedexData_CaptureEntry(PokedexData *pokedexData, Pokemon *pokemon) Write_SeenSpecies(pokedexData, species); } -void PokedexData_TradeEntry(PokedexData *pokedexData, Pokemon *pokemon) +void PokedexData_Capture(PokedexData *pokedexData, Pokemon *pokemon) { u16 species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL); u32 language = Pokemon_GetValue(pokemon, MON_DATA_LANGUAGE, NULL); diff --git a/src/scrcmd.c b/src/scrcmd.c index 22aee2eace..599534cd79 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -6773,7 +6773,7 @@ static void sub_020451B4(FieldSystem *fieldSystem, u16 param1) Pokemon_Init(v1); Pokemon_InitWith(v1, param1, 50, 32, FALSE, 0, OTID_NOT_SET, 0); - PokedexData_CaptureEntry(v0, v1); + PokedexData_Encounter(v0, v1); Heap_FreeToHeap(v1); return; @@ -6896,7 +6896,7 @@ static BOOL ScrCmd_263(ScriptContext *ctx) if (v3 == SPECIES_DEOXYS) { Pokemon_SetValue(v5, MON_DATA_FORM, &v0); Pokemon_CalcLevelAndStats(v5); - PokedexData_TradeEntry(v6, v5); + PokedexData_Capture(v6, v5); } } @@ -8333,7 +8333,7 @@ static BOOL ScrCmd_328(ScriptContext *ctx) v5 = Party_GetPokemonBySlotIndex(v1, v3); if ((Pokemon_GetValue(v5, MON_DATA_IS_EGG, NULL) == 0) && (Pokemon_GetValue(v5, MON_DATA_SPECIES, NULL) == SPECIES_GIRATINA)) { - PokedexData_TradeEntry(SaveData_PokedexData(fieldSystem->saveData), v5); + PokedexData_Capture(SaveData_PokedexData(fieldSystem->saveData), v5); } } } diff --git a/src/unk_0202F180.c b/src/unk_0202F180.c index 4a55103720..a7156d11d6 100644 --- a/src/unk_0202F180.c +++ b/src/unk_0202F180.c @@ -17,7 +17,7 @@ void sub_0202F180(SaveData *param0, const Pokemon *param1) PokedexData *v0 = SaveData_PokedexData(param0); GameRecords_IncrementTrainerScoreOnCatch(SaveData_GetGameRecordsPtr(param0), v0, Pokemon_GetValue((Pokemon *)param1, MON_DATA_SPECIES, NULL)); - PokedexData_TradeEntry(v0, (Pokemon *)param1); + PokedexData_Capture(v0, (Pokemon *)param1); PoketchData_PokemonHistoryEnqueue(SaveData_PoketchData(param0), (const BoxPokemon *)param1); } } diff --git a/src/unk_0207AE68.c b/src/unk_0207AE68.c index eea3f1613e..3cde97b85c 100644 --- a/src/unk_0207AE68.c +++ b/src/unk_0207AE68.c @@ -409,7 +409,7 @@ static void sub_0207B180(UnkStruct_0207AE68 *param0) case 12: if (Text_IsPrinterActive(param0->unk_65) == 0) { if (--param0->unk_66 == 0) { - PokedexData_TradeEntry(param0->unk_48, param0->unk_28); + PokedexData_Capture(param0->unk_48, param0->unk_28); GameRecords_IncrementRecordValue(param0->records, RECORD_UNK_012); GameRecords_IncrementTrainerScore(param0->records, TRAINER_SCORE_EVENT_CAUGHT_SPECIES); PoketchData_PokemonHistoryEnqueue(param0->poketchData, Pokemon_GetBoxPokemon(param0->unk_28)); @@ -739,7 +739,7 @@ static void sub_0207C028(UnkStruct_0207AE68 *param0) Pokemon_CalcLevelAndStats(v1); Party_AddPokemon(param0->unk_24, v1); - PokedexData_TradeEntry(param0->unk_48, v1); + PokedexData_Capture(param0->unk_48, v1); GameRecords_IncrementRecordValue(param0->records, RECORD_UNK_012); GameRecords_IncrementTrainerScore(param0->records, TRAINER_SCORE_EVENT_CAUGHT_SPECIES); PoketchData_PokemonHistoryEnqueue(param0->poketchData, Pokemon_GetBoxPokemon(v1)); diff --git a/src/unk_020933F8.c b/src/unk_020933F8.c index 42b9fa5092..cec44a83ff 100644 --- a/src/unk_020933F8.c +++ b/src/unk_020933F8.c @@ -1626,7 +1626,7 @@ void sub_02094C44(UnkStruct_02095C48 *param0, SaveData *param1, u32 param2, Jour PokedexData *v7 = SaveData_PokedexData(param0->unk_1970); for (i = param0->unk_00.unk_117; i < 4; i++) { - PokedexData_CaptureEntry(v7, param0->unk_00.unk_00[i]); + PokedexData_Encounter(v7, param0->unk_00.unk_00[i]); } } else { sub_0202F134(param0->unk_1970, param0->unk_00.unk_10F, param0->unk_00.unk_118[param0->unk_00.unk_113].unk_08); From 59711b30faff854a7efa18ffdc67dab651941745 Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:32:42 -0500 Subject: [PATCH 4/7] Minor Polish --- src/pokedex_data.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pokedex_data.c b/src/pokedex_data.c index c6c2446d52..5af158546f 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -80,13 +80,13 @@ static BOOL SpeciesInvalid(u16 species) static inline BOOL ReadBit_2Forms(const u8 *array, u16 bitIndex) { bitIndex--; - return 0 != (array[bitIndex >> 0x3] & (1 << (bitIndex & 0x7))); + return 0 != (array[bitIndex >> 3] & (1 << (bitIndex & 0x7))); } static inline void ActivateBit_2Forms(u8 *array, u16 bitIndex) { bitIndex--; - array[bitIndex >> 0x3] |= 1 << (bitIndex & 0x7); + array[bitIndex >> 3] |= 1 << (bitIndex & 0x7); } static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex) @@ -95,8 +95,8 @@ static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex) bitIndex--; - array[bitIndex >> 0x3] &= ~(1 << (bitIndex & 0x7)); - array[bitIndex >> 0x3] |= value << (bitIndex & 0x7); + array[bitIndex >> 3] &= ~(1 << (bitIndex & 0x7)); + array[bitIndex >> 3] |= value << (bitIndex & 0x7); } static inline u32 ReadBit_3Forms(const u8 *array, u16 bitIndex) @@ -133,7 +133,7 @@ static void SetBit_Gender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bi static void UpdateGender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bitIndex) { - GF_ASSERT(gender <= 2); + GF_ASSERT(gender <= GENDER_NONE); if (gender == GENDER_NONE) { gender = GENDER_MALE; @@ -587,8 +587,6 @@ static void UpdateForm(PokedexData *pokedexData, u16 species, Pokemon *pokemon) form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL); UpdateForms_Rotom(pokedexData, species, form); break; - default: - break; } } From 63b79e4bdee69e97c6be64d3cb708887ecb4c711 Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Sat, 4 Jan 2025 01:02:27 -0500 Subject: [PATCH 5/7] Dynamic ExcludedMons Made ExcludedMons a global variable so that NUM_EXCLUDED can be defined dynamically. Also added in dummy code for applying exclusions to the local dex. --- src/pokedex_data.c | 56 +++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/pokedex_data.c b/src/pokedex_data.c index 5af158546f..72ee377a87 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -11,10 +11,27 @@ #include "savedata.h" #include "unk_020986CC.h" +static const u16 sExcludedMons_national[] = { + SPECIES_MEW, + SPECIES_LUGIA, + SPECIES_HO_OH, + SPECIES_CELEBI, + SPECIES_JIRACHI, + SPECIES_DEOXYS, + SPECIES_PHIONE, + SPECIES_MANAPHY, + SPECIES_DARKRAI, + SPECIES_SHAYMIN, + SPECIES_ARCEUS +}; +static const u16 sExcludedMons_local[] = {}; + #define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 #define MAGIC_NUMBER 0xbeefcafe -#define NUM_MYTHICALS_NATIONAL 11 -#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_MYTHICALS_NATIONAL) +#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMons_national) / sizeof(u16))) +#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMons_local) / sizeof(u16))) +#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_EXCLUDED_NATIONAL) +#define LOCAL_DEX_GOAL (LOCAL_DEX_COUNT - NUM_EXCLUDED_LOCAL) #define UNOWN_COUNT 28 #define DEOXYS_COUNT 4 #define ROTOM_COUNT 6 @@ -689,25 +706,10 @@ static int GetForm_3Forms(const PokedexData *pokedexData, u32 species, int formI static BOOL CountsForDexCompletion_National(u16 species) { int i; - BOOL included; - static const u16 excludedMons[NUM_MYTHICALS_NATIONAL] = { - SPECIES_MEW, - SPECIES_LUGIA, - SPECIES_HO_OH, - SPECIES_CELEBI, - SPECIES_JIRACHI, - SPECIES_DEOXYS, - SPECIES_PHIONE, - SPECIES_MANAPHY, - SPECIES_DARKRAI, - SPECIES_SHAYMIN, - SPECIES_ARCEUS - }; - - included = TRUE; - - for (i = 0; i < NUM_MYTHICALS_NATIONAL; i++) { - if (excludedMons[i] == species) { + BOOL included = TRUE; + + for (i = 0; i < NUM_EXCLUDED_NATIONAL; i++) { + if (sExcludedMons_national[i] == species) { included = FALSE; } } @@ -717,7 +719,15 @@ static BOOL CountsForDexCompletion_National(u16 species) static BOOL CountsForDexCompletion_Local(u16 species) { - return TRUE; + BOOL included = TRUE; + + for (int i = 0; i < NUM_EXCLUDED_LOCAL; i++) { + if (sExcludedMons_local[i] == species) { + included = FALSE; + } + } + + return included; } void PokedexData_Init(PokedexData *pokedexData) @@ -826,7 +836,7 @@ BOOL PokedexData_LocalDexCompleted(const PokedexData *pokedexData) { u16 numCaught = PokedexData_NumCaught_Local(pokedexData); - if (numCaught >= LOCAL_DEX_COUNT) { + if (numCaught >= LOCAL_DEX_GOAL) { return TRUE; } From 4cd87e24314f26e582c25981ffac2b9a13034e5a Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Sat, 4 Jan 2025 01:18:55 -0500 Subject: [PATCH 6/7] Format Defines --- src/pokedex_data.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pokedex_data.c b/src/pokedex_data.c index 72ee377a87..57c76f0a94 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -26,19 +26,19 @@ static const u16 sExcludedMons_national[] = { }; static const u16 sExcludedMons_local[] = {}; -#define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 -#define MAGIC_NUMBER 0xbeefcafe -#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMons_national) / sizeof(u16))) -#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMons_local) / sizeof(u16))) -#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_EXCLUDED_NATIONAL) -#define LOCAL_DEX_GOAL (LOCAL_DEX_COUNT - NUM_EXCLUDED_LOCAL) -#define UNOWN_COUNT 28 -#define DEOXYS_COUNT 4 -#define ROTOM_COUNT 6 -#define TERMINAL_4BITS 0x7 -#define TERMINAL_BYTE 0xf -#define TERMINAL_U8 0xff -#define TERMINAL_U32 0xffffffff +#define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 +#define MAGIC_NUMBER 0xbeefcafe +#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMons_national) / sizeof(u16))) +#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMons_local) / sizeof(u16))) +#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_EXCLUDED_NATIONAL) +#define LOCAL_DEX_GOAL (LOCAL_DEX_COUNT - NUM_EXCLUDED_LOCAL) +#define UNOWN_COUNT 28 +#define DEOXYS_COUNT 4 +#define ROTOM_COUNT 6 +#define TERMINAL_4BITS 0x7 +#define TERMINAL_BYTE 0xf +#define TERMINAL_U8 0xff +#define TERMINAL_U32 0xffffffff typedef struct PokedexData { u32 magic; From b52baee43180e720f14c50cd19cec9d50bd6de6b Mon Sep 17 00:00:00 2001 From: h2o-DS <71458559+h2o-DS@users.noreply.github.com> Date: Sat, 4 Jan 2025 20:02:40 -0500 Subject: [PATCH 7/7] Hex Formatting Removed Unnecessary constants. Gave hex values correct capitalization and padding. sExcludedMons_national-> sExcludedMonsNational --- src/pokedex_data.c | 68 ++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/pokedex_data.c b/src/pokedex_data.c index 57c76f0a94..2cb1d1f771 100644 --- a/src/pokedex_data.c +++ b/src/pokedex_data.c @@ -11,7 +11,7 @@ #include "savedata.h" #include "unk_020986CC.h" -static const u16 sExcludedMons_national[] = { +static const u16 sExcludedMonsNational[] = { SPECIES_MEW, SPECIES_LUGIA, SPECIES_HO_OH, @@ -24,21 +24,17 @@ static const u16 sExcludedMons_national[] = { SPECIES_SHAYMIN, SPECIES_ARCEUS }; -static const u16 sExcludedMons_local[] = {}; +static const u16 sExcludedMonsLocal[] = {}; #define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16 -#define MAGIC_NUMBER 0xbeefcafe -#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMons_national) / sizeof(u16))) -#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMons_local) / sizeof(u16))) +#define MAGIC_NUMBER 0xBEEFCAFE +#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMonsNational) / sizeof(u16))) +#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMonsLocal) / sizeof(u16))) #define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_EXCLUDED_NATIONAL) #define LOCAL_DEX_GOAL (LOCAL_DEX_COUNT - NUM_EXCLUDED_LOCAL) #define UNOWN_COUNT 28 #define DEOXYS_COUNT 4 #define ROTOM_COUNT 6 -#define TERMINAL_4BITS 0x7 -#define TERMINAL_BYTE 0xf -#define TERMINAL_U8 0xff -#define TERMINAL_U32 0xffffffff typedef struct PokedexData { u32 magic; @@ -97,13 +93,13 @@ static BOOL SpeciesInvalid(u16 species) static inline BOOL ReadBit_2Forms(const u8 *array, u16 bitIndex) { bitIndex--; - return 0 != (array[bitIndex >> 3] & (1 << (bitIndex & 0x7))); + return 0 != (array[bitIndex >> 3] & (1 << (bitIndex & 0x07))); } static inline void ActivateBit_2Forms(u8 *array, u16 bitIndex) { bitIndex--; - array[bitIndex >> 3] |= 1 << (bitIndex & 0x7); + array[bitIndex >> 3] |= 1 << (bitIndex & 0x07); } static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex) @@ -112,21 +108,21 @@ static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex) bitIndex--; - array[bitIndex >> 3] &= ~(1 << (bitIndex & 0x7)); - array[bitIndex >> 3] |= value << (bitIndex & 0x7); + array[bitIndex >> 3] &= ~(1 << (bitIndex & 0x07)); + array[bitIndex >> 3] |= value << (bitIndex & 0x07); } static inline u32 ReadBit_3Forms(const u8 *array, u16 bitIndex) { - return (array[bitIndex >> 2] >> ((bitIndex & 0x3) * 2)) & 0x3; + return (array[bitIndex >> 2] >> ((bitIndex & 0x03) * 2)) & 0x03; } static inline void SetBit_3Forms(u8 *array, u8 value, u16 bitIndex) { GF_ASSERT(value < 4); - array[bitIndex >> 2] &= ~(0x3 << ((bitIndex & 0x3) * 2)); - array[bitIndex >> 2] |= value << ((bitIndex & 0x3) * 2); + array[bitIndex >> 2] &= ~(0x03 << ((bitIndex & 0x03) * 2)); + array[bitIndex >> 2] |= value << ((bitIndex & 0x03) * 2); } static inline void Write_SeenSpecies(PokedexData *pokedexData, u16 species) @@ -186,7 +182,7 @@ static int NumFormsSeen_Unown(const PokedexData *pokedexData) int formIndex; for (formIndex = 0; formIndex < UNOWN_COUNT; formIndex++) { - if (pokedexData->unownFormsSeen[formIndex] == TERMINAL_U8) { + if (pokedexData->unownFormsSeen[formIndex] == 0xFF) { break; } } @@ -402,7 +398,7 @@ static void UpdateForms_ThreeForms(PokedexData *pokedexData, u32 species, int fo static void WriteBit_Deoxys(u32 *array, u8 value, u8 bitIndex) { u32 bitOffset = (24 + (bitIndex * 4)); - u32 emptyBits = ~(0xf << bitOffset); + u32 emptyBits = ~(0x0F << bitOffset); array[DEX_SIZE_U32 - 1] &= emptyBits; array[DEX_SIZE_U32 - 1] |= (value << bitOffset); @@ -414,7 +410,7 @@ static void UpdateFormArray_Deoxys(PokedexData *pokedexData, u8 form, u8 bitInde // This will want to be changed when modding to avoid overlapping references GF_ASSERT(bitIndex < DEOXYS_COUNT); - GF_ASSERT(form <= TERMINAL_BYTE); + GF_ASSERT(form <= 0x0F); if (bitIndex < 2) { WriteBit_Deoxys(pokedexData->caughtPokemon, form, bitIndex); @@ -426,7 +422,7 @@ static void UpdateFormArray_Deoxys(PokedexData *pokedexData, u8 form, u8 bitInde static inline u32 ReadBit_Deoxys(const u32 *array, u8 bitIndex) { u32 bitOffset = (24 + (bitIndex * 4)); - return (array[DEX_SIZE_U32 - 1] >> bitOffset) & 0xf; + return (array[DEX_SIZE_U32 - 1] >> bitOffset) & 0x0F; } static u32 GetForm_Deoxys(const PokedexData *pokedexData, u8 formIndex) @@ -449,7 +445,7 @@ static u32 NumFormsSeen_Deoxys(const PokedexData *pokedexData) int formIndex; for (formIndex = 0; formIndex < DEOXYS_COUNT; formIndex++) { - if (GetForm_Deoxys(pokedexData, formIndex) == TERMINAL_BYTE) { + if (GetForm_Deoxys(pokedexData, formIndex) == 0x0F) { break; } } @@ -483,20 +479,20 @@ static void UpdateForms_Deoxys(PokedexData *pokedexData, u16 species, Pokemon *p static void InitDeoxys(PokedexData *pokedexData) { for (int formIndex = 0; formIndex < DEOXYS_COUNT; formIndex++) { - UpdateFormArray_Deoxys(pokedexData, TERMINAL_BYTE, formIndex); + UpdateFormArray_Deoxys(pokedexData, 0x0F, formIndex); } } static inline u32 ReadBit_Rotom(u32 formArray, u32 formIndex) { - return (formArray >> (formIndex * 3)) & 0x7; + return (formArray >> (formIndex * 3)) & 0x07; } static inline void SetBit_Rotom(u32 *formArray, u32 formIndex, u32 form) { - GF_ASSERT(form < TERMINAL_4BITS); + GF_ASSERT(form < 0x07); - (*formArray) &= ~(0x7 << (formIndex * 3)); + (*formArray) &= ~(0x07 << (formIndex * 3)); (*formArray) |= (form << (formIndex * 3)); } @@ -515,7 +511,7 @@ static int NumFormsSeen_Rotom(const PokedexData *pokedexData, u32 species) for (formIndex = 0; formIndex < ROTOM_COUNT; formIndex++) { form = ReadBit_Rotom(pokedexData->rotomFormsSeen, formIndex); - if (form != TERMINAL_4BITS) { + if (form != 0x07) { numFormsSeen++; } else { break; @@ -709,7 +705,7 @@ static BOOL CountsForDexCompletion_National(u16 species) BOOL included = TRUE; for (i = 0; i < NUM_EXCLUDED_NATIONAL; i++) { - if (sExcludedMons_national[i] == species) { + if (sExcludedMonsNational[i] == species) { included = FALSE; } } @@ -722,7 +718,7 @@ static BOOL CountsForDexCompletion_Local(u16 species) BOOL included = TRUE; for (int i = 0; i < NUM_EXCLUDED_LOCAL; i++) { - if (sExcludedMons_local[i] == species) { + if (sExcludedMonsLocal[i] == species) { included = FALSE; } } @@ -737,15 +733,15 @@ void PokedexData_Init(PokedexData *pokedexData) pokedexData->magic = MAGIC_NUMBER; pokedexData->nationalDexObtained = FALSE; - memset(pokedexData->unownFormsSeen, TERMINAL_U8, sizeof(u8) * UNOWN_COUNT); + memset(pokedexData->unownFormsSeen, 0xFF, sizeof(u8) * UNOWN_COUNT); - pokedexData->shellosFormsSeen = TERMINAL_U8; - pokedexData->gastrodonFormsSeen = TERMINAL_U8; - pokedexData->burmyFormsSeen = TERMINAL_U8; - pokedexData->wormadamFormsSeen = TERMINAL_U8; - pokedexData->rotomFormsSeen = TERMINAL_U32; - pokedexData->shayminFormsSeen = TERMINAL_U8; - pokedexData->giratinaFormsSeen = TERMINAL_U8; + pokedexData->shellosFormsSeen = 0xFF; + pokedexData->gastrodonFormsSeen = 0xFF; + pokedexData->burmyFormsSeen = 0xFF; + pokedexData->wormadamFormsSeen = 0xFF; + pokedexData->rotomFormsSeen = 0xFFFFFFFF; + pokedexData->shayminFormsSeen = 0xFF; + pokedexData->giratinaFormsSeen = 0xFF; InitDeoxys(pokedexData); }