From 62d08e2d172a072d4547f26a6b2740658054fc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 26 May 2017 21:29:15 +0200 Subject: [PATCH] DiscIO: Fix the wrong NAND root being used The whole NANDContentLoader stuff is truly awful and will be removed as soon as possible. For now, this fixes a bug that was exposed by std::optional::operator*. --- Source/Core/DiscIO/NANDContentLoader.cpp | 14 ++++++++------ Source/Core/DiscIO/NANDContentLoader.h | 10 +++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index b55efc413b..e9700ac1e2 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -94,7 +94,8 @@ bool CNANDContentDataBuffer::GetRange(u32 start, u32 size, u8* buffer) return true; } -CNANDContentLoader::CNANDContentLoader(const std::string& content_name) +CNANDContentLoader::CNANDContentLoader(const std::string& content_name, Common::FromWhichRoot from) + : m_root(from) { m_Valid = Initialize(content_name); } @@ -185,7 +186,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector& data_ap u32 data_app_offset = 0; const std::vector title_key = m_ticket.GetTitleKey(); - IOS::ES::SharedContentMap shared_content{Common::FromWhichRoot::FROM_SESSION_ROOT}; + IOS::ES::SharedContentMap shared_content{m_root}; for (size_t i = 0; i < contents.size(); ++i) { @@ -223,14 +224,15 @@ CNANDContentManager::~CNANDContentManager() { } -const CNANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& content_path) +const CNANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& content_path, + Common::FromWhichRoot from) { auto it = m_map.find(content_path); if (it != m_map.end()) return *it->second; return *m_map - .emplace_hint(it, std::make_pair(content_path, - std::make_unique(content_path))) + .emplace_hint(it, std::make_pair(content_path, std::make_unique( + content_path, from))) ->second; } @@ -238,7 +240,7 @@ const CNANDContentLoader& CNANDContentManager::GetNANDLoader(u64 title_id, Common::FromWhichRoot from) { std::string path = Common::GetTitleContentPath(title_id, from); - return GetNANDLoader(path); + return GetNANDLoader(path, from); } void CNANDContentManager::ClearCache() diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h index af4ff4909c..7dee6b488c 100644 --- a/Source/Core/DiscIO/NANDContentLoader.h +++ b/Source/Core/DiscIO/NANDContentLoader.h @@ -75,7 +75,7 @@ struct SNANDContent class CNANDContentLoader final { public: - explicit CNANDContentLoader(const std::string& content_name); + explicit CNANDContentLoader(const std::string& content_name, Common::FromWhichRoot from); ~CNANDContentLoader(); bool IsValid() const; @@ -90,6 +90,7 @@ private: bool m_Valid = false; bool m_IsWAD = false; + Common::FromWhichRoot m_root; std::string m_Path; IOS::ES::TMDReader m_tmd; IOS::ES::TicketReader m_ticket; @@ -107,8 +108,11 @@ public: return instance; } - const CNANDContentLoader& GetNANDLoader(const std::string& content_path); - const CNANDContentLoader& GetNANDLoader(u64 title_id, Common::FromWhichRoot from); + const CNANDContentLoader& + GetNANDLoader(const std::string& content_path, + Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT); + const CNANDContentLoader& + GetNANDLoader(u64 title_id, Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT); void ClearCache(); private: