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 a ReplaceModule block whose type differs
Olcay Seygan87e007eec91a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3ab2f357e..a435eeac5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1675,6 +1675,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Audio is real, through the audio library the retail game ships with.- 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.- 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 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/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.hindex 86297c189..8c394f5e8 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h@@ -790,6 +790,7 @@ private:Byte m_shadowType; ///< settings which determine the type of shadow renderedByte m_moduleParsingMode;Byte m_locomotorSetsLostToReplace; ///< port defect 33: locomotor sets a ReplaceModule of the AI module discarded (0: none); see ThingFactory's checkLocomotors+ Byte m_replaceModuleSkipped; ///< set by parseModuleName when a ReplaceModule block names a module of another type; parseReplaceModule then undoes the blockUnsignedByte m_crusherLevel; ///< crusher > crushable level to actually crushUnsignedByte m_crushableLevel; ///< Specifies the level of crushability (must be hit by a crusher greater than this to crush me).diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cppindex bc0b10f33..a877a532a 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp@@ -597,9 +597,16 @@ void ThingTemplate::parseModuleName(INI* ini, void *instance, void* store, const&& self->m_moduleBeingReplacedName.isNotEmpty()&& self->m_moduleBeingReplacedName != tokenStr){- DEBUG_CRASH(("[LINE: %d - FILE: '%s'] ReplaceModule must replace modules with another module of the same type, but you are attempting to replace a %s with a %s for Object %s.\n",- ini->getLineNum(), ini->getFilename().str(), self->m_moduleBeingReplacedName.str(), tokenStr.str(), self->getName().str()));- throw INI_INVALID_DATA;+ /* A tag that holds a module of another type means a mod's data numbered the object's modules+ differently: Shockwave's Tank_ChinaBunker ModuleTag_05 is no StructureBody, and BalanceReforged.ini's+ replacement of it stopped the game at start. The module is read to its End and dropped, so the+ parse stays in step, and parseReplaceModule puts the template back as it was before the block. */+ DEBUG_LOG(("[LINE: %d - FILE: '%s'] ReplaceModule %s on %s holds a %s, not a %s; the block is skipped.\n",+ ini->getLineNum(), ini->getFilename().str(), self->m_moduleBeingReplacedTag.str(), self->getName().str(),+ self->m_moduleBeingReplacedName.str(), tokenStr.str()));+ TheModuleFactory->newModuleDataFromINI(ini, tokenStr, type, moduleTagStr);+ self->m_replaceModuleSkipped = TRUE;+ return;}if (self->m_moduleParsingMode == MODULEPARSE_ADD_REMOVE_REPLACE@@ -810,6 +817,12 @@ void ThingTemplate::parseReplaceModule(INI *ini, void *instance, void *store, coconst AIUpdateModuleData *aiBefore = self->friend_getAIModuleInfo();const LocomotorTemplateMap locomotorsBefore = aiBefore ? aiBefore->m_locomotorTemplates : LocomotorTemplateMap();+ // What the block may have to be undone to: parseModuleName skips a replacement of another type.+ const ModuleInfo behaviorBefore = self->m_behaviorModuleInfo;+ const ModuleInfo drawBefore = self->m_drawModuleInfo;+ const ModuleInfo clientUpdateBefore = self->m_clientUpdateModuleInfo;+ self->m_replaceModuleSkipped = FALSE;+const char *modToRemove = ini->getNextToken();AsciiString removedModuleName;/* Port defect 33's guard: the sets the replaced AI module had are counted here, and ThingFactory's@@ -833,13 +846,23 @@ void ThingTemplate::parseReplaceModule(INI *ini, void *instance, void *store, coself->m_moduleBeingReplacedTag = modToRemove;ini->initFromINI(self, self->getFieldParse());- AIUpdateModuleData *aiAfter = self->friend_getAIModuleInfo();- if (replacesAIModule && aiAfter != NULL && aiAfter->m_locomotorTemplates.empty())- aiAfter->m_locomotorTemplates = locomotorsBefore;self->m_moduleBeingReplacedName.clear();self->m_moduleBeingReplacedTag.clear();- if (replacesAIModule && setsBefore > 0)- self->m_locomotorSetsLostToReplace = (Byte)(setsBefore > 127 ? 127 : setsBefore);+ if (self->m_replaceModuleSkipped)+ {+ self->m_behaviorModuleInfo = behaviorBefore;+ self->m_drawModuleInfo = drawBefore;+ self->m_clientUpdateModuleInfo = clientUpdateBefore;+ self->m_replaceModuleSkipped = FALSE;+ }+ else+ {+ AIUpdateModuleData *aiAfter = self->friend_getAIModuleInfo();+ if (replacesAIModule && aiAfter != NULL && aiAfter->m_locomotorTemplates.empty())+ aiAfter->m_locomotorTemplates = locomotorsBefore;+ if (replacesAIModule && setsBefore > 0)+ self->m_locomotorSetsLostToReplace = (Byte)(setsBefore > 127 ? 127 : setsBefore);+ }self->m_moduleParsingMode = oldMode;}@@ -1050,6 +1073,7 @@ ThingTemplate::ThingTemplate() :{m_moduleParsingMode = MODULEPARSE_NORMAL;m_locomotorSetsLostToReplace = 0;+ m_replaceModuleSkipped = FALSE;m_reskinnedFrom = NULL;m_radarPriority = RADAR_PRIORITY_INVALID;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex a57ade2f7..2e80f8442 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -65,6 +65,8 @@#include "GameLogic/LogicRandomValue.h"#include "GameClient/ClientRandomValue.h"#include "Common/ThingTemplate.h"+#include "Common/ThingFactory.h"+#include "Common/ModuleFactory.h"#include "Common/SimulationMathCrc.h"#include "GameLogic/FPUControl.h"#include "GameLogic/ExperienceTracker.h"@@ -651,6 +653,92 @@ TEST(balance_patch_edits_a_weapon_in_place)remove( TEST_INI );}+/* BalanceReforged.ini replaces Tank_ChinaBunker's ModuleTag_05 with a StructureBody. Under the+ Shockwave mod that tag holds another module, and the type check in ThingTemplate::parseModuleName+ threw and stopped the game at start. The block is skipped now: the template keeps the module it+ had, and the lines after the block still parse. */+TEST(replace_module_of_another_type_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 ReplaceModuleProbe\r\n"+ " Body = ActiveBody ModuleTag_01\r\n"+ " MaxHealth = 100.0\r\n"+ " InitialHealth = 100.0\r\n"+ " End\r\n"+ " Behavior = DestroyDie ModuleTag_02\r\n"+ " End\r\n"+ "End\r\n" );+ CHECK( loadIni( TEST_INI ) );++ writeFile( TEST_INI,+ "Object ReplaceModuleProbe\r\n"+ " ReplaceModule ModuleTag_02\r\n"+ " Body = StructureBody ModuleTag_02_Override\r\n"+ " MaxHealth = 500.0\r\n"+ " InitialHealth = 500.0\r\n"+ " End\r\n"+ " End\r\n"+ " ReplaceModule ModuleTag_01\r\n"+ " Body = ActiveBody ModuleTag_01_Override\r\n"+ " MaxHealth = 250.0\r\n"+ " InitialHealth = 250.0\r\n"+ " End\r\n"+ " End\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( "ReplaceModuleProbe" );+ CHECK( probe != NULL );+ if( probe != NULL )+ {+ const ModuleInfo &modules = probe->getBehaviorModuleInfo();+ CHECK_EQ( modules.getCount(), 2 );+ Bool keptDie = FALSE, droppedReplacement = TRUE, replacedBody = FALSE;+ for( Int i = 0; i < modules.getCount(); ++i )+ {+ if( modules.getNthTag( i ) == "ModuleTag_02" && modules.getNthName( i ) == "DestroyDie" )+ keptDie = TRUE;+ if( modules.getNthTag( i ) == "ModuleTag_02_Override" )+ droppedReplacement = FALSE;+ if( modules.getNthTag( i ) == "ModuleTag_01_Override" && modules.getNthName( i ) == "ActiveBody" )+ replacedBody = TRUE;+ }+ CHECK( keptDie );+ CHECK( droppedReplacement );+ CHECK( replacedBody );+ }++ 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 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.