diff --git a/asm/code_8048480.s b/asm/code_8048480.s deleted file mode 100644 index a269780cd..000000000 --- a/asm/code_8048480.s +++ /dev/null @@ -1,166 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_8048A68 -sub_8048A68: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - mov r9, r0 - mov r8, r1 - ldrb r1, [r1] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08048A90 - ldr r0, _08048A8C -_08048A80: - ldr r1, [r0] - movs r0, 0 - movs r2, 0x1 - bl PrintFieldMessage - b _08048B8C - .align 2, 0 -_08048A8C: .4byte gUnknown_80FE3E8 -_08048A90: - ldr r0, _08048AA4 - ldr r0, [r0] - ldr r1, _08048AA8 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _08048AB0 - ldr r0, _08048AAC - b _08048A80 - .align 2, 0 -_08048AA4: .4byte gDungeon -_08048AA8: .4byte 0x0000065c -_08048AAC: .4byte gUnknown_80F9BD8 -_08048AB0: - movs r7, 0 -_08048AB2: - ldr r0, _08048B24 - ldr r0, [r0] - lsls r1, r7, 2 - ldr r2, _08048B28 - adds r0, r2 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _08048B4A - ldr r5, [r4, 0x70] - movs r6, 0x1 - ldrb r0, [r5, 0xA] - cmp r0, 0x3 - bhi _08048AF4 - ldr r2, _08048B2C - ldrb r1, [r5, 0xA] - movs r0, 0x64 - muls r1, r0 - ldr r0, _08048B30 - adds r1, r0 - ldr r0, [r2] - adds r0, r1 - movs r1, 0xA - ldrsh r0, [r0, r1] - bl sub_806A538 - lsls r0, 24 - cmp r0, 0 - beq _08048AF6 -_08048AF4: - movs r6, 0 -_08048AF6: - adds r0, r4, 0 - movs r1, 0 - bl CannotMove - lsls r0, 24 - cmp r0, 0 - beq _08048B06 - movs r6, 0 -_08048B06: - adds r0, r5, 0 - adds r0, 0xA4 - ldrb r0, [r0] - cmp r0, 0x1 - bne _08048B12 - movs r6, 0 -_08048B12: - adds r0, r5, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _08048B20 - cmp r0, 0x47 - bne _08048B34 -_08048B20: - movs r0, 0x1 - b _08048B36 - .align 2, 0 -_08048B24: .4byte gDungeon -_08048B28: .4byte 0x0001357c -_08048B2C: .4byte gRecruitedPokemonRef -_08048B30: .4byte 0x00008df8 -_08048B34: - movs r0, 0 -_08048B36: - cmp r0, 0 - beq _08048B3C - movs r6, 0 -_08048B3C: - ldrb r0, [r5, 0x7] - cmp r0, 0 - beq _08048B44 - movs r6, 0 -_08048B44: - ldr r2, _08048B84 - adds r0, r5, r2 - strb r6, [r0] -_08048B4A: - adds r7, 0x1 - cmp r7, 0x3 - ble _08048AB2 - movs r0, 0 - movs r1, 0x1 - bl DrawFieldGiveItemMenu - adds r4, r0, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _08048B8C - mov r0, r9 - mov r1, r8 - bl sub_804245C - ldr r0, _08048B88 - ldr r0, [r0] - adds r0, 0xBC - str r4, [r0] - movs r2, 0xA1 - lsls r2, 1 - mov r0, r9 - movs r1, 0 - bl sub_8044E24 - movs r0, 0x1 - b _08048B8E - .align 2, 0 -_08048B84: .4byte 0x00000157 -_08048B88: .4byte gDungeon -_08048B8C: - movs r0, 0 -_08048B8E: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8048A68 - - .align 2, 0 diff --git a/include/dungeon_global_data.h b/include/dungeon_global_data.h index e9e0b36de..a46ceddea 100644 --- a/include/dungeon_global_data.h +++ b/include/dungeon_global_data.h @@ -78,7 +78,7 @@ struct Dungeon s16 unk12; u8 fill14[0xB8 - 0x14]; struct Entity *unkB8; - u32 unkBC; + struct Entity *unkBC; u8 fillC0[0x16D - 0xC0]; u8 unk16D; u8 fill16E[0x179 - 0x16E]; diff --git a/include/pokemon.h b/include/pokemon.h index c2fabef6b..e2e19709f 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -75,7 +75,7 @@ struct PokemonStruct2 /* 0x3 */ u8 unkHasNextStage; // unk3 /* 0x4 */ struct DungeonLocation dungeonLocation; // unk4 /* 0x8 */ u16 IQ; // IQ (other offset) - /* 0xA */ u16 unkA; + /* 0xA */ s16 unkA; /* 0xC */ u16 unkC; /* 0xE */ s16 speciesNum; // speciesNum (other offset) /* 0x10 */ u16 unk10; // pokeHP diff --git a/ld_script.txt b/ld_script.txt index be91dbee4..897757750 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -200,8 +200,6 @@ SECTIONS { src/dungeon_items.o(.text); asm/code_8046CE4.o(.text); src/code_8048480.o(.text); - asm/code_8048480.o(.text); - src/code_8048DB8.o(.text); src/dungeon_ai_item_weight.o(.text); src/dungeon_map_access.o(.text); asm/code_80495E4.o(.text); diff --git a/src/code_8048480.c b/src/code_8048480.c index f77925de5..0db39440a 100644 --- a/src/code_8048480.c +++ b/src/code_8048480.c @@ -1,6 +1,8 @@ #include "global.h" +#include "constants/dungeon_action.h" #include "constants/iq_skill.h" #include "constants/status.h" +#include "dungeon_action.h" #include "dungeon_entity.h" #include "dungeon_util.h" #include "dungeon_global_data.h" @@ -11,6 +13,7 @@ #include "number_util.h" #include "moves.h" #include "code_8077274_1.h" +#include "code_80521D0.h" #include "pokemon.h" #include "position.h" #include "status.h" @@ -463,3 +466,323 @@ bool8 sub_8048950(u32 param_1,struct Item *item) } return FALSE; } + +extern void sub_803E708(u32, u32); +extern void sub_80421C0(struct Entity *r0, u16 r1); +extern void sub_8078B5C(struct Entity *, struct Entity *, u32, u32, u32); + +extern u8 gAvailablePokemonNames[]; +extern u8 gUnknown_202DE58[]; + +extern u8 *gPtrMusicBoxPlayedCrumbledMessage[]; +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 u8 *gUnknown_80FE3E8[]; +extern u8 *gUnknown_80F9BD8[]; + +extern u32 gUnknown_8106A4C; +extern u32 gUnknown_8106A50; +extern s16 gUnknown_80F4FAC; + +extern u8 sub_806A538(s32); +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 *); +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 void sub_8044E24(u32, u32, u32); +extern void sub_804245C(u32, struct Item *); + +static inline bool8 sub_8048A68_sub(struct EntityInfo *pokemonInfo) +{ + if (pokemonInfo->joinedAt == 0x4A) + { + return TRUE; + } + if (pokemonInfo->joinedAt == 0x47) + { + return TRUE; + } + return FALSE; +} + +bool8 sub_8048A68(u32 param_1,struct Item *item) +{ + u8 flag; + struct Entity *entity2; + struct Entity *entity; + struct EntityInfo *pEVar6; + s32 index; + struct PokemonStruct2 *pokemon; + + if ((item->flags & ITEM_FLAG_STICKY)) { + PrintFieldMessage(0,*gUnknown_80FE3E8,1); + return FALSE; + } + else + { + if (gDungeon->unk65C == 0) { + PrintFieldMessage(0,*gUnknown_80F9BD8,1); + return FALSE; + } + else + { + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity = gDungeon->teamPokemon[index]; + if (EntityExists(entity)) { + pEVar6 = entity->info; + flag = TRUE; + if(((MAX_TEAM_MEMBERS - 1) < pEVar6->teamIndex)) + flag = FALSE; + else + { + pokemon = &gRecruitedPokemonRef->pokemon2[pEVar6->teamIndex]; + if (sub_806A538(pokemon->unkA)) + flag = FALSE; + } + + if (CannotMove(entity, FALSE)) { + flag = FALSE; + } + if (pEVar6->clientType == CLIENT_TYPE_CLIENT) { + flag = FALSE; + } + if (sub_8048A68_sub(pEVar6)) { + flag = FALSE; + } + if (pEVar6->isTeamLeader) { + flag = FALSE; + } + pEVar6->unk157 = flag; + } + } + entity2 = DrawFieldGiveItemMenu(0,1); + if (!EntityExists(entity2)) { + return FALSE; + } + sub_804245C(param_1,item); + gDungeon->unkBC = entity2; + sub_8044E24(param_1,0,0x142); + return TRUE; + } + } + return FALSE; +} + +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) +{ + struct EntityInfo *entityInfo; + + entityInfo = pokemon->info; + + if ((item->flags & ITEM_FLAG_STICKY) != 0) { + sub_8045BF8(gUnknown_202DE58, item); + SendMessage(pokemon,*gUnknown_80FE3E8); + return FALSE; + } + else + { + if ((entityInfo->muzzled == TRUE) && (IsEdibleItem(item->id))) { + SetMessageArgument(gAvailablePokemonNames,pokemon,0); + SendMessage(pokemon,*gUnknown_80FDCA4); + return FALSE; + } + } + return TRUE; +} + +void sub_8048DB8(struct Entity *pokemon, struct Entity *target, u8 r2) +{ + u8 temp; + if(r2 != 0) + sub_806F370(pokemon, target, gUnknown_80F4FAC, 1, &temp, 0, 0x217, 0, 0, 0); + else + sub_8051E7C(pokemon); +} + +void sub_8048E04(struct Entity *pokemon, struct Entity * target) +{ + sub_8078B5C(pokemon, target, 0x1E, 0, 1); + switch(DungeonRandInt(5)) + { + case 0: + PoisonedStatusTarget(pokemon, target, TRUE); + break; + case 1: + ImmobilizedStatusTarget(pokemon, target); + break; + case 2: + BurnedStatusTarget(pokemon, target, 1, TRUE); + break; + case 3: + ParalyzeStatusTarget(pokemon, target, TRUE); + break; + case 4: + LowerAttackStageTarget(pokemon, target, gUnknown_8106A4C, 3, 1, TRUE); + LowerAttackStageTarget(pokemon, target, gUnknown_8106A50, 3, 1, TRUE); + break; + } +} + +void sub_8048EB0(struct Entity *pokemon) +{ + SendMessage(pokemon, *gPtrIcePartCrumbledMessage); +} + +void sub_8048EC4(struct Entity *pokemon) +{ + SendMessage(pokemon, *gPtrRockPartCrumbledMessage); +} + +void sub_8048ED8(struct Entity *pokemon) +{ + SendMessage(pokemon, *gPtrSteelPartCrumbledMessage); +} + +void sub_8048EEC(struct Entity *pokemon) +{ + SendMessage(pokemon, *gPtrWishStoneCrumbledMessage); +} + +void sub_8048F00(struct Entity *pokemon) +{ + sub_80421C0(pokemon, 0xD6); + SendMessage(pokemon, *gPtrMusicBoxPlayedCrumbledMessage); + sub_803E708(0x3C, 0x46); +} diff --git a/src/code_8048DB8.c b/src/code_8048DB8.c deleted file mode 100644 index d03bf36fb..000000000 --- a/src/code_8048DB8.c +++ /dev/null @@ -1,253 +0,0 @@ -#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" - -extern void sub_803E708(u32, u32); -extern void sub_80421C0(struct Entity *r0, u16 r1); -extern void sub_8078B5C(struct Entity *, struct Entity *, u32, u32, u32); - -extern u8 gAvailablePokemonNames[]; -extern u8 gUnknown_202DE58[]; - -extern u8 *gPtrMusicBoxPlayedCrumbledMessage[]; -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); - - -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) -{ - struct EntityInfo *entityInfo; - - entityInfo = pokemon->info; - - if ((item->flags & ITEM_FLAG_STICKY) != 0) { - sub_8045BF8(gUnknown_202DE58, item); - SendMessage(pokemon,*gUnknown_80FE3E8); - return FALSE; - } - else - { - if ((entityInfo->muzzled == TRUE) && (IsEdibleItem(item->id))) { - SetMessageArgument(gAvailablePokemonNames,pokemon,0); - SendMessage(pokemon,*gUnknown_80FDCA4); - return FALSE; - } - } - return TRUE; -} - -void sub_8048DB8(struct Entity *pokemon, struct Entity *target, u8 r2) -{ - u8 temp; - if(r2 != 0) - sub_806F370(pokemon, target, gUnknown_80F4FAC, 1, &temp, 0, 0x217, 0, 0, 0); - else - sub_8051E7C(pokemon); -} - -void sub_8048E04(struct Entity *pokemon, struct Entity * target) -{ - sub_8078B5C(pokemon, target, 0x1E, 0, 1); - switch(DungeonRandInt(5)) - { - case 0: - PoisonedStatusTarget(pokemon, target, TRUE); - break; - case 1: - ImmobilizedStatusTarget(pokemon, target); - break; - case 2: - BurnedStatusTarget(pokemon, target, 1, TRUE); - break; - case 3: - ParalyzeStatusTarget(pokemon, target, TRUE); - break; - case 4: - LowerAttackStageTarget(pokemon, target, gUnknown_8106A4C, 3, 1, TRUE); - LowerAttackStageTarget(pokemon, target, gUnknown_8106A50, 3, 1, TRUE); - break; - } -} - -void sub_8048EB0(struct Entity *pokemon) -{ - SendMessage(pokemon, *gPtrIcePartCrumbledMessage); -} - -void sub_8048EC4(struct Entity *pokemon) -{ - SendMessage(pokemon, *gPtrRockPartCrumbledMessage); -} - -void sub_8048ED8(struct Entity *pokemon) -{ - SendMessage(pokemon, *gPtrSteelPartCrumbledMessage); -} - -void sub_8048EEC(struct Entity *pokemon) -{ - SendMessage(pokemon, *gPtrWishStoneCrumbledMessage); -} - -void sub_8048F00(struct Entity *pokemon) -{ - sub_80421C0(pokemon, 0xD6); - SendMessage(pokemon, *gPtrMusicBoxPlayedCrumbledMessage); - sub_803E708(0x3C, 0x46); -} -