diff options
| author | JosJuice <josjuice@gmail.com> | 2016-12-23 18:41:21 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2017-01-02 20:57:11 +0100 |
| commit | 66ea9f5cc18ca6beb87ddd7f7a291d96669ad653 (patch) | |
| tree | 011a81833e2b2b5452b390ba4f58181ab77e8d66 /Source/Core/DiscIO | |
| parent | 6aef0630f74e61d6847fc1f1186056df8bd42651 (diff) | |
DiscIO: Add GetRegion function and Region enum
Instead of needing different switch cases for
converting countries to regions in multiple places,
we now only need a single country-to-region switch case
(in DiscIO/Enums.cpp), and we get a nice Region type.
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/Enums.cpp | 44 | ||||
| -rw-r--r-- | Source/Core/DiscIO/Enums.h | 12 | ||||
| -rw-r--r-- | Source/Core/DiscIO/NANDContentLoader.cpp | 6 | ||||
| -rw-r--r-- | Source/Core/DiscIO/NANDContentLoader.h | 4 | ||||
| -rw-r--r-- | Source/Core/DiscIO/Volume.h | 8 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeDirectory.cpp | 8 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeDirectory.h | 2 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeGC.cpp | 17 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeGC.h | 2 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWad.cpp | 15 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWad.h | 2 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWiiCrypted.cpp | 53 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWiiCrypted.h | 2 |
13 files changed, 122 insertions, 53 deletions
diff --git a/Source/Core/DiscIO/Enums.cpp b/Source/Core/DiscIO/Enums.cpp index 385fff1317..6689470f32 100644 --- a/Source/Core/DiscIO/Enums.cpp +++ b/Source/Core/DiscIO/Enums.cpp @@ -13,6 +13,50 @@ namespace DiscIO { // Increment CACHE_REVISION (ISOFile.cpp & GameFile.cpp) if the code below is modified +Region RegionSwitchGC(u8 country_code) +{ + Region region = RegionSwitchWii(country_code); + return region == Region::NTSC_K ? Region::UNKNOWN_REGION : region; +} + +Region RegionSwitchWii(u8 country_code) +{ + switch (country_code) + { + case 'J': + case 'W': + return Region::NTSC_J; + + case 'B': + case 'E': + case 'N': + case 'Z': + return Region::NTSC_U; + + case 'D': + case 'F': + case 'H': + case 'I': + case 'L': + case 'M': + case 'P': + case 'R': + case 'S': + case 'U': + case 'X': + case 'Y': + return Region::PAL; + + case 'K': + case 'Q': + case 'T': + return Region::NTSC_K; + + default: + return Region::UNKNOWN_REGION; + } +} + Country CountrySwitch(u8 country_code) { switch (country_code) diff --git a/Source/Core/DiscIO/Enums.h b/Source/Core/DiscIO/Enums.h index 59f61561de..01f7ddb529 100644 --- a/Source/Core/DiscIO/Enums.h +++ b/Source/Core/DiscIO/Enums.h @@ -38,6 +38,16 @@ enum class Country NUMBER_OF_COUNTRIES }; +// Regions 0 - 2 and 4 match Nintendo's Wii region numbering. +enum class Region +{ + NTSC_J = 0, // Japan and Taiwan + NTSC_U = 1, // Mainly North America + PAL = 2, // Mainly Europe and Oceania + UNKNOWN_REGION = 3, // 3 seems to be unused? Anyway, we need an UNKNOWN_REGION. Let's put it here + NTSC_K = 4 // South Korea (Wii only) +}; + // Languages 0 - 9 match Nintendo's Wii language numbering. // Languages 1 - 6 match Nintendo's PAL GameCube languages 0 - 5. // NTSC GameCubes only support one language and thus don't number languages. @@ -56,6 +66,8 @@ enum class Language LANGUAGE_UNKNOWN }; +Region RegionSwitchGC(u8 country_code); +Region RegionSwitchWii(u8 country_code); Country CountrySwitch(u8 country_code); u8 GetSysMenuRegion(u16 title_version); std::string GetCompanyFromID(const std::string& company_id); diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index 5b3057efbf..2c5e0e87e7 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -311,12 +311,12 @@ std::vector<u8> CNANDContentLoader::GetKeyFromTicket(const std::vector<u8>& tick return AESDecode(common_key, iv, &ticket[0x01BF], 16); } -DiscIO::Country CNANDContentLoader::GetCountry() const +DiscIO::Region CNANDContentLoader::GetRegion() const { if (!IsValid()) - return DiscIO::Country::COUNTRY_UNKNOWN; + return DiscIO::Region::UNKNOWN_REGION; - return CountrySwitch(m_Country); + return RegionSwitchWii(m_Country); } CNANDContentManager::~CNANDContentManager() diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h index 6643e2789c..f8d3bb6711 100644 --- a/Source/Core/DiscIO/NANDContentLoader.h +++ b/Source/Core/DiscIO/NANDContentLoader.h @@ -20,7 +20,7 @@ class IOFile; namespace DiscIO { -enum class Country; +enum class Region; bool AddTicket(u64 title_id, const std::vector<u8>& ticket); @@ -94,7 +94,7 @@ public: const std::vector<SNANDContent>& GetContent() const { return m_Content; } u16 GetTitleVersion() const { return m_TitleVersion; } u16 GetNumEntries() const { return m_NumEntries; } - DiscIO::Country GetCountry() const; + DiscIO::Region GetRegion() const; u8 GetCountryChar() const { return m_Country; } enum { diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 44af039cba..6f4a6defe4 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -55,6 +55,7 @@ public: virtual bool SupportsIntegrityCheck() const { return false; } virtual bool CheckIntegrity() const { return false; } virtual bool ChangePartition(u64 offset) { return false; } + virtual Region GetRegion() const = 0; virtual Country GetCountry() const = 0; virtual BlobType GetBlobType() const = 0; // Size of virtual disc (not always accurate) @@ -71,12 +72,7 @@ protected: // strnlen to trim NULLs std::string string(data, strnlen(data, sizeof(data))); - // There doesn'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::COUNTRY_JAPAN == GetCountry() || Country::COUNTRY_TAIWAN == GetCountry()); - - if (use_shift_jis) + if (GetRegion() == Region::NTSC_J) return SHIFTJISToUTF8(string); else return CP1252ToUTF8(string); diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 504d17c20f..40dda01d0d 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -166,6 +166,14 @@ void CVolumeDirectory::SetGameID(const std::string& id) memcpy(m_disk_header.data(), id.c_str(), std::min(id.length(), MAX_ID_LENGTH)); } +Region CVolumeDirectory::GetRegion() const +{ + if (m_is_wii) + return RegionSwitchWii(m_disk_header[3]); + + return RegionSwitchGC(m_disk_header[3]); +} + Country CVolumeDirectory::GetCountry() const { return CountrySwitch(m_disk_header[3]); diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h index ab0a96400d..13a8799eda 100644 --- a/Source/Core/DiscIO/VolumeDirectory.h +++ b/Source/Core/DiscIO/VolumeDirectory.h @@ -26,6 +26,7 @@ namespace DiscIO enum class BlobType; enum class Country; enum class Language; +enum class Region; enum class Platform; class CVolumeDirectory : public IVolume @@ -56,6 +57,7 @@ public: std::string GetApploaderDate() const override; Platform GetVolumeType() const override; + Region GetRegion() const override; Country GetCountry() const override; BlobType GetBlobType() const override; diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 58faed4fe8..fcba359931 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -61,13 +61,20 @@ std::string CVolumeGC::GetGameID() const return DecodeString(ID); } -Country CVolumeGC::GetCountry() const +Region CVolumeGC::GetRegion() const { - if (!m_pReader) - return Country::COUNTRY_UNKNOWN; + u8 country_code; + if (!m_pReader->Read(3, 1, &country_code)) + return Region::UNKNOWN_REGION; + return RegionSwitchGC(country_code); +} + +Country CVolumeGC::GetCountry() const +{ u8 country_code; - m_pReader->Read(3, 1, &country_code); + if (!m_pReader->Read(3, 1, &country_code)) + return Country::COUNTRY_UNKNOWN; return CountrySwitch(country_code); } @@ -247,7 +254,7 @@ void CVolumeGC::ExtractBannerInformation(const GCBanner& banner_file, bool is_bn if (is_bnr1) // NTSC { - bool is_japanese = GetCountry() == Country::COUNTRY_JAPAN; + bool is_japanese = GetRegion() == Region::NTSC_J; number_of_languages = 1; start_language = is_japanese ? Language::LANGUAGE_JAPANESE : Language::LANGUAGE_ENGLISH; } diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index ca461949e2..ab424c6c50 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -19,6 +19,7 @@ namespace DiscIO enum class BlobType; enum class Country; enum class Language; +enum class Region; enum class Platform; class CVolumeGC : public IVolume @@ -42,6 +43,7 @@ public: u8 GetDiscNumber() const override; Platform GetVolumeType() const override; + Region GetRegion() const override; Country GetCountry() const override; BlobType GetBlobType() const override; u64 GetSize() const override; diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 3254190be9..7c089ad10a 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -57,14 +57,21 @@ bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) cons return m_pReader->Read(_Offset, _Length, _pBuffer); } -Country CVolumeWAD::GetCountry() const +Region CVolumeWAD::GetRegion() const { - if (!m_pReader) - return Country::COUNTRY_UNKNOWN; + u8 country_code; + if (!Read(m_tmd_offset + 0x0193, 1, &country_code)) + return Region::UNKNOWN_REGION; + + return RegionSwitchWii(country_code); +} +Country CVolumeWAD::GetCountry() const +{ // read the last digit of the titleID in the ticket u8 country_code; - Read(m_tmd_offset + 0x0193, 1, &country_code); + if (!Read(m_tmd_offset + 0x0193, 1, &country_code)) + return Country::COUNTRY_UNKNOWN; if (country_code == 2) // SYSMENU { diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index 68fc6a7612..0f28064387 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -21,6 +21,7 @@ namespace DiscIO enum class BlobType; enum class Country; enum class Language; +enum class Region; enum class Platform; class CVolumeWAD : public IVolume @@ -39,6 +40,7 @@ public: u64 GetFSTSize() const override { return 0; } std::string GetApploaderDate() const override { return ""; } Platform GetVolumeType() const override; + Region GetRegion() const override; Country GetCountry() const override; BlobType GetBlobType() const override; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 09224e04aa..7976e1d758 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -153,51 +153,38 @@ std::string CVolumeWiiCrypted::GetGameID() const return DecodeString(ID); } -Country CVolumeWiiCrypted::GetCountry() const +Region CVolumeWiiCrypted::GetRegion() const { - if (!m_pReader) - return Country::COUNTRY_UNKNOWN; + u32 region_code; + if (!ReadSwapped(0x4E000, ®ion_code, false)) + return Region::UNKNOWN_REGION; + + return static_cast<Region>(region_code); +} +Country CVolumeWiiCrypted::GetCountry() const +{ u8 country_byte; if (!m_pReader->Read(3, 1, &country_byte)) return Country::COUNTRY_UNKNOWN; - Country country_value = CountrySwitch(country_byte); + const Region region = GetRegion(); - u32 region_code; - if (!ReadSwapped(0x4E000, ®ion_code, false)) - return country_value; + if (RegionSwitchWii(country_byte) == region) + return CountrySwitch(country_byte); - switch (region_code) + switch (region) { - case 0: - switch (country_value) - { - case Country::COUNTRY_TAIWAN: - return Country::COUNTRY_TAIWAN; - default: - return Country::COUNTRY_JAPAN; - } - case 1: + case Region::NTSC_J: + return Country::COUNTRY_JAPAN; + case Region::NTSC_U: return Country::COUNTRY_USA; - case 2: - switch (country_value) - { - case Country::COUNTRY_FRANCE: - case Country::COUNTRY_GERMANY: - case Country::COUNTRY_ITALY: - case Country::COUNTRY_NETHERLANDS: - case Country::COUNTRY_RUSSIA: - case Country::COUNTRY_SPAIN: - case Country::COUNTRY_AUSTRALIA: - return country_value; - default: - return Country::COUNTRY_EUROPE; - } - case 4: + case Region::PAL: + return Country::COUNTRY_EUROPE; + case Region::NTSC_K: return Country::COUNTRY_KOREA; default: - return country_value; + return Country::COUNTRY_UNKNOWN; } } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index 9bb449980d..d578dd5ba0 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -20,6 +20,7 @@ namespace DiscIO enum class BlobType; enum class Country; enum class Language; +enum class Region; enum class Platform; class CVolumeWiiCrypted : public IVolume @@ -46,6 +47,7 @@ public: bool CheckIntegrity() const override; bool ChangePartition(u64 offset) override; + Region GetRegion() const override; Country GetCountry() const override; BlobType GetBlobType() const override; u64 GetSize() const override; |
