mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Merge pull request #4544 from JosJuice/region-enum
DiscIO: Add GetRegion function and Region enum
This commit is contained in:
@ -11,8 +11,57 @@
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
bool IsNTSC(Region region)
|
||||
{
|
||||
return region == Region::NTSC_J || region == Region::NTSC_U || region == Region::NTSC_K;
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
@ -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,9 @@ enum class Language
|
||||
LANGUAGE_UNKNOWN
|
||||
};
|
||||
|
||||
bool IsNTSC(Region region);
|
||||
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);
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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]);
|
||||
|
@ -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;
|
||||
|
@ -61,13 +61,20 @@ std::string CVolumeGC::GetGameID() const
|
||||
return DecodeString(ID);
|
||||
}
|
||||
|
||||
Region CVolumeGC::GetRegion() const
|
||||
{
|
||||
u8 country_code;
|
||||
if (!m_pReader->Read(3, 1, &country_code))
|
||||
return Region::UNKNOWN_REGION;
|
||||
|
||||
return RegionSwitchGC(country_code);
|
||||
}
|
||||
|
||||
Country CVolumeGC::GetCountry() const
|
||||
{
|
||||
if (!m_pReader)
|
||||
return Country::COUNTRY_UNKNOWN;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -57,14 +57,21 @@ bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) cons
|
||||
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
||||
}
|
||||
|
||||
Region CVolumeWAD::GetRegion() const
|
||||
{
|
||||
u8 country_code;
|
||||
if (!Read(m_tmd_offset + 0x0193, 1, &country_code))
|
||||
return Region::UNKNOWN_REGION;
|
||||
|
||||
return RegionSwitchWii(country_code);
|
||||
}
|
||||
|
||||
Country CVolumeWAD::GetCountry() const
|
||||
{
|
||||
if (!m_pReader)
|
||||
return Country::COUNTRY_UNKNOWN;
|
||||
|
||||
// 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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -153,51 +153,38 @@ std::string CVolumeWiiCrypted::GetGameID() const
|
||||
return DecodeString(ID);
|
||||
}
|
||||
|
||||
Region CVolumeWiiCrypted::GetRegion() const
|
||||
{
|
||||
u32 region_code;
|
||||
if (!ReadSwapped(0x4E000, ®ion_code, false))
|
||||
return Region::UNKNOWN_REGION;
|
||||
|
||||
return static_cast<Region>(region_code);
|
||||
}
|
||||
|
||||
Country CVolumeWiiCrypted::GetCountry() const
|
||||
{
|
||||
if (!m_pReader)
|
||||
return Country::COUNTRY_UNKNOWN;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user