From a0e68c46e9c1c718266ef2b31e5dd92aef96d4fe Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 16 Oct 2024 16:10:14 +0200 Subject: [PATCH] remove DUMMY_TEAM_ITEMS_ASM_MATCH --- include/items.h | 8 -------- src/code_805D8C8_1.c | 31 +++++++++---------------------- src/items.c | 22 ++++------------------ src/trap.c | 31 ++++++++++++++----------------- 4 files changed, 27 insertions(+), 65 deletions(-) diff --git a/include/items.h b/include/items.h index 3a4d88714..a57805e82 100644 --- a/include/items.h +++ b/include/items.h @@ -83,14 +83,6 @@ s32 SaveTeamInventory(u8 *, u32 size); s32 WriteHighDecimal(s32, u8 *strbuf, u8); u32 sub_80913E0(Item *slot, u32, struct subStruct_203B240 **); -// This macro doesn't do anything, it creates unused variables for the purpose of tricking the compiler and matching the asm. -// It's possible there was some unknown macro, or the structure of TeamInventory/Item is not 100% how it was originally written. -#define DUMMY_TEAM_ITEMS_ASM_MATCH(id) \ -{ \ - UNUSED size_t offs = id * sizeof(Item); \ - UNUSED Item *item = &gTeamInventoryRef->teamItems[id]; \ -} - static inline void ZeroOutItem(Item *item) { item->id = 0; diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index 06c3139ab..eece1b88b 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -2731,11 +2731,7 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 case 0: PrintFormatStringOnWindow(x, 0, gTeamToolboxAPtr, 0, 0); for (i = 0; i < 10; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (items[i].flags & ITEM_FLAG_EXISTS) { + if (ItemExists(&gTeamInventoryRef->teamItems[i])) { gUnknown_202EE10.unk1A++; sub_8090E14(txtBuff, &gTeamInventoryRef->teamItems[i], &gUnknown_8106B60); y = sub_8013800(&gUnknown_202EE10, i); @@ -2749,11 +2745,7 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 case 1: PrintFormatStringOnWindow(x, 0, gTeamToolboxBPtr, 0, 0); for (i = 0; i < 10; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (items[i + 10].flags & 1) { + if (ItemExists(&gTeamInventoryRef->teamItems[i + 10])) { gUnknown_202EE10.unk1A++; sub_8090E14(txtBuff, &gTeamInventoryRef->teamItems[i + 10], &gUnknown_8106B60); y = sub_8013800(&gUnknown_202EE10, i); @@ -2912,10 +2904,9 @@ void sub_8060900(Entity *a0) sub_8044FF0(9); } } - // Why is it checking actionUseIndex again? - if (gUnknown_202F238.actionUseIndex == 128 && gDungeon->unk65B != 0) { - sub_8044F5C(10, item->id); - } + } + if (gUnknown_202F238.actionUseIndex == 128 && gDungeon->unk65B != 0) { + sub_8044F5C(10, item->id); } val_sub8044DC8 = sub_8044DC8(item); if (val_sub8044DC8 != 0) { @@ -2933,7 +2924,7 @@ void sub_8060900(Entity *a0) { s32 i; - if (item->flags & ITEM_FLAG_SET) { + if (ItemSet(item)) { sub_8044F5C(0x3D, item->id); } else { @@ -2941,13 +2932,9 @@ void sub_8060900(Entity *a0) } for (i = 0; i < INVENTORY_SIZE; i++) { - // Compiler uses r5 without the fakematch trick. It's gTeamInventoryRef causing matching issues again... - #ifndef NONMATCHING - item++;item--; - #endif // NONMATCHING - if (gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_EXISTS - && gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_SET - && gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_STICKY) + if (ItemExists(&gTeamInventoryRef->teamItems[i]) + && ItemSet(&gTeamInventoryRef->teamItems[i]) + && ItemSticky(&gTeamInventoryRef->teamItems[i])) { sub_8044FF0(0x3C); sub_8044FF0(0x3D); diff --git a/src/items.c b/src/items.c index 70160aa24..21aeecda5 100644 --- a/src/items.c +++ b/src/items.c @@ -484,14 +484,7 @@ void FillInventoryGaps() // clear out the rest of the slots for (; last_filled < INVENTORY_SIZE; last_filled++) { - struct Item *items; - - DUMMY_TEAM_ITEMS_ASM_MATCH(last_filled); - items = gTeamInventoryRef->teamItems; - - items[last_filled].id = ITEM_NOTHING; - items[last_filled].quantity = 0; - items[last_filled].flags = 0; + ZeroOutItem(&gTeamInventoryRef->teamItems[last_filled]); } } @@ -575,12 +568,8 @@ bool8 AddItemToInventory(const Item* slot) // try to add item to inventory, return 1 if failed for (i = 0; i < INVENTORY_SIZE; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (!(items[i].flags & ITEM_FLAG_EXISTS)) { - items[i] = *slot; + if (!ItemExists(&gTeamInventoryRef->teamItems[i])) { + gTeamInventoryRef->teamItems[i] = *slot; return FALSE; } } @@ -908,12 +897,9 @@ bool8 IsGummiItem(u8 id) bool8 HasGummiItem(void) { - Item *items; s32 i; for (i = 0; i < INVENTORY_SIZE; i++) { - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - items = gTeamInventoryRef->teamItems; - if ((items[i].flags & ITEM_FLAG_EXISTS) && IsGummiItem(items[i].id)) { + if (ItemExists(&gTeamInventoryRef->teamItems[i]) && IsGummiItem(gTeamInventoryRef->teamItems[i].id)) { return TRUE; } } diff --git a/src/trap.c b/src/trap.c index e195af20d..a2c44e550 100644 --- a/src/trap.c +++ b/src/trap.c @@ -407,7 +407,7 @@ void HandleStickyTrap(Entity *pokemon,Entity *target) int newIndex; Item *itemStack[21]; - info = target->info; + info = GetEntInfo(target); if (HasHeldItem(target,0xe)) { sub_80522F4(pokemon,target,*gUnknown_80FDC7C); } @@ -416,32 +416,29 @@ void HandleStickyTrap(Entity *pokemon,Entity *target) itemCount = 0; if (info->isTeamLeader) { for (index = 0; index < INVENTORY_SIZE; index++) { - struct Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(index); - - items = gTeamInventoryRef->teamItems; - if ((items[index].flags & ITEM_FLAG_EXISTS) - && IsNotSpecialItem(items[index].id) - && !(gTeamInventoryRef->teamItems[index].flags & ITEM_FLAG_STICKY)) { - itemStack[itemCount] = &gTeamInventoryRef->teamItems[index]; + if (ItemExists(&gTeamInventoryRef->teamItems[index]) && IsNotSpecialItem(gTeamInventoryRef->teamItems[index].id)) { + Item *item = &gTeamInventoryRef->teamItems[index]; + if (!ItemSticky(item)) { + itemStack[itemCount] = item; itemCount++; } + } } } - if ((info->heldItem.flags & ITEM_FLAG_EXISTS) && IsNotSpecialItem((info->heldItem).id) && !(info->heldItem.flags & ITEM_FLAG_STICKY)) { - itemStack[itemCount] = &info->heldItem; - itemCount++; + if (ItemExists(&info->heldItem) && IsNotSpecialItem((info->heldItem).id) && !ItemSticky(&info->heldItem)) { + itemStack[itemCount] = &info->heldItem; + itemCount++; } if (itemCount == 0) { sub_80522F4(pokemon,target,*gUnknown_80FDC40); } else { - newIndex = DungeonRandInt(itemCount); - sub_8045BF8(gFormatItems, itemStack[newIndex]); - itemStack[newIndex]->flags |= ITEM_FLAG_STICKY; - sub_80421C0(target, 0x192); - sub_80522F4(pokemon,target,*gUnknown_80FDC18); + newIndex = DungeonRandInt(itemCount); + sub_8045BF8(gFormatItems, itemStack[newIndex]); + itemStack[newIndex]->flags |= ITEM_FLAG_STICKY; + sub_80421C0(target, 0x192); + sub_80522F4(pokemon,target,*gUnknown_80FDC18); } } }