From 25c669e36b8d23a24da567007bda1210ad9ce97e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 29 Apr 2018 13:36:26 +0200 Subject: [PATCH] decompile item --- asm/battle_frontier_2.s | 2 +- asm/item.s | 1921 ------------------- asm/party_menu.s | 2 +- asm/pokemon_storage_system.s | 4 +- asm/pokemon_summary_screen.s | 4 +- asm/shop.s | 6 +- data/scripts/maps/MauvilleCity_BikeShop.inc | 2 +- data/specials.inc | 2 +- include/constants/items.h | 10 +- include/global.h | 74 +- include/item.h | 24 +- include/item_menu.h | 2 +- include/secret_base.h | 1 + ld_script.txt | 1 - src/item.c | 1033 +++++++++- src/item_menu.c | 40 +- src/lilycove_lady.c | 4 +- src/player_pc.c | 12 +- src/pokeblock.c | 2 +- src/pokemon_summary_screen.c | 4 +- src/tv.c | 24 +- 21 files changed, 1083 insertions(+), 2091 deletions(-) delete mode 100644 asm/item.s diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 491a87948..84228bc2d 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -12985,7 +12985,7 @@ _081A10F4: adds r1, r0 adds r1, 0xBA ldrh r0, [r1] - bl ItemId_GetItem + bl ItemId_GetName adds r1, r0, 0 b _081A1174 .pool diff --git a/asm/item.s b/asm/item.s deleted file mode 100644 index 89177c5d4..000000000 --- a/asm/item.s +++ /dev/null @@ -1,1921 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start CheckBagHasSpace -CheckBagHasSpace: @ 80D6800 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - lsls r1, 16 - lsrs r5, r1, 16 - bl ItemId_GetPocket - lsls r0, 24 - cmp r0, 0 - beq _080D6906 - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - bne _080D6838 - ldr r0, =0x00004004 - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080D684C -_080D6838: - mov r0, r8 - adds r1, r5, 0 - bl CheckPyramidBagHasSpace - lsls r0, 24 - lsrs r0, 24 - b _080D6916 - .pool -_080D684C: - mov r0, r8 - bl ItemId_GetPocket - subs r0, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - ldr r7, =0x000003e7 - cmp r2, 0x3 - beq _080D6860 - movs r7, 0x63 -_080D6860: - movs r6, 0 - ldr r1, =gBagPockets - lsls r4, r2, 3 - adds r0, r4, r1 - mov r9, r4 - ldrb r0, [r0, 0x4] - cmp r6, r0 - bcs _080D68BC - subs r0, r2, 0x2 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 -_080D6878: - adds r0, r4, r1 - ldr r1, [r0] - lsls r0, r6, 2 - adds r1, r0, r1 - ldrh r0, [r1] - cmp r0, r8 - bne _080D68AC - adds r0, r1, 0x2 - str r2, [sp] - bl GetBagItemQuantity - lsls r0, 16 - lsrs r1, r0, 16 - adds r0, r1, r5 - ldr r2, [sp] - cmp r0, r7 - ble _080D6914 - mov r0, r10 - cmp r0, 0x1 - bls _080D6906 - subs r0, r7, r1 - subs r0, r5, r0 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0 - beq _080D6914 -_080D68AC: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - ldr r1, =gBagPockets - adds r0, r4, r1 - ldrb r0, [r0, 0x4] - cmp r6, r0 - bcc _080D6878 -_080D68BC: - cmp r5, 0 - beq _080D6914 - movs r6, 0 - ldr r3, =gBagPockets - mov r1, r9 - adds r0, r1, r3 - ldrb r0, [r0, 0x4] - cmp r6, r0 - bcs _080D6902 - adds r4, r3, 0 - subs r0, r2, 0x2 - lsls r0, 24 - lsrs r2, r0, 24 -_080D68D6: - adds r0, r1, r4 - ldr r1, [r0] - lsls r0, r6, 2 - adds r0, r1 - ldrh r0, [r0] - cmp r0, 0 - bne _080D68F2 - cmp r5, r7 - bls _080D6914 - cmp r2, 0x1 - bls _080D6906 - subs r0, r5, r7 - lsls r0, 16 - lsrs r5, r0, 16 -_080D68F2: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - mov r1, r9 - adds r0, r1, r3 - ldrb r0, [r0, 0x4] - cmp r6, r0 - bcc _080D68D6 -_080D6902: - cmp r5, 0 - beq _080D6914 -_080D6906: - movs r0, 0 - b _080D6916 - .pool -_080D6914: - movs r0, 0x1 -_080D6916: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end CheckBagHasSpace - - thumb_func_start AddBagItem -@ int AddBagItem(int item_id, int quantity) -AddBagItem: @ 80D6928 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - lsls r1, 16 - lsrs r5, r1, 16 - bl ItemId_GetPocket - lsls r0, 24 - cmp r0, 0 - bne _080D694C - movs r0, 0 - b _080D6A92 -_080D694C: - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - bne _080D6964 - ldr r0, =0x00004004 - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080D6978 -_080D6964: - mov r0, r9 - adds r1, r5, 0 - bl AddPyramidBagItem - lsls r0, 24 - lsrs r0, 24 - b _080D6A92 - .pool -_080D6978: - mov r0, r9 - bl ItemId_GetPocket - subs r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - lsls r1, r0, 3 - ldr r0, =gBagPockets - adds r7, r1, r0 - ldrb r0, [r7, 0x4] - lsls r0, 2 - bl AllocZeroed - mov r8, r0 - ldr r1, [r7] - ldrb r2, [r7, 0x4] - lsls r2, 2 - bl memcpy - ldr r2, =0x000003e7 - mov r0, r10 - cmp r0, 0x3 - beq _080D69AA - movs r2, 0x63 -_080D69AA: - movs r6, 0 - ldrb r0, [r7, 0x4] - cmp r6, r0 - bcs _080D6A06 - mov r0, r10 - subs r0, 0x2 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] -_080D69BC: - lsls r0, r6, 2 - mov r3, r8 - adds r1, r0, r3 - ldrh r0, [r1] - cmp r0, r9 - bne _080D69FA - adds r4, r1, 0x2 - adds r0, r4, 0 - str r2, [sp, 0x4] - bl GetBagItemQuantity - lsls r0, 16 - lsrs r0, 16 - adds r1, r0, r5 - ldr r2, [sp, 0x4] - cmp r1, r2 - ble _080D6A68 - ldr r1, [sp] - cmp r1, 0x1 - bls _080D6A74 - subs r0, r2, r0 - subs r0, r5, r0 - lsls r0, 16 - lsrs r5, r0, 16 - adds r0, r4, 0 - adds r1, r2, 0 - bl SetBagItemQuantity - ldr r2, [sp, 0x4] - cmp r5, 0 - beq _080D6A7E -_080D69FA: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - ldrb r0, [r7, 0x4] - cmp r6, r0 - bcc _080D69BC -_080D6A06: - cmp r5, 0 - beq _080D6A7E - movs r6, 0 - cmp r6, r0 - bcs _080D6A62 - mov r0, r10 - subs r0, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 -_080D6A18: - lsls r0, r6, 2 - mov r3, r8 - adds r1, r0, r3 - ldrh r0, [r1] - cmp r0, 0 - bne _080D6A56 - mov r0, r9 - strh r0, [r1] - cmp r5, r2 - bhi _080D6A40 - adds r0, r1, 0x2 - adds r1, r5, 0 - bl SetBagItemQuantity - b _080D6A7E - .pool -_080D6A40: - cmp r4, 0x1 - bls _080D6A74 - subs r0, r5, r2 - lsls r0, 16 - lsrs r5, r0, 16 - adds r0, r1, 0x2 - adds r1, r2, 0 - str r2, [sp, 0x4] - bl SetBagItemQuantity - ldr r2, [sp, 0x4] -_080D6A56: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - ldrb r1, [r7, 0x4] - cmp r6, r1 - bcc _080D6A18 -_080D6A62: - cmp r5, 0 - beq _080D6A7E - b _080D6A74 -_080D6A68: - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl SetBagItemQuantity - b _080D6A7E -_080D6A74: - mov r0, r8 - bl Free - movs r0, 0 - b _080D6A92 -_080D6A7E: - ldr r0, [r7] - ldrb r2, [r7, 0x4] - lsls r2, 2 - mov r1, r8 - bl memcpy - mov r0, r8 - bl Free - movs r0, 0x1 -_080D6A92: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end AddBagItem - - thumb_func_start RemoveBagItem -@ pokescrcmd -RemoveBagItem: @ 80D6AA4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - lsls r1, 16 - lsrs r7, r1, 16 - movs r4, 0 - bl ItemId_GetPocket - lsls r0, 24 - cmp r0, 0 - beq _080D6B38 - mov r0, r8 - cmp r0, 0 - beq _080D6B38 - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - bne _080D6AE0 - ldr r0, =0x00004004 - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080D6AF4 -_080D6AE0: - mov r0, r8 - adds r1, r7, 0 - bl RemovePyramidBagItem - lsls r0, 24 - lsrs r0, 24 - b _080D6C5A - .pool -_080D6AF4: - mov r0, r8 - bl ItemId_GetPocket - subs r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r1, r0, 3 - ldr r0, =gBagPockets - adds r5, r1, r0 - movs r6, 0 - ldrb r2, [r5, 0x4] - cmp r6, r2 - bcs _080D6B34 -_080D6B10: - ldr r0, [r5] - lsls r1, r6, 2 - adds r1, r0 - ldrh r0, [r1] - cmp r0, r8 - bne _080D6B28 - adds r0, r1, 0x2 - bl GetBagItemQuantity - adds r0, r4, r0 - lsls r0, 16 - lsrs r4, r0, 16 -_080D6B28: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - ldrb r0, [r5, 0x4] - cmp r6, r0 - bcc _080D6B10 -_080D6B34: - cmp r4, r7 - bcs _080D6B40 -_080D6B38: - movs r0, 0 - b _080D6C5A - .pool -_080D6B40: - bl CurrentMapIsSecretBase - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080D6B70 - ldr r4, =0x000040ee - adds r0, r4, 0 - bl VarGet - adds r1, r0, 0 - movs r2, 0x80 - lsls r2, 2 - adds r0, r2, 0 - orrs r1, r0 - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl VarSet - ldr r0, =0x000040ed - mov r1, r8 - bl VarSet -_080D6B70: - mov r0, r9 - bl sub_81ABB2C - lsls r0, 24 - lsrs r1, r0, 24 - ldrb r0, [r5, 0x4] - cmp r0, r1 - bls _080D6BE6 - ldr r0, [r5] - lsls r1, 2 - adds r2, r1, r0 - ldrh r0, [r2] - adds r4, r1, 0 - cmp r0, r8 - bne _080D6BE6 - adds r0, r2, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, r7 - bcc _080D6BB8 - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - subs r1, r7 - lsls r1, 16 - lsrs r1, 16 - bl SetBagItemQuantity - movs r7, 0 - b _080D6BCA - .pool -_080D6BB8: - subs r0, r7, r1 - lsls r0, 16 - lsrs r7, r0, 16 - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - movs r1, 0 - bl SetBagItemQuantity -_080D6BCA: - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0 - bne _080D6BE2 - ldr r0, [r5] - adds r0, r4, r0 - strh r2, [r0] -_080D6BE2: - cmp r7, 0 - beq _080D6C58 -_080D6BE6: - movs r6, 0 - ldrb r0, [r5, 0x4] - cmp r6, r0 - bcs _080D6C58 -_080D6BEE: - ldr r0, [r5] - lsls r1, r6, 2 - adds r2, r1, r0 - ldrh r0, [r2] - adds r4, r1, 0 - cmp r0, r8 - bne _080D6C4C - adds r0, r2, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, r7 - bcc _080D6C1E - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - subs r1, r7 - lsls r1, 16 - lsrs r1, 16 - bl SetBagItemQuantity - movs r7, 0 - b _080D6C30 -_080D6C1E: - subs r0, r7, r1 - lsls r0, 16 - lsrs r7, r0, 16 - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - movs r1, 0 - bl SetBagItemQuantity -_080D6C30: - ldr r0, [r5] - adds r0, r4 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0 - bne _080D6C48 - ldr r0, [r5] - adds r0, r4, r0 - strh r2, [r0] -_080D6C48: - cmp r7, 0 - beq _080D6C58 -_080D6C4C: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - ldrb r2, [r5, 0x4] - cmp r6, r2 - bcc _080D6BEE -_080D6C58: - movs r0, 0x1 -_080D6C5A: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end RemoveBagItem - - thumb_func_start GetPocketByItemId -GetPocketByItemId: @ 80D6C68 - push {lr} - lsls r0, 16 - lsrs r0, 16 - bl ItemId_GetPocket - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - thumb_func_end GetPocketByItemId - - thumb_func_start ClearItemSlots -ClearItemSlots: @ 80D6C7C - push {r4-r7,lr} - adds r6, r0, 0 - lsls r1, 24 - movs r4, 0 - lsrs r1, 24 - cmp r4, r1 - bcs _080D6CA6 - adds r5, r1, 0 - movs r7, 0 -_080D6C8E: - lsls r0, r4, 2 - adds r0, r6 - strh r7, [r0] - adds r0, 0x2 - movs r1, 0 - bl SetBagItemQuantity - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, r5 - bcc _080D6C8E -_080D6CA6: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end ClearItemSlots - - thumb_func_start sub_80D6CAC -sub_80D6CAC: @ 80D6CAC - push {lr} - movs r1, 0 - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - movs r3, 0x93 - lsls r3, 3 -_080D6CB8: - lsls r0, r1, 24 - asrs r1, r0, 24 - lsls r0, r1, 2 - adds r0, r2, r0 - adds r0, r3 - ldrh r0, [r0] - cmp r0, 0 - bne _080D6CD0 - adds r0, r1, 0 - b _080D6CE0 - .pool -_080D6CD0: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - asrs r0, 24 - cmp r0, 0x31 - ble _080D6CB8 - movs r0, 0x1 - negs r0, r0 -_080D6CE0: - pop {r1} - bx r1 - thumb_func_end sub_80D6CAC - - thumb_func_start sub_80D6CE4 -sub_80D6CE4: @ 80D6CE4 - push {r4,lr} - movs r2, 0 - movs r1, 0 - ldr r0, =gSaveBlock1Ptr - ldr r3, [r0] - movs r4, 0x93 - lsls r4, 3 -_080D6CF2: - lsls r0, r1, 2 - adds r0, r3, r0 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0 - beq _080D6D04 - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 -_080D6D04: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x31 - bls _080D6CF2 - adds r0, r2, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80D6CE4 - - thumb_func_start CheckPCHasItem -CheckPCHasItem: @ 80D6D1C - push {r4-r6,lr} - lsls r0, 16 - lsrs r6, r0, 16 - lsls r1, 16 - lsrs r5, r1, 16 - movs r4, 0 -_080D6D28: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - lsls r1, r4, 2 - adds r0, r2, r1 - movs r3, 0x93 - lsls r3, 3 - adds r0, r3 - ldrh r0, [r0] - cmp r0, r6 - bne _080D6D5C - adds r0, r1, r2 - ldr r1, =0x0000049a - adds r0, r1 - bl GetBagItemId - lsls r0, 16 - lsrs r0, 16 - cmp r0, r5 - bcc _080D6D5C - movs r0, 0x1 - b _080D6D68 - .pool -_080D6D5C: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x31 - bls _080D6D28 - movs r0, 0 -_080D6D68: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end CheckPCHasItem - - thumb_func_start AddPCItem -AddPCItem: @ 80D6D70 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - lsls r1, 16 - lsrs r5, r1, 16 - movs r0, 0xC8 - bl AllocZeroed - adds r7, r0, 0 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0x93 - lsls r0, 3 - adds r1, r0 - adds r0, r7, 0 - movs r2, 0xC8 - bl memcpy - movs r6, 0 -_080D6D9C: - lsls r0, r6, 2 - adds r1, r0, r7 - ldrh r0, [r1] - cmp r0, r8 - bne _080D6DD0 - adds r4, r1, 0x2 - adds r0, r4, 0 - bl GetBagItemId - lsls r0, 16 - lsrs r2, r0, 16 - adds r1, r2, r5 - ldr r3, =0x000003e7 - cmp r1, r3 - ble _080D6E04 - ldr r1, =0x0000fc19 - adds r0, r5, r1 - adds r0, r2, r0 - lsls r0, 16 - lsrs r5, r0, 16 - adds r0, r4, 0 - adds r1, r3, 0 - bl SetBagItemId - cmp r5, 0 - beq _080D6E20 -_080D6DD0: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0x31 - bls _080D6D9C - cmp r5, 0 - beq _080D6E20 - bl sub_80D6CAC - lsls r0, 24 - asrs r1, r0, 24 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - bne _080D6E10 - adds r0, r7, 0 - bl Free - movs r0, 0 - b _080D6E3A - .pool -_080D6E04: - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl SetBagItemId - b _080D6E20 -_080D6E10: - lsls r0, r1, 2 - adds r0, r7 - mov r1, r8 - strh r1, [r0] - adds r0, 0x2 - adds r1, r5, 0 - bl SetBagItemId -_080D6E20: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0x93 - lsls r1, 3 - adds r0, r1 - adds r1, r7, 0 - movs r2, 0xC8 - bl memcpy - adds r0, r7, 0 - bl Free - movs r0, 0x1 -_080D6E3A: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end AddPCItem - - thumb_func_start sub_80D6E48 -sub_80D6E48: @ 80D6E48 - push {lr} - lsls r0, 24 - lsls r1, 16 - lsrs r1, 16 - ldr r2, =gSaveBlock1Ptr - ldr r2, [r2] - lsrs r0, 22 - adds r3, r2, r0 - ldr r0, =0x0000049a - adds r2, r3, r0 - ldrh r0, [r2] - subs r0, r1 - strh r0, [r2] - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _080D6E76 - movs r2, 0x93 - lsls r2, 3 - adds r0, r3, r2 - strh r1, [r0] - bl sub_80D6E84 -_080D6E76: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D6E48 - - thumb_func_start sub_80D6E84 -sub_80D6E84: @ 80D6E84 - push {r4-r7,lr} - movs r2, 0 -_080D6E88: - adds r1, r2, 0x1 - lsls r0, r1, 16 - lsrs r4, r0, 16 - adds r6, r1, 0 - cmp r4, 0x31 - bhi _080D6ECA - ldr r0, =gSaveBlock1Ptr - mov r12, r0 - lsls r5, r2, 2 - movs r7, 0x93 - lsls r7, 3 -_080D6E9E: - mov r0, r12 - ldr r1, [r0] - adds r0, r1, r5 - adds r0, r7 - ldrh r0, [r0] - cmp r0, 0 - bne _080D6EC0 - movs r0, 0x93 - lsls r0, 3 - adds r1, r0 - adds r2, r1, r5 - ldr r3, [r2] - lsls r0, r4, 2 - adds r1, r0 - ldr r0, [r1] - str r0, [r2] - str r3, [r1] -_080D6EC0: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x31 - bls _080D6E9E -_080D6ECA: - lsls r0, r6, 16 - lsrs r2, r0, 16 - cmp r2, 0x30 - bls _080D6E88 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D6E84 - - thumb_func_start sub_80D6EDC -sub_80D6EDC: @ 80D6EDC - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r2, =0x00000496 - adds r1, r0, r2 - ldrh r2, [r1] - ldr r3, =0x00000103 - cmp r2, r3 - beq _080D6F04 - movs r0, 0x88 - lsls r0, 1 - cmp r2, r0 - beq _080D6F0C - b _080D6F0E - .pool -_080D6F04: - movs r0, 0x88 - lsls r0, 1 - strh r0, [r1] - b _080D6F0E -_080D6F0C: - strh r3, [r1] -_080D6F0E: - pop {r0} - bx r0 - thumb_func_end sub_80D6EDC - - thumb_func_start BagGetItemIdByPocketPosition -@ int BagGetItemIdByPocketPosition(int pocket_id_plus_1, int item_index_in_pocket) -BagGetItemIdByPocketPosition: @ 80D6F14 - lsls r0, 24 - lsls r1, 16 - ldr r2, =gBagPockets - lsrs r0, 21 - subs r0, 0x8 - adds r0, r2 - ldr r0, [r0] - lsrs r1, 14 - adds r1, r0 - ldrh r0, [r1] - bx lr - .pool - thumb_func_end BagGetItemIdByPocketPosition - - thumb_func_start BagGetQuantityByPocketPosition -@ int BagGetQuantityByPocketPosition(int pocket_id_plus_1, int item_index_in_pocket) -BagGetQuantityByPocketPosition: @ 80D6F30 - push {lr} - lsls r0, 24 - lsls r1, 16 - ldr r2, =gBagPockets - lsrs r0, 21 - subs r0, 0x8 - adds r0, r2 - lsrs r1, 14 - ldr r0, [r0] - adds r0, r1 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsrs r0, 16 - pop {r1} - bx r1 - .pool - thumb_func_end BagGetQuantityByPocketPosition - - thumb_func_start swap32 -swap32: @ 80D6F58 - ldr r3, [r0] - ldr r2, [r1] - str r2, [r0] - str r3, [r1] - bx lr - thumb_func_end swap32 - - thumb_func_start sub_80D6F64 -sub_80D6F64: @ 80D6F64 - push {r4-r7,lr} - adds r6, r0, 0 - movs r3, 0 - b _080D6FA6 -_080D6F6C: - adds r1, r3, 0x1 - lsls r0, r1, 16 - lsrs r4, r0, 16 - adds r7, r1, 0 - cmp r4, r2 - bcs _080D6FA2 - lsls r5, r3, 2 -_080D6F7A: - ldr r0, [r6] - adds r0, r5 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - cmp r0, 0 - bne _080D6F96 - ldr r1, [r6] - adds r0, r1, r5 - lsls r2, r4, 2 - adds r1, r2 - bl swap32 -_080D6F96: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - ldrb r0, [r6, 0x4] - cmp r4, r0 - bcc _080D6F7A -_080D6FA2: - lsls r0, r7, 16 - lsrs r3, r0, 16 -_080D6FA6: - ldrb r2, [r6, 0x4] - subs r0, r2, 0x1 - cmp r3, r0 - blt _080D6F6C - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80D6F64 - - thumb_func_start sub_80D6FB4 -sub_80D6FB4: @ 80D6FB4 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r6, r0, 0 - movs r3, 0 - b _080D701A -_080D6FC0: - adds r1, r3, 0x1 - lsls r0, r1, 16 - lsrs r5, r0, 16 - mov r8, r1 - cmp r5, r2 - bcs _080D7014 - lsls r7, r3, 2 -_080D6FCE: - ldr r0, [r6] - adds r0, r7 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - lsls r4, r5, 2 - cmp r0, 0 - beq _080D6FFE - ldr r0, [r6] - adds r0, r4 - adds r0, 0x2 - bl GetBagItemQuantity - lsls r0, 16 - cmp r0, 0 - beq _080D7008 - ldr r0, [r6] - adds r1, r7, r0 - adds r0, r4, r0 - ldrh r1, [r1] - ldrh r0, [r0] - cmp r1, r0 - bls _080D7008 -_080D6FFE: - ldr r1, [r6] - adds r0, r1, r7 - adds r1, r4 - bl swap32 -_080D7008: - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - ldrb r0, [r6, 0x4] - cmp r5, r0 - bcc _080D6FCE -_080D7014: - mov r1, r8 - lsls r0, r1, 16 - lsrs r3, r0, 16 -_080D701A: - ldrb r2, [r6, 0x4] - subs r0, r2, 0x1 - cmp r3, r0 - blt _080D6FC0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80D6FB4 - - thumb_func_start sub_80D702C -sub_80D702C: @ 80D702C - push {r4-r6,lr} - adds r4, r0, 0 - adds r3, r2, 0 - cmp r1, r3 - beq _080D708C - lsls r0, r1, 2 - adds r0, r4 - ldr r6, [r0] - cmp r3, r1 - bls _080D7064 - subs r3, 0x1 - lsls r1, 16 - lsls r0, r3, 16 - asrs r2, r0, 16 - cmp r1, r0 - bge _080D7086 - adds r5, r2, 0 -_080D704E: - asrs r2, r1, 16 - lsls r0, r2, 2 - adds r0, r4 - ldr r1, [r0, 0x4] - str r1, [r0] - adds r2, 0x1 - lsls r1, r2, 16 - asrs r0, r1, 16 - cmp r0, r5 - blt _080D704E - b _080D7086 -_080D7064: - lsls r1, 16 - lsls r0, r3, 16 - asrs r2, r0, 16 - cmp r1, r0 - ble _080D7086 - adds r5, r2, 0 -_080D7070: - asrs r2, r1, 16 - lsls r1, r2, 2 - adds r1, r4 - subs r0, r1, 0x4 - ldr r0, [r0] - str r0, [r1] - subs r2, 0x1 - lsls r1, r2, 16 - asrs r0, r1, 16 - cmp r0, r5 - bgt _080D7070 -_080D7086: - lsls r0, r3, 2 - adds r0, r4 - str r6, [r0] -_080D708C: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80D702C - - thumb_func_start ClearBag -ClearBag: @ 80D7094 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gBagPockets -_080D709A: - lsls r1, r4, 3 - adds r1, r5 - ldr r0, [r1] - ldrb r1, [r1, 0x4] - bl ClearItemSlots - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x4 - bls _080D709A - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end ClearBag - - thumb_func_start CountTotalItemQuantityInBag -@ u16 CountTotalItemQuantityInBag(u16 itemId) -CountTotalItemQuantityInBag: @ 80D70BC - push {r4-r7,lr} - lsls r0, 16 - lsrs r6, r0, 16 - movs r7, 0 - adds r0, r6, 0 - bl ItemId_GetPocket - lsls r0, 24 - lsrs r0, 21 - ldr r1, =gUnknown_02039DD0 - adds r5, r0, r1 - movs r4, 0 - ldrb r0, [r5, 0x4] - cmp r7, r0 - bcs _080D70FE -_080D70DA: - ldr r0, [r5] - lsls r1, r4, 2 - adds r1, r0 - ldrh r0, [r1] - cmp r0, r6 - bne _080D70F2 - adds r0, r1, 0x2 - bl GetBagItemQuantity - adds r0, r7, r0 - lsls r0, 16 - lsrs r7, r0, 16 -_080D70F2: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - ldrb r0, [r5, 0x4] - cmp r4, r0 - bcc _080D70DA -_080D70FE: - adds r0, r7, 0 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end CountTotalItemQuantityInBag - - thumb_func_start CheckPyramidBagHasItem -CheckPyramidBagHasItem: @ 80D710C - push {r4,r5,lr} - lsls r0, 16 - lsrs r5, r0, 16 - lsls r1, 16 - lsrs r4, r1, 16 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r1, =0x00000ca9 - adds r0, r3, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r2, r1, 30 - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 2 - ldr r2, =0x00000e2c - adds r0, r2 - adds r2, r3, r0 - lsrs r1, 30 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 1 - ldr r1, =0x00000e54 - adds r0, r1 - adds r3, r0 - movs r1, 0 -_080D7140: - lsls r0, r1, 1 - adds r0, r2 - ldrh r0, [r0] - cmp r0, r5 - bne _080D7170 - adds r0, r3, r1 - ldrb r0, [r0] - cmp r0, r4 - bcs _080D715C - subs r0, r4, r0 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - bne _080D7170 -_080D715C: - movs r0, 0x1 - b _080D717C - .pool -_080D7170: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x9 - bls _080D7140 - movs r0, 0 -_080D717C: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end CheckPyramidBagHasItem - - thumb_func_start CheckPyramidBagHasSpace -CheckPyramidBagHasSpace: @ 80D7184 - push {r4,r5,lr} - lsls r0, 16 - lsrs r5, r0, 16 - lsls r1, 16 - lsrs r4, r1, 16 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r1, =0x00000ca9 - adds r0, r3, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r2, r1, 30 - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 2 - ldr r2, =0x00000e2c - adds r0, r2 - adds r2, r3, r0 - lsrs r1, 30 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 1 - ldr r1, =0x00000e54 - adds r0, r1 - adds r3, r0 - movs r1, 0 -_080D71B8: - lsls r0, r1, 1 - adds r0, r2 - ldrh r0, [r0] - cmp r0, r5 - beq _080D71C6 - cmp r0, 0 - bne _080D71F0 -_080D71C6: - adds r0, r3, r1 - ldrb r0, [r0] - adds r0, r4 - cmp r0, 0x63 - ble _080D71DA - subs r0, 0x63 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - bne _080D71F0 -_080D71DA: - movs r0, 0x1 - b _080D71FC - .pool -_080D71F0: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x9 - bls _080D71B8 - movs r0, 0 -_080D71FC: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end CheckPyramidBagHasSpace - - thumb_func_start AddPyramidBagItem -AddPyramidBagItem: @ 80D7204 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 16 - lsrs r7, r0, 16 - lsls r1, 16 - lsrs r4, r1, 16 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r1, =0x00000ca9 - adds r0, r3, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r2, r1, 30 - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 2 - ldr r2, =0x00000e2c - adds r0, r2 - adds r0, r3 - mov r9, r0 - lsrs r1, 30 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 1 - ldr r1, =0x00000e54 - adds r0, r1 - adds r3, r0 - mov r8, r3 - movs r0, 0x14 - bl Alloc - adds r5, r0, 0 - movs r0, 0xA - bl Alloc - adds r6, r0, 0 - adds r0, r5, 0 - mov r1, r9 - movs r2, 0x14 - bl memcpy - adds r0, r6, 0 - mov r1, r8 - movs r2, 0xA - bl memcpy - movs r2, 0 -_080D7266: - lsls r0, r2, 1 - adds r0, r5 - ldrh r0, [r0] - cmp r0, r7 - bne _080D72AA - adds r1, r6, r2 - ldrb r0, [r1] - cmp r0, 0x62 - bhi _080D72AA - adds r0, r4 - strb r0, [r1] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x63 - bls _080D72A4 - ldrb r0, [r1] - subs r0, 0x63 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x63 - strb r0, [r1] - b _080D72A6 - .pool -_080D72A4: - movs r4, 0 -_080D72A6: - cmp r4, 0 - beq _080D7304 -_080D72AA: - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x9 - bls _080D7266 - cmp r4, 0 - beq _080D7304 - movs r2, 0 -_080D72BA: - lsls r0, r2, 1 - adds r1, r0, r5 - ldrh r0, [r1] - cmp r0, 0 - bne _080D72E6 - strh r7, [r1] - adds r1, r6, r2 - strb r4, [r1] - lsls r0, r4, 24 - lsrs r0, 24 - cmp r0, 0x63 - bls _080D72E0 - ldrb r0, [r1] - subs r0, 0x63 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x63 - strb r0, [r1] - b _080D72E2 -_080D72E0: - movs r4, 0 -_080D72E2: - cmp r4, 0 - beq _080D7304 -_080D72E6: - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x9 - bls _080D72BA - cmp r4, 0 - beq _080D7304 - adds r0, r5, 0 - bl Free - adds r0, r6, 0 - bl Free - movs r0, 0 - b _080D7326 -_080D7304: - mov r0, r9 - adds r1, r5, 0 - movs r2, 0x14 - bl memcpy - mov r0, r8 - adds r1, r6, 0 - movs r2, 0xA - bl memcpy - adds r0, r5, 0 - bl Free - adds r0, r6, 0 - bl Free - movs r0, 0x1 -_080D7326: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end AddPyramidBagItem - - thumb_func_start RemovePyramidBagItem -RemovePyramidBagItem: @ 80D7334 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - lsls r1, 16 - lsrs r4, r1, 16 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r1, =0x00000ca9 - adds r0, r3, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r2, r1, 30 - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 2 - ldr r2, =0x00000e2c - adds r0, r2 - adds r0, r3 - mov r8, r0 - lsrs r1, 30 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 1 - ldr r1, =0x00000e54 - adds r0, r1 - adds r7, r3, r0 - ldr r1, =gUnknown_0203CF30 - ldrh r0, [r1, 0x8] - ldrh r1, [r1, 0x6] - adds r0, r1 - lsls r0, 16 - lsrs r2, r0, 16 - lsls r0, r2, 1 - mov r1, r8 - adds r3, r0, r1 - ldrh r0, [r3] - cmp r0, r9 - bne _080D73B4 - adds r1, r7, r2 - ldrb r0, [r1] - cmp r0, r4 - bcc _080D73B4 - subs r0, r4 - strb r0, [r1] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0 - bne _080D744C - strh r0, [r3] - b _080D744C - .pool -_080D73B4: - movs r0, 0x14 - bl Alloc - adds r5, r0, 0 - movs r0, 0xA - bl Alloc - adds r6, r0, 0 - adds r0, r5, 0 - mov r1, r8 - movs r2, 0x14 - bl memcpy - adds r0, r6, 0 - adds r1, r7, 0 - movs r2, 0xA - bl memcpy - movs r2, 0 -_080D73DA: - lsls r0, r2, 1 - adds r3, r0, r5 - ldrh r0, [r3] - cmp r0, r9 - bne _080D740E - adds r1, r6, r2 - ldrb r0, [r1] - cmp r0, r4 - bcc _080D73FC - subs r0, r4 - strb r0, [r1] - movs r4, 0 - lsls r0, 24 - cmp r0, 0 - bne _080D740A - strh r4, [r3] - b _080D740A -_080D73FC: - subs r0, r4, r0 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0 - strb r0, [r1] - movs r0, 0 - strh r0, [r3] -_080D740A: - cmp r4, 0 - beq _080D742C -_080D740E: - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x9 - bls _080D73DA - cmp r4, 0 - beq _080D742C - adds r0, r5, 0 - bl Free - adds r0, r6, 0 - bl Free - movs r0, 0 - b _080D744E -_080D742C: - mov r0, r8 - adds r1, r5, 0 - movs r2, 0x14 - bl memcpy - adds r0, r7, 0 - adds r1, r6, 0 - movs r2, 0xA - bl memcpy - adds r0, r5, 0 - bl Free - adds r0, r6, 0 - bl Free -_080D744C: - movs r0, 0x1 -_080D744E: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end RemovePyramidBagItem - - thumb_func_start SanitizeItemId -SanitizeItemId: @ 80D745C - push {lr} - lsls r0, 16 - lsrs r1, r0, 16 - movs r0, 0xBC - lsls r0, 1 - cmp r1, r0 - bhi _080D746E - adds r0, r1, 0 - b _080D7470 -_080D746E: - movs r0, 0 -_080D7470: - pop {r1} - bx r1 - thumb_func_end SanitizeItemId - - thumb_func_start ItemId_GetItem -@ item *ItemId_GetItem(s16 itemId) -ItemId_GetItem: @ 80D7474 - push {lr} - lsls r0, 16 - lsrs r0, 16 - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - ldr r1, =gItems - adds r0, r1 - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetItem - - thumb_func_start itemid_get_number -itemid_get_number: @ 80D7494 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrh r0, [r0, 0xE] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end itemid_get_number - - thumb_func_start itemid_get_market_price -itemid_get_market_price: @ 80D74B8 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrh r0, [r0, 0x10] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end itemid_get_market_price - - thumb_func_start ItemId_GetHoldEffect -ItemId_GetHoldEffect: @ 80D74DC - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x12] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetHoldEffect - - thumb_func_start ItemId_GetHoldEffectParam -ItemId_GetHoldEffectParam: @ 80D7500 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x13] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetHoldEffectParam - - thumb_func_start ItemId_GetDescription -ItemId_GetDescription: @ 80D7524 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r4, 0x14 - adds r0, r4 - ldr r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetDescription - - thumb_func_start itemid_is_unique -itemid_is_unique: @ 80D7548 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x18] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end itemid_is_unique - - thumb_func_start itemid_get_x19 -itemid_get_x19: @ 80D756C - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x19] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end itemid_get_x19 - - thumb_func_start ItemId_GetPocket -ItemId_GetPocket: @ 80D7590 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x1A] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetPocket - - thumb_func_start ItemId_GetType -ItemId_GetType: @ 80D75B4 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - ldrb r0, [r0, 0x1B] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetType - - thumb_func_start ItemId_GetFieldFunc -ItemId_GetFieldFunc: @ 80D75D8 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r4, 0x1C - adds r0, r4 - ldr r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetFieldFunc - - thumb_func_start ItemId_GetBattleUsage -ItemId_GetBattleUsage: @ 80D75FC - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - adds r0, 0x20 - ldrb r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetBattleUsage - - thumb_func_start ItemId_GetBattleFunc -ItemId_GetBattleFunc: @ 80D7620 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r4, 0x24 - adds r0, r4 - ldr r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetBattleFunc - - thumb_func_start ItemId_GetSecondaryId -ItemId_GetSecondaryId: @ 80D7644 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gItems - bl SanitizeItemId - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x2C - muls r0, r1 - adds r0, r4 - adds r0, 0x28 - ldrb r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end ItemId_GetSecondaryId - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/party_menu.s b/asm/party_menu.s index 29e2e67a6..185d26109 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -15368,7 +15368,7 @@ sub_81B83F0: @ 81B83F0 lsls r0, r1, 24 lsrs r0, 24 movs r1, 0x1 - bl sub_80D6E48 + bl RemovePCItem b _081B8418 .pool _081B8410: diff --git a/asm/pokemon_storage_system.s b/asm/pokemon_storage_system.s index 21647dfdf..111093bee 100644 --- a/asm/pokemon_storage_system.s +++ b/asm/pokemon_storage_system.s @@ -14810,7 +14810,7 @@ _080CF020: beq _080CF0AC ldr r3, =0x00000d65 adds r4, r3 - bl ItemId_GetItem + bl ItemId_GetName adds r1, r0, 0 adds r0, r4, 0 movs r2, 0 @@ -19057,7 +19057,7 @@ sub_80D12B8: @ 80D12B8 ldr r1, =0x00002234 adds r0, r1 ldrh r0, [r0] - bl ItemId_GetItem + bl ItemId_GetName pop {r1} bx r1 .pool diff --git a/asm/pokemon_summary_screen.s b/asm/pokemon_summary_screen.s index 3b41afb55..c7f2ad085 100644 --- a/asm/pokemon_summary_screen.s +++ b/asm/pokemon_summary_screen.s @@ -4686,7 +4686,7 @@ sub_81C6648: @ 81C6648 .pool _081C667C: ldrh r0, [r5] - bl itemid_is_unique + bl ItemId_GetImportance lsls r0, 24 cmp r0, 0 bne _081C66A0 @@ -4799,7 +4799,7 @@ sub_81C674C: @ 81C674C .pool _081C677C: ldrh r0, [r5] - bl itemid_is_unique + bl ItemId_GetImportance lsls r0, 24 cmp r0, 0 bne _081C6790 diff --git a/asm/shop.s b/asm/shop.s index ae60eb364..eac0956cb 100644 --- a/asm/shop.s +++ b/asm/shop.s @@ -790,7 +790,7 @@ BuyMenuPrintPriceInList: @ 80E0114 ldr r5, =gStringVar1 lsls r0, r1, 16 lsrs r0, 16 - bl itemid_get_market_price + bl ItemId_GetPrice adds r4, r0, 0 movs r0, 0x1 bl GetPriceReduction @@ -2017,7 +2017,7 @@ _080E0B32: bne _080E0B80 lsls r0, r5, 16 lsrs r0, 16 - bl itemid_get_market_price + bl ItemId_GetPrice adds r4, r0, 0 movs r0, 0x1 bl GetPriceReduction @@ -2259,7 +2259,7 @@ Task_BuyHowManyDialogueHandleInput: @ 80E0D88 cmp r0, 0x1 bne _080E0DF0 ldrh r0, [r5, 0xA] - bl itemid_get_market_price + bl ItemId_GetPrice adds r4, r0, 0 movs r0, 0x1 bl GetPriceReduction diff --git a/data/scripts/maps/MauvilleCity_BikeShop.inc b/data/scripts/maps/MauvilleCity_BikeShop.inc index d4915a478..0231e5bde 100644 --- a/data/scripts/maps/MauvilleCity_BikeShop.inc +++ b/data/scripts/maps/MauvilleCity_BikeShop.inc @@ -58,7 +58,7 @@ MauvilleCity_BikeShop_EventScript_20EC6D:: @ 820EC6D MauvilleCity_BikeShop_EventScript_20EC87:: @ 820EC87 msgbox MauvilleCity_BikeShop_Text_20F1BD, 4 - special sub_80D6EDC + special SwapRegisteredBike release end diff --git a/data/specials.inc b/data/specials.inc index 2290c9d21..91580fa96 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -141,7 +141,7 @@ gSpecials:: @ 81DBA64 def_special TrendyPhraseIsOld def_special sub_811EF6C def_special GetDewfordHallPaintingNameIndex - def_special sub_80D6EDC + def_special SwapRegisteredBike def_special CalculatePlayerPartyCount def_special CountPartyNonEggMons def_special CountPartyAliveNonEggMons_IgnoreVar0x8004Slot diff --git a/include/constants/items.h b/include/constants/items.h index 8717ecbd5..4ca5cb7df 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -108,6 +108,8 @@ #define ITEM_064 100 #define ITEM_065 101 #define ITEM_066 102 + +// Unusable #define ITEM_TINY_MUSHROOM 103 #define ITEM_BIG_MUSHROOM 104 #define ITEM_069 105 @@ -126,6 +128,8 @@ #define ITEM_076 118 #define ITEM_077 119 #define ITEM_078 120 + +// Mails #define ITEM_ORANGE_MAIL 121 #define ITEM_HARBOR_MAIL 122 #define ITEM_GLITTER_MAIL 123 @@ -138,6 +142,8 @@ #define ITEM_DREAM_MAIL 130 #define ITEM_FAB_MAIL 131 #define ITEM_RETRO_MAIL 132 + +// Berries #define ITEM_CHERI_BERRY 133 #define ITEM_CHESTO_BERRY 134 #define ITEM_PECHA_BERRY 135 @@ -185,7 +191,7 @@ #define ITEM_0B1 177 #define ITEM_0B2 178 -// hold items +// Battle Held items #define ITEM_BRIGHT_POWDER 179 #define ITEM_WHITE_HERB 180 #define ITEM_MACHO_BRACE 181 @@ -261,6 +267,8 @@ #define ITEM_0FB 251 #define ITEM_0FC 252 #define ITEM_0FD 253 + +// Contest held items #define ITEM_RED_SCARF 254 #define ITEM_BLUE_SCARF 255 #define ITEM_PINK_SCARF 256 diff --git a/include/global.h b/include/global.h index f88203c90..b0c3bed4a 100644 --- a/include/global.h +++ b/include/global.h @@ -43,9 +43,6 @@ #define PARTY_SIZE 6 -#define POKEMON_NAME_LENGTH 10 -#define OT_NAME_LENGTH 7 - #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) >= (b) ? (a) : (b)) @@ -97,6 +94,31 @@ enum LanguageId #define GAME_VERSION (VERSION_EMERALD) #define GAME_LANGUAGE (LANGUAGE_ENGLISH) +// capacities of various saveblock objects +#define DAYCARE_MON_COUNT 2 +#define POKEBLOCKS_COUNT 40 +#define MAP_OBJECTS_COUNT 16 +#define BERRY_TREES_COUNT 128 +#define FLAGS_COUNT 300 +#define VARS_COUNT 256 +#define MAIL_COUNT 16 +#define SECRET_BASES_COUNT 20 +#define PC_ITEMS_COUNT 50 +#define BAG_ITEMS_COUNT 30 +#define BAG_KEYITEMS_COUNT 30 +#define BAG_POKEBALLS_COUNT 16 +#define BAG_TMHM_COUNT 64 +#define BAG_BERRIES_COUNT 46 + +#define PYRAMID_BAG_ITEMS_COUNT 10 + +// string lengths +#define ITEM_NAME_LENGTH 14 +#define POKEMON_NAME_LENGTH 10 +#define OT_NAME_LENGTH 7 +#define PLAYER_NAME_LENGTH 8 +#define MAIL_WORDS_COUNT 9 + enum { MALE, @@ -129,15 +151,6 @@ enum OPTIONS_BATTLE_STYLE_SET }; -enum -{ - BAG_ITEMS = 1, - BAG_POKEBALLS, - BAG_TMsHMs, - BAG_BERRIES, - BAG_KEYITEMS -}; - struct Coords16 { s16 x; @@ -209,11 +222,11 @@ struct BerryPickingResults // possibly used in the game itself? Size may be wron u8 field_F; }; +// two arrays for lvl50 and open level struct PyramidBag { - u16 items_Lvl50[10]; - u16 items_OpenLvl[10]; - u8 quantity[10]; + u16 itemId[2][PYRAMID_BAG_ITEMS_COUNT]; + u8 quantity[2][PYRAMID_BAG_ITEMS_COUNT]; }; struct BerryCrush @@ -223,8 +236,6 @@ struct BerryCrush u32 unk; }; -#define PLAYER_NAME_LENGTH 8 - struct UnknownSaveBlock2Struct { u8 field_0; @@ -303,7 +314,7 @@ struct SaveBlock2 /*0xE1A*/ u16 battlePyramidFloor; // possibly? /*0xE1C*/ u8 field_E1C[16]; /*0xE2C*/ struct PyramidBag pyramidBag; - /*0x???*/ u8 field_notSure[13]; + /*0x???*/ u8 field_unkown[6]; /*0xE6E*/ u16 battleTentWinStreak; /*0xE70*/ u8 field_E70[72]; /*0xEB8*/ u16 frontierBattlePoints; @@ -417,8 +428,6 @@ struct EasyChatPair u16 words[2]; }; /*size = 0x8*/ -#define MAIL_WORDS_COUNT 9 - struct MailStruct { /*0x00*/ u16 words[MAIL_WORDS_COUNT]; @@ -530,8 +539,6 @@ struct DaycareMon u32 steps; }; -#define DAYCARE_MON_COUNT 2 - struct DayCare { struct DaycareMon mons[DAYCARE_MON_COUNT]; @@ -552,13 +559,6 @@ struct RecordMixingDayCareMail bool16 holdsItem[DAYCARE_MON_COUNT]; }; -#define POKEBLOCKS_COUNT 40 -#define MAP_OBJECTS_COUNT 16 -#define BERRY_TREES_COUNT 128 -#define FLAGS_COUNT 300 -#define VARS_COUNT 256 -#define MAIL_COUNT 16 - enum { LILYCOVE_LADY_QUIZ, @@ -645,16 +645,16 @@ struct SaveBlock1 /*0x32*/ u16 mapDataId; /*0x34*/ u16 mapView[0x100]; /*0x234*/ u8 playerPartyCount; - /*0x238*/ struct Pokemon playerParty[6]; + /*0x238*/ struct Pokemon playerParty[PARTY_SIZE]; /*0x490*/ u32 money; /*0x494*/ u16 coins; /*0x496*/ u16 registeredItem; // registered for use with SELECT button - /*0x498*/ struct ItemSlot pcItems[50]; - /*0x560*/ struct ItemSlot bagPocket_Items[30]; - /*0x5D8*/ struct ItemSlot bagPocket_KeyItems[30]; - /*0x650*/ struct ItemSlot bagPocket_PokeBalls[16]; - /*0x690*/ struct ItemSlot bagPocket_TMHM[64]; - /*0x790*/ struct ItemSlot bagPocket_Berries[46]; + /*0x498*/ struct ItemSlot pcItems[PC_ITEMS_COUNT]; + /*0x560*/ struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT]; + /*0x5D8*/ struct ItemSlot bagPocket_KeyItems[BAG_KEYITEMS_COUNT]; + /*0x650*/ struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT]; + /*0x690*/ struct ItemSlot bagPocket_TMHM[BAG_TMHM_COUNT]; + /*0x790*/ struct ItemSlot bagPocket_Berries[BAG_BERRIES_COUNT]; /*0x848*/ struct Pokeblock pokeblocks[POKEBLOCKS_COUNT]; /*0x988*/ u8 seen1[52]; /*0x9BC*/ u16 berryBlenderRecords[3]; @@ -667,7 +667,7 @@ struct SaveBlock1 /*0x139C*/ u16 vars[VARS_COUNT]; /*0x159C*/ u32 gameStats[NUM_GAME_STATS]; /*0x169C*/ struct BerryTree berryTrees[BERRY_TREES_COUNT]; - /*0x1A9C*/ struct SecretBaseRecord secretBases[20]; + /*0x1A9C*/ struct SecretBaseRecord secretBases[SECRET_BASES_COUNT]; /*0x271C*/ u8 playerRoomDecor[12]; /*0x2728*/ u8 playerRoomDecorPos[12]; /*0x2734*/ u8 decorDesk[10]; diff --git a/include/item.h b/include/item.h index 33d434f78..3153807c4 100644 --- a/include/item.h +++ b/include/item.h @@ -1,11 +1,21 @@ -#ifndef ITEM_H -#define ITEM_H +#ifndef GUARD_ITEM_H +#define GUARD_ITEM_H + +enum +{ + ITEMS_POCKET, + BALLS_POCKET, + TMHM_POCKET, + BERRIES_POCKET, + KEYITEMS_POCKET, + POCKETS_COUNT +}; typedef void (*ItemUseFunc)(u8); struct Item { - u8 name[14]; + u8 name[ITEM_NAME_LENGTH]; u16 itemId; u16 price; u8 holdEffect; @@ -63,10 +73,14 @@ u16 itemid_get_market_price(u16 itemId); u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos); void sub_80D6FB4(struct BagPocket*); void sub_80D6F64(struct BagPocket*); -void sub_80D702C(struct ItemSlot*, s16, u16); +void MoveItemSlotInList(struct ItemSlot* itemSlots, u32 a1, u32 a2); u8 sub_80D6CE4(); bool8 itemid_is_unique(u16 itemId); void sub_80D6E48(u8, u16); void sub_80D6E84(void); +void CompactPCItems(void); +void SortBerriesOrTMHMs(struct BagPocket *bagPocket); +void CompactItemsInBagPocket(struct BagPocket *bagPocket); +const u8 *ItemId_GetName(u16 itemId); -#endif // ITEM_H +#endif // GUARD_ITEM_H diff --git a/include/item_menu.h b/include/item_menu.h index 68393c9ee..40c015a8e 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -55,7 +55,7 @@ void sub_81AAC14(void); void sub_81AAC50(void); void sub_81AAC70(void); void bag_menu_mail_related(void); - void CB2_BagMenuFromStartMenu(void); +u8 sub_81ABB2C(u8 pocketId); #endif //GUARD_item_menu_H diff --git a/include/secret_base.h b/include/secret_base.h index b2502889c..3e8a80987 100644 --- a/include/secret_base.h +++ b/include/secret_base.h @@ -10,5 +10,6 @@ void sub_80E9578(void); void sub_80E980C(void); u8 *GetSecretBaseMapName(u8 *dest); const u8 *GetSecretBaseTrainerLoseText(void); +bool8 CurrentMapIsSecretBase(void); #endif //GUARD_SECRET_BASE_H diff --git a/ld_script.txt b/ld_script.txt index 2832bcada..e947e648f 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -137,7 +137,6 @@ SECTIONS { src/item_menu_icons.o(.text); asm/battle_anim_80D51AC.o(.text); src/item.o(.text); - asm/item.o(.text); asm/contest.o(.text); asm/shop.o(.text); src/berry.o(.text); diff --git a/src/item.c b/src/item.c index a17599db9..a6e89a8e5 100644 --- a/src/item.c +++ b/src/item.c @@ -5,50 +5,63 @@ #include "string_util.h" #include "text.h" #include "event_data.h" +#include "malloc.h" +#include "secret_base.h" +#include "item_menu.h" -extern void ApplyNewEncryptionKeyToHword(u16* hword, u32 newKey); +// These constants are used in gItems +enum +{ + POCKET_NONE, + POCKET_ITEMS, + POCKET_POKE_BALLS, + POCKET_TM_HM, + POCKET_BERRIES, + POCKET_KEY_ITEMS, +}; + +extern void ApplyNewEncryptionKeyToHword(u16 *hword, u32 newKey); extern bool8 InBattlePyramid(void); extern const u8 gText_PokeBalls[]; extern const u8 gText_Berries[]; extern const u8 gText_Berry[]; -bool8 CheckPyramidBagHasItem(u16 itemId, u16 count); -bool8 CheckPyramidBagHasSpace(u16 itemId, u16 count); +extern const struct Item gItems[]; -enum -{ - ITEMS_POCKET, - BALLS_POCKET, - TMHM_POCKET, - BERRIES_POCKET, - KEYITEMS_POCKET -}; +// this file's functions -u16 GetBagItemQuantity(u16* quantity) +static bool8 CheckPyramidBagHasItem(u16 itemId, u16 count); +static bool8 CheckPyramidBagHasSpace(u16 itemId, u16 count); +static bool8 AddPyramidBagItem(u16 itemId, u16 count); +static bool8 RemovePyramidBagItem(u16 itemId, u16 count); + +// code + +u16 GetBagItemQuantity(u16 *quantity) { return gSaveBlock2Ptr->encryptionKey ^ *quantity; } -void SetBagItemQuantity(u16* quantity, u16 newValue) +void SetBagItemQuantity(u16 *quantity, u16 newValue) { *quantity = newValue ^ gSaveBlock2Ptr->encryptionKey; } -u16 GetBagItemId(u16* slot) +u16 GetPCItemQuantity(u16 *quantity) { - return *slot; + return *quantity; } -void SetBagItemId(u16* slot, u16 newItemId) +void SetPCItemQuantity(u16 *quantity, u16 newValue) { - *slot = newItemId; + *quantity = newValue; } void ApplyNewEncryptionKeyToBagItems(u32 newKey) { u32 pocket, item; - for (pocket = 0; pocket < 5; pocket++) + for (pocket = 0; pocket < POCKETS_COUNT; pocket++) { for (item = 0; item < gBagPockets[pocket].capacity; item++) ApplyNewEncryptionKeyToHword(&(gBagPockets[pocket].itemSlots[item].quantity), newKey); @@ -60,29 +73,27 @@ void ApplyNewEncryptionKeyToBagItems_(u32 newKey) // really GF? ApplyNewEncryptionKeyToBagItems(newKey); } -// TODO: move those max values to defines - void SetBagItemsPointers(void) { gBagPockets[ITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Items; - gBagPockets[ITEMS_POCKET].capacity = 30; + gBagPockets[ITEMS_POCKET].capacity = BAG_ITEMS_COUNT; gBagPockets[KEYITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_KeyItems; - gBagPockets[KEYITEMS_POCKET].capacity = 30; + gBagPockets[KEYITEMS_POCKET].capacity = BAG_KEYITEMS_COUNT; gBagPockets[BALLS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_PokeBalls; - gBagPockets[BALLS_POCKET].capacity = 16; + gBagPockets[BALLS_POCKET].capacity = BAG_POKEBALLS_COUNT; gBagPockets[TMHM_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_TMHM; - gBagPockets[TMHM_POCKET].capacity = 64; + gBagPockets[TMHM_POCKET].capacity = BAG_TMHM_COUNT; gBagPockets[BERRIES_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Berries; - gBagPockets[BERRIES_POCKET].capacity = 46; + gBagPockets[BERRIES_POCKET].capacity = BAG_BERRIES_COUNT; } void CopyItemName(u16 itemId, u8 *string) { - StringCopy(string, ItemId_GetItem(itemId)->name); + StringCopy(string, ItemId_GetName(itemId)); } void CopyItemNameHandlePlural(u16 itemId, u8 *string, u32 quantity) @@ -90,7 +101,7 @@ void CopyItemNameHandlePlural(u16 itemId, u8 *string, u32 quantity) if (itemId == ITEM_POKE_BALL) { if (quantity < 2) - StringCopy(string, ItemId_GetItem(ITEM_POKE_BALL)->name); + StringCopy(string, ItemId_GetName(ITEM_POKE_BALL)); else StringCopy(string, gText_PokeBalls); } @@ -99,19 +110,20 @@ void CopyItemNameHandlePlural(u16 itemId, u8 *string, u32 quantity) if (itemId >= ITEM_CHERI_BERRY && itemId <= ITEM_ENIGMA_BERRY) GetBerryCountString(string, gBerries[itemId - ITEM_CHERI_BERRY].name, quantity); else - StringCopy(string, ItemId_GetItem(itemId)->name); + StringCopy(string, ItemId_GetName(itemId)); } } -void GetBerryCountString(u8* dst, const u8* berryName, u32 quantity) +void GetBerryCountString(u8 *dst, const u8 *berryName, u32 quantity) { - const u8* berryString; - u8* txtPtr; + const u8 *berryString; + u8 *txtPtr; if (quantity < 2) berryString = gText_Berry; else berryString = gText_Berries; + txtPtr = StringCopy(dst, berryName); *txtPtr = CHAR_SPACE; StringCopy(txtPtr + 1, berryString); @@ -136,10 +148,10 @@ bool8 CheckBagHasItem(u16 itemId, u16 count) if (ItemId_GetPocket(itemId) == 0) return FALSE; - if (InBattlePyramid() || FlagGet(0x4004) == TRUE) + if (InBattlePyramid() || FlagGet(FLAG_SPECIAL_FLAG_0x4004) == TRUE) return CheckPyramidBagHasItem(itemId, count); pocket = ItemId_GetPocket(itemId) - 1; - //Check for item slots that contain the item + // Check for item slots that contain the item for (i = 0; i < gBagPockets[pocket].capacity; i++) { if (gBagPockets[pocket].itemSlots[i].itemId == itemId) @@ -161,69 +173,948 @@ bool8 CheckBagHasItem(u16 itemId, u16 count) bool8 HasAtLeastOneBerry(void) { u16 i; - for (i = 0x85; i < 0xB3; i++) + + for (i = FIRST_BERRY_INDEX; i < ITEM_BRIGHT_POWDER; i++) { if (CheckBagHasItem(i, 1) == TRUE) { - gSpecialVar_Result = 1; + gSpecialVar_Result = TRUE; return TRUE; } } - gSpecialVar_Result = 0; + gSpecialVar_Result = FALSE; return FALSE; } -/* Refuses to match. +#ifdef NONMATCHING +// Refuses to match. bool8 CheckBagHasSpace(u16 itemId, u16 count) { u8 i; - u8 pocket; - u16 slotCapacity; - u16 quantity; - if (ItemId_GetPocket(itemId) == 0) + if (ItemId_GetPocket(itemId) == POCKET_NONE) return FALSE; - if (InBattlePyramid() || FlagGet(0x4004) == TRUE) - return CheckPyramidBagHasSpace(itemId, count); - pocket = ItemId_GetPocket(itemId) - 1; - if (pocket != BERRIES_POCKET) - slotCapacity = 99; - else - slotCapacity = 999; - //Check space in any existing item slots that already contain this item - for (i = 0; i < gBagPockets[pocket].capacity; i++) + if (InBattlePyramid() || FlagGet(FLAG_SPECIAL_FLAG_0x4004) == TRUE) { - if (gBagPockets[pocket].itemSlots[i].itemId == itemId) + return CheckPyramidBagHasSpace(itemId, count); + } + else + { + u8 pocket; + u16 slotCapacity; + u16 ownedCount; + + pocket = ItemId_GetPocket(itemId) - 1; + if (pocket != BERRIES_POCKET) + slotCapacity = 99; + else + slotCapacity = 999; + + // Check space in any existing item slots that already contain this item + for (i = 0; i < gBagPockets[pocket].capacity; i++) { - quantity = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); - if (quantity + count <= slotCapacity) - return TRUE; - if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + if (gBagPockets[pocket].itemSlots[i].itemId == itemId) + { + ownedCount = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); + if (ownedCount + count <= slotCapacity) + return TRUE; + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + return FALSE; + count -= slotCapacity - ownedCount; + if (count == 0) + return TRUE; + } + } + + // Check space in empty item slots + if (count > 0) + { + for (i = 0; i < gBagPockets[pocket].capacity; i++) + { + if (gBagPockets[pocket].itemSlots[i].itemId == 0) + { + if (count <= slotCapacity) + return TRUE; + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + return FALSE; + count -= slotCapacity; + } + } + if (count > 0) + return FALSE; // No more item slots. The bag is full + } + + return TRUE; + } +} +#else +ASM_DIRECT +bool8 CheckBagHasSpace(u16 itemId, u16 count) +{ + asm_unified("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x4\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + mov r8, r0\n\ + lsls r1, 16\n\ + lsrs r5, r1, 16\n\ + bl ItemId_GetPocket\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + beq _080D6906\n\ + bl InBattlePyramid\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _080D6838\n\ + ldr r0, =0x00004004\n\ + bl FlagGet\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, 0x1\n\ + bne _080D684C\n\ +_080D6838:\n\ + mov r0, r8\n\ + adds r1, r5, 0\n\ + bl CheckPyramidBagHasSpace\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + b _080D6916\n\ + .pool\n\ +_080D684C:\n\ + mov r0, r8\n\ + bl ItemId_GetPocket\n\ + subs r0, 0x1\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r7, =0x000003e7\n\ + cmp r2, 0x3\n\ + beq _080D6860\n\ + movs r7, 0x63\n\ +_080D6860:\n\ + movs r6, 0\n\ + ldr r1, =gBagPockets\n\ + lsls r4, r2, 3\n\ + adds r0, r4, r1\n\ + mov r9, r4\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcs _080D68BC\n\ + subs r0, r2, 0x2\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r10, r0\n\ +_080D6878:\n\ + adds r0, r4, r1\n\ + ldr r1, [r0]\n\ + lsls r0, r6, 2\n\ + adds r1, r0, r1\n\ + ldrh r0, [r1]\n\ + cmp r0, r8\n\ + bne _080D68AC\n\ + adds r0, r1, 0x2\n\ + str r2, [sp]\n\ + bl GetBagItemQuantity\n\ + lsls r0, 16\n\ + lsrs r1, r0, 16\n\ + adds r0, r1, r5\n\ + ldr r2, [sp]\n\ + cmp r0, r7\n\ + ble _080D6914\n\ + mov r0, r10\n\ + cmp r0, 0x1\n\ + bls _080D6906\n\ + subs r0, r7, r1\n\ + subs r0, r5, r0\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, 0\n\ + beq _080D6914\n\ +_080D68AC:\n\ + adds r0, r6, 0x1\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + ldr r1, =gBagPockets\n\ + adds r0, r4, r1\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcc _080D6878\n\ +_080D68BC:\n\ + cmp r5, 0\n\ + beq _080D6914\n\ + movs r6, 0\n\ + ldr r3, =gBagPockets\n\ + mov r1, r9\n\ + adds r0, r1, r3\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcs _080D6902\n\ + adds r4, r3, 0\n\ + subs r0, r2, 0x2\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ +_080D68D6:\n\ + adds r0, r1, r4\n\ + ldr r1, [r0]\n\ + lsls r0, r6, 2\n\ + adds r0, r1\n\ + ldrh r0, [r0]\n\ + cmp r0, 0\n\ + bne _080D68F2\n\ + cmp r5, r7\n\ + bls _080D6914\n\ + cmp r2, 0x1\n\ + bls _080D6906\n\ + subs r0, r5, r7\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ +_080D68F2:\n\ + adds r0, r6, 0x1\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + mov r1, r9\n\ + adds r0, r1, r3\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcc _080D68D6\n\ +_080D6902:\n\ + cmp r5, 0\n\ + beq _080D6914\n\ +_080D6906:\n\ + movs r0, 0\n\ + b _080D6916\n\ + .pool\n\ +_080D6914:\n\ + movs r0, 0x1\n\ +_080D6916:\n\ + add sp, 0x4\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1"); +} +#endif // NONMATCHING + +bool8 AddBagItem(u16 itemId, u16 count) +{ + u8 i; + + if (ItemId_GetPocket(itemId) == POCKET_NONE) + return FALSE; + + // check Battle Pyramid Bag + if (InBattlePyramid() || FlagGet(FLAG_SPECIAL_FLAG_0x4004) == TRUE) + { + return AddPyramidBagItem(itemId, count); + } + else + { + struct BagPocket *itemPocket; + struct ItemSlot *newItems; + u16 slotCapacity; + u16 ownedCount; + u8 pocket = ItemId_GetPocket(itemId) - 1; + + itemPocket = &gBagPockets[pocket]; + newItems = AllocZeroed(itemPocket->capacity * sizeof(struct ItemSlot)); + memcpy(newItems, itemPocket->itemSlots, itemPocket->capacity * sizeof(struct ItemSlot)); + + if (pocket != BERRIES_POCKET) + slotCapacity = 99; + else + slotCapacity = 999; + + for (i = 0; i < itemPocket->capacity; i++) + { + if (newItems[i].itemId == itemId) + { + ownedCount = GetBagItemQuantity(&newItems[i].quantity); + // check if won't exceed max slot capacity + if (ownedCount + count <= slotCapacity) + { + // successfully added to already existing item's count + SetBagItemQuantity(&newItems[i].quantity, ownedCount + count); + + // goto SUCCESS_ADD_ITEM; + // is equivalent but won't match + + memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot)); + Free(newItems); + return TRUE; + } + else + { + // try creating another instance of the item if possible + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + { + Free(newItems); + return FALSE; + } + else + { + count -= slotCapacity - ownedCount; + SetBagItemQuantity(&newItems[i].quantity, slotCapacity); + // don't create another instance of the item if it's at max slot capacity and count is equal to 0 + if (count == 0) + { + goto SUCCESS_ADD_ITEM; + } + } + } + } + } + + // we're done if quantity is equal to 0 + if (count > 0) + { + // either no existing item was found or we have to create another instance, because the capacity was exceeded + for (i = 0; i < itemPocket->capacity; i++) + { + if (newItems[i].itemId == ITEM_NONE) + { + newItems[i].itemId = itemId; + if (count > slotCapacity) + { + // try creating a new slot with max capacity if duplicates are possible + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + { + Free(newItems); + return FALSE; + } + count -= slotCapacity; + SetBagItemQuantity(&newItems[i].quantity, slotCapacity); + } + else + { + // created a new slot and added quantity + SetBagItemQuantity(&newItems[i].quantity, count); + goto SUCCESS_ADD_ITEM; + } + } + } + + if (count > 0) + { + Free(newItems); return FALSE; - count -= slotCapacity - quantity; + } + } + + SUCCESS_ADD_ITEM: + memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot)); + Free(newItems); + return TRUE; + } +} + +bool8 RemoveBagItem(u16 itemId, u16 count) +{ + u8 i; + u16 totalQuantity = 0; + + if (ItemId_GetPocket(itemId) == POCKET_NONE || itemId == ITEM_NONE) + return FALSE; + + // check Battle Pyramid Bag + if (InBattlePyramid() || FlagGet(FLAG_SPECIAL_FLAG_0x4004) == TRUE) + { + return RemovePyramidBagItem(itemId, count); + } + else + { + u8 pocket; + u8 var; + u16 ownedCount; + struct BagPocket *itemPocket; + + pocket = ItemId_GetPocket(itemId) - 1; + itemPocket = &gBagPockets[pocket]; + + for (i = 0; i < itemPocket->capacity; i++) + { + if (itemPocket->itemSlots[i].itemId == itemId) + totalQuantity += GetBagItemQuantity(&itemPocket->itemSlots[i].quantity); + } + + if (totalQuantity < count) + return FALSE; // We don't have enough of the item + + if (CurrentMapIsSecretBase() == TRUE) + { + VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x200); + VarSet(VAR_0x40ED, itemId); + } + + var = sub_81ABB2C(pocket); + if (itemPocket->capacity > var + && itemPocket->itemSlots[var].itemId == itemId) + { + ownedCount = GetBagItemQuantity(&itemPocket->itemSlots[var].quantity); + if (ownedCount >= count) + { + SetBagItemQuantity(&itemPocket->itemSlots[var].quantity, ownedCount - count); + count = 0; + } + else + { + count -= ownedCount; + SetBagItemQuantity(&itemPocket->itemSlots[var].quantity, 0); + } + + if (GetBagItemQuantity(&itemPocket->itemSlots[var].quantity) == 0) + itemPocket->itemSlots[var].itemId = ITEM_NONE; + + if (count == 0) + return TRUE; + } + + for (i = 0; i < itemPocket->capacity; i++) + { + if (itemPocket->itemSlots[i].itemId == itemId) + { + ownedCount = GetBagItemQuantity(&itemPocket->itemSlots[i].quantity); + if (ownedCount >= count) + { + SetBagItemQuantity(&itemPocket->itemSlots[i].quantity, ownedCount - count); + count = 0; + } + else + { + count -= ownedCount; + SetBagItemQuantity(&itemPocket->itemSlots[i].quantity, 0); + } + + if (GetBagItemQuantity(&itemPocket->itemSlots[i].quantity) == 0) + itemPocket->itemSlots[i].itemId = ITEM_NONE; + + if (count == 0) + return TRUE; + } + } + return TRUE; + } +} + +u8 GetPocketByItemId(u16 itemId) +{ + return ItemId_GetPocket(itemId); +} + +void ClearItemSlots(struct ItemSlot *itemSlots, u8 itemCount) +{ + u16 i; + + for (i = 0; i < itemCount; i++) + { + itemSlots[i].itemId = ITEM_NONE; + SetBagItemQuantity(&itemSlots[i].quantity, 0); + } +} + +static s32 FindFreePCItemSlot(void) +{ + s8 i; + + for (i = 0; i < PC_ITEMS_COUNT; i++) + { + if (gSaveBlock1Ptr->pcItems[i].itemId == ITEM_NONE) + return i; + } + return -1; +} + +u8 CountUsedPCItemSlots(void) +{ + u8 usedSlots = 0; + u8 i; + + for (i = 0; i < PC_ITEMS_COUNT; i++) + { + if (gSaveBlock1Ptr->pcItems[i].itemId != ITEM_NONE) + usedSlots++; + } + return usedSlots; +} + +bool8 CheckPCHasItem(u16 itemId, u16 count) +{ + u8 i; + + for (i = 0; i < PC_ITEMS_COUNT; i++) + { + if (gSaveBlock1Ptr->pcItems[i].itemId == itemId && GetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity) >= count) + return TRUE; + } + return FALSE; +} + +bool8 AddPCItem(u16 itemId, u16 count) +{ + u8 i; + s8 freeSlot; + u16 ownedCount; + struct ItemSlot *newItems; + + // Copy PC items + newItems = AllocZeroed(sizeof(gSaveBlock1Ptr->pcItems)); + memcpy(newItems, gSaveBlock1Ptr->pcItems, sizeof(gSaveBlock1Ptr->pcItems)); + + // Use any item slots that already contain this item + for (i = 0; i < PC_ITEMS_COUNT; i++) + { + if (newItems[i].itemId == itemId) + { + ownedCount = GetPCItemQuantity(&newItems[i].quantity); + if (ownedCount + count <= 999) + { + SetPCItemQuantity(&newItems[i].quantity, ownedCount + count); + memcpy(gSaveBlock1Ptr->pcItems, newItems, sizeof(gSaveBlock1Ptr->pcItems)); + Free(newItems); + return TRUE; + } + count += ownedCount - 999; + SetPCItemQuantity(&newItems[i].quantity, 999); + if (count == 0) + { + memcpy(gSaveBlock1Ptr->pcItems, newItems, sizeof(gSaveBlock1Ptr->pcItems)); + Free(newItems); + return TRUE; + } + } + } + + // Put any remaining items into a new item slot. + if (count > 0) + { + freeSlot = FindFreePCItemSlot(); + if (freeSlot == -1) + { + Free(newItems); + return FALSE; + } + else + { + newItems[freeSlot].itemId = itemId; + SetPCItemQuantity(&newItems[freeSlot].quantity, count); + } + } + + // Copy items back to the PC + memcpy(gSaveBlock1Ptr->pcItems, newItems, sizeof(gSaveBlock1Ptr->pcItems)); + Free(newItems); + return TRUE; +} + +void RemovePCItem(u8 index, u16 count) +{ + // UB: should use GetPCItemQuantity and SetPCItemQuantity functions + gSaveBlock1Ptr->pcItems[index].quantity -= count; + if (gSaveBlock1Ptr->pcItems[index].quantity == 0) + { + gSaveBlock1Ptr->pcItems[index].itemId = ITEM_NONE; + CompactPCItems(); + } +} + +void CompactPCItems(void) +{ + u16 i; + u16 j; + + for (i = 0; i < PC_ITEMS_COUNT - 1; i++) + { + for (j = i + 1; j < PC_ITEMS_COUNT; j++) + { + if (gSaveBlock1Ptr->pcItems[i].itemId == 0) + { + struct ItemSlot temp = gSaveBlock1Ptr->pcItems[i]; + gSaveBlock1Ptr->pcItems[i] = gSaveBlock1Ptr->pcItems[j]; + gSaveBlock1Ptr->pcItems[j] = temp; + } + } + } +} + +void SwapRegisteredBike(void) +{ + switch (gSaveBlock1Ptr->registeredItem) + { + case ITEM_MACH_BIKE: + gSaveBlock1Ptr->registeredItem = ITEM_ACRO_BIKE; + break; + case ITEM_ACRO_BIKE: + gSaveBlock1Ptr->registeredItem = ITEM_MACH_BIKE; + break; + } +} + +u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos) +{ + return gBagPockets[pocketId - 1].itemSlots[pocketPos].itemId; +} + +u16 BagGetQuantityByPocketPosition(u8 pocketId, u16 pocketPos) +{ + return GetBagItemQuantity(&gBagPockets[pocketId - 1].itemSlots[pocketPos].quantity); +} + +static void SwapItemSlots(struct ItemSlot *a, struct ItemSlot *b) +{ + struct ItemSlot temp = *a; + *a = *b; + *b = temp; +} + +void CompactItemsInBagPocket(struct BagPocket *bagPocket) +{ + u16 i, j; + + for (i = 0; i < bagPocket->capacity - 1; i++) + { + for (j = i + 1; j < bagPocket->capacity; j++) + { + if (GetBagItemQuantity(&bagPocket->itemSlots[i].quantity) == 0) + SwapItemSlots(&bagPocket->itemSlots[i], &bagPocket->itemSlots[j]); + } + } +} + +void SortBerriesOrTMHMs(struct BagPocket *bagPocket) +{ + u16 i, j; + + for (i = 0; i < bagPocket->capacity - 1; i++) + { + for (j = i + 1; j < bagPocket->capacity; j++) + { + if (GetBagItemQuantity(&bagPocket->itemSlots[i].quantity) != 0) + { + if (GetBagItemQuantity(&bagPocket->itemSlots[j].quantity) == 0) + continue; + if (bagPocket->itemSlots[i].itemId <= bagPocket->itemSlots[j].itemId) + continue; + } + SwapItemSlots(&bagPocket->itemSlots[i], &bagPocket->itemSlots[j]); + } + } +} + +void MoveItemSlotInList(struct ItemSlot* itemSlots_, u32 from, u32 to_) +{ + // dumb assignments needed to match + struct ItemSlot *itemSlots = itemSlots_; + u32 to = to_; + + if (from != to) + { + s16 i, count; + struct ItemSlot firstSlot = itemSlots[from]; + + if (to > from) + { + to--; + for (i = from, count = to; i < count; i++) + itemSlots[i] = itemSlots[i + 1]; + } + else + { + for (i = from, count = to; i > count; i--) + itemSlots[i] = itemSlots[i - 1]; + } + itemSlots[to] = firstSlot; + } +} + +void ClearBag(void) +{ + u16 i; + + for (i = 0; i < POCKETS_COUNT; i++) + { + ClearItemSlots(gBagPockets[i].itemSlots, gBagPockets[i].capacity); + } +} + +u16 CountTotalItemQuantityInBag(u16 itemId) +{ + u16 i; + u16 ownedCount = 0; + struct BagPocket *bagPocket = &gBagPockets[ItemId_GetPocket(itemId) - 1]; + + for (i = 0; i < bagPocket->capacity; i++) + { + if (bagPocket->itemSlots[i].itemId == itemId) + ownedCount += GetBagItemQuantity(&bagPocket->itemSlots[i].quantity); + } + + return ownedCount; +} + +static bool8 CheckPyramidBagHasItem(u16 itemId, u16 count) +{ + u8 i; + u16 *items = gSaveBlock2Ptr->pyramidBag.itemId[gSaveBlock2Ptr->frontierChosenLvl]; + u8 *quantities = gSaveBlock2Ptr->pyramidBag.quantity[gSaveBlock2Ptr->frontierChosenLvl]; + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + if (items[i] == itemId) + { + if (quantities[i] >= count) + return TRUE; + + count -= quantities[i]; if (count == 0) return TRUE; } } - //Check space in empty item slots - if (count > 0) + return FALSE; +} + +static bool8 CheckPyramidBagHasSpace(u16 itemId, u16 count) +{ + u8 i; + u16 *items = gSaveBlock2Ptr->pyramidBag.itemId[gSaveBlock2Ptr->frontierChosenLvl]; + u8 *quantities = gSaveBlock2Ptr->pyramidBag.quantity[gSaveBlock2Ptr->frontierChosenLvl]; + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) { - for (i = 0; i < gBagPockets[pocket].capacity; i++) + if (items[i] == itemId || items[i] == ITEM_NONE) { - if (gBagPockets[pocket].itemSlots[i].itemId == 0) - { - if (count <= slotCapacity) - return TRUE; - if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) - return FALSE; - count -= slotCapacity; - } + if (quantities[i] + count <= 99) + return TRUE; + + count = (quantities[i] + count) - 99; + if (count == 0) + return TRUE; } - if (count > 0) - return FALSE; //No more item slots. The bag is full } - return TRUE; -}*/ + return FALSE; +} + +static bool8 AddPyramidBagItem(u16 itemId, u16 count) +{ + u16 i; + + u16 *items = gSaveBlock2Ptr->pyramidBag.itemId[gSaveBlock2Ptr->frontierChosenLvl]; + u8 *quantities = gSaveBlock2Ptr->pyramidBag.quantity[gSaveBlock2Ptr->frontierChosenLvl]; + + u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + + memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + if (newItems[i] == itemId && newQuantities[i] < 99) + { + newQuantities[i] += count; + if (newQuantities[i] > 99) + { + count = newQuantities[i] - 99; + newQuantities[i] = 99; + } + else + { + count = 0; + } + + if (count == 0) + break; + } + } + + if (count > 0) + { + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + if (newItems[i] == ITEM_NONE) + { + newItems[i] = itemId; + newQuantities[i] = count; + if (newQuantities[i] > 99) + { + count = newQuantities[i] - 99; + newQuantities[i] = 99; + } + else + { + count = 0; + } + + if (count == 0) + break; + } + } + } + + if (count == 0) + { + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + Free(newItems); + Free(newQuantities); + return TRUE; + } + else + { + Free(newItems); + Free(newQuantities); + return FALSE; + } +} + +extern u16 gUnknown_0203CF30[]; + +static bool8 RemovePyramidBagItem(u16 itemId, u16 count) +{ + u16 i; + + u16 *items = gSaveBlock2Ptr->pyramidBag.itemId[gSaveBlock2Ptr->frontierChosenLvl]; + u8 *quantities = gSaveBlock2Ptr->pyramidBag.quantity[gSaveBlock2Ptr->frontierChosenLvl]; + + i = gUnknown_0203CF30[3] + gUnknown_0203CF30[4]; + if (items[i] == itemId && quantities[i] >= count) + { + quantities[i] -= count; + if (quantities[i] == 0) + items[i] = ITEM_NONE; + return TRUE; + } + else + { + u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + + memcpy(newItems, items, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + memcpy(newQuantities, quantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + if (newItems[i] == itemId) + { + if (newQuantities[i] >= count) + { + newQuantities[i] -= count; + count = 0; + if (newQuantities[i] == 0) + newItems[i] = ITEM_NONE; + } + else + { + count -= newQuantities[i]; + newQuantities[i] = 0; + newItems[i] = ITEM_NONE; + } + + if (count == 0) + break; + } + } + + if (count == 0) + { + memcpy(items, newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); + memcpy(quantities, newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); + Free(newItems); + Free(newQuantities); + return TRUE; + } + else + { + Free(newItems); + Free(newQuantities); + return FALSE; + } + } +} + +static u16 SanitizeItemId(u16 itemId) +{ + if (itemId >= ITEM_LAST_ID + 1) + return ITEM_NONE; + else + return itemId; +} + +const u8 *ItemId_GetName(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].name; +} + +u16 ItemId_GetId(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].itemId; +} + +u16 ItemId_GetPrice(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].price; +} + +u8 ItemId_GetHoldEffect(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].holdEffect; +} + +u8 ItemId_GetHoldEffectParam(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].holdEffectParam; +} + +const u8 *ItemId_GetDescription(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].description; +} + + +u8 ItemId_GetImportance(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].importance; +} + +// unused +u8 ItemId_GetUnknownValue(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].unk19; +} + +u8 ItemId_GetPocket(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].pocket; +} + +u8 ItemId_GetType(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].type; +} + +ItemUseFunc ItemId_GetFieldFunc(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].fieldUseFunc; +} + +u8 ItemId_GetBattleUsage(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].battleUsage; +} + +ItemUseFunc ItemId_GetBattleFunc(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].battleUseFunc; +} + +u8 ItemId_GetSecondaryId(u16 itemId) +{ + return gItems[SanitizeItemId(itemId)].secondaryId; +} diff --git a/src/item_menu.c b/src/item_menu.c index 8c05f0828..d7edea301 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -72,7 +72,7 @@ void AddBagItemIconSprite(u16, u8); void bag_menu_print_description_box_text(int); void bag_menu_print_cursor(u8, u8); void bag_menu_print(u8, u8, const u8*, u8, u8, u8, u8, u8, u8); -bool8 itemid_is_unique(u16); +bool8 ItemId_GetImportance(u16); u16 BagGetQuantityByPocketPosition(u8, u16); void sub_81AB89C(void); void task_close_bag_menu_2(u8); @@ -687,7 +687,7 @@ void sub_81AB520(u8 rboxId, int item_index_in_pocket, u8 a) offset = GetStringRightAlignXOffset(7, gStringVar4, 0x77); bag_menu_print(rboxId, 7, gStringVar4, offset, a, 0, 0, -1, 0); } - else if (gUnknown_0203CE58.pocket != 4 && (unique = itemid_is_unique(itemId)) == FALSE) + else if (gUnknown_0203CE58.pocket != 4 && (unique = ItemId_GetImportance(itemId)) == FALSE) { ConvertIntToDecimalStringN(gStringVar1, itemQuantity, 1, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); @@ -804,10 +804,10 @@ void sub_81AB9A8(u8 pocketId) { case 2: case 3: - sub_80D6FB4(pocket); + SortBerriesOrTMHMs(pocket); break; default: - sub_80D6F64(pocket); + CompactItemsInBagPocket(pocket); break; } gUnknown_0203CE54->unk829[pocketId] = 0; @@ -847,9 +847,9 @@ void sub_81ABAE0(void) sub_8122298(&gUnknown_0203CE58.scrollPosition[i], &gUnknown_0203CE58.cursorPosition[i], gUnknown_0203CE54->unk82E[i], gUnknown_0203CE54->unk829[i], 8); } -u8 sub_81ABB2C(u8 a) +u8 sub_81ABB2C(u8 pocketId) { - return gUnknown_0203CE58.scrollPosition[a] + gUnknown_0203CE58.cursorPosition[a]; + return gUnknown_0203CE58.scrollPosition[pocketId] + gUnknown_0203CE58.cursorPosition[pocketId]; } void DisplayItemMessage(u8 taskId, u8 fontId, const u8 *str, void ( *callback)(u8 taskId)) @@ -1179,7 +1179,7 @@ void sub_81AC498(u8 taskId) sub_81AC590(taskId); else { - sub_80D702C(gBagPockets[gUnknown_0203CE58.pocket].itemSlots, data[1], realPos); + MoveItemSlotInList(gBagPockets[gUnknown_0203CE58.pocket].itemSlots, data[1], realPos); gUnknown_0203CE54->unk81A = -1; DestroyListMenuTask(data[0], scrollPos, cursorPos); if (data[1] < realPos) @@ -1231,7 +1231,7 @@ void sub_81AC644(u8 unused) gUnknown_0203CE54->unk828 = 4; break; case 8: - if (!itemid_is_unique(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) { gUnknown_0203CE54->unk820 = gUnknown_0861404B; gUnknown_0203CE54->unk828 = 2; @@ -1243,7 +1243,7 @@ void sub_81AC644(u8 unused) } break; case 6: - if (!itemid_is_unique(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) { gUnknown_0203CE54->unk820 = gUnknown_0861404D; gUnknown_0203CE54->unk828 = 2; @@ -1255,7 +1255,7 @@ void sub_81AC644(u8 unused) } break; case 7: - if (!itemid_is_unique(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) { gUnknown_0203CE54->unk820 = gUnknown_0861404F; gUnknown_0203CE54->unk828 = 2; @@ -1605,7 +1605,7 @@ void ItemMenu_Give(u8 taskId) { DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); } - else if (!itemid_is_unique(gSpecialVar_ItemId)) + else if (!ItemId_GetImportance(gSpecialVar_ItemId)) { if (CalculatePlayerPartyCount() == 0) bag_menu_print_there_is_no_pokemon(taskId); @@ -1686,7 +1686,7 @@ void item_menu_type_2(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeldHere); DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350); } - else if (gUnknown_0203CE58.pocket != 4 && !itemid_is_unique(gSpecialVar_ItemId)) + else if (gUnknown_0203CE58.pocket != 4 && !ItemId_GetImportance(gSpecialVar_ItemId)) { unknown_ItemMenu_Confirm(taskId); } @@ -1700,7 +1700,7 @@ void item_menu_type_b(u8 taskId) { if (ItemIsMail(gSpecialVar_ItemId) == TRUE) DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); - else if (gUnknown_0203CE58.pocket != 4 && !itemid_is_unique(gSpecialVar_ItemId)) + else if (gUnknown_0203CE58.pocket != 4 && !ItemId_GetImportance(gSpecialVar_ItemId)) gTasks[taskId].func = unknown_ItemMenu_Confirm; else bag_menu_print_cant_be_held_msg(taskId); @@ -1738,7 +1738,7 @@ void display_sell_item_ask_str(u8 taskId) { s16* data = gTasks[taskId].data; - if (itemid_get_market_price(gSpecialVar_ItemId) == 0) + if (ItemId_GetPrice(gSpecialVar_ItemId) == 0) { CopyItemName(gSpecialVar_ItemId, gStringVar2); StringExpandPlaceholders(gStringVar4, gText_CantBuyKeyItem); @@ -1765,7 +1765,7 @@ void sub_81AD680(u8 taskId) { s16* data = gTasks[taskId].data; - ConvertIntToDecimalStringN(gStringVar1, (itemid_get_market_price(gSpecialVar_ItemId) / 2) * data[8], 0, 6); + ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8], 0, 6); StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1); DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD6E4); } @@ -1790,7 +1790,7 @@ void sub_81AD730(u8 taskId) s16* data = gTasks[taskId].data; u8 windowId = bag_menu_add_window(8); - sub_81ABCC0(windowId, 1, (itemid_get_market_price(gSpecialVar_ItemId) / 2) * data[8]); + sub_81ABCC0(windowId, 1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]); bag_menu_AddMoney_window(); gTasks[taskId].func = sub_81AD794; } @@ -1801,7 +1801,7 @@ void sub_81AD794(u8 taskId) if (AdjustQuantityAccordingToDPadInput(&data[8], data[2]) == TRUE) { - sub_81ABCC0(gUnknown_0203CE54->unk818, data[8], (itemid_get_market_price(gSpecialVar_ItemId) / 2) * data[8]); + sub_81ABCC0(gUnknown_0203CE54->unk818, data[8], (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]); } else if (gMain.newKeys & A_BUTTON) { @@ -1825,7 +1825,7 @@ void sub_81AD84C(u8 taskId) s16* data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar2); - ConvertIntToDecimalStringN(gStringVar1, (itemid_get_market_price(gSpecialVar_ItemId) / 2) * data[8], 0, 6); + ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8], 0, 6); StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2); DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD8C8); } @@ -1838,7 +1838,7 @@ void sub_81AD8C8(u8 taskId) PlaySE(SE_REGI); RemoveBagItem(gSpecialVar_ItemId, data[8]); - AddMoney(&gSaveBlock1Ptr->money, (itemid_get_market_price(gSpecialVar_ItemId) / 2) * data[8]); + AddMoney(&gSaveBlock1Ptr->money, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]); DestroyListMenuTask(data[0], scrollPos, cursorPos); sub_81AB9A8(gUnknown_0203CE58.pocket); sub_81ABA88(gUnknown_0203CE58.pocket); @@ -1908,7 +1908,7 @@ void sub_81ADB14(u8 taskId) s16* data = gTasks[taskId].data; FillWindowPixelBuffer(1, 0); - if (itemid_is_unique(gSpecialVar_ItemId)) + if (ItemId_GetImportance(gSpecialVar_ItemId)) { bag_menu_print(1, 1, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, 0); gTasks[taskId].func = sub_81ADC0C; diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c index 812f1f975..ea244b6a0 100644 --- a/src/lilycove_lady.c +++ b/src/lilycove_lady.c @@ -392,7 +392,7 @@ bool8 sub_818DC60(void) static void sub_818DCAC(u8 *dest, u16 itemId) { - StringCopy(dest, ItemId_GetItem(itemId)->name); + StringCopy(dest, ItemId_GetName(itemId)); } void sub_818DCC8(void) @@ -671,7 +671,7 @@ static u8 sub_818E258(const u8 *str) void sub_818E274(void) { - StringCopy(gStringVar1, ItemId_GetItem(gUnknown_0203CD68->itemId)->name); + StringCopy(gStringVar1, ItemId_GetName(gUnknown_0203CD68->itemId)); } bool8 sub_818E298(void) diff --git a/src/player_pc.c b/src/player_pc.c index f56ecb128..6f39fa449 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -444,7 +444,7 @@ static void ItemStorage_Withdraw(u8 taskId) { s16 *data = gTasks[taskId].data; - NUM_ITEMS = sub_80D6CE4(); + NUM_ITEMS = CountUsedPCItemSlots(); if (NUM_ITEMS != 0) ItemStorage_WithdrawToss_Helper(taskId, FALSE); else @@ -459,7 +459,7 @@ static void ItemStorage_Toss(u8 taskId) { s16 *data = gTasks[taskId].data; - NUM_ITEMS = sub_80D6CE4(); + NUM_ITEMS = CountUsedPCItemSlots(); if (NUM_ITEMS != 0) ItemStorage_WithdrawToss_Helper(taskId, TRUE); else @@ -967,7 +967,7 @@ static void sub_816C0C8(void) static void sub_816C110(void) { - sub_80D6E84(); + CompactPCItems(); sub_812220C(gSaveBlock1Ptr->pcItems, 50, &(playerPCItemPageInfo.pageItems), &(playerPCItemPageInfo.count), 0x8); } @@ -1180,7 +1180,7 @@ static void ItemStorage_DoItemSwap(u8 taskId, bool8 a) { if(c != b - 1) { - sub_80D702C(gSaveBlock1Ptr->pcItems, c, b); + MoveItemSlotInList(gSaveBlock1Ptr->pcItems, c, b); ItemStorage_RefreshListMenu(); } } @@ -1301,7 +1301,7 @@ static void ItemStorage_DoItemToss(u8 taskId) data = gTasks[taskId].data; b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if(!itemid_is_unique(gSaveBlock1Ptr->pcItems[b].itemId)) + if(!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) { CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); @@ -1335,7 +1335,7 @@ static void ItemStorage_HandleRemoveItem(u8 taskId) data = gTasks[taskId].data; if(gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub_80D6E48((playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove), data[2]); + RemovePCItem((playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove), data[2]); DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); sub_816C110(); sub_816C140(); diff --git a/src/pokeblock.c b/src/pokeblock.c index e829452b2..60087b5bf 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -589,7 +589,7 @@ static void PutPokeblockInfoText(void) { u8 i; - const u8 *itemName = ItemId_GetItem(ITEM_POKEBLOCK_CASE)->name; + const u8 *itemName = ItemId_GetName(ITEM_POKEBLOCK_CASE); PrintOnPokeblockWindow(0, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48)); PrintOnPokeblockWindow(2, gText_Spicy, 0); diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index e7fcce629..f77b7c38c 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -3173,11 +3173,11 @@ void sub_81C3554(u8 taskId) void sub_81C35E4() { - u8 *text; + const u8 *text; int offset; if (gUnknown_0203CF1C->summary.item == ITEM_ENIGMA_BERRY && sub_81B1250() == 1 && (gUnknown_0203CF1C->unk40BE == 1 || gUnknown_0203CF1C->unk40BE == 4 || gUnknown_0203CF1C->unk40BE == 5)) { - text = (u8*)ItemId_GetItem(ITEM_ENIGMA_BERRY); + text = ItemId_GetName(ITEM_ENIGMA_BERRY); } else if (gUnknown_0203CF1C->summary.item == ITEM_NONE) text = gText_None; diff --git a/src/tv.c b/src/tv.c index b7c2812fe..21b81347c 100644 --- a/src/tv.c +++ b/src/tv.c @@ -2945,7 +2945,7 @@ static void sub_80EF40C(u8 varIdx, TVShow *show) { if (show->smartshopperShow.itemIds[i] != ITEM_NONE) { - price += itemid_get_market_price(show->smartshopperShow.itemIds[i]) * show->smartshopperShow.itemAmounts[i]; + price += ItemId_GetPrice(show->smartshopperShow.itemIds[i]) * show->smartshopperShow.itemAmounts[i]; } } if (show->smartshopperShow.priceReduced == TRUE) @@ -5120,7 +5120,7 @@ static void DoTVShowTodaysSmartShopper(void) break; case 1: TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - StringCopy(gStringVar2, ItemId_GetItem(show->smartshopperShow.itemIds[0])->name); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[0]); sTVShowState += 1 + (Random() % 4); break; @@ -5148,7 +5148,7 @@ static void DoTVShowTodaysSmartShopper(void) } break; case 6: - StringCopy(gStringVar2, ItemId_GetItem(show->smartshopperShow.itemIds[1])->name); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[1])); TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[1]); if (show->smartshopperShow.itemIds[2] != ITEM_NONE) { @@ -5164,7 +5164,7 @@ static void DoTVShowTodaysSmartShopper(void) } break; case 7: - StringCopy(gStringVar2, ItemId_GetItem(show->smartshopperShow.itemIds[2])->name); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[2])); TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[2]); if (show->smartshopperShow.priceReduced == TRUE) { @@ -5201,7 +5201,7 @@ static void DoTVShowTodaysSmartShopper(void) break; case 11: TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - StringCopy(gStringVar2, ItemId_GetItem(show->smartshopperShow.itemIds[0])->name); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); if (show->smartshopperShow.priceReduced == TRUE) { sTVShowState = 8; @@ -5344,7 +5344,7 @@ static void DoTVShowPokemonTodaySuccessfulCapture(void) sTVShowState = 2; break; case 2: - StringCopy(gStringVar2, ItemId_GetItem(show->pokemonToday.ball)->name); + StringCopy(gStringVar2, ItemId_GetName(show->pokemonToday.ball)); TV_PrintIntToStringVar(2, show->pokemonToday.nBallsUsed); if (show->pokemonToday.nBallsUsed < 4) { @@ -6457,7 +6457,7 @@ static void DoTVShowHoennTreasureInvestigators(void) switch (state) { case 0: - StringCopy(gStringVar1, ItemId_GetItem(show->treasureInvestigators.item)->name); + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); if (show->treasureInvestigators.location == MAPSEC_DYNAMIC) { switch (show->treasureInvestigators.mapDataId) @@ -6476,13 +6476,13 @@ static void DoTVShowHoennTreasureInvestigators(void) } break; case 1: - StringCopy(gStringVar1, ItemId_GetItem(show->treasureInvestigators.item)->name); + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); GetMapName(gStringVar3, show->treasureInvestigators.location, 0); TVShowDone(); break; case 2: - StringCopy(gStringVar1, ItemId_GetItem(show->treasureInvestigators.item)->name); + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); TVShowDone(); break; @@ -6598,7 +6598,7 @@ static void DoTVShowBreakingNewsTV(void) break; case 3: TV_PrintIntToStringVar(0, show->breakingNews.balls); - StringCopy(gStringVar2, ItemId_GetItem(show->breakingNews.caughtMonBall)->name); + StringCopy(gStringVar2, ItemId_GetName(show->breakingNews.caughtMonBall)); sTVShowState = 4; break; case 4: @@ -6788,7 +6788,7 @@ static void DoTVShowPokemonLotteryWinnerFlashReport(void) { StringCopy(gStringVar2, gText_Third); } - StringCopy(gStringVar3, ItemId_GetItem(show->lottoWinner.item)->name); + StringCopy(gStringVar3, ItemId_GetName(show->lottoWinner.item)); TVShowDone(); ShowFieldMessage(sTVPokemonLotteryWinnerFlashReportTextGroup[state]); } @@ -7530,7 +7530,7 @@ static void DoTVShowSecretBaseSecrets(void) sTVShowState = show->secretBaseSecrets.savedState; break; case 19: - StringCopy(gStringVar2, ItemId_GetItem(show->secretBaseSecrets.item)->name); + StringCopy(gStringVar2, ItemId_GetName(show->secretBaseSecrets.item)); sTVShowState = show->secretBaseSecrets.savedState; break; case 20: