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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): skip unknown fields in a map's map.ini instead of crashing
Olcay Seyganbfc6239b33de
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fcaaf6e65..20a34b20c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -936,6 +936,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Quitting faulted twice every time; it now takes about half a second.- A long chat message or an unusual map name could kill the process.- A map name the game cannot make sense of is refused as you start, instead of taking the game down later. A path with a space in it and no quotes around it left the loader walking the same step of that path forever, growing a string until it ran out of room, and the game then went on starting with half of itself missing. What you saw was a crash a second later, in the part of the game that runs a match, naming nothing that had anything to do with it. Any failure during start-up now stops the game there and says which one it was.+- A downloaded map made for another mod loads instead of crashing as the match starts. Maps can carry their own tweaks to units, and one a player tried gave a wall a setting Zero Hour has never had; one unfamiliar line was enough to take the whole game down. A setting the game does not know is now passed over and the rest of the map's tweaks still apply.- Starting the game from the folder the zip was unpacked to says what is wrong. None of Zero Hour's own files are in that folder, so the first one the game asked for was missing, and the box that came up blamed viruses and overheated hardware. It now names the folder it looked in and tells you to run install.bat.- A machine that once had Generals installed from a disc or The First Decade, and later removed it, no longer loses the original game's files. The old install leaves its address behind in Windows, the game trusted it over the copy Steam keeps beside Zero Hour, and the main menu came up over magenta water and black hills. A folder that turns out to be empty is passed over now.- Buying both games on Steam is enough. Steam writes nothing to Windows saying where it put them and installs the two side by side in their own folders, so the game had no way of finding the original one unless you had copied its files across by hand: a fresh install of both came up on a magenta main menu with most of the sound effects missing. The folder next to Zero Hour's is searched now. When the original game's files really are nowhere, a box names the folder to put them in, rather than leaving you to read a pink menu.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.hindex 074c0d4cc..4a234e78d 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h@@ -246,6 +246,11 @@ public:inline AsciiString getFilename( void ) const { return m_filename; }inline INILoadType getLoadType( void ) const { return m_loadType; }inline UnsignedInt getLineNum( void ) const { return m_lineNum; }++ /** A map.ini is written by a map maker, often against another mod's objects, and one field+ this game does not know used to end the match before it started. Set, an unknown field+ name is logged and its line skipped instead of throwing. */+ inline void setSkipUnknownFields( Bool skip ) { m_skipUnknownFields = skip; }inline const char *getSeps( void ) const { return m_seps; }inline const char *getSepsPercent( void ) const { return m_sepsPercent; }inline const char *getSepsColon( void ) const { return m_sepsColon; }@@ -410,6 +415,7 @@ protected:const char *m_sepsQuote; ///< token to represent a quoted ascii stringconst char *m_blockEndToken; ///< token to represent end of data blockBool m_endOfFile; ///< TRUE when we've hit EOF+ Bool m_skipUnknownFields; ///< log and skip an unknown field instead of throwing#if defined(_DEBUG) || defined(_INTERNAL)char m_curBlockStart[ INI_MAX_CHARS_PER_LINE ]; ///< first line of cur block#endifdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cppindex b9d487e77..747ee7f33 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp@@ -196,6 +196,7 @@ INI::INI( void )m_sepsQuote = "\"\n="; ///< stop at " = EOLm_blockEndToken = "END";m_endOfFile = FALSE;+ m_skipUnknownFields = FALSE;m_buffer[0] = 0;#if defined(_DEBUG) || defined(_INTERNAL)m_curBlockStart[0] = 0;@@ -1547,7 +1548,12 @@ void INI::initFromINIMulti( void *what, const MultiIniFieldParse& parseTableList}}- if (!found)+ if (!found && m_skipUnknownFields)+ {+ DEBUG_LOG(("[LINE: %d - FILE: '%s'] skipping unknown field '%s'\n",+ INI::getLineNum(), INI::getFilename().str(), field));+ }+ else if (!found){DEBUG_ASSERTCRASH( 0, ("[LINE: %d - FILE: '%s'] Unknown field '%s' in block '%s'\n",INI::getLineNum(), INI::getFilename().str(), field, m_curBlockStart) );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 78d2990f1..21de7aa8f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -2534,6 +2534,7 @@ void GameLogic::loadMapINI( AsciiString mapName )if (TheFileSystem->doesFileExist(fullFledgeFilename)) {DEBUG_LOG(("Loading map.ini\n"));INI ini;+ ini.setSkipUnknownFields( TRUE );ini.load( AsciiString(fullFledgeFilename), INI_LOAD_CREATE_OVERRIDES, NULL );}@@ -2541,6 +2542,7 @@ void GameLogic::loadMapINI( AsciiString mapName )if (TheFileSystem->doesFileExist(fullFledgeFilename)) {DEBUG_LOG(("Loading solo.ini\n"));INI ini;+ ini.setSkipUnknownFields( TRUE );ini.load( AsciiString(fullFledgeFilename), INI_LOAD_CREATE_OVERRIDES, NULL );}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 9c95ccd19..b10154a70 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -488,6 +488,39 @@ TEST(ini_unknown_block_aborts_the_file)remove( TEST_INI );}+/* A map.ini from a player's map folder named a ThreatLevel field on an Object, which Zero Hour has+ never had, and the match crashed while loading. GameLogic loads map.ini with unknown fields+ skipped; every other file still throws on one. */+TEST(ini_unknown_field_is_skipped_only_when_asked)+{+ CHECK( bootOnce() );++ writeFile( TEST_INI,+ "WaterSet EVENING\r\n"+ " ThreatLevel = 3\r\n"+ " WaterRepeatCount = 6\r\n"+ "End\r\n" );++ WaterSettings[ TIME_OF_DAY_EVENING ].m_waterRepeatCount = -1;+ CHECK( loadIni( TEST_INI ) == FALSE );++ Bool threw = FALSE;+ INI ini;+ ini.setSkipUnknownFields( TRUE );+ try+ {+ ini.load( AsciiString( TEST_INI ), INI_LOAD_OVERWRITE, NULL );+ }+ catch( ... )+ {+ threw = TRUE;+ }+ CHECK( threw == FALSE );+ CHECK_EQ( WaterSettings[ TIME_OF_DAY_EVENING ].m_waterRepeatCount, 6 );++ remove( TEST_INI );+}+/* Data\INI\FXListReforged.ini is the fork's own explosion light: 89 of EA's FXLists, each repeatedwhole with one LightPulse added. Whole, because FXListStore::parseFXListDefinition clears anentry before re-reading it - a half-copied block does not add a light, it deletes an explosion.