diff --git a/asm/include/main_0200CAFC.inc b/asm/include/main_0200CAFC.inc index 8abb478e..8c431cb4 100644 --- a/asm/include/main_0200CAFC.inc +++ b/asm/include/main_0200CAFC.inc @@ -25,6 +25,7 @@ .public CopyBitsFrom .public CopyBitsTo .public GetDungeonGroup +.public GetExclusiveItemOffsetEnsureValid .public GetItemActionName .public GetItemBuyPrice .public GetItemCategory diff --git a/asm/main_0200CAFC.s b/asm/main_0200CAFC.s index d52a31f2..7bf2b09e 100644 --- a/asm/main_0200CAFC.s +++ b/asm/main_0200CAFC.s @@ -1889,27 +1889,3 @@ GetExclusiveItemType: ; 0x0200E760 .align 2, 0 _0200E778: .word ITEM_DATA_TABLE_PTRS arm_func_end GetExclusiveItemType - - arm_func_start GetExclusiveItemOffsetEnsureValid -GetExclusiveItemOffsetEnsureValid: ; 0x0200E77C - stmdb sp!, {r4, lr} - mov r4, r0 - cmp r4, #0x1bc - blt _0200E798 - ldr r1, _0200E7BC ; =0x00000578 - cmp r4, r1 - blt _0200E7A0 -_0200E798: - mov r0, #0x55 - ldmia sp!, {r4, pc} -_0200E7A0: - bl IsItemValid - cmp r0, #0 - subne r0, r4, #0x1bc - movne r0, r0, lsl #0x10 - movne r0, r0, asr #0x10 - moveq r0, #0x55 - ldmia sp!, {r4, pc} - .align 2, 0 -_0200E7BC: .word 0x00000578 - arm_func_end GetExclusiveItemOffsetEnsureValid diff --git a/include/item_util_1.h b/include/item_util_1.h index 66ebf400..318c1118 100644 --- a/include/item_util_1.h +++ b/include/item_util_1.h @@ -3,6 +3,8 @@ #include "util.h" +s16 GetExclusiveItemOffsetEnsureValid(s16 item_id); + // 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); diff --git a/src/item_util_1.c b/src/item_util_1.c index 7128646b..84e0282d 100644 --- a/src/item_util_1.c +++ b/src/item_util_1.c @@ -3,6 +3,16 @@ extern struct item_data_entry *ITEM_DATA_TABLE_PTRS[3]; +s16 GetExclusiveItemOffsetEnsureValid(s16 item_id) { + if (item_id < ITEM_PRISM_RUFF || item_id >= NUM_ITEM_IDS) { + return ITEM_PLAIN_SEED; + } + if (IsItemValid(item_id)) { + return (s16)(item_id - ITEM_PRISM_RUFF); + } + return ITEM_PLAIN_SEED; +} + bool8 IsItemValid(s16 item_id) { if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_VALID)