Merge pull request #5795 from JosJuice/gc-region-detection

Improve GameCube region detection
This commit is contained in:
Leo Lam 2017-07-20 14:13:11 +08:00 committed by GitHub
commit c207a1072d
13 changed files with 69 additions and 28 deletions

View File

@ -13,6 +13,7 @@
#include "AudioCommon/AudioCommon.h"
#include "Common/Assert.h"
#include "Common/CDUtils.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
@ -869,6 +870,18 @@ bool SConfig::IsUSBDeviceWhitelisted(const std::pair<u16, u16> vid_pid) const
return m_usb_passthrough_devices.find(vid_pid) != m_usb_passthrough_devices.end();
}
// The reason we need this function is because some memory card code
// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii.
DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region)
{
if (region != DiscIO::Region::NTSC_K)
return region;
// GameCube has no NTSC-K region. No choice of replacement value is completely
// non-arbitrary, but let's go with NTSC-J since Korean GameCubes are NTSC-J.
return DiscIO::Region::NTSC_J;
}
const char* SConfig::GetDirectoryForRegion(DiscIO::Region region)
{
switch (region)
@ -883,13 +896,8 @@ const char* SConfig::GetDirectoryForRegion(DiscIO::Region region)
return EUR_DIR;
case DiscIO::Region::NTSC_K:
// This function can't return a Korean directory name, because this
// function is only used for GameCube things (memory cards, IPL), and
// GameCube has no NTSC-K region. Since NTSC-K doesn't correspond to any
// GameCube region, let's return an arbitrary pick. Returning nullptr like
// with unknown regions would be inappropriate, because Dolphin expects
// to get valid memory card paths even when running an NTSC-K Wii game.
return JAP_DIR;
_assert_msg_(BOOT, false, "NTSC-K is not a valid GameCube region");
return nullptr;
default:
return nullptr;
@ -982,7 +990,7 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot)
return false;
// Set up region
const char* retrieved_region_dir = GetDirectoryForRegion(region);
const char* retrieved_region_dir = GetDirectoryForRegion(ToGameCubeRegion(region));
m_region = retrieved_region_dir ? region : DiscIO::Region::PAL;
const std::string set_region_dir = retrieved_region_dir ? retrieved_region_dir : EUR_DIR;
if (!retrieved_region_dir &&

View File

@ -217,6 +217,9 @@ struct SConfig : NonCopyable
void SetRunningGameMetadata(const IOS::ES::TMDReader& tmd);
void LoadDefaults();
// Replaces NTSC-K with some other region, and doesn't replace non-NTSC-K regions
static DiscIO::Region ToGameCubeRegion(DiscIO::Region region);
// The region argument must be valid for GameCube (i.e. must not be NTSC-K)
static const char* GetDirectoryForRegion(DiscIO::Region region);
std::string GetBootROMPath(const std::string& region_directory) const;
bool SetPathsAndGameMetadata(const BootParameters& boot);

View File

@ -157,7 +157,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index, bool gciFolder) : card_index(ind
void CEXIMemoryCard::SetupGciFolder(u16 sizeMb)
{
DiscIO::Region region = SConfig::GetInstance().m_region;
const DiscIO::Region region = SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region);
const std::string& game_id = SConfig::GetInstance().GetGameID();
u32 CurrentGameId = 0;

View File

@ -44,6 +44,7 @@ int GCMemcardDirectory::LoadGCI(const std::string& file_name, DiscIO::Region car
return NO_INDEX;
}
// This isn't a reliable way to detect regions. TODO: Get rid of this?
DiscIO::Region gci_region = DiscIO::RegionSwitchGC(gci.m_gci_header.Gamecode[3]);
// Some special save files have game IDs that we parse as UNKNOWN_REGION. For instance:
// - Datel Action Replay uses C as the fourth character. (Can be on any region's card.)

View File

@ -232,14 +232,6 @@ u64 TMDReader::GetIOSId() const
return Common::swap64(m_bytes.data() + offsetof(TMDHeader, ios_id));
}
DiscIO::Region TMDReader::GetRegion() const
{
if (GetTitleId() == Titles::SYSTEM_MENU)
return DiscIO::GetSysMenuRegion(GetTitleVersion());
return DiscIO::RegionSwitchWii(static_cast<u8>(GetTitleId() & 0xff));
}
u64 TMDReader::GetTitleId() const
{
return Common::swap64(m_bytes.data() + offsetof(TMDHeader, title_id));
@ -260,6 +252,14 @@ u16 TMDReader::GetGroupId() const
return Common::swap16(m_bytes.data() + offsetof(TMDHeader, group_id));
}
DiscIO::Region TMDReader::GetRegion() const
{
if (GetTitleId() == Titles::SYSTEM_MENU)
return DiscIO::GetSysMenuRegion(GetTitleVersion());
return DiscIO::RegionSwitchWii(static_cast<u8>(GetTitleId() & 0xff));
}
std::string TMDReader::GetGameID() const
{
char game_id[6];

View File

@ -185,12 +185,14 @@ public:
u16 GetBootIndex() const;
u64 GetIOSId() const;
DiscIO::Region GetRegion() const;
u64 GetTitleId() const;
u32 GetTitleFlags() const;
u16 GetTitleVersion() const;
u16 GetGroupId() const;
// Provides a best guess for the region. Might be inaccurate or UNKNOWN_REGION.
DiscIO::Region GetRegion() const;
// Constructs a 6-character game ID in the format typically used by Dolphin.
// If the 6-character game ID would contain unprintable characters,
// the title ID converted to hexadecimal is returned instead.

View File

@ -94,12 +94,12 @@ static bool IsWiiTitle(const std::string& game_id)
static bool IsJapaneseGCTitle(const std::string& game_id)
{
return IsGCTitle(game_id) && DiscIO::RegionSwitchGC(game_id[3]) == DiscIO::Region::NTSC_J;
return IsGCTitle(game_id) && DiscIO::CountrySwitch(game_id[3]) == DiscIO::Country::COUNTRY_JAPAN;
}
static bool IsNonJapaneseGCTitle(const std::string& game_id)
{
return IsGCTitle(game_id) && DiscIO::RegionSwitchGC(game_id[3]) != DiscIO::Region::NTSC_J;
return IsGCTitle(game_id) && DiscIO::CountrySwitch(game_id[3]) != DiscIO::Country::COUNTRY_JAPAN;
}
// Note that this function will not overwrite entries that already are in the maps

View File

@ -48,7 +48,7 @@ Country TypicalCountryForRegion(Region region)
Region RegionSwitchGC(u8 country_code)
{
Region region = RegionSwitchWii(country_code);
return region == Region::NTSC_K ? Region::UNKNOWN_REGION : region;
return region == Region::NTSC_K ? Region::NTSC_J : region;
}
Region RegionSwitchWii(u8 country_code)

View File

@ -40,10 +40,10 @@ enum class Country
NUMBER_OF_COUNTRIES
};
// Regions 0 - 2 and 4 match Nintendo's Wii region numbering.
// Regions 0 - 2 and 4 match Nintendo's GameCube/Wii region numbering.
enum class Region
{
NTSC_J = 0, // Japan and Taiwan
NTSC_J = 0, // Japan and Taiwan (and South Korea for GameCube only)
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
@ -71,11 +71,16 @@ enum class Language
bool IsDisc(Platform volume_type);
bool IsWii(Platform volume_type);
bool IsNTSC(Region region);
Country TypicalCountryForRegion(Region region);
// Avoid using this function if you can. Country codes aren't always reliable region indicators.
Region RegionSwitchGC(u8 country_code);
// Avoid using this function if you can. Country codes aren't always reliable region indicators.
Region RegionSwitchWii(u8 country_code);
Country CountrySwitch(u8 country_code);
Region GetSysMenuRegion(u16 title_version);
std::string GetSysMenuVersionString(u16 title_version);
std::string GetCompanyFromID(const std::string& company_id);
}

View File

@ -83,6 +83,7 @@ public:
virtual Platform GetVolumeType() const = 0;
virtual bool SupportsIntegrityCheck() const { return false; }
virtual bool CheckIntegrity(const Partition& partition) const { return false; }
// May be inaccurate for WADs
virtual Region GetRegion() const = 0;
Country GetCountry() const { return GetCountry(GetGamePartition()); }
virtual Country GetCountry(const Partition& partition) const = 0;

View File

@ -60,14 +60,31 @@ std::string VolumeGC::GetGameID(const Partition& partition) const
Region VolumeGC::GetRegion() const
{
const std::optional<u8> country_code = ReadSwapped<u8>(3, PARTITION_NONE);
return country_code ? RegionSwitchGC(*country_code) : Region::UNKNOWN_REGION;
const std::optional<u32> region_code = ReadSwapped<u32>(0x458, PARTITION_NONE);
if (!region_code)
return Region::UNKNOWN_REGION;
const Region region = static_cast<Region>(*region_code);
return region <= Region::PAL ? region : Region::UNKNOWN_REGION;
}
Country VolumeGC::GetCountry(const Partition& partition) const
{
const std::optional<u8> country_code = ReadSwapped<u8>(3, partition);
return country_code ? CountrySwitch(*country_code) : Country::COUNTRY_UNKNOWN;
// The 0 that we use as a default value is mapped to COUNTRY_UNKNOWN and UNKNOWN_REGION
const u8 country = ReadSwapped<u8>(3, partition).value_or(0);
const Region region = GetRegion();
// Korean GC releases use NTSC-J.
// E is normally used for America, but it's also used for English-language Korean GC releases.
// K is used by games that are in the Korean language.
// W means Taiwan for Wii games, but on the GC, it's used for English-language Korean releases.
// (There doesn't seem to be any pattern to which of E and W is used for Korean GC releases.)
if (region == Region::NTSC_J && (country == 'E' || country == 'K' || country == 'W'))
return Country::COUNTRY_KOREA;
if (RegionSwitchGC(country) != region)
return TypicalCountryForRegion(region);
return CountrySwitch(country);
}
std::string VolumeGC::GetMakerID(const Partition& partition) const

View File

@ -50,6 +50,7 @@ public:
return "";
}
Platform GetVolumeType() const override;
// Provides a best guess for the region. Might be inaccurate or UNKNOWN_REGION.
Region GetRegion() const override;
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;

View File

@ -233,7 +233,10 @@ std::string VolumeWii::GetGameID(const Partition& partition) const
Region VolumeWii::GetRegion() const
{
const std::optional<u32> region_code = m_pReader->ReadSwapped<u32>(0x4E000);
return region_code ? static_cast<Region>(*region_code) : Region::UNKNOWN_REGION;
if (!region_code)
return Region::UNKNOWN_REGION;
const Region region = static_cast<Region>(*region_code);
return region <= Region::NTSC_K ? region : Region::UNKNOWN_REGION;
}
Country VolumeWii::GetCountry(const Partition& partition) const