diff options
Diffstat (limited to 'src/battle_tower.c')
-rw-r--r-- | src/battle_tower.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/battle_tower.c b/src/battle_tower.c index b7d03a5bc..d7123f3d2 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -999,7 +999,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void) return FALSE; winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); - for (i = 0; i < 5; i++) + for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++) { u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); u32 recordHasData = 0; @@ -1010,7 +1010,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void) checksum += record[j]; } validMons = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_FRONTIER_PARTY_SIZE; j++) { if (gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0 && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode)) @@ -1324,7 +1324,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) struct EmeraldBattleTowerRecord *newRecord = newRecordEm; // Needed to match. // Find a record slot of the same player and replace it. - for (i = 0; i < 5; i++) + for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++) { k = 0; for (j = 0; j < TRAINER_ID_LENGTH; j++) @@ -1336,10 +1336,15 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) { for (k = 0; k < PLAYER_NAME_LENGTH; k++) { - // BUG: Wrong variable used, 'j' instead of 'k'. + #ifdef BUGFIX + if (gSaveBlock2Ptr->frontier.towerRecords[i].name[k] != newRecord->name[k]) + break; + if (newRecord->name[k] == EOS) + #else if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecord->name[j]) break; if (newRecord->name[j] == EOS) + #endif { k = PLAYER_NAME_LENGTH; break; @@ -1350,19 +1355,19 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) if (k == PLAYER_NAME_LENGTH) break; } - if (i < 5) + if (i < BATTLE_TOWER_RECORD_COUNT) { gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord; return; } // Find an empty record slot. - for (i = 0; i < 5; i++) + for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++) { if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == 0) break; } - if (i < 5) + if (i < BATTLE_TOWER_RECORD_COUNT) { gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord; return; @@ -1373,7 +1378,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) slotIds[0] = 0; slotsCount++; - for (i = 1; i < 5; i++) + for (i = 1; i < BATTLE_TOWER_RECORD_COUNT; i++) { for (j = 0; j < slotsCount; j++) { @@ -2240,7 +2245,7 @@ static void GetRecordMixFriendMultiPartnerParty(u16 trainerId) u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); count = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++) { if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species1 && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species2 @@ -2362,7 +2367,7 @@ static void LoadMultiPartnerCandidatesData(void) } r10 = 0; - for (i = 0; i < 5; i++) + for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++) { u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); u32 recordHasData = 0; @@ -2379,7 +2384,7 @@ static void LoadMultiPartnerCandidatesData(void) && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum) { k = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_FRONTIER_PARTY_SIZE; j++) { if (species1 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species && species2 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species @@ -2682,7 +2687,7 @@ static void ValidateBattleTowerRecordChecksums(void) if (gSaveBlock2Ptr->frontier.towerPlayer.checksum != checksum) ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerPlayer); - for (i = 0; i < 5; i++) + for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++) { record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); checksum = 0; @@ -2956,7 +2961,12 @@ static void FillPartnerParty(u16 trainerId) sStevenMons[i].species, sStevenMons[i].level, sStevenMons[i].fixedIV, - TRUE, i, // BUG: personality was stored in the 'j' variable. As a result, Steven's pokemon do not have the intended natures. + TRUE, + #ifdef BUGFIX + j, + #else + i, // BUG: personality was stored in the 'j' variable. As a result, Steven's pokemon do not have the intended natures. + #endif OT_ID_PRESET, STEVEN_OTID); for (j = 0; j < PARTY_SIZE; j++) SetMonData(&gPlayerParty[MULTI_PARTY_SIZE + i], MON_DATA_HP_EV + j, &sStevenMons[i].evs[j]); @@ -3062,9 +3072,12 @@ bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct Em { dst->lvlMode = src->lvlMode; dst->winStreak = src->winStreak; - // BUG: Reading outside the array. sRubyFacilityClassToEmerald has less than FACILITY_CLASSES_COUNT entries. - // Fix by using ARRAY_COUNT(sRubyFacilityClassToEmerald) + // UB: Reading outside the array. sRubyFacilityClassToEmerald has less than FACILITY_CLASSES_COUNT entries. + #ifdef UBFIX + for (i = 0; i < ARRAY_COUNT(sRubyFacilityClassToEmerald); i++) + #else for (i = 0; i < FACILITY_CLASSES_COUNT; i++) + #endif { if (sRubyFacilityClassToEmerald[i][0] == src->facilityClass) break; @@ -3112,9 +3125,12 @@ bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, stru { dst->lvlMode = src->lvlMode; dst->winStreak = src->winStreak; - // BUG: Reading outside the array. sRubyFacilityClassToEmerald has less than FACILITY_CLASSES_COUNT entries. - // Fix by using ARRAY_COUNT(sRubyFacilityClassToEmerald) instead + // UB: Reading outside the array. sRubyFacilityClassToEmerald has less than FACILITY_CLASSES_COUNT entries. + #ifdef UBFIX + for (i = 0; i < ARRAY_COUNT(sRubyFacilityClassToEmerald); i++) + #else for (i = 0; i < FACILITY_CLASSES_COUNT; i++) + #endif { if (sRubyFacilityClassToEmerald[i][1] == src->facilityClass) break; |