From 5ecb84bfbcddb14a010e7e0af4df852b5c0efee9 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Tue, 18 Oct 2022 18:45:08 -0500 Subject: [PATCH] doing some more decomp --- asm/code_8044210.s | 191 ---------------------------------- asm/code_805D8C8.s | 12 +-- asm/code_8083654.s | 9 -- include/dungeon_global_data.h | 6 +- include/dungeon_leader.h | 1 + include/item.h | 2 +- src/dungeon_action.c | 97 +++++++++++++++++ src/dungeon_leader.c | 5 + src/items.c | 2 +- 9 files changed, 115 insertions(+), 210 deletions(-) diff --git a/asm/code_8044210.s b/asm/code_8044210.s index f92362577..72ac45fbf 100644 --- a/asm/code_8044210.s +++ b/asm/code_8044210.s @@ -1033,195 +1033,4 @@ _08044B20: .4byte gDungeonGlobalData _08044B24: .4byte 0x000135cc thumb_func_end sub_8044AB4 - thumb_func_start sub_8044B28 -sub_8044B28: - push {r4,lr} - ldr r4, _08044B48 - ldr r0, [r4] - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _08044B76 - bl GetLeaderEntity - cmp r0, 0 - bne _08044B50 - ldr r0, [r4] - ldr r1, _08044B4C - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] - b _08044B76 - .align 2, 0 -_08044B48: .4byte gDungeonGlobalData -_08044B4C: .4byte 0x00000654 -_08044B50: - ldr r0, [r4] - ldrb r2, [r0, 0x2] - cmp r2, 0x1 - bne _08044B68 - ldr r2, _08044B64 - adds r1, r0, r2 - movs r0, 0x2 - strb r0, [r1] - b _08044B76 - .align 2, 0 -_08044B64: .4byte 0x00000654 -_08044B68: - cmp r2, 0x2 - beq _08044B70 - movs r0, 0 - b _08044B78 -_08044B70: - ldr r1, _08044B80 - adds r0, r1 - strb r2, [r0] -_08044B76: - movs r0, 0x1 -_08044B78: - pop {r4} - pop {r1} - bx r1 - .align 2, 0 -_08044B80: .4byte 0x00000654 - thumb_func_end sub_8044B28 - - thumb_func_start sub_8044B84 -sub_8044B84: - push {lr} - ldr r0, _08044B9C - ldr r0, [r0] - ldrb r0, [r0, 0x10] - cmp r0, 0 - bne _08044BA0 - bl sub_8044B28 - lsls r0, 24 - lsrs r0, 24 - b _08044BA2 - .align 2, 0 -_08044B9C: .4byte gDungeonGlobalData -_08044BA0: - movs r0, 0x1 -_08044BA2: - pop {r1} - bx r1 - thumb_func_end sub_8044B84 - - thumb_func_start sub_8044BA8 -sub_8044BA8: - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - lsls r1, 24 - lsrs r5, r1, 24 - cmp r4, 0x26 - bne _08044BCC - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _08044BCC - ldr r0, _08044BC8 - b _08044C02 - .align 2, 0 -_08044BC8: .4byte gUnknown_80F91EC -_08044BCC: - ldr r1, _08044BEC - lsls r0, r4, 3 - adds r4, r0, r1 - ldr r0, [r4] - ldr r1, _08044BF0 - bl strcmp - cmp r0, 0 - beq _08044BE0 - movs r0, 0x1 -_08044BE0: - lsls r0, 24 - cmp r0, 0 - beq _08044BF4 - ldr r0, [r4] - b _08044C04 - .align 2, 0 -_08044BEC: .4byte gUnknown_80F7C50 -_08044BF0: .4byte gUnknown_80F697C -_08044BF4: - ldr r4, _08044C0C - adds r0, r5, 0 - bl GetItemCategory - lsls r0, 3 - adds r4, 0x4 - adds r0, r4 -_08044C02: - ldr r0, [r0] -_08044C04: - pop {r4,r5} - pop {r1} - bx r1 - .align 2, 0 -_08044C0C: .4byte gActions - thumb_func_end sub_8044BA8 - - thumb_func_start sub_8044C10 -sub_8044C10: - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl sub_8083654 - adds r2, r0, 0 - adds r1, r2, 0 - adds r1, 0x44 - movs r3, 0 - movs r0, 0 - strh r0, [r1] - cmp r4, 0 - beq _08044C44 - adds r0, r2, 0 - adds r0, 0x48 - strb r3, [r0] - adds r0, 0x8 - strb r3, [r0] - adds r1, 0x14 - ldr r0, _08044C4C - strh r0, [r1] - adds r1, 0x2 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] -_08044C44: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08044C4C: .4byte 0x0000ffff - thumb_func_end sub_8044C10 - - thumb_func_start sub_8044C50 -sub_8044C50: - push {r4,lr} - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - bl sub_8083654 - adds r2, r0, 0 - adds r0, 0x44 - movs r1, 0 - strh r4, [r0] - adds r0, 0x4 - strb r1, [r0] - adds r0, 0x8 - strb r1, [r0] - adds r1, r2, 0 - adds r1, 0x58 - ldr r0, _08044C84 - strh r0, [r1] - adds r1, 0x2 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08044C84: .4byte 0x0000ffff - thumb_func_end sub_8044C50 - .align 2, 0 diff --git a/asm/code_805D8C8.s b/asm/code_805D8C8.s index f7d79d2f3..cb68e38cc 100644 --- a/asm/code_805D8C8.s +++ b/asm/code_805D8C8.s @@ -2907,7 +2907,7 @@ sub_805EFB4: mov r8, r0 lsls r1, 24 lsrs r7, r1, 24 - bl sub_8083654 + bl GetLeaderEntityData adds r6, r0, 0 cmp r7, 0 beq _0805EFE2 @@ -3146,7 +3146,7 @@ _0805F19C: .4byte gUnknown_80F9BB0 thumb_func_start sub_805F1A0 sub_805F1A0: push {lr} - bl sub_8083654 + bl GetLeaderEntityData adds r0, 0x44 pop {r1} bx r1 @@ -3155,7 +3155,7 @@ sub_805F1A0: thumb_func_start sub_805F1AC sub_805F1AC: push {lr} - bl sub_8083654 + bl GetLeaderEntityData adds r0, 0x44 ldrh r0, [r0] pop {r1} @@ -3638,7 +3638,7 @@ _0805F5B0: movs r2, 0x1 movs r3, 0x1 bl sub_804A728 - bl sub_8083654 + bl GetLeaderEntityData adds r0, 0x48 strb r7, [r0] movs r0, 0 @@ -3726,7 +3726,7 @@ _0805F65C: cmp r0, 0 beq _0805F64E _0805F676: - bl sub_8083654 + bl GetLeaderEntityData adds r0, 0x48 strb r7, [r0] cmp r4, r7 @@ -7991,7 +7991,7 @@ _08061994: subs r0, 0x1 cmp r0, r9 bge _08061994 - bl sub_8083654 + bl GetLeaderEntityData ldrb r1, [r0, 0x9] add r0, sp, 0x4 bl GetAvailTacticsforLvl diff --git a/asm/code_8083654.s b/asm/code_8083654.s index ac0e95c88..e1996fa57 100644 --- a/asm/code_8083654.s +++ b/asm/code_8083654.s @@ -5,15 +5,6 @@ .text - thumb_func_start sub_8083654 -sub_8083654: - push {lr} - bl GetLeaderEntity - ldr r0, [r0, 0x70] - pop {r1} - bx r1 - thumb_func_end sub_8083654 - thumb_func_start sub_8083660 sub_8083660: push {r4-r7,lr} diff --git a/include/dungeon_global_data.h b/include/dungeon_global_data.h index ed6b25640..c75fa3288 100644 --- a/include/dungeon_global_data.h +++ b/include/dungeon_global_data.h @@ -35,7 +35,7 @@ struct DungeonGlobalData u8 unkC; u8 unkD[0xF - 0xD]; /* 0xF */ bool8 inputAllowed; // Whether the game is currently accepting input. Set to false while action animations play. - u8 fill10; + u8 unk10; u8 unk11; s16 unk12; u8 fill14[0x16D - 0x14]; @@ -47,7 +47,9 @@ struct DungeonGlobalData /* 0x57C */ u8 fill57C[0x644 - 0x57c]; /* 0x644 */ u8 unk644; /* 0x645 */ u8 floorNumber; - u8 fill646[0x65C - 0x646]; + u8 fill646[0x654 - 0x646]; + u8 unk654; + u8 fill655[0x65C - 0x655]; u8 unk65C; u8 fill65D[0x660 - 0x65D]; /* 0x660 */ s16 speedTurnCounter; // Handles turn order when Pokémon have different movement speeds. diff --git a/include/dungeon_leader.h b/include/dungeon_leader.h index 52f70cbca..58f433127 100644 --- a/include/dungeon_leader.h +++ b/include/dungeon_leader.h @@ -2,5 +2,6 @@ #define GUARD_DUNGEON_LEADER_H struct DungeonEntity* GetLeaderEntity(); +struct DungeonEntityData* GetLeaderEntityData(void); #endif diff --git a/include/item.h b/include/item.h index 799d8e528..1b687c341 100644 --- a/include/item.h +++ b/include/item.h @@ -88,7 +88,7 @@ s32 GetItemBuyPrice(u8 itemIndex); s32 GetItemSellPrice(u8 itemIndex); s32 GetItemOrder(u8 itemIndex); u8 GetItemPalette(u8 itemIndex); -u8 GetItemCategory(u8 itemIndex); +u32 GetItemCategory(u8 itemIndex); u32 GetItemUnkThrow(u8 itemIndex, u32 r1); u8 *GetItemDescription(u8 itemIndex); bool8 GetItemAIFlag(u8 itemIndex, u32 r1); diff --git a/src/dungeon_action.c b/src/dungeon_action.c index 912e8b434..469837755 100644 --- a/src/dungeon_action.c +++ b/src/dungeon_action.c @@ -3,7 +3,104 @@ #include "constants/dungeon_action.h" #include "dungeon_entity.h" +#include "dungeon_global_data.h" +#include "dungeon_leader.h" #include "pokemon.h" +#include "item.h" + +extern u8 *gUnknown_80F91EC[]; +extern u8 *gUnknown_80F7C50[]; +extern u8 gUnknown_80F697C[]; + +struct ItemText +{ + u8 *desc; + u8 *useText; +}; +extern const struct ItemText gActions[]; + + +extern u8 sub_8043D10(void); +extern bool8 sub_8044B28(void); + +bool8 sub_8044B28(void) +{ + if (gDungeonGlobalData->unk4 == 0) { + if (GetLeaderEntity() == NULL) { + gDungeonGlobalData->unk654 = 1; + } + else if (gDungeonGlobalData->unk2 == 1) { + gDungeonGlobalData->unk654 = 2; + } + else if (gDungeonGlobalData->unk2 != 2) { + return FALSE; + } + else { + gDungeonGlobalData->unk654 = 2; + } + } + return TRUE; +} + +bool8 sub_8044B84(void) +{ + if(gDungeonGlobalData->unk10 != 0) + { + return TRUE; + } + else { + return sub_8044B28(); + } +} + +u8 *sub_8044BA8(u16 param_1, u8 itemIndex) +{ + u32 uVar3; + u32 uVar4; + + if ((param_1 == 0x26) && (sub_8043D10() == 2)) { + return *gUnknown_80F91EC; + } + else { + uVar3 = uVar4 = strcmp(gUnknown_80F7C50[param_1 << 1], gUnknown_80F697C); + if (uVar3 != 0) { + uVar4 = 1; + } + if ((u8)(uVar4) == 0) { + return gActions[GetItemCategory(itemIndex)].useText; + } + else + { + return gUnknown_80F7C50[param_1 << 1]; + } + } +} + +void sub_8044C10(u8 param_1) +{ + struct DungeonEntityData * entityData = GetLeaderEntityData(); + + entityData->action.action = DUNGEON_ACTION_NONE; + + if(param_1) + { + entityData->action.actionUseIndex = 0; + entityData->action.unkC = 0; + entityData->itemTargetPosition.x = -1; + entityData->itemTargetPosition.y = -1; + } +} + +void sub_8044C50(u16 action) +{ + struct DungeonEntityData * entityData = GetLeaderEntityData(); + + entityData->action.action = action; + entityData->action.actionUseIndex = 0; + entityData->action.unkC = 0; + entityData->itemTargetPosition.x = -1; + entityData->itemTargetPosition.y = -1; +} void ResetAction(struct DungeonActionContainer *actionPointer) { diff --git a/src/dungeon_leader.c b/src/dungeon_leader.c index 5bff54220..17a676aef 100644 --- a/src/dungeon_leader.c +++ b/src/dungeon_leader.c @@ -25,3 +25,8 @@ struct DungeonEntity* GetLeaderEntity() } return leader; } + +struct DungeonEntityData* GetLeaderEntityData(void) +{ + return GetLeaderEntity()->entityData; +} diff --git a/src/items.c b/src/items.c index a09c83ec5..a1ab3ba6e 100644 --- a/src/items.c +++ b/src/items.c @@ -281,7 +281,7 @@ u8 GetItemPalette(u8 itemIndex) return gItemParametersData[itemIndex].palette; } -u8 GetItemCategory(u8 itemIndex) +u32 GetItemCategory(u8 itemIndex) { return gItemParametersData[itemIndex].category; }