From 4c67e48456a9071ddce569fc49b503b0ecf86a12 Mon Sep 17 00:00:00 2001 From: Gregory Heskett Date: Mon, 6 Mar 2023 20:53:08 -0500 Subject: [PATCH] Add define for wiping save data if existing save data from vanilla or another hack exists (#579) --- include/config/config_rom.h | 7 +++++++ src/game/save_file.c | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/config/config_rom.h b/include/config/config_rom.h index 76e664a98..a5927c3d6 100644 --- a/include/config/config_rom.h +++ b/include/config/config_rom.h @@ -29,6 +29,13 @@ #define BORDER_HEIGHT_CONSOLE 0 #define BORDER_HEIGHT_EMULATOR 0 +/** + * Force the game to delete any existing save data originating from a different hack. This requires INTERNAL_ROM_NAME to be unique to work properly. + * It is recommended to enable this if any significant changes to the save file are made that could cause issues with this or other hacks. + * NOTE: Using save editors with this define will likely just end up wiping your save, since SM64 specific save editors most likely use hardcoded save magic. + */ +// #define UNIQUE_SAVE_DATA + /** * Informs supported emulators to default to gamecube controller inputs. */ diff --git a/src/game/save_file.c b/src/game/save_file.c index 4663adac8..1e95415f4 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -18,8 +18,13 @@ #endif #include "puppycam2.h" +#ifdef UNIQUE_SAVE_DATA +u16 MENU_DATA_MAGIC = 0x4849; +u16 SAVE_FILE_MAGIC = 0x4441; +#else #define MENU_DATA_MAGIC 0x4849 #define SAVE_FILE_MAGIC 0x4441 +#endif //STATIC_ASSERT(sizeof(struct SaveBuffer) == EEPROM_SIZE, "eeprom buffer size must match"); @@ -332,10 +337,28 @@ void save_file_copy(s32 srcFileIndex, s32 destFileIndex) { save_file_do_save(destFileIndex); } +#ifdef UNIQUE_SAVE_DATA +// This should only be called once on boot and never again. +static void calculate_unique_save_magic(void) { + u16 checksum = 0; + + for (s32 i = 0; i < 20; i++) { + checksum += (u16) INTERNAL_ROM_NAME[i] << (i & 0x07); + } + + MENU_DATA_MAGIC += checksum; + SAVE_FILE_MAGIC += checksum; +} +#endif + void save_file_load_all(void) { s32 file; s32 validSlots; +#ifdef UNIQUE_SAVE_DATA + calculate_unique_save_magic(); // This should only be called once on boot and never again. +#endif + gMainMenuDataModified = FALSE; gSaveFileModified = FALSE;