fix some fake/non/weird matches by static inlines

This commit is contained in:
DizzyEggg 2024-10-13 15:32:58 +02:00
parent fda81d1e1c
commit 74c5df2674
7 changed files with 90 additions and 348 deletions

View File

@ -98,4 +98,19 @@ static inline void ZeroOutItem(Item *item)
item->flags = 0;
}
static inline bool8 ItemSticky(Item *item)
{
return (item->flags & ITEM_FLAG_STICKY);
}
static inline bool8 ItemExists(Item *item)
{
return (item->flags & ITEM_FLAG_EXISTS);
}
static inline bool8 ItemInShop(Item *item)
{
return (item->flags & ITEM_FLAG_IN_SHOP);
}
#endif // GUARD_ITEMS_H

View File

@ -240,14 +240,12 @@ void sub_8066BD4(Entity *param_1)
{
Entity *entity;
EntityInfo *info;
EntityInfo *info2; // NOTE: needed two of these to match
Item *item;
Item *heldItem;
Item temp;
entity = sub_8044DA4(param_1,0);
info = entity->info;
info2 = entity->info;
info = GetEntInfo(entity);
heldItem = &info->heldItem;
item = sub_8044D90(param_1,1,0x1565);
if (heldItem->flags & ITEM_FLAG_STICKY)
@ -274,8 +272,8 @@ void sub_8066BD4(Entity *param_1)
if (sub_80706A4(entity,&entity->pos) != 0) {
sub_807D148(param_1,entity,0,0);
}
if (!info2->isTeamLeader) {
info2->flags = info2->flags | MOVEMENT_FLAG_UNK_14;
if (!info->isTeamLeader) {
info->flags = info->flags | MOVEMENT_FLAG_UNK_14;
}
sub_807AB38(param_1,gDungeon->unk3A08);
}

View File

@ -489,21 +489,6 @@ void HandleDealingDamage(Entity *attacker, Entity *target, struct DamageStruct *
}
}
static inline bool8 ItemSticky(Item *item)
{
return (item->flags & ITEM_FLAG_STICKY);
}
static inline bool8 ItemExists(Item *item)
{
return (item->flags & ITEM_FLAG_EXISTS);
}
static inline bool8 ItemInShop(Item *item)
{
return (item->flags & ITEM_FLAG_IN_SHOP);
}
static inline u8 ItemId(Item *item)
{
return item->id;

View File

@ -76,13 +76,7 @@ void sub_8086A54(Entity *pokemon)
void SetupBossFightHP(Entity *pokemon, s32 newHP, u16 songIndex)
{
// NOTE: needed two of these to match.. very dumb
EntityInfo *entityInfo;
EntityInfo *enityData_1;
entityInfo = pokemon->info;
enityData_1 = pokemon->info;
EntityInfo *entityInfo = GetEntInfo(pokemon);
entityInfo->bossFlag = TRUE;
@ -97,7 +91,7 @@ void SetupBossFightHP(Entity *pokemon, s32 newHP, u16 songIndex)
}
gDungeon->bossSongIndex = songIndex;
SetDefaultIQSkills(enityData_1->IQSkillMenuFlags, enityData_1->bossFlag);
SetDefaultIQSkills(entityInfo->IQSkillMenuFlags, entityInfo->bossFlag);
LoadIQSkills(pokemon);
}

View File

@ -92,7 +92,6 @@ u8 sub_8046D70(void)
return 0;
}
#ifdef NONMATCHING
void MusicBoxCreation(void)
{
bool8 musicBoxOnce;
@ -127,28 +126,13 @@ void MusicBoxCreation(void)
if ((indexes[0] >= 0) && (indexes[1] >= 0) && (indexes[2] >= 0)) {
// NOTE: doesn't match here.. tried to register pin but still not perfect
register Item *pbVar4 asm("r1");
register Item *pbVar5 asm("r0");
musicBoxOnce = TRUE;
createMusicBox = TRUE;
// clear out each of the parts
pbVar4 = &gTeamInventoryRef->teamItems[indexes[0]];
pbVar4->id = 0;
pbVar4->quantity = 0;
pbVar4->flags = 0;
pbVar5 = &gTeamInventoryRef->teamItems[indexes[1]];
pbVar5->id = 0;
pbVar5->quantity = 0;
pbVar5->flags = 0;
pbVar5 = &gTeamInventoryRef->teamItems[indexes[2]];
pbVar5->id = 0;
pbVar5->quantity = 0;
pbVar5->flags = 0;
ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[0]]);
ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[1]]);
ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[2]]);
// init the music box
xxx_init_itemslot_8090A8C(&gTeamInventoryRef->teamItems[indexes[0]], ITEM_MUSIC_BOX, 0);
@ -179,180 +163,6 @@ void MusicBoxCreation(void)
sub_8040A84();
}
}
#else
NAKED
void MusicBoxCreation(void)
{
asm_unified(
"\tpush {r4-r7,lr}\n"
"\tsub sp, 0xC\n"
"\tmovs r6, 0\n"
"\tldr r5, _08046EDC\n"
"\tmovs r4, 0\n"
"_08046D96:\n"
"\tmovs r7, 0\n"
"\tmovs r0, 0x1\n"
"\tnegs r0, r0\n"
"\tstr r0, [sp]\n"
"\tstr r0, [sp, 0x4]\n"
"\tstr r0, [sp, 0x8]\n"
"\tmovs r3, 0\n"
"\tldr r2, [r5]\n"
"_08046DA6:\n"
"\tldrb r1, [r2]\n"
"\tmovs r0, 0x1\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbeq _08046DC8\n"
"\tldrb r0, [r2, 0x2]\n"
"\tcmp r0, 0x79\n"
"\tbne _08046DB8\n"
"\tstr r3, [sp]\n"
"_08046DB8:\n"
"\tldrb r0, [r2, 0x2]\n"
"\tcmp r0, 0x77\n"
"\tbne _08046DC0\n"
"\tstr r3, [sp, 0x4]\n"
"_08046DC0:\n"
"\tldrb r0, [r2, 0x2]\n"
"\tcmp r0, 0x78\n"
"\tbne _08046DC8\n"
"\tstr r3, [sp, 0x8]\n"
"_08046DC8:\n"
"\tadds r2, 0x4\n"
"\tadds r3, 0x1\n"
"\tcmp r3, 0x13\n"
"\tble _08046DA6\n"
"\tldr r1, [sp]\n"
"\tcmp r1, 0\n"
"\tblt _08046E1E\n"
"\tldr r0, [sp, 0x4]\n"
"\tcmp r0, 0\n"
"\tblt _08046E1E\n"
"\tldr r0, [sp, 0x8]\n"
"\tcmp r0, 0\n"
"\tblt _08046E1E\n"
"\tmovs r7, 0x1\n"
"\tmovs r6, 0x1\n"
"\tlsls r1, 2\n"
"\tldr r0, [r5]\n"
"\tadds r1, r0\n"
"\tstrb r4, [r1, 0x2]\n"
"\tstrb r4, [r1, 0x1]\n"
"\tstrb r4, [r1]\n"
"\tldr r0, [sp, 0x4]\n"
"\tlsls r0, 2\n"
"\tldr r1, [r5]\n"
"\tadds r0, r1\n"
"\tstrb r4, [r0, 0x2]\n"
"\tstrb r4, [r0, 0x1]\n"
"\tstrb r4, [r0]\n"
"\tldr r0, [sp, 0x8]\n"
"\tlsls r0, 2\n"
"\tldr r1, [r5]\n"
"\tadds r0, r1\n"
"\tstrb r4, [r0, 0x2]\n"
"\tstrb r4, [r0, 0x1]\n"
"\tstrb r4, [r0]\n"
"\tldr r1, [sp]\n"
"\tlsls r1, 2\n"
"\tldr r0, [r5]\n"
"\tadds r0, r1\n"
"\tmovs r1, 0x7A\n"
"\tmovs r2, 0\n"
"\tbl xxx_init_itemslot_8090A8C\n"
"_08046E1E:\n"
"\tcmp r7, 0\n"
"\tbne _08046D96\n"
"\tbl FillInventoryGaps\n"
"\tcmp r6, 0\n"
"\tbeq _08046ED4\n"
"\tbl GetLeader\n"
"\tadds r4, r0, 0\n"
"\tldr r0, _08046EE0\n"
"\tbl sub_80855E4\n"
"\tldr r6, _08046EE4\n"
"\tldr r0, [r6]\n"
"\tldr r5, _08046EE8\n"
"\tadds r0, r5\n"
"\tmovs r1, 0x1\n"
"\tstrb r1, [r0]\n"
"\tldr r0, _08046EEC\n"
"\tldr r1, [r0]\n"
"\tmovs r0, 0\n"
"\tmovs r2, 0x1\n"
"\tbl PrintFieldMessage\n"
"\tmovs r0, 0x3C\n"
"\tmovs r1, 0x41\n"
"\tbl sub_803E708\n"
"\tldr r0, _08046EF0\n"
"\tldr r1, [r0]\n"
"\tmovs r0, 0\n"
"\tmovs r2, 0x1\n"
"\tbl PrintFieldMessage\n"
"\tadds r0, r4, 0\n"
"\tmovs r1, 0x4\n"
"\tmovs r2, 0xA\n"
"\tmovs r3, 0\n"
"\tbl sub_80869E4\n"
"\tadds r0, r4, 0\n"
"\tadds r0, 0xC\n"
"\tmovs r1, 0x86\n"
"\tlsls r1, 1\n"
"\tmovs r2, 0\n"
"\tbl sub_80416E0\n"
"\tadds r0, r4, 0\n"
"\tmovs r1, 0xD7\n"
"\tbl sub_80421C0\n"
"\tmovs r0, 0x3C\n"
"\tmovs r1, 0x41\n"
"\tbl sub_803E708\n"
"\tldr r0, _08046EF4\n"
"\tadds r1, r4, 0\n"
"\tmovs r2, 0\n"
"\tbl SetMessageArgument\n"
"\tldr r0, _08046EF8\n"
"\tldr r1, [r0]\n"
"\tmovs r0, 0\n"
"\tmovs r2, 0x1\n"
"\tbl PrintFieldMessage\n"
"\tmovs r0, 0xA\n"
"\tmovs r1, 0x41\n"
"\tbl sub_803E708\n"
"\tmovs r0, 0xD4\n"
"\tbl PlaySoundEffect\n"
"\tldr r0, _08046EFC\n"
"\tldr r1, [r0]\n"
"\tmovs r0, 0\n"
"\tmovs r2, 0x1\n"
"\tbl PrintFieldMessage\n"
"\tmovs r0, 0xA\n"
"\tmovs r1, 0x41\n"
"\tbl sub_803E708\n"
"\tmovs r0, 0x1\n"
"\tbl sub_804178C\n"
"\tldr r0, [r6]\n"
"\tadds r0, r5\n"
"\tstrb r7, [r0]\n"
"\tbl sub_8040A84\n"
"_08046ED4:\n"
"\tadd sp, 0xC\n"
"\tpop {r4-r7}\n"
"\tpop {r0}\n"
"\tbx r0\n"
"\t.align 2, 0\n"
"_08046EDC: .4byte gTeamInventoryRef\n"
"_08046EE0: .4byte sub_80861A8\n"
"_08046EE4: .4byte gDungeon\n"
"_08046EE8: .4byte 0x0001356c\n"
"_08046EEC: .4byte gUnknown_810531C\n"
"_08046EF0: .4byte gUnknown_8105360\n"
"_08046EF4: .4byte gAvailablePokemonNames\n"
"_08046EF8: .4byte gUnknown_81053A8\n"
"_08046EFC: .4byte gUnknown_8105434"
);
}
#endif
bool8 sub_8046F00(Item *item)
{
@ -448,35 +258,28 @@ void sub_804700C(void)
bool8 sub_8047084(s32 itemFlag)
{
Item *item;
Entity *entity;
EntityInfo *entityInfo;
s32 index;
s32 i;
// NEED THIS ORDERING TO MATCH
index = 0;
item = &gTeamInventoryRef->teamItems[index];
for(index = 0; index < INVENTORY_SIZE; item++, index++)
{
if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) {
return TRUE;
for (i = 0; i < INVENTORY_SIZE; i++)
{
if ((ItemExists(&gTeamInventoryRef->teamItems[i])) && (gTeamInventoryRef->teamItems[i].flags & itemFlag)) {
return TRUE;
}
}
}
FillInventoryGaps();
FillInventoryGaps();
for(index = 0; index < MAX_TEAM_MEMBERS; index++)
{
entity = gDungeon->teamPokemon[index];
if (EntityExists(entity)) {
entityInfo = entity->info;
item = &entityInfo->heldItem;
if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) {
return TRUE;
}
for (i = 0; i < MAX_TEAM_MEMBERS; i++)
{
Entity *entity = gDungeon->teamPokemon[i];
if (EntityExists(entity)) {
EntityInfo *entityInfo = GetEntInfo(entity);
Item *item = &entityInfo->heldItem;
if ((ItemExists(item) & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) {
return TRUE;
}
}
}
}
return FALSE;
return FALSE;
}
void sub_8047104(void)

View File

@ -97,33 +97,34 @@ bool8 sub_80571F0(Entity * pokemon, Move *move)
bool8 sub_805727C(Entity * pokemon, Entity * target, s32 chance)
{
bool8 uVar2;
if (!sub_8044B28() && EntityExists(pokemon) && EntityExists(target) &&
(target->info->unk158 != 0) &&
(target->info->HP != 0)) {
if (chance != 0) {
if (HasAbility(pokemon, ABILITY_SERENE_GRACE)) {
uVar2 = DungeonRandOutcome_2(chance * 2);
}
else
{
uVar2 = DungeonRandOutcome_2(chance);
}
if (sub_8044B28())
return FALSE;
if (!EntityExists(pokemon) || !EntityExists(target))
return FALSE;
if (target->info->unk158 == 0 || target->info->HP == 0)
return FALSE;
if (chance != 0) {
if (HasAbility(pokemon, ABILITY_SERENE_GRACE)) {
uVar2 = DungeonRandOutcome_2(chance * 2);
}
else
{
uVar2 = TRUE;
uVar2 = DungeonRandOutcome_2(chance);
}
if ((uVar2 != 0) && (pokemon != target) && HasAbility(target, ABILITY_SHIELD_DUST))
{
sub_80429C8(target);
end:
return FALSE;
}
else
return uVar2;
}
else
{
uVar2 = TRUE;
}
goto end;
if (uVar2 && (pokemon != target) && HasAbility(target, ABILITY_SHIELD_DUST))
{
sub_80429C8(target);
return FALSE;
}
return uVar2;
}
bool8 sub_8057308(Entity *pokemon, s32 chance)

View File

@ -50,100 +50,46 @@ extern MonsterDataEntry *gMonsterParameters;
extern struct FileArchive gMonsterFileArchive;
extern const char gUnknown_8107684[];
static inline bool8 sub_808D654_sub(PokemonStruct1 *ptr)
s32 sub_808D654(s32 *ptr)
{
return ptr->dungeonLocation.id == DUNGEON_JOIN_LOCATION_PARTNER;
}
s32 sub_808D654(s32 *ptr) {
s32 index;
s32 count;
PokemonStruct1 *pokeStruct;
s32 i;
PokemonStruct1 *mon = &gRecruitedPokemonRef->pokemon[0];
s32 count = 0;
s32 *ptr2;
pokeStruct = gRecruitedPokemonRef->pokemon;
count = 0;
for(index = 0, ptr2 = ptr; index < NUM_MONSTERS; index++, pokeStruct++)
{
if(((pokeStruct->unk0 >> 1) & 1) && (!pokeStruct->isTeamLeader) && !sub_808D654_sub(pokeStruct)){
if(ptr != 0) *ptr2 = index;
for (i = 0, ptr2 = ptr; i < NUM_MONSTERS; i++, mon++) {
if (PokemonFlag2(mon) && !IsMonTeamLeader(mon) && !IsMonPartner(mon)) {
if (ptr != NULL) {
*ptr2 = i;
}
ptr2++;
count++;
}
}
return count;
}
// 80 (97.58 % matching) - Seth
// https://decomp.me/scratch/B8Ont
#ifdef NONMATCHING
s32 sub_808D6A4(s32 *param_1)
// The same as sub_808D654 except it doesn't exclude partner.
s32 sub_808D6A4(s32 *ptr)
{
PokemonStruct1 *pokeStruct;
int index;
s32 counter;
s32 *piVar1;
s32 i;
PokemonStruct1 *mon = &gRecruitedPokemonRef->pokemon[0];
s32 count = 0;
s32 *ptr2;
pokeStruct = gRecruitedPokemonRef->pokemon;
counter = 0;
for(index = 0, piVar1 = param_1; index < 0x19d; index++)
{
pokeStruct = &gRecruitedPokemonRef->pokemon[index];
if (((pokeStruct->unk0 >> 1 & 1) != 0) && (!pokeStruct->isTeamLeader)) {
if (param_1 != 0x0) {
*piVar1 = index;
}
piVar1++;
counter++;
for (i = 0, ptr2 = ptr; i < NUM_MONSTERS; i++, mon++) {
if (PokemonFlag2(mon) && !IsMonTeamLeader(mon)) {
if (ptr != NULL) {
*ptr2 = i;
}
ptr2++;
count++;
}
}
}
return counter;
}
#else
NAKED
s32 sub_808D6A4(s32 *param_1)
{
asm_unified(
"\tpush {r4-r6,lr}\n"
"\tadds r5, r0, 0\n"
"\tldr r0, _0808D6E4\n"
"\tldr r2, [r0]\n"
"\tmovs r6, 0\n"
"\tmovs r4, 0\n"
"\tadds r3, r5, 0\n"
"_0808D6B2:\n"
"\tldrh r0, [r2]\n"
"\tlsrs r0, 1\n"
"\tmovs r1, 0x1\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbeq _0808D6CE\n"
"\tldrb r0, [r2, 0x2]\n"
"\tcmp r0, 0\n"
"\tbne _0808D6CE\n"
"\tcmp r5, 0\n"
"\tbeq _0808D6CA\n"
"\tstr r4, [r3]\n"
"_0808D6CA:\n"
"\tadds r3, 0x4\n"
"\tadds r6, 0x1\n"
"_0808D6CE:\n"
"\tadds r4, 0x1\n"
"\tadds r2, 0x58\n"
"\tmovs r0, 0xCE\n"
"\tlsls r0, 1\n"
"\tcmp r4, r0\n"
"\tble _0808D6B2\n"
"\tadds r0, r6, 0\n"
"\tpop {r4-r6}\n"
"\tpop {r1}\n"
"\tbx r1\n"
"\t.align 2, 0\n"
"_0808D6E4: .4byte gRecruitedPokemonRef");
}
#endif
return count;
}
bool8 sub_808D6E8()
{
@ -152,7 +98,7 @@ bool8 sub_808D6E8()
s32 size_count = 0;
for (i = 0; i < NUM_MONSTERS; i++) {
PokemonStruct1* pokemon = &gRecruitedPokemonRef->pokemon[i];
if ((1 & pokemon->unk0) && ((pokemon->unk0 >> 1) % 2)) {
if (PokemonFlag1(pokemon) && PokemonFlag2(pokemon)) {
size_count += GetBodySize(pokemon->speciesNum);
count++;
}