Skip to content

Commit

Permalink
save info
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaMech committed Jun 30, 2024
1 parent 975b962 commit c55dc51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
5 changes: 5 additions & 0 deletions include/save_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions src/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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))) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c55dc51

Please sign in to comment.