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): room for mod-prefixed ini lines under -modfactions

Olcay Seygan6e88f45e3a55
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef7c30673..00042f7ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,7 @@ found and fixed — EA's own, not port damage.**
- Contra's cyborgs no longer stand on black squares. Their little ground shadow is drawn the way Zero Hour draws it again, darkening the ground by the shape painted in the picture, so it comes out as a soft patch under the feet. We had been reading the shape from the picture's transparency instead, and Contra's shadow picture has none: it filled its whole square. Zero Hour's own shadows look as they did.
- A computer opponent on ShockWave's Armor, Special Weapons or Salvage general plays on every map now. Those are the three generals ShockWave adds to Zero Hour's nine, and Shockwave Chaos renames two of them the Scumbag Artillery and Bandana generals. A map made before they existed, every one Zero Hour ships among them, has no computer player for them, so the seat started with no AI at all: its base sat idle, and clicking it with nothing selected handed it to you, which is how a player found himself running the enemy's base. The seat now takes the mod's skirmish AI for that general and builds like any other; on Tournament Desert it had three buildings up in forty seconds where it used to have none.
- ShockWave's EMP Patriot fires its missiles again. ShockWave switched on a short-range field around the battery that EA had left commented out, and every time the field pulsed, every 0.75 seconds, the battery's missiles had to wait their turn again from the start. The turret kept tracking its target and nothing left the rails: a lone EMP Patriot fired 0 missiles in 6 seconds at rocket soldiers 200 away, where Zero Hour's fires 12. The field now keeps its own clock, so the battery fires 12 like Zero Hour's and the field still pulses. ShockWave's Superweapon Humvee, its Reaper tank and its Salvage SA-2 site carried the same pairing.
+- Shockwave Chaos beside a second full mod starts now. With Contra, ShockWave and Shockwave Chaos switched on together the game stopped while loading, on one line of Chaos's Black Market tank that lists 43 of the mod's own tanks it can turn into. Keeping each mod's armies apart puts a short mark in front of every name the mod defines, and that line grew past the room the game gave a line of text. A line has three times the room now, more than any mod can fill.
- A `-mod` path with `.` or `..` in it is refused. An archive counts as your mod's only when it was loaded for that mod. Two mods under `-modfactions` that define a command set with the same name both load now, and the later one wins.
## One interface
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
index a92dee73a..7a27a640c 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
@@ -66,6 +66,9 @@ enum INILoadType
enum
{
INI_MAX_CHARS_PER_LINE = 1028, ///< max characters per line entry in any ini file
+ /// a line once -modfactions has put "M<n>~" before its names: at most one name every two characters,
+ /// four characters of prefix each up to mod 99, so a full line can triple
+ INI_MAX_CHARS_PER_PREFIXED_LINE = INI_MAX_CHARS_PER_LINE * 3,
};
//-------------------------------------------------------------------------------------------------
@@ -518,7 +521,7 @@ protected:
AsciiString m_filename; ///< filename of file currently loading
INILoadType m_loadType; ///< load time for current file
UnsignedInt m_lineNum; ///< current line number that's been read
- char m_buffer[ INI_MAX_CHARS_PER_LINE+1 ];///< buffer to read file contents into
+ char m_buffer[ INI_MAX_CHARS_PER_PREFIXED_LINE+1 ];///< one line of the file, room for its mod prefixes
const char *m_seps; ///< for strtok parsing
const char *m_sepsPercent; ///< m_seps with percent delimiter as well
const char *m_sepsColon; ///< m_seps with colon delimiter as well
@@ -528,7 +531,7 @@ protected:
Bool m_skipUnknownFields; ///< log and skip an unknown field instead of throwing
Bool m_missingSpecialPower; ///< a patch named a special power that does not exist
#if defined(_DEBUG) || defined(_INTERNAL)
- char m_curBlockStart[ INI_MAX_CHARS_PER_LINE ]; ///< first line of cur block
+ char m_curBlockStart[ INI_MAX_CHARS_PER_PREFIXED_LINE+1 ]; ///< first line of cur block, a copy of m_buffer
#endif
};
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
index 9543770a0..61c5f08cb 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
@@ -1225,7 +1225,7 @@ void INI::parseAsciiStringVectorAppend( INI* ini, void * /*instance*/, void *sto
AsciiString INI::getNextQuotedAsciiString()
{
AsciiString result;
- char buff[INI_MAX_CHARS_PER_LINE];
+ char buff[INI_MAX_CHARS_PER_PREFIXED_LINE]; // a token of m_buffer, prefixes and all
const char *token = getNextTokenOrNull(); // if null, just leave an empty string
if (token != NULL)
@@ -1285,7 +1285,7 @@ AsciiString INI::getNextAsciiString()
}
else
{
- static char buff[INI_MAX_CHARS_PER_LINE];
+ static char buff[INI_MAX_CHARS_PER_PREFIXED_LINE];
buff[0] = 0;
if (strlen(token) > 1)
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 936d08782..a2d017c08 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -17346,6 +17346,47 @@ TEST(modfactions_prefix_only_the_mods_own_names)
CHECK_EQ( key, NAMEKEY( "Upgrade_Retail" ) );
}
+// Shockwave Chaos's BlackMarketTank.ini has a 1019-character BuildVariations line of 43 of its own
+// tanks. It fits the file reader, but three characters of "M2~" on each name took it past a buffer of
+// that size, and the game stopped at startup whenever Chaos ran beside another full mod.
+TEST(modfactions_prefixed_line_outgrows_the_raw_line)
+{
+ bootOnce();
+ ModNamespace names;
+ std::string line = " BuildVariations =";
+ for (Int i = 0; i < 43; ++i)
+ {
+ char name[ 32 ];
+ snprintf( name, sizeof( name ), "ChaosVariationTank_X%02d", i );
+ names.scanLine( 1, (std::string( "Object " ) + name).c_str() );
+ line += " ";
+ line += name;
+ }
+ names.finishScan( 1 );
+ names.setActive( 1 );
+ CHECK( (Int)line.size() < INI_MAX_CHARS_PER_LINE );
+
+ char buffer[ INI_MAX_CHARS_PER_PREFIXED_LINE + 1 ];
+ strcpy( buffer, line.c_str() );
+ CHECK( !names.rewriteLine( buffer, INI_MAX_CHARS_PER_LINE + 1 ) ); // the old buffer
+ CHECK( names.rewriteLine( buffer, sizeof( buffer ) ) );
+ CHECK_EQ( (Int)strlen( buffer ), (Int)line.size() + 43 * 3 );
+ CHECK( (Int)strlen( buffer ) > INI_MAX_CHARS_PER_LINE );
+ CHECK( strstr( buffer, " M2~ChaosVariationTank_X00 " ) != NULL );
+ CHECK( strstr( buffer, " M2~ChaosVariationTank_X42" ) != NULL );
+
+ // the worst a full line can do: a one-letter name in every other character, mod 99's prefix on each
+ ModNamespace worst;
+ worst.scanLine( 98, "Object A" );
+ worst.finishScan( 98 );
+ worst.setActive( 98 );
+ std::string full = "X";
+ while ((Int)full.size() + 2 < INI_MAX_CHARS_PER_LINE)
+ full += " A";
+ strcpy( buffer, full.c_str() );
+ CHECK( worst.rewriteLine( buffer, sizeof( buffer ) ) );
+}
+
// The Power of the West defines "FXList No", and -modfactions made every "IsGrantable = No" an
// "M2~No" that parseBool refused: a word the parser reads for itself is never the mod's name.
TEST(modfactions_never_prefix_a_reserved_word)