diff --git a/data/data_8106A4C.s b/data/data_8106A4C.s index 4d46c6ff7..ea2317b5d 100644 --- a/data/data_8106A4C.s +++ b/data/data_8106A4C.s @@ -34,10 +34,7 @@ gUnknown_8106AC8: @ 8106AC8 .global gUnknown_8106AE8 gUnknown_8106AE8: @ 8106AE8 - .byte 0x00, 0x00, 0x01, 0x00 - - .global gUnknown_8106AEC -gUnknown_8106AEC: @ 8106AEC +.byte 0x00, 0x00, 0x01, 0x00 .byte 0x12, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x13, 0x02, 0x00, 0x00 .byte 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x01, 0x00, 0xff, 0xff, 0x13, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff diff --git a/include/global.h b/include/global.h index c4cb58d9f..e833a5847 100644 --- a/include/global.h +++ b/include/global.h @@ -23,6 +23,13 @@ // Prevent cross-jump optimization. #define BLOCK_CROSS_JUMP asm(""); +// Sometimes incrementing and decrementing a variable changes how registers are allocated, which helps with matching functions. Functionality-wise this doesn't do anything. +#ifdef NONMATCHING +#define ASM_MATCH_TRICK(a) {;} +#else +#define ASM_MATCH_TRICK(a) {a++;a--;} +#endif // NONMATCHING + // to help in decompiling #define asm_comment(x) asm volatile("@ -- " x " -- ") diff --git a/include/items.h b/include/items.h index 76790b700..a57805e82 100644 --- a/include/items.h +++ b/include/items.h @@ -83,14 +83,6 @@ s32 SaveTeamInventory(u8 *, u32 size); s32 WriteHighDecimal(s32, u8 *strbuf, u8); u32 sub_80913E0(Item *slot, u32, struct subStruct_203B240 **); -// This macro doesn't do anything, it creates unused variables for the purpose of tricking the compiler and matching the asm. -// It's possible there was some unknown macro, or the structure of TeamInventory/Item is not 100% how it was originally written. -#define DUMMY_TEAM_ITEMS_ASM_MATCH(id) \ -{ \ - UNUSED size_t offs = id * sizeof(Item); \ - UNUSED Item *item = &gTeamInventoryRef->teamItems[id]; \ -} - static inline void ZeroOutItem(Item *item) { item->id = 0; @@ -108,6 +100,11 @@ static inline bool8 ItemExists(Item *item) return (item->flags & ITEM_FLAG_EXISTS); } +static inline bool8 ItemSet(Item *item) +{ + return (item->flags & ITEM_FLAG_SET); +} + static inline bool8 ItemInShop(Item *item) { return (item->flags & ITEM_FLAG_IN_SHOP); diff --git a/include/moves.h b/include/moves.h index c0d508cb3..30e87ce5e 100644 --- a/include/moves.h +++ b/include/moves.h @@ -22,7 +22,7 @@ typedef struct MoveDataFile } MoveDataFile; bool8 CanBeSnatched(u16 moveID); -void CopyAndResetMoves(Move *destMoves, Move *srcMoves); +void CopyAndResetMoves(Moves *destMoves, Move *srcMoves); void CopyBareMoveData(Move *destMoves, Move *srcMoves); bool8 DoesMoveCharge(u16 move); bool8 FailsWhileMuzzled(u16 moveID); @@ -94,6 +94,16 @@ static inline bool8 MoveFlagExists(Move *move) return (move->moveFlags & MOVE_FLAG_EXISTS); } +static inline bool8 MoveFlagSet(Move *move) +{ + return (move->moveFlags & MOVE_FLAG_SET); +} + +static inline bool8 MoveFlagLastUsed(Move *move) +{ + return (move->moveFlags & MOVE_FLAG_LAST_USED); +} + static inline bool8 MoveFlagLinkChain(Move *move) { return (move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN); diff --git a/include/pokemon.h b/include/pokemon.h index f0ea773c6..c48239df6 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -120,4 +120,11 @@ static inline bool8 IsMonPartner(PokemonStruct1 *mon) return (mon->dungeonLocation.id == DUNGEON_JOIN_LOCATION_PARTNER); } +// Needed to match a couple of functions which use species id. +// The theory is that there was some internal species conversion which got scrapped later on. +static inline s16 SpeciesId(s32 id) +{ + return id; +} + #endif // GUARD_POKEMON_H diff --git a/include/sprite_oam.h b/include/sprite_oam.h index 0f08fef1f..06e2c20fb 100644 --- a/include/sprite_oam.h +++ b/include/sprite_oam.h @@ -22,72 +22,72 @@ typedef struct SpriteOAM #define SPRITEOAM_MAX_Y 0xFF #define SPRITEOAM_SHIFT_Y 0 -#define SPRITEOAM_MASK_Y (SPRITEOAM_MAX_Y << SPRITEOAM_SHIFT_Y) +#define SPRITEOAM_MASK_Y (SPRITEOAM_MAX_Y << SPRITEOAM_SHIFT_Y) // ~ 0xFF00 #define SPRITEOAM_MAX_AFFINEMODE1 1 #define SPRITEOAM_SHIFT_AFFINEMODE1 8 -#define SPRITEOAM_MASK_AFFINEMODE1 (SPRITEOAM_MAX_AFFINEMODE1 << SPRITEOAM_SHIFT_AFFINEMODE1) +#define SPRITEOAM_MASK_AFFINEMODE1 (SPRITEOAM_MAX_AFFINEMODE1 << SPRITEOAM_SHIFT_AFFINEMODE1) // ~ 0xFEFF #define SPRITEOAM_MAX_AFFINEMODE2 1 #define SPRITEOAM_SHIFT_AFFINEMODE2 9 -#define SPRITEOAM_MASK_AFFINEMODE2 (SPRITEOAM_MAX_AFFINEMODE2 << SPRITEOAM_SHIFT_AFFINEMODE2) +#define SPRITEOAM_MASK_AFFINEMODE2 (SPRITEOAM_MAX_AFFINEMODE2 << SPRITEOAM_SHIFT_AFFINEMODE2) // ~ 0xFDFF #define SPRITEOAM_MAX_OBJMODE 3 #define SPRITEOAM_SHIFT_OBJMODE 10 -#define SPRITEOAM_MASK_OBJMODE (SPRITEOAM_MAX_OBJMODE << SPRITEOAM_SHIFT_OBJMODE) +#define SPRITEOAM_MASK_OBJMODE (SPRITEOAM_MAX_OBJMODE << SPRITEOAM_SHIFT_OBJMODE) // ~ 0xF3FF #define SPRITEOAM_MAX_MOSAIC 1 #define SPRITEOAM_SHIFT_MOSAIC 12 -#define SPRITEOAM_MASK_MOSAIC (SPRITEOAM_MAX_MOSAIC << SPRITEOAM_SHIFT_MOSAIC) +#define SPRITEOAM_MASK_MOSAIC (SPRITEOAM_MAX_MOSAIC << SPRITEOAM_SHIFT_MOSAIC) // ~ 0xEFFF #define SPRITEOAM_MAX_BPP 1 #define SPRITEOAM_SHIFT_BPP 13 -#define SPRITEOAM_MASK_BPP (SPRITEOAM_MAX_BPP << SPRITEOAM_SHIFT_BPP) +#define SPRITEOAM_MASK_BPP (SPRITEOAM_MAX_BPP << SPRITEOAM_SHIFT_BPP) // ~ 0xDFFF #define SPRITEOAM_MAX_SHAPE 3 #define SPRITEOAM_SHIFT_SHAPE 14 -#define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) +#define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) // ~ 0x3FFF // attrib2 #define SPRITEOAM_MAX_X 0x1FF #define SPRITEOAM_SHIFT_X 0 -#define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) +#define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) // ~ 0xFE00 #define SPRITEOAM_MAX_MATRIXNUM 31 #define SPRITEOAM_SHIFT_MATRIXNUM 9 -#define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) +#define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) // ~ 0xC1FF #define SPRITEOAM_MAX_SIZE 3 #define SPRITEOAM_SHIFT_SIZE 14 -#define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) +#define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) // ~ 0x3FFF // attrib3 #define SPRITEOAM_MAX_TILENUM 0x3FF #define SPRITEOAM_SHIFT_TILENUM 0 -#define SPRITEOAM_MASK_TILENUM (SPRITEOAM_MAX_TILENUM << SPRITEOAM_SHIFT_TILENUM) +#define SPRITEOAM_MASK_TILENUM (SPRITEOAM_MAX_TILENUM << SPRITEOAM_SHIFT_TILENUM) // ~ 0xFC00 #define SPRITEOAM_MAX_PRIORITY 3 #define SPRITEOAM_SHIFT_PRIORITY 10 -#define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) +#define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) // ~ 0xF3FF #define SPRITEOAM_MAX_PALETTENUM 15 #define SPRITEOAM_SHIFT_PALETTENUM 12 -#define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) +#define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) // ~ 0xFFF // unk6 #define SPRITEOAM_MAX_UNK6_0 1 #define SPRITEOAM_SHIFT_UNK6_0 0 -#define SPRITEOAM_MASK_UNK6_0 (SPRITEOAM_MAX_UNK6_0 << SPRITEOAM_SHIFT_UNK6_0) +#define SPRITEOAM_MASK_UNK6_0 (SPRITEOAM_MAX_UNK6_0 << SPRITEOAM_SHIFT_UNK6_0) // ~ 0xFFFE #define SPRITEOAM_MAX_UNK6_1 1 #define SPRITEOAM_SHIFT_UNK6_1 1 -#define SPRITEOAM_MASK_UNK6_1 (SPRITEOAM_MAX_UNK6_1 << SPRITEOAM_SHIFT_UNK6_1) +#define SPRITEOAM_MASK_UNK6_1 (SPRITEOAM_MAX_UNK6_1 << SPRITEOAM_SHIFT_UNK6_1) // ~ 0xFFFD #define SPRITEOAM_MAX_UNK6_4 0xFFF #define SPRITEOAM_SHIFT_UNK6_4 4 -#define SPRITEOAM_MASK_UNK6_4 (SPRITEOAM_MAX_UNK6_4 << SPRITEOAM_SHIFT_UNK6_4) +#define SPRITEOAM_MASK_UNK6_4 (SPRITEOAM_MAX_UNK6_4 << SPRITEOAM_SHIFT_UNK6_4) // ~ 0xF -#endif // GUARD_SPRITE_OAM_H \ No newline at end of file +#endif // GUARD_SPRITE_OAM_H diff --git a/include/structs/dungeon_entity.h b/include/structs/dungeon_entity.h index f7c59105d..beddfc0bd 100644 --- a/include/structs/dungeon_entity.h +++ b/include/structs/dungeon_entity.h @@ -260,7 +260,7 @@ typedef struct EntityInfo /* 0xF8 */ bool8 speedStageChanged; // Toggled when pokemon is movement speed is sped up /* 0xF9 */ u8 unkF9; /* 0xFA */ u8 terrifiedTurns; // Doubles as a bool for whether the Pokémon is terrified. - u8 unkFB; + u8 expMultiplier; // Set to true if the player makes a teammate use their held item. // This is done by going to the teammate's held item in the toolbox and selecting "Use". /* 0xFC */ bool8 useHeldItem; @@ -418,6 +418,31 @@ enum VisualFlag VISUAL_FLAG_RUN_AWAY = 2 }; +enum ExpMultiplier +{ + EXP_HALVED, // 0.5x when fainting a mon with only the regular attack and no moves + EXP_REGULAR, // 1x + EXP_BOOSTED, // 1.5x so far use not found, but most likely linked moves ; to be confirmed once more code is decompiled +}; + +static inline bool8 ExpMultiplierChanged(EntityInfo *info) +{ + return (info->expMultiplier != EXP_HALVED); +} + +static inline void SetRegularExpMultiplier(EntityInfo *info) +{ + info->expMultiplier = EXP_REGULAR; +} + +// After using a move, pokemon will get more experience than +// This inline is needed to match one function - sub_805AD54 +static inline void SetExpMultplier(EntityInfo *info) +{ + if (!ExpMultiplierChanged(info)) + SetRegularExpMultiplier(info); +} + static inline EntityInfo *GetEntInfo(Entity *ent) { return ent->info; diff --git a/src/code_803D110.c b/src/code_803D110.c index d3c040dcf..e52a6268c 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -491,12 +491,6 @@ void sub_803D8F0(void) } } -// Hmm... -static inline s16 SpeciesId(s32 id) -{ - return id; -} - bool8 sub_803D930(s16 speciesToFind) { s32 i; diff --git a/src/code_803E724.c b/src/code_803E724.c index 6d4893018..59d70b432 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -1399,9 +1399,7 @@ void sub_803FE30(s32 a0, u16 *a1, bool8 a2, bool8 a3) s32 arrId = (!a2) ? 1 : 0; for (i = 0; i < 9; i++) { - #ifndef NONMATCHING - a1++;a1--; // Good old matching trick. - #endif // NONMATCHING + ASM_MATCH_TRICK(a1); if (gUnknown_80F64B4[i] <= a0) { *a1 = gUnknown_80F64D8[arrId][i]; *ptr = (((a0 - gUnknown_80F64B4[i]) + varAdd) + 0x258) | 0xF000; diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index a0cddcbed..3a97f0266 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -10,6 +10,8 @@ #include "dungeon_random.h" #include "dungeon_util.h" #include "pokemon.h" +#include "moves.h" +#include "items.h" #include "dungeon_music.h" #include "dungeon_ai_movement.h" #include "code_8045A00.h" @@ -93,7 +95,7 @@ void sub_8044C10(u8 a0); u16 GetLeaderActionId(void); void sub_80978C8(s16 a0); void sub_8044C50(u16 a0); -void sub_805E2C4(Entity *leader); +static void TryCreateModeArrows(Entity *leader); bool8 sub_8094C48(void); void sub_8052210(u8 a0); bool8 sub_805EC4C(Entity *a0, u8 a1); @@ -125,14 +127,8 @@ extern bool8 sub_8071A8C(Entity *pokemon); extern void sub_80643AC(Entity *pokemon); extern u8 sub_8062F90(Entity *, u32, u32, u32, u32); -extern Entity *gLeaderPointer; - -extern u8 gUnknown_202F22D; -extern u8 gUnknown_202F22C; -extern u8 gUnknown_202F230; -extern u8 gUnknown_202F231; extern u8 gUnknown_202EE00; -extern u16 gUnknown_202F22E; +extern Entity *gLeaderPointer; extern const u8 *gUnknown_80F8A84; extern const u8 *gUnknown_80F8A6C; @@ -155,28 +151,21 @@ extern const u8 *gFieldItemMenuGroundTextPtr; extern const u8 *gUnknown_80FE940; extern const u8 *gWhichTextPtr1; -#ifdef NONMATCHING -void sub_805D8C8(void) // https://decomp.me/scratch/96Sci +static EWRAM_DATA bool8 sInDiagonalMode = 0; +static EWRAM_DATA bool8 sInRotateMode = 0; +// Frames counter for arrows in diagonal/rotate mode. +static EWRAM_DATA s16 sArrowsFrames = 0; +// If both of these are set to TRUE, there are 3 arrows visible instead of 1 in rotate mode +static EWRAM_DATA bool8 sShowThreeArrows1 = 0; +static EWRAM_DATA bool8 sShowThreeArrows2 = 0; + +void DungeonHandlePlayerInput(void) { struct UnkMenuBitsStruct r6; - s32 i; //r4 - s32 j; // r3 - u32 r7; - s32 r9; - s32 r5; - Entity *leader; // r10 - EntityInfo *leaderInfo; // r8 - u32 buttonsR1, buttonsR2; // r1 r2 - const u8 *msg; // r3 - bool32 r3; - s32 r4; - s32 prevMapOption; // r4 - - // Stack - u8 sp0[5]; + bool8 triggers[5]; // Always FALSE, if one of these is TRUE - they can open various menus or cause an item throw. Most likely used for debugging/testing. s32 frames; s32 var_38; - unkDungeonGlobal_unk181E8_sub *unkPtr; + UnkDungeonGlobal_unk181E8_sub *unkPtr; unkPtr = &gDungeon->unk181e8; var_38 = 3; @@ -205,9 +194,8 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci sub_806A914(1, 1, 1); while (1) { - - leader = GetLeader(); - leaderInfo = leader->info; + Entity *leader = GetLeader(); + EntityInfo *leaderInfo = GetEntInfo(leader); sub_80978C8(leaderInfo->id); if (gDungeon->unk66C != 0) { @@ -218,25 +206,31 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci } sub_805E804(); } - gUnknown_202F22D = 0; - gUnknown_202F22C = 0; + sInRotateMode = FALSE; + sInDiagonalMode = FALSE; if (gDungeon->unk5C0 >= 0) { r6.a0_8 = 1; + r6.a0_16 = 0; + r6.a0_24 = 0; } else { r6.a0_8 = 0; + r6.a0_16 = 0; + r6.a0_24 = 0; } - r6.a0_16 = 0; - r6.a0_24 = 0; frames = 0; sub_8044C50(0); - gUnknown_202F230 = 0; - gUnknown_202F231 = 0; - while (r6.a0_8 == 0) { - bool32 alwaysFalse = FALSE; + sShowThreeArrows1 = FALSE; + sShowThreeArrows2 = FALSE; - gUnknown_202F22E++; + while (r6.a0_8 == 0) { + u32 dpadDiagonal, dpadSimple; + bool32 highlightTiles, tryItemThrow; + bool32 bPress, rPress, unkBool; // Always FALSE, might've been used as debug variables. + s32 directionNew; + + sArrowsFrames++; if (unkPtr->unk1821A != 0) { frames = 0; } @@ -248,12 +242,12 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci sub_8075680(0); } - sub_805E2C4(leader); - r7 = 0; + TryCreateModeArrows(leader); + unkBool = FALSE; { s32 i; for (i = 0; i < 5; i++) { - sp0[i] = 0; + triggers[i] = FALSE; } } @@ -263,7 +257,9 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci break; } - r9 = 0; + bPress = FALSE; + rPress = FALSE; + if (gRealInputs.pressed & A_BUTTON) { if (gRealInputs.held & B_BUTTON) { if (FixedPointToInt(leaderInfo->belly) != 0) { @@ -278,58 +274,55 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci gDungeon->unk673 = 1; break; } - else { - if (gRealInputs.held & L_BUTTON) { - register bool32 r7; + else if (gRealInputs.held & L_BUTTON) { + bool32 canUseMove; + s32 i, j; - for (i = 0; i < MAX_MON_MOVES; i++) { - if (!(leaderInfo->moves[i].moveFlags & 1)) - continue; - if (leaderInfo->moves[i].moveFlags & 8) - break; - } - if (i == MAX_MON_MOVES) { - SendMessage(leader, gUnknown_80F8A28); + for (i = 0; i < MAX_MON_MOVES; i++) { + if (MoveFlagExists(&leaderInfo->moves.moves[i]) && MoveFlagSet(&leaderInfo->moves.moves[i])) { break; } - - for (j = 0; j < MAX_MON_MOVES; j++) { - - if (!(leaderInfo->moves[j].moveFlags & 1)) - continue; - if (leaderInfo->moves[j].PP != 0) - break; - } - if (j == MAX_MON_MOVES) { - SetMonsterActionFields(&leaderInfo->action, 0x17); - break; - } - - r7 = 0; - for (j = i; j < MAX_MON_MOVES; j++) { - if (j != i && !(leaderInfo->moves[j].moveFlags & 2)) - break; - if (leaderInfo->moves[j].PP != 0) { - r7 = 1; - break; - } - } - if (r7 == 0) { - SendMessage(leader, gUnknown_80F8A4C); - } - else { - SetMonsterActionFields(&leaderInfo->action, 0x14); - leaderInfo->action.unk4[0].actionUseIndex = GetTeamMemberEntityIndex(leader); - leaderInfo->action.unk4[1].actionUseIndex = i; - } + } + if (i == MAX_MON_MOVES) { + SendMessage(leader, gUnknown_80F8A28); break; } - else { - if (!sub_805EF60(leader, leaderInfo)) { - SetMonsterActionFields(&leaderInfo->action, 0x32); + + for (j = 0; j < MAX_MON_MOVES; j++) { + if (MoveFlagExists(&leaderInfo->moves.moves[j])) { + if (leaderInfo->moves.moves[j].PP != 0) + break; } + } + if (j == MAX_MON_MOVES) { + SetMonsterActionFields(&leaderInfo->action, ACTION_STRUGGLE); break; } + + canUseMove = FALSE; + for (j = i; j < MAX_MON_MOVES; j++) { + if (j != i && !(leaderInfo->moves.moves[j].moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) { + break; + } + if (leaderInfo->moves.moves[j].PP != 0) { + canUseMove = TRUE; + break; + } + } + if (!canUseMove) { + SendMessage(leader, gUnknown_80F8A4C); + } + else { + SetMonsterActionFields(&leaderInfo->action, ACTION_USE_MOVE_PLAYER); + leaderInfo->action.unk4[0].actionUseIndex = GetTeamMemberEntityIndex(leader); + leaderInfo->action.unk4[1].actionUseIndex = i; + } + break; + } + else { + if (!sub_805EF60(leader, leaderInfo)) { + SetMonsterActionFields(&leaderInfo->action, ACTION_REGULAR_ATTACK); + } break; } } @@ -340,53 +333,50 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci r6.a0_24 = 0; break; } - else if (sp0[1] != 0) { // Opens moves menu + else if (triggers[1]) { // Opens moves menu gDungeon->unk5C0 = 0; r6.a0_8 = 1; r6.a0_16 = 0; r6.a0_24 = 1; break; } - else if (sp0[2] != 0) { // Opens item menu + else if (triggers[2]) { // Opens item menu gDungeon->unk5C0 = 1; r6.a0_8 = 1; r6.a0_16 = 0; r6.a0_24 = 1; break; } - else if (sp0[3] != 0) { // Opens pokemon menu + else if (triggers[3]) { // Opens pokemon menu gDungeon->unk5C0 = 2; r6.a0_8 = 1; r6.a0_16 = 0; r6.a0_24 = 1; break; } - else if (sp0[4] != 0) { // Opens regular menu - + else if (triggers[4]) { // Opens regular menu r6.a0_8 = 1; r6.a0_16 = 0; r6.a0_24 = 1; break; } else if (frames > 0x707) { // Opens simple menu when idling - r6.a0_8 = 1; r6.a0_16 = 1; r6.a0_24 = 0; break; } - r4 = gGameOptionsRef->unk9; - if (r4 == 0) { - - // 0 != 0 comparision here... - if ((gRealInputs.pressed & B_BUTTON || (r7 == 0 && alwaysFalse != FALSE)) && unkPtr->unk1821A != 0) { - sub_804AA60(); - gUnknown_202F22D = r4; - ResetRepeatTimers(); - ResetUnusedInputStruct(); - } + if (gGameOptionsRef->unk9 == 0 + && (gRealInputs.pressed & B_BUTTON || (!unkBool && bPress)) + && unkPtr->unk1821A != 0) + { + sub_804AA60(); + sInRotateMode = FALSE; + ResetRepeatTimers(); + ResetUnusedInputStruct(); } + if (gRealInputs.held & L_BUTTON) { if (gRealInputs.pressed & B_BUTTON) { sub_80532B4(); @@ -394,44 +384,44 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci ResetUnusedInputStruct(); } } - r4 = 0; + + tryItemThrow = FALSE; if (gRealInputs.held & R_BUTTON) { - if (gUnknown_202F22C == 0) { - gUnknown_202F22E = 0; + if (!sInDiagonalMode) { + sArrowsFrames = 0; } - gUnknown_202F22C = 1; + sInDiagonalMode = TRUE; } else { - gUnknown_202F22C = 0; + sInDiagonalMode = FALSE; } - r3 = FALSE; + highlightTiles = FALSE; if (gGameOptionsRef->unk9 == 0) { - if (gRealInputs.shortPress & R_BUTTON || r9 != 0 || gRealInputs.pressed & START_BUTTON) { - r3 = TRUE; + if (gRealInputs.shortPress & R_BUTTON || rPress || gRealInputs.pressed & START_BUTTON) { + highlightTiles = TRUE; } } - if (r3) { + if (highlightTiles) { sub_805E738(leader); - gUnknown_202F22D = 1; + sInRotateMode = TRUE; unkPtr->unk1821B = leaderInfo->action.direction; unkPtr->unk1821C = 0xFF; ResetRepeatTimers(); } if ((gRealInputs.held & L_BUTTON) == L_BUTTON && (gRealInputs.pressed & R_BUTTON) == R_BUTTON) { - r4 = 1; + tryItemThrow = TRUE; } - if (sp0[0] != 0) { - r4 = 1; + if (triggers[0]) { + tryItemThrow = TRUE; } - if (r4) { + if (tryItemThrow) { + s32 i; for (i = 0; i < INVENTORY_SIZE; i++) { - if (!(gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_EXISTS)) - continue; - if (gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_SET) { + if (ItemExists(&gTeamInventoryRef->teamItems[i]) && ItemSet(&gTeamInventoryRef->teamItems[i])) { sub_8044C50(11); - leaderInfo->action.unk4[0].actionUseIndex = i + 1; + leaderInfo->action.unk4[0].actionUseIndex = i +1; leaderInfo->action.unk4[0].lastItemThrowPosition.x = 0; leaderInfo->action.unk4[0].lastItemThrowPosition.y = 0; break; @@ -444,7 +434,7 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci // SELECT button if (!gDungeon->unk181e8.blinded && gGameOptionsRef->mapOption != 6 && gRealInputs.pressed & SELECT_BUTTON) { - prevMapOption = gGameOptionsRef->mapOption; + s32 prevMapOption = gGameOptionsRef->mapOption; gUnknown_202EE00 = 1; gDungeon->unk181e8.unk18214 = 1; if (!sub_8094C48()) { @@ -462,7 +452,7 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci break; if (gRealInputs.pressed & A_BUTTON) { - gUnknown_202EE00 = (gUnknown_202EE00 == 0) ? 1 : 0; + gUnknown_202EE00 = (gUnknown_202EE00 == 0) ? 1 : 0; // Flip sub_8040A84(); } } @@ -475,104 +465,100 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci sub_803E46C(0x2F); } - if (gDungeon->unk66D != 0 && gUnknown_202F22C == 0) { - buttonsR1 = buttonsR2 = gRealInputs.pressed; + if (gDungeon->unk66D != 0 && !sInDiagonalMode) { + dpadDiagonal = dpadSimple = gRealInputs.pressed; } else { - buttonsR1 = gRealInputs.held; - buttonsR2 = (unkPtr->unk1821A == 0) ? gRealInputs.held : gRealInputs.pressed; + dpadDiagonal = gRealInputs.held; + dpadSimple = (unkPtr->unk1821A == 0) ? gRealInputs.held : gRealInputs.pressed; } - buttonsR1 &= DPAD_ANY; - buttonsR2 &= DPAD_ANY; - r5 = -1; - if (buttonsR1 == (DPAD_UP | DPAD_RIGHT)) - r5 = 3; - if (buttonsR1 == (DPAD_UP | DPAD_LEFT)) - r5 = 5; - if (buttonsR1 == (DPAD_DOWN | DPAD_RIGHT)) - r5 = 1; - if (buttonsR1 == (DPAD_DOWN | DPAD_LEFT)) - r5 = 7; + dpadDiagonal &= DPAD_ANY; + dpadSimple &= DPAD_ANY; + directionNew = -1; + if (dpadDiagonal == (DPAD_UP | DPAD_RIGHT)) + directionNew = DIRECTION_NORTHEAST; + if (dpadDiagonal == (DPAD_UP | DPAD_LEFT)) + directionNew = DIRECTION_NORTHWEST; + if (dpadDiagonal == (DPAD_DOWN | DPAD_RIGHT)) + directionNew = DIRECTION_SOUTHEAST; + if (dpadDiagonal == (DPAD_DOWN | DPAD_LEFT)) + directionNew = DIRECTION_SOUTHWEST; - if (buttonsR2 == DPAD_UP) - r5 = 4; - if (buttonsR2 == DPAD_DOWN) - r5 = 0; - if (buttonsR2 == DPAD_RIGHT) - r5 = 2; - if (buttonsR2 == DPAD_LEFT) - r5 = 6; + if (dpadSimple == DPAD_UP) + directionNew = DIRECTION_NORTH; + if (dpadSimple == DPAD_DOWN) + directionNew = DIRECTION_SOUTH; + if (dpadSimple == DPAD_RIGHT) + directionNew = DIRECTION_EAST; + if (dpadSimple == DPAD_LEFT) + directionNew = DIRECTION_WEST; - if (r5 >= 0 && (gUnknown_202F22C == 0 || (r5 & 1))) { - bool32 aaa = 0; - bool32 register r7 = (leaderInfo->action.direction != r5); - leaderInfo->action.direction = r5 & 7; - if (gUnknown_202F22D != 0) { - unkPtr->unk1821B = r5; - sub_806CDD4(leader, sub_806CEBC(leader), r5); + if (directionNew >= 0 && (!sInDiagonalMode || (directionNew & 1))) { + bool32 directionChanged = (leaderInfo->action.direction != directionNew); + leaderInfo->action.direction = directionNew & DIRECTION_MASK; + if (sInRotateMode) { + unkPtr->unk1821B = directionNew; + sub_806CDD4(leader, sub_806CEBC(leader), directionNew); } else { + u8 canMoveFlags = 0; + const u8 *immobilizedMsg = NULL; - r4 = 0; - - msg = NULL; if (sub_805EC4C(leader, 1)) break; - if (leaderInfo->immobilize.immobilizeStatus == 2) { - msg = gUnknown_80F8A84, r4 = 1; + if (leaderInfo->immobilize.immobilizeStatus == STATUS_SHADOW_HOLD) { + immobilizedMsg = gUnknown_80F8A84, canMoveFlags |= 1; } - else if (leaderInfo->immobilize.immobilizeStatus == 7) { - msg = gUnknown_80F8A6C, r4 = 1; + else if (leaderInfo->immobilize.immobilizeStatus == STATUS_CONSTRICTION) { + immobilizedMsg = gUnknown_80F8A6C, canMoveFlags |= 1; } - else if (leaderInfo->immobilize.immobilizeStatus == 5) { - msg = gUnknown_80F8AB0, r4 = 1; + else if (leaderInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) { + immobilizedMsg = gUnknown_80F8AB0, canMoveFlags |= 1; } - else if (leaderInfo->immobilize.immobilizeStatus == 3) { - msg = gUnknown_80F8ADC, r4 = 1; + else if (leaderInfo->immobilize.immobilizeStatus == STATUS_WRAP) { + immobilizedMsg = gUnknown_80F8ADC, canMoveFlags |= 1; } - else if (leaderInfo->immobilize.immobilizeStatus == 4) { - msg = gUnknown_80F8B0C, r4 = 1; + else if (leaderInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) { + immobilizedMsg = gUnknown_80F8B0C, canMoveFlags |= 1; } - if (!CanMoveInDirection(leader, r5)) - r4 |= 2; - if (r7) { - sub_806CDD4(leader, sub_806CEBC(leader), r5); - } - // Note to self: r7 is set to 2, but I guess it's because the variable is not used anymore? - //r7 = 2; - if (!(r4 & 2)) { + if (!CanMoveInDirection(leader, directionNew)) + canMoveFlags |= 2; - //r9 = 1; - if (r4 & 1) { - if (msg != NULL) { - SendMessage(leader, msg); + if (directionChanged) { + sub_806CDD4(leader, sub_806CEBC(leader), directionNew); + } + + if (!(canMoveFlags & 2)) { + if (canMoveFlags & 1) { + if (immobilizedMsg != NULL) { + SendMessage(leader, immobilizedMsg); } sub_8044C50(1); - gDungeon->unk673 = 1; // or r9? - break; + gDungeon->unk673 = 1; } - sub_8044C50(2); - - // mov r0, cmp r0, #0 wtf - if ((gRealInputs.held & B_BUTTON || aaa != 0) && FixedPointToInt(leaderInfo->belly) != 0) { - if (leader->info->volatileStatus.volatileStatus != 2) { - gDungeon->unk66C = 1; // or r9? + else { + sub_8044C50(2); + if ((gRealInputs.held & B_BUTTON || bPress) && FixedPointToInt(leaderInfo->belly) != 0) { + if (GetEntInfo(leader)->volatileStatus.volatileStatus != STATUS_CONFUSED) { + gDungeon->unk66C = 1; + } + leaderInfo->action.unk4[0].actionUseIndex = 0; + } + else { + leaderInfo->action.unk4[0].actionUseIndex = 1; } - leaderInfo->action.unk4[0].actionUseIndex = 0; - break; } - leaderInfo->action.unk4[0].actionUseIndex = 1; break; } - - if (r4 & 1) + else if (canMoveFlags & 1) { sub_803E724(0x23); + } + } } - sub_803E46C(0xF); } @@ -597,14 +583,12 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci sub_803E46C(0xF); } else { - u8 r2; sub_803E46C(0xF); sub_8047158(); - r2 = (r6.a0_16 == 0) ? 1 : 0; - ShowFieldMenu(r2, r6.a0_24); + ShowFieldMenu((r6.a0_16 == 0) ? 1 : 0, r6.a0_24); ResetRepeatTimers(); ResetUnusedInputStruct(); - gUnknown_202F22D = 0; + sInRotateMode = FALSE; unkPtr->unk1821A = 0; sub_804AA60(); if (sub_8044B28()) @@ -627,1267 +611,195 @@ void sub_805D8C8(void) // https://decomp.me/scratch/96Sci } } -#else -NAKED void sub_805D8C8(void) +struct UnkStruct_8106AC8 { - 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, 0x24\n" -"ldr r4, _0805D90C\n" -"ldr r1, [r4]\n" -"ldr r0, _0805D910\n" -"adds r0, r1, r0\n" -"str r0, [sp, 0x10]\n" -"movs r2, 0x3\n" -"str r2, [sp, 0xC]\n" -"movs r5, 0\n" -"movs r0, 0\n" -"strh r0, [r1, 0x12]\n" -"bl GetLeader\n" -"movs r1, 0x1\n" -"bl sub_806A2BC\n" -"bl GetLeader\n" -"bl sub_80701A4\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"beq _0805D928\n" -"movs r0, 0x3C\n" -"movs r1, 0x10\n" -"bl sub_803E708\n" -"bl _0805E2B0\n" -".align 2, 0\n" -"_0805D90C: .4byte gDungeon\n" -"_0805D910: .4byte 0x000181e8\n" -"_0805D914:\n" -"mov r1, r8\n" -"adds r1, 0x44\n" -"movs r2, 0\n" -"movs r0, 0x2\n" -"strh r0, [r1]\n" -"mov r0, r8\n" -"adds r0, 0x48\n" -"strb r2, [r0]\n" -"bl _0805E2B0\n" -"_0805D928:\n" -"ldr r0, [r4]\n" -"ldr r3, _0805D9D4\n" -"adds r0, r3\n" -"strb r5, [r0]\n" -"bl sub_8040A78\n" -"ldr r1, [r4]\n" -"ldrb r0, [r1, 0x1]\n" -"cmp r0, 0\n" -"beq _0805D976\n" -"strb r5, [r1, 0x1]\n" -"bl GetLeader\n" -"movs r1, 0x1\n" -"bl ShouldMonsterRunAwayAndShowEffect\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805D976\n" -"movs r0, 0x1\n" -"bl sub_8044C10\n" -"bl sub_805E804\n" -"bl GetLeader\n" -"bl sub_80647F0\n" -"bl ResetRepeatTimers\n" -"bl ResetUnusedInputStruct\n" -"bl GetLeaderActionId\n" -"lsls r0, 16\n" -"cmp r0, 0\n" -"beq _0805D976\n" -"bl _0805E2B0\n" -"_0805D976:\n" -"movs r0, 0x1\n" -"movs r1, 0x1\n" -"movs r2, 0x1\n" -"bl sub_806A914\n" -"_0805D980:\n" -"bl GetLeader\n" -"mov r10, r0\n" -"ldr r5, [r0, 0x70]\n" -"mov r8, r5\n" -"movs r1, 0x2\n" -"ldrsh r0, [r5, r1]\n" -"bl sub_80978C8\n" -"ldr r2, _0805D9D8\n" -"ldr r0, [r2]\n" -"ldr r3, _0805D9DC\n" -"adds r0, r3\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"beq _0805D9AE\n" -"bl sub_805E874\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805D914\n" -"bl sub_805E804\n" -"_0805D9AE:\n" -"ldr r0, _0805D9E0\n" -"movs r1, 0\n" -"strb r1, [r0]\n" -"ldr r0, _0805D9E4\n" -"strb r1, [r0]\n" -"ldr r5, _0805D9D8\n" -"ldr r0, [r5]\n" -"movs r1, 0xB8\n" -"lsls r1, 3\n" -"adds r0, r1\n" -"ldr r0, [r0]\n" -"cmp r0, 0\n" -"bge _0805D9CA\n" -"b _0805DAE8\n" -"_0805D9CA:\n" -"ldr r0, _0805D9E8\n" -"ands r6, r0\n" -"movs r2, 0x1\n" -"orrs r6, r2\n" -"b _0805DAEC\n" -".align 2, 0\n" -"_0805D9D4: .4byte 0x00000673\n" -"_0805D9D8: .4byte gDungeon\n" -"_0805D9DC: .4byte 0x0000066c\n" -"_0805D9E0: .4byte gUnknown_202F22D\n" -"_0805D9E4: .4byte gUnknown_202F22C\n" -"_0805D9E8: .4byte 0xffffff00\n" -"_0805D9EC:\n" -"movs r0, 0x1\n" -"bl sub_8044C50\n" -"ldr r3, _0805DA00\n" -"ldr r0, [r3]\n" -"ldr r5, _0805DA04\n" -"adds r0, r5\n" -"strb r4, [r0]\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805DA00: .4byte gDungeon\n" -"_0805DA04: .4byte 0x00000673\n" -"_0805DA08:\n" -"ldr r0, _0805DA14\n" -"ldr r1, [r0]\n" -"mov r0, r10\n" -"bl SendMessage\n" -"b _0805DBDA\n" -".align 2, 0\n" -"_0805DA14: .4byte gUnknown_80FD4B0\n" -"_0805DA18:\n" -"ldr r0, _0805DA1C\n" -"b _0805DCBC\n" -".align 2, 0\n" -"_0805DA1C: .4byte gUnknown_80F8A28\n" -"_0805DA20:\n" -"ldr r0, [sp, 0x1C]\n" -"movs r1, 0x17\n" -"bl SetMonsterActionFields\n" -"b _0805E1AE\n" -"_0805DA2A:\n" -"ldr r0, _0805DA38\n" -"ands r6, r0\n" -"movs r3, 0x1\n" -"orrs r6, r3\n" -"ldr r0, _0805DA3C\n" -"ands r6, r0\n" -"b _0805DAD6\n" -".align 2, 0\n" -"_0805DA38: .4byte 0xffffff00\n" -"_0805DA3C: .4byte 0xffff00ff\n" -"_0805DA40:\n" -"ldr r5, _0805DA58\n" -"ldr r0, [r5]\n" -"movs r2, 0xB8\n" -"lsls r2, 3\n" -"adds r0, r2\n" -"str r1, [r0]\n" -"ldr r0, _0805DA5C\n" -"ands r6, r0\n" -"movs r3, 0x1\n" -"orrs r6, r3\n" -"b _0805DAA8\n" -".align 2, 0\n" -"_0805DA58: .4byte gDungeon\n" -"_0805DA5C: .4byte 0xffffff00\n" -"_0805DA60:\n" -"ldr r5, _0805DA78\n" -"ldr r0, [r5]\n" -"movs r1, 0xB8\n" -"lsls r1, 3\n" -"adds r0, r1\n" -"movs r2, 0x1\n" -"str r2, [r0]\n" -"ldr r0, _0805DA7C\n" -"ands r6, r0\n" -"orrs r6, r2\n" -"b _0805DAA8\n" -".align 2, 0\n" -"_0805DA78: .4byte gDungeon\n" -"_0805DA7C: .4byte 0xffffff00\n" -"_0805DA80:\n" -"ldr r3, _0805DA98\n" -"ldr r0, [r3]\n" -"movs r5, 0xB8\n" -"lsls r5, 3\n" -"adds r0, r5\n" -"str r2, [r0]\n" -"ldr r0, _0805DA9C\n" -"ands r6, r0\n" -"movs r0, 0x1\n" -"orrs r6, r0\n" -"b _0805DAA8\n" -".align 2, 0\n" -"_0805DA98: .4byte gDungeon\n" -"_0805DA9C: .4byte 0xffffff00\n" -"_0805DAA0:\n" -"ldr r0, _0805DAB8\n" -"ands r6, r0\n" -"movs r1, 0x1\n" -"orrs r6, r1\n" -"_0805DAA8:\n" -"ldr r0, _0805DABC\n" -"ands r6, r0\n" -"ldr r0, _0805DAC0\n" -"ands r6, r0\n" -"movs r0, 0x80\n" -"lsls r0, 9\n" -"orrs r6, r0\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805DAB8: .4byte 0xffffff00\n" -"_0805DABC: .4byte 0xffff00ff\n" -"_0805DAC0: .4byte 0xff00ffff\n" -"_0805DAC4:\n" -"ldr r0, _0805DADC\n" -"ands r6, r0\n" -"movs r2, 0x1\n" -"orrs r6, r2\n" -"ldr r0, _0805DAE0\n" -"ands r6, r0\n" -"movs r0, 0x80\n" -"lsls r0, 1\n" -"orrs r6, r0\n" -"_0805DAD6:\n" -"ldr r0, _0805DAE4\n" -"ands r6, r0\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805DADC: .4byte 0xffffff00\n" -"_0805DAE0: .4byte 0xffff00ff\n" -"_0805DAE4: .4byte 0xff00ffff\n" -"_0805DAE8:\n" -"ldr r0, _0805DB3C\n" -"ands r6, r0\n" -"_0805DAEC:\n" -"ldr r0, _0805DB40\n" -"ands r6, r0\n" -"ldr r0, _0805DB44\n" -"ands r6, r0\n" -"movs r3, 0\n" -"str r3, [sp, 0x8]\n" -"movs r0, 0\n" -"bl sub_8044C50\n" -"ldr r0, _0805DB48\n" -"mov r5, sp\n" -"ldrb r5, [r5, 0x8]\n" -"strb r5, [r0]\n" -"ldr r0, _0805DB4C\n" -"mov r1, sp\n" -"ldrb r1, [r1, 0x8]\n" -"strb r1, [r0]\n" -"lsls r0, r6, 24\n" -"mov r2, r8\n" -"adds r2, 0x44\n" -"str r2, [sp, 0x1C]\n" -"str r0, [sp, 0x14]\n" -"ldr r3, [sp, 0x10]\n" -"adds r3, 0x32\n" -"str r3, [sp, 0x18]\n" -"cmp r0, 0\n" -"beq _0805DB24\n" -"b _0805E1AE\n" -"_0805DB24:\n" -"ldr r0, _0805DB50\n" -"ldrh r1, [r0]\n" -"adds r1, 0x1\n" -"strh r1, [r0]\n" -"ldr r5, [sp, 0x18]\n" -"ldrb r0, [r5]\n" -"cmp r0, 0\n" -"beq _0805DB54\n" -"movs r0, 0\n" -"str r0, [sp, 0x8]\n" -"b _0805DB5A\n" -".align 2, 0\n" -"_0805DB3C: .4byte 0xffffff00\n" -"_0805DB40: .4byte 0xffff00ff\n" -"_0805DB44: .4byte 0xff00ffff\n" -"_0805DB48: .4byte gUnknown_202F230\n" -"_0805DB4C: .4byte gUnknown_202F231\n" -"_0805DB50: .4byte gUnknown_202F22E\n" -"_0805DB54:\n" -"ldr r1, [sp, 0x8]\n" -"adds r1, 0x1\n" -"str r1, [sp, 0x8]\n" -"_0805DB5A:\n" -"ldr r2, [sp, 0xC]\n" -"cmp r2, 0\n" -"beq _0805DB6E\n" -"subs r2, 0x1\n" -"str r2, [sp, 0xC]\n" -"cmp r2, 0\n" -"bne _0805DB6E\n" -"movs r0, 0\n" -"bl sub_8075680\n" -"_0805DB6E:\n" -"mov r0, r10\n" -"bl sub_805E2C4\n" -"movs r7, 0\n" -"movs r1, 0\n" -"add r0, sp, 0x4\n" -"_0805DB7A:\n" -"strb r1, [r0]\n" -"subs r0, 0x1\n" -"cmp r0, sp\n" -"bge _0805DB7A\n" -"ldr r0, _0805DBEC\n" -"ldrh r1, [r0]\n" -"movs r4, 0x1\n" -"movs r0, 0x1\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DBAA\n" -"movs r0, 0x2\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DBAA\n" -"movs r0, 0x9E\n" -"lsls r0, 1\n" -"add r0, r8\n" -"ldr r0, [r0]\n" -"bl FixedPointToInt\n" -"cmp r0, 0\n" -"beq _0805DBAA\n" -"b _0805D9EC\n" -"_0805DBAA:\n" -"movs r3, 0\n" -"mov r9, r3\n" -"ldr r4, _0805DBEC\n" -"ldrh r1, [r4, 0x2]\n" -"movs r5, 0x1\n" -"movs r0, 0x1\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DBBE\n" -"b _0805DD02\n" -"_0805DBBE:\n" -"ldrh r1, [r4]\n" -"movs r0, 0x2\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DBF8\n" -"movs r0, 0x9E\n" -"lsls r0, 1\n" -"add r0, r8\n" -"ldr r0, [r0]\n" -"bl FixedPointToInt\n" -"cmp r0, 0\n" -"bne _0805DBDA\n" -"b _0805DD02\n" -"_0805DBDA:\n" -"movs r0, 0x1\n" -"bl sub_8044C50\n" -"ldr r1, _0805DBF0\n" -"ldr r0, [r1]\n" -"ldr r2, _0805DBF4\n" -"adds r0, r2\n" -"strb r5, [r0]\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805DBEC: .4byte gRealInputs\n" -"_0805DBF0: .4byte gDungeon\n" -"_0805DBF4: .4byte 0x00000673\n" -"_0805DBF8:\n" -"mov r0, r10\n" -"movs r1, 0x1\n" -"bl ShouldMonsterRunAwayAndShowEffect\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"beq _0805DC08\n" -"b _0805DA08\n" -"_0805DC08:\n" -"ldrh r0, [r4]\n" -"movs r3, 0x80\n" -"lsls r3, 2\n" -"adds r1, r3, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DCE8\n" -"movs r4, 0\n" -"movs r2, 0x8C\n" -"lsls r2, 1\n" -"add r2, r8\n" -"movs r3, 0x8\n" -"_0805DC20:\n" -"ldrb r1, [r2]\n" -"movs r0, 0x1\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DC32\n" -"adds r0, r3, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DC3A\n" -"_0805DC32:\n" -"adds r2, 0x8\n" -"adds r4, 0x1\n" -"cmp r4, 0x3\n" -"ble _0805DC20\n" -"_0805DC3A:\n" -"cmp r4, 0x4\n" -"bne _0805DC40\n" -"b _0805DA18\n" -"_0805DC40:\n" -"movs r3, 0\n" -"movs r5, 0x8C\n" -"lsls r5, 1\n" -"movs r7, 0x1\n" -"mov r2, r8\n" -"_0805DC4A:\n" -"lsls r0, r3, 3\n" -"add r0, r8\n" -"adds r0, r5\n" -"ldrb r1, [r0]\n" -"adds r0, r7, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DC66\n" -"movs r1, 0x8E\n" -"lsls r1, 1\n" -"adds r0, r2, r1\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"bne _0805DC6E\n" -"_0805DC66:\n" -"adds r2, 0x8\n" -"adds r3, 0x1\n" -"cmp r3, 0x3\n" -"ble _0805DC4A\n" -"_0805DC6E:\n" -"cmp r3, 0x4\n" -"bne _0805DC74\n" -"b _0805DA20\n" -"_0805DC74:\n" -"movs r7, 0\n" -"adds r3, r4, 0\n" -"cmp r4, 0x3\n" -"bgt _0805DCB6\n" -"lsls r0, r4, 3\n" -"adds r2, r0, 0\n" -"add r2, r8\n" -"mov r12, r2\n" -"movs r5, 0x8E\n" -"lsls r5, 1\n" -"adds r0, r5\n" -"mov r1, r8\n" -"adds r2, r0, r1\n" -"movs r5, 0x2\n" -"_0805DC90:\n" -"ldrb r0, [r2]\n" -"cmp r0, 0\n" -"bne _0805DCCC\n" -"movs r0, 0x8\n" -"add r12, r0\n" -"adds r2, 0x8\n" -"adds r3, 0x1\n" -"cmp r3, 0x3\n" -"bgt _0805DCB6\n" -"cmp r3, r4\n" -"beq _0805DC90\n" -"movs r0, 0x8C\n" -"lsls r0, 1\n" -"add r0, r12\n" -"ldrb r1, [r0]\n" -"adds r0, r5, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DC90\n" -"_0805DCB6:\n" -"cmp r7, 0\n" -"bne _0805DCCC\n" -"ldr r0, _0805DCC8\n" -"_0805DCBC:\n" -"ldr r1, [r0]\n" -"mov r0, r10\n" -"bl SendMessage\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805DCC8: .4byte gUnknown_80F8A4C\n" -"_0805DCCC:\n" -"ldr r0, [sp, 0x1C]\n" -"movs r1, 0x14\n" -"bl SetMonsterActionFields\n" -"mov r0, r10\n" -"bl GetTeamMemberEntityIndex\n" -"mov r1, r8\n" -"adds r1, 0x48\n" -"strb r0, [r1]\n" -"mov r0, r8\n" -"adds r0, 0x50\n" -"strb r4, [r0]\n" -"b _0805E1AE\n" -"_0805DCE8:\n" -"mov r0, r10\n" -"mov r1, r8\n" -"bl sub_805EF60\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"beq _0805DCF8\n" -"b _0805E1AE\n" -"_0805DCF8:\n" -"ldr r0, [sp, 0x1C]\n" -"movs r1, 0x32\n" -"bl SetMonsterActionFields\n" -"b _0805E1AE\n" -"_0805DD02:\n" -"ldr r3, _0805DDC8\n" -"ldrh r1, [r3, 0x6]\n" -"movs r2, 0x2\n" -"adds r0, r2, 0\n" -"ands r0, r1\n" -"lsls r0, 16\n" -"lsrs r1, r0, 16\n" -"cmp r1, 0\n" -"beq _0805DD16\n" -"b _0805DA2A\n" -"_0805DD16:\n" -"mov r0, sp\n" -"ldrb r0, [r0, 0x1]\n" -"cmp r0, 0\n" -"beq _0805DD20\n" -"b _0805DA40\n" -"_0805DD20:\n" -"mov r0, sp\n" -"ldrb r0, [r0, 0x2]\n" -"cmp r0, 0\n" -"beq _0805DD2A\n" -"b _0805DA60\n" -"_0805DD2A:\n" -"mov r0, sp\n" -"ldrb r0, [r0, 0x3]\n" -"cmp r0, 0\n" -"beq _0805DD34\n" -"b _0805DA80\n" -"_0805DD34:\n" -"mov r0, sp\n" -"ldrb r0, [r0, 0x4]\n" -"cmp r0, 0\n" -"beq _0805DD3E\n" -"b _0805DAA0\n" -"_0805DD3E:\n" -"ldr r0, _0805DDCC\n" -"ldr r1, [sp, 0x8]\n" -"cmp r1, r0\n" -"ble _0805DD48\n" -"b _0805DAC4\n" -"_0805DD48:\n" -"ldr r0, _0805DDD0\n" -"ldr r0, [r0]\n" -"ldrb r4, [r0, 0x9]\n" -"cmp r4, 0\n" -"bne _0805DD7E\n" -"ldrh r1, [r3, 0x2]\n" -"adds r0, r2, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DD66\n" -"cmp r7, 0\n" -"bne _0805DD7E\n" -"movs r2, 0\n" -"cmp r2, 0\n" -"beq _0805DD7E\n" -"_0805DD66:\n" -"ldr r3, [sp, 0x18]\n" -"ldrb r0, [r3]\n" -"cmp r0, 0\n" -"beq _0805DD7E\n" -"bl sub_804AA60\n" -"ldr r0, _0805DDD4\n" -"strb r4, [r0]\n" -"bl ResetRepeatTimers\n" -"bl ResetUnusedInputStruct\n" -"_0805DD7E:\n" -"ldr r2, _0805DDC8\n" -"ldrh r0, [r2]\n" -"movs r5, 0x80\n" -"lsls r5, 2\n" -"adds r1, r5, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DDA4\n" -"ldrh r1, [r2, 0x2]\n" -"movs r0, 0x2\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DDA4\n" -"bl sub_80532B4\n" -"bl ResetRepeatTimers\n" -"bl ResetUnusedInputStruct\n" -"_0805DDA4:\n" -"movs r4, 0\n" -"ldr r0, _0805DDC8\n" -"ldrh r0, [r0]\n" -"movs r2, 0x80\n" -"lsls r2, 1\n" -"adds r1, r2, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DDFA\n" -"ldr r1, _0805DDD8\n" -"ldrb r0, [r1]\n" -"cmp r0, 0\n" -"bne _0805DDC2\n" -"ldr r0, _0805DDDC\n" -"strh r4, [r0]\n" -"_0805DDC2:\n" -"movs r3, 0x1\n" -"strb r3, [r1]\n" -"b _0805DDFE\n" -".align 2, 0\n" -"_0805DDC8: .4byte gRealInputs\n" -"_0805DDCC: .4byte 0x00000707\n" -"_0805DDD0: .4byte gGameOptionsRef\n" -"_0805DDD4: .4byte gUnknown_202F22D\n" -"_0805DDD8: .4byte gUnknown_202F22C\n" -"_0805DDDC: .4byte gUnknown_202F22E\n" -"_0805DDE0:\n" -"movs r0, 0xB\n" -"bl sub_8044C50\n" -"adds r2, r4, 0x1\n" -"mov r0, r8\n" -"adds r0, 0x48\n" -"movs r1, 0\n" -"strb r2, [r0]\n" -"adds r0, 0x4\n" -"strh r1, [r0]\n" -"adds r0, 0x2\n" -"strh r1, [r0]\n" -"b _0805DE92\n" -"_0805DDFA:\n" -"ldr r0, _0805DEF8\n" -"strb r4, [r0]\n" -"_0805DDFE:\n" -"movs r3, 0\n" -"ldr r0, _0805DEFC\n" -"ldr r0, [r0]\n" -"ldrb r0, [r0, 0x9]\n" -"cmp r0, 0\n" -"bne _0805DE2C\n" -"ldr r2, _0805DF00\n" -"ldrh r0, [r2, 0x6]\n" -"movs r5, 0x80\n" -"lsls r5, 1\n" -"adds r1, r5, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DE2A\n" -"mov r0, r9\n" -"cmp r0, 0\n" -"bne _0805DE2A\n" -"ldrh r1, [r2, 0x2]\n" -"movs r0, 0x8\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DE2C\n" -"_0805DE2A:\n" -"movs r3, 0x1\n" -"_0805DE2C:\n" -"cmp r3, 0\n" -"beq _0805DE54\n" -"mov r0, r10\n" -"bl sub_805E738\n" -"ldr r0, _0805DF04\n" -"movs r1, 0x1\n" -"strb r1, [r0]\n" -"mov r0, r8\n" -"adds r0, 0x46\n" -"ldrb r0, [r0]\n" -"ldr r1, [sp, 0x10]\n" -"adds r1, 0x33\n" -"strb r0, [r1]\n" -"ldr r1, [sp, 0x10]\n" -"adds r1, 0x34\n" -"movs r0, 0xFF\n" -"strb r0, [r1]\n" -"bl ResetRepeatTimers\n" -"_0805DE54:\n" -"ldr r0, _0805DF00\n" -"ldr r1, [r0]\n" -"ldr r0, _0805DF08\n" -"ands r1, r0\n" -"cmp r1, r0\n" -"bne _0805DE62\n" -"movs r4, 0x1\n" -"_0805DE62:\n" -"mov r0, sp\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"beq _0805DE6C\n" -"movs r4, 0x1\n" -"_0805DE6C:\n" -"cmp r4, 0\n" -"beq _0805DE9C\n" -"movs r4, 0\n" -"ldr r0, _0805DF0C\n" -"ldr r2, [r0]\n" -"movs r3, 0x10\n" -"_0805DE78:\n" -"ldrb r1, [r2]\n" -"movs r0, 0x1\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DE8A\n" -"adds r0, r3, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DDE0\n" -"_0805DE8A:\n" -"adds r2, 0x4\n" -"adds r4, 0x1\n" -"cmp r4, 0x13\n" -"ble _0805DE78\n" -"_0805DE92:\n" -"ldr r2, [sp, 0x1C]\n" -"ldrh r0, [r2]\n" -"cmp r0, 0\n" -"beq _0805DE9C\n" -"b _0805E1AE\n" -"_0805DE9C:\n" -"ldr r5, _0805DF10\n" -"ldr r3, [r5]\n" -"ldr r1, _0805DF14\n" -"adds r0, r3, r1\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"bne _0805DF82\n" -"ldr r0, _0805DEFC\n" -"ldr r2, [r0]\n" -"ldrb r0, [r2, 0x4]\n" -"cmp r0, 0x6\n" -"beq _0805DF82\n" -"ldr r0, _0805DF00\n" -"ldrh r1, [r0, 0x2]\n" -"movs r0, 0x4\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DF82\n" -"ldrb r4, [r2, 0x4]\n" -"ldr r0, _0805DF18\n" -"movs r2, 0x1\n" -"strb r2, [r0]\n" -"ldr r5, _0805DF1C\n" -"adds r0, r3, r5\n" -"strb r2, [r0]\n" -"bl sub_8094C48\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805DEDC\n" -"bl sub_8094C88\n" -"_0805DEDC:\n" -"movs r0, 0x1\n" -"bl sub_8052210\n" -"bl sub_8040A84\n" -"movs r0, 0x1E\n" -"bl SetBGOBJEnableFlags\n" -"movs r0, 0xA\n" -"movs r1, 0x2F\n" -"bl sub_803E708\n" -"b _0805DF3A\n" -".align 2, 0\n" -"_0805DEF8: .4byte gUnknown_202F22C\n" -"_0805DEFC: .4byte gGameOptionsRef\n" -"_0805DF00: .4byte gRealInputs\n" -"_0805DF04: .4byte gUnknown_202F22D\n" -"_0805DF08: .4byte 0x01000200\n" -"_0805DF0C: .4byte gTeamInventoryRef\n" -"_0805DF10: .4byte gDungeon\n" -"_0805DF14: .4byte 0x0001820a\n" -"_0805DF18: .4byte gUnknown_202EE00\n" -"_0805DF1C: .4byte 0x00018214\n" -"_0805DF20:\n" -"movs r0, 0x1\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DF3A\n" -"ldr r2, _0805DFA0\n" -"movs r1, 0\n" -"ldrb r0, [r2]\n" -"cmp r0, 0\n" -"bne _0805DF34\n" -"movs r1, 0x1\n" -"_0805DF34:\n" -"strb r1, [r2]\n" -"bl sub_8040A84\n" -"_0805DF3A:\n" -"movs r0, 0x2F\n" -"bl sub_803E46C\n" -"ldr r0, _0805DFA4\n" -"ldrh r1, [r0, 0x2]\n" -"movs r0, 0x4\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805DF54\n" -"movs r0, 0x2\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"beq _0805DF20\n" -"_0805DF54:\n" -"ldr r1, _0805DFA8\n" -"ldr r0, [r1]\n" -"ldr r2, _0805DFAC\n" -"adds r0, r2\n" -"movs r1, 0\n" -"strb r1, [r0]\n" -"ldr r0, _0805DFB0\n" -"ldr r0, [r0]\n" -"strb r4, [r0, 0x4]\n" -"ldr r0, _0805DFA0\n" -"movs r3, 0x1\n" -"strb r3, [r0]\n" -"bl sub_8040A84\n" -"movs r0, 0\n" -"bl SetBGOBJEnableFlags\n" -"movs r0, 0x2F\n" -"bl sub_803E46C\n" -"movs r0, 0x2F\n" -"bl sub_803E46C\n" -"_0805DF82:\n" -"ldr r5, _0805DFA8\n" -"ldr r0, [r5]\n" -"ldr r1, _0805DFB4\n" -"adds r0, r1\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"beq _0805DFBC\n" -"ldr r0, _0805DFB8\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"bne _0805DFBC\n" -"ldr r0, _0805DFA4\n" -"ldrh r2, [r0, 0x2]\n" -"adds r1, r2, 0\n" -"b _0805DFCC\n" -".align 2, 0\n" -"_0805DFA0: .4byte gUnknown_202EE00\n" -"_0805DFA4: .4byte gRealInputs\n" -"_0805DFA8: .4byte gDungeon\n" -"_0805DFAC: .4byte 0x00018214\n" -"_0805DFB0: .4byte gGameOptionsRef\n" -"_0805DFB4: .4byte 0x0000066d\n" -"_0805DFB8: .4byte gUnknown_202F22C\n" -"_0805DFBC:\n" -"ldr r3, _0805E05C\n" -"ldrh r1, [r3]\n" -"ldr r2, [sp, 0x18]\n" -"ldrb r0, [r2]\n" -"adds r2, r1, 0\n" -"cmp r0, 0\n" -"beq _0805DFCC\n" -"ldrh r2, [r3, 0x2]\n" -"_0805DFCC:\n" -"movs r0, 0xF0\n" -"ands r1, r0\n" -"ands r2, r0\n" -"movs r5, 0x1\n" -"negs r5, r5\n" -"cmp r1, 0x50\n" -"bne _0805DFDC\n" -"movs r5, 0x3\n" -"_0805DFDC:\n" -"cmp r1, 0x60\n" -"bne _0805DFE2\n" -"movs r5, 0x5\n" -"_0805DFE2:\n" -"cmp r1, 0x90\n" -"bne _0805DFE8\n" -"movs r5, 0x1\n" -"_0805DFE8:\n" -"cmp r1, 0xA0\n" -"bne _0805DFEE\n" -"movs r5, 0x7\n" -"_0805DFEE:\n" -"cmp r2, 0x40\n" -"bne _0805DFF4\n" -"movs r5, 0x4\n" -"_0805DFF4:\n" -"cmp r2, 0x80\n" -"bne _0805DFFA\n" -"movs r5, 0\n" -"_0805DFFA:\n" -"cmp r2, 0x10\n" -"bne _0805E000\n" -"movs r5, 0x2\n" -"_0805E000:\n" -"cmp r2, 0x20\n" -"bne _0805E006\n" -"movs r5, 0x6\n" -"_0805E006:\n" -"cmp r5, 0\n" -"bge _0805E00C\n" -"b _0805E1A0\n" -"_0805E00C:\n" -"ldr r0, _0805E060\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"beq _0805E020\n" -"adds r0, r5, 0\n" -"movs r3, 0x1\n" -"ands r0, r3\n" -"cmp r0, 0\n" -"bne _0805E020\n" -"b _0805E1A0\n" -"_0805E020:\n" -"mov r2, r8\n" -"adds r2, 0x46\n" -"ldrb r1, [r2]\n" -"eors r1, r5\n" -"negs r0, r1\n" -"orrs r0, r1\n" -"lsrs r7, r0, 31\n" -"movs r1, 0x7\n" -"adds r0, r5, 0\n" -"ands r0, r1\n" -"strb r0, [r2]\n" -"ldr r0, _0805E064\n" -"ldrb r0, [r0]\n" -"cmp r0, 0\n" -"beq _0805E068\n" -"ldr r0, [sp, 0x10]\n" -"adds r0, 0x33\n" -"strb r5, [r0]\n" -"mov r0, r10\n" -"bl sub_806CEBC\n" -"adds r1, r0, 0\n" -"lsls r1, 24\n" -"lsrs r1, 24\n" -"mov r0, r10\n" -"adds r2, r5, 0\n" -"bl sub_806CDD4\n" -"b _0805E1A0\n" -".align 2, 0\n" -"_0805E05C: .4byte gRealInputs\n" -"_0805E060: .4byte gUnknown_202F22C\n" -"_0805E064: .4byte gUnknown_202F22D\n" -"_0805E068:\n" -"movs r4, 0\n" -"movs r3, 0\n" -"mov r0, r10\n" -"movs r1, 0x1\n" -"str r3, [sp, 0x20]\n" -"bl sub_805EC4C\n" -"lsls r0, 24\n" -"ldr r3, [sp, 0x20]\n" -"cmp r0, 0\n" -"beq _0805E080\n" -"b _0805E1AE\n" -"_0805E080:\n" -"mov r0, r8\n" -"adds r0, 0xB0\n" -"ldrb r0, [r0]\n" -"cmp r0, 0x2\n" -"bne _0805E094\n" -"ldr r0, _0805E090\n" -"b _0805E0BE\n" -".align 2, 0\n" -"_0805E090: .4byte gUnknown_80F8A84\n" -"_0805E094:\n" -"cmp r0, 0x7\n" -"bne _0805E0A0\n" -"ldr r0, _0805E09C\n" -"b _0805E0BE\n" -".align 2, 0\n" -"_0805E09C: .4byte gUnknown_80F8A6C\n" -"_0805E0A0:\n" -"cmp r0, 0x5\n" -"bne _0805E0AC\n" -"ldr r0, _0805E0A8\n" -"b _0805E0BE\n" -".align 2, 0\n" -"_0805E0A8: .4byte gUnknown_80F8AB0\n" -"_0805E0AC:\n" -"cmp r0, 0x3\n" -"bne _0805E0B8\n" -"ldr r0, _0805E0B4\n" -"b _0805E0BE\n" -".align 2, 0\n" -"_0805E0B4: .4byte gUnknown_80F8ADC\n" -"_0805E0B8:\n" -"cmp r0, 0x4\n" -"bne _0805E0C2\n" -"ldr r0, _0805E128\n" -"_0805E0BE:\n" -"ldr r3, [r0]\n" -"movs r4, 0x1\n" -"_0805E0C2:\n" -"mov r0, r10\n" -"adds r1, r5, 0\n" -"str r3, [sp, 0x20]\n" -"bl CanMoveInDirection\n" -"lsls r0, 24\n" -"ldr r3, [sp, 0x20]\n" -"cmp r0, 0\n" -"bne _0805E0D8\n" -"movs r0, 0x2\n" -"orrs r4, r0\n" -"_0805E0D8:\n" -"cmp r7, 0\n" -"beq _0805E0F4\n" -"mov r0, r10\n" -"str r3, [sp, 0x20]\n" -"bl sub_806CEBC\n" -"adds r1, r0, 0\n" -"lsls r1, 24\n" -"lsrs r1, 24\n" -"mov r0, r10\n" -"adds r2, r5, 0\n" -"bl sub_806CDD4\n" -"ldr r3, [sp, 0x20]\n" -"_0805E0F4:\n" -"movs r7, 0x2\n" -"adds r0, r4, 0\n" -"ands r0, r7\n" -"cmp r0, 0\n" -"bne _0805E192\n" -"movs r5, 0x1\n" -"mov r9, r5\n" -"ands r5, r4\n" -"cmp r5, 0\n" -"beq _0805E134\n" -"cmp r3, 0\n" -"beq _0805E114\n" -"mov r0, r10\n" -"adds r1, r3, 0\n" -"bl SendMessage\n" -"_0805E114:\n" -"movs r0, 0x1\n" -"bl sub_8044C50\n" -"ldr r1, _0805E12C\n" -"ldr r0, [r1]\n" -"ldr r2, _0805E130\n" -"adds r0, r2\n" -"mov r3, r9\n" -"strb r3, [r0]\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805E128: .4byte gUnknown_80F8B0C\n" -"_0805E12C: .4byte gDungeon\n" -"_0805E130: .4byte 0x00000673\n" -"_0805E134:\n" -"movs r0, 0x2\n" -"bl sub_8044C50\n" -"ldr r0, _0805E17C\n" -"ldrh r1, [r0]\n" -"adds r0, r7, 0\n" -"ands r0, r1\n" -"cmp r0, 0\n" -"bne _0805E14C\n" -"movs r0, 0\n" -"cmp r0, 0\n" -"beq _0805E188\n" -"_0805E14C:\n" -"movs r0, 0x9E\n" -"lsls r0, 1\n" -"add r0, r8\n" -"ldr r0, [r0]\n" -"bl FixedPointToInt\n" -"cmp r0, 0\n" -"beq _0805E188\n" -"mov r1, r10\n" -"ldr r0, [r1, 0x70]\n" -"adds r0, 0xBC\n" -"ldrb r0, [r0]\n" -"cmp r0, 0x2\n" -"beq _0805E174\n" -"ldr r2, _0805E180\n" -"ldr r0, [r2]\n" -"ldr r3, _0805E184\n" -"adds r0, r3\n" -"mov r1, r9\n" -"strb r1, [r0]\n" -"_0805E174:\n" -"mov r0, r8\n" -"adds r0, 0x48\n" -"strb r5, [r0]\n" -"b _0805E1AE\n" -".align 2, 0\n" -"_0805E17C: .4byte gRealInputs\n" -"_0805E180: .4byte gDungeon\n" -"_0805E184: .4byte 0x0000066c\n" -"_0805E188:\n" -"mov r0, r8\n" -"adds r0, 0x48\n" -"movs r2, 0x1\n" -"strb r2, [r0]\n" -"b _0805E1AE\n" -"_0805E192:\n" -"movs r3, 0x1\n" -"ands r4, r3\n" -"cmp r4, 0\n" -"beq _0805E1A0\n" -"movs r0, 0x23\n" -"bl sub_803E724\n" -"_0805E1A0:\n" -"movs r0, 0xF\n" -"bl sub_803E46C\n" -"ldr r5, [sp, 0x14]\n" -"cmp r5, 0\n" -"bne _0805E1AE\n" -"b _0805DB24\n" -"_0805E1AE:\n" -"ldr r1, [sp, 0x18]\n" -"ldrb r0, [r1]\n" -"cmp r0, 0\n" -"beq _0805E1BA\n" -"bl sub_804AA60\n" -"_0805E1BA:\n" -"ldr r4, [sp, 0x1C]\n" -"ldrh r0, [r4]\n" -"cmp r0, 0x2D\n" -"beq _0805E1C6\n" -"cmp r0, 0x13\n" -"bne _0805E1E0\n" -"_0805E1C6:\n" -"mov r0, r10\n" -"bl HandleTalkFieldAction\n" -"bl sub_8044B28\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805E2B0\n" -"movs r0, 0\n" -"bl sub_8044C50\n" -"bl _0805D980\n" -"_0805E1E0:\n" -"lsls r0, r6, 24\n" -"lsrs r1, r0, 24\n" -"cmp r1, 0\n" -"bne _0805E222\n" -"ldr r2, _0805E210\n" -"ldr r0, [r2]\n" -"ldr r3, _0805E214\n" -"adds r0, r3\n" -"strb r1, [r0]\n" -"ldrh r0, [r4]\n" -"cmp r0, 0\n" -"beq _0805E218\n" -"mov r0, r10\n" -"movs r1, 0\n" -"bl IsNotAttacking\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805E2B0\n" -"movs r0, 0xF\n" -"bl sub_803E46C\n" -"b _0805E2B0\n" -".align 2, 0\n" -"_0805E210: .4byte gDungeon\n" -"_0805E214: .4byte 0x0000066d\n" -"_0805E218:\n" -"movs r0, 0xF\n" -"bl sub_803E46C\n" -"bl _0805D980\n" -"_0805E222:\n" -"movs r0, 0xF\n" -"bl sub_803E46C\n" -"bl sub_8047158\n" -"movs r2, 0\n" -"lsrs r0, r6, 8\n" -"lsls r0, 24\n" -"cmp r0, 0\n" -"bne _0805E238\n" -"movs r2, 0x1\n" -"_0805E238:\n" -"lsrs r1, r6, 16\n" -"lsls r1, 24\n" -"lsrs r1, 24\n" -"adds r0, r2, 0\n" -"bl ShowFieldMenu\n" -"bl ResetRepeatTimers\n" -"bl ResetUnusedInputStruct\n" -"ldr r1, _0805E294\n" -"movs r0, 0\n" -"strb r0, [r1]\n" -"movs r0, 0\n" -"ldr r5, [sp, 0x18]\n" -"strb r0, [r5]\n" -"bl sub_804AA60\n" -"bl sub_8044B28\n" -"lsls r0, 24\n" -"lsrs r1, r0, 24\n" -"cmp r1, 0\n" -"bne _0805E2B0\n" -"ldrh r0, [r4]\n" -"cmp r0, 0\n" -"beq _0805E29C\n" -"cmp r0, 0x2B\n" -"bne _0805E27E\n" -"ldr r2, _0805E298\n" -"ldr r0, [r2]\n" -"movs r3, 0x1\n" -"strb r3, [r0, 0x4]\n" -"ldr r0, [r2]\n" -"strb r3, [r0, 0x3]\n" -"_0805E27E:\n" -"ldr r5, [sp, 0x1C]\n" -"ldrh r0, [r5]\n" -"cmp r0, 0x2E\n" -"bne _0805E2B0\n" -"ldr r2, _0805E298\n" -"ldr r0, [r2]\n" -"movs r3, 0x1\n" -"strb r3, [r0, 0x4]\n" -"ldr r0, [r2]\n" -"strb r1, [r0, 0x3]\n" -"b _0805E2B0\n" -".align 2, 0\n" -"_0805E294: .4byte gUnknown_202F22D\n" -"_0805E298: .4byte gDungeon\n" -"_0805E29C:\n" -"movs r0, 0xF\n" -"bl sub_803E46C\n" -"ldr r5, _0805E2C0\n" -"ldr r0, [r5]\n" -"ldrb r0, [r0, 0x4]\n" -"cmp r0, 0\n" -"bne _0805E2B0\n" -"bl _0805D980\n" -"_0805E2B0:\n" -"add sp, 0x24\n" -"pop {r3-r5}\n" -"mov r8, r3\n" -"mov r9, r4\n" -"mov r10, r5\n" -"pop {r4-r7}\n" -"pop {r0}\n" -"bx r0\n" -".align 2, 0\n" -"_0805E2C0: .4byte gDungeon\n"); -} + s16 unk0; + s16 unk2; + u8 unk4; + u8 unk5; +}; -#endif +extern const struct UnkStruct_8106AC8 gUnknown_8106AC8[]; -/* TODO: leaving this for now as it uses weird sprite OAM logic -void sub_805E2C4(Entity *leader) +struct UnkStruct_8106AE8 { - unkDungeonGlobal_unk181E8_sub *unkPtr; + s16 unk0; + s16 unk2; + u32 unk4; + u8 unk8; + u8 unk9; + u8 unkA; +}; - unkPtr = &gDungeon->unk181e8; - if (gUnknown_202F22C == 0) { +extern const struct UnkStruct_8106AE8 gUnknown_8106AE8[]; +#ifdef NONMATCHING +// Not even close in terms of matching, but functionally equivalent. Sprite OAM memes break the stack here. +// Creates arrow sprites which are used when in rotate or diagonal modes. +static void TryCreateModeArrows(Entity *leader) // https://decomp.me/scratch/gFX1S +{ + UnkDungeonGlobal_unk181E8_sub *unkPtr = &gDungeon->unk181e8; + + if (sInDiagonalMode) { + s32 i; + SpriteOAM sprite; + + for (i = 0; i < 4; i++) { + u32 objMode, matrixNum, tileNum, prio, xSprite, unk6; + s32 x, xMul, x2; + s32 unk1, unk1Mul, unk2; + + sprite.attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; + sprite.attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + + objMode = 1 << SPRITEOAM_SHIFT_OBJMODE; + sprite.attrib1 &= ~SPRITEOAM_MASK_OBJMODE; + sprite.attrib1 |= objMode; + + sprite.attrib1 &= ~SPRITEOAM_MASK_MOSAIC; + sprite.attrib1 &= ~SPRITEOAM_MASK_BPP; + + sprite.attrib1 &= ~SPRITEOAM_MASK_SHAPE; + + if (gUnknown_8106AC8[i].unk4 != 0) + matrixNum = 8; + else + matrixNum = 0; + + if (gUnknown_8106AC8[i].unk5) + matrixNum += 16; + + matrixNum &= SPRITEOAM_MAX_MATRIXNUM; + matrixNum <<= SPRITEOAM_SHIFT_MATRIXNUM; + sprite.attrib2 &= ~SPRITEOAM_MASK_MATRIXNUM; + sprite.attrib2 |= matrixNum; + + sprite.attrib2 &= ~SPRITEOAM_MASK_SHAPE; + + tileNum = 0x213 << SPRITEOAM_SHIFT_TILENUM; + sprite.attrib3 &= ~SPRITEOAM_MASK_TILENUM; + sprite.attrib3 |= tileNum; + + prio = 2 << SPRITEOAM_SHIFT_PRIORITY; + sprite.attrib3 &= ~SPRITEOAM_MASK_PRIORITY; + sprite.attrib3 |= prio; + + sprite.attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_0; + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_1; + + x = gUnknown_8106AC8[i].unk0; + xMul = x * 10; + x2 = (sArrowsFrames / 2) & 7; + xSprite = xMul + 116 + (x2 * x); + xSprite &= SPRITEOAM_MAX_X; + xSprite <<= SPRITEOAM_SHIFT_X; + sprite.attrib2 &= ~SPRITEOAM_MASK_X; + sprite.attrib2 |= xSprite; + + unk1 = gUnknown_8106AC8[i].unk2; + unk1Mul = unk1 * 10; + unk2 = (sArrowsFrames / 2) & 7; + unk6 = 82 + unk1Mul + (unk2 * unk1); + unk6 &= SPRITEOAM_MAX_UNK6_4; + unk6 <<= SPRITEOAM_SHIFT_UNK6_4; + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_4; + sprite.unk6 |= unk6; + + AddSprite(&sprite, 0x100, NULL, NULL); + } + } + else if (unkPtr->unk1821A) { + s32 i, to; + SpriteOAM sprite; + s32 var_2C = unkPtr->unk1821B; + s32 x, y; + s32 x1, x2, xMul; + s32 y1, y2, yMul; + + if (var_2C < 8u) { + to = (sShowThreeArrows2 != 0 && sShowThreeArrows1 != 0) ? 3 : 1; + + x1 = gUnknown_8106AE8[var_2C].unk0; + xMul = x1 * 10; + x2 = (sArrowsFrames / 2) & 7; + x = xMul + 116 + (x1 * x2); + + y1 = gUnknown_8106AE8[var_2C].unk2; + yMul = y1 * 10; + y2 = (sArrowsFrames / 2) & 7; + y = 82 + yMul + (y2 * y1); + for (i = 0; i < to; i++) { + u32 objMode, tileNum, prio, matrixNum, xSprite, ySprite; + + sprite.attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; + sprite.attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + + objMode = 1 << SPRITEOAM_SHIFT_OBJMODE; + sprite.attrib1 &= ~SPRITEOAM_MASK_OBJMODE; + sprite.attrib1 |= objMode; + + sprite.attrib1 &= ~SPRITEOAM_MASK_MOSAIC; + sprite.attrib1 &= ~SPRITEOAM_MASK_BPP; + + sprite.attrib1 &= ~SPRITEOAM_MASK_SHAPE; + + if (gUnknown_8106AE8[var_2C].unk8 != 0) + matrixNum = 8; + else + matrixNum = 0; + + if (gUnknown_8106AE8[var_2C].unk9) + matrixNum += 16; + + matrixNum &= SPRITEOAM_MAX_MATRIXNUM; + matrixNum <<= SPRITEOAM_SHIFT_MATRIXNUM; + sprite.attrib2 &= ~SPRITEOAM_MASK_MATRIXNUM; + sprite.attrib2 |= matrixNum; + + sprite.attrib2 &= ~SPRITEOAM_MASK_SIZE; + + tileNum = gUnknown_8106AE8[var_2C].unk4; + sprite.attrib3 &= ~SPRITEOAM_MASK_TILENUM; + sprite.attrib3 |= tileNum; + + prio = 2 << SPRITEOAM_SHIFT_PRIORITY; + sprite.attrib3 &= ~SPRITEOAM_MASK_PRIORITY; + sprite.attrib3 |= prio; + + sprite.attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_0; + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_1; + + xSprite = x; + xSprite &= SPRITEOAM_MAX_X; + xSprite <<= SPRITEOAM_SHIFT_X; + sprite.attrib2 &= ~SPRITEOAM_MASK_X; + sprite.attrib2 |= xSprite; + + ySprite = y; + ySprite &= SPRITEOAM_MAX_UNK6_4; + ySprite <<= SPRITEOAM_SHIFT_UNK6_4; + sprite.unk6 &= ~SPRITEOAM_MASK_UNK6_4; + sprite.unk6 |= ySprite; + + AddSprite(&sprite, 0x100, NULL, NULL); + x += gUnknown_8106AE8[var_2C].unk0 * 4; + y += gUnknown_8106AE8[var_2C].unk2 * 4; + } + } + } + + if (sInRotateMode && unkPtr->unk1821C != unkPtr->unk1821B) { + unkPtr->unk1821C = unkPtr->unk1821B; + sub_804A728(&leader->pos, unkPtr->unk1821B, 0, sInRotateMode); } } -*/ -NAKED void sub_805E2C4(Entity *leader) +#else +NAKED static void TryCreateModeArrows(Entity *leader) { asm_unified( "\n" " push {r4-r7,lr}\n" @@ -2116,7 +1028,7 @@ NAKED void sub_805E2C4(Entity *leader) " .align 2, 0\n" "_0805E47C: .4byte gDungeon\n" "_0805E480: .4byte 0x000181e8\n" -"_0805E484: .4byte gUnknown_202F22C\n" +"_0805E484: .4byte sInDiagonalMode\n" "_0805E488: .4byte 0xffff0000\n" "_0805E48C: .4byte 0x0000feff\n" "_0805E490: .4byte 0x0000fdff\n" @@ -2130,7 +1042,7 @@ NAKED void sub_805E2C4(Entity *leader) "_0805E4B0: .4byte 0x00000fff\n" "_0805E4B4: .4byte 0x0000fffe\n" "_0805E4B8: .4byte 0x0000fffd\n" -"_0805E4BC: .4byte gUnknown_202F22E\n" +"_0805E4BC: .4byte sArrowsFrames\n" "_0805E4C0: .4byte 0x000001ff\n" "_0805E4C4:\n" " ldr r3, _0805E6E4\n" @@ -2414,10 +1326,10 @@ NAKED void sub_805E2C4(Entity *leader) " .align 2, 0\n" "_0805E6E4: .4byte 0x0001821a\n" "_0805E6E8: .4byte 0x0001821b\n" -"_0805E6EC: .4byte gUnknown_202F231\n" -"_0805E6F0: .4byte gUnknown_202F230\n" +"_0805E6EC: .4byte sShowThreeArrows2\n" +"_0805E6F0: .4byte sShowThreeArrows1\n" "_0805E6F4: .4byte gUnknown_8106AE8\n" -"_0805E6F8: .4byte gUnknown_202F22E\n" +"_0805E6F8: .4byte sArrowsFrames\n" "_0805E6FC: .4byte 0xffff0000\n" "_0805E700: .4byte 0x0000feff\n" "_0805E704: .4byte 0x0000fdff\n" @@ -2426,16 +1338,18 @@ NAKED void sub_805E2C4(Entity *leader) "_0805E710: .4byte 0x0000dfff\n" "_0805E714: .4byte 0x00003fff\n" "_0805E718: .4byte 0x0000c1ff\n" -"_0805E71C: .4byte gUnknown_8106AEC\n" +"_0805E71C: .4byte gUnknown_8106AE8 + 4\n" "_0805E720: .4byte 0x000003ff\n" "_0805E724: .4byte 0x00000fff\n" "_0805E728: .4byte 0x0000fffe\n" "_0805E72C: .4byte 0x0000fffd\n" "_0805E730: .4byte 0x000001ff\n" -"_0805E734: .4byte gUnknown_202F22D" +"_0805E734: .4byte sInRotateMode" ); } +#endif // NONMATCHING + void sub_805E738(Entity *a0) { Tile *tile; @@ -2622,7 +1536,7 @@ bool8 sub_805EC4C(Entity *a0, u8 a1) Tile *tile; EntityInfo *tileMonsterInfo; Entity *tileMonster; - EntityInfo *entityInfo = a0->info; + EntityInfo *entityInfo = GetEntInfo(a0); pos.x = a0->pos.x + gAdjacentTileOffsets[entityInfo->action.direction].x; pos.y = a0->pos.y + gAdjacentTileOffsets[entityInfo->action.direction].y; @@ -2632,11 +1546,11 @@ bool8 sub_805EC4C(Entity *a0, u8 a1) if (tileMonster == NULL) return FALSE; if (GetEntityType(tileMonster) != ENTITY_MONSTER) return FALSE; - tileMonsterInfo = tileMonster->info; + tileMonsterInfo = GetEntInfo(tileMonster); if (tileMonsterInfo->isNotTeamMember && (tileMonsterInfo->shopkeeper != 1 && tileMonsterInfo->shopkeeper != 2) && !IsClientOrTeamBase(tileMonsterInfo->joinedAt.joinedAt) - && tileMonsterInfo->clientType != 1) { + && tileMonsterInfo->clientType != CLIENT_TYPE_CLIENT) { return FALSE; } @@ -2796,7 +1710,6 @@ extern void sub_8083CE0(u8 param_1); extern u8 gAvailablePokemonNames[]; extern u8 gUnknown_202749A[]; -extern s32 gUnknown_202F260; extern MenuInputStruct gUnknown_202EE10; void sub_805F02C(void) @@ -2867,6 +1780,17 @@ u16 GetLeaderActionId(void) return GetLeaderInfo()->action.action; } +// Could this be a start of a new file? +static UNUSED EWRAM_DATA u8 sUnused[4] = {0}; +static EWRAM_DATA unkStruct_8044CC8 sUnknownActionUnk4 = {0}; +static EWRAM_DATA s32 sUnknown_202F240 = 0; +static UNUSED EWRAM_DATA u8 sUnused2[4] = {0}; +static EWRAM_DATA s16 sUnknown_202F248[8] = {0}; +static EWRAM_DATA s32 sUnknown_202F258 = 0; +static UNUSED EWRAM_DATA u8 sUnused3[4] = {0}; +static EWRAM_DATA s32 sTeamMenuChosenId = 0; +static UNUSED EWRAM_DATA u8 sUnused4[4] = {0}; + void ShowFieldMenu(u8 a0_, bool8 a1) { Item *item; @@ -2895,7 +1819,7 @@ void ShowFieldMenu(u8 a0_, bool8 a1) while (1) { if (r10 < 0) { sub_8044C10(1); - gUnknown_202F260 = -1; + sTeamMenuChosenId = -1; DrawFieldMenu(a0); sub_806A2BC(GetLeader(), 0); while (1) { @@ -3020,7 +1944,7 @@ void ShowFieldMenu(u8 a0_, bool8 a1) Entity *teamMon = gDungeon->teamPokemon[i]; if (EntityExists(teamMon)) { if (i == GetLeaderActionContainer()->unk4[0].actionUseIndex) { - gUnknown_202F260 = count; + sTeamMenuChosenId = count; if (GetLeaderActionId() != 0) { sub_806A2BC(teamMon, 0); } @@ -3150,7 +2074,7 @@ void ShowFieldMenu(u8 a0_, bool8 a1) var_30.a0_32 = 1; if (sub_805FD74(GetLeader(), &var_30)) { // This actually doesn't do anything, it's just there to make the code match as the compiler does a `lsl r0, r0, #0x10, mov r0, r4` - leader = 0; leader = leader; + ASM_MATCH_TRICK(leader); } if (sub_805FD3C(&var_30) && sub_805FD74(GetLeader(), &var_30)) { sub_8044C10(1); @@ -3460,11 +2384,6 @@ bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0) return a0->a0_8; } -extern unkStruct_8044CC8 gUnknown_202F238; -extern s32 gUnknown_202F240; -extern s16 gUnknown_202F248[]; -extern s32 gUnknown_202F258; - s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4); void sub_8060890(Position *a0); @@ -3504,9 +2423,9 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) }, }; - gUnknown_202F238.actionUseIndex = 0; - gUnknown_202F238.lastItemThrowPosition.x = 0; - gUnknown_202F238.lastItemThrowPosition.y = 0; + sUnknownActionUnk4.actionUseIndex = 0; + sUnknownActionUnk4.lastItemThrowPosition.x = 0; + sUnknownActionUnk4.lastItemThrowPosition.y = 0; if (a1 != NULL) { var_2C = (a1->a0_8 != 0); var_34 = (a1->a0_16 != 0); @@ -3514,14 +2433,14 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) var_28 = (a1->a0_32 != 0); } - gUnknown_202F258 = sub_8060D64(gUnknown_202F248, var_30, var_34, var_28, a0); - if (gUnknown_202F258 == 0) { + sUnknown_202F258 = sub_8060D64(sUnknown_202F248, var_30, var_34, var_28, a0); + if (sUnknown_202F258 == 0) { DisplayDungeonMessage(0, gUnknown_80F8B24, 1); return TRUE; } r8 = 0; - gUnknown_202F240 = 0; + sUnknown_202F240 = 0; while (1) { s32 id; @@ -3533,7 +2452,7 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) if (item->flags & ITEM_FLAG_EXISTS && item->flags & ITEM_FLAG_UNPAID) { item->flags &= ~(ITEM_FLAG_UNPAID); r8 = i / 10; - gUnknown_202F240 = i % 10; + sUnknown_202F240 = i % 10; } } for (i_r6 = 0; i_r6 < MAX_TEAM_MEMBERS; i_r6++) { @@ -3542,19 +2461,19 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) EntityInfo *monInfo = teamMon->info; if (monInfo->heldItem.flags & ITEM_FLAG_EXISTS && monInfo->heldItem.flags & ITEM_FLAG_UNPAID) { monInfo->heldItem.flags &= ~(ITEM_FLAG_UNPAID); - for (i = 0; i < gUnknown_202F258; i++) { - if (gUnknown_202F248[i] == i_r6 + 4) { + for (i = 0; i < sUnknown_202F258; i++) { + if (sUnknown_202F248[i] == i_r6 + 4) { r8 = i; break; } } - gUnknown_202F240 = 0; + sUnknown_202F240 = 0; } } } CreateFieldItemMenu(r8, a0, var_2C, var_30, &var_FC, &var_3C); - id = gUnknown_202F248[gUnknown_202EE10.unk1E]; + id = sUnknown_202F248[gUnknown_202EE10.unk1E]; if (id >= MAX_TEAM_MEMBERS) { r4 = gDungeon->teamPokemon[id - MAX_TEAM_MEMBERS]; } @@ -3568,21 +2487,21 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) AddMenuCursorSprite(&gUnknown_202EE10); sub_803E46C(0x14); if (!var_30) { - if (gUnknown_202F258 > 1) { + if (sUnknown_202F258 > 1) { if ((gRealInputs.pressed & DPAD_LEFT) || gUnknown_202EE10.unk28.dpad_left) { sub_8083CE0(0); if (--r8 < 0) { - r8 = gUnknown_202F258 - 1; + r8 = sUnknown_202F258 - 1; } - gUnknown_202F240 = var_30; + sUnknown_202F240 = var_30; break; } if ((gRealInputs.pressed & DPAD_RIGHT) || gUnknown_202EE10.unk28.dpad_right) { sub_8083CE0(0); - if (++r8 == gUnknown_202F258) { + if (++r8 == sUnknown_202F258) { r8 = 0; } - gUnknown_202F240 = var_30; + sUnknown_202F240 = var_30; break; } } @@ -3594,7 +2513,7 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) sub_8083CE0(1); sub_8013744(&gUnknown_202EE10, 1); } - if (gRealInputs.pressed & SELECT_BUTTON && gUnknown_202F248[r8] <= 1) { + if (gRealInputs.pressed & SELECT_BUTTON && sUnknown_202F248[r8] <= 1) { s32 r3; bool32 r7 = TRUE; s16 arr[10]; @@ -3602,11 +2521,11 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) PlaySoundEffect(0x132); sub_8047158(); ConvertMoneyItemToMoney(); - gUnknown_202F240 = 0; + sUnknown_202F240 = 0; r3 = sub_8060D64(arr, var_30, var_34, var_28, a0); - if (gUnknown_202F258 == r3) { + if (sUnknown_202F258 == r3) { for (i_r6 = 0; i_r6 < r3; i_r6++) { - if (arr[i_r6] != gUnknown_202F248[i_r6]) { + if (arr[i_r6] != sUnknown_202F248[i_r6]) { break; } } @@ -3616,10 +2535,10 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) } if (r7) { r8 = 0; - gUnknown_202F240 = 0; - gUnknown_202F258 = r3; - for (i_r6 = 0; i_r6 < gUnknown_202F258; i_r6++) { - gUnknown_202F248[i_r6] = arr[i_r6]; + sUnknown_202F240 = 0; + sUnknown_202F258 = r3; + for (i_r6 = 0; i_r6 < sUnknown_202F258; i_r6++) { + sUnknown_202F248[i_r6] = arr[i_r6]; } } break; @@ -3650,7 +2569,7 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) } AddMenuCursorSprite(&gUnknown_202EE10); sub_803E46C(0x14); - if (gUnknown_202F248[gUnknown_202EE10.unk1E] <= 1 && !(gTeamInventoryRef->teamItems[0].flags & ITEM_FLAG_EXISTS)) { + if (sUnknown_202F248[gUnknown_202EE10.unk1E] <= 1 && !(gTeamInventoryRef->teamItems[0].flags & ITEM_FLAG_EXISTS)) { r9 = 2; } @@ -3664,15 +2583,15 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) } else if (r9 == 3) { SetMonsterActionFields(&a0Info->action, 0xC); - a0Info->action.unk4[0] = gUnknown_202F238; + a0Info->action.unk4[0] = sUnknownActionUnk4; sub_803EAF0(0, NULL); r9 = 0; break; } else { - gUnknown_202F240 = gUnknown_202EE10.menuIndex; + sUnknown_202F240 = gUnknown_202EE10.menuIndex; if (var_2C != 0) { - a0Info->action.unk4[1] = gUnknown_202F238; + a0Info->action.unk4[1] = sUnknownActionUnk4; sub_803EAF0(0, NULL); r9 = 0; break; @@ -3713,7 +2632,7 @@ bool8 sub_805FD74(Entity * a0, struct UnkMenuBitsStruct *a1) if (r9 != 1 || var_30 != 0) { if (a0Info->action.action == 0x37 || a0Info->action.action == 0x38 || a0Info->action.action == 0x3E) { // Hm... - int newAction = gUnknown_202F238.actionUseIndex - 0x90; + int newAction = sUnknownActionUnk4.actionUseIndex - 0x90; a0Info->action.unk4[0].actionUseIndex = newAction; sub_803EAF0(0, 0); r9 = 0; @@ -3761,16 +2680,16 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 var_94 = gUnknown_8106B6C; a1Info = a1->info; r10 = sub_8060800(a5, a0); - gUnknown_202EE10.menuIndex = gUnknown_202F240; + gUnknown_202EE10.menuIndex = sUnknown_202F240; gUnknown_202EE10.unk1A = 0; gUnknown_202EE10.unk1E = a0; - gUnknown_202EE10.unk20 = gUnknown_202F258; + gUnknown_202EE10.unk20 = sUnknown_202F258; gUnknown_202EE10.unk4 = 0; gUnknown_202EE10.unk0 = 0; gUnknown_202EE10.unk14.x = 0; sub_801317C(&gUnknown_202EE10.unk28); gDungeon->unk181e8.unk18212 = 0; - switch (gUnknown_202F248[a0]) { + switch (sUnknown_202F248[a0]) { case 0: case 1: a4->a0[0].unk10 = 0x10; @@ -3814,16 +2733,12 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 sub_80137B0(&gUnknown_202EE10, 0x70); sub_80073B8(0); x = ((a0 - r10) * 8) + 0xC; - switch (gUnknown_202F248[a0]) + switch (sUnknown_202F248[a0]) { case 0: PrintFormatStringOnWindow(x, 0, gTeamToolboxAPtr, 0, 0); for (i = 0; i < 10; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (items[i].flags & ITEM_FLAG_EXISTS) { + if (ItemExists(&gTeamInventoryRef->teamItems[i])) { gUnknown_202EE10.unk1A++; sub_8090E14(txtBuff, &gTeamInventoryRef->teamItems[i], &gUnknown_8106B60); y = sub_8013800(&gUnknown_202EE10, i); @@ -3837,11 +2752,7 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 case 1: PrintFormatStringOnWindow(x, 0, gTeamToolboxBPtr, 0, 0); for (i = 0; i < 10; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (items[i + 10].flags & 1) { + if (ItemExists(&gTeamInventoryRef->teamItems[i + 10])) { gUnknown_202EE10.unk1A++; sub_8090E14(txtBuff, &gTeamInventoryRef->teamItems[i + 10], &gUnknown_8106B60); y = sub_8013800(&gUnknown_202EE10, i); @@ -3880,7 +2791,7 @@ void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextStruct3 } break; default: { - Entity *chosenTeamMember = gDungeon->teamPokemon[gUnknown_202F248[a0] - MAX_TEAM_MEMBERS]; + Entity *chosenTeamMember = gDungeon->teamPokemon[sUnknown_202F248[a0] - MAX_TEAM_MEMBERS]; if (EntityExists(chosenTeamMember)) { Item *item = &chosenTeamMember->info->heldItem; SetMessageArgument_2(gAvailablePokemonNames, chosenTeamMember->info, 0); @@ -3912,20 +2823,20 @@ s32 sub_8060800(UnkTextStruct2_sub2 *a0, s32 a1) s32 i, r1, r2, r3; r1 = 0; - for (i = 0; i < gUnknown_202F258; i++) { - if (gUnknown_202F248[i] <= 1) { + for (i = 0; i < sUnknown_202F258; i++) { + if (sUnknown_202F248[i] <= 1) { r1++; } } - if (gUnknown_202F248[a1] <= 1) { + if (sUnknown_202F248[a1] <= 1) { r3 = a1; r2 = r1; r1 = 0; } else { r3 = a1 - r1; - r2 = gUnknown_202F258 - r1; + r2 = sUnknown_202F258 - r1; } if (a0 != NULL) { @@ -3939,7 +2850,7 @@ s32 sub_8060800(UnkTextStruct2_sub2 *a0, s32 a1) bool8 sub_8060860(s32 a0) { - if (gUnknown_202EE10.unk1A <= 1 || gUnknown_202F248[a0] > 1) + if (gUnknown_202EE10.unk1A <= 1 || sUnknown_202F248[a0] > 1) return FALSE; else return TRUE; @@ -3947,25 +2858,25 @@ bool8 sub_8060860(s32 a0) void sub_8060890(Position *a0) { - s32 var = gUnknown_202F248[gUnknown_202EE10.unk1E]; + s32 var = sUnknown_202F248[gUnknown_202EE10.unk1E]; switch (var) { case 0: - gUnknown_202F238.actionUseIndex = gUnknown_202EE10.menuIndex + 1; + sUnknownActionUnk4.actionUseIndex = gUnknown_202EE10.menuIndex + 1; break; case 1: - gUnknown_202F238.actionUseIndex = gUnknown_202EE10.menuIndex + 11; + sUnknownActionUnk4.actionUseIndex = gUnknown_202EE10.menuIndex + 11; break; case 2: - gUnknown_202F238.actionUseIndex = 128; + sUnknownActionUnk4.actionUseIndex = 128; break; default: - gUnknown_202F238.actionUseIndex = var - 116; + sUnknownActionUnk4.actionUseIndex = var - 116; break; } - gUnknown_202F238.lastItemThrowPosition.x = a0->x; - gUnknown_202F238.lastItemThrowPosition.y = a0->y; + sUnknownActionUnk4.lastItemThrowPosition.x = a0->x; + sUnknownActionUnk4.lastItemThrowPosition.y = a0->y; } extern Item * sub_8044CC8(Entity *param_1, unkStruct_8044CC8 *param_2, UNUSED s32 a3); @@ -3978,12 +2889,12 @@ extern void sub_8045064(void); void sub_8060900(Entity *a0) { u16 val_sub8044DC8; - Item *item = sub_8044CC8(a0, &gUnknown_202F238, 0xA); + Item *item = sub_8044CC8(a0, &sUnknownActionUnk4, 0xA); EntityInfo *a0Info = a0->info; gUnknown_202EE6C = 0; - if (gUnknown_202F238.actionUseIndex < 144) { - if (gUnknown_202F238.actionUseIndex == 128) { + if (sUnknownActionUnk4.actionUseIndex < 144) { + if (sUnknownActionUnk4.actionUseIndex == 128) { sub_8044F5C(9, item->id); if (GetItemCategory(item->id) != CATEGORY_POKE) { bool32 r2 = 0; @@ -4000,10 +2911,9 @@ void sub_8060900(Entity *a0) sub_8044FF0(9); } } - // Why is it checking actionUseIndex again? - if (gUnknown_202F238.actionUseIndex == 128 && gDungeon->unk65B != 0) { - sub_8044F5C(10, item->id); - } + } + if (sUnknownActionUnk4.actionUseIndex == 128 && gDungeon->unk65B != 0) { + sub_8044F5C(10, item->id); } val_sub8044DC8 = sub_8044DC8(item); if (val_sub8044DC8 != 0) { @@ -4016,12 +2926,12 @@ void sub_8060900(Entity *a0) } } - if (gUnknown_202F238.actionUseIndex <= 20 + if (sUnknownActionUnk4.actionUseIndex <= 20 && (GetItemCategory(item->id) == CATEGORY_THROWN_LINE || GetItemCategory(item->id) == CATEGORY_THROWN_ARC)) { s32 i; - if (item->flags & ITEM_FLAG_SET) { + if (ItemSet(item)) { sub_8044F5C(0x3D, item->id); } else { @@ -4029,13 +2939,9 @@ void sub_8060900(Entity *a0) } for (i = 0; i < INVENTORY_SIZE; i++) { - // Compiler uses r5 without the fakematch trick. It's gTeamInventoryRef causing matching issues again... - #ifndef NONMATCHING - item++;item--; - #endif // NONMATCHING - if (gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_EXISTS - && gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_SET - && gTeamInventoryRef->teamItems[i].flags & ITEM_FLAG_STICKY) + if (ItemExists(&gTeamInventoryRef->teamItems[i]) + && ItemSet(&gTeamInventoryRef->teamItems[i]) + && ItemSticky(&gTeamInventoryRef->teamItems[i])) { sub_8044FF0(0x3C); sub_8044FF0(0x3D); @@ -4044,8 +2950,8 @@ void sub_8060900(Entity *a0) } } - if (gUnknown_202F238.actionUseIndex != 129) { - if (gUnknown_202F238.actionUseIndex != 128) { + if (sUnknownActionUnk4.actionUseIndex != 129) { + if (sUnknownActionUnk4.actionUseIndex != 128) { s32 i; bool32 r8 = FALSE; @@ -4080,7 +2986,7 @@ void sub_8060900(Entity *a0) } } - if (gUnknown_202F238.actionUseIndex <= 20) { + if (sUnknownActionUnk4.actionUseIndex <= 20) { Entity *tileEntity = GetTile(a0->pos.x, a0->pos.y)->object; if (tileEntity == NULL) { sub_8044F5C(8, item->id); @@ -4107,7 +3013,7 @@ void sub_8060900(Entity *a0) } } else { - s32 index = gUnknown_202F238.actionUseIndex - 144; + s32 index = sUnknownActionUnk4.actionUseIndex - 144; Entity *teamMon = gDungeon->teamPokemon[index]; if (EntityExists(teamMon)) { bool32 r5, r6, r4; @@ -4169,7 +3075,7 @@ void sub_8060900(Entity *a0) void sub_8060CE8(ActionContainer *a0) { SetMonsterActionFields(a0, gUnknown_202EE44[gUnknown_202EE10.menuIndex].unk0); - a0->unk4[0] = gUnknown_202F238; + a0->unk4[0] = sUnknownActionUnk4; a0->unk4[1].actionUseIndex = 0; a0->unk4[1].lastItemThrowPosition.x = 0; a0->unk4[1].lastItemThrowPosition.y = 0; @@ -4330,7 +3236,7 @@ bool8 sub_8060E38(Entity *a0) } sp.unk0 = gUnknown_202EE10.menuIndex; - gUnknown_202F260 = gUnknown_202EE10.menuIndex; + sTeamMenuChosenId = gUnknown_202EE10.menuIndex; sub_806145C(&sp); if (r10) { EntityInfo *info = a0->info; @@ -4417,18 +3323,18 @@ void DrawFieldTeamMenu(struct UnkFieldTeamMenuStruct *a0, UnkTextStruct3 *a1, bo a0->unk4[count] = i; monInfo = teamMon->info; a0->unk14[count] = monInfo->unk157; - if (pos.x == teamMon->pos.x && pos.y == teamMon->pos.y && gUnknown_202F260 < 0) { - gUnknown_202F260 = count; + if (pos.x == teamMon->pos.x && pos.y == teamMon->pos.y && sTeamMenuChosenId < 0) { + sTeamMenuChosenId = count; } count++; } } - if (gUnknown_202F260 >= count) { - gUnknown_202F260 = count - 1; + if (sTeamMenuChosenId >= count) { + sTeamMenuChosenId = count - 1; } - if (gUnknown_202F260 < 0) { - gUnknown_202F260 = 0; + if (sTeamMenuChosenId < 0) { + sTeamMenuChosenId = 0; } for (i = count; i < MAX_TEAM_MEMBERS; i++) { @@ -4439,7 +3345,7 @@ void DrawFieldTeamMenu(struct UnkFieldTeamMenuStruct *a0, UnkTextStruct3 *a1, bo gUnknown_202F270.f0 = 1; gUnknown_202F270.f1 = 0; gUnknown_202F270.f3 = 0; - gUnknown_202EE10.menuIndex = gUnknown_202F260; + gUnknown_202EE10.menuIndex = sTeamMenuChosenId; gUnknown_202EE10.unk1A = count; gUnknown_202EE10.unk1C = count; gUnknown_202EE10.unk1E = 0; @@ -4535,7 +3441,7 @@ void sub_806145C(struct UnkFieldTeamMenuStruct *a0) gUnknown_202EE6C = 0; teamMon = gDungeon->teamPokemon[a0->unk4[gUnknown_202EE10.menuIndex]]; - monInfo = teamMon->info; + monInfo = GetEntInfo(teamMon); sub_8044F5C(0x1B, 0); sub_8044F5C(0x19, 0); if (!monInfo->isTeamLeader) { @@ -4547,28 +3453,27 @@ void sub_806145C(struct UnkFieldTeamMenuStruct *a0) sub_8044F5C(0x30, 0); if (!monInfo->isTeamLeader) { sub_8044F5C(0x1A, 0); - // Why checking teamLeader again? - if (!monInfo->isTeamLeader && gDungeon->unk65C && CanLeaderSwitch(gDungeon->dungeonLocation.id)) { - bool32 r5; + } + if (!monInfo->isTeamLeader && gDungeon->unk65C && CanLeaderSwitch(gDungeon->dungeonLocation.id)) { + bool32 r5; - sub_8044F5C(0x3B, 0); - r5 = TRUE; - if (monInfo->teamIndex >= MAX_TEAM_MEMBERS) { + sub_8044F5C(0x3B, 0); + r5 = TRUE; + if (monInfo->teamIndex >= MAX_TEAM_MEMBERS) { + r5 = FALSE; + } + else { + PokemonStruct2 *mon = &gRecruitedPokemonRef->pokemon2[monInfo->teamIndex]; + if (sub_806A538(mon->unkA)) { r5 = FALSE; } - else { - PokemonStruct2 *mon = &gRecruitedPokemonRef->pokemon2[monInfo->teamIndex]; - if (sub_806A538(mon->unkA)) { - r5 = FALSE; - } - } + } - if (CheckVariousStatuses2(teamMon, FALSE)) { - r5 = FALSE; - } - if (!r5) { - sub_8044FF0(0x3B); - } + if (CheckVariousStatuses2(teamMon, FALSE)) { + r5 = FALSE; + } + if (!r5) { + sub_8044FF0(0x3B); } } diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 0d78b4fde..db46caaa5 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -171,21 +171,18 @@ void sub_806CE94(Entity *entity, u32 newDir) u8 sub_806CEBC(Entity *entity) { u8 sleep; - EntityInfo *entityInfo1; - EntityInfo *entityInfo2; + EntityInfo *entityInfo; - // NOTE: copy needed to match - entityInfo1 = entity->info; - entityInfo2 = entity->info; - sleep = entityInfo1->sleep.sleep; + entityInfo = GetEntInfo(entity); + sleep = entityInfo->sleep.sleep; if (sleep == STATUS_SLEEP || sleep == STATUS_NAPPING || sleep == STATUS_NIGHTMARE) { - if (entityInfo2->apparentID != MONSTER_SUDOWOODO || entityInfo2->sleep.sleepTurns != 0x7F) + if (entityInfo->apparentID != MONSTER_SUDOWOODO || entityInfo->sleep.sleepTurns != 0x7F) return 5; else return 7; } - if (entityInfo2->charging.chargingStatus == STATUS_BIDE) + if (entityInfo->charging.chargingStatus == STATUS_BIDE) return 11; return 7; } @@ -924,12 +921,12 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc if (GetEntityType(attacker) == ENTITY_MONSTER) { EntityInfo *attackerData = GetEntInfo(attacker); s32 exp = CalculateEXPGain(targetData->id, targetData->level); - switch (targetData->unkFB) { - case 2: + switch (targetData->expMultiplier) { + case EXP_BOOSTED: exp *= 3; exp /= 2; break; - case 0: + case EXP_HALVED: exp /= 2; break; } diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index e0bab1df4..33624775a 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -508,14 +508,11 @@ void RaiseAtkStatTarget(Entity * pokemon, Entity *target, s32 increment) u32 oldStat1; s32 newStat; EntityInfo *entityInfo; - EntityInfo *entityInfo1; if (EntityExists(target)) { SetMessageArgument(gAvailablePokemonNames,target,0); - // NOTE: had to have duplicates to match.. - entityInfo = target->info; - entityInfo1 = entityInfo; + entityInfo = GetEntInfo(target); oldStat = entityInfo->atk; oldStat1 = oldStat; @@ -523,7 +520,7 @@ void RaiseAtkStatTarget(Entity * pokemon, Entity *target, s32 increment) if (0xfe < newStat) { newStat = 0xff; } - entityInfo1->atk = newStat; + entityInfo->atk = newStat; if (oldStat1 < (u8)newStat) { sub_8041E60(target); sub_80522F4(pokemon,target,*gUnknown_80FC33C); @@ -541,14 +538,11 @@ void RaiseSpAtkStatTarget(Entity * pokemon, Entity *target, s32 increment) u32 oldStat1; s32 newStat; EntityInfo *entityInfo; - EntityInfo *entityInfo1; if (EntityExists(target)) { SetMessageArgument(gAvailablePokemonNames,target,0); - // NOTE: had to have duplicates to match.. - entityInfo = target->info; - entityInfo1 = entityInfo; + entityInfo = GetEntInfo(target); oldStat = entityInfo->spAtk; oldStat1 = oldStat; @@ -556,7 +550,7 @@ void RaiseSpAtkStatTarget(Entity * pokemon, Entity *target, s32 increment) if (0xfe < newStat) { newStat = 0xff; } - entityInfo1->spAtk = newStat; + entityInfo->spAtk = newStat; if (oldStat1 < (u8)newStat) { sub_8041E74(target); sub_80522F4(pokemon,target,*gUnknown_80FC388); @@ -574,14 +568,11 @@ void RaiseDefStatTarget(Entity * pokemon, Entity *target, s32 increment) u32 oldStat1; s32 newStat; EntityInfo *entityInfo; - EntityInfo *entityInfo1; if (EntityExists(target)) { SetMessageArgument(gAvailablePokemonNames,target,0); - // NOTE: had to have duplicates to match.. - entityInfo = target->info; - entityInfo1 = entityInfo; + entityInfo = GetEntInfo(target); oldStat = entityInfo->def; oldStat1 = oldStat; @@ -589,7 +580,7 @@ void RaiseDefStatTarget(Entity * pokemon, Entity *target, s32 increment) if (0xfe < newStat) { newStat = 0xff; } - entityInfo1->def = newStat; + entityInfo->def = newStat; if (oldStat1 < (u8)newStat) { sub_8041E84(target); sub_80522F4(pokemon,target,*gUnknown_80FC3D8); @@ -607,14 +598,11 @@ void RaiseSpDefStatTarget(Entity * pokemon, Entity *target, s32 increment) u32 oldStat1; s32 newStat; EntityInfo *entityInfo; - EntityInfo *entityInfo1; if (EntityExists(target)) { SetMessageArgument(gAvailablePokemonNames,target,0); - // NOTE: had to have duplicates to match.. - entityInfo = target->info; - entityInfo1 = entityInfo; + entityInfo = GetEntInfo(target); oldStat = entityInfo->spDef; oldStat1 = oldStat; @@ -622,7 +610,7 @@ void RaiseSpDefStatTarget(Entity * pokemon, Entity *target, s32 increment) if (0xfe < newStat) { newStat = 0xff; } - entityInfo1->spDef = newStat; + entityInfo->spDef = newStat; if (oldStat1 < (u8)newStat) { sub_8041E94(target); sub_80522F4(pokemon,target,*gUnknown_80FC428); diff --git a/src/code_8097670.c b/src/code_8097670.c index cdecdbbd8..5f028c526 100644 --- a/src/code_8097670.c +++ b/src/code_8097670.c @@ -4,6 +4,7 @@ #include "pokemon.h" #include "pokemon_3.h" #include "friend_area.h" +#include "moves.h" static EWRAM_DATA struct unkStruct_203B494 sUnknown_2039778 = {0}; @@ -216,12 +217,9 @@ void sub_8097944(void) { bool8 bVar2; bool8 bVar3; - int index; + s32 i, j; s32 counter; Move *move; - PokemonStruct1 *pokeStruct; - s32 index1; - s32 temp; bVar2 = 1; bVar3 = 1; @@ -229,99 +227,88 @@ void sub_8097944(void) sub_80976F8(0xd); } - for(index = 0; index < NUM_MONSTERS; index++) + for(i = 0; i < NUM_MONSTERS; i++) { + if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i])) { + s32 species = gRecruitedPokemonRef->pokemon[i].speciesNum; + gUnknown_203B494->unk1C[species / 32] |= 1 << species % 32; -#ifdef NONMATCHING - pokeStruct = &index[gRecruitedPokemonRef->pokemon]; -#else - register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[index]); - PokemonStruct1* p = gRecruitedPokemonRef->pokemon; - size_t addr = offset + (size_t)p; - pokeStruct = (PokemonStruct1*)addr; -#endif - - - if (((u8)(pokeStruct->unk0) & 1)) { - temp = pokeStruct->speciesNum; - gUnknown_203B494->unk1C[temp / 32] |= 1 << temp % 32; - - for(index1 = 0; index1 < MAX_MON_MOVES; index1++) + for(j = 0; j < MAX_MON_MOVES; j++) { - move = &gRecruitedPokemonRef->pokemon[index].moves[index1]; - if ((move->moveFlags & MOVE_FLAG_EXISTS)) { + move = &gRecruitedPokemonRef->pokemon[i].moves[j]; + if (MoveFlagExists(move)) { gUnknown_203B494->unk8C[move->id / 32] |= 1 << move->id % 32; } } } } - for(index = 0; index < MONSTER_MAX; index++) + for(i = 0; i < MONSTER_MAX; i++) { - if (index == MONSTER_NONE) continue; - if (index == MONSTER_CASTFORM_SNOWY) continue; - if (index == MONSTER_CASTFORM_SUNNY) continue; - if (index == MONSTER_CASTFORM_RAINY) continue; - if (index == MONSTER_DEOXYS_ATTACK) continue; - if (index == MONSTER_DEOXYS_DEFENSE) continue; - if (index == MONSTER_DEOXYS_SPEED) continue; - if (index == MONSTER_MUNCHLAX) continue; - if (index == MONSTER_DECOY) continue; - if (index == MONSTER_STATUE) continue; - if (index == MONSTER_RAYQUAZA_CUTSCENE) continue; + if (i == MONSTER_NONE) continue; + if (i == MONSTER_CASTFORM_SNOWY) continue; + if (i == MONSTER_CASTFORM_SUNNY) continue; + if (i == MONSTER_CASTFORM_RAINY) continue; + if (i == MONSTER_DEOXYS_ATTACK) continue; + if (i == MONSTER_DEOXYS_DEFENSE) continue; + if (i == MONSTER_DEOXYS_SPEED) continue; + if (i == MONSTER_MUNCHLAX) continue; + if (i == MONSTER_DECOY) continue; + if (i == MONSTER_STATUE) continue; + if (i == MONSTER_RAYQUAZA_CUTSCENE) continue; - if ((gUnknown_203B494->unk54[index / 32] & 1 << index % 32) == 0) + if ((gUnknown_203B494->unk54[i / 32] & 1 << i % 32) == 0) { bVar3 = 0; } - if ((gUnknown_203B494->unk1C[index / 32] & 1 << index % 32) != 0) + if ((gUnknown_203B494->unk1C[i / 32] & 1 << i % 32) != 0) { - if (index == MONSTER_MOLTRES) { + if (i == MONSTER_MOLTRES) { sub_80976F8(0x10); } - if (index == MONSTER_ZAPDOS) { + if (i == MONSTER_ZAPDOS) { sub_80976F8(0x11); } - if (index == MONSTER_ARTICUNO) { + if (i == MONSTER_ARTICUNO) { sub_80976F8(0x12); } - if (index == MONSTER_DEOXYS_NORMAL) { + if (i == MONSTER_DEOXYS_NORMAL) { sub_80976F8(0x13); } - if (index == MONSTER_ENTEI) { + if (i == MONSTER_ENTEI) { sub_80976F8(0x14); } - if (index == MONSTER_RAIKOU) { + if (i == MONSTER_RAIKOU) { sub_80976F8(0x15); } - if (index == MONSTER_SUICUNE) { + if (i == MONSTER_SUICUNE) { sub_80976F8(0x16); } - if (index == MONSTER_HO_OH) { + if (i == MONSTER_HO_OH) { sub_80976F8(0x17); } - if (index == MONSTER_KYOGRE) { + if (i == MONSTER_KYOGRE) { sub_80976F8(0x18); } - if (index == MONSTER_GROUDON) { + if (i == MONSTER_GROUDON) { sub_80976F8(0x19); } - if (index == MONSTER_RAYQUAZA) { + if (i == MONSTER_RAYQUAZA) { sub_80976F8(0x1a); } - if (index == MONSTER_LUGIA) { + if (i == MONSTER_LUGIA) { sub_80976F8(0x1b); } - if (index == MONSTER_CELEBI) { + if (i == MONSTER_CELEBI) { sub_80976F8(0x1c); } - if (index == MONSTER_MEW) { + if (i == MONSTER_MEW) { sub_80976F8(0x1d); } - if (index == MONSTER_MEWTWO) { + if (i == MONSTER_MEWTWO) { sub_80976F8(0x1e); } - if (index == MONSTER_JIRACHI) { + if (i == MONSTER_JIRACHI) { sub_80976F8(0x1f); } } @@ -338,10 +325,10 @@ void sub_8097944(void) sub_80976F8(0xe); } counter = 0; - for(index = 0; index < NUM_MONSTERS; index++) + for(i = 0; i < NUM_MONSTERS; i++) { - if (index == MONSTER_NONE || index == MONSTER_FLYGON || index == MONSTER_CACNEA || index == MONSTER_CACTURNE) continue; - if (gUnknown_203B494->unk8C[index / 32] & 1 << index % 32) { + if (i == MONSTER_NONE || i == MONSTER_FLYGON || i == MONSTER_CACNEA || i == MONSTER_CACTURNE) continue; + if (gUnknown_203B494->unk8C[i / 32] & 1 << i % 32) { counter++; } } diff --git a/src/dungeon_engine.c b/src/dungeon_engine.c index 24911f16f..a81c336d1 100644 --- a/src/dungeon_engine.c +++ b/src/dungeon_engine.c @@ -25,7 +25,7 @@ extern void sub_8086AC0(void); extern void sub_8043ED0(u32); extern void sub_8071DA4(Entity *); extern void TriggerWeatherAbilities(void); -extern void sub_805D8C8(void); +extern void DungeonHandlePlayerInput(void); extern void sub_805F02C(void); static void sub_8044454(void); @@ -140,7 +140,7 @@ static bool8 xxx_dungeon_80442D0(bool8 param_1) if (sub_8044B28()) return FALSE; sub_8071DA4(entity); gDungeon->noActionInProgress = TRUE; - sub_805D8C8(); + DungeonHandlePlayerInput(); gDungeon->noActionInProgress = FALSE; if (sub_8044B28()) break; sub_8072CF4(entity); diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index dc847d666..7c5eb8fb2 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -106,9 +106,8 @@ u8 sub_80703A0(Entity *pokemon, Position *pos) bool8 CanCrossWalls(Entity *pokemon) { - EntityInfo *pokemonInfo = pokemon->info; - EntityInfo *pokemonInfo2 = pokemonInfo; - if (pokemonInfo2->transformStatus.transformStatus == STATUS_MOBILE) + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->transformStatus.transformStatus == STATUS_MOBILE) { return TRUE; } @@ -116,7 +115,7 @@ bool8 CanCrossWalls(Entity *pokemon) { return TRUE; } - if (GetCrossableTerrain(pokemonInfo2->id) == CROSSABLE_TERRAIN_WALL) + if (GetCrossableTerrain(pokemonInfo->id) == CROSSABLE_TERRAIN_WALL) { return TRUE; } diff --git a/src/items.c b/src/items.c index efcb563e0..83954bf45 100644 --- a/src/items.c +++ b/src/items.c @@ -484,14 +484,7 @@ void FillInventoryGaps() // clear out the rest of the slots for (; last_filled < INVENTORY_SIZE; last_filled++) { - struct Item *items; - - DUMMY_TEAM_ITEMS_ASM_MATCH(last_filled); - items = gTeamInventoryRef->teamItems; - - items[last_filled].id = ITEM_NOTHING; - items[last_filled].quantity = 0; - items[last_filled].flags = 0; + ZeroOutItem(&gTeamInventoryRef->teamItems[last_filled]); } } @@ -510,11 +503,11 @@ s32 GetItemCountInInventory(u8 id) { s32 i; s32 count = 0; - struct Item *item = &gTeamInventoryRef->teamItems[0]; - for (i = 0; i < INVENTORY_SIZE; item++, i++) { - if (item->flags & 1 && item->id == id) + for (i = 0; i < INVENTORY_SIZE; i++) { + if (ItemExists(&gTeamInventoryRef->teamItems[i]) && gTeamInventoryRef->teamItems[i].id == id) { count++; + } } return count; @@ -522,20 +515,20 @@ s32 GetItemCountInInventory(u8 id) s32 GetItemPossessionCount(u8 id) { - s32 item_count = GetItemCountInInventory(id); - s32 i = 0; + s32 count = GetItemCountInInventory(id); + s32 i = 0; - unkStruct_203B45C *_gRecruitedPokemonRef = gRecruitedPokemonRef; - for (i = 0; i < NUM_MONSTERS; i++) { - PokemonStruct1* pokemon = &_gRecruitedPokemonRef->pokemon[i]; - if ((1 & pokemon->unk0) - && ((pokemon->unk0 >> 1) % 2) - && (pokemon->heldItem.id != ITEM_NOTHING) - && (pokemon->heldItem.id == id)) { - item_count++; + for (i = 0; i < NUM_MONSTERS; i++) { + PokemonStruct1 *mon = &gRecruitedPokemonRef->pokemon[i]; + if (PokemonFlag1(mon) + && PokemonFlag2(mon) + && (mon->heldItem.id != ITEM_NOTHING) + && (mon->heldItem.id == id)) + { + count++; + } } - } - return item_count; + return count; } void ShiftItemsDownFrom(s32 start) @@ -575,12 +568,8 @@ bool8 AddItemToInventory(const Item* slot) // try to add item to inventory, return 1 if failed for (i = 0; i < INVENTORY_SIZE; i++) { - Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - - items = gTeamInventoryRef->teamItems; - if (!(items[i].flags & ITEM_FLAG_EXISTS)) { - items[i] = *slot; + if (!ItemExists(&gTeamInventoryRef->teamItems[i])) { + gTeamInventoryRef->teamItems[i] = *slot; return FALSE; } } @@ -589,55 +578,39 @@ bool8 AddItemToInventory(const Item* slot) void ConvertMoneyItemToMoney(void) { - s32 i = 0; + s32 i, j; - do { - UNUSED TeamInventory * _gTeamInventoryRef = gTeamInventoryRef; - UNUSED size_t offs = offsetof(TeamInventory, teamItems[i]); - - Item* current_slot = &gTeamInventoryRef->teamItems[i]; - if ((current_slot->flags & ITEM_FLAG_EXISTS) && (current_slot->id == ITEM_POKE)) { - u32 result; - - result = GetMoneyValue(current_slot); - AddToTeamMoney(result); - current_slot->id = ITEM_NOTHING; - current_slot->quantity = 0; - current_slot->flags = 0; - } - } while (++i < INVENTORY_SIZE); - FillInventoryGaps(); - - i = 0; - do { - s32 lowest_index = -1; - UNUSED size_t offs = offsetof(TeamInventory, teamItems[i]); - - bool8 item_occupied = i[gTeamInventoryRef->teamItems].flags & ITEM_FLAG_EXISTS; - s32 next = i + 1; - - if (item_occupied) { - s32 lowest_order = GetItemOrder(gTeamInventoryRef->teamItems[i].id); - s32 j; - - // find next lowest - for (j = next; j < INVENTORY_SIZE; j++) { - UNUSED size_t offs = offsetof(TeamInventory, teamItems[j]); - if ((j[gTeamInventoryRef->teamItems].flags & ITEM_FLAG_EXISTS) && (lowest_order > GetItemOrder(gTeamInventoryRef->teamItems[j].id))) { - lowest_index = j; - lowest_order = GetItemOrder(gTeamInventoryRef->teamItems[j].id); + for (i = 0; i < INVENTORY_SIZE; i++) { + Item *item = &gTeamInventoryRef->teamItems[i]; + if (ItemExists(item) && item->id == ITEM_POKE) { + AddToTeamMoney(GetMoneyValue(item)); + ZeroOutItem(item); } - } - - if (lowest_index >= 0) { - // swap the slots - Item current = gTeamInventoryRef->teamItems[i]; - gTeamInventoryRef->teamItems[i] = gTeamInventoryRef->teamItems[lowest_index]; - gTeamInventoryRef->teamItems[lowest_index] = current; - } } - } while (++i < INVENTORY_SIZE); - FillInventoryGaps(); + FillInventoryGaps(); + + for (i = 0; i < INVENTORY_SIZE; i++) { + s32 lowestIndex = -1; + + if (ItemExists(&gTeamInventoryRef->teamItems[i])) { + s32 lowestOrder = GetItemOrder(gTeamInventoryRef->teamItems[i].id); + + for (j = i + 1; j < INVENTORY_SIZE; j++) { + if (ItemExists(&gTeamInventoryRef->teamItems[j]) && lowestOrder > GetItemOrder(gTeamInventoryRef->teamItems[j].id)) { + lowestIndex = j; + lowestOrder = GetItemOrder(gTeamInventoryRef->teamItems[j].id); + } + } + + if (lowestIndex >= 0) { + // swap the slots + Item temp = gTeamInventoryRef->teamItems[i]; + gTeamInventoryRef->teamItems[i] = gTeamInventoryRef->teamItems[lowestIndex]; + gTeamInventoryRef->teamItems[lowestIndex] = temp; + } + } + } + FillInventoryGaps(); } void AddToTeamMoney(s32 amount) @@ -908,12 +881,9 @@ bool8 IsGummiItem(u8 id) bool8 HasGummiItem(void) { - Item *items; s32 i; for (i = 0; i < INVENTORY_SIZE; i++) { - DUMMY_TEAM_ITEMS_ASM_MATCH(i); - items = gTeamInventoryRef->teamItems; - if ((items[i].flags & ITEM_FLAG_EXISTS) && IsGummiItem(items[i].id)) { + if (ItemExists(&gTeamInventoryRef->teamItems[i]) && IsGummiItem(gTeamInventoryRef->teamItems[i].id)) { return TRUE; } } @@ -1444,42 +1414,32 @@ s32 sub_8091E94(s32 a1, s32 a2, s32 a3) #endif } -void ClearAllItems_8091FB4() { - s32 i; +void ClearAllItems_8091FB4(void) +{ + s32 i; - for (i = 0; i < INVENTORY_SIZE; i++) { - Item* slot = &gTeamInventoryRef->teamItems[i]; - if (slot->flags & ITEM_FLAG_EXISTS) { - slot->flags &= 0xf7; - if (slot->id == ITEM_POKE) { - AddToTeamMoney(GetMoneyValue(slot)); - slot->id = ITEM_NOTHING; - slot->quantity = 0; - slot->flags = 0; - } - } - } - FillInventoryGaps(); - for (i = 0; i < NUM_MONSTERS; i++) { - PokemonStruct1* pokemon; -#ifdef NONMATCHING - pokemon = &i[gRecruitedPokemonRef->pokemon]; -#else - register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[i]); - PokemonStruct1* p = gRecruitedPokemonRef->pokemon; - size_t addr = offset + (size_t)p; - pokemon = (PokemonStruct1*)addr; -#endif - - if ((u8)pokemon->unk0 & 1) { - if (pokemon->heldItem.id) { - if (pokemon->heldItem.id == ITEM_POKE) { - AddToTeamMoney(GetMoneyValueHeld(&pokemon->heldItem)); - pokemon->heldItem.id = ITEM_NOTHING; + for (i = 0; i < INVENTORY_SIZE; i++) { + Item* slot = &gTeamInventoryRef->teamItems[i]; + if (ItemExists(slot)) { + slot->flags &= ~(ITEM_FLAG_STICKY); + if (slot->id == ITEM_POKE) { + AddToTeamMoney(GetMoneyValue(slot)); + ZeroOutItem(slot); + } + } + } + FillInventoryGaps(); + for (i = 0; i < NUM_MONSTERS; i++) { + if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i])) { + PokemonStruct1 *pokemon = &gRecruitedPokemonRef->pokemon[i]; + if (pokemon->heldItem.id) { + if (pokemon->heldItem.id == ITEM_POKE) { + AddToTeamMoney(GetMoneyValueHeld(&pokemon->heldItem)); + pokemon->heldItem.id = ITEM_NOTHING; + } + } } - } } - } } bool8 IsInvalidItemReward(u8 itemID) diff --git a/src/move_actions.c b/src/move_actions.c index 8f5bb5406..f2ddcc38e 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -46,6 +46,8 @@ extern u8 gFormatItems[]; extern u8 gAvailablePokemonNames[]; extern u8 gUnknown_202DFE8[]; +extern const u8 *const gUnknown_80FD350; +extern const u8 *const gUnknown_80FD370; extern u8 *gUnknown_80FE3BC[]; extern u8 *gUnknown_80FE38C[]; extern u8 *gUnknown_80FC888[]; @@ -510,37 +512,27 @@ bool32 sub_8057974(Entity *pokemon, Entity *target, Move *move, u32 param_4) return local_24; } -bool8 PainSplitMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) +bool8 PainSplitMoveAction(Entity *attacker, Entity *target, Move *move, s32 param_4) { - s32 newHP; - EntityInfo *iVar2; - EntityInfo *iVar3; - EntityInfo *iVar4; - EntityInfo *iVar5; + EntityInfo *attackerInfo = GetEntInfo(attacker); + EntityInfo *targetInfo = GetEntInfo(target); + s32 newHP = (attackerInfo->HP + targetInfo->HP) / 2; - // Need copies for some reason to match.. - iVar3 = (pokemon->info); - iVar4 = iVar3; - iVar2 = (target->info); - iVar5 = iVar2; + attackerInfo->HP = newHP; + targetInfo->HP = newHP; + if (attackerInfo->HP > attackerInfo->maxHPStat) { + attackerInfo->HP = attackerInfo->maxHPStat; + } + if (targetInfo->HP > targetInfo->maxHPStat) { + targetInfo->HP = targetInfo->maxHPStat; + } + SetMessageArgument(gAvailablePokemonNames,attacker,0); + SetMessageArgument(gAvailablePokemonNames + 0x50,target,0); + SetExpMultplier(attackerInfo); - newHP = ((iVar3->HP + iVar2->HP) / 2); - iVar3->HP = newHP; - iVar5->HP = newHP; - if (iVar3->HP > iVar3->maxHPStat) { - iVar3->HP = iVar3->maxHPStat; - } - if (iVar5->HP > iVar5->maxHPStat) { - iVar5->HP = iVar5->maxHPStat; - } - SetMessageArgument(gAvailablePokemonNames,pokemon,0); - SetMessageArgument(gAvailablePokemonNames + 0x50,target,0); - if (iVar4->unkFB == 0) { - iVar4->unkFB = 1; - } - // $m0 and $m1 shared their HP - sub_80522F4(pokemon,target,*gUnknown_80FC7EC); - return TRUE; + // $m0 and $m1 shared their HP + sub_80522F4(attacker,target,*gUnknown_80FC7EC); + return TRUE; } bool8 TormentMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) @@ -693,73 +685,29 @@ bool8 sub_8057D7C(Entity * pokemon, Entity * target, Move *move, s32 param_4) return TRUE; } -NAKED bool8 sub_8057D9C(Entity * pokemon, Entity * target, Move *move, s32 param_4) +bool8 sub_8057D9C(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - asm_unified( - "\tpush {r4-r7,lr}\n" - "\tmov r7, r8\n" - "\tpush {r7}\n" - "\tadds r6, r0, 0\n" - "\tadds r4, r1, 0\n" - "\tldr r0, [r4, 0x70]\n" - "\tmovs r5, 0\n" - "\tldr r1, _08057DF8\n" - "\tmov r8, r1\n" - "\tmovs r1, 0x8C\n" - "\tlsls r1, 1\n" - "\tadds r2, r0, r1\n" - "\tmovs r0, 0x1\n" - "\tmov r12, r0\n" - "\tmovs r7, 0x10\n" - "\tmovs r3, 0x3\n" -"_08057DBC:\n" - "\tldrb r1, [r2]\n" - "\tmov r0, r12\n" - "\tands r0, r1\n" - "\tcmp r0, 0\n" - "\tbeq _08057DD4\n" - "\tadds r0, r7, 0\n" - "\tands r0, r1\n" - "\tcmp r0, 0\n" - "\tbeq _08057DD4\n" - "\tmovs r0, 0\n" - "\tstrb r0, [r2, 0x4]\n" - "\tmovs r5, 0x1\n" -"_08057DD4:\n" - "\tadds r2, 0x8\n" - "\tsubs r3, 0x1\n" - "\tcmp r3, 0\n" - "\tbge _08057DBC\n" - "\tmov r0, r8\n" - "\tadds r1, r4, 0\n" - "\tmovs r2, 0\n" - "\tbl SetMessageArgument\n" - "\tcmp r5, 0\n" - "\tbeq _08057E00\n" - "\tldr r0, _08057DFC\n" - "\tldr r2, [r0]\n" - "\tadds r0, r6, 0\n" - "\tadds r1, r4, 0\n" - "\tbl sub_80522F4\n" - "\tb _08057E0C\n" - "\t.align 2, 0\n" -"_08057DF8: .4byte gUnknown_202DFE8\n" -"_08057DFC: .4byte gUnknown_80FD350\n" -"_08057E00:\n" - "\tldr r0, _08057E18\n" - "\tldr r2, [r0]\n" - "\tadds r0, r6, 0\n" - "\tadds r1, r4, 0\n" - "\tbl sub_80522F4\n" -"_08057E0C:\n" - "\tadds r0, r5, 0\n" - "\tpop {r3}\n" - "\tmov r8, r3\n" - "\tpop {r4-r7}\n" - "\tpop {r1}\n" - "\tbx r1\n" - "\t.align 2, 0\n" -"_08057E18: .4byte gUnknown_80FD370"); + s32 i; + EntityInfo *targetInfo = GetEntInfo(target); + bool8 flag = FALSE; + + for (i = 0; i < MAX_MON_MOVES; i++) { + Move *move = &targetInfo->moves.moves[i]; + if (MoveFlagExists(move) && MoveFlagLastUsed(move)) { + move->PP = 0; + flag = TRUE; + } + } + + SetMessageArgument(gUnknown_202DFE8, target, 0); + if (flag) { + sub_80522F4(pokemon, target, gUnknown_80FD350); + } + else { + sub_80522F4(pokemon, target, gUnknown_80FD370); + } + + return flag; } bool8 FocusEnergyMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) @@ -1194,9 +1142,7 @@ bool8 sub_80586DC(Entity * pokemon, Entity * target, Move * move, u32 param_4) if (newHP < 1) { newHP = 1; } - if (!entityInfo->unkFB) { - entityInfo->unkFB = TRUE; - } + SetExpMultplier(entityInfo); if (hasLiquidOoze) { DealDamageToEntity(pokemon, newHP, 0xd, 0x1fa); } @@ -1208,44 +1154,28 @@ bool8 sub_80586DC(Entity * pokemon, Entity * target, Move * move, u32 param_4) } -// NOTE: copy of sub_805AFA4 in status_checker.c except for different reg for entityInfo +// NOTE: almost the same as sub_8058D44 and sub_805AFA4 in status_actions.c bool8 sub_8058770(Entity * pokemon, Entity * target, Move * move, u32 param_4) { - s32 r0; - s32 r2; - s32 r1; - bool8 flag; - -#ifndef NONMATCHING - register EntityInfo *entityInfo asm("r2"); -#else - EntityInfo *entityInfo; -#endif - - entityInfo = pokemon->info; - r2 = entityInfo->maxHPStat; - r0 = r2; - if (r2 < 0) { - r0 = r2 + 3; - } - if (entityInfo->HP <= r0 >> 2) { - r2 = 0; - } - else if (r1 = entityInfo->HP, r1 <= r2 / 2) { - r2 = 1; - } - else - { - r0 = r2 * 3; - if (r0 < 0) { - r0 = r0 + 3; + s32 index; + bool8 flag; + EntityInfo *entityInfo = GetEntInfo(pokemon); + s32 maxHp = entityInfo->maxHPStat; + if (entityInfo->HP <= entityInfo->maxHPStat / 4) { + index = 0; } - if (r0 >>= 2, r2 = 3, r1 <= r0) { - r2 = 2; + else if (entityInfo->HP <= maxHp / 2) { + index = 1; } - } - flag = sub_8055640(pokemon,target,move,gUnknown_80F51A4[r2],param_4) ? TRUE : FALSE; - return flag; + else if (entityInfo->HP <= (maxHp * 3) / 4) { + index = 2; + } + else { + index = 3; + } + + flag = sub_8055640(pokemon,target,move,gUnknown_80F51A4[index],param_4) ? TRUE : FALSE; + return flag; } bool8 sub_80587E8(Entity * pokemon, Entity * target, Move * move, u32 param_4) @@ -1331,10 +1261,7 @@ bool8 sub_8058930(Entity *pokemon, Entity *target, Move *move, u32 param_4) RaiseAttackStageTarget(pokemon, pokemon, index2, 1); RaiseDefenseStageTarget(pokemon, pokemon, index1, 1); RaiseDefenseStageTarget(pokemon, pokemon, index2, 1); - if(entityInfo->unkFB == 0) - { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); } } return flag; @@ -1426,8 +1353,7 @@ bool8 sub_8058B84(Entity *pokemon, Entity *target, Move *move, u32 param_4) { entityInfo = pokemon->info; RaiseAttackStageTarget(pokemon, pokemon, gUnknown_8106A4C, 1); - if(entityInfo->unkFB == 0) - entityInfo->unkFB = 1; + SetExpMultplier(entityInfo); } } return flag; @@ -1516,41 +1442,25 @@ bool8 sub_8058D38(Entity *pokemon, Entity *target, Move *move, u32 param_4) // NOTE: same as sub_8058770 bool8 sub_8058D44(Entity * pokemon, Entity * target, Move * move, u32 param_4) { - s32 r0; - s32 r2; - s32 r1; - bool8 flag; - -#ifndef NONMATCHING - register EntityInfo *entityInfo asm("r2"); -#else - EntityInfo *entityInfo; -#endif - - entityInfo = pokemon->info; - r2 = entityInfo->maxHPStat; - r0 = r2; - if (r2 < 0) { - r0 = r2 + 3; - } - if (entityInfo->HP <= r0 >> 2) { - r2 = 0; - } - else if (r1 = entityInfo->HP, r1 <= r2 / 2) { - r2 = 1; - } - else - { - r0 = r2 * 3; - if (r0 < 0) { - r0 = r0 + 3; + s32 index; + bool8 flag; + EntityInfo *entityInfo = GetEntInfo(pokemon); + s32 maxHp = entityInfo->maxHPStat; + if (entityInfo->HP <= entityInfo->maxHPStat / 4) { + index = 0; } - if (r0 >>= 2, r2 = 3, r1 <= r0) { - r2 = 2; + else if (entityInfo->HP <= maxHp / 2) { + index = 1; } - } - flag = sub_8055640(pokemon,target,move,gUnknown_80F51B4[r2],param_4) ? TRUE : FALSE; - return flag; + else if (entityInfo->HP <= (maxHp * 3) / 4) { + index = 2; + } + else { + index = 3; + } + + flag = sub_8055640(pokemon,target,move,gUnknown_80F51B4[index],param_4) ? TRUE : FALSE; + return flag; } @@ -1574,9 +1484,7 @@ bool8 PsychUpMoveAction(Entity * pokemon, Entity * target, Move * move, u32 para } SetMessageArgument(gAvailablePokemonNames,target,0); sub_80522F4(pokemon,target,*gUnknown_80FBD58); // It psyched itself up! - if (iVar4->unkFB == 0) { - iVar4->unkFB = 1; - } + SetExpMultplier(iVar4); return TRUE; } @@ -1753,7 +1661,6 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4) s32 iVar3; s32 iVar4; bool8 flag; - EntityInfo *entityInfo; flag = FALSE; hasLiquidOoze = HasAbility(target, ABILITY_LIQUID_OOZE); @@ -1764,11 +1671,9 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4) iVar4 = 1; } if (EntityExists(pokemon)) { - entityInfo = pokemon->info; + EntityInfo *entityInfo = GetEntInfo(pokemon); flag = TRUE; - if (entityInfo->unkFB == 0) { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); if (sub_8057308(pokemon,0)) { if (hasLiquidOoze) { DealDamageToEntity(pokemon,iVar4,0xd,0x1fa); @@ -1784,34 +1689,27 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool8 SkillSwapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) { - u8 ability_1; - u8 ability_2; - bool8 flag; - u8 *puVar5; - u8 *puVar6; - EntityInfo * targetEntityInfo; - EntityInfo * pokeEntityData; + bool32 flag; - pokeEntityData = pokemon->info; - targetEntityInfo = target->info; + EntityInfo *pokeEntityData = GetEntInfo(pokemon); + EntityInfo *targetEntityInfo = GetEntInfo(target); if ((HasAbility(target, ABILITY_WONDER_GUARD)) || (HasAbility(pokemon, ABILITY_WONDER_GUARD))) { sub_80522F4(pokemon,target,*gUnknown_80FC8C0); flag = FALSE; } else { - puVar5 = &targetEntityInfo->abilities[0]; - ability_1 = *puVar5; - puVar6 = &targetEntityInfo->abilities[1]; - ability_2 = *puVar6; - *puVar5 = pokeEntityData->abilities[0]; - *puVar6 = pokeEntityData ->abilities[1]; - pokeEntityData->abilities[0] = ability_1; - pokeEntityData->abilities[1] = ability_2; + s32 ability1 = targetEntityInfo->abilities[0]; + s32 ability2 = targetEntityInfo->abilities[1]; + targetEntityInfo->abilities[0] = pokeEntityData->abilities[0]; + targetEntityInfo->abilities[1] = pokeEntityData->abilities[1]; + pokeEntityData->abilities[0] = ability1; + pokeEntityData->abilities[1] = ability2; gDungeon->unkC = 1; sub_80522F4(pokemon,target,*gUnknown_80FC888); - if (pokeEntityData->unkFB == 0) { - pokeEntityData->unkFB = 1; + // Weirdly enough SetExpMultplier inline doesn't work here... + if (pokeEntityData->expMultiplier == EXP_HALVED) { + pokeEntityData->expMultiplier = EXP_REGULAR; } sub_806ABAC(pokemon,pokemon); sub_806ABAC(pokemon,target); @@ -1820,178 +1718,44 @@ bool8 SkillSwapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param return flag; } -// https://decomp.me/scratch/Ul8x5 -#ifdef NONMATCHING bool32 SketchMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) { - u16 moveID; - struct EntityInfo *targetInfo; - struct EntityInfo *pokeInfo; - int moveIndex; - register bool32 flag asm("sl"); - struct Move *move1; - s32 other_flag = 0; + s32 i; + bool32 ret = FALSE; + EntityInfo *pokeInfo = GetEntInfo(pokemon); + EntityInfo *targetInfo = GetEntInfo(target); + bool32 moveFound = FALSE; + u16 moveId = MOVE_NOTHING; - flag = 0; - pokeInfo = pokemon->info; - targetInfo = target->info; - moveID = 0; - - for(moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++) - { - move1 = &targetInfo->moves[moveIndex]; - if ((((move1->moveFlags & MOVE_FLAG_EXISTS))) && ((targetInfo->moves[moveIndex].moveFlags & 0x10))) { - moveID = targetInfo->moves[moveIndex].id; - goto _moveIDcheck; - } - } - - if(other_flag == 0) - { - sub_80522F4(pokemon, target, *gUnknown_80FE3BC); - return 0; - } - -_moveIDcheck: - if (moveID == 0) { - sub_80522F4(pokemon, target, *gUnknown_80FE3BC); - } - else { - InitPokemonMove(move, moveID); - sub_80928C0(gFormatItems, move, 0); - move->moveFlags2 |= MOVE_FLAG2_UNK4; - move->moveFlags2 |= MOVE_FLAG_REPLACE; - sub_80522F4(pokemon, target, *gUnknown_80FE38C); - if (pokeInfo->unkFB == 0) { - pokeInfo->unkFB = 1; - } - flag = 1; + for (i = 0; i < MAX_MON_MOVES; i++) { + if (MoveFlagExists(&targetInfo->moves.moves[i]) && targetInfo->moves.moves[i].moveFlags & MOVE_FLAG_LAST_USED) { + moveId = targetInfo->moves.moves[i].id; + moveFound = TRUE; + break; + } } - return flag; -} -#else -NAKED -bool32 SketchMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) -{ - asm_unified( - "\tpush {r4-r7,lr}\n" - "\tmov r7, r10\n" - "\tmov r6, r9\n" - "\tmov r5, r8\n" - "\tpush {r5-r7}\n" - "\tsub sp, 0x4\n" - "\tadds r6, r0, 0\n" - "\tadds r7, r1, 0\n" - "\tadds r5, r2, 0\n" - "\tmovs r0, 0\n" - "\tmov r10, r0\n" - "\tldr r1, [r6, 0x70]\n" - "\tstr r1, [sp]\n" - "\tldr r0, [r7, 0x70]\n" - "\tmovs r2, 0\n" - "\tmov r12, r2\n" - "\tmovs r4, 0\n" - "\tmovs r1, 0x8C\n" - "\tlsls r1, 1\n" - "\tadds r3, r0, r1\n" - "\tadds r1, r0, 0\n" - "\tmovs r2, 0x1\n" - "\tmov r9, r2\n" - "\tmovs r0, 0x10\n" - "\tmov r8, r0\n" -"_08059372:\n" - "\tldrb r2, [r3]\n" - "\tmov r0, r9\n" - "\tands r0, r2\n" - "\tcmp r0, 0\n" - "\tbeq _08059384\n" - "\tmov r0, r8\n" - "\tands r0, r2\n" - "\tcmp r0, 0\n" - "\tbne _080593A8\n" -"_08059384:\n" - "\tadds r3, 0x8\n" - "\tadds r1, 0x8\n" - "\tadds r4, 0x1\n" - "\tcmp r4, 0x3\n" - "\tble _08059372\n" - "\tmovs r0, 0\n" - "\tcmp r0, 0\n" - "\tbne _080593B2\n" - "\tldr r0, _080593A4\n" - "\tldr r2, [r0]\n" - "\tadds r0, r6, 0\n" - "\tadds r1, r7, 0\n" - "\tbl sub_80522F4\n" - "\tmovs r0, 0\n" - "\tb _0805940A\n" - "\t.align 2, 0\n" -"_080593A4: .4byte gUnknown_80FE3BC\n" -"_080593A8:\n" - "\tmovs r2, 0x8D\n" - "\tlsls r2, 1\n" - "\tadds r0, r1, r2\n" - "\tldrh r0, [r0]\n" - "\tmov r12, r0\n" -"_080593B2:\n" - "\tmov r0, r12\n" - "\tcmp r0, 0\n" - "\tbne _080593CC\n" - "\tldr r0, _080593C8\n" - "\tldr r2, [r0]\n" - "\tadds r0, r6, 0\n" - "\tadds r1, r7, 0\n" - "\tbl sub_80522F4\n" - "\tb _08059408\n" - "\t.align 2, 0\n" -"_080593C8: .4byte gUnknown_80FE3BC\n" -"_080593CC:\n" - "\tadds r0, r5, 0\n" - "\tmov r1, r12\n" - "\tbl InitPokemonMove\n" - "\tldr r0, _0805941C\n" - "\tadds r1, r5, 0\n" - "\tmovs r2, 0\n" - "\tbl sub_80928C0\n" - "\tldrb r1, [r5, 0x1]\n" - "\tmovs r0, 0x4\n" - "\torrs r0, r1\n" - "\tmovs r1, 0x20\n" - "\torrs r0, r1\n" - "\tstrb r0, [r5, 0x1]\n" - "\tldr r0, _08059420\n" - "\tldr r2, [r0]\n" - "\tadds r0, r6, 0\n" - "\tadds r1, r7, 0\n" - "\tbl sub_80522F4\n" - "\tldr r1, [sp]\n" - "\tadds r1, 0xFB\n" - "\tldrb r0, [r1]\n" - "\tcmp r0, 0\n" - "\tbne _08059404\n" - "\tmovs r0, 0x1\n" - "\tstrb r0, [r1]\n" -"_08059404:\n" - "\tmovs r1, 0x1\n" - "\tmov r10, r1\n" -"_08059408:\n" - "\tmov r0, r10\n" -"_0805940A:\n" - "\tadd sp, 0x4\n" - "\tpop {r3-r5}\n" - "\tmov r8, r3\n" - "\tmov r9, r4\n" - "\tmov r10, r5\n" - "\tpop {r4-r7}\n" - "\tpop {r1}\n" - "\tbx r1\n" - "\t.align 2, 0\n" -"_0805941C: .4byte gFormatItems\n" -"_08059420: .4byte gUnknown_80FE38C\n" - ); + if (!moveFound) { + sub_80522F4(pokemon, target, *gUnknown_80FE3BC); + return FALSE; + } + + if (moveId == MOVE_NOTHING) { + sub_80522F4(pokemon, target, *gUnknown_80FE3BC); + } + else { + InitPokemonMove(move, moveId); + sub_80928C0(gFormatItems, move, 0); + move->moveFlags2 |= MOVE_FLAG2_UNK4; + move->moveFlags2 |= MOVE_FLAG_REPLACE; + sub_80522F4(pokemon, target, *gUnknown_80FE38C); + ASM_MATCH_TRICK(pokeInfo); + SetExpMultplier(pokeInfo); + ret = TRUE; + } + + return ret; } -#endif bool8 sub_8059424(Entity *pokemon, Entity *target, Move *move, u32 param_4) { @@ -2619,9 +2383,7 @@ bool8 sub_805A120(Entity * pokemon,Entity * target, Move *move, u32 param_4) sp->heldItem = item; sub_806A6E8(pokemon); sub_806A6E8(target); - if (r7->unkFB == 0) { - r7->unkFB = 1; - } + SetExpMultplier(r7); sub_80522F4(pokemon,target,*gUnknown_80FC790); // Traded items return TRUE; } @@ -2717,9 +2479,7 @@ bool8 RolePlayMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_ entityInfo->abilities[0] = targetEntityInfo->abilities[0]; entityInfo->abilities[1] = targetEntityInfo->abilities[1]; gDungeon->unkC = 1; - if (entityInfo->unkFB == 0) { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); sub_80522F4(pokemon,target,*gUnknown_80FC81C); sub_806ABAC(pokemon, pokemon); return TRUE; @@ -2864,9 +2624,7 @@ bool8 sub_805A5E8(Entity *pokemon, Entity *target, Move *move, u32 stat, u32 par if (sub_805727C(pokemon,pokemon,gUnknown_80F4DD2) != 0) { entityInfo = pokemon->info; RaiseDefenseStageTarget(pokemon,pokemon,stat,1); - if (entityInfo->unkFB == 0) { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); } } return flag; @@ -2905,17 +2663,12 @@ bool8 sub_805A688(Entity *pokemon, Entity *target, Move *move, u32 param_4) bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_4) { EntityInfo *entityInfo; - EntityInfo *targetEntityInfo1; - EntityInfo *targetEntityInfo2; + EntityInfo *targetEntityInfo; Item heldItem; Position pos; - Item *itemPtr; - u32 flag; - u32 itemFlag; - entityInfo = pokemon->info; - targetEntityInfo1 = target->info; - targetEntityInfo2 = targetEntityInfo1; + entityInfo = GetEntInfo(pokemon); + targetEntityInfo = GetEntInfo(target); SetMessageArgument(gAvailablePokemonNames, pokemon, 0); SetMessageArgument(gAvailablePokemonNames + 0x50, target, 0); if (HasAbility(target, ABILITY_STICKY_HOLD)) @@ -2930,21 +2683,15 @@ bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_ } else { - heldItem = targetEntityInfo1->heldItem; - itemFlag = heldItem.flags; - flag = ITEM_FLAG_EXISTS; - flag &= itemFlag; - if (flag == 0) + heldItem = targetEntityInfo->heldItem; + if (!ItemExists(&heldItem)) { sub_80522F4(pokemon,target,*gUnknown_80FD18C); return FALSE; } else { - itemPtr = &targetEntityInfo2->heldItem; - itemPtr->id = ITEM_NOTHING; - itemPtr->quantity = 0; - itemPtr->flags = 0; + ZeroOutItem(&targetEntityInfo->heldItem); sub_80522F4(pokemon,target,*gUnknown_80FD170); // $m1's item was swatted down! pos.x = gAdjacentTileOffsets[entityInfo->action.direction].x; pos.y = gAdjacentTileOffsets[entityInfo->action.direction].y; @@ -3189,57 +2936,42 @@ bool8 sub_805AD34(Entity *pokemon, Entity *target, Move *move, u32 param_4) return TRUE; } -static inline bool8 sub_805AD54_sub(Entity *entity) +bool32 sub_805AD54(Entity * pokemon, Entity * target, Move *move, u32 param_4) { - if ((entity->info->joinedAt.joinedAt == 0x4A) || (entity->info->joinedAt.joinedAt == 0x47)) { - return TRUE; + s32 numPossibleTargets; + s32 i; + Entity **possibleTargets; + bool32 flag = FALSE; + EntityInfo *info = GetEntInfo(pokemon); + + if (info->isNotTeamMember) { + possibleTargets = gDungeon->wildPokemon; + numPossibleTargets = DUNGEON_MAX_WILD_POKEMON; } else { - return FALSE; + possibleTargets = gDungeon->teamPokemon; + numPossibleTargets = MAX_TEAM_MEMBERS; } -} -bool8 sub_805AD54(Entity * pokemon, Entity * target, Move *move, u32 param_4) -{ - s32 numPossibleTargets; - EntityInfo *info; - Entity *targetEntity; -#ifndef NONMATCHING - register s32 index asm("r6"); -#else - s32 index; -#endif - Entity **possibleTargets; - bool8 flag; - - flag = FALSE; - info = pokemon->info; - if (pokemon->info->isNotTeamMember) { - possibleTargets = gDungeon->wildPokemon; - numPossibleTargets = DUNGEON_MAX_WILD_POKEMON; - } - else { - possibleTargets = gDungeon->teamPokemon; - numPossibleTargets = MAX_TEAM_MEMBERS; - } - for ( index = 0; index < numPossibleTargets; index++) { - targetEntity = possibleTargets[index]; - if ((((EntityExists(targetEntity)) && (pokemon != targetEntity)) && - (GetTreatmentBetweenMonsters(pokemon,targetEntity,FALSE,FALSE) == TREATMENT_TREAT_AS_ALLY)) && - (targetEntity->info->clientType != CLIENT_TYPE_CLIENT)) { - if (!sub_805AD54_sub(targetEntity)) { - sub_807D148(pokemon,targetEntity,2,&target->pos); - flag = TRUE; - if (info->unkFB == 0) { - info->unkFB = 1; + for (i = 0; i < numPossibleTargets; i++) { + Entity *targetEntity = possibleTargets[i]; + if (EntityExists(targetEntity) + && pokemon != targetEntity + && GetTreatmentBetweenMonsters(pokemon,targetEntity,FALSE,FALSE) == TREATMENT_TREAT_AS_ALLY) + { + EntityInfo *targetInfo = GetEntInfo(targetEntity); + if (targetInfo->clientType != CLIENT_TYPE_CLIENT && !IsClientOrTeamBase(targetInfo->joinedAt.joinedAt)) { + sub_807D148(pokemon,targetEntity,2,&target->pos); + flag = TRUE; + SetExpMultplier(info); + } } - } } - } - if (!flag) { - sub_80522F4(pokemon,target,*gUnknown_81004EC); - } - return flag; + + if (!flag) { + sub_80522F4(pokemon,target,*gUnknown_81004EC); + } + return flag; } bool8 sub_805AE3C(Entity *pokemon, Entity *target, Move *move, u32 param_4) @@ -3282,43 +3014,26 @@ bool8 sub_805AECC(Entity * pokemon, Entity * target, Move *move, u32 param_4) bool8 PresentMoveAction(Entity * pokemon, Entity * target, Move *move, u32 param_4) { - s32 rand1; - s32 rand2; - s32 HP; - bool8 flag; -#ifndef NONMATCHING - register Move *move_r6 asm("r6"); - register u32 param_4_r4 asm("r4"); -#else - Move *move_r6; - u32 param_4_r4; -#endif + bool8 flag; - move_r6 = move; - param_4_r4 = param_4; - - rand1 = DungeonRandInt(100); - rand2 = rand1; - if (rand1 < 10) { - flag = sub_8055864(pokemon,target,move_r6,0x78,param_4_r4) != 0 ? TRUE : FALSE; - return flag; - } - else { - if (rand1 < 0x1e) { - HP = target->info->maxHPStat; - if (HP < 0) { - HP = HP + 3; - } - HealTargetHP(pokemon,target,HP >> 2,0,TRUE); - return TRUE; - } - if (rand2 > 0x3B) { - flag = sub_8055864(pokemon,target,move_r6,0x28,param_4_r4) != 0 ? TRUE : FALSE; + s32 rand1 = DungeonRandInt(100); + s32 rand2 = rand1; + if (rand1 < 10) { + flag = (sub_8055864(pokemon,target,move,0x78,param_4) != 0); return flag; } else { - flag = sub_8055864(pokemon,target,move_r6,0x50,param_4_r4) != 0 ? TRUE : FALSE; - return flag; + if (rand1 < 30) { + HealTargetHP(pokemon,target,target->info->maxHPStat/4,0,TRUE); + return TRUE; + } + else if (rand2 >= 60) { + flag = (sub_8055864(pokemon,target,move,0x28,param_4) != 0); + return flag; + } + else { + flag = (sub_8055864(pokemon,target,move,0x50,param_4) != 0); + return flag; + } } - } } diff --git a/src/move_effects_target.c b/src/move_effects_target.c index f693d5c20..fc7ec50b9 100644 --- a/src/move_effects_target.c +++ b/src/move_effects_target.c @@ -759,7 +759,7 @@ void FrozenStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage) } else { - if ((u8)(entityInfo->immobilize.immobilizeStatus - 3) <= 1) { + if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) { sub_8076CB4(entityInfo->unk9C); } sub_8041F08(target); @@ -781,8 +781,8 @@ void SqueezedStatusTarget(Entity * pokemon, Entity * target, s16 param_3, bool32 bool8 displayMessage_u8 = displayMessage; if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,displayMessage_u8))) { - entityInfo = target->info; - if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) { + entityInfo = GetEntInfo(target); + if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) { sub_8076CB4(entityInfo->unk9C); } else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) { @@ -811,8 +811,8 @@ void ImmobilizedStatusTarget(Entity * pokemon, Entity * target) EntityInfo *entityInfo; if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,TRUE))) { - entityInfo = target->info; - if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) { + entityInfo = GetEntInfo(target); + if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) { sub_8076CB4(entityInfo->unk9C); } else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) { @@ -838,19 +838,17 @@ void ImmobilizedStatusTarget(Entity * pokemon, Entity * target) void IngrainedStatusTarget(Entity * pokemon, Entity * target) { EntityInfo *entityInfo; - EntityInfo *entityInfo2; if (EntityExists(target)) { - entityInfo = target->info; - entityInfo2 = entityInfo; - if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) { + entityInfo = GetEntInfo(target); + if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) { sub_8076CB4(entityInfo->unk9C); } SetMessageArgument(gAvailablePokemonNames,target,0); - if (entityInfo2->immobilize.immobilizeStatus != STATUS_INGRAIN) { - entityInfo2->immobilize.immobilizeStatus = STATUS_INGRAIN; - entityInfo2->immobilize.immobilizeStatusTurns = CalculateStatusTurns(target,gUnknown_80F4E60,TRUE) + 1; - entityInfo2->immobilize.immobilizeStatusDamageCountdown = 0; + if (entityInfo->immobilize.immobilizeStatus != STATUS_INGRAIN) { + entityInfo->immobilize.immobilizeStatus = STATUS_INGRAIN; + entityInfo->immobilize.immobilizeStatusTurns = CalculateStatusTurns(target,gUnknown_80F4E60,TRUE) + 1; + entityInfo->immobilize.immobilizeStatusDamageCountdown = 0; nullsub_90(target); sub_80522F4(pokemon,target,*gUnknown_80FB6A4); } diff --git a/src/moves.c b/src/moves.c index 9efc729be..ba8fc260a 100644 --- a/src/moves.c +++ b/src/moves.c @@ -171,40 +171,24 @@ u8 GetMoveType(Move *move) const u8 *GetLevelUpMoves(s16 species) { -#ifndef NONMATCHING - register s32 species1 asm("r1"), species2; -#else - s32 species1, species2; -#endif - - species1 = species; - species2 = species1; - if (species1 == MONSTER_DECOY || species1 == MONSTER_NONE) + s32 id = SpeciesId(species); + if (species == MONSTER_DECOY || species == MONSTER_NONE) + return &gUnknown_810992B; + if (id == MONSTER_MUNCHLAX) return &gUnknown_810992B; - if (species2 == MONSTER_MUNCHLAX) - return &gUnknown_810992B; - - return sMoveLearnsets[species2].levelUpMoves; + return sMoveLearnsets[id].levelUpMoves; } const u8 *GetHMTMMoves(s16 species) { -#ifndef NONMATCHING - register s32 species1 asm("r1"), species2; -#else - s32 species1, species2; -#endif - - species1 = species; - species2 = species1; - if (species1 == MONSTER_DECOY || species1 == MONSTER_NONE) + s32 id = SpeciesId(species); + if (species == MONSTER_DECOY || species == MONSTER_NONE) + return &gUnknown_810992B; + if (id == MONSTER_MUNCHLAX) return &gUnknown_810992B; - if (species2 == MONSTER_MUNCHLAX) - return &gUnknown_810992B; - - return sMoveLearnsets[species2].HMTMMoves; + return sMoveLearnsets[id].HMTMMoves; } u8 GetMoveAIWeight(Move *move) @@ -1325,15 +1309,7 @@ UNUSED static void RemoveLinkSequenceFromMoves8_v2(Move *moves, s32 index) for (i = index + 1; i < 8; i++) { Move* move = &moves[i]; - - #ifndef NONMATCHING - asm(""); - #endif - - if (!(move->moveFlags & MOVE_FLAG_EXISTS)) - break; - - if (!(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) + if (!MoveFlagExists(move) || !(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) break; move->moveFlags = 0; @@ -1364,15 +1340,7 @@ void RemoveLinkSequenceFromMoves8(Move *moves, s32 index) for (i = index + 1; i < 8; i++) { Move* move = &moves[i]; - - #ifndef NONMATCHING - asm(""); - #endif - - if (!(move->moveFlags & MOVE_FLAG_EXISTS)) - break; - - if (!(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) + if (!MoveFlagExists(move) || !(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) break; move->moveFlags = 0; @@ -1454,7 +1422,7 @@ static void unk_MovePrintData(Move *move, s32 y) static void CopyAndResetMove(Move *dest, Move *src) { - if (src->moveFlags & MOVE_FLAG_EXISTS) { + if (MoveFlagExists(src)) { dest->moveFlags = src->moveFlags; dest->moveFlags2 = 0; dest->id = src->id; @@ -1465,26 +1433,23 @@ static void CopyAndResetMove(Move *dest, Move *src) dest->moveFlags = 0; } -void CopyAndResetMoves(Move *destMoves, Move *srcMoves) +void CopyAndResetMoves(Moves *destMoves, Move *srcMoves) { s32 i; for (i = 0; i < MAX_MON_MOVES; i++) { - if (srcMoves[i].moveFlags & 1) { - destMoves[i].moveFlags = srcMoves[i].moveFlags; - destMoves[i].moveFlags2 = 0; - destMoves[i].id = srcMoves[i].id; - destMoves[i].PP = sMovesData[srcMoves[i].id].basePP; - destMoves[i].ginseng = srcMoves[i].PP; // This seems horribly bugged + if (MoveFlagExists(&srcMoves[i])) { + destMoves->moves[i].moveFlags = srcMoves[i].moveFlags; + destMoves->moves[i].moveFlags2 = 0; + destMoves->moves[i].id = srcMoves[i].id; + destMoves->moves[i].PP = sMovesData[srcMoves[i].id].basePP; + destMoves->moves[i].ginseng = srcMoves[i].PP; // This seems horribly bugged } else - destMoves[i].moveFlags = 0; + destMoves->moves[i].moveFlags = 0; } - // possibly destMoves is not just an array and this is the - // next struct field - // this index would be out of bounds after all - destMoves[MAX_MON_MOVES].moveFlags = 0; + destMoves->struggleMoveFlags = 0; } void CopyBareMoveData(Move *destMoves, Move *srcMoves) diff --git a/src/pokemon_mid.c b/src/pokemon_mid.c index 5e8db5caa..f41f92bfb 100644 --- a/src/pokemon_mid.c +++ b/src/pokemon_mid.c @@ -585,7 +585,7 @@ void xxx_pokemonstruct_to_pokemon2_808DE50(PokemonStruct2 * a1, PokemonStruct1 * } a1->currExp = pokemon->currExp; - CopyAndResetMoves(a1->moves.moves, pokemon->moves); + CopyAndResetMoves(&a1->moves, pokemon->moves); for (i = 0; i < POKEMON_NAME_LENGTH; i++) { a1->name[i] = pokemon->name[i]; diff --git a/src/post_office_guide1.c b/src/post_office_guide1.c index 4a0b17406..70539ac12 100644 --- a/src/post_office_guide1.c +++ b/src/post_office_guide1.c @@ -45,18 +45,18 @@ bool8 CreateHelperPelipperMenu(s16 speciesID) OpenedFile *faceFile; s32 species_32; - species_32 = speciesID; + species_32 = SpeciesId(speciesID); ResetUnusedInputStruct(); xxx_call_save_unk_text_struct_800641C(NULL, TRUE, TRUE); sPostOfficeHelper = MemoryAlloc(sizeof(PostOfficeWork), 8); - CopyYellowMonsterNametoBuffer(gUnknown_202E5D8, speciesID); - monName = GetMonSpecies(speciesID); + CopyYellowMonsterNametoBuffer(gUnknown_202E5D8, species_32); + monName = GetMonSpecies(species_32); strcpy(gAvailablePokemonNames, monName); sPostOfficeHelper->monPortrait.faceFile = NULL; sPostOfficeHelper->monPortrait.faceData = NULL; - if (speciesID != MONSTER_NONE) { + if (species_32 != MONSTER_NONE) { faceFile = GetDialogueSpriteDataPtr(species_32); sPostOfficeHelper->monPortrait.faceFile = faceFile; sPostOfficeHelper->monPortrait.spriteId = 0; diff --git a/src/status.c b/src/status.c index 64711f2f2..76e0ed85b 100644 --- a/src/status.c +++ b/src/status.c @@ -1092,8 +1092,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target) { Entity * entity; s32 index; - EntityInfo * targetEntityInfo; - EntityInfo * targetEntityInfo2; + EntityInfo *targetEntityInfo; if (EntityExists(target)) { SendWaitingEndMessage(pokemon,target,STATUS_SNATCH); @@ -1107,8 +1106,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target) } nullsub_81(target); - targetEntityInfo = target->info; - targetEntityInfo2 = targetEntityInfo; + targetEntityInfo = GetEntInfo(target); if (targetEntityInfo->waitingStruct.waitingStatus != STATUS_SNATCH) { targetEntityInfo->waitingStruct.waitingStatus = STATUS_SNATCH; targetEntityInfo->waitingStruct.waitingStatusTurns= CalculateStatusTurns(target,gUnknown_80F4EA8,FALSE) + 1; @@ -1116,7 +1114,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target) } gDungeon->snatchPokemon = target; - gDungeon->unk17B3C = targetEntityInfo2->unk98; + gDungeon->unk17B3C = targetEntityInfo->unk98; SetMessageArgument(gAvailablePokemonNames,target,0); sub_80522F4(pokemon,target,*gUnknown_80FB01C); EntityUpdateStatusSprites(target); @@ -1313,7 +1311,7 @@ void sub_8078B5C(Entity *pokemon, Entity *target, u32 bellyIncrement, s32 maxBel { bellySizeIncreased = TRUE; } - if (bellyIncrement == 999) + if (bellyIncrement == 999) { bellySizeIncreased = TRUE; } @@ -1360,7 +1358,7 @@ void sub_8078B5C(Entity *pokemon, Entity *target, u32 bellyIncrement, s32 maxBel } else { if (FixedPointToInt(*bellyPtr) >= FixedPointToInt(*puVar8)) { - if (displayMessage) sub_80522F4(pokemon,target,*gUnknown_80FBE64); // $m0's belly filled up full! + if (displayMessage) sub_80522F4(pokemon,target,*gUnknown_80FBE64); // $m0's belly filled up full! } else { diff --git a/src/status_actions.c b/src/status_actions.c index 6c041b424..e0a5238fb 100644 --- a/src/status_actions.c +++ b/src/status_actions.c @@ -159,42 +159,29 @@ extern struct NaturePowerMove gUnknown_80F59C8[10]; bool8 sub_805AFA4(Entity * pokemon, Entity * target, Move *move, u32 param_4) { - s32 r0; - s32 r2; - s32 r1; - bool8 flag; + EntityInfo *entityInfo; + s32 maxHp; + s32 index; + bool8 flag; + SendThawedMessage(pokemon, target); -#ifndef NONMATCHING - register EntityInfo *entityInfo asm("r3"); -#else - EntityInfo *entityInfo; -#endif + entityInfo = GetEntInfo(pokemon); + maxHp = entityInfo->maxHPStat; + if (entityInfo->HP <= entityInfo->maxHPStat / 4) { + index = 0; + } + else if (entityInfo->HP <= maxHp / 2) { + index = 1; + } + else if (entityInfo->HP <= (maxHp * 3) / 4) { + index = 2; + } + else { + index = 3; + } - SendThawedMessage(pokemon, target); - entityInfo = pokemon->info; - r2 = entityInfo->maxHPStat; - r0 = r2; - if (r2 < 0) { - r0 = r2 + 3; - } - if (entityInfo->HP <= r0 >> 2) { - r2 = 0; - } - else if (r1 = entityInfo->HP, r1 <= r2 / 2) { - r2 = 1; - } - else - { - r0 = r2 * 3; - if (r0 < 0) { - r0 = r0 + 3; - } - if (r0 >>= 2, r2 = 3, r1 <= r0) { - r2 = 2; - } - } - flag = sub_8055640(pokemon,target,move,gUnknown_80F51C4[r2],param_4) ? TRUE : FALSE; - return flag; + flag = sub_8055640(pokemon,target,move,gUnknown_80F51C4[index],param_4) ? TRUE : FALSE; + return flag; } bool8 sub_805B028(Entity * pokemon,Entity * target,Move *move) @@ -428,9 +415,7 @@ bool8 sub_805B3FC(Entity * pokemon,Entity * target,Move *move, s32 param_4, s32 if (sub_805727C(pokemon,pokemon,gUnknown_80F4DCE) != 0) { entityInfo = pokemon->info; RaiseAttackStageTarget(pokemon,pokemon,param_4,1); - if (entityInfo->unkFB == 0) { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); } } return flag; @@ -469,9 +454,7 @@ bool8 MimicMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4 } SetMessageArgument(gAvailablePokemonNames,pokemon,0); if (moveCounter != 0) { - if (entityInfo->unkFB == 0) { - entityInfo->unkFB = 1; - } + SetExpMultplier(entityInfo); sub_80522F4(pokemon,target,*gUnknown_80FDCE4); mimicSuccess = TRUE; } @@ -513,9 +496,7 @@ _0805B598: bool8 LeechSeedMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { HandleLeechSeed(pokemon, target, TRUE); - if (pokemon->info->unkFB == 0) { - pokemon->info->unkFB = 1; - } + SetExpMultplier(GetEntInfo(pokemon)); return TRUE; } @@ -550,9 +531,7 @@ bool8 sub_805B668(Entity * pokemon, Entity * target, Move *move, s32 param_4) newHP = 1; } if (sub_8057308(pokemon,0) != 0) { - if (pokemon->info->unkFB == 0) { - pokemon->info->unkFB = 1; - } + SetExpMultplier(GetEntInfo(pokemon)); if (sub_8057308(pokemon,0) != 0) { if (hasLiquidOoze) { DealDamageToEntity(pokemon,newHP,0xd,0x1fa); @@ -578,42 +557,35 @@ bool8 SnatchMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_ bool8 RecycleMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - Item *item; - s32 index; - EntityInfo *entityInfo; - bool8 isTMRecycled; + s32 i; + EntityInfo *entityInfo = GetEntInfo(target); + bool32 isTMRecycled = FALSE; - entityInfo = target->info; - isTMRecycled = FALSE; - if (!entityInfo->isNotTeamMember) { - for(index = 0; index < INVENTORY_SIZE; index++) - { -#ifdef NONMATCHING - item = &gTeamInventoryRef->teamItems[index]; -#else - register size_t offset asm("r1") = offsetof(TeamInventory, teamItems[index]); - Item* p = gTeamInventoryRef->teamItems; - size_t addr = offset + (size_t)p; - item = (Item*)addr; -#endif - if ((item->flags & ITEM_FLAG_EXISTS) && ((item->flags & ITEM_FLAG_IN_SHOP) == 0)) - if(item->id == ITEM_TM_USED_TM) { - xxx_init_itemslot_8090A8C(item, item->quantity + 0x7d,0); - isTMRecycled = TRUE; + if (!entityInfo->isNotTeamMember) { + for(i = 0; i < INVENTORY_SIZE; i++) + { + if (ItemExists(&gTeamInventoryRef->teamItems[i]) && !ItemInShop(&gTeamInventoryRef->teamItems[i])) + { + Item *item = &gTeamInventoryRef->teamItems[i]; + if (item->id == ITEM_TM_USED_TM) { + xxx_init_itemslot_8090A8C(item, item->quantity + 0x7d,0); + isTMRecycled = TRUE; + } } } - if ((entityInfo->heldItem.flags & ITEM_FLAG_EXISTS) && (entityInfo->heldItem.id == ITEM_TM_USED_TM)) { - xxx_init_itemslot_8090A8C(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0); - isTMRecycled = TRUE; + if (ItemExists(&entityInfo->heldItem) && (entityInfo->heldItem.id == ITEM_TM_USED_TM)) { + xxx_init_itemslot_8090A8C(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0); + isTMRecycled = TRUE; + } } - } - if (isTMRecycled) { - sub_80522F4(pokemon,target,*gUnknown_80FDC9C); // The Used TM was recharged! - } - else { - sub_80522F4(pokemon,target,*gUnknown_80FDCA0); // But nothing happened! - } - return isTMRecycled; + + if (isTMRecycled) { + sub_80522F4(pokemon,target,*gUnknown_80FDC9C); // The Used TM was recharged! + } + else { + sub_80522F4(pokemon,target,*gUnknown_80FDCA0); // But nothing happened! + } + return isTMRecycled; } bool8 ReflectMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) @@ -695,29 +667,21 @@ bool8 sub_805B968(Entity * pokemon, Entity * target, Move * move, s32 param_4) bool8 RockSmashMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - bool8 flag; Position pos; + bool8 flag = FALSE; -#ifdef NONMATCHING - Entity *temp; - Entity *temp1; -#else - register Entity *temp asm("r5"); - register Entity *temp1 asm("r4"); -#endif - - temp = pokemon; - temp1 = target; - - flag = 0; if (sub_8069D18(&pos) != 0) { - sub_80522F4(temp,temp1,*gUnknown_80FD430); // Can't use that diagonally! - } - else if (flag = (sub_804AD34(&pos)), flag != 0) { - sub_80522F4(temp,temp1,*gUnknown_80FD3F0); // It dug the wall in front! + sub_80522F4(pokemon,target,*gUnknown_80FD430); // Can't use that diagonally! } else { - sub_80522F4(temp,temp1,*gUnknown_80FD40C); // Can't use that here! + ASM_MATCH_TRICK(target); + flag = sub_804AD34(&pos); + if (flag) { + sub_80522F4(pokemon,target,*gUnknown_80FD3F0); // It dug the wall in front! + } + else { + sub_80522F4(pokemon,target,*gUnknown_80FD40C); // Can't use that here! + } } return flag; } @@ -768,14 +732,10 @@ bool8 sub_805BA50(Entity * pokemon, Entity * target, Move *move, s32 param_4) } else { iVar3->heldItem = iVar6->heldItem; - targetItem->id = ITEM_NOTHING; - targetItem->quantity = 0; - targetItem->flags = 0; + ZeroOutItem(targetItem); sub_806A6E8(pokemon); sub_806A6E8(target); - if (iVar3->unkFB == 0) { - iVar3->unkFB = 1; - } + SetExpMultplier(iVar3); sub_80522F4(pokemon,target,*gUnknown_80FC614); // Got $m1's item! } } @@ -792,10 +752,7 @@ bool8 ReboundOrbAction(Entity * pokemon, Entity * target, Move *move, s32 param_ bool8 sub_805BB74(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - if(pokemon->info->unkFB == 0) - { - pokemon->info->unkFB = 1; - } + SetExpMultplier(GetEntInfo(pokemon)); sub_807E254(pokemon, target, 1); return TRUE; } @@ -808,43 +765,33 @@ bool8 sub_805BB98(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 CleanseOrbAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - Item *item; - Entity *entity; - EntityInfo *entityInfo; - s32 index; - bool8 isItemCleaned; + s32 i; + EntityInfo *entityInfo = GetEntInfo(target); + bool32 isItemCleaned = FALSE; -#ifdef NONMATCHING - u8 flag; -#else - register u8 flag asm("r2"); -#endif - - entityInfo = target->info; - isItemCleaned = FALSE; if (!entityInfo->isNotTeamMember) { - for(index = 0; index < INVENTORY_SIZE; index++){ - // WTF why does this work... - UNUSED Item* current = &gTeamInventoryRef->teamItems[index]; - flag = index[gTeamInventoryRef->teamItems].flags; - if (((flag & ITEM_FLAG_EXISTS) != 0) && ((flag & ITEM_FLAG_IN_SHOP) == 0)) - if((flag & ITEM_FLAG_STICKY) != 0) { - gTeamInventoryRef->teamItems[index].flags = flag & 0xf7; + for(i = 0; i < INVENTORY_SIZE; i++){ + if (ItemExists(&gTeamInventoryRef->teamItems[i]) + && !ItemInShop(&gTeamInventoryRef->teamItems[i]) + && ItemSticky(&gTeamInventoryRef->teamItems[i])) + { + gTeamInventoryRef->teamItems[i].flags &= ~(ITEM_FLAG_STICKY); + isItemCleaned = TRUE; + } + } + for(i = 0; i < MAX_TEAM_MEMBERS; i++) + { + Entity *entity = gDungeon->teamPokemon[i]; + if (EntityExists(entity)) { + Item *item = &GetEntInfo(entity)->heldItem; + if (ItemExists(item) && ItemSticky(item)) { + item->flags &= ~(ITEM_FLAG_STICKY); isItemCleaned = TRUE; } - } - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if (EntityExists(entity)) { - item = &entity->info->heldItem; - if (((item->flags & ITEM_FLAG_EXISTS) != 0) && ((item->flags & ITEM_FLAG_STICKY) != 0)) { - item->flags &= 0xf7; - isItemCleaned = TRUE; - } - } } + } } + if (isItemCleaned) { sub_80522F4(pokemon,target,*gUnknown_80FC8F0); } diff --git a/src/status_checks_1.c b/src/status_checks_1.c index ee73ea556..a7c03d556 100644 --- a/src/status_checks_1.c +++ b/src/status_checks_1.c @@ -179,14 +179,13 @@ bool8 IsSleeping(Entity *pokemon) bool8 HasLowHealth(Entity *pokemon) { - EntityInfo *pokemonInfo = pokemon->info; - EntityInfo *pokemonInfo2 = pokemon->info; + EntityInfo *pokemonInfo = GetEntInfo(pokemon); s32 maxHPStat = pokemonInfo->maxHPStat; if (maxHPStat < 0) { maxHPStat += 3; } - if (pokemonInfo2->HP <= maxHPStat >> 2) + if (pokemonInfo->HP <= maxHPStat >> 2) { return TRUE; } diff --git a/src/trap.c b/src/trap.c index e195af20d..a2c44e550 100644 --- a/src/trap.c +++ b/src/trap.c @@ -407,7 +407,7 @@ void HandleStickyTrap(Entity *pokemon,Entity *target) int newIndex; Item *itemStack[21]; - info = target->info; + info = GetEntInfo(target); if (HasHeldItem(target,0xe)) { sub_80522F4(pokemon,target,*gUnknown_80FDC7C); } @@ -416,32 +416,29 @@ void HandleStickyTrap(Entity *pokemon,Entity *target) itemCount = 0; if (info->isTeamLeader) { for (index = 0; index < INVENTORY_SIZE; index++) { - struct Item *items; - DUMMY_TEAM_ITEMS_ASM_MATCH(index); - - items = gTeamInventoryRef->teamItems; - if ((items[index].flags & ITEM_FLAG_EXISTS) - && IsNotSpecialItem(items[index].id) - && !(gTeamInventoryRef->teamItems[index].flags & ITEM_FLAG_STICKY)) { - itemStack[itemCount] = &gTeamInventoryRef->teamItems[index]; + if (ItemExists(&gTeamInventoryRef->teamItems[index]) && IsNotSpecialItem(gTeamInventoryRef->teamItems[index].id)) { + Item *item = &gTeamInventoryRef->teamItems[index]; + if (!ItemSticky(item)) { + itemStack[itemCount] = item; itemCount++; } + } } } - if ((info->heldItem.flags & ITEM_FLAG_EXISTS) && IsNotSpecialItem((info->heldItem).id) && !(info->heldItem.flags & ITEM_FLAG_STICKY)) { - itemStack[itemCount] = &info->heldItem; - itemCount++; + if (ItemExists(&info->heldItem) && IsNotSpecialItem((info->heldItem).id) && !ItemSticky(&info->heldItem)) { + itemStack[itemCount] = &info->heldItem; + itemCount++; } if (itemCount == 0) { sub_80522F4(pokemon,target,*gUnknown_80FDC40); } else { - newIndex = DungeonRandInt(itemCount); - sub_8045BF8(gFormatItems, itemStack[newIndex]); - itemStack[newIndex]->flags |= ITEM_FLAG_STICKY; - sub_80421C0(target, 0x192); - sub_80522F4(pokemon,target,*gUnknown_80FDC18); + newIndex = DungeonRandInt(itemCount); + sub_8045BF8(gFormatItems, itemStack[newIndex]); + itemStack[newIndex]->flags |= ITEM_FLAG_STICKY; + sub_80421C0(target, 0x192); + sub_80522F4(pokemon,target,*gUnknown_80FDC18); } } } diff --git a/src/trap_1.c b/src/trap_1.c index 8ed6d1579..a13bcccae 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -382,7 +382,7 @@ void SaveEntity(unkStruct_8094924 *param_1, Entity *param_2) pbStack_50 = &info->stairSpotter; puStack_4c = &info->unkF3; pbStack_48 = &info->grudge; - puStack_34 = &info->unkFB; + puStack_34 = &info->expMultiplier; pbStack_44 = &info->exposed; pbStack_40 = &info->isColorChanged; pbStack_3c = &info->bossFlag; diff --git a/sym_ewram.txt b/sym_ewram.txt index d17364d46..ed2d88649 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -433,28 +433,8 @@ gUnknown_202F224: /* 202F224 (sub_8040DA0 - sub_805B264) */ gUnknown_202F228: /* 202F228 (sub_8055FA0 - sub_805B618) */ .space 0x4 -gUnknown_202F22C: /* 202F22C (sub_805D8C8 - sub_805E2C4) */ - .space 0x1 -gUnknown_202F22D: /* 202F22D (sub_805D8C8 - sub_805E2C4) */ - .space 0x1 -gUnknown_202F22E: /* 202F22E (sub_805D8C8 - sub_805E2C4) */ - .space 0x2 -gUnknown_202F230: /* 202F230 (sub_805D8C8 - sub_805E2C4) */ - .space 0x1 -gUnknown_202F231: /* 202F231 (sub_805D8C8 - sub_805E2C4) */ - .space 0x7 + .include "src/code_805D8C8_1.o" -gUnknown_202F238: /* 202F238 (sub_805FD74 - sub_8060CE8) */ - .space 0x8 -gUnknown_202F240: /* 202F240 (sub_805FD74 - CreateFieldItemMenu) */ - .space 0x8 -gUnknown_202F248: /* 202F248 (sub_805FD74 - sub_8060890) */ - .space 0x10 -gUnknown_202F258: /* 202F258 (sub_805FD74 - sub_8060800) */ - .space 0x8 - -gUnknown_202F260: /* 202F260 (ShowFieldMenu - DrawFieldTeamMenu) */ - .space 0x8 gUnknown_202F268: /* 202F268 (sub_8062500) */ .space 0x8 gUnknown_202F270: /* 202F270 (sub_8060E38 - sub_8061A38) */