diff --git a/include/battle.h b/include/battle.h index fa6c3aa968..34910781ba 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 16ac31df2c..ef5430cd89 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 3a6a8129a5..5ae4ac12d5 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 86cdac4c27..d063fe5a13 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 5db4f82c54..e29792766e 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)