From a6d5c9c0c5fb89005e564912580fdefff12a49b2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Feb 2021 10:41:53 -0800 Subject: [PATCH 1/2] Core: Use homebrew disc IDs/titles when available. Soem homebrew do have valid data here - better to use it if possible. This affects reporting, which recently got a large chunk of homebrew reports with empty titles because of this. --- Core/PSPLoaders.cpp | 64 +++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 69a1b94855..ae718cddce 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -185,6 +185,28 @@ void InitMemoryForGamePBP(FileLoader *fileLoader) { if (paramSFO.ReadSFO(sfoData)) { // This is the parameter CFW uses to determine homebrew wants the full 64MB. UseLargeMem(paramSFO.GetValueInt("MEMSIZE")); + + // Take this moment to bring over the title, if set. + bool updateTitle = false; + std::string title = paramSFO.GetValueString("TITLE"); + if (g_paramSFO.GetValueString("TITLE").empty() && !title.empty()) { + g_paramSFO.SetValue("TITLE", title, (int)title.size()); + } + + std::string discID = paramSFO.GetValueString("DISC_ID"); + // Homebrew typically always leave this zero. + bool discTotalCheck = paramSFO.GetValueInt("DISC_TOTAL") != 0; + // A lot of homebrew reuse real game disc IDs - avoid. + bool formatCheck = discID.substr(0, 2) != "NP" && discID.substr(0, 2) != "UL" && discID.substr(0, 2) != "UC"; + char region = discID.size() > 3 ? discID[2] : '\0'; + bool regionCheck = region != 'A' && region != 'E' && region != 'H' && region != 'I' && region != 'J' && region != 'K' && region != 'U' && region != 'X'; + if (formatCheck || regionCheck || discTotalCheck) { + g_paramSFO.SetValue("DISC_ID", discID, (int)discID.size()); + std::string ver = paramSFO.GetValueString("DISC_VERSION"); + if (ver.empty()) + ver = "1.00"; + g_paramSFO.SetValue("DISC_VERSION", ver, (int)ver.size()); + } } } } @@ -393,33 +415,35 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) { std::string homebrewName = PSP_CoreParameter().fileToStart; std::size_t lslash = homebrewName.find_last_of("/"); - homebrewName = homebrewName.substr(lslash + 1); + if (lslash != homebrewName.npos) + homebrewName = homebrewName.substr(lslash + 1); + std::string homebrewTitle = g_paramSFO.GetValueString("TITLE"); + if (homebrewTitle.empty()) + homebrewTitle = homebrewName; + std::string discID = g_paramSFO.GetDiscID(); + std::string discVersion = g_paramSFO.GetValueString("DISC_VERSION"); std::string madeUpID = g_paramSFO.GenerateFakeID(); - std::string title = StringFromFormat("%s : %s", madeUpID.c_str(), homebrewName.c_str()); + std::string title = StringFromFormat("%s : %s", discID.c_str(), homebrewTitle.c_str()); INFO_LOG(LOADER, "%s", title.c_str()); host->SetWindowTitle(title.c_str()); - // Temporary code - // TODO: Remove this after ~ 1.6 - // It checks for old filenames for homebrew savestates(folder name) and rename them to new fakeID format - std::string savestateDir = GetSysDirectory(DIRECTORY_SAVESTATE); + // Migrate old save states from old versions of fake game IDs. + const std::string savestateDir = GetSysDirectory(DIRECTORY_SAVESTATE); + for (int i = 0; i < 5; ++i) { + std::string newPrefix = StringFromFormat("%s%s_%s_%d", savestateDir.c_str(), discID.c_str(), discVersion.c_str(), i); + std::string oldNamePrefix = StringFromFormat("%s%s_%d", savestateDir.c_str(), homebrewName.c_str(), i); + std::string oldIDPrefix = StringFromFormat("%s%s_1.00_%d", savestateDir.c_str(), madeUpID.c_str(), i); - for (int i = 0; i < 5; i += 1) { - std::string oldName = StringFromFormat("%s%s_%d.ppst", savestateDir.c_str(), homebrewName.c_str(), i); - if (File::Exists(oldName)) { - std::string newName = StringFromFormat("%s%s_1.00_%d.ppst", savestateDir.c_str(), madeUpID.c_str(), i); - File::Rename(oldName, newName); - } + if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix + ".ppst")) + File::Rename(oldIDPrefix + ".ppst", newPrefix + ".ppst"); + else if (File::Exists(oldNamePrefix + ".ppst")) + File::Rename(oldNamePrefix + ".ppst", newPrefix + ".ppst"); + if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix + ".jpg")) + File::Rename(oldIDPrefix + ".jpg", newPrefix + ".jpg"); + else if (File::Exists(oldNamePrefix + ".jpg")) + File::Rename(oldNamePrefix + ".jpg", newPrefix + ".jpg"); } - for (int i = 0; i < 5; i += 1) { - std::string oldName = StringFromFormat("%s%s_%d.jpg", savestateDir.c_str(), homebrewName.c_str(), i); - if (File::Exists(oldName)) { - std::string newName = StringFromFormat("%s%s_1.00_%d.jpg", savestateDir.c_str(), madeUpID.c_str(), i); - File::Rename(oldName, newName); - } - } - // End of temporary code PSPLoaders_Shutdown(); // Note: See Load_PSP_ISO for notes about this thread. From a76ba9a957282145549145b5d036239572bdbfeb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Feb 2021 10:52:35 -0800 Subject: [PATCH 2/2] Core: Handle Disc ID a bit more consistently. --- Core/CwCheat.cpp | 11 ++--------- Core/HLE/sceIo.cpp | 2 +- Core/HLE/sceKernelModule.cpp | 2 +- Core/Reporting.cpp | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 8243d2fcc2..c86ef008b4 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -249,16 +249,9 @@ static void __CheatStop() { static void __CheatStart() { __CheatStop(); - std::string realGameID = g_paramSFO.GetValueString("DISC_ID"); - std::string gameID = realGameID; - const std::string gamePath = PSP_CoreParameter().fileToStart; - const bool badGameSFO = realGameID.empty() || !g_paramSFO.GetValueInt("DISC_TOTAL"); - if (badGameSFO && gamePath.find("/PSP/GAME/") != std::string::npos) { - gameID = g_paramSFO.GenerateFakeID(gamePath); - } - - cheatEngine = new CWCheatEngine(gameID); + cheatEngine = new CWCheatEngine(g_paramSFO.GetDiscID()); // This only generates ini files on boot, let's leave homebrew ini file for UI. + std::string realGameID = g_paramSFO.GetValueString("DISC_ID"); if (!realGameID.empty()) { cheatEngine->CreateCheatFile(); } diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 73031965da..55ffcff2fe 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -637,7 +637,7 @@ void __IoInit() { pspFileSystem.Mount("flash0:", flash0System); if (g_RemasterMode) { - const std::string gameId = g_paramSFO.GetValueString("DISC_ID"); + const std::string gameId = g_paramSFO.GetDiscID(); const std::string exdataPath = g_Config.memStickDirectory + "exdata/" + gameId + "/"; if (File::Exists(exdataPath)) { exdataSystem = new DirectoryFileSystem(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD); diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 014da30a1c..0a2aa4ea77 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -879,7 +879,7 @@ static void __SaveDecryptedEbootToStorageMedia(const u8 *decryptedEbootDataPtr, return; } - const std::string filenameToDumpTo = g_paramSFO.GetValueString("DISC_ID") + ".BIN"; + const std::string filenameToDumpTo = g_paramSFO.GetDiscID() + ".BIN"; const std::string dumpDirectory = GetSysDirectory(DIRECTORY_DUMP); const std::string fullPath = dumpDirectory + filenameToDumpTo; diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index 3a621a0825..58c5489875 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -400,7 +400,7 @@ namespace Reporting std::string CurrentGameID() { // TODO: Maybe ParamSFOData shouldn't include nulls in std::strings? Don't work to break savedata, though... - const std::string disc_id = StripTrailingNull(g_paramSFO.GetValueString("DISC_ID")); + const std::string disc_id = StripTrailingNull(g_paramSFO.GetDiscID()); const std::string disc_version = StripTrailingNull(g_paramSFO.GetValueString("DISC_VERSION")); return disc_id + "_" + disc_version; }