From 235ecfbed71986f0be2ecf469a10e1105dcb3c96 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Apr 2015 17:44:53 +0200 Subject: Return GetNames languages, to avoid hardcoded language lists in callers This makes the code cleaner and also leads to some user-visible changes: The wx game properties will no longer let the user select WAD languages that don't have any names. The Qt game list will now display names using the languages set in the configuration instead of always using English for PAL GC games and Japanese for WADs. If a WAD doesn't have a name in the user's preferred language, English is now selected as a fallback before Japanese. --- Source/Core/DiscIO/BannerLoader.h | 6 ++-- Source/Core/DiscIO/BannerLoaderGC.cpp | 60 ++++++++++++++++++--------------- Source/Core/DiscIO/BannerLoaderGC.h | 5 +-- Source/Core/DiscIO/BannerLoaderWii.cpp | 23 ++++++++----- Source/Core/DiscIO/BannerLoaderWii.h | 5 +-- Source/Core/DiscIO/Volume.h | 60 +++++++++++++++++++++------------ Source/Core/DiscIO/VolumeCommon.cpp | 3 +- Source/Core/DiscIO/VolumeDirectory.cpp | 7 ++-- Source/Core/DiscIO/VolumeDirectory.h | 2 +- Source/Core/DiscIO/VolumeGC.cpp | 7 ++-- Source/Core/DiscIO/VolumeGC.h | 3 +- Source/Core/DiscIO/VolumeWad.cpp | 20 +++++------ Source/Core/DiscIO/VolumeWad.h | 3 +- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 7 ++-- Source/Core/DiscIO/VolumeWiiCrypted.h | 3 +- 15 files changed, 125 insertions(+), 89 deletions(-) (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/BannerLoader.h b/Source/Core/DiscIO/BannerLoader.h index 7d6a25b8cf..31a09f56d0 100644 --- a/Source/Core/DiscIO/BannerLoader.h +++ b/Source/Core/DiscIO/BannerLoader.h @@ -4,10 +4,12 @@ #pragma once +#include #include #include #include "Common/CommonTypes.h" +#include "DiscIO/Volume.h" namespace DiscIO { @@ -28,9 +30,9 @@ public: virtual std::vector GetBanner(int* pWidth, int* pHeight) = 0; - virtual std::vector GetNames() = 0; + virtual std::map GetNames() = 0; virtual std::string GetCompany() = 0; - virtual std::vector GetDescriptions() = 0; + virtual std::map GetDescriptions() = 0; bool IsValid() { diff --git a/Source/Core/DiscIO/BannerLoaderGC.cpp b/Source/Core/DiscIO/BannerLoaderGC.cpp index ce265a016e..a5da3c4512 100644 --- a/Source/Core/DiscIO/BannerLoaderGC.cpp +++ b/Source/Core/DiscIO/BannerLoaderGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -60,9 +61,9 @@ std::vector CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) } -std::vector CBannerLoaderGC::GetNames() +std::map CBannerLoaderGC::GetNames() { - std::vector names; + std::map names; if (!IsValid()) { @@ -70,16 +71,21 @@ std::vector CBannerLoaderGC::GetNames() } u32 name_count = 0; + IVolume::ELanguage language; + bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; // find Banner type switch (m_BNRType) { case CBannerLoaderGC::BANNER_BNR1: name_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; break; + // English, German, French, Spanish, Italian, Dutch case CBannerLoaderGC::BANNER_BNR2: name_count = 6; + language = IVolume::ELanguage::LANGUAGE_ENGLISH; break; default: @@ -88,20 +94,16 @@ std::vector CBannerLoaderGC::GetNames() auto const banner = reinterpret_cast(m_pBannerFile); - for (u32 i = 0; i != name_count; ++i) + for (u32 i = 0; i < name_count; ++i) { auto& comment = banner->comment[i]; + std::string name = GetDecodedString(comment.longTitle); - if (comment.longTitle[0]) - { - auto& data = comment.longTitle; - names.push_back(GetDecodedString(data)); - } - else - { - auto& data = comment.shortTitle; - names.push_back(GetDecodedString(data)); - } + if (name.empty()) + name = GetDecodedString(comment.shortTitle); + + if (!name.empty()) + names[(IVolume::ELanguage)(language + i)] = name; } return names; @@ -123,9 +125,9 @@ std::string CBannerLoaderGC::GetCompany() } -std::vector CBannerLoaderGC::GetDescriptions() +std::map CBannerLoaderGC::GetDescriptions() { - std::vector descriptions; + std::map descriptions; if (!IsValid()) { @@ -133,16 +135,20 @@ std::vector CBannerLoaderGC::GetDescriptions() } u32 desc_count = 0; + IVolume::ELanguage language; + bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; // find Banner type switch (m_BNRType) { case CBannerLoaderGC::BANNER_BNR1: desc_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; break; // English, German, French, Spanish, Italian, Dutch case CBannerLoaderGC::BANNER_BNR2: + language = IVolume::ELanguage::LANGUAGE_ENGLISH; desc_count = 6; break; @@ -152,10 +158,13 @@ std::vector CBannerLoaderGC::GetDescriptions() auto banner = reinterpret_cast(m_pBannerFile); - for (u32 i = 0; i != desc_count; ++i) + for (u32 i = 0; i < desc_count; ++i) { auto& data = banner->comment[i].comment; - descriptions.push_back(GetDecodedString(data)); + std::string description = GetDecodedString(data); + + if (!description.empty()) + descriptions[(IVolume::ELanguage)(language + i)] = description; } return descriptions; @@ -164,20 +173,15 @@ std::vector CBannerLoaderGC::GetDescriptions() CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() { u32 bannerSignature = *(u32*)m_pBannerFile; - CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN; switch (bannerSignature) { - // "BNR1" - case 0x31524e42: - type = CBannerLoaderGC::BANNER_BNR1; - break; - - // "BNR2" - case 0x32524e42: - type = CBannerLoaderGC::BANNER_BNR2; - break; + case 0x31524e42: // "BNR1" + return CBannerLoaderGC::BANNER_BNR1; + case 0x32524e42: // "BNR2" + return CBannerLoaderGC::BANNER_BNR2; + default: + return CBannerLoaderGC::BANNER_UNKNOWN; } - return type; } } // namespace diff --git a/Source/Core/DiscIO/BannerLoaderGC.h b/Source/Core/DiscIO/BannerLoaderGC.h index 94e261699c..b381e10f92 100644 --- a/Source/Core/DiscIO/BannerLoaderGC.h +++ b/Source/Core/DiscIO/BannerLoaderGC.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -28,9 +29,9 @@ public: virtual std::vector GetBanner(int* pWidth, int* pHeight) override; - virtual std::vector GetNames() override; + virtual std::map GetNames() override; virtual std::string GetCompany() override; - virtual std::vector GetDescriptions() override; + virtual std::map GetDescriptions() override; private: enum diff --git a/Source/Core/DiscIO/BannerLoaderWii.cpp b/Source/Core/DiscIO/BannerLoaderWii.cpp index eaab54a942..1de9120c10 100644 --- a/Source/Core/DiscIO/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/BannerLoaderWii.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -91,14 +92,15 @@ bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::stri return false; } -std::vector CBannerLoaderWii::GetNames() +std::map CBannerLoaderWii::GetNames() { - std::vector ret(1); + std::map result; - if (!GetStringFromComments(NAME_IDX, ret[0])) - ret.clear(); + std::string name; + if (GetStringFromComments(NAME_IDX, name)) + result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; - return ret; + return result; } std::string CBannerLoaderWii::GetCompany() @@ -106,11 +108,14 @@ std::string CBannerLoaderWii::GetCompany() return ""; } -std::vector CBannerLoaderWii::GetDescriptions() +std::map CBannerLoaderWii::GetDescriptions() { - std::vector result(1); - if (!GetStringFromComments(DESC_IDX, result[0])) - result.clear(); + std::map result; + + std::string name; + if (GetStringFromComments(DESC_IDX, name)) + result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; + return result; } diff --git a/Source/Core/DiscIO/BannerLoaderWii.h b/Source/Core/DiscIO/BannerLoaderWii.h index 1bbe077509..29d3b0f470 100644 --- a/Source/Core/DiscIO/BannerLoaderWii.h +++ b/Source/Core/DiscIO/BannerLoaderWii.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -25,9 +26,9 @@ public: virtual std::vector GetBanner(int* pWidth, int* pHeight) override; - virtual std::vector GetNames() override; + virtual std::map GetNames() override; virtual std::string GetCompany() override; - virtual std::vector GetDescriptions() override; + virtual std::map GetDescriptions() override; private: enum diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 6efe04a37f..50e09c34d1 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -16,6 +17,43 @@ namespace DiscIO class IVolume { public: + // Increment CACHE_REVISION if the enums below are modified (ISOFile.cpp & GameFile.cpp) + enum ECountry + { + COUNTRY_EUROPE = 0, + COUNTRY_JAPAN, + COUNTRY_USA, + COUNTRY_AUSTRALIA, + COUNTRY_FRANCE, + COUNTRY_GERMANY, + COUNTRY_ITALY, + COUNTRY_KOREA, + COUNTRY_NETHERLANDS, + COUNTRY_RUSSIA, + COUNTRY_SPAIN, + COUNTRY_TAIWAN, + COUNTRY_WORLD, + COUNTRY_UNKNOWN, + NUMBER_OF_COUNTRIES + }; + + // Languages 0 - 9 match the official Wii language numbering. + // Languages 1 - 6 match the official GC PAL languages 0 - 5. + enum ELanguage + { + LANGUAGE_JAPANESE = 0, + LANGUAGE_ENGLISH = 1, + LANGUAGE_GERMAN = 2, + LANGUAGE_FRENCH = 3, + LANGUAGE_SPANISH = 4, + LANGUAGE_ITALIAN = 5, + LANGUAGE_DUTCH = 6, + LANGUAGE_SIMPLIFIED_CHINESE = 7, + LANGUAGE_TRADITIONAL_CHINESE = 8, + LANGUAGE_KOREAN = 9, + LANGUAGE_UNKNOWN + }; + IVolume() {} virtual ~IVolume() {} @@ -39,7 +77,7 @@ public: virtual int GetRevision() const { return 0; } // TODO: eliminate? virtual std::string GetName() const; - virtual std::vector GetNames() const = 0; + virtual std::map GetNames() const = 0; virtual u32 GetFSTSize() const = 0; virtual std::string GetApploaderDate() const = 0; @@ -50,26 +88,6 @@ public: virtual bool CheckIntegrity() const { return false; } virtual bool ChangePartition(u64 offset) { return false; } - // Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp) - enum ECountry - { - COUNTRY_EUROPE = 0, - COUNTRY_JAPAN, - COUNTRY_USA, - COUNTRY_AUSTRALIA, - COUNTRY_FRANCE, - COUNTRY_GERMANY, - COUNTRY_ITALY, - COUNTRY_KOREA, - COUNTRY_NETHERLANDS, - COUNTRY_RUSSIA, - COUNTRY_SPAIN, - COUNTRY_TAIWAN, - COUNTRY_WORLD, - COUNTRY_UNKNOWN, - NUMBER_OF_COUNTRIES - }; - virtual ECountry GetCountry() const = 0; virtual u64 GetSize() const = 0; diff --git a/Source/Core/DiscIO/VolumeCommon.cpp b/Source/Core/DiscIO/VolumeCommon.cpp index 87f0c722a7..1728e78732 100644 --- a/Source/Core/DiscIO/VolumeCommon.cpp +++ b/Source/Core/DiscIO/VolumeCommon.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include #include #include @@ -104,7 +105,7 @@ std::string IVolume::GetName() const if (names.empty()) return ""; else - return names[0]; + return names.cbegin()->second; } } diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 6f3e4ccb7f..9db6e58e46 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "Common/CommonPaths.h" @@ -183,9 +182,11 @@ std::string CVolumeDirectory::GetMakerID() const return "VOID"; } -std::vector CVolumeDirectory::GetNames() const +std::map CVolumeDirectory::GetNames() const { - return std::vector(1, (char*)(&m_diskHeader[0x20])); + std::map names; + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = (char*)(&m_diskHeader[0x20]); + return names; } void CVolumeDirectory::SetName(const std::string& name) diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h index c3e9c881c2..d283e9051b 100644 --- a/Source/Core/DiscIO/VolumeDirectory.h +++ b/Source/Core/DiscIO/VolumeDirectory.h @@ -39,7 +39,7 @@ public: std::string GetMakerID() const override; - std::vector GetNames() const override; + std::map GetNames() const override; void SetName(const std::string&); u32 GetFSTSize() const override; diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 132a630cf0..272408011e 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -92,15 +93,15 @@ int CVolumeGC::GetRevision() const return revision; } -std::vector CVolumeGC::GetNames() const +std::map CVolumeGC::GetNames() const { - std::vector names; + std::map names; auto const string_decoder = GetStringDecoder(GetCountry()); char name[0x60 + 1] = {}; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) - names.push_back(string_decoder(name)); + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); return names; } diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index c2efcd6e9f..e9757df948 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -27,7 +28,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector GetNames() const override; + std::map GetNames() const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 1dc746ea4d..5bc27738da 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -117,9 +118,9 @@ bool CVolumeWAD::IsWadFile() const return true; } -std::vector CVolumeWAD::GetNames() const +std::map CVolumeWAD::GetNames() const { - std::vector names; + std::map names; u32 footer_size; if (!Read(0x1C, 4, (u8*)&footer_size)) @@ -129,26 +130,23 @@ std::vector CVolumeWAD::GetNames() const footer_size = Common::swap32(footer_size); - //Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean - for (int i = 0; i != 10; ++i) + //Japanese, English, German, French, Spanish, Italian, Dutch, Simplified Chinese, Traditional Chinese, Korean + for (int i = 0; i < 10; ++i) { static const u32 string_length = 42; static const u32 bytes_length = string_length * sizeof(u16); u16 temp[string_length]; - if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp)) - { - names.push_back(""); - } - else + if (footer_size >= 0xF1 && Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp)) { std::wstring out_temp; out_temp.resize(string_length); std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); - - names.push_back(UTF16ToUTF8(out_temp)); + std::string name = UTF16ToUTF8(out_temp); + if (!name.empty()) + names[(IVolume::ELanguage)i] = name; } } diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index 3205da3a24..33dc213aee 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -30,7 +31,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector GetNames() const override; + std::map GetNames() const override; u32 GetFSTSize() const override { return 0; } std::string GetApploaderDate() const override { return "0"; } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 4c703fdb3f..935d18b8f8 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -191,15 +192,15 @@ int CVolumeWiiCrypted::GetRevision() const return revision; } -std::vector CVolumeWiiCrypted::GetNames() const +std::map CVolumeWiiCrypted::GetNames() const { - std::vector names; + std::map names; auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry()); char name[0xFF] = {}; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name, true)) - names.push_back(string_decoder(name)); + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); return names; } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index 4816bc2ebc..f4712fd230 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -30,7 +31,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector GetNames() const override; + std::map GetNames() const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; -- cgit v1.2.3 From ee694e327ada8c42949a3907d6fa222f73f276b0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 10 Apr 2015 22:10:49 +0200 Subject: Get rid of banner loaders and move their functionality to volumes Having some data available in banner loaders and some other data data available in volumes gets messy, especially with GetNames(), which is available in both but returns different results depending on which one is used. This change drops support for reading names and descriptions from Wii save data. --- Source/Core/DiscIO/BannerLoader.cpp | 28 ----- Source/Core/DiscIO/BannerLoader.h | 49 -------- Source/Core/DiscIO/BannerLoaderGC.cpp | 187 ------------------------------ Source/Core/DiscIO/BannerLoaderGC.h | 87 -------------- Source/Core/DiscIO/BannerLoaderWii.cpp | 122 ------------------- Source/Core/DiscIO/BannerLoaderWii.h | 64 ---------- Source/Core/DiscIO/CMakeLists.txt | 5 +- Source/Core/DiscIO/DiscIO.vcxproj | 6 - Source/Core/DiscIO/DiscIO.vcxproj.filters | 18 --- Source/Core/DiscIO/Volume.h | 26 ++++- Source/Core/DiscIO/VolumeCommon.cpp | 55 +++++++-- Source/Core/DiscIO/VolumeDirectory.cpp | 13 ++- Source/Core/DiscIO/VolumeDirectory.h | 2 + Source/Core/DiscIO/VolumeGC.cpp | 167 ++++++++++++++++++++++++-- Source/Core/DiscIO/VolumeGC.h | 45 ++++++- Source/Core/DiscIO/VolumeWad.h | 5 +- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 18 +-- Source/Core/DiscIO/VolumeWiiCrypted.h | 1 + 18 files changed, 299 insertions(+), 599 deletions(-) delete mode 100644 Source/Core/DiscIO/BannerLoader.cpp delete mode 100644 Source/Core/DiscIO/BannerLoader.h delete mode 100644 Source/Core/DiscIO/BannerLoaderGC.cpp delete mode 100644 Source/Core/DiscIO/BannerLoaderGC.h delete mode 100644 Source/Core/DiscIO/BannerLoaderWii.cpp delete mode 100644 Source/Core/DiscIO/BannerLoaderWii.h (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/BannerLoader.cpp b/Source/Core/DiscIO/BannerLoader.cpp deleted file mode 100644 index b5353b5a0f..0000000000 --- a/Source/Core/DiscIO/BannerLoader.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include - -#include "DiscIO/BannerLoader.h" -#include "DiscIO/BannerLoaderGC.h" -#include "DiscIO/BannerLoaderWii.h" -#include "DiscIO/Filesystem.h" - -namespace DiscIO -{ - -class IBannerLoader; -class IVolume; - -IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume) -{ - if (pVolume->IsWiiDisc() || pVolume->IsWadFile()) - return new CBannerLoaderWii(pVolume); - if (_rFileSystem.IsValid()) - return new CBannerLoaderGC(_rFileSystem, pVolume); - - return nullptr; -} - -} // namespace diff --git a/Source/Core/DiscIO/BannerLoader.h b/Source/Core/DiscIO/BannerLoader.h deleted file mode 100644 index 31a09f56d0..0000000000 --- a/Source/Core/DiscIO/BannerLoader.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "Common/CommonTypes.h" -#include "DiscIO/Volume.h" - -namespace DiscIO -{ - -class IFileSystem; -class IVolume; - -class IBannerLoader -{ -public: - IBannerLoader() - : m_IsValid(false) - , m_pBannerFile(nullptr) - {} - - virtual ~IBannerLoader() - {} - - virtual std::vector GetBanner(int* pWidth, int* pHeight) = 0; - - virtual std::map GetNames() = 0; - virtual std::string GetCompany() = 0; - virtual std::map GetDescriptions() = 0; - - bool IsValid() - { - return m_IsValid; - } - -protected: - bool m_IsValid; - u8* m_pBannerFile; -}; - -IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume); - -} // namespace DiscIO diff --git a/Source/Core/DiscIO/BannerLoaderGC.cpp b/Source/Core/DiscIO/BannerLoaderGC.cpp deleted file mode 100644 index a5da3c4512..0000000000 --- a/Source/Core/DiscIO/BannerLoaderGC.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include -#include -#include - -#include "Common/ColorUtil.h" -#include "Common/CommonTypes.h" -#include "Common/MsgHandler.h" -#include "Common/Logging/Log.h" -#include "DiscIO/BannerLoaderGC.h" -#include "DiscIO/Filesystem.h" -#include "DiscIO/Volume.h" - -namespace DiscIO -{ -CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume) - : m_country(volume->GetCountry()) -{ - // load the opening.bnr - size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr"); - if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE) - { - m_pBannerFile = new u8[FileSize]; - if (m_pBannerFile) - { - _rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize); - m_BNRType = getBannerType(); - if (m_BNRType == BANNER_UNKNOWN) - PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.", - _rFileSystem.GetVolume()->GetName().c_str()); - else m_IsValid = true; - } - } - else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", - (unsigned long)FileSize); -} - - -CBannerLoaderGC::~CBannerLoaderGC() -{ - if (m_pBannerFile) - { - delete [] m_pBannerFile; - m_pBannerFile = nullptr; - } -} - -std::vector CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) -{ - std::vector Buffer; - Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT); - auto const pBanner = (DVDBanner*)m_pBannerFile; - ColorUtil::decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT); - *pWidth = DVD_BANNER_WIDTH; - *pHeight = DVD_BANNER_HEIGHT; - return Buffer; -} - - -std::map CBannerLoaderGC::GetNames() -{ - std::map names; - - if (!IsValid()) - { - return names; - } - - u32 name_count = 0; - IVolume::ELanguage language; - bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; - - // find Banner type - switch (m_BNRType) - { - case CBannerLoaderGC::BANNER_BNR1: - name_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - // English, German, French, Spanish, Italian, Dutch - case CBannerLoaderGC::BANNER_BNR2: - name_count = 6; - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - default: - break; - } - - auto const banner = reinterpret_cast(m_pBannerFile); - - for (u32 i = 0; i < name_count; ++i) - { - auto& comment = banner->comment[i]; - std::string name = GetDecodedString(comment.longTitle); - - if (name.empty()) - name = GetDecodedString(comment.shortTitle); - - if (!name.empty()) - names[(IVolume::ELanguage)(language + i)] = name; - } - - return names; -} - - -std::string CBannerLoaderGC::GetCompany() -{ - std::string company; - - if (IsValid()) - { - auto const pBanner = (DVDBanner*)m_pBannerFile; - auto& data = pBanner->comment[0].shortMaker; - company = GetDecodedString(data); - } - - return company; -} - - -std::map CBannerLoaderGC::GetDescriptions() -{ - std::map descriptions; - - if (!IsValid()) - { - return descriptions; - } - - u32 desc_count = 0; - IVolume::ELanguage language; - bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; - - // find Banner type - switch (m_BNRType) - { - case CBannerLoaderGC::BANNER_BNR1: - desc_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - // English, German, French, Spanish, Italian, Dutch - case CBannerLoaderGC::BANNER_BNR2: - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - desc_count = 6; - break; - - default: - break; - } - - auto banner = reinterpret_cast(m_pBannerFile); - - for (u32 i = 0; i < desc_count; ++i) - { - auto& data = banner->comment[i].comment; - std::string description = GetDecodedString(data); - - if (!description.empty()) - descriptions[(IVolume::ELanguage)(language + i)] = description; - } - - return descriptions; -} - -CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() -{ - u32 bannerSignature = *(u32*)m_pBannerFile; - switch (bannerSignature) - { - case 0x31524e42: // "BNR1" - return CBannerLoaderGC::BANNER_BNR1; - case 0x32524e42: // "BNR2" - return CBannerLoaderGC::BANNER_BNR2; - default: - return CBannerLoaderGC::BANNER_UNKNOWN; - } -} - -} // namespace diff --git a/Source/Core/DiscIO/BannerLoaderGC.h b/Source/Core/DiscIO/BannerLoaderGC.h deleted file mode 100644 index b381e10f92..0000000000 --- a/Source/Core/DiscIO/BannerLoaderGC.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include -#include - -#include "Common/CommonTypes.h" - -#include "DiscIO/BannerLoader.h" -#include "DiscIO/Volume.h" -#include "DiscIO/VolumeGC.h" - -namespace DiscIO -{ - -class IFileSystem; - -class CBannerLoaderGC - : public IBannerLoader -{ -public: - CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume); - virtual ~CBannerLoaderGC(); - - virtual std::vector GetBanner(int* pWidth, int* pHeight) override; - - virtual std::map GetNames() override; - virtual std::string GetCompany() override; - virtual std::map GetDescriptions() override; - -private: - enum - { - DVD_BANNER_WIDTH = 96, - DVD_BANNER_HEIGHT = 32 - }; - - enum BANNER_TYPE - { - BANNER_UNKNOWN, - BANNER_BNR1, - BANNER_BNR2, - }; - - // Banner Comment - struct DVDBannerComment - { - char shortTitle[32]; // Short game title shown in IPL menu - char shortMaker[32]; // Short developer, publisher names shown in IPL menu - char longTitle[64]; // Long game title shown in IPL game start screen - char longMaker[64]; // Long developer, publisher names shown in IPL game start screen - char comment[128]; // Game description shown in IPL game start screen in two lines. - }; - - // "opening.bnr" file format for EU console - struct DVDBanner - { - u32 id; // 'BNR2' - u32 padding[7]; - u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image - DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type) - }; - - static const u32 BNR1_SIZE = sizeof(DVDBanner) - sizeof(DVDBannerComment) * 5; - static const u32 BNR2_SIZE = sizeof(DVDBanner); - - template - std::string GetDecodedString(const char (&data)[N]) - { - auto const string_decoder = CVolumeGC::GetStringDecoder(m_country); - - // strnlen to trim NULLs - return string_decoder(std::string(data, strnlen(data, sizeof(data)))); - } - - BANNER_TYPE m_BNRType; - BANNER_TYPE getBannerType(); - - DiscIO::IVolume::ECountry const m_country; -}; - -} // namespace diff --git a/Source/Core/DiscIO/BannerLoaderWii.cpp b/Source/Core/DiscIO/BannerLoaderWii.cpp deleted file mode 100644 index 1de9120c10..0000000000 --- a/Source/Core/DiscIO/BannerLoaderWii.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include -#include -#include -#include -#include - -#include "Common/ColorUtil.h" -#include "Common/CommonFuncs.h" -#include "Common/CommonTypes.h" -#include "Common/FileUtil.h" -#include "Common/StringUtil.h" - -#include "DiscIO/BannerLoaderWii.h" -#include "DiscIO/Volume.h" - -namespace DiscIO -{ - -CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume) -{ - u64 TitleID = 0; - pVolume->GetTitleID((u8*)&TitleID); - TitleID = Common::swap64(TitleID); - - std::string Filename = StringFromFormat("%stitle/%08x/%08x/data/banner.bin", - File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID); - - if (!File::Exists(Filename)) - { - m_IsValid = false; - return; - } - - // load the banner.bin - size_t FileSize = (size_t) File::GetSize(Filename); - - if (FileSize > 0) - { - m_pBannerFile = new u8[FileSize]; - File::IOFile pFile(Filename, "rb"); - if (pFile) - { - pFile.ReadBytes(m_pBannerFile, FileSize); - m_IsValid = true; - } - } -} - -CBannerLoaderWii::~CBannerLoaderWii() -{ - if (m_pBannerFile) - { - delete [] m_pBannerFile; - m_pBannerFile = nullptr; - } -} - -std::vector CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight) -{ - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - std::vector Buffer; - Buffer.resize(192 * 64); - ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64); - *pWidth = 192; - *pHeight = 64; - return Buffer; -} - -bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result) -{ - if (IsValid()) - { - auto const banner = reinterpret_cast(m_pBannerFile); - auto const src_ptr = banner->m_Comment[index]; - - // Trim at first nullptr - auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr; - - std::wstring src; - src.resize(length); - std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16); - result = UTF16ToUTF8(src); - - return true; - } - - return false; -} - -std::map CBannerLoaderWii::GetNames() -{ - std::map result; - - std::string name; - if (GetStringFromComments(NAME_IDX, name)) - result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; - - return result; -} - -std::string CBannerLoaderWii::GetCompany() -{ - return ""; -} - -std::map CBannerLoaderWii::GetDescriptions() -{ - std::map result; - - std::string name; - if (GetStringFromComments(DESC_IDX, name)) - result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; - - return result; -} - -} // namespace diff --git a/Source/Core/DiscIO/BannerLoaderWii.h b/Source/Core/DiscIO/BannerLoaderWii.h deleted file mode 100644 index 29d3b0f470..0000000000 --- a/Source/Core/DiscIO/BannerLoaderWii.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "Common/CommonTypes.h" -#include "DiscIO/BannerLoader.h" - -namespace DiscIO -{ - -class IVolume; - -class CBannerLoaderWii - : public IBannerLoader -{ -public: - CBannerLoaderWii(DiscIO::IVolume *pVolume); - - virtual ~CBannerLoaderWii(); - - virtual std::vector GetBanner(int* pWidth, int* pHeight) override; - - virtual std::map GetNames() override; - virtual std::string GetCompany() override; - virtual std::map GetDescriptions() override; - -private: - enum - { - TEXTURE_SIZE = 192 * 64 * 2, - ICON_SIZE = 48 * 48 * 2, - COMMENT_SIZE = 32 - }; - - enum CommentIndex - { - NAME_IDX, - DESC_IDX - }; - - struct SWiiBanner - { - u32 ID; - - u32 m_Flag; - u16 m_Speed; - u8 m_Unknown[22]; - - // Not null terminated! - u16 m_Comment[2][COMMENT_SIZE]; - u8 m_BannerTexture[TEXTURE_SIZE]; - u8 m_IconTexture[8][ICON_SIZE]; - }; - - bool GetStringFromComments(const CommentIndex index, std::string& s); -}; - -} // namespace diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index 7cc2859053..e9f20ffe8d 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -1,7 +1,4 @@ -set(SRCS BannerLoader.cpp - BannerLoaderGC.cpp - BannerLoaderWii.cpp - Blob.cpp +set(SRCS Blob.cpp CISOBlob.cpp WbfsBlob.cpp CompressedBlob.cpp diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj index 5ef6853456..b0a9ef63fd 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj +++ b/Source/Core/DiscIO/DiscIO.vcxproj @@ -35,9 +35,6 @@ - - - @@ -58,9 +55,6 @@ - - - diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters index 1f5f383831..3d27813cba 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj.filters +++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters @@ -24,15 +24,6 @@ DiscScrubber - - FileHandler - - - FileHandler - - - FileHandler - FileSystem @@ -89,15 +80,6 @@ DiscScrubber - - FileHandler - - - FileHandler - - - FileHandler - FileSystem diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 50e09c34d1..ff7e6a8b63 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -11,6 +11,7 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" +#include "Common/StringUtil.h" namespace DiscIO { @@ -74,10 +75,12 @@ public: } virtual std::string GetUniqueID() const = 0; virtual std::string GetMakerID() const = 0; - virtual int GetRevision() const { return 0; } - // TODO: eliminate? - virtual std::string GetName() const; + virtual int GetRevision() const = 0; + virtual std::string GetName() const = 0; virtual std::map GetNames() const = 0; + virtual std::map GetDescriptions() const { return std::map(); } + virtual std::string GetCompany() const { return std::string(); } + virtual std::vector GetBanner(int* width, int* height) const; virtual u32 GetFSTSize() const = 0; virtual std::string GetApploaderDate() const = 0; @@ -93,6 +96,23 @@ public: // Size on disc (compressed size) virtual u64 GetRawSize() const = 0; + +protected: + template + std::string DecodeString(const char(&data)[N]) const + { + // strnlen to trim NULLs + std::string string(data, strnlen(data, sizeof(data))); + + // There don't seem to be any GC discs with the country set to Taiwan... + // But maybe they would use Shift_JIS if they existed? Not sure + bool use_shift_jis = (COUNTRY_JAPAN == GetCountry() || COUNTRY_TAIWAN == GetCountry()); + + if (use_shift_jis) + return SHIFTJISToUTF8(string); + else + return CP1252ToUTF8(string); + } }; // Generic Switch function for all volumes diff --git a/Source/Core/DiscIO/VolumeCommon.cpp b/Source/Core/DiscIO/VolumeCommon.cpp index 1728e78732..e2c3117170 100644 --- a/Source/Core/DiscIO/VolumeCommon.cpp +++ b/Source/Core/DiscIO/VolumeCommon.cpp @@ -4,15 +4,59 @@ #include #include +#include #include +#include "Common/ColorUtil.h" +#include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" +#include "Common/FileUtil.h" +#include "Common/StringUtil.h" #include "Common/Logging/Log.h" #include "DiscIO/Volume.h" -// Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp) namespace DiscIO { + +static const unsigned int WII_BANNER_WIDTH = 192; +static const unsigned int WII_BANNER_HEIGHT = 64; +static const unsigned int WII_BANNER_SIZE = WII_BANNER_WIDTH * WII_BANNER_HEIGHT * 2; +static const unsigned int WII_BANNER_OFFSET = 0xA0; + +std::vector IVolume::GetBanner(int* width, int* height) const +{ + *width = 0; + *height = 0; + + u64 TitleID = 0; + GetTitleID((u8*)&TitleID); + TitleID = Common::swap64(TitleID); + + std::string file_name = StringFromFormat("%stitle/%08x/%08x/data/banner.bin", + File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID >> 32), (u32)TitleID); + if (!File::Exists(file_name)) + return std::vector(); + + if (File::GetSize(file_name) < WII_BANNER_OFFSET + WII_BANNER_SIZE) + return std::vector(); + + File::IOFile file(file_name, "rb"); + if (!file.Seek(WII_BANNER_OFFSET, SEEK_SET)) + return std::vector(); + + std::vector banner_file(WII_BANNER_SIZE); + if (!file.ReadBytes(banner_file.data(), banner_file.size())) + return std::vector(); + + std::vector image_buffer(WII_BANNER_WIDTH * WII_BANNER_HEIGHT); + ColorUtil::decode5A3image(image_buffer.data(), (u16*)banner_file.data(), WII_BANNER_WIDTH, WII_BANNER_HEIGHT); + + *width = WII_BANNER_WIDTH; + *height = WII_BANNER_HEIGHT; + return image_buffer; +} + +// Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp) IVolume::ECountry CountrySwitch(u8 country_code) { switch (country_code) @@ -99,13 +143,4 @@ u8 GetSysMenuRegion(u16 _TitleVersion) } } -std::string IVolume::GetName() const -{ - auto names = GetNames(); - if (names.empty()) - return ""; - else - return names.cbegin()->second; -} - } diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 9db6e58e46..876848b2d3 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -182,10 +182,21 @@ std::string CVolumeDirectory::GetMakerID() const return "VOID"; } +std::string CVolumeDirectory::GetName() const +{ + char name[0x60]; + if (Read(0x20, 0x60, (u8*)name, false)) + return DecodeString(name); + else + return ""; +} + std::map CVolumeDirectory::GetNames() const { std::map names; - names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = (char*)(&m_diskHeader[0x20]); + std::string name = GetName(); + if (!name.empty()) + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; return names; } diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h index d283e9051b..7187e8a017 100644 --- a/Source/Core/DiscIO/VolumeDirectory.h +++ b/Source/Core/DiscIO/VolumeDirectory.h @@ -39,6 +39,8 @@ public: std::string GetMakerID() const override; + int GetRevision() const override { return 0; } + std::string GetName() const override; std::map GetNames() const override; void SetName(const std::string&); diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 272408011e..dd18338f63 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -8,10 +8,13 @@ #include #include +#include "Common/ColorUtil.h" #include "Common/CommonTypes.h" #include "Common/StringUtil.h" +#include "Common/Logging/Log.h" #include "DiscIO/Blob.h" #include "DiscIO/FileMonitor.h" +#include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeGC.h" @@ -93,19 +96,133 @@ int CVolumeGC::GetRevision() const return revision; } +std::string CVolumeGC::GetName() const +{ + char name[0x60]; + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) + return DecodeString(name); + else + return ""; +} + std::map CVolumeGC::GetNames() const { std::map names; - auto const string_decoder = GetStringDecoder(GetCountry()); + if (!LoadBannerFile()) + return names; - char name[0x60 + 1] = {}; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) - names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); + u32 name_count = 0; + IVolume::ELanguage language; + bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; + + switch (m_banner_file_type) + { + case BANNER_BNR1: + name_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_BNR2: + name_count = 6; + language = IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_INVALID: + case BANNER_NOT_LOADED: + break; + } + + auto const banner = reinterpret_cast(m_banner_file.data()); + + for (u32 i = 0; i < name_count; ++i) + { + auto& comment = banner->comment[i]; + std::string name = DecodeString(comment.longTitle); + + if (name.empty()) + name = DecodeString(comment.shortTitle); + + if (!name.empty()) + names[(IVolume::ELanguage)(language + i)] = name; + } return names; } +std::map CVolumeGC::GetDescriptions() const +{ + std::map descriptions; + + if (!LoadBannerFile()) + return descriptions; + + u32 desc_count = 0; + IVolume::ELanguage language; + bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; + + switch (m_banner_file_type) + { + case BANNER_BNR1: + desc_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_BNR2: + language = IVolume::ELanguage::LANGUAGE_ENGLISH; + desc_count = 6; + break; + + case BANNER_INVALID: + case BANNER_NOT_LOADED: + break; + } + + auto banner = reinterpret_cast(m_banner_file.data()); + + for (u32 i = 0; i < desc_count; ++i) + { + auto& data = banner->comment[i].comment; + std::string description = DecodeString(data); + + if (!description.empty()) + descriptions[(IVolume::ELanguage)(language + i)] = description; + } + + return descriptions; +} + +std::string CVolumeGC::GetCompany() const +{ + if (!LoadBannerFile()) + return ""; + + auto const pBanner = (GCBanner*)m_banner_file.data(); + std::string company = DecodeString(pBanner->comment[0].longMaker); + + if (company.empty()) + company = DecodeString(pBanner->comment[0].shortMaker); + + return company; +} + +std::vector CVolumeGC::GetBanner(int* width, int* height) const +{ + if (!LoadBannerFile()) + { + *width = 0; + *height = 0; + return std::vector(); + } + + std::vector image_buffer(GC_BANNER_WIDTH * GC_BANNER_HEIGHT); + auto const pBanner = (GCBanner*)m_banner_file.data(); + ColorUtil::decode5A3image(image_buffer.data(), pBanner->image, GC_BANNER_WIDTH, GC_BANNER_HEIGHT); + *width = GC_BANNER_WIDTH; + *height = GC_BANNER_HEIGHT; + return image_buffer; +} + u32 CVolumeGC::GetFSTSize() const { if (m_pReader == nullptr) @@ -155,10 +272,46 @@ bool CVolumeGC::IsDiscTwo() const return (disc_two_check == 1); } -CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country) +bool CVolumeGC::LoadBannerFile() const { - return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ? - SHIFTJISToUTF8 : CP1252ToUTF8; + // The methods GetNames, GetDescriptions, GetCompany and GetBanner + // all need to access the opening.bnr file. These four methods are + // typically called after each other, so we store the file in RAM + // to avoid reading it from the disc several times. However, + // if none of these methods are called, the file is never loaded. + + if (m_banner_file_type != BANNER_NOT_LOADED) + return m_banner_file_type != BANNER_INVALID; + + std::unique_ptr file_system(CreateFileSystem(this)); + size_t file_size = (size_t)file_system->GetFileSize("opening.bnr"); + if (file_size == BNR1_SIZE || file_size == BNR2_SIZE) + { + m_banner_file.resize(file_size); + file_system->ReadFile("opening.bnr", m_banner_file.data(), m_banner_file.size()); + + u32 bannerSignature = *(u32*)m_banner_file.data(); + switch (bannerSignature) + { + case 0x31524e42: // "BNR1" + m_banner_file_type = BANNER_BNR1; + break; + case 0x32524e42: // "BNR2" + m_banner_file_type = BANNER_BNR2; + break; + default: + m_banner_file_type = BANNER_INVALID; + WARN_LOG(DISCIO, "Invalid opening.bnr type"); + break; + } + } + else + { + m_banner_file_type = BANNER_INVALID; + WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", (unsigned long)file_size); + } + + return m_banner_file_type != BANNER_INVALID; } } // namespace diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index e9757df948..3c4abcba31 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -28,7 +28,11 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::map GetNames() const override; + virtual std::string GetName() const override; + std::map GetNames() const override; + std::map GetDescriptions() const override; + std::string GetCompany() const override; + std::vector GetBanner(int* width, int* height) const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; @@ -38,11 +42,44 @@ public: u64 GetSize() const override; u64 GetRawSize() const override; - typedef std::string(*StringDecoder)(const std::string&); +private: + bool LoadBannerFile() const; - static StringDecoder GetStringDecoder(ECountry country); + static const int GC_BANNER_WIDTH = 96; + static const int GC_BANNER_HEIGHT = 32; + + // Banner Comment + struct GCBannerComment + { + char shortTitle[32]; // Short game title shown in IPL menu + char shortMaker[32]; // Short developer, publisher names shown in IPL menu + char longTitle[64]; // Long game title shown in IPL game start screen + char longMaker[64]; // Long developer, publisher names shown in IPL game start screen + char comment[128]; // Game description shown in IPL game start screen in two lines. + }; + + struct GCBanner + { + u32 id; // "BNR1" for NTSC, "BNR2" for PAL + u32 padding[7]; + u16 image[GC_BANNER_WIDTH * GC_BANNER_HEIGHT]; // RGB5A3 96x32 image + GCBannerComment comment[6]; // Comments in six languages (only one for BNR1 type) + }; + + static const size_t BNR1_SIZE = sizeof(GCBanner) - sizeof(GCBannerComment) * 5; + static const size_t BNR2_SIZE = sizeof(GCBanner); + + enum BannerFileType + { + BANNER_NOT_LOADED, + BANNER_INVALID, + BANNER_BNR1, + BANNER_BNR2 + }; + + mutable BannerFileType m_banner_file_type = BANNER_NOT_LOADED; + mutable std::vector m_banner_file; -private: std::unique_ptr m_pReader; }; diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index 33dc213aee..229ec6d31b 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -31,9 +31,10 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; + std::string GetName() const override { return ""; } std::map GetNames() const override; - u32 GetFSTSize() const override { return 0; } - std::string GetApploaderDate() const override { return "0"; } + u32 GetFSTSize() const override { return 0; } + std::string GetApploaderDate() const override { return ""; } bool IsWadFile() const override; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 935d18b8f8..baf96f2e5d 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -192,16 +192,20 @@ int CVolumeWiiCrypted::GetRevision() const return revision; } -std::map CVolumeWiiCrypted::GetNames() const +std::string CVolumeWiiCrypted::GetName() const { - std::map names; + char name_buffer[0x60]; + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name_buffer, false)) + return DecodeString(name_buffer); - auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry()); - - char name[0xFF] = {}; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name, true)) - names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); + return ""; +} +std::map CVolumeWiiCrypted::GetNames() const +{ + // TODO: Read opening.bnr + std::map names; + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = GetName(); return names; } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index f4712fd230..11092c33d1 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -31,6 +31,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; + std::string GetName() const override; std::map GetNames() const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; -- cgit v1.2.3 From 272f9d3cbc35c65bc98d89bcd36da3adabf648f9 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 28 Apr 2015 16:47:03 +0200 Subject: FileSystemGCWii: Allow reading files partially --- Source/Core/DiscIO/FileSystemGCWii.cpp | 14 ++++++++------ Source/Core/DiscIO/FileSystemGCWii.h | 2 +- Source/Core/DiscIO/Filesystem.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 381d1bdbd4..e23a8cb177 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -63,7 +63,7 @@ const std::string CFileSystemGCWii::GetFileName(u64 _Address) return ""; } -u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) +u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) { if (!m_Initialized) InitFileSystem(); @@ -72,14 +72,16 @@ u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size if (pFileInfo == nullptr) return 0; - if (pFileInfo->m_FileSize > _MaxBufferSize) + if (_OffsetInFile >= pFileInfo->m_FileSize) return 0; - DEBUG_LOG(DISCIO, "Filename: %s. Offset: %" PRIx64 ". Size: %" PRIx64, _rFullPath.c_str(), - pFileInfo->m_Offset, pFileInfo->m_FileSize); + u64 read_length = std::min(_MaxBufferSize, pFileInfo->m_FileSize - _OffsetInFile); - m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer, m_Wii); - return pFileInfo->m_FileSize; + DEBUG_LOG(DISCIO, "Reading %" PRIx64 " bytes at %" PRIx64 " from file %s. Offset: %" PRIx64 " Size: %" PRIx64, + read_length, _OffsetInFile, _rFullPath.c_str(), pFileInfo->m_Offset, pFileInfo->m_FileSize); + + m_rVolume->Read(pFileInfo->m_Offset + _OffsetInFile, read_length, _pBuffer, m_Wii); + return read_length; } bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) diff --git a/Source/Core/DiscIO/FileSystemGCWii.h b/Source/Core/DiscIO/FileSystemGCWii.h index 24a1c65ab3..03f4bb9eff 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.h +++ b/Source/Core/DiscIO/FileSystemGCWii.h @@ -25,7 +25,7 @@ public: virtual u64 GetFileSize(const std::string& _rFullPath) override; virtual size_t GetFileList(std::vector &_rFilenames) override; virtual const std::string GetFileName(u64 _Address) override; - virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) override; + virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) override; virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override; virtual bool ExportApploader(const std::string& _rExportFolder) const override; virtual bool ExportDOL(const std::string& _rExportFolder) const override; diff --git a/Source/Core/DiscIO/Filesystem.h b/Source/Core/DiscIO/Filesystem.h index 78f179d6dd..181c25f354 100644 --- a/Source/Core/DiscIO/Filesystem.h +++ b/Source/Core/DiscIO/Filesystem.h @@ -45,7 +45,7 @@ public: virtual bool IsValid() const = 0; virtual size_t GetFileList(std::vector &_rFilenames) = 0; virtual u64 GetFileSize(const std::string& _rFullPath) = 0; - virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) = 0; + virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile = 0) = 0; virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0; virtual bool ExportApploader(const std::string& _rExportFolder) const = 0; virtual bool ExportDOL(const std::string& _rExportFolder) const = 0; -- cgit v1.2.3 From 2d5d5fa83e9ccb32252756fc0390740c952121b1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 10 Apr 2015 23:18:41 +0200 Subject: Read opening.bnr to get names from Wii discs This makes Dolphin display the same names as the Disc Channel. --- Source/Core/DiscIO/Volume.h | 7 +++++++ Source/Core/DiscIO/VolumeCommon.cpp | 22 ++++++++++++++++++++ Source/Core/DiscIO/VolumeWad.cpp | 36 ++++----------------------------- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 9 +++++---- 4 files changed, 38 insertions(+), 36 deletions(-) (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index ff7e6a8b63..c0fea6ccc4 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -113,6 +113,13 @@ protected: else return CP1252ToUTF8(string); } + + static std::map ReadWiiNames(std::vector& data); + + static const size_t NUMBER_OF_LANGUAGES = 10; + static const size_t NAME_STRING_LENGTH = 42; + static const size_t NAME_BYTES_LENGTH = NAME_STRING_LENGTH * sizeof(u16); + static const size_t NAMES_TOTAL_BYTES = NAME_BYTES_LENGTH * NUMBER_OF_LANGUAGES; }; // Generic Switch function for all volumes diff --git a/Source/Core/DiscIO/VolumeCommon.cpp b/Source/Core/DiscIO/VolumeCommon.cpp index e2c3117170..d9b5240327 100644 --- a/Source/Core/DiscIO/VolumeCommon.cpp +++ b/Source/Core/DiscIO/VolumeCommon.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include #include #include #include @@ -56,6 +57,27 @@ std::vector IVolume::GetBanner(int* width, int* height) const return image_buffer; } +std::map IVolume::ReadWiiNames(std::vector& data) +{ + std::map names; + for (size_t i = 0; i < NUMBER_OF_LANGUAGES; ++i) + { + size_t name_start = NAME_BYTES_LENGTH * i; + size_t name_end = name_start + NAME_BYTES_LENGTH; + if (data.size() >= name_end) + { + u16* temp = (u16*)(data.data() + name_start); + std::wstring out_temp(NAME_STRING_LENGTH, '\0'); + std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); + out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); + std::string name = UTF16ToUTF8(out_temp); + if (!name.empty()) + names[(IVolume::ELanguage)i] = name; + } + } + return names; +} + // Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp) IVolume::ECountry CountrySwitch(u8 country_code) { diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 5bc27738da..7b52e7a82e 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include #include #include #include @@ -120,37 +119,10 @@ bool CVolumeWAD::IsWadFile() const std::map CVolumeWAD::GetNames() const { - std::map names; - - u32 footer_size; - if (!Read(0x1C, 4, (u8*)&footer_size)) - { - return names; - } - - footer_size = Common::swap32(footer_size); - - //Japanese, English, German, French, Spanish, Italian, Dutch, Simplified Chinese, Traditional Chinese, Korean - for (int i = 0; i < 10; ++i) - { - static const u32 string_length = 42; - static const u32 bytes_length = string_length * sizeof(u16); - - u16 temp[string_length]; - - if (footer_size >= 0xF1 && Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp)) - { - std::wstring out_temp; - out_temp.resize(string_length); - std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); - out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); - std::string name = UTF16ToUTF8(out_temp); - if (!name.empty()) - names[(IVolume::ELanguage)i] = name; - } - } - - return names; + std::vector name_data(NAMES_TOTAL_BYTES); + if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data())) + return std::map(); + return ReadWiiNames(name_data); } u64 CVolumeWAD::GetSize() const diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index baf96f2e5d..7657c0a28d 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -16,6 +16,7 @@ #include "Common/Logging/Log.h" #include "DiscIO/Blob.h" #include "DiscIO/FileMonitor.h" +#include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeCreator.h" #include "DiscIO/VolumeGC.h" @@ -203,10 +204,10 @@ std::string CVolumeWiiCrypted::GetName() const std::map CVolumeWiiCrypted::GetNames() const { - // TODO: Read opening.bnr - std::map names; - names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = GetName(); - return names; + std::unique_ptr file_system(CreateFileSystem(this)); + std::vector opening_bnr(NAMES_TOTAL_BYTES); + opening_bnr.resize(file_system->ReadFile("opening.bnr", opening_bnr.data(), opening_bnr.size(), 0x5C)); + return ReadWiiNames(opening_bnr); } u32 CVolumeWiiCrypted::GetFSTSize() const -- cgit v1.2.3