Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/overworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ void UpdateEscapeWarp(s16 x, s16 y);
bool8 SetDiveWarpEmerge(u16 x, u16 y);
bool8 SetDiveWarpDive(u16 x, u16 y);

#if REVISION >= 0xA
#if defined(BUGFIX) || REVISION >= 0xA
// Clears stale post-link callback after CB2_LinkError (see link.c).
void ClearFieldCallback(void);
#endif

Expand Down
7 changes: 4 additions & 3 deletions src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,14 +819,15 @@ static void SetLinkBattleEndCallbacks(void)

void SetBattleEndCallbacks(void)
{
#if REVISION >= 0xA
#else
// BUGFIX: Link battles wait for RFU/cable idle and fade end before standby/close.
// SetLinkStandbyCallback no-ops while gRfu.callback is set, which could skip teardown.
#if !(defined(BUGFIX) || REVISION >= 0xA)
if (!gPaletteFade.active)
#endif
{
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
#if REVISION >= 0xA
#if REVISION >= 0xA || defined(BUGFIX)
if (!IsLinkTaskFinished() || gPaletteFade.active) return;
#endif
if (gWirelessCommType == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,8 @@ static void CB2_PreInitMultiBattle(void)
}
break;
case 2:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before closing link after multi battle party showcase.
#if defined(BUGFIX) || REVISION >= 0xA
if (IsLinkTaskFinished() && !gPaletteFade.active)
#else
if (!gPaletteFade.active)
Expand Down Expand Up @@ -3927,6 +3928,7 @@ static void ReturnFromBattleToOverworld(void)
if (gBattleTypeFlags & BATTLE_TYPE_ROAMER)
{
UpdateRoamerHPStatus(&gEnemyParty[0]);
// BUGFIX: Use == B_OUTCOME_WON, not &. Roar sets outcome to PLAYER_TELEPORTED (5); 5 & 1 is nonzero.
#if defined(BUGFIX) || REVISION >= 0xA
if ((gBattleOutcome == B_OUTCOME_WON) || gBattleOutcome == B_OUTCOME_CAUGHT || gBattleOutcome == B_OUTCOME_DREW)
#else
Expand Down
6 changes: 4 additions & 2 deletions src/cable_club.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@ static void Task_StartWirelessCableClubBattle(u8 taskId)
tState = 5;
break;
case 5:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before starting cable club battle standby.
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
SetLinkStandbyCallback();
Expand Down Expand Up @@ -923,7 +924,8 @@ static void Task_StartWirelessTrade(u8 taskId)
tState++;
break;
case 2:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before trade setup standby.
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
gSelectedTradeMonPositions[TRADE_PLAYER] = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/field_fadetransition.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static void Task_ReturnToFieldRecordMixing(u8 taskId)
switch (task->data[0])
{
case 0:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before wireless return-to-field standby.
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
SetLinkStandbyCallback();
Expand Down
2 changes: 2 additions & 0 deletions src/librfu_rfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ static void rfu_CB_pollConnectParent(u8 reqCommand, u16 reqResult)
u16 id;
u8 slot;
u8 bm_slot_flag, i;
// UBFIX: Initialize target_p; some failure paths never assign it before use.
#if REVISION >= 0xA || defined(UBFIX)
struct RfuTgtData *target_p = NULL;
#else
Expand Down Expand Up @@ -1424,6 +1425,7 @@ static u16 rfu_STC_setSendData_org(u8 ni_or_uni, u8 bmSendSlot, u8 subFrameSize,
{
u8 bm_slot_id, sendSlotFlag;
u8 frameSize;
// UBFIX: llFrameSize_p may be unset if parentChild is neither parent nor child.
#if REVISION >= 0xA || defined(UBFIX)
u8 *llFrameSize_p = NULL;
#else
Expand Down
4 changes: 3 additions & 1 deletion src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,9 @@ void CB2_LinkError(void)
{
u8 *tilemapBuffer;

#if REVISION >= 0xA
// BUGFIX: Link error calls ResetTasks() but leaves gFieldCallback set; overworld may
// then run a stale post-link callback on a dead connection (softlock / erratic link state).
#if defined(BUGFIX) || REVISION >= 0xA
ClearFieldCallback();
#endif
SetGpuReg(REG_OFFSET_DISPCNT, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void AgbMain()
RegisterRamReset(RESET_ALL);
#endif //MODERN

// It is white because the GBA Boot screen is white.
// Sloop does not display this screen, so fade from black instead.
#if REVISION >= 0xA
*(vu16 *)BG_PLTT = RGB_BLACK;
#else
Expand Down Expand Up @@ -184,6 +186,8 @@ void AgbMain()
&& (gMain.heldKeysRaw & B_START_SELECT) == B_START_SELECT)
{
rfu_REQ_stopMode();

// Note: Rev10 skips rfu_waitREQComplete for faster Sloop reset; keep the wait on real hardware.
#if REVISION < 0xA
rfu_waitREQComplete();
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,13 @@ s8 Menu_ProcessInputNoWrapClearOnChoose(void)

void DestroyYesNoMenu(void)
{
#if REVISION >= 0xA
// UBFIX: Guard double-destroy when sYesNoWindowId is already invalid.
#if REVISION >= 0xA || defined(UBFIX)
if (sYesNoWindowId == 0xFF) return;
#endif
ClearStdWindowAndFrameToTransparent(sYesNoWindowId, TRUE);
RemoveWindow(sYesNoWindowId);
#if REVISION >= 0xA
#if REVISION >= 0xA || defined(UBFIX)
sYesNoWindowId = 0xFF;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/overworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ static bool8 RunFieldCallback(void)
return TRUE;
}

#if REVISION >= 0xA
#if defined(BUGFIX) || REVISION >= 0xA
void ClearFieldCallback(void)
{
gFieldCallback = NULL;
Expand Down
9 changes: 6 additions & 3 deletions src/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ void Task_LinkFullSave(u8 taskId)
gTasks[taskId].data[0] = 1;
break;
case 1:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before link full-save standby (see also cases 7 and 9).
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
SetLinkStandbyCallback();
Expand Down Expand Up @@ -924,7 +925,8 @@ void Task_LinkFullSave(u8 taskId)
gTasks[taskId].data[0] = 7;
break;
case 7:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle between save sectors.
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
ClearContinueGameWarpStatus2();
Expand All @@ -942,7 +944,8 @@ void Task_LinkFullSave(u8 taskId)
}
break;
case 9:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before final post-save standby.
#if defined(BUGFIX) || REVISION >= 0xA
if (!IsLinkTaskFinished()) break;
#endif
SetLinkStandbyCallback();
Expand Down
4 changes: 2 additions & 2 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ static void InsertTask(u8 newTaskId)

void DestroyTask(u8 taskId)
{
#if REVISION >= 0xA
// Bounds check on the task ID.
#if REVISION >= 0xA || defined(UBFIX)
// UBFIX: Invalid taskId would read past gTasks[].
if (taskId >= NUM_TASKS) return;
#endif
if (gTasks[taskId].isActive)
Expand Down
3 changes: 2 additions & 1 deletion src/trade.c
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,8 @@ static void CB_HandleTradeCanceled(void)

static void CB_InitExitCanceledTrade(void)
{
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before exiting a canceled trade.
#if defined(BUGFIX) || REVISION >= 0xA
if (IsLinkTaskFinished() && !gPaletteFade.active)
#else
if (!gPaletteFade.active)
Expand Down
23 changes: 15 additions & 8 deletions src/union_room.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ static void Task_TryBecomeLinkLeader(u8 taskId)
}
break;
case LL_STATE_MEMBER_LEFT:
#if REVISION >= 0xA
// BUGFIX: Use group size, not activity id, to pick the unavailable-player message.
#if defined(BUGFIX) || REVISION >= 0xA
id = (GROUP_MAX(sPlayerActivityGroupSize) != 2) ? 1 : 0;
#else
id = (GROUP_MAX(sPlayerCurrActivity) == 2) ? 1 : 0;
Expand Down Expand Up @@ -619,7 +620,8 @@ static void Task_TryBecomeLinkLeader(u8 taskId)
{
RequestDisconnectSlotByTrainerNameAndId(data->playerList->players[data->playerCount].rfu.name, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId));
data->playerList->players[data->playerCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
#if REVISION >= 0xA
// BUGFIX: Use LeaderPrunePlayerList return value to update playerCount.
#if defined(BUGFIX) || REVISION >= 0xA
data->playerCount = LeaderPrunePlayerList(data->playerList);
#else
LeaderPrunePlayerList(data->playerList);
Expand Down Expand Up @@ -966,11 +968,13 @@ static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader * dat
#endif
break;
case UNION_ROOM_SPAWN_OUT:
#if REVISION >= 0xA
// BUGFIX: Handle pending disconnect (countdown != 0) before player is fully removed.
#if defined(BUGFIX) || REVISION >= 0xA
case UNION_ROOM_SPAWN_OUT_SOON:
#endif
RfuSetStatus(RFU_STATUS_OK, 0);
#if REVISION >= 0xA
// BUGFIX: Prune list when member leaves (or is about to).
#if defined(BUGFIX) || REVISION >= 0xA
data->playerCount = LeaderPrunePlayerList(data->playerList);
#endif
RedrawListMenu(data->listTaskId);
Expand Down Expand Up @@ -1006,7 +1010,8 @@ static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y)
static u8 LeaderUpdateGroupMembership(struct RfuPlayerList * list)
{
struct WirelessLink_Leader * data = sWirelessLinkMain.leader;
#if REVISION >= 0xA
// BUGFIX: Classify spawn in/out by countdown so SPAWN_OUT_SOON can be handled.
#if defined(BUGFIX) || REVISION >= 0xA
s32 id;
#else
u8 ret = UNION_ROOM_SPAWN_NONE;
Expand All @@ -1030,7 +1035,7 @@ static u8 LeaderUpdateGroupMembership(struct RfuPlayerList * list)
{
// No new incoming player
data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
#if REVISION >= 0xA
#if defined(BUGFIX) || REVISION >= 0xA
#else
ret = UNION_ROOM_SPAWN_OUT;
#endif
Expand All @@ -1041,7 +1046,7 @@ static u8 LeaderUpdateGroupMembership(struct RfuPlayerList * list)
for (id = 0; id < RFU_CHILD_MAX; id++)
TryAddIncomingPlayerToList(data->playerList->players, &data->incomingPlayerList->players[id], MAX_RFU_PLAYERS);

#if REVISION >= 0xA
#if defined(BUGFIX) || REVISION >= 0xA
id = 1;
{
struct RfuPlayerList* playerList = data->playerList;
Expand Down Expand Up @@ -1593,6 +1598,7 @@ static bool32 IsPartnerActivityAcceptable(u32 activity, u32 group)
return TRUE;

#ifdef UBFIX
// UBFIX: group <= ARRAY_COUNT may read one past sAcceptedActivityIds.
if (group < ARRAY_COUNT(sAcceptedActivityIds))
#else
if (group <= ARRAY_COUNT(sAcceptedActivityIds)) // UB: <= may access data outside the array
Expand Down Expand Up @@ -1992,7 +1998,8 @@ static void Task_RunScriptAndFadeToActivity(u8 taskId)
}
break;
case 2:
#if REVISION >= 0xA
// BUGFIX: Wait for link idle before activity start standby.
#if defined(BUGFIX) || REVISION >= 0xA
if (IsLinkTaskFinished() && !gPaletteFade.active)
#else
if (!gPaletteFade.active)
Expand Down
7 changes: 4 additions & 3 deletions src/union_room_battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ void CB2_UnionRoomBattle(void)
case 50:
if (!UpdatePaletteFade())
{
#if REVISION >= 0xA
// BUGFIX: Defer standby until after fade; extra round syncs link before battle start.
#if REVISION >= 0xA || defined(BUGFIX)
#else
SetLinkStandbyCallback();
#endif
Expand All @@ -189,15 +190,15 @@ void CB2_UnionRoomBattle(void)
case 51:
if (IsLinkTaskFinished())
{
#if REVISION >= 0xA
#if REVISION >= 0xA || defined(BUGFIX)
SetLinkStandbyCallback();
gMain.state++;
#else
SetMainCallback2(SetUpPartiesAndStartBattle);
#endif
}
break;
#if REVISION >= 0xA
#if REVISION >= 0xA || defined(BUGFIX)
case 52:
if (IsLinkTaskFinished())
{
Expand Down
Loading