From 7be7cd3bf680f5c825ddd21b2576e6b7e53c6f6e Mon Sep 17 00:00:00 2001 From: Skeli Date: Sun, 19 Apr 2020 16:40:17 +0300 Subject: [PATCH] Regional Dex Support --- BPRE.ld | 3 + assembly/hooks.s | 87 +------------- assembly/pokedex_hooks.s | 155 +++++++++++++++++++++++++ hooks | 10 +- include/pokedex.h | 13 ++- special_inserts.asm | 30 +++-- src/Front_Pic_Coords_Table.c | 2 +- src/Pokedex_Data_Table.c | 2 +- src/Pokedex_Orders.c | 160 +++++++++++++++++++++++++- src/updated_code.c | 214 +++++++++++++++++++++++++---------- 10 files changed, 512 insertions(+), 164 deletions(-) create mode 100644 assembly/pokedex_hooks.s diff --git a/BPRE.ld b/BPRE.ld index f8c8e0b..612b1d3 100644 --- a/BPRE.ld +++ b/BPRE.ld @@ -13,8 +13,11 @@ GetGenderFromSpeciesAndPersonality = 0x803F78C | 1; GetMonData = 0x803FBE8 | 1; SpeciesToNationalPokedexNum = 0x8043298 | 1; DrawSpindaSpots = 0x8043458 | 1; +IsNationalPokedexEnabled = 0x806E25C | 1; GetUnownLetterFromPersonality = 0x8082AB8 | 1; +GetSetPokedexFlag = 0x8088E74 | 1; SafeLoadMonIconPalette = 0x80970A0 | 1; +DexFlagCheck = 0x8104AB0 | 1; LZ77UnCompWram = 0x81E3B70 | 1; /*The Deal Breaker*/ diff --git a/assembly/hooks.s b/assembly/hooks.s index 1a6bbdd..12e63b9 100644 --- a/assembly/hooks.s +++ b/assembly/hooks.s @@ -1,92 +1,6 @@ .thumb .align 2 -@0x81025E8 with r0 -PokedexMemoryAllocationHook: - ldr r0, [r5] - strb r4, [r0] - bl IsInBattle - cmp r0, #0x0 - bne RegularPokedexMemoryAlloc - ldr r0, .ExpandedPokedexSize - b PokedexMemoryAllocReturn - -RegularPokedexMemoryAlloc: - ldr r0, .RegularPokedexSize - -PokedexMemoryAllocReturn: - ldr r1, =0x81025F0 | 1 - bx r1 - -.align 2 -.RegularPokedexSize: .word 0xC10 -.ExpandedPokedexSize: .word 999 * 8 - -.pool -@0x8103530 with r1 -PrepareDexListViewsHook: - cmp r0, #0x0 - beq PrepareDexListViewsReturn - ldr r2, =gNumDexEntries - ldrh r2, [r2] - str r2, [sp] - -PrepareDexListViewsReturn: - ldr r0, =0x810353A | 1 - bx r0 - -.pool -@0x8103684 with r1 -AlphabeticalDexHook: - add r8, r0 - ldr r0, =gNumSpecies - ldrh r0, [r0] - cmp r8, r0 - ldr r1, =0x810368C | 1 - bx r1 - -.pool -@0x8105CBC with r0 -AlternateDexEntriesHook: - lsl r2, r2, #0x18 - lsr r5, r2, #0x18 - lsl r3, r3, #0x18 - lsr r7, r3, #0x18 - mov r0, r1 - mov r4, r1 - bl TryLoadAlternateDexEntry - cmp r0, #0x0 - bne AlternateDexEntriesReturn - mov r0, r4 - ldr r1, =0x8105CC6 | 1 -bxr1: - bx r1 - -AlternateDexEntriesReturn: - push {r0} - mov r0, r4 - ldr r1, =SpeciesToNationalPokedexNum - bl bxr1 - mov r4, r0 - mov r1, #0x1 - mov r2, #0x0 - bl DexFlagCheckCall - lsl r0, #0x18 - cmp r0, #0x0 - pop {r0} - beq DontDisplayDesc - mov r1, r0 - ldr r0, =0x8105CEA | 1 - bx r0 - -DontDisplayDesc: - ldr r0, =0x8105D5C | 1 - bx r0 - -DexFlagCheckCall: - ldr r3, =0x8104AB0 | 1 - bx r3 - .pool @0x800ECF2 with r4 LoadSpecialPokePicHook: @@ -131,6 +45,7 @@ BattleLoadOpponentMonSpriteGfxHook: ldr r2, =GetMonData bl bxr2 ldr r1, =0x08034374 | 1 +bxr1: bx r1 /* diff --git a/assembly/pokedex_hooks.s b/assembly/pokedex_hooks.s new file mode 100644 index 0000000..50c6a1b --- /dev/null +++ b/assembly/pokedex_hooks.s @@ -0,0 +1,155 @@ +.thumb +.align 2 + +@0x81025E8 with r0 +PokedexMemoryAllocationHook: + ldr r0, [r5] + strb r4, [r0] + bl IsInBattle + cmp r0, #0x0 + bne RegularPokedexMemoryAlloc + ldr r0, .ExpandedPokedexSize + b PokedexMemoryAllocReturn + +RegularPokedexMemoryAlloc: + ldr r0, .RegularPokedexSize + +PokedexMemoryAllocReturn: + ldr r1, =0x81025F0 | 1 + bx r1 + +.align 2 +.RegularPokedexSize: .word 0xC10 +.ExpandedPokedexSize: .word 999 * 8 + +.pool +@0x8103530 with r1 +PrepareDexListViewsHook: + cmp r0, #0x0 + beq PrepareDexListViewsReturn + ldr r2, =gNumDexEntries + ldrh r2, [r2] + str r2, [sp] + +PrepareDexListViewsReturn: + ldr r2, =gRegionalDexCount + ldrh r2, [r2] + sub r2, #0x1 + lsl r2, #0x1 + ldr r0, =gPokedexOrder_Regional + ldrh r2, [r0, r2] @Load final dexNum in regional dex + ldr r0, =0x810353A | 1 + bx r0 + +@0x810356C with r0 +RegionalDexHook: + mov r4, r8 + lsl r0, r4, #0x1 @;Index x2 + ldr r1, =gPokedexOrder_Regional + ldrh r0, [r1, r0] + add r4, #0x1 + mov r5, r0 + mov r1, #0 + ldr r2, =0x8103578 | 1 + bx r2 + +@0x81035B4 with r1 +StoreLastDexSeenHook: + str r0, [r2] + mov r10, r4 + mov r4, r3 + ldr r0, =0x081035D6 | 1 + bx r0 + +@0x081035F4 with r0 +LazyRegionalDexEndHook: + mov r0, r8 + ldr r1, =gRegionalDexCount + ldrh r1, [r1] + cmp r0, r1 + bcc RegionalDexHook + ldr r1, =0x08103906 | 1 +bxr1: + bx r1 + +@0x8104A66 with r1 +DisplayRegionalDexNumHook: + mov r5, r0 + ldr r1, =IsNationalPokedexEnabled + bl bxr1 + cmp r0, #0x0 + beq UseRegionalDexOrdering + ldr r1, =0x203ACF0 + ldr r1, [r1] + add r1, #0x42 + ldrb r1, [r1] + cmp r1, #0x0 @;Check if looking at regional dex + beq UseRegionalDexOrdering + mov r0, r5 + ldr r1, =SpeciesToNationalPokedexNum + bl bxr1 + b DisplayDexNumberReturn + +UseRegionalDexOrdering: + mov r0, r5 + ldr r1, =SpeciesToNationalPokedexNum + bl bxr1 + bl NatDexNumToRegionalDexNum + +DisplayDexNumberReturn: + mov r5, r0 + ldr r0, =0x8104A70 | 1 + bx r0 + +.pool +@0x8103684 with r1 +AlphabeticalDexHook: + add r8, r0 + ldr r0, =gNumDexEntries + ldrh r0, [r0] + sub r0, #0x1 + cmp r8, r0 + ldr r1, =0x810368C | 1 + bx r1 + +.pool +@0x8105CBC with r0 +AlternateDexEntriesHook: + lsl r2, r2, #0x18 + lsr r5, r2, #0x18 + lsl r3, r3, #0x18 + lsr r7, r3, #0x18 + mov r0, r1 + mov r4, r1 + bl TryLoadAlternateDexEntry + cmp r0, #0x0 + bne AlternateDexEntriesReturn + mov r0, r4 + ldr r1, =0x8105CC6 | 1 + bx r1 + +AlternateDexEntriesReturn: + push {r0} + mov r0, r4 + ldr r1, =SpeciesToNationalPokedexNum + bl bxr1 + mov r4, r0 + mov r1, #0x1 + mov r2, #0x0 + bl DexFlagCheckCall + lsl r0, #0x18 + cmp r0, #0x0 + pop {r0} + beq DontDisplayDesc + mov r1, r0 + ldr r0, =0x8105CEA | 1 + bx r0 + +DontDisplayDesc: + ldr r0, =0x8105D5C | 1 + bx r0 + +DexFlagCheckCall: + ldr r3, =0x8104AB0 | 1 + bx r3 + diff --git a/hooks b/hooks index 61e7131..81f5810 100644 --- a/hooks +++ b/hooks @@ -11,10 +11,18 @@ GetMonSpritePalStructFromOtIdPersonality 8044180 3 GetEggSpecies 8045970 1 GetEggMoves 8045C28 2 CreateMonSprite_PicBoxHook 808398C 1 +GetRegionalPokedexCount 8088EDC 1 +HasAllRegionalMons 8088F58 0 +HasAllMons 8088F84 0 GenderedMonIconHook 8096E38 2 GetIconSpecies 8096F5C 2 PokedexMemoryAllocationHook 81025E8 0 PrepareDexListViewsHook 8103530 1 +RegionalDexHook 810356C 0 +StoreLastDexSeenHook 81035B4 1 +LazyRegionalDexEndHook 81035F4 0 AlphabeticalDexHook 8103684 1 +DisplayRegionalDexNumHook 8104A66 1 +CountSpeciesInDex 8104BBC 2 AlternateDexEntriesHook 8105CBC 0 -SummaryScreenIconPalHook 8139DDC 1 \ No newline at end of file +SummaryScreenIconPalHook 8139DDC 1 diff --git a/include/pokedex.h b/include/pokedex.h index c71a2c7..be0c4f0 100644 --- a/include/pokedex.h +++ b/include/pokedex.h @@ -21,6 +21,14 @@ struct AlternateDexEntries const u8* description; }; +enum +{ + FLAG_GET_SEEN, + FLAG_GET_CAUGHT, + FLAG_SET_SEEN, + FLAG_SET_CAUGHT +}; + //Kanto #define NATIONAL_DEX_NONE 0 #define NATIONAL_DEX_BULBASAUR 1 @@ -850,7 +858,8 @@ struct AlternateDexEntries #define NATIONAL_DEX_MELTAN 808 #define NATIONAL_DEX_MELMETAL 809 -#define NUM_DEX_ENTRIES NATIONAL_DEX_MELMETAL //Not +1 b/c used like this for some asm +#define FINAL_DEX_ENTRY NATIONAL_DEX_MELMETAL //Not +1 b/c used like this for some asm +#define NATIONAL_DEX_COUNT NATIONAL_DEX_MELMETAL + 1 extern const u8 DEX_ENTRY_TURTWIG[]; extern const u8 DEX_ENTRY_GROTLE[]; @@ -1304,4 +1313,4 @@ extern const u8 DEX_ENTRY_LYCANROC_DUSK[]; extern const u8 DEX_ENTRY_WISHIWASHI_S[]; extern const u8 DEX_ENTRY_NECROZMA_DUSK_MANE[]; extern const u8 DEX_ENTRY_NECROZMA_DAWN_WINGS[]; -extern const u8 DEX_ENTRY_NECROZMA_ULTRA[]; \ No newline at end of file +extern const u8 DEX_ENTRY_NECROZMA_ULTRA[]; diff --git a/special_inserts.asm b/special_inserts.asm index dc34aa7..d3742cb 100644 --- a/special_inserts.asm +++ b/special_inserts.asm @@ -4,10 +4,10 @@ .equ NUM_SPECIES, 1102 .equ EVOS_PER_MON, 16 -.equ NUM_DEX_ENTRIES, 809 +.equ FINAL_DEX_ENTRY, 809 @;.equ SEEN_DEX_FLAGS, 0x202583C -@;.equ CAUGHT_DEX_FLAGS, (SEEN_DEX_FLAGS + (NUM_DEX_ENTRIES / 8) + 1) +@;.equ CAUGHT_DEX_FLAGS, (SEEN_DEX_FLAGS + (FINAL_DEX_ENTRY / 8) + 1) @@Fix Num Evolutions@@ .org 0x4598A, 0xFF @@ -27,29 +27,29 @@ add r3, #EVOS_PER_MON * 8 mov r0, r4 mov r8, r8 mov r1, #0x0 - mov r2, #(NUM_DEX_ENTRIES / 8) + 1 + mov r2, #(FINAL_DEX_ENTRY / 8) + 1 .org 0x549BC, 0xFF mov r0, r4 - add r0, #(NUM_DEX_ENTRIES / 8) + 1 + add r0, #(FINAL_DEX_ENTRY / 8) + 1 mov r1, #0x0 - mov r2, #(NUM_DEX_ENTRIES / 8) + 1 + mov r2, #(FINAL_DEX_ENTRY / 8) + 1 @;.org 0x549D0, 0xFF @;.word SEEN_DEX_FLAGS @@Fix Dex Views@@ .org 0x88EA4, 0xFF @Pokedex Count -.word NUM_DEX_ENTRIES - 1 +.word FINAL_DEX_ENTRY - 1 .org 0x1037D4, 0xFF @Weight View -.word NUM_DEX_ENTRIES - 1 +.word FINAL_DEX_ENTRY - 1 .org 0x103870, 0xFF @Height View -.word NUM_DEX_ENTRIES - 1 +.word FINAL_DEX_ENTRY - 1 .org 0x103920, 0xFF @General -.word NUM_DEX_ENTRIES - 1 +.word FINAL_DEX_ENTRY - 1 @;.org 0x104B10, 0xFF @;.word SEEN_DEX_FLAGS @@ -64,4 +64,14 @@ add r3, #EVOS_PER_MON * 8 @;.word CAUGHT_DEX_FLAGS .org 0x104C28, 0xFF -.word NUM_DEX_ENTRIES - 1 +.word FINAL_DEX_ENTRY - 1 + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Remove Caught Mon Pokedex 151 Limiter +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +.org 0x10682E, 0xFF + mov r8, r8 + +.org 0x106B80, 0xFF +RemoveCaughtMonPokedex151Limiter: + b RemoveCaughtMonPokedex151Limiter + 0x24 @0x106BA4 diff --git a/src/Front_Pic_Coords_Table.c b/src/Front_Pic_Coords_Table.c index a35271b..b598fe9 100644 --- a/src/Front_Pic_Coords_Table.c +++ b/src/Front_Pic_Coords_Table.c @@ -4111,7 +4111,7 @@ const struct MonCoords gMonFrontPicCoords[NUM_SPECIES] = [SPECIES_AVALUGG] = { .size = 0x0, - .y_offset = 0x0, + .y_offset = 0x6, }, [SPECIES_NOIBAT] = { diff --git a/src/Pokedex_Data_Table.c b/src/Pokedex_Data_Table.c index 1a6bc71..8f4e5b4 100644 --- a/src/Pokedex_Data_Table.c +++ b/src/Pokedex_Data_Table.c @@ -2,7 +2,7 @@ #include "../include/pokedex.h" #include "../include/text.h" -const struct PokedexEntry gPokedexEntries[NUM_DEX_ENTRIES + 1] = +const struct PokedexEntry gPokedexEntries[NATIONAL_DEX_COUNT] = { [NATIONAL_DEX_NONE] = { diff --git a/src/Pokedex_Orders.c b/src/Pokedex_Orders.c index cace5f5..7fc3f5c 100644 --- a/src/Pokedex_Orders.c +++ b/src/Pokedex_Orders.c @@ -1,6 +1,163 @@ #include "defines.h" #include "../include/pokedex.h" +const u16 gPokedexOrder_Regional[] = +{ + NATIONAL_DEX_BULBASAUR, + NATIONAL_DEX_IVYSAUR, + NATIONAL_DEX_VENUSAUR, + NATIONAL_DEX_CHARMANDER, + NATIONAL_DEX_CHARMELEON, + NATIONAL_DEX_CHARIZARD, + NATIONAL_DEX_SQUIRTLE, + NATIONAL_DEX_WARTORTLE, + NATIONAL_DEX_BLASTOISE, + NATIONAL_DEX_CATERPIE, + NATIONAL_DEX_METAPOD, + NATIONAL_DEX_BUTTERFREE, + NATIONAL_DEX_WEEDLE, + NATIONAL_DEX_KAKUNA, + NATIONAL_DEX_BEEDRILL, + NATIONAL_DEX_PIDGEY, + NATIONAL_DEX_PIDGEOTTO, + NATIONAL_DEX_PIDGEOT, + NATIONAL_DEX_RATTATA, + NATIONAL_DEX_RATICATE, + NATIONAL_DEX_SPEAROW, + NATIONAL_DEX_FEAROW, + NATIONAL_DEX_EKANS, + NATIONAL_DEX_ARBOK, + NATIONAL_DEX_PIKACHU, + NATIONAL_DEX_RAICHU, + NATIONAL_DEX_SANDSHREW, + NATIONAL_DEX_SANDSLASH, + NATIONAL_DEX_NIDORAN_F, + NATIONAL_DEX_NIDORINA, + NATIONAL_DEX_NIDOQUEEN, + NATIONAL_DEX_NIDORAN_M, + NATIONAL_DEX_NIDORINO, + NATIONAL_DEX_NIDOKING, + NATIONAL_DEX_CLEFAIRY, + NATIONAL_DEX_CLEFABLE, + NATIONAL_DEX_VULPIX, + NATIONAL_DEX_NINETALES, + NATIONAL_DEX_JIGGLYPUFF, + NATIONAL_DEX_WIGGLYTUFF, + NATIONAL_DEX_ZUBAT, + NATIONAL_DEX_GOLBAT, + NATIONAL_DEX_ODDISH, + NATIONAL_DEX_GLOOM, + NATIONAL_DEX_VILEPLUME, + NATIONAL_DEX_PARAS, + NATIONAL_DEX_PARASECT, + NATIONAL_DEX_VENONAT, + NATIONAL_DEX_VENOMOTH, + NATIONAL_DEX_DIGLETT, + NATIONAL_DEX_DUGTRIO, + NATIONAL_DEX_MEOWTH, + NATIONAL_DEX_PERSIAN, + NATIONAL_DEX_PSYDUCK, + NATIONAL_DEX_GOLDUCK, + NATIONAL_DEX_MANKEY, + NATIONAL_DEX_PRIMEAPE, + NATIONAL_DEX_GROWLITHE, + NATIONAL_DEX_ARCANINE, + NATIONAL_DEX_POLIWAG, + NATIONAL_DEX_POLIWHIRL, + NATIONAL_DEX_POLIWRATH, + NATIONAL_DEX_ABRA, + NATIONAL_DEX_KADABRA, + NATIONAL_DEX_ALAKAZAM, + NATIONAL_DEX_MACHOP, + NATIONAL_DEX_MACHOKE, + NATIONAL_DEX_MACHAMP, + NATIONAL_DEX_BELLSPROUT, + NATIONAL_DEX_WEEPINBELL, + NATIONAL_DEX_VICTREEBEL, + NATIONAL_DEX_TENTACOOL, + NATIONAL_DEX_TENTACRUEL, + NATIONAL_DEX_GEODUDE, + NATIONAL_DEX_GRAVELER, + NATIONAL_DEX_GOLEM, + NATIONAL_DEX_PONYTA, + NATIONAL_DEX_RAPIDASH, + NATIONAL_DEX_SLOWPOKE, + NATIONAL_DEX_SLOWBRO, + NATIONAL_DEX_MAGNEMITE, + NATIONAL_DEX_MAGNETON, + NATIONAL_DEX_FARFETCHD, + NATIONAL_DEX_DODUO, + NATIONAL_DEX_DODRIO, + NATIONAL_DEX_SEEL, + NATIONAL_DEX_DEWGONG, + NATIONAL_DEX_GRIMER, + NATIONAL_DEX_MUK, + NATIONAL_DEX_SHELLDER, + NATIONAL_DEX_CLOYSTER, + NATIONAL_DEX_GASTLY, + NATIONAL_DEX_HAUNTER, + NATIONAL_DEX_GENGAR, + NATIONAL_DEX_ONIX, + NATIONAL_DEX_DROWZEE, + NATIONAL_DEX_HYPNO, + NATIONAL_DEX_KRABBY, + NATIONAL_DEX_KINGLER, + NATIONAL_DEX_VOLTORB, + NATIONAL_DEX_ELECTRODE, + NATIONAL_DEX_EXEGGCUTE, + NATIONAL_DEX_EXEGGUTOR, + NATIONAL_DEX_CUBONE, + NATIONAL_DEX_MAROWAK, + NATIONAL_DEX_HITMONLEE, + NATIONAL_DEX_HITMONCHAN, + NATIONAL_DEX_LICKITUNG, + NATIONAL_DEX_KOFFING, + NATIONAL_DEX_WEEZING, + NATIONAL_DEX_RHYHORN, + NATIONAL_DEX_RHYDON, + NATIONAL_DEX_CHANSEY, + NATIONAL_DEX_TANGELA, + NATIONAL_DEX_KANGASKHAN, + NATIONAL_DEX_HORSEA, + NATIONAL_DEX_SEADRA, + NATIONAL_DEX_GOLDEEN, + NATIONAL_DEX_SEAKING, + NATIONAL_DEX_STARYU, + NATIONAL_DEX_STARMIE, + NATIONAL_DEX_MR_MIME, + NATIONAL_DEX_SCYTHER, + NATIONAL_DEX_JYNX, + NATIONAL_DEX_ELECTABUZZ, + NATIONAL_DEX_MAGMAR, + NATIONAL_DEX_PINSIR, + NATIONAL_DEX_TAUROS, + NATIONAL_DEX_MAGIKARP, + NATIONAL_DEX_GYARADOS, + NATIONAL_DEX_LAPRAS, + NATIONAL_DEX_DITTO, + NATIONAL_DEX_EEVEE, + NATIONAL_DEX_VAPOREON, + NATIONAL_DEX_JOLTEON, + NATIONAL_DEX_FLAREON, + NATIONAL_DEX_PORYGON, + NATIONAL_DEX_OMANYTE, + NATIONAL_DEX_OMASTAR, + NATIONAL_DEX_KABUTO, + NATIONAL_DEX_KABUTOPS, + NATIONAL_DEX_AERODACTYL, + NATIONAL_DEX_SNORLAX, + NATIONAL_DEX_ARTICUNO, + NATIONAL_DEX_ZAPDOS, + NATIONAL_DEX_MOLTRES, + NATIONAL_DEX_DRATINI, + NATIONAL_DEX_DRAGONAIR, + NATIONAL_DEX_DRAGONITE, + NATIONAL_DEX_MEWTWO, + NATIONAL_DEX_MEW, +}; + +const u16 gRegionalDexCount = ARRAY_COUNT(gPokedexOrder_Regional); + const u16 gPokedexOrder_Alphabetical[] = { NATIONAL_DEX_ABOMASNOW, @@ -482,7 +639,6 @@ const u16 gPokedexOrder_Alphabetical[] = NATIONAL_DEX_NOCTOWL, NATIONAL_DEX_NOIBAT, NATIONAL_DEX_NOIVERN, - NATIONAL_DEX_NONE, NATIONAL_DEX_NOSEPASS, NATIONAL_DEX_NUMEL, NATIONAL_DEX_NUZLEAF, @@ -2443,4 +2599,4 @@ const u16 gPokedexOrder_Height[] = const u16 gPokedexOrder_Type[] = { -}; \ No newline at end of file +}; diff --git a/src/updated_code.c b/src/updated_code.c index eb4e2bd..79fd110 100644 --- a/src/updated_code.c +++ b/src/updated_code.c @@ -8,6 +8,8 @@ extern const u16 gSpeciesIdToCryId[]; extern const u16 gSpeciesToNationalPokedexNum[]; +extern const u16 gRegionalDexCount; +extern const u16 gPokedexOrder_Regional[]; extern const struct AlternateDexEntries gAlternateDexEntries[]; extern const struct CompressedSpriteSheet gMonBackPicTable[]; extern const struct CompressedSpriteSheet gMonFrontPicTable[]; @@ -15,10 +17,12 @@ extern const struct CompressedSpritePalette gMonPaletteTable[]; extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; const u16 gNumSpecies = NUM_SPECIES; -const u16 gNumDexEntries = NUM_DEX_ENTRIES; +const u16 gNumDexEntries = FINAL_DEX_ENTRY; u8 __attribute__((long_call)) GetGenderFromSpeciesAndPersonality(u16 species, u32 personality); u8 __attribute__((long_call)) GetUnownLetterFromPersonality(u32 personality); +bool8 __attribute__((long_call)) GetSetPokedexFlag(u16 nationalNum, u8 caseID); +s8 __attribute__((long_call)) DexFlagCheck(u16 nationalDexNo, u8 caseId, bool8 indexIsSpecies); void __attribute__((long_call)) break_func(u32); //This file's functions @@ -26,25 +30,25 @@ u16 TryGetFemaleGenderedSpecies(u16 species, u32 personality); u16 SpeciesToCryId(u16 species) { - return species + 1; + return species + 1; } u16 NationalPokedexNumToSpecies(u16 nationalNum) { - u16 species; + u16 species; - if (!nationalNum) - return 0; + if (!nationalNum) + return 0; - species = 0; + species = 0; - while (species < (NUM_SPECIES - 1) && gSpeciesToNationalPokedexNum[species] != nationalNum) - species++; + while (species < (NUM_SPECIES - 1) && gSpeciesToNationalPokedexNum[species] != nationalNum) + species++; - if (species == NUM_SPECIES - 1) - return 0; + if (species == NUM_SPECIES - 1) + return 0; - return species + 1; + return species + 1; } const u8* TryLoadAlternateDexEntry(u16 species) @@ -67,55 +71,55 @@ void LoadSpecialPokePic(const struct CompressedSpriteSheet* src, void* dest, u16 if (species != oldSpecies) //Updated sprite src = &table[species]; - if (species == SPECIES_UNOWN) - { - u16 i = GetUnownLetterFromPersonality(personality); + if (species == SPECIES_UNOWN) + { + u16 i = GetUnownLetterFromPersonality(personality); - // The other Unowns are separate from Unown A. - if (i == 0) - i = SPECIES_UNOWN; - else - i += SPECIES_UNOWN_B - 1; + // The other Unowns are separate from Unown A. + if (i == 0) + i = SPECIES_UNOWN; + else + i += SPECIES_UNOWN_B - 1; - if (!isFrontPic) - LZ77UnCompWram((void*) gMonBackPicTable[i].data, dest); - else - LZ77UnCompWram((void*) gMonFrontPicTable[i].data, dest); - } - else if (species > NUM_SPECIES) // is species unknown? draw the ? icon - LZ77UnCompWram((void*) gMonFrontPicTable[0].data, dest); - else - LZ77UnCompWram((void*) src->data, dest); + if (!isFrontPic) + LZ77UnCompWram((void*) gMonBackPicTable[i].data, dest); + else + LZ77UnCompWram((void*) gMonFrontPicTable[i].data, dest); + } + else if (species > NUM_SPECIES) // is species unknown? draw the ? icon + LZ77UnCompWram((void*) gMonFrontPicTable[0].data, dest); + else + LZ77UnCompWram((void*) src->data, dest); - DrawSpindaSpots(species, personality, dest, isFrontPic); + DrawSpindaSpots(species, personality, dest, isFrontPic); } const u32* GetFrontSpritePalFromSpeciesAndPersonality(u16 species, u32 otId, u32 personality) { - u32 shinyValue; + u32 shinyValue; species = TryGetFemaleGenderedSpecies(species, personality); - if (species > NUM_SPECIES) - return (u32*) gMonPaletteTable[0].data; + if (species > NUM_SPECIES) + return (u32*) gMonPaletteTable[0].data; - shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); - if (shinyValue < 8) - return (u32*) gMonShinyPaletteTable[species].data; - else - return (u32*) gMonPaletteTable[species].data; + shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); + if (shinyValue < 8) + return (u32*) gMonShinyPaletteTable[species].data; + else + return (u32*) gMonPaletteTable[species].data; } const struct CompressedSpritePalette* GetMonSpritePalStructFromOtIdPersonality(u16 species, u32 otId , u32 personality) { - u32 shinyValue; + u32 shinyValue; species = TryGetFemaleGenderedSpecies(species, personality); - shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); - if (shinyValue < 8) - return &gMonShinyPaletteTable[species]; - else - return &gMonPaletteTable[species]; + shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); + if (shinyValue < 8) + return &gMonShinyPaletteTable[species]; + else + return &gMonPaletteTable[species]; } u16 TryGetFemaleGenderedSpecies(u16 species, u32 personality) @@ -151,29 +155,117 @@ u16 TryGetFemaleGenderedSpecies(u16 species, u32 personality) u16 GetIconSpecies(u16 species, u32 personality) { - u16 result; + u16 result; - if (species == SPECIES_UNOWN) - { - u16 letter = GetUnownLetterFromPersonality(personality); - if (letter == 0) - letter = SPECIES_UNOWN; - else - letter += (SPECIES_UNOWN_B - 1); - result = letter; - } - else - { - if (species > NUM_SPECIES) - result = 0; - else - result = TryGetFemaleGenderedSpecies(species, personality); - } + if (species == SPECIES_UNOWN) + { + u16 letter = GetUnownLetterFromPersonality(personality); + if (letter == 0) + letter = SPECIES_UNOWN; + else + letter += (SPECIES_UNOWN_B - 1); + result = letter; + } + else + { + if (species > NUM_SPECIES) + result = 0; + else + result = TryGetFemaleGenderedSpecies(species, personality); + } - return result; + return result; } bool8 IsInBattle(void) { return gMain.inBattle; } + + +u16 CountSpeciesInDex(u8 caseId, bool8 whichDex) +{ + u16 count = 0; + u16 i; + + switch (whichDex) { + case 0: //Regional + for (i = 0; i < gRegionalDexCount; ++i) + { + if (DexFlagCheck(gPokedexOrder_Regional[i], caseId, FALSE)) + count++; + } + break; + case 1: //National + for (i = 1; i <= FINAL_DEX_ENTRY; ++i) + { + if (DexFlagCheck(i, caseId, FALSE)) + count++; + } + break; + } + + return count; +} + +u16 GetRegionalPokedexCount(u8 caseID) +{ + u16 count = 0; + u16 i; + + for (i = 0; i < gRegionalDexCount; ++i) + { + switch (caseID) + { + case FLAG_GET_SEEN: + if (GetSetPokedexFlag(gPokedexOrder_Regional[i], FLAG_GET_SEEN)) + count++; + break; + case FLAG_GET_CAUGHT: + if (GetSetPokedexFlag(gPokedexOrder_Regional[i], FLAG_GET_CAUGHT)) + count++; + break; + } + } + + return count; +} + +bool16 HasAllRegionalMons(void) +{ + u16 i; + + for (i = 0; i < gRegionalDexCount; ++i) + { + if (!GetSetPokedexFlag(gPokedexOrder_Regional[i], FLAG_GET_CAUGHT)) + return FALSE; + } + + return TRUE; +} + +bool16 HasAllMons(void) +{ + u16 i; + + for (i = 1; i <= FINAL_DEX_ENTRY; ++i) + { + if (!GetSetPokedexFlag(i, FLAG_GET_CAUGHT)) + return FALSE; + } + + return TRUE; +} + +u16 NatDexNumToRegionalDexNum(u16 natDexNum) +{ + u16 i; + + for (i = 0; i < gRegionalDexCount; ++i) + { + if (gPokedexOrder_Regional[i] == natDexNum) + return i + 1; + } + + return 0; +}