From d0fcb9168bc36dff9c9da0d36baefd4fbf3a1c55 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sat, 12 Sep 2020 21:51:16 -0400 Subject: [PATCH 01/15] Match two minor functions in battle_tent and berry_crush --- src/battle_tent.c | 9 +++------ src/berry_crush.c | 17 +++++------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/battle_tent.c b/src/battle_tent.c index 0a03fc167..250e2d8ee 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -355,11 +355,7 @@ static void GenerateOpponentMons(void) { u16 trainerId; s32 i, j, k; - #ifndef NONMATCHING - register const u16 *monSet asm("r9"); // Fix me. Compiler insists on moving that variable into stack. - #else - const u16 *monSet; - #endif + const u16 *monSet; u16 species[FRONTIER_PARTY_SIZE]; u16 heldItems[FRONTIER_PARTY_SIZE]; s32 monId = 0; @@ -380,7 +376,8 @@ static void GenerateOpponentMons(void) } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); gTrainerBattleOpponent_A = trainerId; - while (gFacilityTrainers[gTrainerBattleOpponent_A].monSet[monId] != 0xFFFF) + monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; + while (monSet[monId] != 0xFFFF) monId++; if (monId > 8) break; diff --git a/src/berry_crush.c b/src/berry_crush.c index 2175d2abb..bc972fec7 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -1779,22 +1779,15 @@ void sub_8022600(struct BerryCrushGame *r6) void sub_80226D0(struct BerryCrushGame *r6) { u8 r5 = 0; - const u32 *r0 = gUnknown_08DE3FD4; -#ifndef NONMATCHING // r4, r5, r6 register roulette - register u8 *r4 asm("r4") = gDecompressionBuffer; - register u32 r0_ asm("r0"); -#else - u8 *r4 = gDecompressionBuffer; - u32 r0_; -#endif + u8 * r4; - LZ77UnCompWram(r0, r4); - for (; r5 < r6->unk9; ++r5) + LZ77UnCompWram(gUnknown_08DE3FD4, gDecompressionBuffer); // required for matching + + for (r4 = gDecompressionBuffer; r5 < r6->unk9; ++r5) { - r0_ = r6->unk138.unkC[r5]->unk0; CopyToBgTilemapBufferRect( 3, - &r4[r0_ * 40], + &r4[r6->unk138.unkC[r5]->unk0 * 40], r6->unk138.unkC[r5]->unk1, r6->unk138.unkC[r5]->unk2, 10, From 449df5860d91570a2b14caf58a51af45c7bbf8d0 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sun, 13 Sep 2020 00:26:01 -0400 Subject: [PATCH 02/15] Begin documenting berry_crush --- src/berry_crush.c | 180 +++++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/src/berry_crush.c b/src/berry_crush.c index bc972fec7..744389ba7 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -149,7 +149,7 @@ struct BerryCrushGame u8 unk8; u8 unk9; - u8 unkA; + u8 mainTask; u8 unkB; u8 unkC; @@ -199,10 +199,10 @@ struct BerryCrushGame u8 unk31C0[0x1000]; }; -static void sub_8020F74(void); -static void sub_8020F88(void); -static void sub_8020FA0(u8); -void sub_8020FC4(struct BerryCrushGame *); +static void VBlankCB(void); +static void MainCB(void); +static void MainTask(u8); +static void InitGame(struct BerryCrushGame *); void sub_8022BEC(u16, u8, u8 *); static void BerryCrush_SetPaletteFadeParams(u8 *, bool8, u32, s8, u8, u8, u16); static int sub_8021450(struct BerryCrushGame *); @@ -243,7 +243,7 @@ static u32 sub_8024444(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1 static u32 sub_8024508(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1); static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1); -static EWRAM_DATA struct BerryCrushGame *gUnknown_02022C90 = NULL; +static EWRAM_DATA struct BerryCrushGame *gBerryCrushGame = NULL; static const u8 gUnknown_082F325C[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; static const u8 gUnknown_082F3264[] = { 0, 1, 2, 3, 5, 0, 0, 0 }; @@ -816,22 +816,21 @@ static const u8 gUnknown_082F4434[][4] = static const u8 gUnknown_082F4444[] = {5, 7, 9, 12}; static const u8 gUnknown_082F4448[] = {3, 7, 15, 31}; - -struct BerryCrushGame *sub_8020C00(void) +struct BerryCrushGame * GetBerryCrushGame(void) { - return gUnknown_02022C90; + return gBerryCrushGame; } -u32 sub_8020C0C(MainCallback callback) +u32 QuitBerryCrush(MainCallback callback) { - if (!gUnknown_02022C90) + if (!gBerryCrushGame) return 2; if (!callback) - callback = gUnknown_02022C90->unk0; + callback = gBerryCrushGame->unk0; - DestroyTask(gUnknown_02022C90->unkA); - FREE_AND_SET_NULL(gUnknown_02022C90); + DestroyTask(gBerryCrushGame->mainTask); + FREE_AND_SET_NULL(gBerryCrushGame); SetMainCallback2(callback); if (callback == CB2_ReturnToField) { @@ -868,8 +867,8 @@ void StartBerryCrush(MainCallback callback) return; } - gUnknown_02022C90 = AllocZeroed(sizeof(*gUnknown_02022C90)); - if (!gUnknown_02022C90) + gBerryCrushGame = AllocZeroed(sizeof(*gBerryCrushGame)); + if (!gBerryCrushGame) { SetMainCallback2(callback); Rfu.unk_10 = 0; @@ -878,110 +877,110 @@ void StartBerryCrush(MainCallback callback) return; } - gUnknown_02022C90->unk0 = callback; - gUnknown_02022C90->unk8 = multiplayerId; - gUnknown_02022C90->unk9 = playerCount; - sub_8020FC4(gUnknown_02022C90); - gUnknown_02022C90->unk12 = 1; - gUnknown_02022C90->unkE = 1; - gUnknown_02022C90->unkF = 6; - BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 1, -1, 0, 16, 0, 0); - sub_8022BEC(4, 1, gUnknown_02022C90->unk36); - SetMainCallback2(sub_8020F88); - gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); + gBerryCrushGame->unk0 = callback; + gBerryCrushGame->unk8 = multiplayerId; + gBerryCrushGame->unk9 = playerCount; + InitGame(gBerryCrushGame); + gBerryCrushGame->unk12 = 1; + gBerryCrushGame->unkE = 1; + gBerryCrushGame->unkF = 6; + BerryCrush_SetPaletteFadeParams(gBerryCrushGame->unk36, 1, -1, 0, 16, 0, 0); + sub_8022BEC(4, 1, gBerryCrushGame->unk36); + SetMainCallback2(MainCB); + gBerryCrushGame->mainTask = CreateTask(MainTask, 8); gTextFlags.autoScroll = 0; } -static void sub_8020D8C(void) +static void GetBerryFromBag(void) { if (gSpecialVar_ItemId < FIRST_BERRY_INDEX || gSpecialVar_ItemId > LAST_BERRY_INDEX + 1) gSpecialVar_ItemId = ITEM_CHERI_BERRY; else RemoveBagItem(gSpecialVar_ItemId, 1); - gUnknown_02022C90->unk68.as_four_players.others[gUnknown_02022C90->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX; - gUnknown_02022C90->unkE = 1; - gUnknown_02022C90->unkF = 9; - BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 0, -1, 0, 16, 0, 0); - sub_8022BEC(4, 1, gUnknown_02022C90->unk36); - gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); - SetMainCallback2(sub_8020F88); + gBerryCrushGame->unk68.as_four_players.others[gBerryCrushGame->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX; + gBerryCrushGame->unkE = 1; + gBerryCrushGame->unkF = 9; + BerryCrush_SetPaletteFadeParams(gBerryCrushGame->unk36, 0, -1, 0, 16, 0, 0); + sub_8022BEC(4, 1, gBerryCrushGame->unk36); + gBerryCrushGame->mainTask = CreateTask(MainTask, 8); + SetMainCallback2(MainCB); } -void sub_8020E1C(void) +static void InitMainTask(void) { - DestroyTask(gUnknown_02022C90->unkA); - ChooseBerryForMachine(sub_8020D8C); + DestroyTask(gBerryCrushGame->mainTask); + ChooseBerryForMachine(GetBerryFromBag); } -static void sub_8020E3C(void) +static void SetVBlankCB(void) { - SetVBlankCallback(sub_8020F74); + SetVBlankCallback(VBlankCB); } -void sub_8020E4C(void) +static void InitVBlankCB(void) { SetVBlankCallback(NULL); } -void sub_8020E58(void) +static void SaveResults(void) { u32 var0, var1; - var0 = gUnknown_02022C90->unk68.as_four_players.unk00.unk04; + var0 = gBerryCrushGame->unk68.as_four_players.unk00.unk04; var0 = Q_24_8(var0); var0 = MathUtil_Div32(var0, Q_24_8(60)); - var1 = gUnknown_02022C90->unk68.as_four_players.unk00.unk0A; + var1 = gBerryCrushGame->unk68.as_four_players.unk00.unk0A; var1 = Q_24_8(var1); var1 = MathUtil_Div32(var1, var0) & 0xFFFF; - gUnknown_02022C90->unk16 = var1; - switch (gUnknown_02022C90->unk9) + gBerryCrushGame->unk16 = var1; + switch (gBerryCrushGame->unk9) { case 2: - if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[0]) + if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[0]) { - gUnknown_02022C90->unk25_1 = 1; - gSaveBlock2Ptr->berryCrush.berryCrushResults[0] = gUnknown_02022C90->unk16; + gBerryCrushGame->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[0] = gBerryCrushGame->unk16; } break; case 3: - if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[1]) + if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[1]) { - gUnknown_02022C90->unk25_1 = 1; - gSaveBlock2Ptr->berryCrush.berryCrushResults[1] = gUnknown_02022C90->unk16; + gBerryCrushGame->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[1] = gBerryCrushGame->unk16; } break; case 4: - if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[2]) + if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[2]) { - gUnknown_02022C90->unk25_1 = 1; - gSaveBlock2Ptr->berryCrush.berryCrushResults[2] = gUnknown_02022C90->unk16; + gBerryCrushGame->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[2] = gBerryCrushGame->unk16; } break; case 5: - if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[3]) + if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[3]) { - gUnknown_02022C90->unk25_1 = 1; - gSaveBlock2Ptr->berryCrush.berryCrushResults[3] = gUnknown_02022C90->unk16; + gBerryCrushGame->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[3] = gBerryCrushGame->unk16; } break; } - gUnknown_02022C90->unk1C = gUnknown_02022C90->unk68.as_four_players.unk00.unk00; - if (GiveBerryPowder(gUnknown_02022C90->unk1C)) + gBerryCrushGame->unk1C = gBerryCrushGame->unk68.as_four_players.unk00.unk00; + if (GiveBerryPowder(gBerryCrushGame->unk1C)) return; - gUnknown_02022C90->unk25_0 = 1; + gBerryCrushGame->unk25_0 = 1; } -static void sub_8020F74(void) +static void VBlankCB(void) { TransferPlttBuffer(); LoadOam(); ProcessSpriteCopyRequests(); } -static void sub_8020F88(void) +static void MainCB(void) { RunTasks(); RunTextPrinters(); @@ -989,12 +988,12 @@ static void sub_8020F88(void) BuildOamBuffer(); } -static void sub_8020FA0(u8 taskId) +static void MainTask(u8 taskId) { - if (gUnknown_02022C90->unk4) - gUnknown_02022C90->unk4(gUnknown_02022C90, gUnknown_02022C90->unk36); + if (gBerryCrushGame->unk4) + gBerryCrushGame->unk4(gBerryCrushGame, gBerryCrushGame->unk36); - sub_8021450(gUnknown_02022C90); + sub_8021450(gBerryCrushGame); } #define PLAYER_UNK14(game, i) \ @@ -1003,11 +1002,11 @@ static void sub_8020FA0(u8 taskId) + offsetof(struct BerryCrushGame_68_x, unk30) \ + sizeof(struct BerryCrushGame_Player) * (i)) -void sub_8020FC4(struct BerryCrushGame *arg0) +static void InitGame(struct BerryCrushGame *arg0) { - u8 i; + u8 i = 0; - for (i = 0; i < arg0->unk9; i++) + for (; i < arg0->unk9; i++) StringCopy(PLAYER_UNK14(arg0, i), gLinkPlayers[i].name); for (; i < 5; i++) { @@ -1029,13 +1028,14 @@ void sub_8020FC4(struct BerryCrushGame *arg0) } } -int sub_802104C(void) +// TODO: Everything from here on is likely in a separate file. +s32 InitBerryCrushDisplay(void) { - struct BerryCrushGame *var0 = sub_8020C00(); - if (!var0) + struct BerryCrushGame *game = GetBerryCrushGame(); + if (!game) return -1; - switch (var0->unkC) + switch (game->unkC) { case 0: SetVBlankCallback(NULL); @@ -1057,9 +1057,9 @@ int sub_802104C(void) case 3: ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_082F32C8, ARRAY_COUNT(gUnknown_082F32C8)); - SetBgTilemapBuffer(1, var0->unk1C0); - SetBgTilemapBuffer(2, var0->unk21C0); - SetBgTilemapBuffer(3, var0->unk31C0); + SetBgTilemapBuffer(1, game->unk1C0); + SetBgTilemapBuffer(2, game->unk21C0); + SetBgTilemapBuffer(3, game->unk31C0); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(2, 0, 0); @@ -1088,8 +1088,8 @@ int sub_802104C(void) InitStandardTextBoxWindows(); InitTextBoxGfxAndPrinters(); - sub_8022588(var0); - sub_8022600(var0); + sub_8022588(game); + sub_8022600(game); gPaletteFade.bufferTransferDisabled = TRUE; break; case 7: @@ -1097,7 +1097,7 @@ int sub_802104C(void) CopyToBgTilemapBuffer(1, gBerryCrushGrinderTopTilemap, 0, 0); CopyToBgTilemapBuffer(2, gBerryCrushContainerCapTilemap, 0, 0); CopyToBgTilemapBuffer(3, gBerryCrushBackgroundTilemap, 0, 0); - sub_80226D0(var0); + sub_80226D0(game); CopyBgTilemapBufferToVram(1); CopyBgTilemapBufferToVram(2); CopyBgTilemapBufferToVram(3); @@ -1105,7 +1105,7 @@ int sub_802104C(void) case 8: LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); - sub_8022730(var0); + sub_8022730(game); SetGpuReg(REG_OFFSET_BG1VOFS, -gSpriteCoordOffsetY); ChangeBgX(1, 0, 0); ChangeBgY(1, 0, 0); @@ -1118,18 +1118,18 @@ int sub_802104C(void) ShowBg(2); ShowBg(3); SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); - sub_8020E3C(); - var0->unkC = 0; + SetVBlankCB(); + game->unkC = 0; return 1; } - var0->unkC++; + game->unkC++; return 0; } int sub_802130C(void) { - struct BerryCrushGame *var0 = sub_8020C00(); + struct BerryCrushGame *var0 = GetBerryCrushGame(); if (!var0) return -1; @@ -1960,7 +1960,7 @@ void sub_8022B28(struct Sprite *sprite) void sub_8022BEC(u16 r5, u8 r4, u8 *r7) { - struct BerryCrushGame *r6 = sub_8020C00(); + struct BerryCrushGame *r6 = GetBerryCrushGame(); if (r5 > 25) r5 = 0; @@ -2097,7 +2097,7 @@ static u32 sub_8022D14(struct BerryCrushGame *r7, u8 *r5) static u32 sub_8022E1C(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) { - if (sub_802104C() != 0) + if (InitBerryCrushDisplay() != 0) sub_8022BEC(r4->unkE, 0, r4->unk36); return 0; } @@ -2155,7 +2155,7 @@ static u32 sub_8022EAC(struct BerryCrushGame *r4, u8 *r5) static u32 sub_8022F04(struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) { r0->unk4 = NULL; - SetMainCallback2(sub_8020E1C); + SetMainCallback2(InitMainTask); return 0; } @@ -2942,7 +2942,7 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 r7->unk10 = 0; break; case 7: - sub_8020E58(); + SaveResults(); sub_8022BEC(18, 1, NULL); r7->unk12 = 11; r7->unkC = 0; @@ -3210,7 +3210,7 @@ static u32 sub_8024508(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1 static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) { - sub_8020C0C(NULL); + QuitBerryCrush(NULL); return 0; } From f952144922b23d258c6b98ce3da79276d5c1e643 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sun, 13 Sep 2020 03:02:41 -0400 Subject: [PATCH 03/15] party_menu fakematch fix --- src/party_menu.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/party_menu.c b/src/party_menu.c index e509ef6e0..39f74e58d 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1964,19 +1964,17 @@ static u8 CanMonLearnTMTutor(struct Pokemon *mon, u16 item, u8 tutor) if (item >= ITEM_TM01_FOCUS_PUNCH) { - if (CanMonLearnTMHM(mon, item - ITEM_TM01_FOCUS_PUNCH)) - move = ItemIdToBattleMoveId(item); - else + if (!CanMonLearnTMHM(mon, item - ITEM_TM01_FOCUS_PUNCH)) return CANNOT_LEARN_MOVE; - do {} while (0); // :morphon: - } - else if (CanLearnTutorMove(GetMonData(mon, MON_DATA_SPECIES), tutor) == FALSE) - { - return CANNOT_LEARN_MOVE; + else + move = ItemIdToBattleMoveId(item); } else { - move = GetTutorMove(tutor); + if (!CanLearnTutorMove(GetMonData(mon, MON_DATA_SPECIES), tutor)) + return CANNOT_LEARN_MOVE; + else + move = GetTutorMove(tutor); } if (MonKnowsMove(mon, move) == TRUE) From 327dd877b5b9cd76fcd4747dea755395aacc6157 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sun, 13 Sep 2020 03:47:12 -0400 Subject: [PATCH 04/15] use_pokeblock: fakematch fix. I am beginning to suspect that we should be using the gflib DMA macros everywhere wherever possible. --- src/use_pokeblock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index ebb237d54..4a70e9b44 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -1,5 +1,6 @@ #include "global.h" #include "main.h" +#include "dma3.h" #include "pokeblock.h" #include "malloc.h" #include "decompress.h" @@ -1240,8 +1241,7 @@ static void UpdateMonPic(u8 loadId) } else { - do {} while(0); // Only needed to match, feel free to remove. - DmaCopy16Defvars(3, sMenu->partySheets[loadId], sMenu->curMonTileStart, 0x800); + Dma3CopyLarge16_(sMenu->partySheets[loadId], sMenu->curMonTileStart, 0x800); LoadPalette(sMenu->partyPalettes[loadId], sMenu->curMonPalette, 32); } } From 171154a0975b1c734b5b2069f1bdb3ca2bab26f2 Mon Sep 17 00:00:00 2001 From: Kaz Date: Wed, 16 Sep 2020 19:27:55 -0400 Subject: [PATCH 05/15] Convert to -g; will be required for eliminating fakematches. --- Makefile | 4 ++-- src/battle_message.c | 3 +-- src/battle_script_commands.c | 9 ++------- src/battle_setup.c | 3 +-- src/berry_crush.c | 22 +++++++++++----------- src/event_object_movement.c | 9 +++------ src/fldeff_cut.c | 3 +-- src/pokenav_match_call_data.c | 13 +++---------- 8 files changed, 24 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index ca282d07e..5484fb26e 100644 --- a/Makefile +++ b/Makefile @@ -63,13 +63,13 @@ ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN) ifeq ($(MODERN),0) CC1 := tools/agbcc/bin/agbcc$(EXE) -override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm +override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm -g ROM := pokeemerald.gba OBJ_DIR := build/emerald LIBPATH := -L ../../tools/agbcc/lib else CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet -override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mcpu=arm7tdmi -fno-toplevel-reorder -Wno-pointer-to-int-cast +override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mcpu=arm7tdmi -fno-toplevel-reorder -Wno-pointer-to-int-cast -g ROM := pokeemerald_modern.gba OBJ_DIR := build/modern LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" diff --git a/src/battle_message.c b/src/battle_message.c index c004665d7..ee1616b5e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2288,8 +2288,7 @@ static const u8* TryGetStatusString(u8 *src) statusPtr = status; for (i = 0; i < 8; i++) { - if (*src == EOS) - break; + if (*src == EOS) break; // one line required to match -g *statusPtr = *src; src++; statusPtr++; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fca2b3879..c2c4e6c41 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5035,14 +5035,9 @@ static void Cmd_openpartyscreen(void) hitmarkerFaintBits = gHitMarker >> 0x1C; gBattlerFainted = 0; - while (1) - { - if (gBitTable[gBattlerFainted] & hitmarkerFaintBits) - break; - if (gBattlerFainted >= gBattlersCount) - break; + while (!(gBitTable[gBattlerFainted] & hitmarkerFaintBits) + && gBattlerFainted < gBattlersCount) gBattlerFainted++; - } if (gBattlerFainted == gBattlersCount) gBattlescriptCurrInstr = jumpPtr; diff --git a/src/battle_setup.c b/src/battle_setup.c index 3c20d9ffe..8b02e1f42 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -1565,8 +1565,7 @@ static s32 TrainerIdToRematchTableId(const struct RematchTrainer *table, u16 tra { for (j = 0; j < REMATCHES_COUNT; j++) { - if (table[i].trainerIds[j] == 0) - break; + if (table[i].trainerIds[j] == 0) break; // one line required to match -g if (table[i].trainerIds[j] == trainerId) return i; } diff --git a/src/berry_crush.c b/src/berry_crush.c index 744389ba7..3554644f2 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -202,7 +202,7 @@ struct BerryCrushGame static void VBlankCB(void); static void MainCB(void); static void MainTask(u8); -static void InitGame(struct BerryCrushGame *); +static void ParseName_Options(struct BerryCrushGame *); void sub_8022BEC(u16, u8, u8 *); static void BerryCrush_SetPaletteFadeParams(u8 *, bool8, u32, s8, u8, u8, u16); static int sub_8021450(struct BerryCrushGame *); @@ -880,7 +880,7 @@ void StartBerryCrush(MainCallback callback) gBerryCrushGame->unk0 = callback; gBerryCrushGame->unk8 = multiplayerId; gBerryCrushGame->unk9 = playerCount; - InitGame(gBerryCrushGame); + ParseName_Options(gBerryCrushGame); gBerryCrushGame->unk12 = 1; gBerryCrushGame->unkE = 1; gBerryCrushGame->unkF = 6; @@ -907,23 +907,23 @@ static void GetBerryFromBag(void) SetMainCallback2(MainCB); } -static void InitMainTask(void) +static void BerryCrush_SetupMainTask(void) { DestroyTask(gBerryCrushGame->mainTask); ChooseBerryForMachine(GetBerryFromBag); } -static void SetVBlankCB(void) +static void BerryCrush_SetVBlankCB(void) { SetVBlankCallback(VBlankCB); } -static void InitVBlankCB(void) +static void BerryCrush_InitVBlankCB(void) { SetVBlankCallback(NULL); } -static void SaveResults(void) +static void BerryCrush_SaveResults(void) { u32 var0, var1; @@ -1002,7 +1002,7 @@ static void MainTask(u8 taskId) + offsetof(struct BerryCrushGame_68_x, unk30) \ + sizeof(struct BerryCrushGame_Player) * (i)) -static void InitGame(struct BerryCrushGame *arg0) +static void ParseName_Options(struct BerryCrushGame *arg0) { u8 i = 0; @@ -1028,7 +1028,7 @@ static void InitGame(struct BerryCrushGame *arg0) } } -// TODO: Everything from here on is likely in a separate file. +// TODO: Everything from here on is likely in separate files. s32 InitBerryCrushDisplay(void) { struct BerryCrushGame *game = GetBerryCrushGame(); @@ -1118,7 +1118,7 @@ s32 InitBerryCrushDisplay(void) ShowBg(2); ShowBg(3); SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); - SetVBlankCB(); + BerryCrush_SetVBlankCB(); game->unkC = 0; return 1; } @@ -2155,7 +2155,7 @@ static u32 sub_8022EAC(struct BerryCrushGame *r4, u8 *r5) static u32 sub_8022F04(struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) { r0->unk4 = NULL; - SetMainCallback2(InitMainTask); + SetMainCallback2(BerryCrush_SetupMainTask); return 0; } @@ -2942,7 +2942,7 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 r7->unk10 = 0; break; case 7: - SaveResults(); + BerryCrush_SaveResults(); sub_8022BEC(18, 1, NULL); r7->unk12 = 11; r7->unkC = 0; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 68f873446..0859fb32f 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1295,22 +1295,19 @@ static bool8 GetAvailableObjectEventId(u16 localId, u8 mapNum, u8 mapGroup, u8 * { u8 i = 0; - for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + for (i = 0; i < OBJECT_EVENTS_COUNT && gObjectEvents[i].active; i++) { - if (!gObjectEvents[i].active) - break; if (gObjectEvents[i].localId == localId && gObjectEvents[i].mapNum == mapNum && gObjectEvents[i].mapGroup == mapGroup) return TRUE; } if (i >= OBJECT_EVENTS_COUNT) return TRUE; *objectEventId = i; - do + for (; i < OBJECT_EVENTS_COUNT; i++) { if (gObjectEvents[i].active && gObjectEvents[i].localId == localId && gObjectEvents[i].mapNum == mapNum && gObjectEvents[i].mapGroup == mapGroup) return TRUE; - i++; - } while (i < OBJECT_EVENTS_COUNT); + } return FALSE; } diff --git a/src/fldeff_cut.c b/src/fldeff_cut.c index 991617713..db9eb4268 100644 --- a/src/fldeff_cut.c +++ b/src/fldeff_cut.c @@ -228,8 +228,7 @@ bool8 SetUpFieldMove_Cut(void) tileCuttable = TRUE; for (j = 0; j < 2; ++j) { - if (sHyperCutStruct[i].unk2[j] == 0) - break; + if (sHyperCutStruct[i].unk2[j] == 0) break; // one line required to match -g if (cutTiles[(u8)(sHyperCutStruct[i].unk2[j] - 1)] == FALSE) { tileCuttable = FALSE; diff --git a/src/pokenav_match_call_data.c b/src/pokenav_match_call_data.c index 91dbe4005..6610dcb80 100644 --- a/src/pokenav_match_call_data.c +++ b/src/pokenav_match_call_data.c @@ -1100,16 +1100,9 @@ const u8 *MatchCall_GetOverrideFlavorText(u32 idx, u32 offset) { if (sCheckPageOverrides[i].idx == idx) { - while (1) - { - if (i + 1 >= ARRAY_COUNT(sCheckPageOverrides)) - break; - if (sCheckPageOverrides[i + 1].idx != idx) - break; - if (!FlagGet(sCheckPageOverrides[i + 1].flag)) - break; - i++; - } + for (; i + 1 < ARRAY_COUNT(sCheckPageOverrides) && + sCheckPageOverrides[i + 1].idx == idx && + FlagGet(sCheckPageOverrides[i + 1].flag); i++); return sCheckPageOverrides[i].flavorTexts[offset]; } } From 5a70f99e16c5c2bb1bd32672dde581054990fae5 Mon Sep 17 00:00:00 2001 From: Kaz Date: Wed, 16 Sep 2020 21:39:44 -0400 Subject: [PATCH 06/15] battle_script_commands.c: Eliminate the last nonmatching (swapped expressions). --- src/battle_script_commands.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c2c4e6c41..14866bbca 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4666,19 +4666,16 @@ static void Cmd_jumpifcantswitch(void) if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - #ifndef NONMATCHING - asm("":::"r5"); - #endif // NONMATCHING if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) party = gEnemyParty; else party = gPlayerParty; - i = 0; + lastMonId = 0; if (gActiveBattler & 2) - i = 3; + lastMonId = 3; - for (lastMonId = i + 3; i < lastMonId; i++) + for (i = lastMonId; i < lastMonId + 3; i++) { if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) @@ -4687,7 +4684,7 @@ static void Cmd_jumpifcantswitch(void) break; } - if (i == lastMonId) + if (i == lastMonId + 3) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); else gBattlescriptCurrInstr += 6; @@ -4700,18 +4697,18 @@ static void Cmd_jumpifcantswitch(void) { party = gPlayerParty; - i = 0; + lastMonId = 0; if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) - i = 3; + lastMonId = 3; } else { party = gEnemyParty; if (gActiveBattler == 1) - i = 0; + lastMonId = 0; else - i = 3; + lastMonId = 3; } } else @@ -4721,12 +4718,12 @@ static void Cmd_jumpifcantswitch(void) else party = gPlayerParty; - i = 0; + lastMonId = 0; if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) - i = 3; + lastMonId = 3; } - for (lastMonId = i + 3; i < lastMonId; i++) + for (i = lastMonId; i < lastMonId + 3; i++) { if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) @@ -4735,7 +4732,7 @@ static void Cmd_jumpifcantswitch(void) break; } - if (i == lastMonId) + if (i == lastMonId + 3) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); else gBattlescriptCurrInstr += 6; @@ -4744,11 +4741,11 @@ static void Cmd_jumpifcantswitch(void) { party = gEnemyParty; - i = 0; + lastMonId = 0; if (gActiveBattler == B_POSITION_OPPONENT_RIGHT) - i = 3; + lastMonId = 3; - for (lastMonId = i + 3; i < lastMonId; i++) + for (i = lastMonId; i < lastMonId + 3; i++) { if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) @@ -4757,7 +4754,7 @@ static void Cmd_jumpifcantswitch(void) break; } - if (i == lastMonId) + if (i == lastMonId + 3) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); else gBattlescriptCurrInstr += 6; From c724f2b8099645daf85884895047e60e23368e4b Mon Sep 17 00:00:00 2001 From: Kaz Date: Wed, 16 Sep 2020 22:01:45 -0400 Subject: [PATCH 07/15] battle_ai_script_commands.c: -g fixes the fakematch. --- src/battle_ai_script_commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 032e5f407..5aef7a04f 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -616,8 +616,8 @@ static void RecordLastUsedMoveByTarget(void) { if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; - if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] != gLastMoves[gBattlerTarget] // HACK: This redundant condition is a hack to make the asm match. - && BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == MOVE_NONE) + + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == MOVE_NONE) { BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] = gLastMoves[gBattlerTarget]; break; From 1404cf3330b49e217c317602194e52d9c49bb12b Mon Sep 17 00:00:00 2001 From: Kaz Date: Thu, 17 Sep 2020 18:24:11 -0400 Subject: [PATCH 08/15] field_player_avatar.c: Fix TryInterruptObjectEventSpecialAnim fakematch. --- include/global.fieldmap.h | 13 ++++--------- src/event_object_movement.c | 24 ++++++++++++------------ src/field_player_avatar.c | 10 +++------- src/overworld.c | 34 +++++++++++++++++++--------------- src/trainer_see.c | 12 ++++++------ 5 files changed, 44 insertions(+), 49 deletions(-) diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 4598e87fa..2729d2a20 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -195,15 +195,10 @@ struct ObjectEvent /*0x0C*/ struct Coords16 initialCoords; /*0x10*/ struct Coords16 currentCoords; /*0x14*/ struct Coords16 previousCoords; - /*0x18*/ u8 facingDirection:4; // current direction? - /*0x18*/ u8 movementDirection:4; - /*0x19*/ union __attribute__((packed)) { - u8 as_byte; - struct __attribute__((packed)) { - u8 x:4; - u8 y:4; - } ALIGNED(1) as_nybbles; - } ALIGNED(1) range; + /*0x18*/ u16 facingDirection:4; // current direction? + u16 movementDirection:4; + u16 rangeX:4; + u16 rangeY:4; /*0x1A*/ u8 fieldEffectSpriteId; /*0x1B*/ u8 warpArrowSpriteId; /*0x1C*/ u8 movementActionId; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 0859fb32f..f97c9bfa0 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1232,8 +1232,8 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->previousCoords.y = y; objectEvent->currentElevation = template->elevation; objectEvent->previousElevation = template->elevation; - objectEvent->range.as_nybbles.x = template->movementRangeX; - objectEvent->range.as_nybbles.y = template->movementRangeY; + objectEvent->rangeX = template->movementRangeX; + objectEvent->rangeY = template->movementRangeY; objectEvent->trainerType = template->trainerType; objectEvent->mapNum = mapNum; //redundant, but needed to match objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId; @@ -1242,13 +1242,13 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, SetObjectEventDynamicGraphicsId(objectEvent); if (gRangedMovementTypes[objectEvent->movementType]) { - if (objectEvent->range.as_nybbles.x == 0) + if (objectEvent->rangeX == 0) { - objectEvent->range.as_nybbles.x++; + objectEvent->rangeX++; } - if (objectEvent->range.as_nybbles.y == 0) + if (objectEvent->rangeY == 0) { - objectEvent->range.as_nybbles.y++; + objectEvent->rangeY++; } } return objectEventId; @@ -4755,19 +4755,19 @@ static bool8 IsCoordOutsideObjectEventMovementRange(struct ObjectEvent *objectEv s16 top; s16 bottom; - if (objectEvent->range.as_nybbles.x != 0) + if (objectEvent->rangeX != 0) { - left = objectEvent->initialCoords.x - objectEvent->range.as_nybbles.x; - right = objectEvent->initialCoords.x + objectEvent->range.as_nybbles.x; + left = objectEvent->initialCoords.x - objectEvent->rangeX; + right = objectEvent->initialCoords.x + objectEvent->rangeX; if (left > x || right < x) { return TRUE; } } - if (objectEvent->range.as_nybbles.y != 0) + if (objectEvent->rangeY != 0) { - top = objectEvent->initialCoords.y - objectEvent->range.as_nybbles.y; - bottom = objectEvent->initialCoords.y + objectEvent->range.as_nybbles.y; + top = objectEvent->initialCoords.y - objectEvent->rangeY; + bottom = objectEvent->initialCoords.y + objectEvent->rangeY; if (top > y || bottom < y) { return TRUE; diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index e907af5b9..a47ee4a93 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -343,10 +343,6 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys) static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEvent, u8 direction) { - u8 r5 = direction; - u8 r6 = direction; - r6++; r6--; - if (ObjectEventIsMovementOverridden(playerObjEvent) && !ObjectEventClearHeldMovementIfFinished(playerObjEvent)) { @@ -358,13 +354,13 @@ static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEve return TRUE; } - if (playerObjEvent->movementDirection != r5) + if (playerObjEvent->movementDirection != direction) { ObjectEventClearHeldMovement(playerObjEvent); return FALSE; } - if (!sub_808B028(r6)) + if (!sub_808B028(direction)) { ObjectEventClearHeldMovement(playerObjEvent); return FALSE; @@ -2086,7 +2082,7 @@ static void sub_808D094(u8 taskId) sub_808D074(object->facingDirection); data[1] = 0; data[2] = 1; - data[3] = (u16)(sprite->pos1.y + sprite->pos2.y) * 16; + data[3] = (u16)(sprite->pos1.y + sprite->pos2.y) << 4; sprite->pos2.y = 0; CameraObjectReset2(); object->fixedPriority = TRUE; diff --git a/src/overworld.c b/src/overworld.c index 2d798f2ec..ee70b3b92 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2909,7 +2909,11 @@ static void ZeroObjectEvent(struct ObjectEvent *objEvent) memset(objEvent, 0, sizeof(struct ObjectEvent)); } -static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4) +#define linkGender(obj) obj->singleMovementActive +// not even one can reference *byte* aligned bitfield members... +#define linkDirection(obj) ((u8*)obj)[offsetof(typeof(*obj), fieldEffectSpriteId) - 1] // -> rangeX + +static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 gender) { u8 objEventId = GetFirstInactiveObjectEventId(); struct LinkPlayerObjectEvent *linkPlayerObjEvent = &gLinkPlayerObjectEvents[linkPlayerId]; @@ -2924,8 +2928,8 @@ static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4) linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FREE; objEvent->active = 1; - objEvent->singleMovementActive = a4; - objEvent->range.as_byte = 2; + linkGender(objEvent) = gender; + linkDirection(objEvent) = 2; objEvent->spriteId = 64; InitLinkPlayerObjectEventPos(objEvent, x, y); @@ -2948,7 +2952,7 @@ static void sub_80877DC(u8 linkPlayerId, u8 a2) { u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId; struct ObjectEvent *objEvent = &gObjectEvents[objEventId]; - objEvent->range.as_byte = a2; + linkDirection(objEvent) = a2; } } @@ -2983,7 +2987,7 @@ static u8 GetLinkPlayerFacingDirection(u8 linkPlayerId) { u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId; struct ObjectEvent *objEvent = &gObjectEvents[objEventId]; - return objEvent->range.as_byte; + return linkDirection(objEvent); } static u8 GetLinkPlayerElevation(u8 linkPlayerId) @@ -3068,10 +3072,10 @@ static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayer { s16 x, y; - objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte); - ObjectEventMoveDestCoords(objEvent, objEvent->range.as_byte, &x, &y); + linkDirection(objEvent) = FlipVerticalAndClearForced(a3, linkDirection(objEvent)); + ObjectEventMoveDestCoords(objEvent, linkDirection(objEvent), &x, &y); - if (LinkPlayerDetectCollision(linkPlayerObjEvent->objEventId, objEvent->range.as_byte, x, y)) + if (LinkPlayerDetectCollision(linkPlayerObjEvent->objEventId, linkDirection(objEvent), x, y)) { return FALSE; } @@ -3086,7 +3090,7 @@ static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayer static bool8 FacingHandler_ForcedFacingChange(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3) { - objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte); + linkDirection(objEvent) = FlipVerticalAndClearForced(a3, linkDirection(objEvent)); return FALSE; } @@ -3100,7 +3104,7 @@ static void MovementStatusHandler_TryAdvanceScript(struct LinkPlayerObjectEvent { objEvent->directionSequenceIndex--; linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FROZEN; - MoveCoords(objEvent->range.as_byte, &objEvent->initialCoords.x, &objEvent->initialCoords.y); + MoveCoords(linkDirection(objEvent), &objEvent->initialCoords.x, &objEvent->initialCoords.y); if (!objEvent->directionSequenceIndex) { ShiftStillObjectEventCoords(objEvent); @@ -3161,14 +3165,14 @@ static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion) { case VERSION_FIRE_RED: case VERSION_LEAF_GREEN: - objEvent->spriteId = AddPseudoObjectEvent(GetFRLGAvatarGraphicsIdByGender(objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0); + objEvent->spriteId = AddPseudoObjectEvent(GetFRLGAvatarGraphicsIdByGender(linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0); break; case VERSION_RUBY: case VERSION_SAPPHIRE: - objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0); + objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0); break; case VERSION_EMERALD: - objEvent->spriteId = AddPseudoObjectEvent(GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0); + objEvent->spriteId = AddPseudoObjectEvent(GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0); break; } @@ -3189,9 +3193,9 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation); if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) - StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte)); + StartSpriteAnim(sprite, GetFaceDirectionAnimNum(linkDirection(objEvent))); else - StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte)); + StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(linkDirection(objEvent))); UpdateObjectEventSpriteVisibility(sprite, 0); if (objEvent->triggerGroundEffectsOnMove) diff --git a/src/trainer_see.c b/src/trainer_see.c index c37f37262..f2024e37c 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -377,15 +377,15 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap } // preserve mapobj_unk_19 before clearing. - unk19_temp = trainerObj->range.as_nybbles.x; - unk19b_temp = trainerObj->range.as_nybbles.y; - trainerObj->range.as_nybbles.x = 0; - trainerObj->range.as_nybbles.y = 0; + unk19_temp = trainerObj->rangeX; + unk19b_temp = trainerObj->rangeY; + trainerObj->rangeX = 0; + trainerObj->rangeY = 0; collision = GetCollisionAtCoords(trainerObj, x, y, direction); - trainerObj->range.as_nybbles.x = unk19_temp; - trainerObj->range.as_nybbles.y = unk19b_temp; + trainerObj->rangeX = unk19_temp; + trainerObj->rangeY = unk19b_temp; if (collision == 4) return approachDistance; From 847878eae9a9f0ac4a722c27c1cdf1a2d3ff1d67 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sat, 19 Sep 2020 13:37:24 -0400 Subject: [PATCH 09/15] battle_gfx_sfx_util.c: Very annoying fakematch fix. daycare.c: -g eliminates the need for the brace hack. battle_transition.c: Fix Phase2_Ripple_Func2...? --- include/battle.h | 6 +++++- src/battle_anim_effects_3.c | 2 +- src/battle_gfx_sfx_util.c | 42 +++++++++++++++++------------------- src/battle_intro.c | 4 ++-- src/battle_main.c | 2 +- src/battle_transition.c | 5 +---- src/contest.c | 4 ++-- src/contest_painting.c | 8 +++---- src/contest_util.c | 8 +++---- src/daycare.c | 3 --- src/egg_hatch.c | 2 +- src/evolution_scene.c | 10 ++++----- src/pokeblock_feed.c | 2 +- src/pokemon.c | 4 ++-- src/pokemon_summary_screen.c | 8 +++---- src/trade.c | 8 +++---- 16 files changed, 57 insertions(+), 61 deletions(-) diff --git a/include/battle.h b/include/battle.h index 5a04c1eec..0f7a262ce 100644 --- a/include/battle.h +++ b/include/battle.h @@ -584,7 +584,11 @@ struct BattleSpriteData struct MonSpritesGfx { void* firstDecompressed; // ptr to the decompressed sprite of the first pokemon - void* sprites[4]; + union + { + void* ptr[4]; + u8* byte[4]; + } sprites; struct SpriteTemplate templates[4]; struct SpriteFrameImage field_74[4][4]; u8 field_F4[0x80]; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 58d335197..4ba2ad1f1 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -2291,7 +2291,7 @@ void AnimTask_TransformMon(u8 taskId) else position = GetBattlerPosition(gBattleAnimAttacker); - src = gMonSpritesGfxPtr->sprites[position] + (gBattleMonForms[gBattleAnimAttacker] << 11); + src = gMonSpritesGfxPtr->sprites.ptr[position] + (gBattleMonForms[gBattleAnimAttacker] << 11); dest = animBg.bgTiles; CpuCopy32(src, dest, 0x800); LoadBgTiles(1, animBg.bgTiles, 0x800, animBg.tilesOffset); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index e3e63f0e8..58b5d8228 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -6,6 +6,7 @@ #include "constants/battle_anim.h" #include "battle_interface.h" #include "main.h" +#include "dma3.h" #include "malloc.h" #include "graphics.h" #include "random.h" @@ -568,7 +569,7 @@ void BattleLoadOpponentMonSpriteGfx(struct Pokemon *mon, u8 battlerId) otId = GetMonData(mon, MON_DATA_OT_ID); position = GetBattlerPosition(battlerId); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], species, currentPersonality); paletteOffset = 0x100 + battlerId * 16; @@ -624,13 +625,13 @@ void BattleLoadPlayerMonSpriteGfx(struct Pokemon *mon, u8 battlerId) if (sub_80688F8(1, battlerId) == 1 || gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) { HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], species, currentPersonality); } else { HandleLoadSpecialPokePic(&gMonBackPicTable[species], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], species, currentPersonality); } @@ -672,7 +673,7 @@ void DecompressTrainerFrontPic(u16 frontPicId, u8 battlerId) { u8 position = GetBattlerPosition(battlerId); DecompressPicFromTable_2(&gTrainerFrontPicTable[frontPicId], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], SPECIES_NONE); LoadCompressedSpritePalette(&gTrainerFrontPicPaletteTable[frontPicId]); } @@ -681,7 +682,7 @@ void DecompressTrainerBackPic(u16 backPicId, u8 battlerId) { u8 position = GetBattlerPosition(battlerId); DecompressPicFromTable_2(&gTrainerBackPicTable[backPicId], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], SPECIES_NONE); LoadCompressedPalette(gTrainerBackPicPaletteTable[backPicId].data, 0x100 + 16 * battlerId, 0x20); @@ -921,7 +922,7 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform otId = gContestResources->moveAnim->otId; HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[0], + gMonSpritesGfxPtr->sprites.ptr[0], targetSpecies, gContestResources->moveAnim->targetPersonality); } @@ -940,7 +941,7 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], targetSpecies, gTransformedPersonalities[battlerAtk]); } @@ -950,13 +951,13 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[position], + gMonSpritesGfxPtr->sprites.ptr[position], targetSpecies, gTransformedPersonalities[battlerAtk]); } } - src = gMonSpritesGfxPtr->sprites[position]; + src = gMonSpritesGfxPtr->sprites.ptr[position]; dst = (void *)(OBJ_VRAM0 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); DmaCopy32(3, src, dst, 0x800); paletteOffset = 0x100 + battlerAtk * 16; @@ -997,18 +998,15 @@ void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite) position = GetBattlerPosition(battlerId); if (IsContest()) - LZDecompressVram(gSubstituteDollTilemap, gMonSpritesGfxPtr->sprites[position]); + LZDecompressVram(gSubstituteDollTilemap, gMonSpritesGfxPtr->sprites.ptr[position]); else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - LZDecompressVram(gSubstituteDollGfx, gMonSpritesGfxPtr->sprites[position]); + LZDecompressVram(gSubstituteDollGfx, gMonSpritesGfxPtr->sprites.ptr[position]); else - LZDecompressVram(gSubstituteDollTilemap, gMonSpritesGfxPtr->sprites[position]); + LZDecompressVram(gSubstituteDollTilemap, gMonSpritesGfxPtr->sprites.ptr[position]); for (i = 1; i < 4; i++) { - u8 (*ptr)[4][0x800] = gMonSpritesGfxPtr->sprites[position]; - ptr++;ptr--; // Needed to match. - - DmaCopy32Defvars(3, (*ptr)[0], (*ptr)[i], 0x800); + Dma3CopyLarge32_(gMonSpritesGfxPtr->sprites.ptr[position], &gMonSpritesGfxPtr->sprites.byte[position][0x800 * i], 0x800); } palOffset = (battlerId * 16) + 0x100; @@ -1245,12 +1243,12 @@ void AllocateMonSpritesGfx(void) for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - gMonSpritesGfxPtr->sprites[i] = gMonSpritesGfxPtr->firstDecompressed + (i * 0x2000); + gMonSpritesGfxPtr->sprites.ptr[i] = gMonSpritesGfxPtr->firstDecompressed + (i * 0x2000); *(gMonSpritesGfxPtr->templates + i) = gUnknown_08329D98[i]; for (j = 0; j < 4; j++) { - gMonSpritesGfxPtr->field_74[i][j].data = gMonSpritesGfxPtr->sprites[i] + (j * 0x800); + gMonSpritesGfxPtr->field_74[i][j].data = gMonSpritesGfxPtr->sprites.ptr[i] + (j * 0x800); gMonSpritesGfxPtr->field_74[i][j].size = 0x800; } @@ -1272,10 +1270,10 @@ void FreeMonSpritesGfx(void) FREE_AND_SET_NULL(gMonSpritesGfxPtr->barFontGfx); FREE_AND_SET_NULL(gMonSpritesGfxPtr->firstDecompressed); - gMonSpritesGfxPtr->sprites[0] = NULL; - gMonSpritesGfxPtr->sprites[1] = NULL; - gMonSpritesGfxPtr->sprites[2] = NULL; - gMonSpritesGfxPtr->sprites[3] = NULL; + gMonSpritesGfxPtr->sprites.ptr[0] = NULL; + gMonSpritesGfxPtr->sprites.ptr[1] = NULL; + gMonSpritesGfxPtr->sprites.ptr[2] = NULL; + gMonSpritesGfxPtr->sprites.ptr[3] = NULL; FREE_AND_SET_NULL(gMonSpritesGfxPtr); } diff --git a/src/battle_intro.c b/src/battle_intro.c index 6964428a3..36ff325f5 100644 --- a/src/battle_intro.c +++ b/src/battle_intro.c @@ -586,7 +586,7 @@ void sub_8118FBC(int bgId, u8 arg1, u8 arg2, u8 battlerPosition, u8 arg4, u8 *ar int i, j; u8 battler = GetBattlerAtPosition(battlerPosition); int offset = tilesOffset; - CpuCopy16(gMonSpritesGfxPtr->sprites[battlerPosition] + BG_SCREEN_SIZE * gBattleMonForms[battler], arg5, BG_SCREEN_SIZE); + CpuCopy16(gMonSpritesGfxPtr->sprites.ptr[battlerPosition] + BG_SCREEN_SIZE * gBattleMonForms[battler], arg5, BG_SCREEN_SIZE); LoadBgTiles(bgId, arg5, 0x1000, tilesOffset); for (i = arg2; i < arg2 + 8; i++) { @@ -604,7 +604,7 @@ void unref_sub_8119094(u8 arg0, u8 arg1, u8 battlerPosition, u8 arg3, u8 arg4, u { int i, j, offset; - DmaCopy16(3, gMonSpritesGfxPtr->sprites[battlerPosition] + BG_SCREEN_SIZE * arg3, (void *)BG_SCREEN_ADDR(0) + arg5, BG_SCREEN_SIZE); + DmaCopy16(3, gMonSpritesGfxPtr->sprites.ptr[battlerPosition] + BG_SCREEN_SIZE * arg3, (void *)BG_SCREEN_ADDR(0) + arg5, BG_SCREEN_SIZE); offset = (arg5 >> 5) - (arg7 << 9); for (i = arg1; i < arg1 + 8; i++) { diff --git a/src/battle_main.c b/src/battle_main.c index bf0fdc1aa..f0fedbd13 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2762,7 +2762,7 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite) } else // Erase bottom part of the sprite to create a smooth illusion of mon falling down. { - u8 *dst = (u8 *)gMonSpritesGfxPtr->sprites[GetBattlerPosition(sprite->sBattler)] + (gBattleMonForms[sprite->sBattler] << 11) + (sprite->data[3] << 8); + u8* dst = gMonSpritesGfxPtr->sprites.byte[GetBattlerPosition(sprite->sBattler)] + (gBattleMonForms[sprite->sBattler] << 11) + (sprite->data[3] << 8); for (i = 0; i < 0x100; i++) *(dst++) = 0; diff --git a/src/battle_transition.c b/src/battle_transition.c index 4a9d26303..43a90ac98 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -1956,10 +1956,7 @@ static bool8 Phase2_Ripple_Func2(struct Task *task) for (i = 0; i < 160; i++, r4 += r8) { s16 var = r4 >> 8; - - var++; - var--; - gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(var, r3); + gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(var & 0xffff, r3); } if (++task->tData3 == 81) diff --git a/src/contest.c b/src/contest.c index 612d79562..61a159bc4 100644 --- a/src/contest.c +++ b/src/contest.c @@ -3119,9 +3119,9 @@ static u8 CreateContestantSprite(u16 species, u32 otId, u32 personality, u32 ind species = SanitizeSpecies(species); if (index == gContestPlayerMonIndex) - HandleLoadSpecialPokePic_2(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites[0], species, personality); + HandleLoadSpecialPokePic_2(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[0], species, personality); else - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites[0], species, personality); + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[0], species, personality); LoadCompressedPalette(GetMonSpritePalFromSpeciesAndPersonality(species, otId, personality), 0x120, 0x20); SetMultiuseSpriteTemplateToPokemon(species, 0); diff --git a/src/contest_painting.c b/src/contest_painting.c index ceef8a902..e903edbbb 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -368,19 +368,19 @@ static void InitContestMonPixels(u16 species, u8 whichSprite) { HandleLoadSpecialPokePic_DontHandleDeoxys( &gMonFrontPicTable[species], - gMonSpritesGfxPtr->sprites[1], + gMonSpritesGfxPtr->sprites.ptr[1], species, gContestPaintingWinner->personality); - _InitContestMonPixels(gMonSpritesGfxPtr->sprites[1], gContestPaintingMonPalette, (void *)gContestMonPixels); + _InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[1], gContestPaintingMonPalette, (void *)gContestMonPixels); } else { HandleLoadSpecialPokePic_DontHandleDeoxys( &gMonBackPicTable[species], - gMonSpritesGfxPtr->sprites[0], + gMonSpritesGfxPtr->sprites.ptr[0], species, gContestPaintingWinner->personality); - _InitContestMonPixels(gMonSpritesGfxPtr->sprites[0], gContestPaintingMonPalette, (void *)gContestMonPixels); + _InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[0], gContestPaintingMonPalette, (void *)gContestMonPixels); } } diff --git a/src/contest_util.c b/src/contest_util.c index ae76eda6b..dbc1e28ed 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -880,7 +880,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId) { HandleLoadSpecialPokePic_2( &gMonFrontPicTable[species], - gMonSpritesGfxPtr->sprites[1], + gMonSpritesGfxPtr->sprites.ptr[1], species, personality); } @@ -888,7 +888,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId) { HandleLoadSpecialPokePic_DontHandleDeoxys( &gMonFrontPicTable[species], - gMonSpritesGfxPtr->sprites[1], + gMonSpritesGfxPtr->sprites.ptr[1], species, personality); } @@ -2552,9 +2552,9 @@ void ShowContestEntryMonPic(void) gTasks[taskId].data[0] = 0; gTasks[taskId].data[1] = species; if (gSpecialVar_0x8006 == gContestPlayerMonIndex) - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality); else - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality); + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality); palette = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality); LoadCompressedSpritePalette(palette); diff --git a/src/daycare.c b/src/daycare.c index 69043a513..1490d3742 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -615,10 +615,7 @@ static u8 GetEggMoves(struct Pokemon *pokemon, u16 *eggMoves) for (i = 0; i < EGG_MOVES_ARRAY_COUNT; i++) { if (gEggMoves[eggMoveIdx + i] > EGG_MOVES_SPECIES_OFFSET) - { - // TODO: the curly braces around this if statement are required for a matching build. break; - } eggMoves[i] = gEggMoves[eggMoveIdx + i]; numEggMoves++; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 87f0a13fd..f90441b68 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -434,7 +434,7 @@ static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID, u16* speciesLoc u16 species = GetMonData(mon, MON_DATA_SPECIES); u32 pid = GetMonData(mon, MON_DATA_PERSONALITY); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], - gMonSpritesGfxPtr->sprites[(a0 * 2) + 1], + gMonSpritesGfxPtr->sprites.ptr [(a0 * 2) + 1], species, pid); LoadCompressedSpritePalette(GetMonSpritePalStruct(mon)); *speciesLoc = species; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 61065367c..faa6195b0 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -256,7 +256,7 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, trainerId = GetMonData(mon, MON_DATA_OT_ID); personality = GetMonData(mon, MON_DATA_PERSONALITY); DecompressPicFromTable_2(&gMonFrontPicTable[currSpecies], - gMonSpritesGfxPtr->sprites[1], + gMonSpritesGfxPtr->sprites.ptr[1], currSpecies); pokePal = GetMonSpritePalStructFromOtIdPersonality(currSpecies, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x110, 0x20); @@ -271,7 +271,7 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, // postEvo sprite DecompressPicFromTable_2(&gMonFrontPicTable[speciesToEvolve], - gMonSpritesGfxPtr->sprites[3], + gMonSpritesGfxPtr->sprites.ptr[3], speciesToEvolve); pokePal = GetMonSpritePalStructFromOtIdPersonality(speciesToEvolve, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x120, 0x20); @@ -348,7 +348,7 @@ static void CB2_EvolutionSceneLoadGraphics(void) gReservedSpritePaletteCount = 4; DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], - gMonSpritesGfxPtr->sprites[3], + gMonSpritesGfxPtr->sprites.ptr[3], postEvoSpecies); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); @@ -420,7 +420,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void) u32 trainerId = GetMonData(Mon, MON_DATA_OT_ID); u32 personality = GetMonData(Mon, MON_DATA_PERSONALITY); DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], - gMonSpritesGfxPtr->sprites[3], + gMonSpritesGfxPtr->sprites.ptr[3], postEvoSpecies); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x120, 0x20); @@ -484,7 +484,7 @@ void TradeEvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, u8 preEvoSpri sEvoStructPtr->preEvoSpriteID = preEvoSpriteID; DecompressPicFromTable_2(&gMonFrontPicTable[speciesToEvolve], - gMonSpritesGfxPtr->sprites[1], + gMonSpritesGfxPtr->sprites.ptr[1], speciesToEvolve); pokePal = GetMonSpritePalStructFromOtIdPersonality(speciesToEvolve, trainerId, personality); diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c index 797771f80..32db6c717 100644 --- a/src/pokeblock_feed.c +++ b/src/pokeblock_feed.c @@ -646,7 +646,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon) case 0: species = GetMonData(mon, MON_DATA_SPECIES2); personality = GetMonData(mon, MON_DATA_PERSONALITY); - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality); sPokeblockFeed->loadGfxState++; break; case 1: diff --git a/src/pokemon.c b/src/pokemon.c index a0e655d1e..72fb4984c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5591,8 +5591,8 @@ u16 SpeciesToCryId(u16 species) void sub_806D544(u16 species, u32 personality, u8 *dest) { if (species == SPECIES_SPINDA - && dest != gMonSpritesGfxPtr->sprites[0] - && dest != gMonSpritesGfxPtr->sprites[2]) + && dest != gMonSpritesGfxPtr->sprites.ptr[0] + && dest != gMonSpritesGfxPtr->sprites.ptr[2]) { int i; for (i = 0; i < 4; i++) diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index bfd849229..805f69542 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -3859,18 +3859,18 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state) if (gMain.inBattle) { if (sub_80688F8(3, sMonSummaryScreen->curMonIndex)) - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid); else - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid); } else { if (gMonSpritesGfxPtr != NULL) { if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == PSS_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid); else - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid); } else { diff --git a/src/trade.c b/src/trade.c index 17aaba565..f48e453a8 100644 --- a/src/trade.c +++ b/src/trade.c @@ -2725,9 +2725,9 @@ static void LoadTradeMonPic(u8 whichParty, u8 state) personality = GetMonData(mon, MON_DATA_PERSONALITY); if (whichParty == TRADE_PLAYER) - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality); else - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[whichParty * 2 + 1], species, personality); + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[whichParty * 2 + 1], species, personality); LoadCompressedSpritePalette(GetMonSpritePalStruct(mon)); sTradeData->monSpecies[whichParty] = species; @@ -3660,7 +3660,7 @@ static bool8 AnimateTradeSequenceCable(void) case 65: if (gSprites[sTradeData->unk_D3].callback == SpriteCallbackDummy) { - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); sTradeData->state++; } break; @@ -4175,7 +4175,7 @@ static bool8 AnimateTradeSequenceWireless(void) case 65: if (gSprites[sTradeData->unk_D3].callback == SpriteCallbackDummy) { - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); sTradeData->state++; } break; From 94711208a2088ec739f04a6bd78a983a76e7ec2e Mon Sep 17 00:00:00 2001 From: Kaz Date: Sat, 19 Sep 2020 17:38:54 -0400 Subject: [PATCH 10/15] menu_specialized.c: Fix fakematches. --- src/menu_specialized.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/menu_specialized.c b/src/menu_specialized.c index f9da20e11..495f9aa10 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -881,34 +881,31 @@ s32 GetBoxOrPartyMonData(u16 boxId, u16 monId, s32 request, u8 *dst) // Gets the name/gender/level string for the condition menu static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) { - u16 species, level, gender; + u16 box, mon, species, level, gender; struct BoxPokemon *boxMon; u8 *str; + box = boxId; + mon = monId; *(dst++) = EXT_CTRL_CODE_BEGIN; *(dst++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; *(dst++) = TEXT_COLOR_BLUE; *(dst++) = TEXT_COLOR_TRANSPARENT; *(dst++) = TEXT_COLOR_LIGHT_BLUE; - if (GetBoxOrPartyMonData(boxId, monId, MON_DATA_IS_EGG, NULL)) - { + if (GetBoxOrPartyMonData(box, mon, MON_DATA_IS_EGG, NULL)) return StringCopyPadded(dst, gText_EggNickname, 0, 12); - } - GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, dst); + GetBoxOrPartyMonData(box, mon, MON_DATA_NICKNAME, dst); StringGetEnd10(dst); - species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES, NULL); - if (boxId == TOTAL_BOXES_COUNT) // Party mon. + species = GetBoxOrPartyMonData(box, mon, MON_DATA_SPECIES, NULL); + if (box == TOTAL_BOXES_COUNT) // Party mon. { - level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); - gender = GetMonGender(&gPlayerParty[monId]); + level = GetMonData(&gPlayerParty[mon], MON_DATA_LEVEL); + gender = GetMonGender(&gPlayerParty[mon]); } else { - // Needed to match, feel free to remove. - boxId++, boxId--; - monId++, monId--; + boxMon = GetBoxedMonPtr(box, mon); - boxMon = GetBoxedMonPtr(boxId, monId); gender = GetBoxMonGender(boxMon); level = GetLevelFromBoxMonExp(boxMon); } @@ -981,6 +978,8 @@ static u8 *BufferConditionMenuSpacedStringN(u8 *dst, const u8 *src, s16 n) void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId, u16 monId, u16 partyId, u16 numMons, bool8 excludesCancel) { u16 i; + u16 box = boxId; + u16 mon = monId; // In this and the below 2 functions, numMons is passed as the number of menu selections (which includes Cancel) // To indicate that the Cancel needs to be subtracted they pass an additional bool @@ -990,21 +989,16 @@ void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId if (partyId != numMons) { - GetConditionMenuMonString(nameDst, boxId, monId); + GetConditionMenuMonString(nameDst, box, mon); locationDst[0] = EXT_CTRL_CODE_BEGIN; locationDst[1] = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; locationDst[2] = TEXT_COLOR_BLUE; locationDst[3] = TEXT_COLOR_TRANSPARENT; locationDst[4] = TEXT_COLOR_LIGHT_BLUE; - if (boxId == TOTAL_BOXES_COUNT) // Party mon. - { + if (box == TOTAL_BOXES_COUNT) // Party mon. BufferConditionMenuSpacedStringN(&locationDst[5], gText_InParty, 8); - } else - { - boxId++;boxId--; // Again...Someone fix this maybe? - BufferConditionMenuSpacedStringN(&locationDst[5], GetBoxNamePtr(boxId), 8); - } + BufferConditionMenuSpacedStringN(&locationDst[5], GetBoxNamePtr(box), 8); } else { From 32ae13f9b66ab1b01146e5746e9350f97f055526 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sat, 19 Sep 2020 19:03:07 -0400 Subject: [PATCH 11/15] walda_phrase.c: Proper sub_81D9C90 match GET. --- src/walda_phrase.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 2b11add76..c9c7809d3 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -173,14 +173,12 @@ static void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) { var1 = (array[0] & 0x80) >> 7; - var1++; var1--; // needed to match - for (j = arg1 - 1; j >= 0; j--) { - var2 = array[j] & 0x80; + var2 = (array[j] & 0x80) >> 7; array[j] <<= 1; array[j] |= var1; - var1 = var2 >> 7; + var1 = var2; } } } From 6faa63347a9ad99d90f81c24fa41531cd20656bb Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 14 Dec 2020 21:41:30 -0500 Subject: [PATCH 12/15] document reuse of variables in link mode --- src/overworld.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/overworld.c b/src/overworld.c index dbc923e7b..3a7eb34de 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2908,6 +2908,9 @@ static void ZeroObjectEvent(struct ObjectEvent *objEvent) memset(objEvent, 0, sizeof(struct ObjectEvent)); } +// Note: Emerald reuses the direction and range variables during Link mode +// as special gender and direction values. The types and placement +// conflict with the usual Event Object struct, thus the definitions. #define linkGender(obj) obj->singleMovementActive // not even one can reference *byte* aligned bitfield members... #define linkDirection(obj) ((u8*)obj)[offsetof(typeof(*obj), fieldEffectSpriteId) - 1] // -> rangeX From 266a23b32712f6a81bc8ffeeb4dac145894747ad Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 14 Dec 2020 21:44:25 -0500 Subject: [PATCH 13/15] fix indentation --- src/menu_specialized.c | 87 +++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/src/menu_specialized.c b/src/menu_specialized.c index c1088d9f7..7de963893 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -903,60 +903,59 @@ static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) } else { - boxMon = GetBoxedMonPtr(box, mon); gender = GetBoxMonGender(boxMon); level = GetLevelFromBoxMonExp(boxMon); } - if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) - gender = MON_GENDERLESS; + if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) + gender = MON_GENDERLESS; - for (str = dst; *str != EOS; str++) - ; + for (str = dst; *str != EOS; str++) + ; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SKIP; - *(str++) = 60; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SKIP; + *(str++) = 60; - switch (gender) - { - default: - *(str++) = CHAR_SPACE; - break; - case MON_MALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_RED; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_RED; - *(str++) = CHAR_MALE; - break; - case MON_FEMALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_GREEN; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_GREEN; - *(str++) = CHAR_FEMALE; - break; - } - - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - *(str++) = TEXT_COLOR_BLUE; - *(str++) = TEXT_COLOR_TRANSPARENT; - *(str++) = TEXT_COLOR_LIGHT_BLUE; - *(str++) = CHAR_SLASH; - *(str++) = CHAR_EXTRA_SYMBOL; - *(str++) = CHAR_LV_2; - str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); + switch (gender) + { + default: *(str++) = CHAR_SPACE; - *str = EOS; + break; + case MON_MALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_RED; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_RED; + *(str++) = CHAR_MALE; + break; + case MON_FEMALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_GREEN; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_GREEN; + *(str++) = CHAR_FEMALE; + break; + } - return str; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + *(str++) = TEXT_COLOR_BLUE; + *(str++) = TEXT_COLOR_TRANSPARENT; + *(str++) = TEXT_COLOR_LIGHT_BLUE; + *(str++) = CHAR_SLASH; + *(str++) = CHAR_EXTRA_SYMBOL; + *(str++) = CHAR_LV_2; + str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); + *(str++) = CHAR_SPACE; + *str = EOS; + + return str; } // Buffers the string in src to dest up to n chars. If src is less than n chars, fill with spaces From 68b456e7f951fa31412cff10a5a47c3f963ae61b Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 14 Dec 2020 21:51:38 -0500 Subject: [PATCH 14/15] name a2 --- src/overworld.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overworld.c b/src/overworld.c index 3a7eb34de..70d63680c 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2948,13 +2948,13 @@ static void InitLinkPlayerObjectEventPos(struct ObjectEvent *objEvent, s16 x, s1 ObjectEventUpdateZCoord(objEvent); } -static void sub_80877DC(u8 linkPlayerId, u8 a2) +static void sub_80877DC(u8 linkPlayerId, u8 dir) { if (gLinkPlayerObjectEvents[linkPlayerId].active) { u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId; struct ObjectEvent *objEvent = &gObjectEvents[objEventId]; - linkDirection(objEvent) = a2; + linkDirection(objEvent) = dir; } } From 69cfe5ad01f135e16c330891d3b6d9fc7853e632 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 14 Dec 2020 21:54:19 -0500 Subject: [PATCH 15/15] use direction constant --- src/overworld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overworld.c b/src/overworld.c index 70d63680c..72aa17929 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2931,7 +2931,7 @@ static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 gender) objEvent->active = 1; linkGender(objEvent) = gender; - linkDirection(objEvent) = 2; + linkDirection(objEvent) = DIR_NORTH; objEvent->spriteId = 64; InitLinkPlayerObjectEventPos(objEvent, x, y);