From a1000afacceef41697588c124f5dd2e7d18ff73b Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 29 Dec 2020 18:10:16 +0100 Subject: [PATCH] Add utility functions for GameCube language codes --- Source/Core/Core/BootManager.cpp | 5 ++--- Source/Core/Core/ConfigManager.cpp | 7 +++---- Source/Core/DiscIO/Enums.cpp | 16 ++++++++++++++++ Source/Core/DiscIO/Enums.h | 3 +++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 78b191e1e7..f622c680fa 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -393,9 +393,8 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) // Override out-of-region languages/countries to prevent games from crashing or behaving oddly if (!StartUp.bOverrideRegionSettings) { - const int gc_language = - static_cast(StartUp.GetLanguageAdjustedForRegion(false, StartUp.m_region)); - StartUp.SelectedLanguage = gc_language - (gc_language > 0); + StartUp.SelectedLanguage = + DiscIO::ToGameCubeLanguage(StartUp.GetLanguageAdjustedForRegion(false, StartUp.m_region)); if (StartUp.bWii) { diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index d4ec804b3a..541940f7e4 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -963,12 +963,11 @@ DiscIO::Region SConfig::GetFallbackRegion() DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const { - int language_value; + DiscIO::Language language; if (wii) - language_value = Config::Get(Config::SYSCONF_LANGUAGE); + language = static_cast(Config::Get(Config::SYSCONF_LANGUAGE)); else - language_value = SConfig::GetInstance().SelectedLanguage + 1; - DiscIO::Language language = static_cast(language_value); + language = DiscIO::FromGameCubeLanguage(SConfig::GetInstance().SelectedLanguage); // Get rid of invalid values (probably doesn't matter, but might as well do it) if (language > DiscIO::Language::Unknown || language < DiscIO::Language::Japanese) diff --git a/Source/Core/DiscIO/Enums.cpp b/Source/Core/DiscIO/Enums.cpp index c43132b7f2..7ee3ce78eb 100644 --- a/Source/Core/DiscIO/Enums.cpp +++ b/Source/Core/DiscIO/Enums.cpp @@ -126,6 +126,22 @@ bool IsNTSC(Region region) return region == Region::NTSC_J || region == Region::NTSC_U || region == Region::NTSC_K; } +int ToGameCubeLanguage(Language language) +{ + if (language < Language::English || language > Language::Dutch) + return 0; + else + return static_cast(language) - 1; +} + +Language FromGameCubeLanguage(int language) +{ + if (language < 0 || language > 5) + return Language::Unknown; + else + return static_cast(language + 1); +} + // Increment CACHE_REVISION (GameFileCache.cpp) if the code below is modified Country TypicalCountryForRegion(Region region) diff --git a/Source/Core/DiscIO/Enums.h b/Source/Core/DiscIO/Enums.h index 14940d92a8..18a344b680 100644 --- a/Source/Core/DiscIO/Enums.h +++ b/Source/Core/DiscIO/Enums.h @@ -76,6 +76,9 @@ bool IsDisc(Platform volume_type); bool IsWii(Platform volume_type); bool IsNTSC(Region region); +int ToGameCubeLanguage(Language language); +Language FromGameCubeLanguage(int language); + Country TypicalCountryForRegion(Region region); Region SysConfCountryToRegion(u8 country_code); // Avoid using this function if you can. Country codes aren't always reliable region indicators.