diff --git a/include/save_data.h b/include/save_data.h index 78495bba51..7cde36275c 100644 --- a/include/save_data.h +++ b/include/save_data.h @@ -35,12 +35,17 @@ typedef struct { u8 unknownBytes[8]; } OnlyBestTimeTrialRecords; // size = 0x38 + typedef struct { // GP Points scored for each CC mode // 1st place is 3 points, 2nd is 2, etc. // Lowest dibit is the Mushroom Cup, 2nd dibit is the Flower Cup, etc u8 grandPrixPoints[4]; u8 soundMode; +} SaveInfo; + +typedef struct { + SaveInfo saveInfo; // It's unknown what the first byte is used for u8 checksum[3]; } Stuff; // size = 0x8 diff --git a/src/menus.c b/src/menus.c index 3c782c2ca2..783f925c32 100644 --- a/src/menus.c +++ b/src/menus.c @@ -260,7 +260,7 @@ void options_menu_act(struct Controller *controller, u16 arg1) { sp38->unk8 = -1; } if (sp2C && gSoundMode != sp38->cursor) { - gSaveData.main.soundMode = gSoundMode; + gSaveData.main.saveInfo.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); sp38->cursor = gSoundMode; @@ -269,7 +269,7 @@ void options_menu_act(struct Controller *controller, u16 arg1) { func_8009E280(); play_sound2(SOUND_MENU_GO_BACK); if (gSoundMode != sp38->cursor) { - gSaveData.main.soundMode = gSoundMode; + gSaveData.main.saveInfo.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); sp38->cursor = gSoundMode; @@ -1123,7 +1123,7 @@ void splash_menu_act(struct Controller *controller, u16 arg1) { } play_sound2(SOUND_MENU_CURSOR_MOVE); func_800B44BC(); - gSaveData.main.soundMode = gSoundMode; + gSaveData.main.saveInfo.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); } @@ -1134,7 +1134,7 @@ void splash_menu_act(struct Controller *controller, u16 arg1) { } play_sound2(SOUND_MENU_CURSOR_MOVE); func_800B44BC(); - gSaveData.main.soundMode = gSoundMode; + gSaveData.main.saveInfo.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); } if (btnAndStick & U_JPAD) { diff --git a/src/save.c b/src/save.c index 664a0faf89..f8314982fd 100644 --- a/src/save.c +++ b/src/save.c @@ -90,9 +90,9 @@ void reset_save_data_grand_prix_points_and_sound_mode(void) { s32 cup_index; Stuff *main = &gSaveData.main; for (cup_index = 0; cup_index < 4; cup_index++) { - main->grandPrixPoints[cup_index] = 0; + main->saveInfo.grandPrixPoints[cup_index] = 0; } - main->soundMode = SOUND_STEREO; + main->saveInfo.soundMode = SOUND_STEREO; gSoundMode = SOUND_STEREO; func_800B44BC(); write_save_data_grand_prix_points_and_sound_mode(); @@ -120,11 +120,11 @@ u8 checksum_time_trial_records(s32 courseIdx) { u8 compute_save_data_checksum_1(void) { - u8 *grandPrixPoints = (u8 *) &gSaveData.main.grandPrixPoints; + u8 *grandPrixPoints = (u8 *) &gSaveData.main.saveInfo.grandPrixPoints; s32 i; s32 crc = 0; - for (i = 0; i < 5; i++) { + for (i = 0; i < sizeof(SaveInfo); i++) { crc += ((grandPrixPoints[i] + 1) * (i + 1)) + i; } @@ -147,7 +147,7 @@ void load_save_data(void) { validate_save_data(); - gSoundMode = gSaveData.main.soundMode; + gSoundMode = gSaveData.main.saveInfo.soundMode; if (gSoundMode >= NUM_SOUND_MODES) { gSoundMode = SOUND_MONO; } @@ -212,10 +212,10 @@ void validate_save_data(void) { if (validate_save_data_checksum_backup() == 0) { for (cup_index = 0; cup_index < 4; cup_index++) { - main->grandPrixPoints[cup_index] = backup->grandPrixPoints[cup_index]; + main->saveInfo.grandPrixPoints[cup_index] = backup->saveInfo.grandPrixPoints[cup_index]; } - main->soundMode = backup->soundMode; + main->saveInfo.soundMode = backup->saveInfo.soundMode; main->checksum[1] = compute_save_data_checksum_backup_1(); main->checksum[2] = compute_save_data_checksum_backup_2(); osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), (u8 *) main, sizeof(Stuff)); @@ -384,7 +384,7 @@ void func_800B536C(s32 arg0) { s32 tmp2; if (arg0 >= 0) { - points = &gSaveData.main.grandPrixPoints[gCCSelection]; + points = &gSaveData.main.saveInfo.grandPrixPoints[gCCSelection]; tmp = func_800B54EC(gCupSelection, *points); tmp2 = 3 - arg0; @@ -406,7 +406,7 @@ void func_800B5404(s32 arg0, s32 arg1) if (arg0 >= 0) { temp2 = arg1 / 4; - points = &gSaveData.main.grandPrixPoints[arg1 % 4]; + points = &gSaveData.main.saveInfo.grandPrixPoints[arg1 % 4]; temp = func_800B54EC(temp2, *points); if ((arg0 < 3) && (temp < (temp_a0 = 3 - arg0))) { @@ -420,7 +420,7 @@ void func_800B5404(s32 arg0, s32 arg1) // Get Grand Prix points for a given cup and CC mode u8 func_800B54C0(s32 cup, s32 cc_mode) { - return func_800B54EC(cup, gSaveData.main.grandPrixPoints[cc_mode]); + return func_800B54EC(cup, gSaveData.main.saveInfo.grandPrixPoints[cc_mode]); } // Get Grand Prix points scored for a given cup @@ -449,7 +449,7 @@ u8 func_800B5508(s32 cup, s32 ccGrandPrixPoints, s32 points_scored) { // Check if all 4 cups have gold cups scored // for a given CC mode s32 func_800B5530(s32 cc_mode) { - if (gSaveData.main.grandPrixPoints[cc_mode] == 0xFF) { + if (gSaveData.main.saveInfo.grandPrixPoints[cc_mode] == 0xFF) { return 1; } return 0; @@ -548,21 +548,21 @@ void update_save_data_backup(void) { s32 cup_index; Stuff *main = &gSaveData.main; Stuff *backup = &gSaveData.backup; - for (cup_index = 0; cup_index < 4; cup_index++) { - backup->grandPrixPoints[cup_index] = main->grandPrixPoints[cup_index]; + for (cup_index = 0; cup_index < NUM_CUPS - 1; cup_index++) { + backup->saveInfo.grandPrixPoints[cup_index] = main->saveInfo.grandPrixPoints[cup_index]; } - backup->soundMode = main->soundMode; + backup->saveInfo.soundMode = main->saveInfo.soundMode; backup->checksum[1] = compute_save_data_checksum_backup_1(); backup->checksum[2] = compute_save_data_checksum_backup_2(); osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(backup), (u8 *) backup, sizeof(Stuff)); } u8 compute_save_data_checksum_backup_1(void) { - u8 *backupGrandPrixPoints = gSaveData.backup.grandPrixPoints; + u8 *backupGrandPrixPoints = gSaveData.backup.saveInfo.grandPrixPoints; s32 i; s32 crc = 0; - for (i = 0; i < 5; i++) { + for (i = 0; i < sizeof(SaveInfo); i++) { crc += ((backupGrandPrixPoints[i] + 1) * (i + 1)) + i; }