Skip to content

Commit

Permalink
Merge pull request #247 from DizzyEggg/nonmatchings
Browse files Browse the repository at this point in the history
Match some register nonmatchings
  • Loading branch information
AnonymousRandomPerson authored Nov 1, 2024
2 parents a169714 + 9d0ce06 commit d93a8b6
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 124 deletions.
5 changes: 2 additions & 3 deletions include/code_80972F4.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ typedef struct MissionText
} MissionText;

const u8 *GetCurrentMissionText(s16 index);
// TODO: this should probably be bool8 but can't get a match just yet
bool32 IsMazeCompleted(s16 mazeIndex);
bool8 IsMazeCompleted(s16 mazeIndex);

bool8 sub_8096F50(WonderMail *mail);
void sub_8097418(s16 index, bool32);
bool8 sub_8097504(s16 mazeIndex);
const u8 *sub_80975DC(u32);
const u8 *sub_80975DC(s16);

// These two are definitely bool8 but can't get them to match with it yet
//bool8 sub_8097384(s16);
Expand Down
7 changes: 6 additions & 1 deletion include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ static inline bool8 PokemonFlag1(PokemonStruct1 *mon)

static inline bool8 PokemonFlag2(PokemonStruct1 *mon)
{
return (((mon->unk0 >> 1) & 1));
return (((mon->unk0 >> (FLAG_ON_TEAM - 1)) & 1));
}

static inline void SetPokemonFlag2(PokemonStruct1 *mon)
{
mon->unk0 |= FLAG_ON_TEAM;
}

static inline bool8 IsMonTeamLeader(PokemonStruct1 *pokemon)
Expand Down
5 changes: 1 addition & 4 deletions src/code_8073CF0.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,7 @@ bool8 UseAttack(Entity *a0)
EntityInfo *monInfo = GetEntInfo(mon);
Unk_Entity_x184 *strPtr = &monInfo->unk184[monInfo->notMoving];

#ifndef NONMATCHING
// Dummy needed to match, feel free to remove if you do not care about matching.
i++;i--;
#endif // NONMATCHING
ASM_MATCH_TRICK(i);
if (monInfo->numMoveTiles != 0) {
IncreaseEntityPixelPos(mon, strPtr->lastMoveIncrement.x, strPtr->lastMoveIncrement.y);
if (--strPtr->walkAnimFramesLeft == 0) {
Expand Down
15 changes: 2 additions & 13 deletions src/code_8094F88.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,10 @@ s32 sub_8095400(u32 param_1)

void sub_809542C(WonderMailSub *param_1)
{
u32 seed;

#ifndef NONMATCHING
register unkStruct_203B480 *preload asm("r2");
#else
unkStruct_203B480 *preload;
#endif

u8 buffer [20];
u8 buffer[20];

gUnknown_203B480->mailType = 1;
preload = gUnknown_203B480;
seed = param_1->seed;
preload->unk4.dungeon = param_1->dungeon;
preload->unk4.seed = seed;
gUnknown_203B480->unk4 = *param_1;
sub_8094D28(Rand32Bit());
gUnknown_203B480->unk10.unk10 = sub_8094E4C();
gUnknown_203B480->clientSpecies = GetPlayerPokemonStruct()->speciesNum;
Expand Down
46 changes: 17 additions & 29 deletions src/code_8097504.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@
#include "dungeon.h"
#include "event_flag.h"
#include "code_80A26CC.h"
#include "code_80972F4.h"

ALIGNED(4) const char gMeetNinetalesText[] = "Meet Ninetales.";
ALIGNED(4) const char gAvoidCaptureText[] = "Avoid capture.";
ALIGNED(4) const char gFinalScenarioText[] = _("Defeat the final Pokémon.");

// Needed to match
static inline s16 Self(s16 a)
{
return a;
}

bool8 sub_8097504(s16 mazeIndex)
{
s32 mazeIndex_s32;

#ifndef NONMATCHING
register s32 mazeIndex_s32_1 asm("r1");
#else
s32 mazeIndex_s32_1;
#endif
s32 uVar3;

mazeIndex_s32 = mazeIndex;
mazeIndex_s32_1 = mazeIndex_s32;

if(mazeIndex_s32 < 17)
s32 mazeIndex_ = Self(mazeIndex);
if(mazeIndex < 17)
{
switch(mazeIndex_s32) {
switch(mazeIndex) {
case 2:
case 10:
case 11:
Expand Down Expand Up @@ -55,9 +51,9 @@ bool8 sub_8097504(s16 mazeIndex)
}
else
{
if (mazeIndex_s32_1 > 22) return FALSE;
if (mazeIndex_s32_1 == 22) return FALSE;
if (mazeIndex_s32_1 == 21) return FALSE;
if (mazeIndex_ > 22) return FALSE;
if (mazeIndex_ == 22) return FALSE;
if (mazeIndex_ == 21) return FALSE;
uVar3 = 6;
}

Expand All @@ -69,16 +65,9 @@ bool8 sub_8097504(s16 mazeIndex)
}
}

// TODO: this should probably be bool8 but can't get a match just yet
bool32 IsMazeCompleted(s16 mazeIndex)
bool8 IsMazeCompleted(s16 mazeIndex)
{
bool32 mazeCompletion;

mazeCompletion = GetScriptVarArrayValue(NULL, TRAINING_CONQUEST_LIST, mazeIndex);
if (mazeCompletion) {
mazeCompletion = TRUE;
}
return mazeCompletion;
return (GetScriptVarArrayValue(NULL, TRAINING_CONQUEST_LIST, mazeIndex) != 0);
}

void sub_80975A8(s16 param_1,u8 param_2)
Expand All @@ -92,15 +81,14 @@ const u8 *sub_80975C4(s16 index)
return GetDungeonName1(sub_80A2728(index));
}

const u8 *sub_80975DC(u32 r0)
const u8 *sub_80975DC(s16 r0)
{
// TODO: slight hack but matches
r0 <<= 16;
if((0xffe90000 + r0) >> 16 < 2)
if(r0 == 23 || r0 == 24) {
if(ScriptVarScenarioEqual(SCENARIO_MAIN, 0xE, -1))
return gMeetNinetalesText;
else
return gAvoidCaptureText;
}
else
return gFinalScenarioText;
}
Expand Down
18 changes: 7 additions & 11 deletions src/dungeon_ai_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,21 +768,17 @@ bool8 IsAITargetEligible(s32 targetingFlags, Entity *user, Entity *target, Move

s32 WeightMove(Entity *user, s32 targetingFlags, Entity *target, u32 moveType)
{
#ifndef NONMATCHING
register EntityInfo *targetData asm("r4");
#else
EntityInfo *targetData;
#endif
s32 targetingFlags2 = (s16) targetingFlags;
u8 moveType2 = moveType;
u8 weight = 1;
EntityInfo *targetData2;
targetData2 = targetData = GetEntInfo(target);
if (!targetData->isNotTeamMember || (targetingFlags2 & 0xF) != TARGETING_FLAG_TARGET_OTHER)
{
targetData = GetEntInfo(target);
if (!targetData->isNotTeamMember)
return 1;
}
else if (IQSkillIsEnabled(user, IQ_EXP_GO_GETTER))
if ((targetingFlags2 & 0xF) != TARGETING_FLAG_TARGET_OTHER)
return 1;

if (IQSkillIsEnabled(user, IQ_EXP_GO_GETTER))
{
// BUG: expYieldRankings has lower values as the Pokémon's experience yield increases.
// This causes Exp. Go-Getter to prioritize Pokémon worth less experience
Expand All @@ -791,7 +787,7 @@ s32 WeightMove(Entity *user, s32 targetingFlags, Entity *target, u32 moveType)
}
else if (IQSkillIsEnabled(user, IQ_EFFICIENCY_EXPERT))
{
weight = -12 - targetData2->HP;
weight = -12 - targetData->HP;
if (weight == 0)
{
weight = 1;
Expand Down
19 changes: 5 additions & 14 deletions src/friend_area_action_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ void sub_80277FC(void)
void sub_80278B4(void)
{
PokemonStruct1 *playerStruct;
PokemonStruct1 *pokeStruct1;
PokemonStruct1 *pokeStruct2;
PokemonStruct1 *newLeader;
u32 menuAction;

menuAction = 0;
Expand All @@ -427,15 +426,7 @@ void sub_80278B4(void)
switch(menuAction) {
case FRIEND_AREA_ACTION_MENU_ACTION_JOIN_TEAM:
if (sub_808D750(sUnknown_203B2BC->targetPoke)) {
#ifdef NONMATCHING
pokeStruct1 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke];
#else
register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[sUnknown_203B2BC->targetPoke]);
PokemonStruct1* p = gRecruitedPokemonRef->pokemon;
size_t addr = offset + (size_t)p;
pokeStruct1 = (PokemonStruct1*)addr;
#endif
pokeStruct1->unk0 |= FLAG_ON_TEAM;
SetPokemonFlag2(&gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke]);
nullsub_104();
}
sub_808ED00();
Expand All @@ -448,11 +439,11 @@ void sub_80278B4(void)
SetFriendAreaActionMenuState(FRIEND_AREA_ACTION_MENU_MAIN_2);
break;
case FRIEND_AREA_ACTION_MENU_ACTION_MAKE_LEADER:
pokeStruct2 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke];
newLeader = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke];
playerStruct = GetPlayerPokemonStruct();
if (!pokeStruct2->isTeamLeader) {
if (!newLeader->isTeamLeader) {
playerStruct->isTeamLeader = FALSE;
pokeStruct2->isTeamLeader = TRUE;
newLeader->isTeamLeader = TRUE;
nullsub_104();
}
sub_808ED00();
Expand Down
8 changes: 1 addition & 7 deletions src/iq_skill_list_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ static void sub_801C440(void);

bool8 CreateIQSkillListMenu(s16 species, u32 index, u32 a2)
{
#ifndef NONMATCHING
register s32 species_s32 asm("r4");
#else
s32 species_s32;
#endif

species_s32 = species;
s32 species_s32 = SpeciesId(species);

if (HasNoAvailIQSkills(species))
return FALSE;
Expand Down
4 changes: 1 addition & 3 deletions src/moves.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,7 @@ s32 sub_80935B8(Move *moves, s32 index)
}

// this is so stupid but it works
#ifndef NONMATCHING
isNonTrivialLinkSequence++; isNonTrivialLinkSequence--;
#endif
ASM_MATCH_TRICK(isNonTrivialLinkSequence);

for (i = linkSequenceStart + 1; i < MAX_MON_MOVES; i++) {
Move *move = &moves[i];
Expand Down
21 changes: 5 additions & 16 deletions src/party_list_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,7 @@ void PartyListMenu_BuildYesNoMenu(void) {
void PartyListMenu_HandleMenu1(void)
{
PokemonStruct1 *playerPokemon;
PokemonStruct1 *pokeStruct;
PokemonStruct1 *pokeStruct2;
PokemonStruct1 *newLeader;
s32 choice;

choice = 0;
Expand All @@ -469,17 +468,7 @@ void PartyListMenu_HandleMenu1(void)
switch(choice) {
case PARTY_LIST_MENU_JOIN_TEAM:
if (sub_808D750(sUnknown_203B2B8->pokeSpecies)) {

#ifdef NONMATCHING
pokeStruct = &sUnknown_203B2B8->pokeSpecies[gRecruitedPokemonRef->pokemon];
#else
register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[sUnknown_203B2B8->pokeSpecies]);
PokemonStruct1* p = gRecruitedPokemonRef->pokemon;
size_t addr = offset + (size_t)p;
pokeStruct = (PokemonStruct1*)addr;
#endif

pokeStruct->unk0 |= FLAG_ON_TEAM;
SetPokemonFlag2(&sUnknown_203B2B8->pokeSpecies[gRecruitedPokemonRef->pokemon]);
nullsub_104();
}
sub_808ED00();
Expand All @@ -492,12 +481,12 @@ void PartyListMenu_HandleMenu1(void)
SetPartyListMenuState(PARTY_LIST_STATE_STANDBY);
break;
case PARTY_LIST_MENU_MAKE_LEADER:
pokeStruct2 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2B8->pokeSpecies];
newLeader = &gRecruitedPokemonRef->pokemon[sUnknown_203B2B8->pokeSpecies];
playerPokemon = GetPlayerPokemonStruct();

if (!pokeStruct2->isTeamLeader) {
if (!newLeader->isTeamLeader) {
playerPokemon->isTeamLeader = FALSE;
pokeStruct2->isTeamLeader = TRUE;
newLeader->isTeamLeader = TRUE;
nullsub_104();
}
sub_808ED00();
Expand Down
36 changes: 13 additions & 23 deletions src/pokemon_mid.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,41 +679,31 @@ void GetPokemonLevelData(LevelData* a1, s16 _id, s32 level)
*a1 = gLevelCurrentData[level];
}

const u8* DecompressMoveID(const u8* a1, u16* moveID)
const u8* DecompressMoveID(const u8* src, u16* moveID)
{
u32 r1 = *a1++;
u32 r3;
if (r1 & 0x80) {
r3 = *a1++;
u32 byte0;
u32 byte1 = *src++;
// If move >= 127 which means it uses 2 bytes and not one
if (byte1 & 0x80) {
byte0 = *src++;
}
else {
r3 = r1;
r1 = 0;
byte0 = byte1;
byte1 = 0;
}
#ifdef NONMATCHING
// wrong order
r1 &= 0x7f;
r3 &= 0x7f;
*moveID = (r1 << 7) | r3;
#else
{
register u32 mask asm("r0") = 0x7f;
r3 &= mask;
r1 &= mask;
*moveID = (r1 << 7) | r3;
}
#endif
return a1;

*moveID = (byte0 & 0x7F) | ((byte1 & 0x7F) << 7);
return src;
}

s32 sub_808E0AC(u16* a1, s16 species, s32 a3, s32 IQPoints)
{
const u8* stream;
u16 moveID; // moveID
s32 count;
register s32 _species asm("r2"); // weird regalloc
s32 _species;

_species = (s16)species;
_species = SpeciesId(species);
count = 0;

if (species == MONSTER_DECOY) return 0;
Expand Down

0 comments on commit d93a8b6

Please sign in to comment.