diff --git a/asm/include/main_0200E864.inc b/asm/include/main_0200E864.inc deleted file mode 100644 index 33cb2bc2..00000000 --- a/asm/include/main_0200E864.inc +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -.public _0209808C -.public _0209809C -.public _020980AC -.public _020980B0 -.public EnsureValidItem -.public GET_ITEM_NAME_FORMATTED_SPRINTF -.public ITEM_DATA_TABLE_PTRS -.public SprintfStatic__0200E808_EU -.public strcpy -.public StringFromId -.public vsprintf diff --git a/asm/main_0200E864.s b/asm/main_0200E864.s deleted file mode 100644 index 09a25997..00000000 --- a/asm/main_0200E864.s +++ /dev/null @@ -1,256 +0,0 @@ - .include "asm/macros.inc" - .include "main_0200E864.inc" - - .text - - arm_func_start GetItemName -GetItemName: ; 0x0200E864 - stmdb sp!, {r3, lr} - bl EnsureValidItem -#if defined(EUROPE) - add r0, r0, #0x278 - add r0, r0, #0x1800 -#elif defined(JAPAN) - add r0, r0, #0x93 - add r0, r0, #0xd00 -#else - add r0, r0, #0x76 - add r0, r0, #0x1a00 -#endif - mov r0, r0, lsl #0x10 - mov r0, r0, lsr #0x10 - bl StringFromId - ldmia sp!, {r3, pc} - arm_func_end GetItemName - - arm_func_start GetItemNameFormatted -GetItemNameFormatted: ; 0x0200E884 -#ifdef EUROPE -#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic__0200E808_EU -#else -#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic__0200E990 -#endif - stmdb sp!, {r4, r5, r6, r7, r8, lr} - mov r7, r1 - mov r8, r0 - mov r0, r7 - mov r6, r2 - mov r5, r3 - bl EnsureValidItem -#if defined(EUROPE) - add r0, r0, #0x278 - add r0, r0, #0x1800 -#elif defined(JAPAN) - add r0, r0, #0x93 - add r0, r0, #0xd00 -#else - add r0, r0, #0x76 - add r0, r0, #0x1a00 -#endif - mov r0, r0, lsl #0x10 - mov r0, r0, lsr #0x10 - bl StringFromId - mov r4, r0 - mov r0, r7 - bl EnsureValidItem - ldr r1, _0200E97C ; =ITEM_DATA_TABLE_PTRS - cmp r5, #0 -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrb r1, [r0, #4] - bne _0200E8E8 - add r0, r1, #0xf4 - and r0, r0, #0xff - cmp r0, #2 - bhi _0200E914 -_0200E8E8: - cmp r6, #0 - beq _0200E904 - ldr r1, _0200E980 ; =_0209808C - mov r0, r8 - mov r2, r4 - bl GET_ITEM_NAME_FORMATTED_SPRINTF - ldmia sp!, {r4, r5, r6, r7, r8, pc} -_0200E904: - mov r0, r8 - mov r1, r4 - bl strcpy - ldmia sp!, {r4, r5, r6, r7, r8, pc} -_0200E914: - cmp r1, #0xf - bne _0200E94C - cmp r6, #0 - beq _0200E938 - ldr r1, _0200E984 ; =_0209809C - mov r0, r8 - mov r2, r4 - bl GET_ITEM_NAME_FORMATTED_SPRINTF - ldmia sp!, {r4, r5, r6, r7, r8, pc} -_0200E938: - ldr r1, _0200E988 ; =_020980AC - mov r0, r8 - mov r2, r4 - bl GET_ITEM_NAME_FORMATTED_SPRINTF - ldmia sp!, {r4, r5, r6, r7, r8, pc} -_0200E94C: - cmp r6, #0 - beq _0200E968 - ldr r1, _0200E98C ; =_020980B0 - mov r0, r8 - mov r2, r4 - bl GET_ITEM_NAME_FORMATTED_SPRINTF - ldmia sp!, {r4, r5, r6, r7, r8, pc} -_0200E968: - ldr r1, _0200E988 ; =_020980AC - mov r0, r8 - mov r2, r4 - bl GET_ITEM_NAME_FORMATTED_SPRINTF - ldmia sp!, {r4, r5, r6, r7, r8, pc} - .align 2, 0 -_0200E97C: .word ITEM_DATA_TABLE_PTRS -_0200E980: .word _0209808C -_0200E984: .word _0209809C -_0200E988: .word _020980AC -_0200E98C: .word _020980B0 - arm_func_end GetItemNameFormatted - -#ifndef EUROPE - arm_func_start SprintfStatic__0200E990 -SprintfStatic__0200E990: ; 0x0200E990 - stmdb sp!, {r0, r1, r2, r3} - stmdb sp!, {r3, lr} - add r2, sp, #0xc - bic r2, r2, #3 - ldr r1, [sp, #0xc] - add r2, r2, #4 - bl vsprintf - ldmia sp!, {r3, lr} - add sp, sp, #0x10 - bx lr - arm_func_end SprintfStatic__0200E990 -#endif - - arm_func_start GetItemBuyPrice -GetItemBuyPrice: ; 0x0200E9B8 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200E9D4 ; =ITEM_DATA_TABLE_PTRS - mov r0, r0, lsl #4 -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - ldrh r0, [r1, r0] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200E9D4: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemBuyPrice - - arm_func_start GetItemSellPrice -GetItemSellPrice: ; 0x0200E9D8 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200E9F4 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrh r0, [r0, #2] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200E9F4: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemSellPrice - - arm_func_start GetItemSpriteId -GetItemSpriteId: ; 0x0200E9F8 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200EA14 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrb r0, [r0, #5] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200EA14: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemSpriteId - - arm_func_start GetItemPaletteId -GetItemPaletteId: ; 0x0200EA18 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200EA34 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrb r0, [r0, #0xc] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200EA34: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemPaletteId - - arm_func_start GetItemActionName -GetItemActionName: ; 0x0200EA38 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200EA54 ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrb r0, [r0, #0xd] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200EA54: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemActionName - - arm_func_start GetThrownItemQuantityLimit -GetThrownItemQuantityLimit: ; 0x0200EA58 - stmdb sp!, {r4, lr} - mov r4, r1 - bl EnsureValidItem - ldr r1, _0200EA7C ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - add r0, r0, r4 - ldrb r0, [r0, #0xa] - ldmia sp!, {r4, pc} - .align 2, 0 -_0200EA7C: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetThrownItemQuantityLimit - - arm_func_start GetItemMoveId -GetItemMoveId: ; 0x0200EA80 - stmdb sp!, {r3, lr} - bl EnsureValidItem - ldr r1, _0200EA9C ; =ITEM_DATA_TABLE_PTRS -#ifdef EUROPE - ldr r1, [r1] -#else - ldr r1, [r1, #4] -#endif - add r0, r1, r0, lsl #4 - ldrsh r0, [r0, #8] - ldmia sp!, {r3, pc} - .align 2, 0 -_0200EA9C: .word ITEM_DATA_TABLE_PTRS - arm_func_end GetItemMoveId diff --git a/asm/main_rodata_020908D4.s b/asm/main_rodata_020908D4.s index 2eadeb39..99dea3cb 100644 --- a/asm/main_rodata_020908D4.s +++ b/asm/main_rodata_020908D4.s @@ -2933,19 +2933,19 @@ _02098070: .byte 0x45, 0x2F, 0x73, 0x74, 0x5F, 0x69, 0x32, 0x6E .byte 0x5F, 0x6A, 0x2E, 0x62, 0x69, 0x6E, 0x00, 0x00 #endif - .global _0209808C -_0209808C: + .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 - .global _0209809C -_0209809C: + .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 - .global _020980AC -_020980AC: + .global ITEM_NAME_FORMAT_PLAIN +ITEM_NAME_FORMAT_PLAIN: // "%s" .byte 0x25, 0x73, 0x00, 0x00 - .global _020980B0 -_020980B0: + .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 .global KECLEON_SHOP_ITEM_TABLE_LISTS_1 diff --git a/include/item.h b/include/item.h index ee09e50f..0ababff7 100644 --- a/include/item.h +++ b/include/item.h @@ -1649,9 +1649,15 @@ struct bag_items { struct item_data_entry { - /* 0x0 */ u8 *name; + /* 0x0 */ u16 buy_price; + /* 0x2 */ u16 sell_price; /* 0x4 */ enum item_category category; - u8 fill5[0xE - 0x5]; + /* 0x5 */ u8 sprite_id; + u8 fill5[0x8 - 0x6]; + /* 0x8 */ u16 move_id; + /* 0xA */ u8 quantity_limit[2]; + /* 0xC */ u8 palette_id; + /* 0xD */ u8 action_name; /* 0xE */ u8 flags; }; diff --git a/include/item_util_2.h b/include/item_util_2.h index dfe07a14..e0126e48 100644 --- a/include/item_util_2.h +++ b/include/item_util_2.h @@ -8,4 +8,23 @@ enum item_category GetItemCategory(s16 item_id); // Checks if the given item ID is valid (using IsItemValid). If so, return the given item ID. Otherwise, return ITEM_PLAIN_SEED. s16 EnsureValidItem(s16 item_id); +u8* GetItemName(s16 item_id); +void GetItemNameFormatted(char* name, s16 item_id, s32 arg2, s32 arg3); +u16 GetItemBuyPrice(s16 item_id); +u16 GetItemSellPrice(s16 item_id); +u8 GetItemSpriteId(s16 item_id); +u8 GetItemPaletteId(s16 item_id); +u8 GetItemActionName(s16 item_id); +u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1); +s16 GetItemMoveId(s16 item_id); + +// Returns a boolean indicating whether the item is consumable, throwable at an ally, or throwable at an enemy, depending on item_flag. +// The table used for this is inaccessible in the code, as it is loaded from a file in the ROM at runtime. +// Bit 7 in the table corresponds to ITEM_FLAG_CONSUMABLE, bit 6 to ITEM_FLAG_THROWABLE_AT_ALLY, and bit 5 to ITEM_FLAG_THROWABLE_AT_ENEMY. +// +// item_id: item_id enum +// flag: item_flag enum. Function will test a different allowed AI action depending on the value. +// return: bool +bool8 TestItemAiFlag(s16 item_id, s32 flag); + #endif //PMDSKY_ITEM_UTIL_2_H diff --git a/include/item_util_3.h b/include/item_util_3.h deleted file mode 100644 index 0f1f62cb..00000000 --- a/include/item_util_3.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef PMDSKY_ITEM_UTIL_3_H -#define PMDSKY_ITEM_UTIL_3_H - -#include "util.h" - -// Returns a boolean indicating whether the item is consumable, throwable at an ally, or throwable at an enemy, depending on item_flag. -// The table used for this is inaccessible in the code, as it is loaded from a file in the ROM at runtime. -// Bit 7 in the table corresponds to ITEM_FLAG_CONSUMABLE, bit 6 to ITEM_FLAG_THROWABLE_AT_ALLY, and bit 5 to ITEM_FLAG_THROWABLE_AT_ENEMY. -// -// item_id: item_id enum -// flag: item_flag enum. Function will test a different allowed AI action depending on the value. -// return: bool -bool8 TestItemAiFlag(s16 item_id, s32 flag); - -#endif //PMDSKY_ITEM_UTIL_3_H diff --git a/main.lsf b/main.lsf index bd4e3f11..e7167b54 100644 --- a/main.lsf +++ b/main.lsf @@ -41,8 +41,6 @@ Static main Object src/item_util_1.o Object asm/main_0200E7E8.o Object src/item_util_2.o - Object asm/main_0200E864.o - Object src/item_util_3.o Object asm/main_0200EB30.o Object src/main_0200ECFC.o Object asm/main_0200ED1C.o diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index be1135ba..770cfb71 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -12,7 +12,7 @@ #include "dungeon_util_static.h" #include "item.h" #include "item_util.h" -#include "item_util_3.h" +#include "item_util_2.h" #include "overlay_29_022E1610.h" #include "position_util.h" diff --git a/src/item_util_2.c b/src/item_util_2.c index 568ac53a..c0a7fa70 100644 --- a/src/item_util_2.c +++ b/src/item_util_2.c @@ -1,7 +1,19 @@ +#include "debug.h" #include "item_util_2.h" #include "item_util_1.h" +#include "main_0202593C.h" extern struct item_data_entry *ITEM_DATA_TABLE_PTRS[3]; +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 char* SprintfStatic__0200E808_EU(char*, const char*, ...); +extern u8* strcpy(u8*, u8*); +extern s32 vsprintf(u8* str, const u8* format, va_list ap); + +static void SprintfStatic(char*, const char*, ...); enum item_category GetItemCategory(s16 item_id) { @@ -19,3 +31,132 @@ s16 EnsureValidItem(s16 item_id) return item_id; } + +u8* GetItemName(s16 item_id) { + u32 valid_item_id = EnsureValidItem(item_id); +#ifdef EUROPE + return StringFromId((u16)(valid_item_id + 0x1A78)); +#elif JAPAN + return StringFromId((u16)(valid_item_id + 0x0D93)); +#else + return StringFromId((u16)(valid_item_id + 0x1A76)); +#endif +} + +#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; + +#ifdef EUROPE + u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x1A78)); +#elif JAPAN + u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x0D93)); +#else + u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x1A76)); +#endif + + category = ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][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); + return; + } + strcpy(name, raw_name); + return; + } + if (category == CATEGORY_EXCLUSIVE_ITEMS) { + if (flag1 != 0) { + GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_INDIGO, raw_name); + return; + } + GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); + return; + } + if (flag1 != 0) { + GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_CREAM, raw_name); + return; + + } + GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name); + return; +} + +#ifndef EUROPE +static void SprintfStatic(char* buf, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsprintf(buf, fmt, args); +} +#endif + +u16 GetItemBuyPrice(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].buy_price; +} + +u16 GetItemSellPrice(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].sell_price; +} + +u8 GetItemSpriteId(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].sprite_id; +} + +u8 GetItemPaletteId(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].palette_id; +} + +u8 GetItemActionName(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].action_name; +} + +u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].quantity_limit[arg1]; +} + +s16 GetItemMoveId(s16 item_id) +{ + item_id = EnsureValidItem(item_id); + return ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].move_id; +} + +bool8 TestItemAiFlag(s16 item_id, s32 flag) +{ + if (flag == 0) + { + item_id = EnsureValidItem(item_id); + if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ENEMY) + return TRUE; + return FALSE; + } + + if (flag == 1) + { + item_id = EnsureValidItem(item_id); + if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ALLY) + return TRUE; + return FALSE; + } + + item_id = EnsureValidItem(item_id); + if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_CONSUMABLE) + return TRUE; + return FALSE; +} diff --git a/src/item_util_3.c b/src/item_util_3.c deleted file mode 100644 index 25396342..00000000 --- a/src/item_util_3.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "item_util_3.h" -#include "item.h" -#include "item_util_2.h" - -extern struct item_data_entry *ITEM_DATA_TABLE_PTRS[3]; - -bool8 TestItemAiFlag(s16 item_id, s32 flag) -{ - if (flag == 0) - { - item_id = EnsureValidItem(item_id); - if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ENEMY) - return TRUE; - return FALSE; - } - - if (flag == 1) - { - item_id = EnsureValidItem(item_id); - if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ALLY) - return TRUE; - return FALSE; - } - - item_id = EnsureValidItem(item_id); - if (ITEM_DATA_TABLE_PTRS[ITEM_DATA_TABLE_PTRS_INDEX][item_id].flags & ITEM_DATA_FLAG_CONSUMABLE) - return TRUE; - return FALSE; -}