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): AsciiString::toLower no longer smashes the stack
Olcay Seygan0425a65830ad
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 56f2baf0f..da073ac13 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -379,6 +379,7 @@ found and fixed — EA's own, not port damage.**- A replay that never recorded which seat was yours plays instead of crashing before the map loads.- Alt-tabbing away with an arrow key held no longer leaves the camera sliding that way when you come back. The key release goes to whatever you switched to, so the game never heard it; losing focus now ends the scroll, the middle-button pan and the ALT pitch drag along with it.- Locking Windows mid-battle no longer eats the game. Nothing that renders runs while the screen is locked, and the particle bookkeeping had been filed under rendering, so every explosion while you were away was created and never cleared up. A hundred rocket buggies firing at the ground for a minute is enough to come back to a game that has run out of memory or simply stopped responding.+- Lowercasing a long name no longer writes off the end of a 2,048 character buffer and takes the game with it. That path handles every file inside an archive and every map name, including one arriving from a host over the network, so it was reachable from outside.- A mission script that waits for a line of speech to finish waits the same length of time on every machine. It used to ask the sound hardware how long the file was, so a player whose sound card was not working, or was turned off, got the answer zero and walked straight through waits that everyone else sat out. That is a different game on two screens, and a replay that stops matching the machine that recorded it. The length now comes out of the file itself: measured on one line of speech, a silent machine said 0 milliseconds and a machine with sound said 3,285. Both say 3,285 now.- Laying a foundation costs less the further up the map you build. Flattening the ground under a new building scanned every row of the map from the bottom edge up to the building, threw all of them away bar the ones actually under it, and did that once per column. It works out the rows it needs now. The ground comes out identical, down to the last unit of height.- EVA announcements that were queued behind another one no longer go quiet. A request waits its turn and expires if its turn never comes, and the sum that worked out when that was could wrap round to zero, retiring the announcement on the frame it was asked for.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cppindex 5e3d66687..c2bc9c0e7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp@@ -228,16 +228,24 @@ void AsciiString::toLower()validate();if (m_data){- char buf[MAX_FORMAT_BUF_LEN];- strcpy(buf, peek());-- char *c = buf;- while (c && *c)+ //+ // This used to strcpy into a fixed 2048 byte buffer on the stack. A longer string - a path,+ // a map name off the network - wrote straight past the end of it, and every call allocated a+ // new buffer for the answer even when the string was already lowercase. Do it where the+ // string already lives, which is the same in-place shape removeLastChar uses just below.+ //+ // tolower() is called on a plain char exactly as it always was. On this compiler a byte+ // above 127 arrives as a negative index and the CRT's table tolerates it; changing that to+ // an unsigned char would be the correct call in the abstract and a different answer for+ // those bytes, and lowercased strings are keys here - the map cache is one.+ //+ const int len = strlen(peek());+ if (len > 0){- *c = tolower(*c);- c++;+ ensureUniqueBufferOfSize(len + 1, true, NULL, NULL);+ for (char *c = peek(); *c; ++c)+ *c = tolower(*c);}- set(buf);}validate();}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex c7fd35603..2db849b47 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -279,6 +279,42 @@ TEST(name_key_generator_round_trips)(Int)TheNameKeyGenerator->nameToLowercaseKey( "tankgeneralusa" ) );}+/* AsciiString::toLower used to strcpy into a fixed 2048-byte stack buffer, so a+ longer string - a path, or a map name arriving over the network - wrote past the+ end of it. 2048 is MAX_FORMAT_BUF_LEN, private to the header, so this walks+ across it rather than naming it. */+TEST(asciistring_tolower_survives_a_string_longer_than_the_old_buffer)+{+ CHECK( bootOnce() );++ AsciiString empty;+ empty.toLower();+ CHECK( empty.isEmpty() ); /* no buffer at all is not a special case */++ AsciiString shrt( "MixedCase.INI" );+ shrt.toLower();+ CHECK_STR( shrt.str(), "mixedcase.ini" );++ for( Int len = 2040; len <= 2060; ++len )+ {+ std::string big( (size_t)len, 'A' );+ big[ (size_t)len - 1 ] = 'Z'; /* so a truncated copy is visible at the end */++ AsciiString str( big.c_str() );+ str.toLower();++ CHECK_EQ( str.getLength(), len );+ CHECK_EQ( (Int)str.str()[ 0 ], (Int)'a' );+ CHECK_EQ( (Int)str.str()[ len - 1 ], (Int)'z' );+ CHECK_EQ( (Int)str.str()[ len ], 0 );+ }++ /* a string with nothing to change comes back the same */+ AsciiString already( "already lower" );+ already.toLower();+ CHECK_STR( already.str(), "already lower" );+}+/* The port aliased hash_map onto unordered_map, which meant supplyingrts::hash<AsciiString>. STLport's default hashed the pointer, so equalstrings in different buffers have to land in the same bucket now. */