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): skip ini patches of objects a mod removed

Olcay Seygan86e0de9f0505
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45b83eac8..72908f215 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1748,6 +1748,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- 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.
- The Shockwave mod no longer stops the game at start. Our balance pass gives the Tank General's bunker 1500 health, Shockwave builds that bunker from different parts, and the game quit with a parsing error naming the bunker. A change that finds some other kind of part where it expected the bunker's health is now passed over, and the mod's bunker keeps the health the mod gave it.
- Contra X Beta 2 starts too. Our China command center menu puts the early Carpet Bomb in its second slot, Contra has no such button, and the game quit at start with a parsing error naming that menu. A menu slot that asks for a button the loaded game does not have is now left empty, and the rest of the menu fills in as before.
+- A mod pack that leaves out a unit we rebalance starts as well. A player running the Alternate packs had no Gattling Cannon under the name our balance pass prices, and the game quit at start with a parsing error naming the cannon. A balance change for a unit, weapon or armor the loaded game does not have is now passed over, and every change after it still applies.
- 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 German or Russian copy with no English files at all closed the same way after 2.5.0, because English was the only language the game knew to fall back to. It now takes whichever language your copy does have, and a copy with none says so and tells you to verify the game's files in Steam.
- 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.
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
index ed9a6d083..17f8b40ab 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
@@ -394,11 +394,17 @@ AsciiString TheThingTemplateBeingParsedName;
ThingTemplate *thingTemplate = TheThingFactory->findTemplateInternal( name, FALSE );
if( !thingTemplate && ini->getLoadType() == INI_LOAD_MULTIFILE && reskinFrom.isEmpty() )
{
- // a patch names an object EA's files built; a name that finds nothing is a typo, and a new
- // template made from it would change no unit and still land in the INI CRC. An ObjectReskin
- // is the exception: it is new by design and names its original, which has to exist.
- DEBUG_CRASH(( "[LINE: %d in '%s'] %s patches an object that does not exist", ini->getLineNum(), ini->getFilename().str(), name.str() ));
- throw INI_INVALID_DATA;
+ /* A patch names an object EA's files built, and a new template made from a name that finds
+ nothing would change no unit. The name is missing when a mod's archives replaced EA's object
+ files, and BalanceReforged.ini's price for Nuke_ChinaGattlingCannon stopped the game at start
+ on an install carrying AlternateINI's archives. The block is read into a
+ template that is thrown away, so the parse stays in step and the rest of the file still applies.
+ An ObjectReskin is new by design and still names an original that has to exist. */
+ DEBUG_LOG(( "[LINE: %d in '%s'] %s patches an object that does not exist; the block is skipped.\n", ini->getLineNum(), ini->getFilename().str(), name.str() ));
+ ThingTemplate *scratch = newInstance(ThingTemplate);
+ ini->initFromINI( scratch, scratch->getFieldParse() );
+ scratch->deleteInstance();
+ return;
}
else if( !thingTemplate )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
index 208046dd5..682fb1d35 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
@@ -161,9 +161,12 @@ void ArmorStore::reset()
TheArmorStore->m_beforeMapOverrides.push_back(std::make_pair(key, existing->second));
if (ini->getLoadType() == INI_LOAD_MULTIFILE && existing == TheArmorStore->m_armorTemplates.end())
{
- // BalanceReforged.ini rewrites armors objects already wear; a new name would reach nothing
- DEBUG_CRASH(("Armor '%s' is patched but was never defined", c));
- throw INI_INVALID_DATA;
+ // BalanceReforged.ini rewrites armors objects already wear; a new name would reach nothing.
+ // A mod's Armor.ini without it: the block is read and dropped, as for a missing object.
+ DEBUG_LOG(("[LINE: %d in '%s'] Armor '%s' is patched but was never defined; the block is skipped.\n", ini->getLineNum(), ini->getFilename().str(), c));
+ ArmorTemplate scratch;
+ ini->initFromINI(&scratch, myFieldParse);
+ return;
}
ArmorTemplate& armorTmpl = TheArmorStore->m_armorTemplates[key];
armorTmpl.clear();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
index a9ebafc19..514a249f3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
@@ -1937,8 +1937,13 @@ void WeaponStore::postProcessLoad()
}
else if (ini->getLoadType() == INI_LOAD_MULTIFILE)
{
- DEBUG_CRASH(("Weapon '%s' is patched but was never defined", c));
- throw INI_INVALID_DATA;
+ // A mod's Weapon.ini without this weapon: the block is read into a scratch template and
+ // dropped, as ThingFactory::parseObjectDefinition does for a missing object.
+ DEBUG_LOG(("[LINE: %d in '%s'] Weapon '%s' is patched but was never defined; the block is skipped.\n", ini->getLineNum(), ini->getFilename().str(), c));
+ WeaponTemplate *scratch = newInstance(WeaponTemplate);
+ ini->initFromINI(scratch, scratch->getFieldParse());
+ scratch->deleteInstance();
+ return;
}
else
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 2c91472e9..ca31e9bb2 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -647,10 +647,14 @@ TEST(balance_patch_edits_a_weapon_in_place)
CHECK_NEAR( gun->getPrimaryDamage( noBonus ), 45.0f, 0.01f );
CHECK_NEAR( gun->getUnmodifiedAttackRange(), 150.0f, 0.01f );
- /* a patch that names a weapon nobody defined is a typo, and has to stop the load */
+ /* a patch that names a weapon the loaded data lacks (a mod's Weapon.ini without it) is read and
+ dropped: no weapon is made for the name, and the block after it still applies */
writeFile( TEST_INI,
"Weapon BalancePatchProbeGunTypo\r\n"
" PrimaryDamage = 45.0\r\n"
+ "End\r\n"
+ "Weapon BalancePatchProbeGun\r\n"
+ " PrimaryDamage = 30.0\r\n"
"End\r\n" );
Bool threw = FALSE;
try
@@ -662,8 +666,9 @@ TEST(balance_patch_edits_a_weapon_in_place)
{
threw = TRUE;
}
- CHECK( threw );
+ CHECK( threw == FALSE );
CHECK( TheWeaponStore->findWeaponTemplate( "BalancePatchProbeGunTypo" ) == NULL );
+ CHECK_NEAR( gun->getPrimaryDamage( noBonus ), 30.0f, 0.01f );
remove( TEST_INI );
}
@@ -754,6 +759,68 @@ TEST(replace_module_of_another_type_is_skipped)
}
}
+/* BalanceReforged.ini prices Nuke_ChinaGattlingCannon, and an install whose mod archives had no such
+ object threw in ThingFactory::parseObjectDefinition and stopped the game at start. The block is
+ read and dropped now: no template is made for the name, and the object after it is still edited. */
+TEST(patch_of_a_missing_object_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;
+
+ writeFile( TEST_INI,
+ "Object MissingObjectProbe\r\n"
+ " BuildCost = 1200\r\n"
+ "End\r\n" );
+ CHECK( loadIni( TEST_INI ) );
+
+ writeFile( TEST_INI,
+ "Object MissingObjectProbeAbsent\r\n"
+ " BuildCost = 1000\r\n"
+ " ReplaceModule ModuleTag_04\r\n"
+ " Body = StructureBody ModuleTag_04_Reforged\r\n"
+ " MaxHealth = 1500.0\r\n"
+ " End\r\n"
+ " End\r\n"
+ "End\r\n"
+ "Object MissingObjectProbe\r\n"
+ " BuildCost = 1000\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 );
+ CHECK( TheThingFactory->findTemplate( "MissingObjectProbeAbsent", FALSE ) == NULL );
+
+ const ThingTemplate *probe = TheThingFactory->findTemplate( "MissingObjectProbe" );
+ CHECK( probe != NULL );
+ if( probe != NULL )
+ CHECK_EQ( probe->friend_getBuildCost(), 1000 );
+
+ remove( TEST_INI );
+ if( savedGlobals == NULL )
+ {
+ delete TheWritableGlobalData;
+ TheWritableGlobalData = NULL;
+ }
+}
+
/* 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.