From b9cd0dddc3bcd66fd4655eb5335838fb1663c4c1 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 28 Nov 2024 14:04:20 +0100 Subject: [PATCH 1/2] sub_80453AC and sub_804550C --- include/code_805D8C8.h | 4 +- src/code_80450F8.c | 527 ++++++----------------------------------- src/code_805D8C8.c | 8 +- src/code_8069E0C.c | 3 +- 4 files changed, 79 insertions(+), 463 deletions(-) diff --git a/include/code_805D8C8.h b/include/code_805D8C8.h index dd2fb228..be4a29c3 100644 --- a/include/code_805D8C8.h +++ b/include/code_805D8C8.h @@ -7,7 +7,7 @@ void CloseAllSpriteFiles(void); void sub_8068768(void); void sub_80687AC(void); -OpenedFile *GetSpriteData(s16 species); +OpenedFile *GetSpriteData(s32 _species); void LoadPokemonSprite(s16 id, bool32); -#endif // GUARD_CODE_805D8C8_H \ No newline at end of file +#endif // GUARD_CODE_805D8C8_H diff --git a/src/code_80450F8.c b/src/code_80450F8.c index 4ef646b6..b11aead9 100644 --- a/src/code_80450F8.c +++ b/src/code_80450F8.c @@ -6,49 +6,51 @@ #include "dungeon_range.h" #include "dungeon_util.h" #include "tile_types.h" +#include "pokemon.h" +#include "code_805D8C8.h" -// Related to sub_80828E0 -// 93.08% https://decomp.me/scratch/AYGBN -/*Entity *sub_80453AC(s16 id) +extern u8 gUnknown_202EE70[MAX_TEAM_BODY_SIZE]; +extern u8 gUnknown_202EE76[DUNGEON_MAX_WILD_POKEMON_BODY_SIZE]; +extern void sub_8045ACC(void); +extern s32 GetMonsterApparentID(Entity *pokemon, s32 id); + +Entity *sub_80453AC(s32 _species) { - s32 something; // r1 - s32 uVar8; // r2 - Entity *entity; // r4 - s32 r5; - u8 bodySize; // r6 - s32 id_; // r8 - //register s32 id_ asm("r8"); // r8 - s32 r9; - - id_ = id; // SpeciesId() ? - r9 = -1; - bodySize = GetBodySize(id_); - - for (r5 = 0; r5 <= MAX_TEAM_BODY_SIZE - bodySize; r5++) { - for (uVar8 = 0; uVar8 < bodySize; uVar8++) { - if (gUnknown_202EE70[r5 + uVar8] != 0) + s32 i; + s32 species = (s16) _species; + s32 validId = -1; + s32 bodySize = GetBodySize(species); + + for (i = 0; i <= MAX_TEAM_BODY_SIZE - bodySize; i++) { + s32 j; + for (j = 0; j < bodySize; j++) { + if (gUnknown_202EE70[i + j] != 0) break; } - if (uVar8 == bodySize) { - r9 = r5; + if (j == bodySize) { + validId = i; break; } } - if (r9 != -1) { - for (r5 = 0; r5 < MAX_TEAM_MEMBERS; r5++) { - entity = gDungeon->teamPokemon[r5]; + if (validId != -1) { + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + s32 apparentId; + s32 j; + Entity *entity = gDungeon->teamPokemon[i]; + if (!EntityExists(entity)) { entity->type = ENTITY_MONSTER; - entity->unk24 = r5; - entity->axObj.info = &gDungeon->unk69C[r5]; - entity->axObj.info->id = id_; - entity->axObj.info->apparentID = sub_8069F54(NULL, id_); - entity->axObj.info->isNotTeamMember = FALSE; - - entity->axObj.spriteFile = GetSpriteData(sub_8069F54(NULL, id_)); - entity->axObj.unk40_maybeAnimTimer = (r9 * 0x10) + 0x40; + entity->unk24 = i; + entity->axObj.info.monster = &gDungeon->unk69C[i]; + entity->axObj.info.monster->id = species; + apparentId = (s16) GetMonsterApparentID(NULL, species); + entity->axObj.info.monster->apparentID = apparentId; + entity->axObj.info.monster->isNotTeamMember = FALSE; + + entity->axObj.spriteFile = GetSpriteData((s16)GetMonsterApparentID(NULL, species)); + entity->axObj.unk40_maybeAnimTimer = (validId * 16) + 0x40; entity->axObj.unk42_animId1 = 7; entity->axObj.unk44_direction1 = 0; entity->axObj.unk43_animId2 = 0xFF; @@ -57,250 +59,59 @@ entity->unk1C = 0; sub_8045ACC(); - entity->axObj.info->unk167 = r9; - entity->axObj.info->unk168 = bodySize; + entity->axObj.info.monster->unk167 = validId; + entity->axObj.info.monster->unk168 = bodySize; - for (something = 0; something < bodySize; something++) { - gUnknown_202EE70[r9] = 1; - r9++; + for (j = 0; j < bodySize; j++) { + gUnknown_202EE70[validId] = 1; + validId++; } - entity->spawnGenID = gDungeon->unk668++; + entity->spawnGenID = gDungeon->unk644.unk24++; return entity; } } } return NULL; -}*/ -NAKED -Entity *sub_80453AC(s16 id) -{ - asm_unified( -" push {r4-r7,lr}\n" -" mov r7, r10\n" -" mov r6, r9\n" -" mov r5, r8\n" -" push {r5-r7}\n" -" lsls r0, 16\n" -" asrs r0, 16\n" -" mov r8, r0\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" mov r9, r0\n" -" mov r0, r8\n" -" bl GetBodySize\n" -" lsls r0, 24\n" -" lsrs r6, r0, 24\n" -" movs r5, 0\n" -" movs r0, 0x6\n" -" subs r3, r0, r6\n" -" ldr r4, _080453D8\n" -" b _080453DE\n" -" .align 2, 0\n" -"_080453D8: .4byte gUnknown_202EE70\n" -"_080453DC:\n" -" adds r5, 0x1\n" -"_080453DE:\n" -" cmp r5, r3\n" -" bgt _08045400\n" -" movs r2, 0\n" -" cmp r2, r6\n" -" bge _080453FA\n" -" adds r1, r5, r4\n" -" b _080453F4\n" -"_080453EC:\n" -" adds r1, 0x1\n" -" adds r2, 0x1\n" -" cmp r2, r6\n" -" bge _080453FA\n" -"_080453F4:\n" -" ldrb r0, [r1]\n" -" cmp r0, 0\n" -" beq _080453EC\n" -"_080453FA:\n" -" cmp r2, r6\n" -" bne _080453DC\n" -" mov r9, r5\n" -"_08045400:\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" cmp r9, r0\n" -" beq _080454FC\n" -" movs r5, 0\n" -" ldr r7, _080454DC\n" -"_0804540C:\n" -" ldr r1, _080454E0\n" -" ldr r0, [r1]\n" -" lsls r1, r5, 2\n" -" ldr r2, _080454E4\n" -" adds r0, r2\n" -" adds r0, r1\n" -" ldr r4, [r0]\n" -" adds r0, r4, 0\n" -" bl EntityExists\n" -" lsls r0, 24\n" -" lsrs r0, 24\n" -" mov r10, r0\n" -" cmp r0, 0\n" -" bne _080454F0\n" -" movs r0, 0x1\n" -" str r0, [r4]\n" -" adds r0, r4, 0\n" -" adds r0, 0x24\n" -" strb r5, [r0]\n" -" ldr r1, _080454E0\n" -" ldr r0, [r1]\n" -" adds r0, r7\n" -" str r0, [r4, 0x70]\n" -" mov r2, r8\n" -" strh r2, [r0, 0x2]\n" -" movs r0, 0\n" -" mov r1, r8\n" -" bl GetMonsterApparentID\n" -" ldr r1, [r4, 0x70]\n" -" strh r0, [r1, 0x4]\n" -" ldr r0, [r4, 0x70]\n" -" movs r5, 0\n" -" strb r5, [r0, 0x6]\n" -" movs r0, 0\n" -" mov r1, r8\n" -" bl GetMonsterApparentID\n" -" lsls r0, 16\n" -" asrs r0, 16\n" -" bl GetSpriteData\n" -" str r0, [r4, 0x64]\n" -" mov r1, r9\n" -" lsls r0, r1, 4\n" -" adds r0, 0x40\n" -" adds r1, r4, 0\n" -" adds r1, 0x68\n" -" strh r0, [r1]\n" -" adds r1, 0x2\n" -" movs r0, 0x7\n" -" strb r0, [r1]\n" -" adds r0, r4, 0\n" -" adds r0, 0x6C\n" -" movs r2, 0\n" -" strb r2, [r0]\n" -" adds r1, 0x1\n" -" movs r0, 0xFF\n" -" strb r0, [r1]\n" -" adds r0, r4, 0\n" -" adds r0, 0x6D\n" -" movs r5, 0x1\n" -" strb r5, [r0]\n" -" adds r0, 0x2\n" -" strb r5, [r0]\n" -" mov r0, r10\n" -" str r0, [r4, 0x1C]\n" -" bl sub_8045ACC\n" -" ldr r0, [r4, 0x70]\n" -" ldr r1, _080454E8\n" -" adds r0, r1\n" -" mov r2, r9\n" -" strb r2, [r0]\n" -" ldr r0, [r4, 0x70]\n" -" movs r5, 0xB4\n" -" lsls r5, 1\n" -" adds r0, r5\n" -" strb r6, [r0]\n" -" cmp r6, 0\n" -" beq _080454C6\n" -" ldr r3, _080454EC\n" -" movs r2, 0x1\n" -" adds r1, r6, 0\n" -"_080454B6:\n" -" mov r5, r9\n" -" adds r0, r5, r3\n" -" strb r2, [r0]\n" -" movs r0, 0x1\n" -" add r9, r0\n" -" subs r1, 0x1\n" -" cmp r1, 0\n" -" bne _080454B6\n" -"_080454C6:\n" -" ldr r1, _080454E0\n" -" ldr r0, [r1]\n" -" movs r2, 0xCD\n" -" lsls r2, 3\n" -" adds r0, r2\n" -" ldrh r2, [r0]\n" -" adds r1, r2, 0x1\n" -" strh r1, [r0]\n" -" strh r2, [r4, 0x26]\n" -" adds r0, r4, 0\n" -" b _080454FE\n" -" .align 2, 0\n" -"_080454DC: .4byte 0x0000069c\n" -"_080454E0: .4byte gDungeon\n" -"_080454E4: .4byte 0x0001357c\n" -"_080454E8: .4byte 0x00000167\n" -"_080454EC: .4byte gUnknown_202EE70\n" -"_080454F0:\n" -" movs r0, 0x82\n" -" lsls r0, 2\n" -" adds r7, r0\n" -" adds r5, 0x1\n" -" cmp r5, 0x3\n" -" ble _0804540C\n" -"_080454FC:\n" -" movs r0, 0\n" -"_080454FE:\n" -" pop {r3-r5}\n" -" mov r8, r3\n" -" mov r9, r4\n" -" mov r10, r5\n" -" pop {r4-r7}\n" -" pop {r1}\n" -" bx r1" -); } -// Related to sub_8082A08 -// 91.51% https://decomp.me/scratch/Fp0Kw -/*Entity *sub_804550C(s16 a) +Entity *sub_804550C(s32 _species) { - s32 something; // r1 - s32 uVar8; // r2 - Entity *entity; // r4 - s32 r5; - u8 r6; - s32 id; // r8 - s32 r9; - s32 timer; // sp0 - - id = a; // SpeciesId() ? - r9 = -1; - r6 = GetBodySize(id); - - for (r5 = 0; r5 <= DUNGEON_MAX_WILD_POKEMON_BODY_SIZE - r6; r5++) { - for (uVar8 = 0; uVar8 < r6; uVar8++) { - if (gUnknown_202EE76[r5 + uVar8] != 0) + s32 i; + s32 species = (s16) _species; + s32 validId = -1; + s32 bodySize = GetBodySize(species); + + for (i = 0; i <= DUNGEON_MAX_WILD_POKEMON_BODY_SIZE - bodySize; i++) { + s32 j; + for (j = 0; j < bodySize; j++) { + if (gUnknown_202EE76[i + j] != 0) break; } - if (uVar8 == r6) { - r9 = r5; + if (j == bodySize) { + validId = i; break; } } - if (r9 != -1) { - for (r5 = 0; r5 < DUNGEON_MAX_WILD_POKEMON_BODY_SIZE; r5++) { - timer = (r9 * 0x10) + 0xA0; - entity = gDungeon->wildPokemon[r5]; + if (validId != -1) { + for (i = 0; i < DUNGEON_MAX_WILD_POKEMON_BODY_SIZE; i++) { + s32 j; + Entity *entity = gDungeon->wildPokemon[i]; + if (!EntityExists(entity)) { entity->type = ENTITY_MONSTER; - entity->unk24 = r5; + entity->unk24 = i; entity->unk22 = 0; - entity->axObj.info = &gDungeon->unkEBC[r5]; - entity->axObj.info->id = id; - entity->axObj.info->apparentID = sub_8069F54(NULL, id); - entity->axObj.info->isNotTeamMember = TRUE; + entity->axObj.info.monster = &gDungeon->unkEBC[i]; + entity->axObj.info.monster->id = species; + entity->axObj.info.monster->apparentID = GetMonsterApparentID(NULL, species); + entity->axObj.info.monster->isNotTeamMember = TRUE; - entity->axObj.spriteFile = GetSpriteData(sub_8069F54(NULL, id)); - entity->axObj.unk40_maybeAnimTimer = timer; + entity->axObj.spriteFile = GetSpriteData((s16)GetMonsterApparentID(NULL, species)); + entity->axObj.unk40_maybeAnimTimer = ((validId + 6) * 16) + 0x40; entity->axObj.unk42_animId1 = 7; entity->axObj.unk44_direction1 = 0; entity->axObj.unk43_animId2 = 0xFF; @@ -309,219 +120,23 @@ Entity *sub_80453AC(s16 id) entity->unk1C = 0; - entity->axObj.info->unk167 = r9; - entity->axObj.info->unk168 = r6; + entity->axObj.info.monster->unk167 = validId; + entity->axObj.info.monster->unk168 = bodySize; - for (something = 0; something < r6; something++) { - gUnknown_202EE76[r9] = 1; - r9++; + for (j = 0; j < bodySize; j++) { + gUnknown_202EE76[validId] = 1; + validId++; } sub_8045ACC(); - entity->spawnGenID = gDungeon->unk668++; + entity->spawnGenID = gDungeon->unk644.unk24++; return entity; } } } return NULL; -}*/ -NAKED -Entity *sub_804550C(s16 a) -{ - asm_unified( -" push {r4-r7,lr}\n" -" mov r7, r10\n" -" mov r6, r9\n" -" mov r5, r8\n" -" push {r5-r7}\n" -" sub sp, 0x8\n" -" lsls r0, 16\n" -" asrs r0, 16\n" -" mov r8, r0\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" mov r9, r0\n" -" mov r0, r8\n" -" bl GetBodySize\n" -" lsls r0, 24\n" -" lsrs r7, r0, 24\n" -" movs r5, 0\n" -" movs r0, 0x10\n" -" subs r3, r0, r7\n" -" ldr r4, _08045538\n" -" b _0804553E\n" -" .align 2, 0\n" -"_08045538: .4byte gUnknown_202EE76\n" -"_0804553C:\n" -" adds r5, 0x1\n" -"_0804553E:\n" -" cmp r5, r3\n" -" bgt _08045560\n" -" movs r2, 0\n" -" cmp r2, r7\n" -" bge _0804555A\n" -" adds r1, r5, r4\n" -" b _08045554\n" -"_0804554C:\n" -" adds r1, 0x1\n" -" adds r2, 0x1\n" -" cmp r2, r7\n" -" bge _0804555A\n" -"_08045554:\n" -" ldrb r0, [r1]\n" -" cmp r0, 0\n" -" beq _0804554C\n" -"_0804555A:\n" -" cmp r2, r7\n" -" bne _0804553C\n" -" mov r9, r5\n" -"_08045560:\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" cmp r9, r0\n" -" bne _0804556A\n" -" b _08045670\n" -"_0804556A:\n" -" movs r5, 0\n" -" movs r1, 0x1\n" -" mov r10, r1\n" -" ldr r2, _08045650\n" -" mov r3, r9\n" -" lsls r0, r3, 4\n" -" adds r0, 0xA0\n" -" str r0, [sp]\n" -"_0804557A:\n" -" ldr r1, _08045654\n" -" ldr r0, [r1]\n" -" lsls r1, r5, 2\n" -" ldr r3, _08045658\n" -" adds r0, r3\n" -" adds r0, r1\n" -" ldr r4, [r0]\n" -" adds r0, r4, 0\n" -" str r2, [sp, 0x4]\n" -" bl EntityExists\n" -" lsls r0, 24\n" -" lsrs r6, r0, 24\n" -" ldr r2, [sp, 0x4]\n" -" cmp r6, 0\n" -" bne _08045664\n" -" mov r0, r10\n" -" str r0, [r4]\n" -" adds r0, r4, 0\n" -" adds r0, 0x24\n" -" strb r5, [r0]\n" -" subs r0, 0x2\n" -" strb r6, [r0]\n" -" ldr r1, _08045654\n" -" ldr r0, [r1]\n" -" adds r0, r2\n" -" str r0, [r4, 0x70]\n" -" mov r2, r8\n" -" strh r2, [r0, 0x2]\n" -" movs r0, 0\n" -" mov r1, r8\n" -" bl GetMonsterApparentID\n" -" ldr r1, [r4, 0x70]\n" -" strh r0, [r1, 0x4]\n" -" ldr r0, [r4, 0x70]\n" -" mov r3, r10\n" -" strb r3, [r0, 0x6]\n" -" movs r0, 0\n" -" mov r1, r8\n" -" bl GetMonsterApparentID\n" -" lsls r0, 16\n" -" asrs r0, 16\n" -" bl GetSpriteData\n" -" str r0, [r4, 0x64]\n" -" adds r0, r4, 0\n" -" adds r0, 0x68\n" -" mov r5, sp\n" -" ldrh r5, [r5]\n" -" strh r5, [r0]\n" -" adds r1, r4, 0\n" -" adds r1, 0x6A\n" -" movs r0, 0x7\n" -" strb r0, [r1]\n" -" adds r0, r4, 0\n" -" adds r0, 0x6C\n" -" movs r1, 0\n" -" strb r1, [r0]\n" -" adds r1, r4, 0\n" -" adds r1, 0x6B\n" -" movs r0, 0xFF\n" -" strb r0, [r1]\n" -" adds r0, r4, 0\n" -" adds r0, 0x6D\n" -" mov r2, r10\n" -" strb r2, [r0]\n" -" adds r0, 0x2\n" -" strb r2, [r0]\n" -" str r6, [r4, 0x1C]\n" -" ldr r0, [r4, 0x70]\n" -" ldr r3, _0804565C\n" -" adds r0, r3\n" -" mov r5, r9\n" -" strb r5, [r0]\n" -" ldr r0, [r4, 0x70]\n" -" movs r1, 0xB4\n" -" lsls r1, 1\n" -" adds r0, r1\n" -" strb r7, [r0]\n" -" cmp r7, 0\n" -" beq _08045636\n" -" ldr r3, _08045660\n" -" movs r2, 0x1\n" -" adds r1, r7, 0\n" -"_08045626:\n" -" mov r5, r9\n" -" adds r0, r5, r3\n" -" strb r2, [r0]\n" -" movs r0, 0x1\n" -" add r9, r0\n" -" subs r1, 0x1\n" -" cmp r1, 0\n" -" bne _08045626\n" -"_08045636:\n" -" bl sub_8045ACC\n" -" ldr r1, _08045654\n" -" ldr r0, [r1]\n" -" movs r2, 0xCD\n" -" lsls r2, 3\n" -" adds r0, r2\n" -" ldrh r2, [r0]\n" -" adds r1, r2, 0x1\n" -" strh r1, [r0]\n" -" strh r2, [r4, 0x26]\n" -" adds r0, r4, 0\n" -" b _08045672\n" -" .align 2, 0\n" -"_08045650: .4byte 0x00000ebc\n" -"_08045654: .4byte gDungeon\n" -"_08045658: .4byte 0x0001358c\n" -"_0804565C: .4byte 0x00000167\n" -"_08045660: .4byte gUnknown_202EE76\n" -"_08045664:\n" -" movs r3, 0x82\n" -" lsls r3, 2\n" -" adds r2, r3\n" -" adds r5, 0x1\n" -" cmp r5, 0xF\n" -" ble _0804557A\n" -"_08045670:\n" -" movs r0, 0\n" -"_08045672:\n" -" add sp, 0x8\n" -" pop {r3-r5}\n" -" mov r8, r3\n" -" mov r9, r4\n" -" mov r10, r5\n" -" pop {r4-r7}\n" -" pop {r1}\n" -" bx r1" -); } Entity *SpawnTrap(u8 trapID, DungeonPos *pos, u8 c) @@ -673,4 +288,4 @@ bool8 sub_8045888(Entity *ent) } return FALSE; -} \ No newline at end of file +} diff --git a/src/code_805D8C8.c b/src/code_805D8C8.c index 07e0a684..b8fa96fe 100644 --- a/src/code_805D8C8.c +++ b/src/code_805D8C8.c @@ -34,10 +34,10 @@ void sub_80687AC(void) gDungeon->unk37F4 = 10; } -OpenedFile *GetSpriteData(s16 species) +OpenedFile *GetSpriteData(s32 _species) { - s32 species32 = SpeciesId(species); - return gDungeon->sprites[species32]; + s32 species = (s16)(_species); + return gDungeon->sprites[species]; } static void EnsureSpriteLoaded(s32 _id) // TODO: Should this param be s16? If so, the castform part of LoadPokemonSprite is preventing us @@ -106,4 +106,4 @@ void CloseAllSpriteFiles(void) gDungeon->sprites[i] = NULL; } } -} \ No newline at end of file +} diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index 24e484b2..4c3267ac 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -151,8 +151,9 @@ void TriggerWeatherAbilities(void) } } -s32 GetMonsterApparentID(Entity *pokemon, s16 id) +s32 GetMonsterApparentID(Entity *pokemon, s32 _id) { + s16 id = (s16)(_id); if (id == MONSTER_CASTFORM || IS_CASTFORM_FORM_MONSTER(id)) { if (HasAbility(pokemon, ABILITY_FORECAST)) return gUnknown_80F520C[GetApparentWeather(pokemon)].unk2; From a6e687d595b4c2223aefdbda6ad798f8ee5a04b7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 28 Nov 2024 14:45:55 +0100 Subject: [PATCH 2/2] sub_8082A08 --- src/dungeon_serializer.c | 60 ++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 480280a9..59dbcdca 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -131,7 +131,7 @@ static void WriteCurseClassStatus(DataSerializer *seri, CurseClassStatus *src); static void WriteWeather(DataSerializer *seri, Weather *src); static Entity* sub_80828E0(s16 id, s16 apparentID, s32 index); -static Entity* sub_8082A08(s16 id, s16 apparentID, s32 index); +static Entity* sub_8082A08(s32 id, s32 apparentID, s32 index); // These externs are from other files extern void sub_80460F8(DungeonPos *, Item *, u32); @@ -1172,41 +1172,29 @@ static Entity* sub_80828E0(s16 id, s16 apparentID, s32 index) } // Related to sub_804550C -// Fakematch with registers. See https://decomp.me/scratch/KpZyK -static Entity* sub_8082A08(s16 id, s16 apparentID, s32 index) +Entity* sub_8082A08(s32 _species, s32 _apparentSpecies, s32 index) { - s32 r1; - s32 r2; - s32 r3; - u8 apparentBodySize; // r6 - Entity *entity; // r7 - #ifdef NONMATCHING - s32 r8; - s32 appID; // r9 - #else - register s32 r8 asm("r8"); - register s32 appID asm("r9"); // r9 - #endif - s32 id_; // sp - - id_ = id; // SpeciesId() ? - appID = apparentID; // SpeciesId() ? - r8 = -1; - apparentBodySize = GetBodySize(appID); - - for (r3 = 0; r3 <= DUNGEON_MAX_WILD_POKEMON_BODY_SIZE - apparentBodySize; r3++) { - for (r2 = 0; r2 < apparentBodySize; r2++) { - if (gUnknown_202EE76[r3 + r2] != 0) + s32 i, j; + Entity *entity; + s32 species = (s16) _species; + s32 apparentSpecies = (s16) _apparentSpecies; + s32 validId = -1; + s32 apparentBodySize = GetBodySize((s16)apparentSpecies); + + for (i = 0; i <= DUNGEON_MAX_WILD_POKEMON_BODY_SIZE - apparentBodySize; i++) { + s32 j; + for (j = 0; j < apparentBodySize; j++) { + if (gUnknown_202EE76[i + j] != 0) break; } - if (r2 == apparentBodySize) { - r8 = r3; + if (j == apparentBodySize) { + validId = i; break; } } - if (r8 == -1) + if (validId == -1) return NULL; entity = gDungeon->wildPokemon[index]; @@ -1214,12 +1202,12 @@ static Entity* sub_8082A08(s16 id, s16 apparentID, s32 index) entity->unk24 = index; entity->unk22 = 0; entity->axObj.info.monster = &gDungeon->unkEBC[index]; - entity->axObj.info.monster->id = id_; - entity->axObj.info.monster->apparentID = appID; + entity->axObj.info.monster->id = species; + entity->axObj.info.monster->apparentID = apparentSpecies; entity->axObj.info.monster->isNotTeamMember = TRUE; - entity->axObj.spriteFile = GetSpriteData(appID); - entity->axObj.unk40_maybeAnimTimer = (r8 * 0x10) + 0xA0; + entity->axObj.spriteFile = GetSpriteData(apparentSpecies); + entity->axObj.unk40_maybeAnimTimer = ((validId + 6) * 16) + 0x40; entity->axObj.unk42_animId1 = 7; entity->axObj.unk44_direction1 = 0; entity->axObj.unk43_animId2 = 0xFF; @@ -1227,12 +1215,12 @@ static Entity* sub_8082A08(s16 id, s16 apparentID, s32 index) entity->axObj.unk47 = 1; entity->unk1C = 0; - entity->axObj.info.monster->unk167 = r8; + entity->axObj.info.monster->unk167 = validId; entity->axObj.info.monster->unk168 = apparentBodySize; - for (r1 = 0; r1 < apparentBodySize; r1++) { - gUnknown_202EE76[r8] = 1; - r8++; + for (j = 0; j < apparentBodySize; j++) { + gUnknown_202EE76[validId] = 1; + validId++; } sub_8045ACC();