Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameengine): fall back to any installed language when english is missing

Olcay Seyganc879fe326ed0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2df47769e..a48ea6a7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1734,7 +1734,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Installs from outside Steam start again. Their copy of the game's data files differs from Steam's in a few places, and one of our fixes, to the Aurora's fuel-air bomb, looked for a piece that copy does not have and stopped the game at start with a parsing error. A fix that finds nothing to change now leaves that piece as it is and the game carries on.
- The Shockwave mod no longer stops the game at start. Our balance pass gives the Tank General's bunker 1500 health, Shockwave builds that bunker from different parts, and the game quit with a parsing error naming the bunker. A change that finds some other kind of part where it expected the bunker's health is now passed over, and the mod's bunker keeps the health the mod gave it.
- Contra X Beta 2 starts too. Our China command center menu puts the early Carpet Bomb in its second slot, Contra has no such button, and the game quit at start with a parsing error naming that menu. A menu slot that asks for a button the loaded game does not have is now left empty, and the rest of the menu fills in as before.
-- A game set to a language it has no files for starts in English. A player whose Windows still said German, with only the English game installed, saw it close as it started: the game went looking for German menus and fonts, found none and closed. It now notices before it loads any text and plays in English.
+- A game set to a language it has no files for starts in English. A player whose Windows still said German, with only the English game installed, saw it close as it started: the game went looking for German menus and fonts, found none and closed. It now notices before it loads any text and plays in English. A German or Russian copy with no English files at all closed the same way after 2.5.0, because English was the only language the game knew to fall back to. It now takes whichever language your copy does have, and a copy with none says so and tells you to verify the game's files in Steam.
- A death cry plays to the end. So does "construction complete", and the tail of a gun. Telling a sound to stop used to cut it off that frame, where the 2003 game let it finish and only kept it from repeating; our own fix for the audio thread broke that, and it is put back. A looping sound caught in the pause between two plays can be stopped too, instead of carrying on after whatever made it is gone.
- Birdsong no longer drowns out the battle. Every sound on the map played at full volume all the way out to the edge of its range, because the game handed the sound library its near and far distances the wrong way round. A sound that carries a long way, like the birds and the wind, came through at full strength from across the map, while a gun firing just off screen had already been cut. Sounds get quieter with distance now, at the same rate the game uses to decide when one is too faint to keep playing, so what is close to the camera is what you hear.
- The world around the battle has its own volume. Birds, wind, waves, crickets and the murmur of a town, 148 looping background sounds in the game's data, played on the Sound FX slider at the same level as the guns, and on a forest or harbour map they covered the replies and the shots. They now answer to an Ambient slider on the Audio page, beside Music, Sound FX and Voice, and it starts at 40%, half of where Sound FX starts. Moving Sound FX leaves them alone. Unit engines, weapons, voices and explosions stay on Sound FX.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
index 153fe817b..07b5a76bb 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
@@ -140,7 +140,8 @@ public:
Bool createDirectory(AsciiString directory); ///< create a directory of the given name.
- /// language when Data\<language>\Language.ini is loose or in an archive, otherwise "english".
+ /// language when Data\<language>\Language.ini is loose or in an archive, otherwise the first
+ /// retail language that has one (english first), otherwise empty.
/// Only meaningful once the archives are mounted.
AsciiString installedLanguage(const AsciiString &language) const;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 9c0ac6578..949a98009 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -979,6 +979,13 @@ void GameEngine::init( int argc, char *argv[] )
{
const AsciiString registryLanguage = GetRegistryLanguage();
const AsciiString language = TheFileSystem->installedLanguage( registryLanguage );
+ if (language.isEmpty())
+ {
+ DEBUG_LOG(("GameEngine::init - no Data\\<language>\\Language.ini in any archive\n"));
+
+ MessageBoxWrapper( "Zero Hour's language files are missing: no Language.ini was found for any language.\n\nVerify the game's files in Steam, or reinstall Command & Conquer Generals Zero Hour.", "Command & Conquer Generals Zero Hour", MSGBOX_OK | MSGBOX_TASKMODAL | MSGBOX_ICONERROR );
+ _exit(1);
+ }
if (language.compareNoCase( registryLanguage ) != 0)
{
DEBUG_LOG(("GameEngine::init - Language=%s has no Data\\%s\\Language.ini, using %s\n",
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
index d0196cbab..c5f6af32b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
@@ -320,12 +320,25 @@ Bool FileSystem::createDirectory(AsciiString directory)
//============================================================================
/* The registry's Language outlives the files it names: a Steam install switched from German to
English keeps Language=german with only EnglishZH.big beside the exe, and GlobalLanguage::init
- then threw on Data\german\Language.ini before the first frame (player report #39). */
+ then threw on Data\german\Language.ini before the first frame (player report #39). A German-only
+ install has no english to fall back to either (issue #63), so every retail language is tried.
+ Empty when no Language.ini is found at all. */
AsciiString FileSystem::installedLanguage(const AsciiString &language) const
{
+ static const char *const fallbacks[] = { "english", "german", "french", "spanish", "italian",
+ "korean", "chinese", "brazilian", "polish", "russian" };
AsciiString probe;
- probe.format("Data\\%s\\Language.ini", language.str());
- return doesFileExist(probe.str()) ? language : AsciiString("english");
+ if (!language.isEmpty()) {
+ probe.format("Data\\%s\\Language.ini", language.str());
+ if (doesFileExist(probe.str()))
+ return language;
+ }
+ for (Int i = 0; i < (Int)(sizeof(fallbacks) / sizeof(fallbacks[0])); ++i) {
+ probe.format("Data\\%s\\Language.ini", fallbacks[i]);
+ if (doesFileExist(probe.str()))
+ return AsciiString(fallbacks[i]);
+ }
+ return AsciiString::TheEmptyString;
}
//============================================================================
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index db57736ca..38ad45b57 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -538,7 +538,8 @@ TEST(ini_missing_file_throws)
/* Player report #39: Language=german in the registry, only English data installed, and
GlobalLanguage::init threw on Data\german\Language.ini at startup. GameEngine::init now asks
- installedLanguage once the archives are up and falls back to english. */
+ installedLanguage once the archives are up and falls back to the first retail language that has
+ data (issue #63: a German-only install has no english either), or to nothing at all. */
TEST(installed_language_falls_back_to_english_when_its_data_is_missing)
{
CHECK( bootOnce() );
@@ -550,7 +551,8 @@ TEST(installed_language_falls_back_to_english_when_its_data_is_missing)
writeFile( "Data\\zhtestlang\\Language.ini", "; test\n" );
CHECK_STR( TheFileSystem->installedLanguage( AsciiString( "zhtestlang" ) ).str(), "zhtestlang" );
- CHECK_STR( TheFileSystem->installedLanguage( AsciiString( "zhtestnodata" ) ).str(), "english" );
+ // no retail language has data here, so there is nothing to fall back to
+ CHECK_STR( TheFileSystem->installedLanguage( AsciiString( "zhtestnodata" ) ).str(), "" );
remove( "Data\\zhtestlang\\Language.ini" );
std::filesystem::remove( "Data/zhtestlang", ec );