From 868a3d6dd5a67d64b04c6319710356e9d8a61861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 11 Dec 2013 14:22:25 +0100 Subject: [PATCH] Load unknown.png for ELFs masquerading as PBP --- Core/ELF/PBPReader.cpp | 9 ++++++++- Core/ELF/PBPReader.h | 4 +++- UI/GameInfoCache.cpp | 16 ++++++++++++---- UI/GameInfoCache.h | 1 + UI/MainScreen.cpp | 1 - 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Core/ELF/PBPReader.cpp b/Core/ELF/PBPReader.cpp index 52672c5dc6..06a17d98d5 100644 --- a/Core/ELF/PBPReader.cpp +++ b/Core/ELF/PBPReader.cpp @@ -23,9 +23,10 @@ #include "Common/FileUtil.h" #include "Core/ELF/PBPReader.h" -PBPReader::PBPReader(const char *filename) : header_() { +PBPReader::PBPReader(const char *filename) : header_(), isELF_(false) { file_ = File::OpenCFile(filename, "rb"); if (!file_) { + ERROR_LOG(LOADER, "Failed to open PBP file %s", filename); return; } @@ -34,6 +35,12 @@ PBPReader::PBPReader(const char *filename) : header_() { fseek(file_, 0, SEEK_SET); fread((char *)&header_, 1, sizeof(header_), file_); if (memcmp(header_.magic, "\0PBP", 4) != 0) { + if (memcmp(header_.magic, "\nFLE", 4) != 0) { + DEBUG_LOG(LOADER, "%s: File actually an ELF, not a PBP", filename); + isELF_ = true; + } else { + ERROR_LOG(LOADER, "Magic number in %s indicated no PBP: %s", filename, header_.magic); + } fclose(file_); file_ = 0; return; diff --git a/Core/ELF/PBPReader.h b/Core/ELF/PBPReader.h index e415c851ce..791365af12 100644 --- a/Core/ELF/PBPReader.h +++ b/Core/ELF/PBPReader.h @@ -43,6 +43,7 @@ public: ~PBPReader(); bool IsValid() const { return file_ != 0; } + bool IsELF() const { return file_ == 0 && isELF_; } // Delete the returned buffer with delete []. u8 *GetSubFile(PBPSubFile file, size_t *outSize); @@ -61,4 +62,5 @@ private: FILE *file_; size_t fileSize_; const PBPHeader header_; -}; \ No newline at end of file + bool isELF_; +}; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index da9e6349d2..6bdb2f9603 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -236,7 +236,10 @@ public: return; std::string filename = gamePath_; + info_->path = gamePath_; info_->fileType = Identify_File(filename); + // Fallback title + info_->title = getFilename(info_->path); switch (info_->fileType) { case FILETYPE_PSP_PBP: @@ -247,8 +250,13 @@ public: pbpFile += "/EBOOT.PBP"; PBPReader pbp(pbpFile.c_str()); - if (!pbp.IsValid()) + if (!pbp.IsValid()) { + if (pbp.IsELF()) { + goto handleELF; + } + ERROR_LOG(LOADER, "invalid pbp %s\n", pbpFile.c_str()); return; + } // First, PARAM.SFO. size_t sfoSize; @@ -265,7 +273,9 @@ public: lock_guard lock(info_->lock); if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) { pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData); + printf("a %s\n", info_->path.c_str()); } else { + printf("b %s\n", info_->path.c_str()); // Read standard icon size_t sz; DEBUG_LOG(LOADER, "Loading unknown.png because a PBP was missing an icon"); @@ -288,12 +298,12 @@ public: break; case FILETYPE_PSP_ELF: +handleELF: // An elf on its own has no usable information, no icons, no nothing. info_->title = getFilename(filename); info_->id = "ELF000000"; info_->id_version = "ELF000000_1.00"; info_->paramSFOLoaded = true; - { // Read standard icon size_t sz; @@ -305,7 +315,6 @@ public: } delete [] contents; } - break; case FILETYPE_PSP_DISC_DIRECTORY: @@ -422,7 +431,6 @@ void GameInfoCache::Decimate() { } void GameInfoCache::Clear() { - ILOG("Wiping GameInfoCache: %i items", info_.size()); if (gameInfoWQ_) gameInfoWQ_->Flush(); for (auto iter = info_.begin(); iter != info_.end(); iter++) { diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 77f1616d66..a1f9f7d4b5 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -67,6 +67,7 @@ public: recursive_mutex lock; FileInfo fileInfo; + std::string path; std::string title; // for easy access, also available in paramSFO. std::string id; std::string id_version; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 37026cb556..bdcaff3f8d 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -134,7 +134,6 @@ void GameButton::Draw(UIContext &dc) { style = dc.theme->itemDownStyle; if (!gridStyle_ || !texture) { - // w = 144 * 80 / 50; h = 50; if (HasFocus()) style = down_ ? dc.theme->itemDownStyle : dc.theme->itemFocusedStyle;