From 83133a292b30cde28568dd24cdc8084ac822be2c Mon Sep 17 00:00:00 2001 From: wiidev Date: Sun, 1 Jan 2023 17:00:33 +0000 Subject: [PATCH] Automatically use a compatible language for games --- source/usbloader/GameBooter.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/source/usbloader/GameBooter.cpp b/source/usbloader/GameBooter.cpp index b72d4363..fbadfec8 100644 --- a/source/usbloader/GameBooter.cpp +++ b/source/usbloader/GameBooter.cpp @@ -56,6 +56,7 @@ #include "prompts/ProgressWindow.h" #include "neek.hpp" #include "lstub.h" +#include "xml/GameTDB.hpp" /* GCC 11 false positives */ #if __GNUC__ > 10 @@ -328,6 +329,40 @@ int GameBooter::BootGame(struct discHdr *gameHdr) if (NandEmuMode == EMUNAND_NEEK && (gameHeader.type == TYPE_GAME_WII_IMG || gameHeader.type == TYPE_GAME_EMUNANDCHAN)) return BootNeek(&gameHeader); + if (languageChoice == CONSOLE_DEFAULT) + { + std::string Filepath(Settings.titlestxt_path); + if (Filepath.back() != '/') + Filepath += '/'; + Filepath += "wiitdb.xml"; + + GameTDB XML_DB; + if (XML_DB.OpenFile(Filepath.c_str())) + { + std::string gameLangs; + if (XML_DB.GetLanguages((char *)gameHeader.id, gameLangs)) + { + // Check if the game supports the system language (CONF_GetLanguage returns 0-9) + std::string sysLangs[] = {"JA", "EN", "DE", "FR", "ES", "IT", "NL", "ZHCN", "ZHTW", "KO"}; + if (gameLangs.find(sysLangs[CONF_GetLanguage()]) == std::string::npos) + { + // Use whatever is the first supported language + std::string lang = gameLangs.substr(0, gameLangs.find(",")); + for (u32 i = 0; i < sizeof(sysLangs) / sizeof(sysLangs[0]); i++) + { + if (sysLangs[i] == lang) + { + gprintf("Changed language to %s\n", lang.c_str()); + languageChoice = i; + break; + } + } + } + } + XML_DB.CloseFile(); + } + } + AppCleanUp(); gprintf("\tSettings.partition: %d\n", Settings.partition);