From c987f58319be3de0cd392e757c4ff375162c196a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 18 Mar 2017 15:01:03 +0100 Subject: [PATCH] Check whether WAD is a channel before reading names Dolphin assumes that content 0 is opening.bnr, without checking whether content 0 exists or if it is even supposed to be there (it's only there for channels). This results in sometimes reading garbage. This adds a check to only try to read names from content 0's header if the title is a channel (channel, system channel or game channel). --- Source/Core/Core/IOS/ES/Formats.cpp | 7 +++++++ Source/Core/Core/IOS/ES/Formats.h | 1 + Source/Core/DiscIO/VolumeWad.cpp | 3 +++ Source/Core/DolphinWX/ISOFile.cpp | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 484273d2d9..60900dec60 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -33,6 +33,13 @@ bool IsDiscTitle(u64 title_id) IsTitleType(title_id, TitleType::GameWithChannel); } +bool IsChannel(u64 title_id) +{ + return IsTitleType(title_id, TitleType::Channel) || + IsTitleType(title_id, TitleType::SystemChannel) || + IsTitleType(title_id, TitleType::GameWithChannel); +} + bool Content::IsShared() const { return (type & 0x8000) != 0; diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index ed0ec73caf..d5543599c1 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -31,6 +31,7 @@ enum class TitleType : u32 bool IsTitleType(u64 title_id, TitleType title_type); bool IsDiscTitle(u64 title_id); +bool IsChannel(u64 title_id); #pragma pack(push, 4) struct TMDHeader diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 79e5423d54..a06c7483e8 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -130,6 +130,9 @@ Platform CVolumeWAD::GetVolumeType() const std::map CVolumeWAD::GetLongNames() const { + if (!m_tmd.IsValid() || !IOS::ES::IsChannel(m_tmd.GetTitleId())) + return {}; + std::vector name_data(NAMES_TOTAL_BYTES); if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data())) return std::map(); diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 0962f17893..23768143bd 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -36,7 +36,7 @@ #include "DolphinWX/ISOFile.h" #include "DolphinWX/WxUtils.h" -static const u32 CACHE_REVISION = 0x128; // Last changed in PR 4542 +static const u32 CACHE_REVISION = 0x129; // Last changed in PR 5102 static std::string GetLanguageString(DiscIO::Language language, std::map strings)