From b75c533e88ce53be50ea23ca3dce421756d6cd50 Mon Sep 17 00:00:00 2001 From: VicSevenT Date: Thu, 1 Jan 2026 12:59:40 -0600 Subject: [PATCH] Decomp LoadItemPspi2n --- asm/include/main_0200CAFC.inc | 13 ---- asm/include/main_rodata_020A2808.inc | 10 +-- asm/main_0200CAFC.s | 68 -------------------- asm/main_rodata_020908D4.s | 92 ++++++++++++++-------------- asm/main_rodata_020A2808.s | 25 ++++---- include/item.h | 10 +-- include/item_util_1.h | 2 + src/item_util_1.c | 45 ++++++++++---- src/item_util_4.c | 2 +- 9 files changed, 104 insertions(+), 163 deletions(-) diff --git a/asm/include/main_0200CAFC.inc b/asm/include/main_0200CAFC.inc index acc4bc41..7a644195 100644 --- a/asm/include/main_0200CAFC.inc +++ b/asm/include/main_0200CAFC.inc @@ -13,13 +13,7 @@ .public _02097FB8 .public _02097FC4 .public _02097FE4 -.public _02098038 -.public _02098054 -.public _02098070 .public _020A18BC -.public _020AF6C4 -.public _020AF6C8 -.public _020AFF88_EU .public AVAILABLE_ITEMS_IN_GROUP_TABLE .public BAG_ITEMS_PTR_MIRROR .public CopyBitsFrom @@ -33,24 +27,18 @@ .public GetItemName .public GetItemPaletteId .public GetItemSellPrice -.public GetLanguage .public GetThrownItemQuantityLimit -.public HandleSir0Translation .public InitItem .public IsAuraBow .public IsItemValid .public IsShoppableItem .public IsThrownItem -.public ITEM_DATA_TABLE_PTRS .public ITEM_TABLES_PTRS_1 -.public LoadFileFromRom .public MemAlloc .public MemFree .public MONEY_QUANTITY_TABLE .public MultiplyByFixedPoint -.public PointsToZero .public RandRangeSafe -.public SprintfStatic__0200E808_EU .public strcpy .public strncpy .public sub_0200EB64 @@ -59,4 +47,3 @@ .public sub_02050990 .public sub_020509BC .public vsprintf -.public ZInit8 diff --git a/asm/include/main_rodata_020A2808.inc b/asm/include/main_rodata_020A2808.inc index 305cef59..d3410797 100644 --- a/asm/include/main_rodata_020A2808.inc +++ b/asm/include/main_rodata_020A2808.inc @@ -35,11 +35,11 @@ .public _02092EBC .public _02092ED0 .public _02094D00 -.public _020983F4 -.public _02098404 -.public _02098414 -.public _02098424 -.public _02098434 +.public ST_I2N_I_BIN +.public ST_I2N_E_BIN +.public ST_I2N_S_BIN +.public ST_I2N_G_BIN +.public ST_I2N_F_BIN .public _02098DAC .public _02098DC8 .public _02098EB0 diff --git a/asm/main_0200CAFC.s b/asm/main_0200CAFC.s index d93584d3..61c8a42f 100644 --- a/asm/main_0200CAFC.s +++ b/asm/main_0200CAFC.s @@ -1789,71 +1789,3 @@ _0200E6CC: blt _0200E628 ldmia sp!, {r4, r5, r6, pc} arm_func_end RemoveEmptyItems - - arm_func_start LoadItemPspi2n -LoadItemPspi2n: ; 0x0200E6D8 -#ifdef EUROPE -#define LOAD_ITEM_PSPI_2N_STACK_SIZE #0x108 -#else -#define LOAD_ITEM_PSPI_2N_STACK_SIZE #8 -#endif - stmdb sp!, {r3, lr} - sub sp, sp, LOAD_ITEM_PSPI_2N_STACK_SIZE - ldr r1, _0200E748 ; =_02098038 - add r0, sp, #0 - mov r2, #1 - bl LoadFileFromRom - ldr r1, [sp] - ldr r0, _0200E74C ; =_020AF6C4 - bl HandleSir0Translation - ldr r1, _0200E750 ; =_02098054 - add r0, sp, #0 - mov r2, #1 - bl LoadFileFromRom - ldr r1, [sp] - ldr r0, _0200E754 ; =ITEM_DATA_TABLE_PTRS - bl HandleSir0Translation - ldr r0, _0200E758 ; =_020AF6C8 - bl PointsToZero - cmp r0, #0 - beq _0200E740 - ldr r0, _0200E758 ; =_020AF6C8 - bl ZInit8 -#ifdef EUROPE - bl GetLanguage - mov r2, r0 - ldr r1, _0200E800 ; =_020AFF88_EU - add r0, sp, #8 - ldr r2, [r1, r2, lsl #2] - ldr r1, _0200E75C ; =_02098070 - bl SprintfStatic__0200E808_EU - ldr r0, _0200E758 ; =_020AF6C8 - add r1, sp, #8 -#else - ldr r0, _0200E758 ; =_020AF6C8 - ldr r1, _0200E75C ; =_02098070 -#endif - mov r2, #1 - bl LoadFileFromRom -_0200E740: - add sp, sp, LOAD_ITEM_PSPI_2N_STACK_SIZE - ldmia sp!, {r3, pc} - .align 2, 0 -_0200E748: .word _02098038 -#ifdef EUROPE -_0200E74C: .word ITEM_DATA_TABLE_PTRS -#else -_0200E74C: .word _020AF6C4 -#endif -_0200E750: .word _02098054 -#ifdef EUROPE -_0200E754: .word _020AF6C4 -#else -_0200E754: .word ITEM_DATA_TABLE_PTRS -#endif -_0200E758: .word _020AF6C8 -#ifdef EUROPE -_0200E800: .word _020AFF88_EU -#endif -_0200E75C: .word _02098070 - arm_func_end LoadItemPspi2n diff --git a/asm/main_rodata_020908D4.s b/asm/main_rodata_020908D4.s index 99dea3cb..d010fa1d 100644 --- a/asm/main_rodata_020908D4.s +++ b/asm/main_rodata_020908D4.s @@ -2886,26 +2886,26 @@ _02097FE4: .byte 0x25, 0x73, 0x5B, 0x43, 0x53, 0x3A, 0x31, 0x3A, 0x52, 0x5D, 0x25, 0x73, 0x5B, 0x43, 0x52, 0x3A .byte 0x31, 0x5D, 0x00, 0x00 #ifdef EUROPE - .global _020983F4 -_020983F4: - .byte 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E, 0x5F, 0x69 - .byte 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 - .global _02098404 -_02098404: - .byte 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E, 0x5F, 0x65 - .byte 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 - .global _02098414 -_02098414: - .byte 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E, 0x5F, 0x73 - .byte 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 - .global _02098424 -_02098424: - .byte 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E, 0x5F, 0x67 - .byte 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 - .global _02098434 -_02098434: - .byte 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E, 0x5F, 0x66 - .byte 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 + .global ST_I2N_I_BIN +ST_I2N_I_BIN: + .string "st_i2n_i.bin" + .align 4 + .global ST_I2N_E_BIN +ST_I2N_E_BIN: + .string "st_i2n_e.bin" + .align 4 + .global ST_I2N_S_BIN +ST_I2N_S_BIN: + .string "st_i2n_s.bin" + .align 4 + .global ST_I2N_G_BIN +ST_I2N_G_BIN: + .string "st_i2n_g.bin" + .align 4 + .global ST_I2N_F_BIN +ST_I2N_F_BIN: + .string "st_i2n_f.bin" + .align 4 #endif .global BABY_EXCLUSIVE_ITEM_PAIRS BABY_EXCLUSIVE_ITEM_PAIRS: @@ -2914,40 +2914,38 @@ BABY_EXCLUSIVE_ITEM_PAIRS: .byte 0xCF, 0x01, 0x0B, 0x01, 0xD0, 0x01, 0x46, 0x01, 0xD1, 0x01, 0x88, 0x01, 0xD2, 0x01, 0xE0, 0x01 .byte 0xD3, 0x01, 0xE1, 0x01, 0xD4, 0x01, 0xE2, 0x01, 0xD5, 0x01, 0xE9, 0x01, 0xD6, 0x01, 0xF4, 0x01 .byte 0xD7, 0x01, 0x13, 0x02 - .global _02098038 -_02098038: - .byte 0x72, 0x6F, 0x6D, 0x30, 0x3A, 0x2F, 0x42, 0x41, 0x4C, 0x41, 0x4E, 0x43 - .byte 0x45, 0x2F, 0x69, 0x74, 0x65, 0x6D, 0x5F, 0x70, 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00 - .global _02098054 -_02098054: - .byte 0x72, 0x6F, 0x6D, 0x30, 0x3A, 0x2F, 0x42, 0x41, 0x4C, 0x41, 0x4E, 0x43, 0x45, 0x2F, 0x69, 0x74 - .byte 0x65, 0x6D, 0x5F, 0x73, 0x5F, 0x70, 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00 - .global _02098070 -_02098070: - .byte 0x72, 0x6F, 0x6D, 0x30 - .byte 0x3A, 0x2F, 0x42, 0x41, 0x4C, 0x41, 0x4E, 0x43 + .global ITEM_P_BIN +ITEM_P_BIN: + .string "rom0:/BALANCE/item_p.bin" + .align 4 + .global ITEM_S_P_BIN +ITEM_S_P_BIN: + .string "rom0:/BALANCE/item_s_p.bin" + .align 4 + .global ITEM_ST_I2N_BIN +ITEM_ST_I2N_BIN: #ifdef EUROPE - .byte 0x45, 0x2F, 0x25, 0x73 - .byte 0x00, 0x00, 0x00, 0x00 + .string "rom0:/BALANCE/%s" #else - .byte 0x45, 0x2F, 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E - .byte 0x5F, 0x6A, 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00 + .string "rom0:/BALANCE/st_i2n_j.bin" #endif + .align 4 .global ITEM_NAME_FORMAT_YELLOW -ITEM_NAME_FORMAT_YELLOW: // "[CS:U]%s[CR]" - .byte 0x5B, 0x43, 0x53, 0x3A, 0x55, 0x5D, 0x25, 0x73 - .byte 0x5B, 0x43, 0x52, 0x5D, 0x00, 0x00, 0x00, 0x00 +ITEM_NAME_FORMAT_YELLOW: + .string "[CS:U]%s[CR]" + .align 4 .global ITEM_NAME_FORMAT_INDIGO -ITEM_NAME_FORMAT_INDIGO: // "[CS:Z]%s[CR]" - .byte 0x5B, 0x43, 0x53, 0x3A, 0x5A, 0x5D, 0x25, 0x73 - .byte 0x5B, 0x43, 0x52, 0x5D, 0x00, 0x00, 0x00, 0x00 +ITEM_NAME_FORMAT_INDIGO: + .string "[CS:Z]%s[CR]" + .align 4 .global ITEM_NAME_FORMAT_PLAIN -ITEM_NAME_FORMAT_PLAIN: // "%s" - .byte 0x25, 0x73, 0x00, 0x00 +ITEM_NAME_FORMAT_PLAIN: + .string "%s" + .align 4 .global ITEM_NAME_FORMAT_CREAM -ITEM_NAME_FORMAT_CREAM: // "[CS:I]%s[CR]" - .byte 0x5B, 0x43, 0x53, 0x3A - .byte 0x49, 0x5D, 0x25, 0x73, 0x5B, 0x43, 0x52, 0x5D, 0x00, 0x00, 0x00, 0x00 +ITEM_NAME_FORMAT_CREAM: + .string "[CS:I]%s[CR]" + .align 4 .global KECLEON_SHOP_ITEM_TABLE_LISTS_1 KECLEON_SHOP_ITEM_TABLE_LISTS_1: .byte 0x10, 0x00, 0x00, 0x00 diff --git a/asm/main_rodata_020A2808.s b/asm/main_rodata_020A2808.s index b7b2e811..d7def128 100644 --- a/asm/main_rodata_020A2808.s +++ b/asm/main_rodata_020A2808.s @@ -11664,21 +11664,18 @@ BAG_ITEMS_PTR_MIRROR: .word _02094D00 .global ITEM_DATA_TABLE_PTRS ITEM_DATA_TABLE_PTRS: - .byte 0x00, 0x00, 0x00, 0x00 - .global _020AF6C4 -_020AF6C4: - .byte 0x00, 0x00, 0x00, 0x00 - .global _020AF6C8 -_020AF6C8: - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .word 0x00 + .word 0x00 + .word 0x00 + .word 0x00 #ifdef EUROPE - .global _020AFF88_EU -_020AFF88_EU: - .word _02098404 - .word _02098434 - .word _02098424 - .word _020983F4 - .word _02098414 + .global ITEM_LANG_FILE_ARRAY +ITEM_LANG_FILE_ARRAY: + .word ST_I2N_E_BIN + .word ST_I2N_F_BIN + .word ST_I2N_G_BIN + .word ST_I2N_I_BIN + .word ST_I2N_S_BIN #endif .global _020AF6D0 _020AF6D0: diff --git a/include/item.h b/include/item.h index 07b9d678..ca83a6f2 100644 --- a/include/item.h +++ b/include/item.h @@ -1,6 +1,7 @@ #ifndef PMDSKY_ITEM_H #define PMDSKY_ITEM_H +#include "file.h" #include "util.h" // Item ID @@ -1666,16 +1667,17 @@ struct item_exclusive_data { u16 unk2; }; +struct item_tables { + #ifdef EUROPE -struct item_tables { struct item_data *data; struct item_exclusive_data *exclusive_data; -}; #else -struct item_tables { struct item_exclusive_data *exclusive_data; struct item_data *data; -}; #endif + struct iovec langFile; +}; + #endif //PMDSKY_ITEM_H diff --git a/include/item_util_1.h b/include/item_util_1.h index 212fcfda..0b2940a6 100644 --- a/include/item_util_1.h +++ b/include/item_util_1.h @@ -4,6 +4,8 @@ #include "item.h" #include "util.h" +void LoadItemPspi2n(void); + #ifdef EUROPE void SprintfStatic__0200E808_EU(char* buf, const char* fmt, ...); #endif diff --git a/src/item_util_1.c b/src/item_util_1.c index 8d438ae0..23a150e7 100644 --- a/src/item_util_1.c +++ b/src/item_util_1.c @@ -1,4 +1,5 @@ #include "debug.h" +#include "main_0200330C.h" #include "main_0202593C.h" #include "item.h" #include "item_util_1.h" @@ -16,7 +17,14 @@ extern const char ITEM_NAME_FORMAT_YELLOW; extern const char ITEM_NAME_FORMAT_INDIGO; extern const char ITEM_NAME_FORMAT_PLAIN; extern const char ITEM_NAME_FORMAT_CREAM; +extern const char ITEM_P_BIN; +extern const char ITEM_S_P_BIN; +extern const char ITEM_ST_I2N_BIN; +extern char* ITEM_LANG_FILE_ARRAY[]; +extern void LoadFileFromRom(struct iovec* iov, const char* filepath, u32 flags); +extern void HandleSir0Translation(void*, void*); +extern s32 GetLanguage(); extern u8* strcpy(u8*, u8*); extern s32 vsprintf(u8* str, const u8* format, va_list ap); @@ -24,8 +32,28 @@ static s16 GetExclusiveItemOffsetEnsureValid(s16 item_id); static s16 EnsureValidItem(s16 item_id); static void SprintfStatic(char*, const char*, ...); + +void LoadItemPspi2n(void) { + struct iovec iov; + + LoadFileFromRom(&iov, &ITEM_P_BIN, 1); + HandleSir0Translation(&ITEM_DATA_TABLE_PTRS.data, iov.iov_base); + LoadFileFromRom(&iov, &ITEM_S_P_BIN, 1); + HandleSir0Translation(&ITEM_DATA_TABLE_PTRS.exclusive_data, iov.iov_base); + if (PointsToZero(&ITEM_DATA_TABLE_PTRS.langFile) != 0) { + ZInit8(&ITEM_DATA_TABLE_PTRS.langFile); #ifdef EUROPE -void SprintfStatic__0200E808_EU(char* buf, const char* fmt, ...) + char buf[256]; + SprintfStatic(buf, &ITEM_ST_I2N_BIN, ITEM_LANG_FILE_ARRAY[GetLanguage()]); + LoadFileFromRom(&ITEM_DATA_TABLE_PTRS.langFile, buf, 1); +#else + LoadFileFromRom(&ITEM_DATA_TABLE_PTRS.langFile, &ITEM_ST_I2N_BIN, 1); +#endif + } +} + +#ifdef EUROPE +static void SprintfStatic(char* buf, const char* fmt, ...) { va_list args; va_start(args, fmt); @@ -83,11 +111,6 @@ u8* GetItemName(s16 item_id) { return StringFromId((u16)(valid_item_id + ITEM_NAME_OFFSET)); } -#ifdef EUROPE -#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic__0200E808_EU -#else -#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic -#endif void GetItemNameFormatted(char* name, s16 item_id, s32 flag1, s32 flag2) { enum item_category category; @@ -97,7 +120,7 @@ void GetItemNameFormatted(char* name, s16 item_id, s32 flag1, s32 flag2) category = ITEM_DATA_TABLE_PTRS.data[EnsureValidItem(item_id)].category; if ((flag2 != 0) || ((u8)(category + 0xF4) <= 2)) { if (flag1 != 0) { - GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_YELLOW, raw_name); + SprintfStatic(name, &ITEM_NAME_FORMAT_YELLOW, raw_name); return; } strcpy(name, raw_name); @@ -105,18 +128,18 @@ void GetItemNameFormatted(char* name, s16 item_id, s32 flag1, s32 flag2) } if (category == CATEGORY_EXCLUSIVE_ITEMS) { if (flag1 != 0) { - GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_INDIGO, raw_name); + SprintfStatic(name, &ITEM_NAME_FORMAT_INDIGO, raw_name); return; } - GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); + SprintfStatic(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); return; } if (flag1 != 0) { - GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_CREAM, raw_name); + SprintfStatic(name, &ITEM_NAME_FORMAT_CREAM, raw_name); return; } - GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); + SprintfStatic(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); return; } diff --git a/src/item_util_4.c b/src/item_util_4.c index ddc0480b..f5cc8200 100644 --- a/src/item_util_4.c +++ b/src/item_util_4.c @@ -2,7 +2,7 @@ #include "dungeon_util_static.h" #include "item.h" #include "item_util.h" -#include "item_util_2.h" +#include "item_util_1.h" extern s16 RandRangeSafe(s32, s32); extern s16 _020A18BC[10];