From e32a1571afc4a9c855c35b6ba17e84603d1b82e8 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 12 Mar 2021 15:37:31 -0500 Subject: [PATCH 1/3] Resolve link comm buffers in gBattleStruct --- include/battle.h | 18 +++++++++++++----- src/battle_main.c | 32 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/battle.h b/include/battle.h index c0baaf313..fa6c3aa96 100644 --- a/include/battle.h +++ b/include/battle.h @@ -344,6 +344,15 @@ struct BattleTvMovePoints s16 points[2][PARTY_SIZE * 4]; }; +struct MultiPartnerEnigmaBerry +{ + u8 field_0; + u8 field_1; + u8 vsScreenHealthFlagsLo; + u8 vsScreenHealthFlagsHi; + struct BattleEnigmaBerry battleEnigmaBerry; +}; + struct BattleStruct { u8 turnEffectsTracker; @@ -419,11 +428,10 @@ struct BattleStruct u8 givenExpMons; // Bits for enemy party's pokemon that gave exp to player's party. u8 lastTakenMoveFrom[MAX_BATTLERS_COUNT * MAX_BATTLERS_COUNT * 2]; // a 3-D array [target][attacker][byte] u16 castformPalette[MAX_BATTLERS_COUNT][16]; - u8 field_180; // weird field, used in battle_main.c, once accessed as an array of u32 overwriting the field below - u8 field_181; - u8 vsScreenHealthFlagsLo; - u8 vsScreenHealthFlagsHi; // Last bit is 'has frontier pass' - struct BattleEnigmaBerry battleEnigmaBerry; + union { + struct MultiPartnerEnigmaBerry multiPartnerEnigmaBerry; + u32 battleVideo[2]; + } multiBuffer; u8 wishPerishSongState; u8 wishPerishSongBattlerId; bool8 overworldWeatherDone; diff --git a/src/battle_main.c b/src/battle_main.c index 2a39a17e1..86cdac4c2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -733,16 +733,16 @@ static void BufferPartyVsScreenHealth_AtStart(void) s32 i; BUFFER_PARTY_VS_SCREEN_STATUS(gPlayerParty, flags, i); - gBattleStruct->vsScreenHealthFlagsLo = flags; - *(&gBattleStruct->vsScreenHealthFlagsHi) = flags >> 8; - gBattleStruct->vsScreenHealthFlagsHi |= FlagGet(FLAG_SYS_FRONTIER_PASS) << 7; + gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo = flags; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi) = flags >> 8; + gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi |= FlagGet(FLAG_SYS_FRONTIER_PASS) << 7; } static void SetPlayerBerryDataInBattleStruct(void) { s32 i; struct BattleStruct *battleStruct = gBattleStruct; - struct BattleEnigmaBerry *battleBerry = &battleStruct->battleEnigmaBerry; + struct BattleEnigmaBerry *battleBerry = &battleStruct->multiBuffer.multiPartnerEnigmaBerry.battleEnigmaBerry; if (IsEnigmaBerryValid() == TRUE) { @@ -970,8 +970,8 @@ static void CB2_HandleStartBattle(void) { if (IsLinkTaskFinished()) { - *(&gBattleStruct->field_180) = 0; - *(&gBattleStruct->field_181) = 3; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); @@ -981,7 +981,7 @@ static void CB2_HandleStartBattle(void) gLinkPlayers[1].id = 1; } - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->field_180, 32); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); gBattleCommunication[MULTIUSE_STATE] = 2; } if (gWirelessCommType) @@ -1008,7 +1008,7 @@ static void CB2_HandleStartBattle(void) gTasks[taskId].data[1] = 0x10E; gTasks[taskId].data[2] = 0x5A; gTasks[taskId].data[5] = 0; - gTasks[taskId].data[3] = gBattleStruct->vsScreenHealthFlagsLo | (gBattleStruct->vsScreenHealthFlagsHi << 8); + gTasks[taskId].data[3] = gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi << 8); gTasks[taskId].data[4] = gBlockRecvBuffer[enemyMultiplayerId][1]; sub_8185F90(gBlockRecvBuffer[playerMultiplayerId][1]); sub_8185F90(gBlockRecvBuffer[enemyMultiplayerId][1]); @@ -1178,11 +1178,11 @@ static void CB2_HandleStartMultiPartnerBattle(void) if (IsLinkTaskFinished()) { - *(&gBattleStruct->field_180) = 0; - *(&gBattleStruct->field_181) = 3; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->field_180, 32); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); gBattleCommunication[MULTIUSE_STATE] = 2; } @@ -1565,12 +1565,12 @@ static void CB2_HandleStartMultiBattle(void) { if (IsLinkTaskFinished()) { - *(&gBattleStruct->field_180) = 0; - *(&gBattleStruct->field_181) = 3; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->field_180, 32); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); gBattleCommunication[MULTIUSE_STATE]++; } if (gWirelessCommType) @@ -1786,10 +1786,10 @@ static void CB2_HandleStartMultiBattle(void) case 8: if (IsLinkTaskFinished()) { - u32* ptr = (u32*)(&gBattleStruct->field_180); + u32* ptr = gBattleStruct->multiBuffer.battleVideo; ptr[0] = gBattleTypeFlags; ptr[1] = gRecordedBattleRngSeed; // UB: overwrites berry data - SendBlock(bitmask_all_link_players_but_self(), ptr, 8); + SendBlock(bitmask_all_link_players_but_self(), ptr, sizeof(gBattleStruct->multiBuffer.battleVideo)); gBattleCommunication[MULTIUSE_STATE]++; } break; From 8d4dcb228afaf8dfc8198b1955d42d1794ac3d81 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 12 Mar 2021 16:55:58 -0500 Subject: [PATCH 2/3] More documentation in battle_main --- include/battle.h | 4 +- include/main.h | 2 +- include/recorded_battle.h | 6 +-- src/battle_main.c | 87 +++++++++++++++++++++------------------ src/recorded_battle.c | 15 +++---- 5 files changed, 61 insertions(+), 53 deletions(-) diff --git a/include/battle.h b/include/battle.h index fa6c3aa96..34910781b 100644 --- a/include/battle.h +++ b/include/battle.h @@ -346,8 +346,8 @@ struct BattleTvMovePoints struct MultiPartnerEnigmaBerry { - u8 field_0; - u8 field_1; + u8 versionSignatureLo; + u8 versionSignatureHi; u8 vsScreenHealthFlagsLo; u8 vsScreenHealthFlagsHi; struct BattleEnigmaBerry battleEnigmaBerry; diff --git a/include/main.h b/include/main.h index 16ac31df2..ef5430cd8 100644 --- a/include/main.h +++ b/include/main.h @@ -37,7 +37,7 @@ struct Main /*0x439*/ u8 oamLoadDisabled:1; /*0x439*/ u8 inBattle:1; - /*0x439*/ u8 field_439_x4:1; + /*0x439*/ u8 isFrontierBattle:1; }; extern const u8 gGameVersion; diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 3a6a8129a..5ae4ac12d 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -22,9 +22,9 @@ u8 GetRecordedBattleFrontierFacility(void); u8 GetRecordedBattleFronterBrainSymbol(void); void RecordedBattle_SaveParties(void); u8 GetActiveBattlerLinkPlayerGender(void); -void sub_8185F84(void); -void sub_8185F90(u16 arg0); -u8 sub_8185FAC(void); +void RecordedBattle_ClearFrontierPassFlag(void); +void RecordedBattle_SetFrontierPassFlagFromHword(u16 arg0); +u8 RecordedBattle_GetFrontierPassFlag(void); u8 GetBattleSceneInRecordedBattle(void); u8 GetTextSpeedInRecordedBattle(void); void RecordedBattle_CopyBattlerMoves(void); diff --git a/src/battle_main.c b/src/battle_main.c index 86cdac4c2..d063fe5a1 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -576,7 +576,7 @@ void CB2_InitBattle(void) AllocateBattleResources(); AllocateBattleSpritesData(); AllocateMonSpritesGfx(); - sub_8185F84(); + RecordedBattle_ClearFrontierPassFlag(); if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -882,52 +882,56 @@ static void SetAllPlayersBerryData(void) } } -static void sub_8036EB8(u8 arg0, u8 arg1) +// This was inlined in Ruby/Sapphire +static void FindLinkBattleMaster(u8 numPlayers, u8 multiPlayerId) { - u8 var = 0; + u8 found = 0; - if (gBlockRecvBuffer[0][0] == 256) + // If player 1 is playing the minimum version, player 1 is master. + if (gBlockRecvBuffer[0][0] == 0x100) { - if (arg1 == 0) + if (multiPlayerId == 0) gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; else gBattleTypeFlags |= BATTLE_TYPE_TRAINER; - var++; + found++; } - if (var == 0) + if (found == 0) { + // If multiple different versions are being used, player 1 is master. s32 i; - for (i = 0; i < arg0; i++) + for (i = 0; i < numPlayers; i++) { if (gBlockRecvBuffer[0][0] != gBlockRecvBuffer[i][0]) break; } - if (i == arg0) + if (i == numPlayers) { - if (arg1 == 0) + if (multiPlayerId == 0) gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; else gBattleTypeFlags |= BATTLE_TYPE_TRAINER; - var++; + found++; } - if (var == 0) + if (found == 0) { - for (i = 0; i < arg0; i++) + // Lowest index player with the highest game version is master. + for (i = 0; i < numPlayers; i++) { - if (gBlockRecvBuffer[i][0] == 0x300) + if (gBlockRecvBuffer[i][0] == 0x300 && i != multiPlayerId) { - if (i != arg1 && i < arg1) + if (i < multiPlayerId) break; } - if (gBlockRecvBuffer[i][0] > 0x300 && i != arg1) + if (gBlockRecvBuffer[i][0] > 0x300 && i != multiPlayerId) break; } - if (i == arg0) + if (i == numPlayers) gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; else gBattleTypeFlags |= BATTLE_TYPE_TRAINER; @@ -970,8 +974,9 @@ static void CB2_HandleStartBattle(void) { if (IsLinkTaskFinished()) { - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; + // 0x300 + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); @@ -1002,7 +1007,7 @@ static void CB2_HandleStartBattle(void) u8 taskId; ResetBlockReceivedFlags(); - sub_8036EB8(2, playerMultiplayerId); + FindLinkBattleMaster(2, playerMultiplayerId); SetAllPlayersBerryData(); taskId = CreateTask(InitLinkBattleVsScreen, 0); gTasks[taskId].data[1] = 0x10E; @@ -1010,8 +1015,8 @@ static void CB2_HandleStartBattle(void) gTasks[taskId].data[5] = 0; gTasks[taskId].data[3] = gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi << 8); gTasks[taskId].data[4] = gBlockRecvBuffer[enemyMultiplayerId][1]; - sub_8185F90(gBlockRecvBuffer[playerMultiplayerId][1]); - sub_8185F90(gBlockRecvBuffer[enemyMultiplayerId][1]); + RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[playerMultiplayerId][1]); + RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[enemyMultiplayerId][1]); SetDeoxysStats(); gBattleCommunication[MULTIUSE_STATE]++; } @@ -1178,8 +1183,9 @@ static void CB2_HandleStartMultiPartnerBattle(void) if (IsLinkTaskFinished()) { - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; + // 0x300 + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); @@ -1204,7 +1210,7 @@ static void CB2_HandleStartMultiPartnerBattle(void) u8 taskId; ResetBlockReceivedFlags(); - sub_8036EB8(2, playerMultiplayerId); + FindLinkBattleMaster(2, playerMultiplayerId); SetAllPlayersBerryData(); taskId = CreateTask(InitLinkBattleVsScreen, 0); gTasks[taskId].data[1] = 0x10E; @@ -1565,8 +1571,9 @@ static void CB2_HandleStartMultiBattle(void) { if (IsLinkTaskFinished()) { - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; + // 0x300 + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); @@ -1589,7 +1596,7 @@ static void CB2_HandleStartMultiBattle(void) if ((GetBlockReceivedStatus() & 0xF) == 0xF) { ResetBlockReceivedFlags(); - sub_8036EB8(4, playerMultiplayerId); + FindLinkBattleMaster(4, playerMultiplayerId); SetAllPlayersBerryData(); SetDeoxysStats(); var = CreateTask(InitLinkBattleVsScreen, 0); @@ -1601,7 +1608,7 @@ static void CB2_HandleStartMultiBattle(void) for (id = 0; id < MAX_LINK_PLAYERS; id++) { - sub_8185F90(gBlockRecvBuffer[id][1]); + RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[id][1]); switch (gLinkPlayers[id].id) { case 0: @@ -2248,7 +2255,7 @@ static void EndLinkBattleInSteps(void) { u8 monsCount; - gMain.field_439_x4 = sub_8185FAC(); + gMain.isFrontierBattle = RecordedBattle_GetFrontierPassFlag(); if (gBattleTypeFlags & BATTLE_TYPE_MULTI) monsCount = 4; @@ -2264,7 +2271,7 @@ static void EndLinkBattleInSteps(void) FreeAllWindowBuffers(); SetMainCallback2(sub_80392A8); } - else if (!gMain.field_439_x4) + else if (!gMain.isFrontierBattle) { SetMainCallback2(gMain.savedCallback); FreeBattleResources(); @@ -2328,9 +2335,9 @@ static void EndLinkBattleInSteps(void) gBattleCommunication[MULTIUSE_STATE]++; break; case 9: - if (!gMain.field_439_x4 || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) + if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.field_439_x4 = 0; + gMain.isFrontierBattle = 0; SetMainCallback2(gMain.savedCallback); FreeBattleResources(); FreeBattleSpritesData(); @@ -2426,7 +2433,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; break; case 1: - if (gMain.field_439_x4 && gReceivedRemoteLinkPlayers == 0) + if (gMain.isFrontierBattle && gReceivedRemoteLinkPlayers == 0) CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; break; @@ -2496,7 +2503,7 @@ static void sub_803939C(void) if (IsLinkTaskFinished() == TRUE) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); - if (gMain.field_439_x4) + if (gMain.isFrontierBattle) { SetLinkStandbyCallback(); BattlePutTextOnWindow(gText_LinkStandby3, 0); @@ -2507,15 +2514,15 @@ static void sub_803939C(void) case 8: if (--gBattleCommunication[1] == 0) { - if (gMain.field_439_x4 && !gWirelessCommType) + if (gMain.isFrontierBattle && !gWirelessCommType) SetCloseLinkCallback(); gBattleCommunication[MULTIUSE_STATE]++; } break; case 9: - if (!gMain.field_439_x4 || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) + if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.field_439_x4 = 0; + gMain.isFrontierBattle = 0; if (!gPaletteFade.active) { SetMainCallback2(gMain.savedCallback); @@ -2545,7 +2552,7 @@ static void sub_803939C(void) case 11: if (IsLinkTaskFinished() == TRUE && !IsTextPrinterActive(0) && --gBattleCommunication[1] == 0) { - if (gMain.field_439_x4) + if (gMain.isFrontierBattle) { SetLinkStandbyCallback(); BattlePutTextOnWindow(gText_LinkStandby3, 0); @@ -2557,7 +2564,7 @@ static void sub_803939C(void) case 7: if (!IsTextPrinterActive(0)) { - if (gMain.field_439_x4) + if (gMain.isFrontierBattle) { if (IsLinkTaskFinished() == TRUE) { diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 5db4f82c5..e29792766 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -84,7 +84,7 @@ EWRAM_DATA static u8 sFrontierFacility = 0; EWRAM_DATA static u8 sFrontierBrainSymbol = 0; EWRAM_DATA static MainCallback sCallback2_AfterRecordedBattle = NULL; EWRAM_DATA u8 gRecordedBattleMultiplayerId = 0; -EWRAM_DATA static u8 sUnknown_0203C7B5 = 0; +EWRAM_DATA static u8 sFrontierPassFlag = 0; EWRAM_DATA static u8 sBattleScene = 0; EWRAM_DATA static u8 sTextSpeed = 0; EWRAM_DATA static u32 sBattleFlags = 0; @@ -687,19 +687,20 @@ u8 GetActiveBattlerLinkPlayerGender(void) return 0; } -void sub_8185F84(void) +void RecordedBattle_ClearFrontierPassFlag(void) { - sUnknown_0203C7B5 = 0; + sFrontierPassFlag = 0; } -void sub_8185F90(u16 arg0) +// Set sFrontierPassFlag to received state of FLAG_SYS_FRONTIER_PASS +void RecordedBattle_SetFrontierPassFlagFromHword(u16 arg0) { - sUnknown_0203C7B5 |= (arg0 & 0x8000) >> 0xF; + sFrontierPassFlag |= (arg0 & 0x8000) >> 15; } -u8 sub_8185FAC(void) +u8 RecordedBattle_GetFrontierPassFlag(void) { - return sUnknown_0203C7B5; + return sFrontierPassFlag; } u8 GetBattleSceneInRecordedBattle(void) From 925e68c03ffe27b6f3467f1ee33be240f879f6b5 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 15 Mar 2021 15:22:41 -0400 Subject: [PATCH 3/3] Update newly named fields --- include/battle.h | 4 ++-- include/main.h | 2 +- src/battle_main.c | 50 +++++++++++++++++++++++------------------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/battle.h b/include/battle.h index 34910781b..954d33b07 100644 --- a/include/battle.h +++ b/include/battle.h @@ -344,7 +344,7 @@ struct BattleTvMovePoints s16 points[2][PARTY_SIZE * 4]; }; -struct MultiPartnerEnigmaBerry +struct LinkBattlerHeader { u8 versionSignatureLo; u8 versionSignatureHi; @@ -429,7 +429,7 @@ struct BattleStruct u8 lastTakenMoveFrom[MAX_BATTLERS_COUNT * MAX_BATTLERS_COUNT * 2]; // a 3-D array [target][attacker][byte] u16 castformPalette[MAX_BATTLERS_COUNT][16]; union { - struct MultiPartnerEnigmaBerry multiPartnerEnigmaBerry; + struct LinkBattlerHeader linkBattlerHeader; u32 battleVideo[2]; } multiBuffer; u8 wishPerishSongState; diff --git a/include/main.h b/include/main.h index ef5430cd8..cad5c0ef9 100644 --- a/include/main.h +++ b/include/main.h @@ -37,7 +37,7 @@ struct Main /*0x439*/ u8 oamLoadDisabled:1; /*0x439*/ u8 inBattle:1; - /*0x439*/ u8 isFrontierBattle:1; + /*0x439*/ u8 anyLinkBattlerHasFrontierPass:1; }; extern const u8 gGameVersion; diff --git a/src/battle_main.c b/src/battle_main.c index d063fe5a1..3507ff765 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -733,16 +733,16 @@ static void BufferPartyVsScreenHealth_AtStart(void) s32 i; BUFFER_PARTY_VS_SCREEN_STATUS(gPlayerParty, flags, i); - gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo = flags; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi) = flags >> 8; - gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi |= FlagGet(FLAG_SYS_FRONTIER_PASS) << 7; + gBattleStruct->multiBuffer.linkBattlerHeader.vsScreenHealthFlagsLo = flags; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.vsScreenHealthFlagsHi) = flags >> 8; + gBattleStruct->multiBuffer.linkBattlerHeader.vsScreenHealthFlagsHi |= FlagGet(FLAG_SYS_FRONTIER_PASS) << 7; } static void SetPlayerBerryDataInBattleStruct(void) { s32 i; struct BattleStruct *battleStruct = gBattleStruct; - struct BattleEnigmaBerry *battleBerry = &battleStruct->multiBuffer.multiPartnerEnigmaBerry.battleEnigmaBerry; + struct BattleEnigmaBerry *battleBerry = &battleStruct->multiBuffer.linkBattlerHeader.battleEnigmaBerry; if (IsEnigmaBerryValid() == TRUE) { @@ -975,8 +975,8 @@ static void CB2_HandleStartBattle(void) if (IsLinkTaskFinished()) { // 0x300 - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); @@ -986,7 +986,7 @@ static void CB2_HandleStartBattle(void) gLinkPlayers[1].id = 1; } - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.linkBattlerHeader, sizeof(gBattleStruct->multiBuffer.linkBattlerHeader)); gBattleCommunication[MULTIUSE_STATE] = 2; } if (gWirelessCommType) @@ -1013,7 +1013,7 @@ static void CB2_HandleStartBattle(void) gTasks[taskId].data[1] = 0x10E; gTasks[taskId].data[2] = 0x5A; gTasks[taskId].data[5] = 0; - gTasks[taskId].data[3] = gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi << 8); + gTasks[taskId].data[3] = gBattleStruct->multiBuffer.linkBattlerHeader.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.linkBattlerHeader.vsScreenHealthFlagsHi << 8); gTasks[taskId].data[4] = gBlockRecvBuffer[enemyMultiplayerId][1]; RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[playerMultiplayerId][1]); RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[enemyMultiplayerId][1]); @@ -1184,11 +1184,11 @@ static void CB2_HandleStartMultiPartnerBattle(void) if (IsLinkTaskFinished()) { // 0x300 - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.linkBattlerHeader, sizeof(gBattleStruct->multiBuffer.linkBattlerHeader)); gBattleCommunication[MULTIUSE_STATE] = 2; } @@ -1572,12 +1572,12 @@ static void CB2_HandleStartMultiBattle(void) if (IsLinkTaskFinished()) { // 0x300 - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0; - *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureLo) = 0; + *(&gBattleStruct->multiBuffer.linkBattlerHeader.versionSignatureHi) = 3; BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); - SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); + SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.linkBattlerHeader, sizeof(gBattleStruct->multiBuffer.linkBattlerHeader)); gBattleCommunication[MULTIUSE_STATE]++; } if (gWirelessCommType) @@ -2255,7 +2255,7 @@ static void EndLinkBattleInSteps(void) { u8 monsCount; - gMain.isFrontierBattle = RecordedBattle_GetFrontierPassFlag(); + gMain.anyLinkBattlerHasFrontierPass = RecordedBattle_GetFrontierPassFlag(); if (gBattleTypeFlags & BATTLE_TYPE_MULTI) monsCount = 4; @@ -2271,7 +2271,7 @@ static void EndLinkBattleInSteps(void) FreeAllWindowBuffers(); SetMainCallback2(sub_80392A8); } - else if (!gMain.isFrontierBattle) + else if (!gMain.anyLinkBattlerHasFrontierPass) { SetMainCallback2(gMain.savedCallback); FreeBattleResources(); @@ -2335,9 +2335,9 @@ static void EndLinkBattleInSteps(void) gBattleCommunication[MULTIUSE_STATE]++; break; case 9: - if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) + if (!gMain.anyLinkBattlerHasFrontierPass || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.isFrontierBattle = 0; + gMain.anyLinkBattlerHasFrontierPass = 0; SetMainCallback2(gMain.savedCallback); FreeBattleResources(); FreeBattleSpritesData(); @@ -2433,7 +2433,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; break; case 1: - if (gMain.isFrontierBattle && gReceivedRemoteLinkPlayers == 0) + if (gMain.anyLinkBattlerHasFrontierPass && gReceivedRemoteLinkPlayers == 0) CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; break; @@ -2503,7 +2503,7 @@ static void sub_803939C(void) if (IsLinkTaskFinished() == TRUE) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); - if (gMain.isFrontierBattle) + if (gMain.anyLinkBattlerHasFrontierPass) { SetLinkStandbyCallback(); BattlePutTextOnWindow(gText_LinkStandby3, 0); @@ -2514,15 +2514,15 @@ static void sub_803939C(void) case 8: if (--gBattleCommunication[1] == 0) { - if (gMain.isFrontierBattle && !gWirelessCommType) + if (gMain.anyLinkBattlerHasFrontierPass && !gWirelessCommType) SetCloseLinkCallback(); gBattleCommunication[MULTIUSE_STATE]++; } break; case 9: - if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) + if (!gMain.anyLinkBattlerHasFrontierPass || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.isFrontierBattle = 0; + gMain.anyLinkBattlerHasFrontierPass = 0; if (!gPaletteFade.active) { SetMainCallback2(gMain.savedCallback); @@ -2552,7 +2552,7 @@ static void sub_803939C(void) case 11: if (IsLinkTaskFinished() == TRUE && !IsTextPrinterActive(0) && --gBattleCommunication[1] == 0) { - if (gMain.isFrontierBattle) + if (gMain.anyLinkBattlerHasFrontierPass) { SetLinkStandbyCallback(); BattlePutTextOnWindow(gText_LinkStandby3, 0); @@ -2564,7 +2564,7 @@ static void sub_803939C(void) case 7: if (!IsTextPrinterActive(0)) { - if (gMain.isFrontierBattle) + if (gMain.anyLinkBattlerHasFrontierPass) { if (IsLinkTaskFinished() == TRUE) {