Skip to content

Commit

Permalink
Merge pull request #302 from DizzyEggg/pokemon_nmtchs
Browse files Browse the repository at this point in the history
Match GetUnitSum_808D544 sub_808E400
  • Loading branch information
SethBarberee authored Dec 19, 2024
2 parents 7b2a96f + 09211e1 commit 288cc11
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 71 deletions.
2 changes: 1 addition & 1 deletion include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ u8 GetFriendArea(s32 index);
s32 GetBaseHP(s32 index);
bool8 MonsterIDCanThrowItems(s16 index);
u8 GetUnk12(s16 index);
s16 GetPokemonEvolveFrom(s16 index);
s32 GetPokemonEvolveFrom(s32 index);
s32 GetBaseOffensiveStat(s32 index, u32 r1);
s32 GetBaseDefensiveStat(s32 index, u32 r1);
u8 GetPokemonType(s32 index, u32 typeIndex);
Expand Down
90 changes: 22 additions & 68 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,66 +479,23 @@ bool8 sub_808D500(void)
return flag;
}

#ifdef NONMATCHING
s32 GetUnitSum_808D544(s32 *team)
{
int *ptr;
int index;
s32 count;
PokemonStruct1 *pokemon;
s32 count, i;
PokemonStruct1 *mon = gRecruitedPokemonRef->pokemon;

pokemon = gRecruitedPokemonRef->pokemon;
count = 0;
for(index = 0, ptr = team; index < NUM_MONSTERS; index++, pokemon++)
{
if ((PokemonFlag2(pokemon))) {
if (team != 0) *ptr = index;
ptr++;
count++;
count = 0;
for (i = 0; i < NUM_MONSTERS; i++, mon++) {
if (PokemonFlag2(mon)) {
if (team != NULL) {
team[count] = i;
}
count++;
}
}
}
return count;
}
#else
NAKED
s32 GetUnitSum_808D544(s32 *team)
{
asm_unified(
"\tpush {r4-r7,lr}\n"
"\tadds r4, r0, 0\n"
"\tldr r0, _0808D57C\n"
"\tldr r3, [r0]\n"
"\tmovs r5, 0\n"
"\tmovs r2, 0\n"
"\tmovs r7, 0x1\n"
"\tmovs r6, 0xCE\n"
"\tlsls r6, 1\n"
"\tadds r1, r4, 0\n"
"_0808D558:\n"
"\tldrh r0, [r3]\n"
"\tlsrs r0, 1\n"
"\tands r0, r7\n"
"\tcmp r0, 0\n"
"\tbeq _0808D56C\n"
"\tcmp r4, 0\n"
"\tbeq _0808D568\n"
"\tstr r2, [r1]\n"
"_0808D568:\n"
"\tadds r1, 0x4\n"
"\tadds r5, 0x1\n"
"_0808D56C:\n"
"\tadds r2, 0x1\n"
"\tadds r3, 0x58\n"
"\tcmp r2, r6\n"
"\tble _0808D558\n"
"\tadds r0, r5, 0\n"
"\tpop {r4-r7}\n"
"\tpop {r1}\n"
"\tbx r1\n"
"\t.align 2, 0\n"
"_0808D57C: .4byte gRecruitedPokemonRef");

return count;
}
#endif

s32 sub_808D580(s32 *team)
{
Expand Down Expand Up @@ -974,9 +931,10 @@ u8 GetUnk12(s16 index)
return gMonsterParameters[index].unk12;
}

s16 GetPokemonEvolveFrom(s16 index)
s32 GetPokemonEvolveFrom(s32 index)
{
return gMonsterParameters[index].preEvolution.evolveFrom;
s16 index_s16 = index;
return gMonsterParameters[index_s16].preEvolution.evolveFrom;
}

s32 GetBaseOffensiveStat(s32 index, u32 r1)
Expand Down Expand Up @@ -1388,7 +1346,7 @@ s32 GetEvolutionSequence(PokemonStruct1* pokemon, struct EvolveStage* a2)
if (!pokemon->unkC[i].level) {
break;
}
species = GetPokemonEvolveFrom(species);
species = (s16) GetPokemonEvolveFrom(species);
if (!species) {
break;
}
Expand Down Expand Up @@ -1418,7 +1376,7 @@ s32 GetEvolutionSequence(PokemonStruct1* pokemon, struct EvolveStage* a2)
if (!has_next_stage->level) {
break;
}
species = GetPokemonEvolveFrom(species);
species = (s16) GetPokemonEvolveFrom(species);
if (!species) {
break;
}
Expand All @@ -1435,22 +1393,18 @@ s32 GetEvolutionSequence(PokemonStruct1* pokemon, struct EvolveStage* a2)
s32 sub_808E400(s32 _species, s16* _a2, bool32 _bodySizeCheck, bool32 _shedinjaCheck)
{
// This is horrible
s32 species = SpeciesId(_species);
s32 species = (s16) (_species);
bool8 bodySizeCheck = _bodySizeCheck;
bool8 shedinjaCheck = _shedinjaCheck;
s32 count = 0;
s32 i = 1;
s16 *a2 = _a2;

for (i = 1; i < MONSTER_MAX; i++) {
s32 loopSpeciesId = SpeciesId(i);
#ifdef NONMATCHING
s32 loopSpeciesId2 = SpeciesId(i);
#else
register s32 loopSpeciesId2 asm("r8") = SpeciesId(i);
#endif // NONMATCHING

if (species != GetPokemonEvolveFrom(loopSpeciesId)) {
s32 loopSpeciesId = (s16) i;
s32 loopSpeciesId2 = (s16) loopSpeciesId; // Needed to match

if (species != (s16) GetPokemonEvolveFrom(loopSpeciesId)) {
continue;
}
if (!bodySizeCheck && GetBodySize(species) != GetBodySize(loopSpeciesId)) {
Expand Down
4 changes: 2 additions & 2 deletions src/pokemon_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ PokemonStruct1 *sub_808F798(PokemonStruct1 *pokemon, short _species)
u8 buffer [64];
s32 species = _species;
bool32 flag = TRUE;

pokeStruct = *pokemon;
r6 = pokeStruct.speciesNum;
GetPokemonLevelData(&levelData,species,pokeStruct.level);
Expand All @@ -1179,7 +1179,7 @@ PokemonStruct1 *sub_808F798(PokemonStruct1 *pokemon, short _species)
else if (pokeStruct.unkC[1].level == 0) {
pokeStruct.unkC[1].level = pokeStruct.level;
}

CopyStringtoBuffer(buffer, GetMonSpecies(r6));

index = 0;
Expand Down

0 comments on commit 288cc11

Please sign in to comment.