From 6494775ecc10288f313b64563bb24da78b651e0d Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 8 Jun 2025 10:34:03 +0200 Subject: [PATCH] More documentation --- include/pokemon_3.h | 8 ++-- include/structs/dungeon_mapparam.h | 3 +- include/structs/str_dungeon.h | 12 ++--- include/structs/str_packed_pokemon_data.h | 15 +++++++ src/code_803D110.c | 9 ++-- src/code_8069E0C.c | 8 ++-- src/dungeon_misc.c | 1 - src/move_orb_effects_2.c | 4 +- src/move_orb_effects_4.c | 2 - src/move_orb_effects_5.c | 2 - src/pokemon_3.c | 54 ++++++++++++++++------- 11 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 include/structs/str_packed_pokemon_data.h diff --git a/include/pokemon_3.h b/include/pokemon_3.h index c02fdccd4..d329b9ace 100644 --- a/include/pokemon_3.h +++ b/include/pokemon_3.h @@ -2,6 +2,7 @@ #define GUARD_POKEMON_3_H #include "pokemon.h" +#include "structs/str_packed_pokemon_data.h" // size: 0x8 typedef struct EvolveStatus @@ -72,9 +73,10 @@ void SetDefaultIQSkills(IqSkillFlags *iq, bool8 enableSelfCurer); void sub_808F468(PokemonStruct1 *param_1, EvolveStatus *evolveStatus, bool8 param_3); s32 sub_808F700(PokemonStruct1 *pokemon); PokemonStruct1 *sub_808F734(PokemonStruct1 *pokemon, s16 _species); -s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0); -void SetSpeciesLevelToExtract(UnkDungeonGlobal_unk1CD98 *r0, s32 level, s32 species); -s32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0); +s16 ExtractSpeciesIndex(PackedPokemonData *data); +void SetSpeciesToExtract(PackedPokemonData *data, s32 species_); +void SetSpeciesLevelToExtract(PackedPokemonData *data, s32 level, s32 species_); +s32 ExtractLevel(PackedPokemonData *data); PokemonStruct1 *sub_808F798(PokemonStruct1 *pokemon, short _species); void CreatePokemonInfoTabScreen(s32 param_1, s32 param_2, struct unkStruct_808FF20 *mon, struct UnkInfoTabStruct *param_4, u32 windowId); void sub_808FF20(struct unkStruct_808FF20 *param_1, struct PokemonStruct1 *pokemon, bool8 param_3); diff --git a/include/structs/dungeon_mapparam.h b/include/structs/dungeon_mapparam.h index 6e293c1df..451bf3a04 100644 --- a/include/structs/dungeon_mapparam.h +++ b/include/structs/dungeon_mapparam.h @@ -2,6 +2,7 @@ #define GUARD_DUNGEON_MAPPARAM_H #include "dungeon.h" +#include "structs/str_packed_pokemon_data.h" struct DungeonMapParam1 { @@ -16,7 +17,7 @@ struct DungeonMapParam2 struct DungeonMapParam1 **unk0; FloorProperties *unk4; u16 **unk8; - UnkDungeonGlobal_unk1CD98 **unkC; + PackedPokemonData **unkC; u16 **unk10; }; diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 561ed1082..f5ca2c0b3 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -10,6 +10,7 @@ #include "structs/str_traps.h" #include "structs/str_dungeon_location.h" #include "structs/str_dungeon_mail_seed.h" +#include "structs/str_packed_pokemon_data.h" #define DUNGEON_MAX_SIZE_X 56 #define DUNGEON_MAX_SIZE_Y 32 @@ -161,13 +162,6 @@ typedef struct ItemSpawns s16 itemValues[NUMBER_OF_ITEM_IDS]; } ItemSpawns; -// size: R=0x8 | B=0x6 -typedef struct UnkDungeonGlobal_unk1CD98 -{ - u16 unk0; // species and level - s16 unk2[2]; -} UnkDungeonGlobal_unk1CD98; - struct unkStruct_Dungeon134_sub { u8 unk134; @@ -402,7 +396,7 @@ typedef struct Dungeon EntityInfo unk69C[MAX_TEAM_MEMBERS]; EntityInfo unkEBC[DUNGEON_MAX_WILD_POKEMON_BODY_SIZE]; /* 0x2F3C */ unkDungeon2F3C unk2F3C[64]; - /* 0x343C */ UnkDungeonGlobal_unk1CD98 unk343C[32]; + /* 0x343C */ PackedPokemonData unk343C[32]; u8 fill353C[0x363c-0x353c]; /* 0x363C */ u8 expYieldRankings[MONSTER_MAX]; /* 0x37E4 */ s32 unk37E4; @@ -486,7 +480,7 @@ typedef struct Dungeon /* 0x1C574 */ FloorProperties floorProperties; /* 0x1C590 */ ItemSpawns itemSpawns[ITEM_SPAWN_TYPES_COUNT]; u16 unk1CD70[20]; - UnkDungeonGlobal_unk1CD98 unk1CD98[32]; + PackedPokemonData unk1CD98[32]; UnkDungeonGlobal_unk1CE98_sub unk1CE98; // TODO: not sure how large this is u8 unk1CEC8; /* 0x1CECC */ DungeonMusicPlayer musPlayer; diff --git a/include/structs/str_packed_pokemon_data.h b/include/structs/str_packed_pokemon_data.h new file mode 100644 index 000000000..fd0089963 --- /dev/null +++ b/include/structs/str_packed_pokemon_data.h @@ -0,0 +1,15 @@ +#ifndef GUARD_STR_PACKED_POKEMON_DATA_H +#define GUARD_STR_PACKED_POKEMON_DATA_H + +#define PACKED_BITS_SPECIES 0x1FF +#define PACKED_BITS_LEVEL 0x7F +#define PACKED_BITS_LEVEL_SHIFT 9 + +// size: R=0x8 | B=0x6 +typedef struct PackedPokemonData +{ + u16 bits; // species first 9 bits, level last 7 bits + s16 unk2[2]; +} PackedPokemonData; + +#endif // GUARD_STR_PACKED_POKEMON_DATA_H diff --git a/src/code_803D110.c b/src/code_803D110.c index 5836c6b97..e40d7b599 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -24,11 +24,10 @@ // File split is correct. extern s32 sub_80902C8(u8 dungeon); -extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); void sub_803D4AC(void) { - gDungeon->unk1C570.id = 0x63; + gDungeon->unk1C570.id = DUNGEON_INVALID; gDungeon->unk1C570.floor = 0xFF; } @@ -61,7 +60,7 @@ void sub_803D4D0(void) break; } while (i <= 31) { - sub_808E9C4(&gDungeon->unk1CD98[i], 0); + SetSpeciesToExtract(&gDungeon->unk1CD98[i], 0); i++; } @@ -133,7 +132,7 @@ u8 GetRandomFloorItem(s32 spawnType) return ITEM_POKE; } -s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) +s32 sub_803D808(PackedPokemonData *strPtr, s32 id) { s32 i; @@ -147,7 +146,7 @@ s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) return id; } -s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) +s32 sub_803D870(PackedPokemonData *strPtr, s32 id) { s32 i; diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index 473e3886e..03c8c3055 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -43,7 +43,7 @@ extern void sub_804178C(u32); extern void sub_803F508(Entity *); extern void sub_8042B20(Entity *entity); extern void sub_8042B0C(Entity *entity); -extern s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id); +extern s32 sub_803D808(PackedPokemonData *strPtr, s32 id); extern void sub_8072AC8(u16 *param_1, s32 species, s32 param_3); extern s16 sub_803D970(u32); extern bool8 sub_8083660(const DungeonPos *param_1); @@ -80,7 +80,7 @@ void sub_806AD3C(void) { s32 r10; s32 i, j; - UnkDungeonGlobal_unk1CD98 sp[64]; + PackedPokemonData sp[64]; unkDungeon2F3C *structPtr = gDungeon->unk2F3C; s32 var_24 = sub_803D808(sp, 0); @@ -212,12 +212,12 @@ void sub_806AED8(Moves *moves, s16 *maxHPStat, u8 *atk, u8 *def, s16 _species, s moves->struggleMoveFlags = 0; } -UNUSED static s32 sub_806B09C(UnkDungeonGlobal_unk1CD98 *unkPtr, bool8 a1) +UNUSED static s32 sub_806B09C(PackedPokemonData *unkPtr, bool8 a1) { s32 i, j; s32 count = 0; s16 *unk2Field; - UnkDungeonGlobal_unk1CD98 *loopPtr; + PackedPokemonData *loopPtr; for (i = 0, unk2Field = unkPtr->unk2, loopPtr = unkPtr; i < MAX_TEAM_MEMBERS; i++) { PokemonStruct2 *monStructPtr = &gRecruitedPokemonRef->pokemon2[i]; diff --git a/src/dungeon_misc.c b/src/dungeon_misc.c index c98e8c593..903893bfb 100644 --- a/src/dungeon_misc.c +++ b/src/dungeon_misc.c @@ -69,7 +69,6 @@ extern void sub_804178C(u32); extern void sub_803F508(Entity *); extern void sub_8042B20(Entity *entity); extern void sub_8042B0C(Entity *entity); -extern s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id); extern void sub_8072AC8(u16 *param_1, s32 species, s32 param_3); extern s16 sub_803D970(u32); extern bool8 sub_8083660(const DungeonPos *param_1); diff --git a/src/move_orb_effects_2.c b/src/move_orb_effects_2.c index 0e9b5337e..241a77177 100644 --- a/src/move_orb_effects_2.c +++ b/src/move_orb_effects_2.c @@ -85,7 +85,7 @@ extern void nullsub_87(Entity *); extern void nullsub_86(Entity *); extern void sub_8041E0C(Entity *); extern void sub_8041DD8(Entity *r0, s32 r1); // NOTE: is s16 in another file -extern s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id); +extern s32 sub_803D870(PackedPokemonData *strPtr, s32 id); extern bool8 sub_806AA0C(s32, u32); extern void sub_803F580(u32); extern void ShowWholeRevealedDungeonMap(void); @@ -909,7 +909,7 @@ void TransformStatusTarget(Entity * pokemon, Entity * target) s32 index; EntityInfo *entityInfo; OpenedFile *sprite; - UnkDungeonGlobal_unk1CD98 auStack544[64]; + PackedPokemonData auStack544[64]; if (!EntityIsValid(target)) return; diff --git a/src/move_orb_effects_4.c b/src/move_orb_effects_4.c index 9286f41d1..dc1edee1c 100644 --- a/src/move_orb_effects_4.c +++ b/src/move_orb_effects_4.c @@ -66,8 +66,6 @@ extern void nullsub_88(Entity *); extern void nullsub_87(Entity *); extern void nullsub_86(Entity *); extern void sub_8041E0C(Entity *); -extern void sub_8041DD8(Entity *r0, s32 r1); // NOTE: is s16 in another file -extern s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id); extern bool8 sub_806AA0C(s32, u32); void CounterStatusTarget(Entity * pokemon, Entity * target, u8 newStatus) diff --git a/src/move_orb_effects_5.c b/src/move_orb_effects_5.c index 8779f9aab..6598bf551 100644 --- a/src/move_orb_effects_5.c +++ b/src/move_orb_effects_5.c @@ -66,8 +66,6 @@ extern void nullsub_88(Entity *); extern void nullsub_87(Entity *); extern void nullsub_86(Entity *); extern void sub_8041E0C(Entity *); -extern void sub_8041DD8(Entity *r0, s32 r1); // NOTE: is s16 in another file -extern s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id); extern bool8 sub_806AA0C(s32, u32); void sub_8079F20(Entity * pokemon, Entity * target, u8 param_3, u8 param_4) diff --git a/src/pokemon_3.c b/src/pokemon_3.c index af02b2177..d8eb0c6f8 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -260,30 +260,31 @@ s32 GetUnownIndex(s16 index) } // arm9.bin::02059B98 -s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0) +s16 ExtractSpeciesIndex(PackedPokemonData *data) { - return r0->unk0 & 0x000001ff; + return data->bits & PACKED_BITS_SPECIES; } // arm9.bin::02059B7C -void sub_808E9C4(PokemonStruct1 *r0, s16 r1) +void SetSpeciesToExtract(PackedPokemonData *data, s32 species_) { - s32 r1_s32 = r1; // cast needed to match - r0->unk0 = ((0xFE << 8) & r0->unk0) | r1_s32 ; + s32 species = (s16) species_; + data->bits &= (PACKED_BITS_LEVEL << PACKED_BITS_LEVEL_SHIFT); + data->bits |= species; } #if (GAME_VERSION == VERSION_RED) -void SetSpeciesLevelToExtract(UnkDungeonGlobal_unk1CD98 *r0, s32 level, s32 species) +void SetSpeciesLevelToExtract(PackedPokemonData *data, s32 level, s32 species_) { - species = SpeciesId(species); - r0->unk0 = species | (level << 9) ; + s32 species = (s16) (species_); + data->bits = species | (level << PACKED_BITS_LEVEL_SHIFT) ; } #endif // arm9.bin::02059B6C -s32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0) +s32 ExtractLevel(PackedPokemonData *data) { - return (r0->unk0 >> 9); + return (data->bits >> PACKED_BITS_LEVEL_SHIFT) & PACKED_BITS_LEVEL; } UNUSED static void GetMonOffenseStats(PokemonStruct1 *mon, struct UnusedOffenseStruct *dst) @@ -443,8 +444,31 @@ void ToggleIQSkill(IqSkillFlags *iq, u32 skillIndex) } } -static const s32 gIQSkillGroups[] = { - 9999, 4, 1, 2, 4, 4, 6, 7, 8, 9, 9, 9, 10, 10, 11, 11, 14, 14, 14, 16, 16, 9, 17, 6 +static const s32 sIQSkillGroups[NUM_IQ_SKILLS] = { + [IQ_NONE] = 9999, + [IQ_TYPE_ADVANTAGE_MASTER] = 4, + [IQ_ITEM_CATCHER] = 1, + [IQ_COURSE_CHECKER] = 2, + [IQ_SURE_HIT_ATTACKER] = 4, + [IQ_QUICK_DODGER] = 4, + [IQ_PP_CHECKER] = 6, + [IQ_NONTRAITOR] = 7, + [IQ_STATUS_CHECKER] = 8, + [IQ_EXP_GO_GETTER] = 9, + [IQ_EFFICIENCY_EXPERT] = 9, + [IQ_WEAK_TYPE_PICKER] = 9, + [IQ_ALL_TERRAIN_HIKER] = 10, + [IQ_SUPER_MOBILE] = 10, + [IQ_TRAP_AVOIDER] = 11, + [IQ_HOUSE_AVOIDER] = 11, + [IQ_ENERGY_SAVER] = 14, + [IQ_NONSLEEPER] = 14, + [IQ_SELF_CURER] = 14, + [IQ_TRAP_SEER] = 16, + [IQ_LAVA_EVADER] = 16, + [IQ_DEDICATED_TRAVELER] = 9, + [IQ_ITEM_MASTER] = 17, + [IQ_EXCLUSIVE_MOVE_USER] = 6, }; void SetIQSkill(IqSkillFlags *iq, u32 skillIndex) @@ -453,9 +477,9 @@ void SetIQSkill(IqSkillFlags *iq, u32 skillIndex) s32 iqSkillGroup; s32 bit; - for (iqSkill = 0, iqSkillGroup = gIQSkillGroups[skillIndex]; iqSkill < NUM_IQ_SKILLS; iqSkill++) { + for (iqSkill = 0, iqSkillGroup = sIQSkillGroups[skillIndex]; iqSkill < NUM_IQ_SKILLS; iqSkill++) { // Turn off each IQ Skill that's in the same group as the chosen skill - if (iqSkillGroup == gIQSkillGroups[iqSkill]) { + if (iqSkillGroup == sIQSkillGroups[iqSkill]) { s32 bit = 1 << (iqSkill); iq->flags[0] &= ~(bit); iq->flags[1] &= ~(bit >> 8); @@ -503,7 +527,7 @@ u32 sub_808ECFC(void) return 0; } -void sub_808ED00() +void sub_808ED00(void) { s32 team[4]; s32 i;