Merge pull request #7284 from Techjar/netplay-fix-unknown-region-crash

Fix segfault on NetPlay start with unknown region
This commit is contained in:
JosJuice 2018-07-22 22:27:34 +02:00 committed by GitHub
commit 7c2d2548a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 13 deletions

View File

@ -806,6 +806,9 @@ DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region)
const char* SConfig::GetDirectoryForRegion(DiscIO::Region region) const char* SConfig::GetDirectoryForRegion(DiscIO::Region region)
{ {
if (region == DiscIO::Region::Unknown)
region = ToGameCubeRegion(GetFallbackRegion());
switch (region) switch (region)
{ {
case DiscIO::Region::NTSC_J: case DiscIO::Region::NTSC_J:
@ -819,10 +822,11 @@ const char* SConfig::GetDirectoryForRegion(DiscIO::Region region)
case DiscIO::Region::NTSC_K: case DiscIO::Region::NTSC_K:
ASSERT_MSG(BOOT, false, "NTSC-K is not a valid GameCube region"); ASSERT_MSG(BOOT, false, "NTSC-K is not a valid GameCube region");
return nullptr; return JAP_DIR; // See ToGameCubeRegion
default: default:
return nullptr; ASSERT_MSG(BOOT, false, "Default case should not be reached");
return EUR_DIR;
} }
} }
@ -926,18 +930,8 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot)
if (!std::visit(SetGameMetadata(this, &m_region), boot.parameters)) if (!std::visit(SetGameMetadata(this, &m_region), boot.parameters))
return false; return false;
// Fall back to the system menu region, if possible.
if (m_region == DiscIO::Region::Unknown) if (m_region == DiscIO::Region::Unknown)
{ m_region = GetFallbackRegion();
IOS::HLE::Kernel ios;
const IOS::ES::TMDReader system_menu_tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
if (system_menu_tmd.IsValid())
m_region = system_menu_tmd.GetRegion();
}
// Fall back to PAL.
if (m_region == DiscIO::Region::Unknown)
m_region = DiscIO::Region::PAL;
// Set up paths // Set up paths
const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region)); const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region));
@ -947,6 +941,18 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot)
return true; return true;
} }
DiscIO::Region SConfig::GetFallbackRegion()
{
// Fall back to the system menu region, if possible.
IOS::HLE::Kernel ios;
const IOS::ES::TMDReader system_menu_tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
if (system_menu_tmd.IsValid())
return system_menu_tmd.GetRegion();
// Fall back to PAL.
return DiscIO::Region::PAL;
}
DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const
{ {
int language_value; int language_value;

View File

@ -211,6 +211,7 @@ struct SConfig
static const char* GetDirectoryForRegion(DiscIO::Region region); static const char* GetDirectoryForRegion(DiscIO::Region region);
std::string GetBootROMPath(const std::string& region_directory) const; std::string GetBootROMPath(const std::string& region_directory) const;
bool SetPathsAndGameMetadata(const BootParameters& boot); bool SetPathsAndGameMetadata(const BootParameters& boot);
static DiscIO::Region GetFallbackRegion();
DiscIO::Language GetCurrentLanguage(bool wii) const; DiscIO::Language GetCurrentLanguage(bool wii) const;
IniFile LoadDefaultGameIni() const; IniFile LoadDefaultGameIni() const;