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): a patch naming what a mod lacks keeps the mod's own
Olcay Seyganb197f48618fb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fc55f6ba6..882417763 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -148,6 +148,7 @@ found and fixed — EA's own, not port damage.**- No empty slots in a mod general's power tray. Mods give unrelated powers the same few types, Contra's small Scud Storm counting as a carpet bomb, so a Contra Cybernetic player's tray picked up another faction's button for a power he only held one of the same type as, then hid it, and an empty frame stood where it had been. The tray offers a button now only for the very power you hold, and a slot whose button goes away takes its frame with it.- A Paladin under Contra no longer crashes the game. Reforged gives every Paladin a second laser for infantry, and that laser borrowed a Zero Hour weapon nothing else fires. Contra deleted it, so the laser had no gun, and the game went down a moment after the first Paladin rolled out. The laser is Reforged's own weapon now and is there whatever mod you load. The same kind of gap took the guns off Contra's Toxin Tunnel Defender and Toxin Stinger soldier, the Chemical Suits off its Rangers, and the death blast off its Demolition Scud Launcher, Toxin demo trap and Toxin Tractors (ShockWave's trap too). Where Reforged names a weapon or armour the mod dropped, the unit now keeps the mod's own, and the death blasts carry Zero Hour's charge.- Contra's units have their attack move, guard and stop buttons again, and A, G and S press them. Contra draws its command bar with eighteen buttons and keeps those three in the last row, which our fourteen-button bar does not have, so they went missing on every Contra unit, the Cybernetic general's cyborgs among them. A button a mod puts past the end of our bar now moves to an empty one, the three orders to the places Zero Hour gives them.+- Contra's Laser Turret draws its beam at aircraft again, and a Contra Toxin General can buy his Rebel Ambush without the game going down. Reforged's fixes for those two named a beam and an ambush of Zero Hour's own that Contra does not have, so the turret shot an invisible beam, and the moment the ambush was bought its button had no power behind it and the game crashed. Now the promotion screen sells it and the powers bar fires it: gas-masked rebels climb out of the ground where you click. Where a Reforged fix names a beam, a power, a science or a spawn list the mod lacks, the mod's own now stays.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.hindex 7a27a640c..eac47ce9c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h@@ -332,10 +332,11 @@ public: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; }+ /** A patch INI loaded over a mod can name a special power or an object creation list the mod+ does not have. The reference raises this, and ThingTemplate::parseModuleName drops the module+ it was read into. */+ inline void setMissingReference( Bool missing ) { m_missingReference = missing; }+ inline Bool hasMissingReference( void ) const { return m_missingReference; }/** -modfactions prefixes every word a mod names a block with, and a mod can name one after anengine word: The Power of the West has a ParticleSystem "Explosion", so "DamageType = Explosion"@@ -529,7 +530,7 @@ protected:const char *m_blockEndToken; ///< token to represent end of data blockBool m_endOfFile; ///< TRUE when we've hit EOFBool m_skipUnknownFields; ///< log and skip an unknown field instead of throwing- Bool m_missingSpecialPower; ///< a patch named a special power that does not exist+ Bool m_missingReference; ///< a patch named a special power or OCL that does not exist#if defined(_DEBUG) || defined(_INTERNAL)char m_curBlockStart[ INI_MAX_CHARS_PER_PREFIXED_LINE+1 ]; ///< first line of cur block, a copy of m_buffer#endifdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cppindex 61c5f08cb..522e489e9 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp@@ -203,7 +203,7 @@ INI::INI( void )m_blockEndToken = "END";m_endOfFile = FALSE;m_skipUnknownFields = FALSE;- m_missingSpecialPower = FALSE;+ m_missingReference = FALSE;m_buffer[0] = 0;#if defined(_DEBUG) || defined(_INTERNAL)m_curBlockStart[0] = 0;@@ -1206,6 +1206,8 @@ void INI::parseAsciiStringVectorAppend( INI* ini, void * /*instance*/, void *sto/* static */void INI::parseScienceVector( INI *ini, void * /*instance*/, void *store, const void *userData ){ScienceVec* asv = (ScienceVec*)store;+ const ScienceVec before = *asv;+ Bool missing = FALSE;asv->clear();for (const char *token = ini->getNextTokenOrNull(); token != NULL; token = ini->getNextTokenOrNull()){@@ -1217,7 +1219,13 @@ void INI::parseAsciiStringVectorAppend( INI* ini, void * /*instance*/, void *stoScienceType science = INI::scanScience( ini, token );if (science != SCIENCE_INVALID)asv->push_back(science);+ else+ missing = TRUE;}+ // a patch whose every science the mod lacks keeps the mod's own: Contra has no Chem_SCIENCE_RebelAmbush1,+ // and an emptied list left its Toxin General's ambush buttons with nothing to buy or show+ if (missing && asv->empty())+ *asv = before;}//-------------------------------------------------------------------------------------------------@@ -1831,6 +1839,14 @@ void INI::parseObjectCreationList( INI* ini, void * /*instance*/, void *store, cConstObjectCreationListPtr* theObjectCreationList = (ConstObjectCreationListPtr*)store;const ObjectCreationList *ocl = TheObjectCreationListStore->findObjectCreationList(token); // could be null!+ if (!ocl && strcasecmp(token, "None") != 0 && ini->getLoadType() == INI_LOAD_MULTIFILE)+ {+ // a patch INI loaded over a mod, as with a missing special power: FixesReforged.ini's Emperor+ // Gattling upgrade names Tank_OCL_OverlordGattlingCannon, which Contra does not have+ DEBUG_LOG(("[LINE: %d in '%s'] object creation list '%s' does not exist; the reference is skipped.\n", ini->getLineNum(), ini->getFilename().str(), token));+ ini->setMissingReference( TRUE );+ return;+ }DEBUG_ASSERTCRASH(ocl || strcasecmp(token, "None") == 0, ("ObjectCreationList %s not found!\n",token));// assign it, even if null!*theObjectCreationList = ocl;@@ -1874,9 +1890,12 @@ void INI::parseSpecialPowerTemplate( INI* ini, void * /*instance*/, void *store,const SpecialPowerTemplate *sPowerT = TheSpecialPowerStore->findSpecialPowerTemplate( AsciiString( token ) );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 );+ // a patch INI loaded over a mod, as with a missing science (scanScience): Contra has no Nuke_ carpet+ // bomb. A module naming it is dropped; a button keeps the mod's own power, or Contra's Toxin+ // General lost his ambush shortcut to Chem_SuperweaponRebelAmbush.+ DEBUG_LOG(("[LINE: %d in '%s'] special power '%s' does not exist; the reference is skipped.\n", ini->getLineNum(), ini->getFilename().str(), token));+ ini->setMissingReference( TRUE );+ return;}else if( !sPowerT && strcasecmp( token, "None" ) != 0 ){diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cppindex cd32713e5..1d234ea53 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp@@ -625,13 +625,16 @@ void ThingTemplate::parseModuleName(INI* ini, void *instance, void* store, constthrow INI_INVALID_DATA;}- ini->setMissingSpecialPower(FALSE);+ ini->setMissingReference(FALSE);ModuleData* data = TheModuleFactory->newModuleDataFromINI(ini, tokenStr, type, moduleTagStr);- if (ini->hasMissingSpecialPower())+ if (ini->hasMissingReference()){- // read to its End and dropped: a special power module with no template faults placing the object+ /* read to its End and dropped: a special power module with no template faults placing the+ object, and an upgrade with no list does nothing. Inside ReplaceModule the module it was+ to replace comes back, so the mod's own stands. */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()));+ self->m_replaceModuleSkipped = TRUE;return;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex aa033dd3c..5d2ba6114 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -153,6 +153,21 @@ static void parseAllVetLevelsAsciiString( INI* ini, void* /*instance*/, void * ss[i] = a;}+//-------------------------------------------------------------------------------------------------+/* The laser object is looked up when the weapon fires, so a name nothing defines draws no beam. A+ patch file loads after every object: one naming a laser the loaded data lacks (FixesReforged.ini's+ Lazr_PatriotLaserBeam under Contra) leaves the weapon the beam it had. */+static void parseLaserName( INI* ini, void* /*instance*/, void * store, const void* /*userData*/ )+{+ AsciiString name = ini->getNextAsciiString();+ if (ini->getLoadType() == INI_LOAD_MULTIFILE && name.isNotEmpty() && TheThingFactory->findTemplate(name, FALSE) == NULL)+ {+ DEBUG_LOG(("[LINE: %d in '%s'] laser '%s' does not exist; the weapon keeps its own.\n", ini->getLineNum(), ini->getFilename().str(), name.str()));+ return;+ }+ *(AsciiString*)store = name;+}+//-------------------------------------------------------------------------------------------------static void parsePerVetLevelFXList( INI* ini, void* /*instance*/, void * store, const void* /*userData*/ ){@@ -267,7 +282,7 @@ const FieldParse WeaponTemplate::TheWeaponTemplateFieldParseTable[] ={ "AntiBallisticMissile", INI::parseBitInInt32, (void*)WEAPON_ANTI_BALLISTIC_MISSILE, offsetof(WeaponTemplate, m_antiMask) },{ "AutoReloadsClip", INI::parseIndexList, TheWeaponReloadNames, offsetof(WeaponTemplate, m_reloadType) },{ "ProjectileStreamName", INI::parseAsciiString, NULL, offsetof(WeaponTemplate, m_projectileStreamName) },- { "LaserName", INI::parseAsciiString, NULL, offsetof(WeaponTemplate, m_laserName) },+ { "LaserName", parseLaserName, NULL, offsetof(WeaponTemplate, m_laserName) },{ "LaserBoneName", INI::parseAsciiString, NULL, offsetof(WeaponTemplate, m_laserBoneName) },{ "WeaponBonus", WeaponTemplate::parseWeaponBonusSet, NULL, 0 },{ "HistoricBonusTime", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_historicBonusTime) },diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex cc37d116b..1a17b3070 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -184,6 +184,7 @@ static int GetSystemMetrics( int which )#include "Common/BuildAssistant.h"#include "GameLogic/Object.h"#include "GameLogic/Weapon.h"+#include "GameLogic/ObjectCreationList.h"#include "GameClient/CommandXlat.h"#include "Common/ActionManager.h"#include "GameLogic/PartitionManager.h"@@ -1096,6 +1097,94 @@ TEST(patch_module_with_a_missing_special_power_is_skipped)}}+/* Under Contra FixesReforged.ini gave the Laser Turret's anti-air weapon Zero Hour's+ Lazr_PatriotLaserBeam, which Contra does not have, so the beam vanished, and gave the Emperor an+ upgrade naming Tank_OCL_OverlordGattlingCannon, which it does not have either. A patch naming+ something the loaded data lacks keeps what was there: the weapon its own beam, and a replaced+ module the module it replaced. */+TEST(patch_naming_a_missing_laser_or_list_keeps_the_mods_own)+{+ 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( TheWeaponStore == NULL )+ TheWeaponStore = NEW WeaponStore;+ if( TheObjectCreationListStore == NULL )+ TheObjectCreationListStore = NEW ObjectCreationListStore;++ writeFile( TEST_INI,+ "Object MissingLaserProbeBeam\r\n"+ "End\r\n"+ "Weapon MissingLaserProbeGun\r\n"+ " LaserName = MissingLaserProbeBeam\r\n"+ "End\r\n"+ "Object MissingListProbe\r\n"+ " Behavior = DestroyDie ModuleTag_07\r\n"+ " End\r\n"+ "End\r\n" );+ CHECK( loadIni( TEST_INI ) );++ writeFile( TEST_INI,+ "Weapon MissingLaserProbeGun\r\n"+ " LaserName = MissingLaserProbeAbsentBeam\r\n"+ "End\r\n"+ "Object MissingListProbe\r\n"+ " ReplaceModule ModuleTag_07\r\n"+ " Behavior = ObjectCreationUpgrade ModuleTag_07_Fix\r\n"+ " UpgradeObject = MissingListProbeAbsentList\r\n"+ " TriggeredBy = Upgrade_MissingListProbe\r\n"+ " End\r\n"+ " End\r\n"+ " BuildCost = 700\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 WeaponTemplate *gun = TheWeaponStore->findWeaponTemplate( "MissingLaserProbeGun" );+ CHECK( gun != NULL );+ if( gun != NULL )+ CHECK_STR( gun->getLaserName().str(), "MissingLaserProbeBeam" );++ const ThingTemplate *probe = TheThingFactory->findTemplate( "MissingListProbe" );+ CHECK( probe != NULL );+ if( probe != NULL )+ {+ const ModuleInfo &modules = probe->getBehaviorModuleInfo();+ CHECK_EQ( modules.getCount(), 1 );+ if( modules.getCount() == 1 )+ {+ CHECK( modules.getNthTag( 0 ) == "ModuleTag_07" );+ CHECK( modules.getNthName( 0 ) == "DestroyDie" );+ }+ CHECK_EQ( probe->friend_getBuildCost(), 700 );+ }++ 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; aline with no percentage is still a syntax error. */