From c2a38181ad75733e92eb73f5031e9c4f7a37a9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 10 Sep 2024 19:06:22 +0200 Subject: [PATCH] Alternate solution for ModNation Racers metadata overwrite (see #18430 comments) --- Core/Dialog/PSPSaveDialog.cpp | 3 ++- Core/Dialog/SavedataParam.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 2d2dacbace..144336e507 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -1112,7 +1112,8 @@ void PSPSaveDialog::ExecuteNotVisibleIOAction() { param.ClearSFOCache(); auto &result = param.GetPspParam()->common.result; - switch ((SceUtilitySavedataType)(u32)param.GetPspParam()->mode) { + SceUtilitySavedataType utilityMode = (SceUtilitySavedataType)(u32)param.GetPspParam()->mode; + switch (utilityMode) { case SCE_UTILITY_SAVEDATA_TYPE_LOAD: // Only load and exit case SCE_UTILITY_SAVEDATA_TYPE_AUTOLOAD: result = param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave); diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index cd77e58e4d..a0cbad3996 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -503,11 +503,13 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD std::string sfopath = dirPath + "/" + SFO_FILENAME; std::shared_ptr sfoFile = LoadCachedSFO(sfopath, true); + // This was added in #18430, see below. bool subWrite = param->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE || param->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA; bool wasCrypted = GetSaveCryptMode(param, saveDirName) != 0; - // Update values - if(!subWrite){ + // Update values. NOTE! #18430 made this conditional on !subWrite, but this is not correct, as it causes #18687. + // So now we do a hacky trick and just check for a valid title before we proceed with updating the sfoFile. + if (strnlen(param->sfoParam.title, sizeof(param->sfoParam.title)) > 0) { sfoFile->SetValue("TITLE", param->sfoParam.title, 128); sfoFile->SetValue("SAVEDATA_TITLE", param->sfoParam.savedataTitle, 128); sfoFile->SetValue("SAVEDATA_DETAIL", param->sfoParam.detail, 1024); @@ -554,7 +556,7 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD // Calc SFO hash for PSP. if (cryptedData != 0 || (subWrite && wasCrypted)) { int offset = sfoFile->GetDataOffset(sfoData, "SAVEDATA_PARAMS"); - if(offset >= 0) + if (offset >= 0) UpdateHash(sfoData, (int)sfoSize, offset, DetermineCryptMode(param)); } @@ -598,7 +600,6 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD delete[] cryptedData; } - // SAVE ICON0 if (param->icon0FileData.buf.IsValid()) {