From f3be2cd40731c1d4d8d232d502f58f678982ad00 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 3 Jun 2023 19:59:48 -0700 Subject: [PATCH] more decomp --- asm/code_8048480.s | 560 ----------------------------- include/constants/dungeon_action.h | 4 + include/dungeon_entity.h | 3 +- src/code_8048480.c | 169 +++++++++ src/code_8048DB8.c | 144 +++++++- 5 files changed, 317 insertions(+), 563 deletions(-) diff --git a/asm/code_8048480.s b/asm/code_8048480.s index c7747b791..a269780cd 100644 --- a/asm/code_8048480.s +++ b/asm/code_8048480.s @@ -5,349 +5,6 @@ .text - thumb_func_start sub_80487E0 -sub_80487E0: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - mov r9, r0 - mov r8, r1 - lsls r3, r2, 24 - ldr r5, [r1, 0x70] - ldr r4, _08048858 - lsrs r3, 23 - adds r0, r5, 0 - adds r0, 0x5C - ldrb r0, [r0] - lsls r1, r0, 3 - adds r1, r0 - lsls r1, 2 - adds r1, r3, r1 - adds r0, r1, r4 - movs r2, 0 - ldrsh r6, [r0, r2] - adds r0, r5, 0 - adds r0, 0x5D - ldrb r2, [r0] - lsls r0, r2, 3 - adds r0, r2 - lsls r0, 2 - adds r3, r0 - adds r4, r3, r4 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r6, r0 - ldr r0, _0804885C - adds r1, r0 - movs r4, 0 - ldrsh r2, [r1, r4] - adds r3, r0 - movs r1, 0 - ldrsh r0, [r3, r1] - adds r2, r0 - movs r0, 0x1 - str r0, [sp] - mov r0, r9 - mov r1, r8 - movs r3, 0 - bl sub_8078B5C - ldrb r0, [r5, 0x6] - cmp r0, 0 - bne _08048906 - adds r0, r5, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _08048852 - cmp r0, 0x47 - bne _08048860 -_08048852: - movs r0, 0x1 - b _08048862 - .align 2, 0 -_08048858: .4byte gTypeGummiIQBoost -_0804885C: .4byte gUnknown_810A808 -_08048860: - movs r0, 0 -_08048862: - cmp r0, 0 - bne _08048906 - movs r2, 0xC - ldrsh r7, [r5, r2] - ldrh r0, [r5, 0xC] - adds r0, r6 - strh r0, [r5, 0xC] - adds r2, r7, r6 - lsls r0, 16 - cmp r0, 0 - bgt _0804887C - movs r0, 0x1 - strh r0, [r5, 0xC] -_0804887C: - movs r4, 0xC - ldrsh r0, [r5, r4] - ldr r1, _080488A0 - cmp r0, r1 - ble _08048888 - strh r1, [r5, 0xC] -_08048888: - movs r1, 0xC - ldrsh r0, [r5, r1] - cmp r7, r0 - bne _080488A8 - ldr r0, _080488A4 - ldr r2, [r0] - mov r0, r9 - mov r1, r8 - bl sub_80522F4 - b _08048906 - .align 2, 0 -_080488A0: .4byte 0x000003e7 -_080488A4: .4byte gUnknown_80FD644 -_080488A8: - subs r0, r2, r7 - movs r2, 0 - cmp r0, 0x8 - bgt _080488BE - movs r2, 0x1 - cmp r0, 0x4 - bgt _080488BE - movs r2, 0x3 - cmp r0, 0x2 - ble _080488BE - movs r2, 0x2 -_080488BE: - movs r4, 0xC - ldrsh r0, [r5, r4] - subs r0, r7 - movs r4, 0 - cmp r0, 0x8 - bgt _080488D8 - movs r4, 0x1 - cmp r0, 0x4 - bgt _080488D8 - movs r4, 0x3 - cmp r0, 0x2 - ble _080488D8 - movs r4, 0x2 -_080488D8: - ldr r1, _08048914 - lsls r0, r2, 2 - adds r0, r1 - ldr r2, [r0] - mov r0, r9 - mov r1, r8 - bl sub_80522F4 - ldr r1, _08048918 - lsls r0, r4, 2 - adds r0, r1 - ldr r2, [r0] - mov r0, r9 - mov r1, r8 - bl sub_80522F4 - mov r0, r8 - bl LoadIQSkills - adds r0, r5, 0 - adds r1, r7, 0 - bl sub_806A7E8 -_08048906: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08048914: .4byte gUnknown_80FD648 -_08048918: .4byte gUnknown_80FD6E8 - thumb_func_end sub_80487E0 - - thumb_func_start sub_804891C -sub_804891C: - push {lr} - movs r2, 0x3 - bl RaiseAtkStatTarget - pop {r0} - bx r0 - thumb_func_end sub_804891C - - thumb_func_start sub_8048928 -sub_8048928: - push {lr} - movs r2, 0x3 - bl RaiseSpAtkStatTarget - pop {r0} - bx r0 - thumb_func_end sub_8048928 - - thumb_func_start sub_8048934 -sub_8048934: - push {lr} - movs r2, 0x3 - bl RaiseDefStatTarget - pop {r0} - bx r0 - thumb_func_end sub_8048934 - - thumb_func_start sub_8048940 -sub_8048940: - push {lr} - movs r2, 0x3 - bl RaiseSpDefStatTarget - pop {r0} - bx r0 - thumb_func_end sub_8048940 - - thumb_func_start nullsub_94 -nullsub_94: - bx lr - thumb_func_end nullsub_94 - - thumb_func_start sub_8048950 -sub_8048950: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r10, r0 - mov r8, r1 - ldrb r0, [r1, 0x2] - bl GetItemMoveID - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - mov r0, r8 - ldrb r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08048988 - ldr r0, _08048984 -_08048978: - ldr r1, [r0] - movs r0, 0 - movs r2, 0x1 - bl PrintFieldMessage - b _08048A58 - .align 2, 0 -_08048984: .4byte gUnknown_80FE3E8 -_08048988: - mov r1, r8 - ldrb r0, [r1, 0x2] - bl IsHMItem - lsls r0, 24 - cmp r0, 0 - beq _080489A0 - ldr r0, _0804899C - b _08048978 - .align 2, 0 -_0804899C: .4byte gPtrCantUseInDungeonMessage -_080489A0: - movs r7, 0 -_080489A2: - ldr r0, _080489FC - ldr r0, [r0] - lsls r1, r7, 2 - ldr r2, _08048A00 - adds r0, r2 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _08048A12 - ldr r6, [r4, 0x70] - movs r0, 0x2 - ldrsh r1, [r6, r0] - mov r0, r9 - bl CanMonLearnMove - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r4, 0 - movs r1, 0 - bl CannotMove - lsls r0, 24 - cmp r0, 0 - beq _080489DC - movs r5, 0 -_080489DC: - adds r0, r6, 0 - adds r0, 0xA4 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080489E8 - movs r5, 0 -_080489E8: - adds r0, r6, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _080489F6 - cmp r0, 0x47 - bne _08048A04 -_080489F6: - movs r0, 0x1 - b _08048A06 - .align 2, 0 -_080489FC: .4byte gDungeon -_08048A00: .4byte 0x0001357c -_08048A04: - movs r0, 0 -_08048A06: - cmp r0, 0 - beq _08048A0C - movs r5, 0 -_08048A0C: - ldr r1, _08048A50 - adds r0, r6, r1 - strb r5, [r0] -_08048A12: - adds r7, 0x1 - cmp r7, 0x3 - ble _080489A2 - movs r0, 0 - movs r1, 0x1 - bl DrawFieldGiveItemMenu - adds r4, r0, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _08048A58 - mov r0, r10 - mov r1, r8 - bl sub_804245C - adds r0, r4, 0 - mov r1, r9 - bl sub_8072938 - lsls r0, 24 - cmp r0, 0 - beq _08048A58 - ldr r2, _08048A54 - mov r0, r10 - movs r1, 0 - bl sub_8044E24 - movs r0, 0x1 - b _08048A5A - .align 2, 0 -_08048A50: .4byte 0x00000157 -_08048A54: .4byte 0x00000141 -_08048A58: - movs r0, 0 -_08048A5A: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8048950 - thumb_func_start sub_8048A68 sub_8048A68: push {r4-r7,lr} @@ -506,221 +163,4 @@ _08048B8E: bx r1 thumb_func_end sub_8048A68 - thumb_func_start sub_8048B9C -sub_8048B9C: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x20 - mov r9, r0 - movs r0, 0 - mov r8, r0 - mov r2, r9 - ldr r0, [r2, 0x70] - adds r6, r0, 0 - adds r6, 0x44 - ldrb r1, [r1] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08048BD4 - ldr r0, _08048BD0 - ldr r1, [r0] - movs r0, 0 - movs r2, 0x1 - bl PrintFieldMessage - movs r0, 0 - b _08048D40 - .align 2, 0 -_08048BD0: .4byte gUnknown_80FE3E8 -_08048BD4: - movs r2, 0 -_08048BD6: - ldr r0, _08048C28 - ldr r0, [r0] - lsls r1, r2, 2 - ldr r3, _08048C2C - adds r0, r3 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - str r2, [sp, 0x1C] - bl EntityExists - lsls r0, 24 - ldr r2, [sp, 0x1C] - cmp r0, 0 - beq _08048C3E - ldr r5, [r4, 0x70] - movs r7, 0x1 - adds r0, r4, 0 - movs r1, 0 - bl CannotMove - lsls r0, 24 - ldr r2, [sp, 0x1C] - cmp r0, 0 - beq _08048C0A - movs r7, 0 -_08048C0A: - adds r0, r5, 0 - adds r0, 0xA4 - ldrb r0, [r0] - cmp r0, 0x1 - bne _08048C16 - movs r7, 0 -_08048C16: - adds r0, r5, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _08048C24 - cmp r0, 0x47 - bne _08048C30 -_08048C24: - movs r0, 0x1 - b _08048C32 - .align 2, 0 -_08048C28: .4byte gDungeon -_08048C2C: .4byte 0x0001357c -_08048C30: - movs r0, 0 -_08048C32: - cmp r0, 0 - beq _08048C38 - movs r7, 0 -_08048C38: - ldr r4, _08048C5C - adds r0, r5, r4 - strb r7, [r0] -_08048C3E: - adds r2, 0x1 - cmp r2, 0x3 - ble _08048BD6 - movs r0, 0 - movs r1, 0x1 - bl DrawFieldGiveItemMenu - adds r4, r0, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - bne _08048C60 - movs r0, 0 - b _08048D40 - .align 2, 0 -_08048C5C: .4byte 0x00000157 -_08048C60: - add r1, sp, 0x4 - adds r0, r6, 0 - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - b _08048CE2 -_08048C6E: - ldrh r0, [r6] - cmp r0, 0x1D - bne _08048C7C - adds r0, r6, 0 - bl sub_80637E8 - b _08048CE2 -_08048C7C: - cmp r0, 0x20 - bne _08048C9A - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - adds r0, r6, 0 - bl sub_8063BB4 - movs r0, 0x1 - bl sub_8044C10 - movs r5, 0x1 - mov r8, r5 - b _08048CE2 -_08048C9A: - cmp r0, 0x21 - bne _08048CB6 - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - adds r0, r6, 0 - movs r1, 0 - bl sub_8063CF0 - movs r0, 0x1 - bl sub_8044C10 - b _08048CE2 -_08048CB6: - cmp r0, 0x1E - beq _08048CBE - cmp r0, 0x33 - bne _08048CD0 -_08048CBE: - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - adds r0, r6, 0 - movs r1, 0 - bl sub_8063A70 - b _08048CE2 -_08048CD0: - cmp r0, 0x1F - bne _08048CE2 - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - adds r0, r6, 0 - bl sub_8063B54 -_08048CE2: - adds r0, r6, 0 - bl ClearMonsterActionFields - movs r0, 0x1 - str r0, [sp] - adds r0, r4, 0 - movs r1, 0x1 - movs r2, 0 - movs r3, 0 - bl sub_8062F90 - lsls r0, 24 - cmp r0, 0 - beq _08048C6E - mov r0, r8 - cmp r0, 0 - beq _08048D38 - ldr r0, _08048D34 - ldr r1, [r0] - movs r0, 0 - movs r2, 0x1 - bl sub_8052B8C - cmp r0, 0x1 - bne _08048C6E - adds r1, r6, 0 - add r0, sp, 0x4 - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - mov r0, r9 - movs r1, 0 - movs r2, 0x6E - bl sub_8044DF0 - adds r0, r6, 0 - movs r1, 0x2C - bl SetMonsterActionFields - b _08048D3E - .align 2, 0 -_08048D34: .4byte gUnknown_80FECA0 -_08048D38: - movs r0, 0x1 - bl sub_8044C10 -_08048D3E: - mov r0, r8 -_08048D40: - add sp, 0x20 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8048B9C - .align 2, 0 diff --git a/include/constants/dungeon_action.h b/include/constants/dungeon_action.h index 0d5a867cf..32a10ae9f 100644 --- a/include/constants/dungeon_action.h +++ b/include/constants/dungeon_action.h @@ -23,7 +23,11 @@ enum Action ACTION_CHANGE_TACTICS = 0x1A, ACTION_CHECK_SUMMARY = 0x1B, ACTION_TALK_MENU = 0x1C, // Talking to another Pokémon via the menu. + ACTION_UNK1D = 0x1D, ACTION_SET_MOVE = 0x1E, // Registering a move. + ACTION_UNK1F = 0x1F, + ACTION_UNK20 = 0x20, + ACTION_UNK21 = 0x21, ACTION_EAT_AI = 0x23, ACTION_THROW_ITEM_AI = 0x24, ACTION_THROW_STRAIGHT_PLAYER = 0x27, diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index d9572b407..435304f03 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -208,7 +208,8 @@ struct EntityInfo u8 unk153; u8 unk154; u8 unk155; - u8 fill158[0x158 - 0x156]; + u8 unk156; + bool8 unk157; u8 unk158; u8 unk159; u8 unk15A; diff --git a/src/code_8048480.c b/src/code_8048480.c index 2aae38ccb..f77925de5 100644 --- a/src/code_8048480.c +++ b/src/code_8048480.c @@ -2,13 +2,16 @@ #include "constants/iq_skill.h" #include "constants/status.h" #include "dungeon_entity.h" +#include "dungeon_util.h" #include "dungeon_global_data.h" #include "move_effects_target.h" +#include "dungeon_capabilities.h" #include "dungeon_pokemon_attributes.h" #include "dungeon_random.h" #include "number_util.h" #include "moves.h" #include "code_8077274_1.h" +#include "pokemon.h" #include "position.h" #include "status.h" @@ -35,7 +38,20 @@ extern u8 *gUnknown_80FE454[]; extern u8 *gPtrSelfHealPreventedHungerMessage[]; extern u8 *gUnknown_80F9740[]; extern u8 *gUnknown_80F9760[]; +extern u8 *gUnknown_80FD644[]; +extern u8 *gUnknown_80FD648[]; +extern u8 *gUnknown_80FD6E8[]; +extern u8 *gPtrCantUseInDungeonMessage[]; +extern u8 *gUnknown_80FE3E8[]; +extern s16 gTypeGummiIQBoost[0x12][NUMBER_OF_GUMMIS]; +extern s16 gUnknown_810A808[0x12][NUMBER_OF_GUMMIS]; + +struct Entity *DrawFieldGiveItemMenu(u32, u32); +extern void PrintFieldMessage(u32, u8 *, u32); +extern void sub_8044E24(u32, u32, u32); +extern void sub_804245C(u32, struct Item *); +extern u8 sub_8072938(struct Entity *, u16); extern void sub_807D148(struct Entity *pokemon, struct Entity *r1, u32 r2, struct Position *r3); extern void sub_8072008(struct Entity *pokemon, struct Entity *r1, u32 r2, u8 r3, u32); extern void LevelDownTarget(struct Entity *pokemon, struct Entity *r1, u32 r2); @@ -48,6 +64,8 @@ extern s32 sub_8042520(struct Entity *); struct Entity *sub_80696FC(struct Entity *); extern void sub_80943A0(void*, s32); extern void sub_803E708(u32 r0, u32 r1); +extern void sub_806A7E8(struct EntityInfo *, s32); + void sub_8048340(struct Entity *pokemon, struct Entity *target, u32 r2) { @@ -294,3 +312,154 @@ void sub_80487CC(struct Entity *pokemon, struct Entity * target, u32 param_3, u3 { sub_8078B5C(pokemon, target, param_3, param_4, 1); } + +static inline bool8 sub_80487E0_sub(struct EntityInfo *pokemonInfo) +{ + if (pokemonInfo->joinedAt == 0x4A) + { + return TRUE; + } + if (pokemonInfo->joinedAt == 0x47) + { + return TRUE; + } + return FALSE; +} + +void sub_80487E0(struct Entity *pokemon, struct Entity *target, u8 gummiIndex) +{ + s32 iVar3; + struct EntityInfo *targetInfo; + s32 gummiBoost; + s32 baseIQ; + s32 iVar4; + s32 iVar5; + s32 currIQ; + + targetInfo = target->info; + gummiBoost = gTypeGummiIQBoost[targetInfo->types[0]][gummiIndex]; + gummiBoost += gTypeGummiIQBoost[targetInfo->types[1]][gummiIndex]; + sub_8078B5C(pokemon,target, + gUnknown_810A808[targetInfo->types[0]][gummiIndex] + + gUnknown_810A808[targetInfo->types[1]][gummiIndex],0,1); + if (!targetInfo->isNotTeamMember) { + if (!sub_80487E0_sub(targetInfo)) { + baseIQ = targetInfo->IQ; + targetInfo->IQ += gummiBoost; + currIQ = baseIQ + gummiBoost; + if (targetInfo->IQ <= 0) { + targetInfo->IQ = 1; + } + if (999 < targetInfo->IQ) { + targetInfo->IQ = 999; + } + if (baseIQ == targetInfo->IQ) { + sub_80522F4(pokemon,target,*gUnknown_80FD644); + } + else { + iVar5 = currIQ - baseIQ; + iVar4 = 0; + if (((iVar5 < 9) && (iVar4 = 1, iVar5 < 5)) && (iVar4 = 3, 2 < iVar5)) { + iVar4 = 2; + } + iVar5 = targetInfo->IQ - baseIQ; + iVar3 = 0; + if (((iVar5 < 9) && (iVar3 = 1, iVar5 < 5)) && (iVar3 = 3, 2 < iVar5)) { + iVar3 = 2; + } + sub_80522F4(pokemon,target,gUnknown_80FD648[iVar4]); + sub_80522F4(pokemon,target,gUnknown_80FD6E8[iVar3]); + LoadIQSkills(target); + sub_806A7E8(targetInfo,baseIQ); + } + } + } +} + +void sub_804891C(struct Entity *pokemon, struct Entity *target) +{ + RaiseAtkStatTarget(pokemon, target, 3); +} + +void sub_8048928(struct Entity *pokemon, struct Entity *target) +{ + RaiseSpAtkStatTarget(pokemon, target, 3); +} + +void sub_8048934(struct Entity *pokemon, struct Entity *target) +{ + RaiseDefStatTarget(pokemon, target, 3); +} + +void sub_8048940(struct Entity *pokemon, struct Entity *target) +{ + RaiseSpDefStatTarget(pokemon, target, 3); +} + +void nullsub_94(void) +{} + +static inline bool8 sub_8048950_sub(struct EntityInfo *pokemonInfo) +{ + if (pokemonInfo->joinedAt == 0x4A) + { + return TRUE; + } + if (pokemonInfo->joinedAt == 0x47) + { + return TRUE; + } + return FALSE; +} + +bool8 sub_8048950(u32 param_1,struct Item *item) +{ + u8 flag; + u16 moveID; + struct Entity *entity2; + struct Entity *entity; + struct EntityInfo *entityInfo; + int index; + + moveID = GetItemMoveID(item->id); + if ((item->flags & ITEM_FLAG_STICKY)) { + PrintFieldMessage(0,*gUnknown_80FE3E8,1); + return FALSE; + } + else if (IsHMItem(item->id)) { + PrintFieldMessage(0,*gPtrCantUseInDungeonMessage,1); + return FALSE; + } + else + { + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity = gDungeon->teamPokemon[index]; + if (EntityExists(entity)) { + entityInfo = entity->info; + flag = CanMonLearnMove(moveID, entityInfo->id); + if (CannotMove(entity, FALSE)) { + flag = FALSE; + } + if (entityInfo->clientType == CLIENT_TYPE_CLIENT) { + flag = FALSE; + } + if (sub_8048950_sub(entityInfo)) { + flag = FALSE; + } + entityInfo->unk157 = flag; + } + } + entity2 = DrawFieldGiveItemMenu(0,1); + if (!EntityExists(entity2)) { + return FALSE; + } + sub_804245C(param_1,item); + if (sub_8072938(entity2,moveID) == 0) { + return FALSE; + } + sub_8044E24(param_1,0,0x141); + return TRUE; + } + return FALSE; +} diff --git a/src/code_8048DB8.c b/src/code_8048DB8.c index 61804d262..d03bf36fb 100644 --- a/src/code_8048DB8.c +++ b/src/code_8048DB8.c @@ -1,8 +1,13 @@ +#include "constants/dungeon_action.h" #include "global.h" #include "constants/status.h" #include "code_80521D0.h" #include "move_effects_target.h" +#include "dungeon_global_data.h" +#include "dungeon_action.h" +#include "dungeon_capabilities.h" #include "dungeon_random.h" +#include "dungeon_util.h" #include "item.h" #include "status.h" @@ -18,16 +23,151 @@ extern u8 *gPtrWishStoneCrumbledMessage[]; extern u8 *gPtrIcePartCrumbledMessage[]; extern u8 *gPtrRockPartCrumbledMessage[]; extern u8 *gPtrSteelPartCrumbledMessage[]; +extern u8 *gUnknown_80FDCA4[]; +extern u8 *gUnknown_80FE3E8[]; +extern u8 *gUnknown_80FECA0[]; + extern u32 gUnknown_8106A4C; extern u32 gUnknown_8106A50; extern s16 gUnknown_80F4FAC; + extern void sub_806F370(struct Entity *r0, struct Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); extern void sub_8051E7C(struct Entity *pokemon); extern void sub_8045BF8(u8 *, struct Item *); extern void SetMessageArgument(char[], struct Entity*, u32); +struct Entity *DrawFieldGiveItemMenu(u32, u32); +extern void PrintFieldMessage(u32, u8 *, u32); +extern void sub_8063B54(struct ActionContainer *); +extern void sub_80637E8(struct ActionContainer *); +extern void sub_8063BB4(struct ActionContainer *); +extern void sub_8063CF0(struct ActionContainer *, u32); +extern void sub_8063A70(struct ActionContainer *, u32); +extern u8 sub_8062F90(struct Entity *, u32, u32, u32, u32); +extern void sub_8044DF0(struct Entity *, u32, u32); +extern s32 sub_8052B8C(u32, u8 *, u32); +extern void sub_803EAF0(u32, u32); +extern void sub_8044C10(bool8); -extern u8 *gUnknown_80FDCA4[]; -extern u8 *gUnknown_80FE3E8[]; + +static inline bool8 sub_8048B9C_sub(struct EntityInfo *pokemonInfo) +{ + if (pokemonInfo->joinedAt == 0x4A) + { + return TRUE; + } + if (pokemonInfo->joinedAt == 0x47) + { + return TRUE; + } + return FALSE; +} + +// TODO: should be bool8 +bool32 sub_8048B9C(struct Entity *entity,struct Item *param_2) +{ +#ifndef NONMATCHING + register bool32 bVar2 asm("r8"); +#else + bool32 bVar2; +#endif + bool8 flag; + struct EntityInfo *entityInfo; + struct Entity * entity2; + int index; + struct Entity *entity1; + struct EntityInfo *entity1Info; + struct ActionContainer *actionPointer; + struct ActionContainer actionContainer; + u16 action; + + bVar2 = FALSE; + entityInfo = entity->info; + actionPointer = &(entityInfo->action); + if ((param_2->flags & ITEM_FLAG_STICKY)) { + PrintFieldMessage(0,*gUnknown_80FE3E8,1); + return FALSE; + } + else + { + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity1 = gDungeon->teamPokemon[index]; + if (EntityExists(entity1)) { + entity1Info = entity1->info; + flag = TRUE; + if(CannotMove(entity1, FALSE)) + { + flag = FALSE; + } + if(entity1Info->clientType == CLIENT_TYPE_CLIENT) + { + flag = FALSE; + } + if(sub_8048B9C_sub(entity1Info)) + { + flag = FALSE; + } + entity1Info->unk157 = flag; + } + } + entity2 = DrawFieldGiveItemMenu(0,1); + if (!EntityExists(entity2)) { + return FALSE; + } + else + { + while( TRUE ) { + entityInfo = entity2->info; + actionContainer = *actionPointer; + goto _clear; +_load: + action = actionPointer->action; + if (action == ACTION_UNK1D) { + sub_80637E8(actionPointer); + } + else if (action == ACTION_UNK20) { + sub_803EAF0(0,0); + sub_8063BB4(actionPointer); + sub_8044C10(TRUE); + bVar2 = TRUE; + } + else if (action == ACTION_UNK21) { + sub_803EAF0(0,0); + sub_8063CF0(actionPointer,0); + sub_8044C10(TRUE); + } + else if ((action == ACTION_SET_MOVE) || (action == ACTION_UNSET_MOVE)) { + sub_803EAF0(0,0); + sub_8063A70(actionPointer,0); + } + else if (action == ACTION_UNK1F) { + sub_803EAF0(0,0); + sub_8063B54(actionPointer); + } +_clear: + ClearMonsterActionFields(actionPointer); + if (sub_8062F90(entity2,1,0,0,1) != 0) { + if (bVar2) + { + if (sub_8052B8C(0,*gUnknown_80FECA0,1) == 1) { + *actionPointer = actionContainer; + sub_8044DF0(entity,0,0x6e); + SetMonsterActionFields(actionPointer,0x2c); + break; + } + } + else + { + sub_8044C10(TRUE); + break; + } + } + goto _load; + } + } + } + return bVar2; +} bool8 sub_8048D50(struct Entity * pokemon, struct Item *item) {