From 4a28783478f42e438df50e2c58f8520e98bef954 Mon Sep 17 00:00:00 2001 From: athrxx Date: Thu, 11 Aug 2022 22:52:48 +0200 Subject: [PATCH] KYRA: (LOK/Mac) - priorize resource files that match the selected language The talkie version seems to have file versions for all supported languages in the game folder. So we try the ones that match our language first. --- engines/kyra/engine/kyra_lok.cpp | 18 ++++++++++++++++++ engines/kyra/engine/kyra_lok.h | 2 ++ engines/kyra/resource/staticres.cpp | 6 +++--- engines/kyra/sequence/sequences_lok.cpp | 5 ++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/engines/kyra/engine/kyra_lok.cpp b/engines/kyra/engine/kyra_lok.cpp index dac0ecc7f17..a4c33de10e1 100644 --- a/engines/kyra/engine/kyra_lok.cpp +++ b/engines/kyra/engine/kyra_lok.cpp @@ -95,6 +95,24 @@ KyraEngine_LoK::KyraEngine_LoK(OSystem *system, const GameFlags &flags) _malcolmFrame = 0; _malcolmTimer1 = _malcolmTimer2 = 0; + + // Determine search order for resource files with language specific file endings. Some versions have multiple + // versions in the folder, so we make sure that the one that matches the selected language gets tried first. + static const Common::Language langOrder[] = { + Common::EN_ANY, Common::FR_FRA, Common::DE_DEU, Common::ES_ESP, Common::IT_ITA, Common::HE_ISR, Common::KO_KOR + }; + static const char *pattern[] = { "15", "_ENG", "_FRE", "_GER", "_SPA", "_ITA", "_HEB", "_HAN", "" }; + uint8 _langFileExtIndex[ARRAYSIZE(pattern)]; + memset(_langFileExtIndex, 0, sizeof(_langFileExtIndex)); + for (int i = 0; i < ARRAYSIZE(langOrder); ++i) { + if (_flags.lang == langOrder[i]) + _langFileExtIndex[0] = i + 1; + } + for (int i = 1; i < ARRAYSIZE(_langFileExtIndex); ++i) + _langFileExtIndex[i] = (i <= _langFileExtIndex[0]) ? i - 1 : i; + for (int i = 0; i < ARRAYSIZE(_langFileExtIndex); ++i) + _langFileExt.push_back(pattern[_langFileExtIndex[i]]); + _defaultFont = Screen::FID_8_FNT; _noteFont = (_flags.isTalkie || flags.platform == Common::kPlatformAmiga) ? _defaultFont : Screen::FID_6_FNT; _defaultLineSpacing = 0; diff --git a/engines/kyra/engine/kyra_lok.h b/engines/kyra/engine/kyra_lok.h index a34f9522089..006b114c75b 100644 --- a/engines/kyra/engine/kyra_lok.h +++ b/engines/kyra/engine/kyra_lok.h @@ -528,6 +528,8 @@ protected: static const int8 _macLQTrackMap[]; static const int _macLQTrackMapSize; + Common::Array _langFileExt; + // TODO: get rid of all variables having pointers to the static resources if possible // i.e. let them directly use the _staticres functions void initStaticResource(); diff --git a/engines/kyra/resource/staticres.cpp b/engines/kyra/resource/staticres.cpp index fceb05f19eb..809c66b24da 100644 --- a/engines/kyra/resource/staticres.cpp +++ b/engines/kyra/resource/staticres.cpp @@ -998,9 +998,9 @@ void KyraEngine_LoK::loadMainScreen(int page) { _screen->clearPage(page); bool success = false; - static const char *pattern[] = { "15", "_ENG", "_FRE", "_GER", "_SPA", "_ITA", "_HEB", "_HAN", "" }; - for (int i = 0; i < ARRAYSIZE(pattern) && !success; ++i) { - Common::String tryFile = Common::String::format("MAIN%s.CPS", pattern[i]); + + for (int i = 0; i < _langFileExt.size() && !success; ++i) { + Common::String tryFile = Common::String::format("MAIN%s.CPS", _langFileExt[i].c_str()); if ((success = _res->exists(tryFile.c_str()))) _screen->loadBitmap(tryFile.c_str(), page, page, i == 0 ? &_screen->getPalette(0) : 0); } diff --git a/engines/kyra/sequence/sequences_lok.cpp b/engines/kyra/sequence/sequences_lok.cpp index c523aa6956a..b6f35c9b765 100644 --- a/engines/kyra/sequence/sequences_lok.cpp +++ b/engines/kyra/sequence/sequences_lok.cpp @@ -252,9 +252,8 @@ bool KyraEngine_LoK::seq_introStory() { return false; bool success = false; - static const char *pattern[] = { "", "_ENG", "_FRE", "_GER", "_SPA", "_ITA", "_HEB", "_HAN" }; - for (int i = 0; i < ARRAYSIZE(pattern) && !success; ++i) { - Common::String tryFile = Common::String::format("TEXT%s.CPS", pattern[i]); + for (int i = 0; i < _langFileExt.size() && !success; ++i) { + Common::String tryFile = Common::String::format("TEXT%s.CPS", _langFileExt[i].c_str()); if ((success = _res->exists(tryFile.c_str()))) _screen->loadBitmap(tryFile.c_str(), 3, 3, &_screen->getPalette(0)); }