From a563e606b33b465a10ec358118d625b5892a4848 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 27 Dec 2015 19:25:28 -0800 Subject: [PATCH] Resolve PBP directories earlier in load process. This allows us to initialize the memory AFTER determining the proper size, in the case of remasters. It also avoids going through load twice. --- Core/Loaders.cpp | 30 +++++++++++++++++++++--------- Core/Loaders.h | 2 ++ Core/PSPLoaders.cpp | 11 +++++++---- Core/System.cpp | 12 +++--------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 8544c92468..3630589f04 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -18,6 +18,7 @@ #include #include +#include "base/stringutil.h" #include "file/file_util.h" #include "Common/FileUtil.h" @@ -191,19 +192,26 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) { return FILETYPE_UNKNOWN; } +FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader) { + IdentifiedFileType type = Identify_File(fileLoader); + if (type == FILETYPE_PSP_PBP_DIRECTORY && !endsWith(fileLoader->Path(), "/EBOOT.PBP")) { + std::string ebootFilename = fileLoader->Path() + "/EBOOT.PBP"; + + // Switch fileLoader to the actual EBOOT. + delete fileLoader; + fileLoader = ConstructFileLoader(ebootFilename); + } + return fileLoader; +} + bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) { FileLoader *&fileLoader = *fileLoaderPtr; // Note that this can modify filename! switch (Identify_File(fileLoader)) { case FILETYPE_PSP_PBP_DIRECTORY: { - std::string filename = fileLoader->Path(); - std::string ebootFilename = filename + "/EBOOT.PBP"; - - // Switch fileLoader to the EBOOT. - delete fileLoader; - fileLoader = ConstructFileLoader(ebootFilename); - + // TODO: Perhaps we should/can never get here now? + fileLoader = ResolveFileLoaderTarget(fileLoader); if (fileLoader->Exists()) { INFO_LOG(LOADER, "File is a PBP in a directory!"); IdentifiedFileType ebootType = Identify_File(fileLoader); @@ -216,10 +224,14 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) { *error_string = "PS1 EBOOTs are not supported by PPSSPP."; return false; } - std::string path = filename; + std::string path = fileLoader->Path(); size_t pos = path.find("/PSP/GAME/"); - if (pos != std::string::npos) + if (pos != std::string::npos) { + if (path.rfind("/EBOOT.PBP") != std::string::npos) { + path = path.substr(0, path.length() - strlen("/EBOOT.PBP")); + } pspFileSystem.SetStartingDirectory("ms0:" + path.substr(pos)); + } return Load_PSP_ELF_PBP(fileLoader, error_string); } else { *error_string = "No EBOOT.PBP, misidentified game"; diff --git a/Core/Loaders.h b/Core/Loaders.h index c5dbbdc579..f7d297923f 100644 --- a/Core/Loaders.h +++ b/Core/Loaders.h @@ -79,6 +79,8 @@ public: }; FileLoader *ConstructFileLoader(const std::string &filename); +// Resolve to the target binary, ISO, or other file (e.g. from a directory.) +FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader); // This can modify the string, for example for stripping off the "/EBOOT.PBP" // for a FILETYPE_PSP_PBP_DIRECTORY. diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index eb309faccb..b0e51d6ca2 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -274,15 +274,13 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) path = ReplaceAll(path, "/", "\\"); #endif - if (!PSP_CoreParameter().mountRoot.empty()) - { + if (!PSP_CoreParameter().mountRoot.empty()) { // We don't want to worry about .. and cwd and such. const std::string rootNorm = NormalizePath(PSP_CoreParameter().mountRoot + "/"); const std::string pathNorm = NormalizePath(path + "/"); // If root is not a subpath of path, we can't boot the game. - if (!startsWith(pathNorm, rootNorm)) - { + if (!startsWith(pathNorm, rootNorm)) { *error_string = "Cannot boot ELF located outside mountRoot."; return false; } @@ -291,6 +289,11 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) file = filepath + "/" + file; path = rootNorm + "/"; pspFileSystem.SetStartingDirectory(filepath); + } else { + size_t pos = path.find("/PSP/GAME/"); + if (pos != std::string::npos) { + pspFileSystem.SetStartingDirectory("ms0:" + path.substr(pos)); + } } DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path); diff --git a/Core/System.cpp b/Core/System.cpp index 5d726ba2ad..e548e8e75a 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -184,7 +184,7 @@ void CPU_Init() { Memory::g_PSPModel = g_Config.iPSPModel; std::string filename = coreParameter.fileToStart; - loadedFile = ConstructFileLoader(filename); + loadedFile = ResolveFileLoaderTarget(ConstructFileLoader(filename)); #ifdef _M_X64 if (g_Config.bCacheFullIsoInRam) { loadedFile = new RamCachingFileLoader(loadedFile); @@ -206,17 +206,11 @@ void CPU_Init() { case FILETYPE_PSP_DISC_DIRECTORY: InitMemoryForGameISO(loadedFile); break; - case FILETYPE_PSP_PBP_DIRECTORY: { - // TODO: Can we get this lower into LoadFile? - std::string ebootFilename = loadedFile->Path() + "/EBOOT.PBP"; - FileLoader *tempLoader = ConstructFileLoader(ebootFilename); - InitMemoryForGamePBP(tempLoader); - delete tempLoader; - break; - } case FILETYPE_PSP_PBP: InitMemoryForGamePBP(loadedFile); break; + case FILETYPE_PSP_PBP_DIRECTORY: + ERROR_LOG(LOADER, "PBP directory resolution failed."); default: break; }