diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 17a79a409a..f31ea26780 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -806,6 +806,9 @@ DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region) const char* SConfig::GetDirectoryForRegion(DiscIO::Region region) { + if (region == DiscIO::Region::Unknown) + region = ToGameCubeRegion(GetFallbackRegion()); + switch (region) { case DiscIO::Region::NTSC_J: @@ -819,10 +822,11 @@ const char* SConfig::GetDirectoryForRegion(DiscIO::Region region) case DiscIO::Region::NTSC_K: ASSERT_MSG(BOOT, false, "NTSC-K is not a valid GameCube region"); - return nullptr; + return JAP_DIR; // See ToGameCubeRegion 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)) return false; - // Fall back to the system menu region, if possible. if (m_region == DiscIO::Region::Unknown) - { - 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; + m_region = GetFallbackRegion(); // Set up paths const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region)); @@ -947,6 +941,18 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot) 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 { int language_value; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 9ad7271baa..0d6248e9ae 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -211,6 +211,7 @@ struct SConfig static const char* GetDirectoryForRegion(DiscIO::Region region); std::string GetBootROMPath(const std::string& region_directory) const; bool SetPathsAndGameMetadata(const BootParameters& boot); + static DiscIO::Region GetFallbackRegion(); DiscIO::Language GetCurrentLanguage(bool wii) const; IniFile LoadDefaultGameIni() const;