From 5daf5a14ac47989cfe18fde3c9b2b03b718775fb Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 14 Jun 2023 20:39:14 -0700 Subject: [PATCH] Section Save Modification (#2947) * Modified `SaveManager::AddSaveFunction` to return the section index assigned to the section name for ease of remembering it on the other end. Also added a clarifying comment. * Modified SaveFunc to accept a boolean for whether the section is being saved individually or as part of a game save (fullSave == true means game save, so all sections registered for game save sync). --- soh/soh/Enhancements/gameplaystats.cpp | 2 +- soh/soh/SaveManager.cpp | 14 ++++++++------ soh/soh/SaveManager.h | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index 712d2812d..93482ffa5 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -339,7 +339,7 @@ void LoadStatsVersion1() { }); } -void SaveStats(SaveContext* saveContext, int sectionID) { +void SaveStats(SaveContext* saveContext, int sectionID, bool fullSave) { SaveManager::Instance->SaveData("buildVersion", saveContext->sohStats.buildVersion); SaveManager::Instance->SaveData("buildVersionMajor", saveContext->sohStats.buildVersionMajor); SaveManager::Instance->SaveData("buildVersionMinor", saveContext->sohStats.buildVersionMinor); diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 7d981d337..f8b671599 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -268,7 +268,7 @@ void SaveManager::LoadRandomizerVersion2() { }); } -void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID) { +void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave) { if(!saveContext->n64ddFlag) return; @@ -716,7 +716,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se } currentJsonContext = §ionBlock["data"]; - sectionHandlerPair.second.func(saveContext, sectionID); + sectionHandlerPair.second.func(saveContext, sectionID, true); } } else { SaveFuncInfo svi = sectionSaveHandlers.find(sectionID)->second; @@ -731,7 +731,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se nlohmann::json& sectionBlock = saveBlock["sections"][sectionName]; sectionBlock["version"] = sectionVersion; currentJsonContext = §ionBlock["data"]; - svi.func(saveContext, sectionID); + svi.func(saveContext, sectionID, false); } #if defined(__SWITCH__) || defined(__WIIU__) @@ -750,6 +750,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se } // SaveSection creates a copy of gSaveContext to prevent mid-save data modification, and passes its reference to SaveFileThreaded +// This should never be called with threaded == false except during file creation void SaveManager::SaveSection(int fileNum, int sectionID, bool threaded) { // Don't save in Boss rush. if (fileNum == 0xFF || fileNum == 0xFE) { @@ -871,11 +872,11 @@ void SaveManager::AddLoadFunction(const std::string& name, int version, LoadFunc sectionLoadHandlers[name][version] = func; } -void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) { +int SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) { if (sectionRegistry.contains(name)) { SPDLOG_ERROR("Adding save function for section that already has one: " + name); assert(false); - return; + return -1; } int index = sectionIndex; @@ -887,6 +888,7 @@ void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc SaveFuncInfo sfi = { name, version, func, saveWithBase, parentSection }; sectionSaveHandlers.emplace(index, sfi); sectionRegistry.emplace(name, index); + return index; } void SaveManager::AddPostFunction(const std::string& name, PostFunc func) { @@ -1656,7 +1658,7 @@ void SaveManager::LoadBaseVersion4() { SaveManager::Instance->LoadData("dogParams", gSaveContext.dogParams); } -void SaveManager::SaveBase(SaveContext* saveContext, int sectionID) { +void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSave) { SaveManager::Instance->SaveData("entranceIndex", saveContext->entranceIndex); SaveManager::Instance->SaveData("linkAge", saveContext->linkAge); SaveManager::Instance->SaveData("cutsceneIndex", saveContext->cutsceneIndex); diff --git a/soh/soh/SaveManager.h b/soh/soh/SaveManager.h index a3fe83253..628b694f2 100644 --- a/soh/soh/SaveManager.h +++ b/soh/soh/SaveManager.h @@ -44,7 +44,7 @@ class SaveManager { using InitFunc = void (*)(bool isDebug); using LoadFunc = void (*)(); - using SaveFunc = void (*)(SaveContext* saveContext, int sectionID); + using SaveFunc = void (*)(SaveContext* saveContext, int sectionID, bool fullSave); using PostFunc = void (*)(int version); typedef struct { @@ -75,7 +75,7 @@ class SaveManager { // Adds a function that is called when saving. This should only be called once for each function, the version is // filled in automatically. - void AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection); + int AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection); // Adds a function to be called after loading is complete. This is to handle any cleanup required from loading old // versions. @@ -144,13 +144,13 @@ class SaveManager { static void LoadRandomizerVersion1(); static void LoadRandomizerVersion2(); - static void SaveRandomizer(SaveContext* saveContext, int sectionID); + static void SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave); static void LoadBaseVersion1(); static void LoadBaseVersion2(); static void LoadBaseVersion3(); static void LoadBaseVersion4(); - static void SaveBase(SaveContext* saveContext, int sectionID); + static void SaveBase(SaveContext* saveContext, int sectionID, bool fullSave); std::vector initFuncs;