From f840173d38f7e0314bbeda567d598683d831771f Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 12 Feb 2025 22:53:14 -0500 Subject: [PATCH] Decomped IsItemValid --- asm/include/main_0200CAFC.inc | 1 + asm/include/main_0200E7E8.inc | 3 +++ asm/include/main_0200E864.inc | 1 + asm/main_0200CAFC.s | 36 ----------------------------------- asm/main_0200E7E8.s | 21 ++++++++++++++++++++ include/item.h | 11 ++++++++++- include/item_util_1.h | 10 ++++++++++ main.lsf | 2 ++ src/item_util_1.c | 12 ++++++++++++ src/item_util_2.c | 9 +-------- 10 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 asm/include/main_0200E7E8.inc create mode 100644 asm/main_0200E7E8.s create mode 100644 include/item_util_1.h create mode 100644 src/item_util_1.c diff --git a/asm/include/main_0200CAFC.inc b/asm/include/main_0200CAFC.inc index 3b4d7100..9851ec0e 100644 --- a/asm/include/main_0200CAFC.inc +++ b/asm/include/main_0200CAFC.inc @@ -16,6 +16,7 @@ .public HandleSir0Translation .public ITEM_DATA_TABLE_PTRS .public ITEM_TABLES_PTRS_1 +.public IsItemValid .public LoadFileFromRom .public MONEY_QUANTITY_TABLE .public MemAlloc diff --git a/asm/include/main_0200E7E8.inc b/asm/include/main_0200E7E8.inc new file mode 100644 index 00000000..66d87dc3 --- /dev/null +++ b/asm/include/main_0200E7E8.inc @@ -0,0 +1,3 @@ +#pragma once +.public GetExclusiveItemOffsetEnsureValid +.public ITEM_DATA_TABLE_PTRS diff --git a/asm/include/main_0200E864.inc b/asm/include/main_0200E864.inc index 7ae1b88d..c1f3b099 100644 --- a/asm/include/main_0200E864.inc +++ b/asm/include/main_0200E864.inc @@ -6,6 +6,7 @@ .public ITEM_DATA_TABLE_PTRS .public IsItemValid .public ItemZInit +.public SprintfStatic__0200E808_EU .public StringFromId .public _0209808C .public _0209809C diff --git a/asm/main_0200CAFC.s b/asm/main_0200CAFC.s index c71ae3db..5631d9b7 100644 --- a/asm/main_0200CAFC.s +++ b/asm/main_0200CAFC.s @@ -2319,39 +2319,3 @@ _0200E7A0: .align 2, 0 _0200E7BC: .word 0x00000578 arm_func_end GetExclusiveItemOffsetEnsureValid - - arm_func_start IsItemValid -IsItemValid: ; 0x0200E7C0 - ldr r1, _0200E7E4 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrb r0, [r0, #0xe] - tst r0, #1 - movne r0, #1 - moveq r0, #0 - and r0, r0, #0xff - bx lr - .align 2, 0 -_0200E7E4: .word ITEM_DATA_TABLE_PTRS - arm_func_end IsItemValid - - arm_func_start GetExclusiveItemParameter -GetExclusiveItemParameter: ; 0x0200E7E8 - stmdb sp!, {r3, lr} - bl GetExclusiveItemOffsetEnsureValid - ldr r1, _0200E804 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1, #4] -#else - ldr r1, [r1] -#endif - add r0, r1, r0, lsl #2 - ldrsh r0, [r0, #2] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200E804: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetExclusiveItemParameter diff --git a/asm/main_0200E7E8.s b/asm/main_0200E7E8.s new file mode 100644 index 00000000..3bca37cb --- /dev/null +++ b/asm/main_0200E7E8.s @@ -0,0 +1,21 @@ + .include "asm/macros.inc" + .include "main_0200E7E8.inc" + + .text + + arm_func_start GetExclusiveItemParameter +GetExclusiveItemParameter: ; 0x0200E7E8 + stmdb sp!, {r3, lr} + bl GetExclusiveItemOffsetEnsureValid + ldr r1, _0200E804 ; =ITEM_DATA_TABLE_PTRS +#ifdef EUROPE + ldr r1, [r1, #4] +#else + ldr r1, [r1] +#endif + add r0, r1, r0, lsl #2 + ldrsh r0, [r0, #2] + ldmia sp!, {r3, pc} + .align 2, 0 +_0200E804: .word ITEM_DATA_TABLE_PTRS + arm_func_end GetExclusiveItemParameter diff --git a/include/item.h b/include/item.h index 85241e00..ffca10c8 100644 --- a/include/item.h +++ b/include/item.h @@ -1,6 +1,14 @@ #ifndef PMDSKY_ITEM_H #define PMDSKY_ITEM_H +#include "util.h" + +#ifdef EUROPE +#define ITEM_DATA_TABLE_PTRS_INDEX 0 +#else +#define ITEM_DATA_TABLE_PTRS_INDEX 1 +#endif + // Item ID enum item_id { ITEM_NOTHING = 0, @@ -1487,7 +1495,8 @@ struct item_data_entry { /* 0x0 */ u8 *name; /* 0x4 */ enum item_category category; - u8 fill8[8]; + u8 fill5[0xE - 0x5]; + /* 0xE */ bool8 valid; }; #endif //PMDSKY_ITEM_H diff --git a/include/item_util_1.h b/include/item_util_1.h new file mode 100644 index 00000000..66ebf400 --- /dev/null +++ b/include/item_util_1.h @@ -0,0 +1,10 @@ +#ifndef PMDSKY_ITEM_UTIL_1_H +#define PMDSKY_ITEM_UTIL_1_H + +#include "util.h" + +// Checks if an item is valid given its ID. +// In particular, checks if the "is valid" flag is set on its item_p.bin entry. +bool8 IsItemValid(s16 item_id); + +#endif //PMDSKY_ITEM_UTIL_1_H diff --git a/main.lsf b/main.lsf index 24670c33..b0905a66 100644 --- a/main.lsf +++ b/main.lsf @@ -23,6 +23,8 @@ Static main Object asm/main_0200C4CC.o Object src/item_util.o Object asm/main_0200CAFC.o + Object src/item_util_1.o + Object asm/main_0200E7E8.o Object src/item_util_2.o Object asm/main_0200E864.o Object src/main_0200ECFC.o diff --git a/src/item_util_1.c b/src/item_util_1.c new file mode 100644 index 00000000..f2a9a24b --- /dev/null +++ b/src/item_util_1.c @@ -0,0 +1,12 @@ +#include "item_util_1.h" +#include "item.h" + +extern struct item_data_entry *ITEM_DATA_TABLE_PTRS[3]; + +bool8 IsItemValid(s16 item_id) +{ + if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].valid & 1) + return TRUE; + + return FALSE; +} diff --git a/src/item_util_2.c b/src/item_util_2.c index 3acdec53..e9653809 100644 --- a/src/item_util_2.c +++ b/src/item_util_2.c @@ -1,14 +1,7 @@ #include "item_util_2.h" -#include "util.h" +#include "item_util_1.h" extern struct item_data_entry *ITEM_DATA_TABLE_PTRS[3]; -extern bool8 IsItemValid(s16 item_id); - -#ifdef EUROPE -#define ITEM_DATA_TABLE_PTRS_INDEX 0 -#else -#define ITEM_DATA_TABLE_PTRS_INDEX 1 -#endif enum item_category GetItemCategory(s16 item_id) {