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): use english when registry language has no data

Olcay Seyganf02a88ab97c5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3129ddb6c..ccec5a0d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1640,6 +1640,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Audio is real, through the audio library the retail game ships with.
- 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.
+- 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 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.
- A sound on the right of the screen comes out of the right speaker. Since the game went 64-bit its sound library worked left and right out the wrong way round, so a tank firing off to the right was heard on the left. Only a sound well off to one side swings far enough to notice, which is why it seemed to come and go.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
index 5f555b554..153fe817b 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
@@ -140,6 +140,10 @@ 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".
+ /// Only meaningful once the archives are mounted.
+ AsciiString installedLanguage(const AsciiString &language) const;
+
Bool areMusicFilesOnCD();
void loadMusicFilesFromCD();
void unloadMusicFilesFromCD();
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Registry.h b/GeneralsMD/Code/GameEngine/Include/Common/Registry.h
index 194927024..2cc0c2c1b 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Registry.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Registry.h
@@ -48,6 +48,9 @@ Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val);
Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt& val);
AsciiString GetRegistryLanguage(void); // convenience function
+/// Replaces what GetRegistryLanguage answers from now on; GameEngine::init uses it once the archives are
+/// mounted, when the registry names a language whose data is not installed (FileSystem::installedLanguage).
+void SetRegistryLanguage(const AsciiString &language);
AsciiString GetRegistryGameName(void); // convenience function
UnsignedInt GetRegistryVersion(void); // convenience function
UnsignedInt GetRegistryMapPackVersion(void); // convenience function
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 178cc3a8c..3568e01e0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -974,6 +974,19 @@ void GameEngine::init( int argc, char *argv[] )
_exit(1);
}
+ // The first place the archives can answer it, and before anything builds a path under
+ // Data\<language>: GlobalLanguage, GameText, the CommandMap, speech and localized art all ask after this.
+ {
+ const AsciiString registryLanguage = GetRegistryLanguage();
+ const AsciiString language = TheFileSystem->installedLanguage( registryLanguage );
+ if (language.compareNoCase( registryLanguage ) != 0)
+ {
+ DEBUG_LOG(("GameEngine::init - Language=%s has no Data\\%s\\Language.ini, using %s\n",
+ registryLanguage.str(), registryLanguage.str(), language.str()));
+ SetRegistryLanguage( language );
+ }
+ }
+
initSubsystem(TheWritableGlobalData, "TheWritableGlobalData", MSGNEW("GameEngineSubsystem") GlobalData(), &xferCRC, "Data\\INI\\Default\\GameData.ini", "Data\\INI\\GameData.ini");
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
index 87f8f97ce..d0196cbab 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
@@ -252,7 +252,7 @@ Bool FileSystem::doesFileExist(const Char *filename) const
m_fileExist[key]=true;
return TRUE;
}
- if (TheArchiveFileSystem->doesFileExist(filename))
+ if (TheArchiveFileSystem != NULL && TheArchiveFileSystem->doesFileExist(filename))
{
m_fileExist[key]=true;
return TRUE;
@@ -315,6 +315,19 @@ Bool FileSystem::createDirectory(AsciiString directory)
return FALSE;
}
+//============================================================================
+// FileSystem::installedLanguage
+//============================================================================
+/* 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). */
+AsciiString FileSystem::installedLanguage(const AsciiString &language) const
+{
+ AsciiString probe;
+ probe.format("Data\\%s\\Language.ini", language.str());
+ return doesFileExist(probe.str()) ? language : AsciiString("english");
+}
+
//============================================================================
// FileSystem::areMusicFilesOnCD
//============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp
index d7949452f..ff4e127d0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp
@@ -361,19 +361,23 @@ Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt&
}
#endif
+// NOTE: static causes a memory leak, but we have to keep it because the value is cached.
+static AsciiString s_registryLanguage = "english";
+static Bool s_registryLanguageCached = FALSE;
+
AsciiString GetRegistryLanguage(void)
{
- static Bool cached = FALSE;
- // NOTE: static causes a memory leak, but we have to keep it because the value is cached.
- static AsciiString val = "english";
- if (cached) {
- return val;
- } else {
- cached = TRUE;
+ if (!s_registryLanguageCached) {
+ s_registryLanguageCached = TRUE;
+ GetStringFromRegistry("", "Language", s_registryLanguage);
}
+ return s_registryLanguage;
+}
- GetStringFromRegistry("", "Language", val);
- return val;
+void SetRegistryLanguage(const AsciiString &language)
+{
+ s_registryLanguageCached = TRUE;
+ s_registryLanguage = language;
}
AsciiString GetRegistryGameName(void)
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 1fd376793..b38f8d598 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -183,6 +183,7 @@ static int GetSystemMetrics( int which )
#include <math.h>
#include <atomic>
#include <chrono>
+#include <filesystem>
#include <thread>
//////////////////////////////////////////////////////////////////////////////
@@ -520,6 +521,27 @@ TEST(ini_missing_file_throws)
CHECK( threw );
}
+/* 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. */
+TEST(installed_language_falls_back_to_english_when_its_data_is_missing)
+{
+ CHECK( bootOnce() );
+
+ /* on POSIX the backslashed name is one flat file in the working directory, which is also
+ what the test file system's fopen looks for */
+ std::error_code ec;
+ std::filesystem::create_directories( "Data/zhtestlang", ec );
+ writeFile( "Data\\zhtestlang\\Language.ini", "; test\n" );
+
+ CHECK_STR( TheFileSystem->installedLanguage( AsciiString( "zhtestlang" ) ).str(), "zhtestlang" );
+ CHECK_STR( TheFileSystem->installedLanguage( AsciiString( "zhtestnodata" ) ).str(), "english" );
+
+ remove( "Data\\zhtestlang\\Language.ini" );
+ std::filesystem::remove( "Data/zhtestlang", ec );
+ std::filesystem::remove( "Data", ec ); // only if this test made it; a non-empty one stays
+}
+
/* An unknown block name aborts the whole file - INI::load throws
INI_UNKNOWN_TOKEN and the blocks after it never get read. Worth pinning:
nothing in the loader skips unknown blocks, so an INI written for a newer