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): load contra and the power of the west under -mod

Olcay Seygan6beac9bc128f
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
index e6ff684a9..35ebdb82b 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
@@ -322,6 +322,25 @@ public:
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; }
+
+ /** A patch INI loaded over a mod can name a special power the mod does not have. The reference
+ raises this, and ThingTemplate::parseModuleName drops the module it was read into. */
+ inline void setMissingSpecialPower( Bool missing ) { m_missingSpecialPower = missing; }
+ inline Bool hasMissingSpecialPower( void ) const { return m_missingSpecialPower; }
+
+ /** -modfactions prefixes every word a mod names a block with, and a mod can name one after an
+ engine word: The Power of the West has a ParticleSystem "Explosion", so "DamageType = Explosion"
+ arrived as "M2~Explosion". A fixed list of names (an enum, Yes/No) is never a mod's, so its
+ scanners read past the prefix. No retail name holds a '~'. */
+ static const char *withoutModPrefix( const char *token )
+ {
+ const char *p = token;
+ if (*p++ != 'M' || *p < '0' || *p > '9')
+ return token;
+ while (*p >= '0' && *p <= '9')
+ ++p;
+ return *p == '~' ? p + 1 : token;
+ }
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; }
@@ -488,6 +507,7 @@ protected:
const char *m_blockEndToken; ///< token to represent end of data block
Bool m_endOfFile; ///< TRUE when we've hit EOF
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
#endif
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
index f17463ecf..274d99b11 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
@@ -203,6 +203,7 @@ INI::INI( void )
m_blockEndToken = "END";
m_endOfFile = FALSE;
m_skipUnknownFields = FALSE;
+ m_missingSpecialPower = FALSE;
m_buffer[0] = 0;
#if defined(_DEBUG) || defined(_INTERNAL)
m_curBlockStart[0] = 0;
@@ -602,6 +603,19 @@ void ModNamespace::finishScan( Int mod )
Names &names = m_mods[ mod ];
for (std::set<std::string>::const_iterator it = names.sides.begin(); it != names.sides.end(); ++it)
names.all.erase( *it );
+ // nor a word the parser reads for itself: The Power of the West has an "FXList No", and every
+ // "IsGrantable = No" became "M2~No", which is no Bool
+ static const char *const Reserved[] = { "none", "no", "yes", "true", "false", "end", "default" };
+ for (std::set<std::string>::iterator it = names.all.begin(); it != names.all.end(); )
+ {
+ Bool reserved = FALSE;
+ for (size_t i = 0; i < ARRAY_SIZE( Reserved ) && !reserved; ++i)
+ reserved = stricmp( it->c_str(), Reserved[ i ] ) == 0;
+ if (reserved)
+ it = names.all.erase( it );
+ else
+ ++it;
+ }
}
/// A-Z only: the result goes into the INI checksum, so no locale may decide it
@@ -993,6 +1007,7 @@ void INI::parseBitInInt32( INI *ini, void *instance, void *store, const void* us
/*static*/ Bool INI::scanBool(const char* token)
{
// translate string yes/no into TRUE/FALSE
+ token = withoutModPrefix( token );
if( strcasecmp( token, "yes" ) == 0 )
return TRUE;
else if( strcasecmp( token, "no" ) == 0 )
@@ -1723,7 +1738,13 @@ void INI::parseSpecialPowerTemplate( INI* ini, void * /*instance*/, void *store,
}
const SpecialPowerTemplate *sPowerT = TheSpecialPowerStore->findSpecialPowerTemplate( AsciiString( token ) );
- if( !sPowerT && strcasecmp( token, "None" ) != 0 )
+ if( !sPowerT && strcasecmp( token, "None" ) != 0 && ini->getLoadType() == INI_LOAD_MULTIFILE )
+ {
+ // a patch INI loaded over a mod, as with a missing science (scanScience): Contra has no Nuke_ carpet bomb
+ DEBUG_LOG(("[LINE: %d in '%s'] special power '%s' does not exist; the module is skipped.\n", ini->getLineNum(), ini->getFilename().str(), token));
+ ini->setMissingSpecialPower( TRUE );
+ }
+ else if( !sPowerT && strcasecmp( token, "None" ) != 0 )
{
DEBUG_CRASH( ("[LINE: %d in '%s'] Specialpower %s not found!\n", ini->getLineNum(), ini->getFilename().str(), token) );
}
@@ -2004,6 +2025,7 @@ void INI::initFromINIMulti( void *what, const MultiIniFieldParse& parseTableList
}
// search for matching name
+ token = withoutModPrefix( token );
Int count = 0;
for(ConstCharPtrArray name = nameList; *name; name++, count++ )
{
@@ -2028,6 +2050,7 @@ void INI::initFromINIMulti( void *what, const MultiIniFieldParse& parseTableList
}
// search for matching name
+ token = withoutModPrefix( token );
Bool found = false;
for( const LookupListRec* lookup = &lookupList[0]; lookup->name; lookup++ )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
index f460a2553..593024cc6 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
@@ -212,8 +212,9 @@ void ArchiveFileSystem::loadMods() {
// In command-line order, each with overwrite: a later -mod wins over an earlier one, and all of them
// over the retail archives. Under -modfactions a -modpatch goes over the full mod it was given
- // after, in that mod's own tree, or over retail's when it came first (-1). A folder's archives go
- // in the order Win32BIGFileSystem's own pass uses.
+ // after, in that mod's own tree, or over retail's when it came first (-1). Inside one folder the
+ // first name wins, as in Win32BIGFileSystem's plain pass, so a mod's "!!" or "00_" archive is its
+ // patch: the folder goes in descending name order, each with overwrite.
std::vector< std::pair<Int, AsciiString> > layers;
for (size_t i = 0; i < TheGlobalData->m_retailPatches.size(); ++i)
layers.push_back(std::make_pair(-1, TheGlobalData->m_retailPatches[i]));
@@ -232,7 +233,7 @@ void ArchiveFileSystem::loadMods() {
else
archives.insert(mod);
- for (FilenameListIter it = archives.begin(); it != archives.end(); ++it)
+ for (FilenameList::reverse_iterator it = archives.rbegin(); it != archives.rend(); ++it)
{
if (isReforgedArchiveName(*it))
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
index 4d6346268..6134665a1 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
@@ -618,7 +618,15 @@ void ThingTemplate::parseModuleName(INI* ini, void *instance, void* store, const
throw INI_INVALID_DATA;
}
+ ini->setMissingSpecialPower(FALSE);
ModuleData* data = TheModuleFactory->newModuleDataFromINI(ini, tokenStr, type, moduleTagStr);
+ if (ini->hasMissingSpecialPower())
+ {
+ // read to its End and dropped: a special power module with no template faults placing the object
+ DEBUG_LOG(("[LINE: %d - FILE: '%s'] %s %s on %s is skipped.\n",
+ ini->getLineNum(), ini->getFilename().str(), tokenStr.str(), moduleTagStr.str(), self->getName().str()));
+ return;
+ }
if (data->isAiModuleData())
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
index 8fee73c76..e6a78e37e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
@@ -86,7 +86,7 @@ Real ArmorTemplate::adjustDamage(DamageType t, Real damage) const
{
ArmorTemplate* self = (ArmorTemplate*) instance;
- const char* damageName = ini->getNextToken();
+ const char* damageName = INI::withoutModPrefix(ini->getNextToken());
Real pct = INI::scanPercentToReal(ini->getNextToken());
if (strcasecmp(damageName, "Default") == 0)
@@ -98,7 +98,14 @@ Real ArmorTemplate::adjustDamage(DamageType t, Real damage) const
return;
}
- DamageType dt = (DamageType)INI::scanIndexList(damageName, DamageTypeFlags::getBitNames());
+ // EA's parse let a misspelt type through (The Power of the West has INFANTRY_MISSIL) and wrote it at
+ // index -1; the line is skipped instead, as a mod's data written against retail expects
+ Int dt = DamageTypeFlags::getSingleBitFromName(damageName);
+ if (dt < 0)
+ {
+ DEBUG_LOG(("[LINE: %d in '%s'] damage type '%s' does not exist; the armor line is skipped.\n", ini->getLineNum(), ini->getFilename().str(), damageName));
+ return;
+ }
self->m_damageCoefficient[dt] = pct;
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 9baf6a25d..34f17877c 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -72,6 +72,8 @@
#include "Common/ThingTemplate.h"
#include "Common/ThingFactory.h"
#include "Common/ModuleFactory.h"
+#include "Common/SpecialPower.h"
+#include "GameLogic/Armor.h"
#include "Common/SimulationMathCrc.h"
#include "GameLogic/FPUControl.h"
#include "GameLogic/ExperienceTracker.h"
@@ -824,6 +826,100 @@ TEST(patch_of_a_missing_object_is_skipped)
}
}
+/* FixesReforged.ini gives every China Command Center the Nuke_ and Early_ carpet bombers. Contra has
+ no such special powers, the module kept a NULL template, and placing the start building faulted in
+ SpecialPowerModule's constructor. A patch's module naming a missing power is read and dropped. */
+TEST(patch_module_with_a_missing_special_power_is_skipped)
+{
+ CHECK( bootOnce() );
+
+ GlobalData *savedGlobals = TheWritableGlobalData;
+ if( savedGlobals == NULL )
+ TheWritableGlobalData = NEW GlobalData;
+ if( TheModuleFactory == NULL )
+ {
+ TheModuleFactory = NEW ModuleFactory;
+ TheModuleFactory->init();
+ }
+ if( TheThingFactory == NULL )
+ TheThingFactory = NEW ThingFactory;
+ if( TheSpecialPowerStore == NULL )
+ TheSpecialPowerStore = NEW SpecialPowerStore;
+
+ writeFile( TEST_INI,
+ "Object MissingPowerProbe\r\n"
+ " Behavior = DestroyDie ModuleTag_01\r\n"
+ " End\r\n"
+ "End\r\n" );
+ CHECK( loadIni( TEST_INI ) );
+
+ writeFile( TEST_INI,
+ "Object MissingPowerProbe\r\n"
+ " AddModule\r\n"
+ " Behavior = OCLSpecialPower ModuleTag_22Nuke_Fix\r\n"
+ " SpecialPowerTemplate = Nuke_MissingPowerProbe\r\n"
+ " End\r\n"
+ " End\r\n"
+ " BuildCost = 900\r\n"
+ "End\r\n" );
+ Bool threw = FALSE;
+ try
+ {
+ INI patch;
+ patch.load( AsciiString( TEST_INI ), INI_LOAD_MULTIFILE, NULL );
+ }
+ catch( ... )
+ {
+ threw = TRUE;
+ }
+ CHECK( threw == FALSE );
+
+ const ThingTemplate *probe = TheThingFactory->findTemplate( "MissingPowerProbe" );
+ CHECK( probe != NULL );
+ if( probe != NULL )
+ {
+ CHECK_EQ( probe->getBehaviorModuleInfo().getCount(), 1 );
+ CHECK_EQ( probe->friend_getBuildCost(), 900 );
+ }
+
+ remove( TEST_INI );
+ if( savedGlobals == NULL )
+ {
+ delete TheWritableGlobalData;
+ TheWritableGlobalData = NULL;
+ }
+}
+
+/* The Power of the West's Armor.ini has "Armor = INFANTRY_MISSIL 100%". EA's parse let it through,
+ 264e2180 made it throw and the mod stopped at start. An unknown damage type skips its line; a
+ line with no percentage is still a syntax error. */
+TEST(armor_skips_an_unknown_damage_type)
+{
+ CHECK( bootOnce() );
+
+ if( TheArmorStore == NULL )
+ TheArmorStore = NEW ArmorStore;
+
+ writeFile( TEST_INI,
+ "Armor UnknownDamageProbe\r\n"
+ " Armor = INFANTRY_MISSIL 100%\r\n"
+ " Armor = SMALL_ARMS 50%\r\n"
+ "End\r\n" );
+ CHECK( loadIni( TEST_INI ) );
+ const ArmorTemplate *armor = TheArmorStore->findArmorTemplate( "UnknownDamageProbe" );
+ CHECK( armor != NULL );
+ if( armor != NULL )
+ CHECK_NEAR( armor->adjustDamage( DAMAGE_SMALL_ARMS, 100.0f ), 50.0f, 0.01f );
+
+ writeFile( TEST_INI,
+ "Armor UnknownDamageProbeBroken\r\n"
+ " Armor = SMALL_ARMS\r\n"
+ "End\r\n" );
+ CHECK( loadIni( TEST_INI ) == FALSE );
+
+ remove( TEST_INI );
+}
+
/* Data\INI\FXListReforged.ini is the fork's own explosion light: 89 of EA's FXLists, each repeated
whole with one LightPulse added. Whole, because FXListStore::parseFXListDefinition clears an
entry before re-reading it - a half-copied block does not add a light, it deletes an explosion.
@@ -16497,6 +16593,37 @@ TEST(modfactions_prefix_only_the_mods_own_names)
CHECK_EQ( key, NAMEKEY( "Upgrade_Retail" ) );
}
+// 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)
+{
+ bootOnce();
+ ModNamespace names;
+ names.scanLine( 0, "FXList No" );
+ names.scanLine( 0, "Upgrade None" );
+ names.scanLine( 0, "FXList FX_Nope" );
+ names.finishScan( 0 );
+ names.setActive( 0 );
+
+ char line[ 64 ];
+ strcpy( line, " IsGrantable = No" );
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " IsGrantable = No" );
+ strcpy( line, " PrerequisiteSciences = None" );
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " PrerequisiteSciences = None" );
+ strcpy( line, " FX = FX_Nope" );
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " FX = M1~FX_Nope" );
+
+ // and a name it gave a block that is also an engine word ("ParticleSystem Explosion") still reads as
+ // that word where only engine words go
+ CHECK( INI::scanBool( "M2~Yes" ) );
+ CHECK_EQ( INI::scanIndexList( "M2~SMALL_ARMS", DamageTypeFlags::getBitNames() ), (Int)DAMAGE_SMALL_ARMS );
+ CHECK_STR( INI::withoutModPrefix( "M~Explosion" ), "M~Explosion" );
+ CHECK_STR( INI::withoutModPrefix( "MX2~Explosion" ), "MX2~Explosion" );
+}
+
class ModTestArchiveFile : public ArchiveFile
{
public:
diff --git a/Tools/Balance/unitmatrix.py b/Tools/Balance/unitmatrix.py
index 43ca5ed0a..b5d897168 100644
--- a/Tools/Balance/unitmatrix.py
+++ b/Tools/Balance/unitmatrix.py
@@ -127,8 +127,9 @@ class GameFiles:
for big in bigs:
self._index(big, big.name.lower().startswith("patch"))
if mod:
- # a folder's archives in FilenameList order (case-insensitive, subfolders too), each with overwrite
- for big in sorted(mod.rglob("*.big"), key=lambda big: str(big).lower()):
+ # a folder's archives against FilenameList order (case-insensitive, subfolders too), each with
+ # overwrite, so the first name wins as in retail's own pass ("!!" or "00_" is the mod's patch)
+ for big in sorted(mod.rglob("*.big"), key=lambda big: str(big).lower(), reverse=True):
if not is_reforged_archive(big):
self._index(big, True)
for big in bigs: