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: four crashes from the v2.4.0 crash reports

Olcay Seygan609d4e215f8d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e62b7d7c..44a99033a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1343,6 +1343,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- A machine whose graphics stack faults while the Direct3D 11 picture is being set up starts the game anyway, on the Direct3D 9 picture. A player's report showed the fault happening inside Windows' own graphics library, before the game got an answer back, and it ended in "Uncaught Exception during initialization". An overlay hooking the graphics calls or a stray dxgi.dll in the game folder is the usual cause. Until now the only way past it was typing -d3d9.
- A campaign mission could crash on its very first frame with the Direct3D 11 picture on, if the screen had been reset before it by an alt-tab or a change on the display options page. The reset threw some textures away, the new picture kept drawing with them, and the first water reflection of the next map read freed memory. A reset now clears every texture from the new picture as well as the old one.
- Changing the resolution in fullscreen could crash the game the moment you pressed Accept, with the Direct3D 11 picture on. The screen reset asks the graphics card for the memory the ground shadows are drawn into, and when the card refused, the next frame wrote into memory that was never handed over. A player on an RTX 5080 met it on v2.4.0. Now the ground shadows sit out until the next reset, and the game keeps running.
+- A save made before v2.2.0 loads again. Since then the Boss General's Scud Storm keeps its missiles in a different weapon slot, and loading an old save looked for the weapon in the slot that is now empty and went down. The game now drops what no longer fits and fills the slots the way today's data has them.
+- A tank or truck with no orders of its own, the burning wreck some mods leave behind, crashed the game the first time it was drawn. The new tread and chassis motion asked every drawn vehicle for its engine, and a wreck has none. A wreck now sits still.
+- Opening Skirmish crashed on a game that loads its menus from a mod or from the original files, as the Shockwave mod does. Those menus have no game speed box, and the game set one up anyway. The same was true of the tree sway box and the detail presets on the Options screen. A missing box is now left out, and a skirmish without one plays at normal speed.
- The opening movies froze on their first frame with that picture on. A movie writes a new image every frame into a texture the copy had already taken.
- Opening Single Player could take the game down a quarter of a second in, as the buttons flashed in. The menu's animation list names a Custom Mission button that only the 1.04 patch's main menu has, and on an install whose menu lacks it, every step of the flash skipped the missing button except one, which tried to draw it. That step skips it now too.
- A skirmish against the computer could crash when a fresh unit joined one of its teams. The newcomer copies what a teammate is doing, and when that teammate was following a road the map had drawn for it, the newcomer got the order without the road and the game fell over looking for its first stop. It now gets the road as well, and a unit handed that order with no road at all gives it up instead.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
index f88085e80..7dbf2af1f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
@@ -211,6 +211,7 @@ private:
Bool m_hasDamageWeapon;
Bool isAnyWithinTargetPitch(const Object* obj, const Object* victim) const;
+ void recountWeapons();
protected:
// snapshot methods
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 43cfdef15..d8f985b0e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -1895,8 +1895,12 @@ void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformI
if (steps != 0)
{
const Object *obj = getObject();
+ // EA's per-appearance versions of this each returned on an object without physics
+ const PhysicsBehavior *physics = obj->getPhysics();
+ if (physics == NULL)
+ return;
BodyDamageType bdt = obj->getBodyModule()->getDamageState();
- Real speed = obj->getPhysics()->getForwardSpeed2D();
+ Real speed = physics->getForwardSpeed2D();
Real angle = getOrientation();
if (steps > MAX_CATCH_UP_FRAMES)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index f6deb6995..28884b817 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -971,7 +971,9 @@ static void setDefaults( void )
// Extra Animations (buildups) and Swaying Trees checkboxes
//
GadgetCheckBoxSetChecked( checkExtraAnimations, !TheGlobalData->m_useDrawModuleLOD);
- GadgetCheckBoxSetChecked( checkTreeSway, TheGlobalData->m_useTreeSway);
+ // the fork's box: a stock or modded OptionsMenu.wnd that wins over Run/Window has none
+ if( checkTreeSway )
+ GadgetCheckBoxSetChecked( checkTreeSway, TheGlobalData->m_useTreeSway);
//-------------------------------------------------------------------------------------------------
// DisableDynamicLOD
@@ -1310,7 +1312,8 @@ static void saveOptions( void )
TheWritableGlobalData->m_useDrawModuleLOD = !GadgetCheckBoxIsChecked( checkExtraAnimations );
(*pref)["ExtraAnimations"] = TheGlobalData->m_useDrawModuleLOD ? AsciiString("no") : AsciiString("yes");
- TheWritableGlobalData->m_useTreeSway = GadgetCheckBoxIsChecked( checkTreeSway );
+ // without the fork's box the trees sway with the extra animations, as retail decided it
+ TheWritableGlobalData->m_useTreeSway = checkTreeSway ? GadgetCheckBoxIsChecked( checkTreeSway ) : !TheGlobalData->m_useDrawModuleLOD;
(*pref)["TreeSway"] = TheGlobalData->m_useTreeSway ? AsciiString("yes") : AsciiString("no");
TheWritableGlobalData->m_enableDynamicLOD = !GadgetCheckBoxIsChecked( checkNoDynamicLod );
@@ -1986,6 +1989,10 @@ static Bool isDetailPresetCatalogControl( const GameWindow *control )
static void showCatalogValue( const OptionDef &def, Int value )
{
GameWindow *widget = findOptionWidget( def );
+ // every catalog control is the fork's, so a stock or modded OptionsMenu.wnd has none of them
+ if( widget == NULL )
+ return;
+
switch( def.kind )
{
case OPTION_BOOL:
@@ -2108,7 +2115,8 @@ static void showDetailPreset( Int index )
GadgetCheckBoxSetChecked( checkExtraAnimations, preset.m_useBuildupScaffolds );
GadgetCheckBoxSetChecked( checkHeatEffects, preset.m_useHeatEffects );
GadgetCheckBoxSetChecked( checkNoDynamicLod, !preset.m_enableDynamicLOD );
- GadgetCheckBoxSetChecked( checkTreeSway, preset.m_useTreeSway );
+ if( checkTreeSway )
+ GadgetCheckBoxSetChecked( checkTreeSway, preset.m_useTreeSway );
for( Int row = 0; row < DETAIL_PRESET_CATALOG_ROW_COUNT; ++row )
showCatalogValue( *findOptionDef( TheDetailPresetCatalogRows[ row ].iniKey ), TheDetailPresetCatalogRows[ row ].values[ index ] );
ignoreSelected = FALSE;
@@ -2461,7 +2469,8 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
GadgetCheckBoxSetChecked( checkExtraAnimations, !TheGlobalData->m_useDrawModuleLOD);
- GadgetCheckBoxSetChecked( checkTreeSway, TheGlobalData->m_useTreeSway);
+ if( checkTreeSway )
+ GadgetCheckBoxSetChecked( checkTreeSway, TheGlobalData->m_useTreeSway);
GadgetCheckBoxSetChecked( checkNoDynamicLod, !TheGlobalData->m_enableDynamicLOD);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
index f27daf668..70630d2a9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
@@ -189,7 +189,8 @@ static Int nearestGameSpeedIndex( Int framesPerSecond )
static Int selectedGameSpeed( void )
{
GameWindow *comboBoxGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxGameSpeedID );
- Int selected = 0;
+ // a layout without the dropdown plays at x1, not at the first entry's x0.5
+ Int selected = nearestGameSpeedIndex( LOGICFRAMES_PER_SECOND );
GadgetComboBoxGetSelectedPos( comboBoxGameSpeed, &selected );
return SKIRMISH_GAME_SPEEDS[ selected ];
}
@@ -1452,12 +1453,17 @@ void SkirmishGameOptionsMenuInit( WindowLayout *layout, void *userData )
//updateSkirmishGameOptions();
//initSkirmishGameOptions();
- // set up the game speed dropdown
+ // set up the game speed dropdown. It is the fork's control, so a stock or modded
+ // SkirmishGameOptionsMenu.wnd that wins over Run/Window has none, like the combo boxes in
+ // InitSkirmishGameGadgets
GameWindow *comboBoxGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxGameSpeedID );
- GadgetComboBoxReset( comboBoxGameSpeed );
- for( Int i = 0; i < SKIRMISH_GAME_SPEED_COUNT; ++i )
- GadgetComboBoxAddEntry( comboBoxGameSpeed, UnicodeString( SKIRMISH_GAME_SPEED_CAPTIONS[ i ] ), comboBoxGameSpeed->winGetEnabledTextColor() );
- GadgetComboBoxSetSelectedPos( comboBoxGameSpeed, nearestGameSpeedIndex( prefs.getInt( "FPS", LOGICFRAMES_PER_SECOND ) ) );
+ if ( comboBoxGameSpeed )
+ {
+ GadgetComboBoxReset( comboBoxGameSpeed );
+ for( Int i = 0; i < SKIRMISH_GAME_SPEED_COUNT; ++i )
+ GadgetComboBoxAddEntry( comboBoxGameSpeed, UnicodeString( SKIRMISH_GAME_SPEED_CAPTIONS[ i ] ), comboBoxGameSpeed->winGetEnabledTextColor() );
+ GadgetComboBoxSetSelectedPos( comboBoxGameSpeed, nearestGameSpeedIndex( prefs.getInt( "FPS", LOGICFRAMES_PER_SECOND ) ) );
+ }
buttonStart->winSetText(TheGameText->fetch("GUI:Start"));
/* hey, for now we're also going to disable the map select button until it doesn't crash */
//buttonSelectMap->winEnable( FALSE );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
index 52d5ff061..02d9b0dcd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
@@ -266,23 +266,49 @@ void WeaponSet::xfer( Xfer *xfer )
wsFlags.xfer( xfer );
}
+ //
+ // On a load the set just read decides which slots hold a weapon, and the save fills in their
+ // state. Object's constructor has already filled the slots of whatever set its own flags chose
+ // then (a production veteran gets the VETERAN set), and a slot the save holds empty used to keep
+ // that weapon. A save written before the data moved a weapon to another slot (Boss_ScudStorm's
+ // went from PRIMARY to SECONDARY in v2.2.0) names a slot the set no longer has; that weapon is
+ // read and dropped. The old fallback to slot 0 handed the Weapon constructor a null template
+ // whenever slot 0 was the empty one.
+ //
+ Bool layoutChanged = FALSE;
for (Int i = 0; i < WEAPONSLOT_COUNT; ++i)
{
Bool hasWeaponInSlot = (m_weapons[i] != NULL);
xfer->xferBool(&hasWeaponInSlot);
- if (hasWeaponInSlot)
+ if (xfer->getXferMode() == XFER_LOAD)
{
- if (xfer->getXferMode() == XFER_LOAD && m_weapons[i] == NULL)
+ const WeaponTemplate* wt = m_curWeaponTemplateSet ? m_curWeaponTemplateSet->getNth((WeaponSlotType)i) : NULL;
+ if (m_weapons[i] != NULL && (!hasWeaponInSlot || wt == NULL))
{
- const WeaponTemplate* wt = m_curWeaponTemplateSet->getNth((WeaponSlotType)i);
- if (wt==NULL) {
- DEBUG_CRASH(("xfer backwards compatibility code - old save file??? jba."));
- wt = m_curWeaponTemplateSet->getNth((WeaponSlotType)0);
- }
- m_weapons[i] = TheWeaponStore->allocateNewWeapon(wt, (WeaponSlotType)i);
+ m_weapons[i]->deleteInstance();
+ m_weapons[i] = NULL;
}
- xfer->xferSnapshot(m_weapons[i]);
+ if (hasWeaponInSlot && wt == NULL)
+ {
+ // Weapon::xfer takes its template from the file, so any of the set's will do to read it into
+ const WeaponTemplate* any = NULL;
+ for (Int j = 0; j < WEAPONSLOT_COUNT && any == NULL && m_curWeaponTemplateSet != NULL; ++j)
+ any = m_curWeaponTemplateSet->getNth((WeaponSlotType)j);
+ if (any == NULL)
+ throw INI_INVALID_DATA;
+ Weapon* dropped = TheWeaponStore->allocateNewWeapon(any, (WeaponSlotType)i);
+ xfer->xferSnapshot(dropped);
+ dropped->deleteInstance();
+ layoutChanged = TRUE;
+ continue;
+ }
+ if (hasWeaponInSlot && m_weapons[i] == NULL)
+ m_weapons[i] = TheWeaponStore->allocateNewWeapon(wt, (WeaponSlotType)i);
+ if (!hasWeaponInSlot && wt != NULL)
+ layoutChanged = TRUE;
}
+ if (hasWeaponInSlot)
+ xfer->xferSnapshot(m_weapons[i]);
}
xfer->xferUser(&m_curWeapon, sizeof(m_curWeapon));
xfer->xferUser(&m_curWeaponLockedStatus, sizeof(m_curWeaponLockedStatus));
@@ -301,6 +327,21 @@ void WeaponSet::xfer( Xfer *xfer )
m_totalDamageTypeMask.xfer(xfer);// BitSet has built in xfer
+ if (layoutChanged)
+ {
+ // The set's slots the save had nothing for start empty and reload first, as a new Weapon does;
+ // the totals in the file describe the old layout.
+ for (Int i = 0; i < WEAPONSLOT_COUNT; ++i)
+ if (m_weapons[i] == NULL && m_curWeaponTemplateSet->getNth((WeaponSlotType)i) != NULL)
+ m_weapons[i] = TheWeaponStore->allocateNewWeapon(m_curWeaponTemplateSet->getNth((WeaponSlotType)i), (WeaponSlotType)i);
+ recountWeapons();
+ if (m_weapons[m_curWeapon] == NULL)
+ {
+ releaseWeaponLock(LOCKED_PERMANENTLY);
+ m_curWeapon = PRIMARY_WEAPON;
+ }
+ }
+
}
// ------------------------------------------------------------------------------------------------
@@ -324,11 +365,6 @@ void WeaponSet::updateWeaponSet(const Object* obj)
releaseWeaponLock(LOCKED_PERMANENTLY); // release all locks. sorry!
m_curWeapon = PRIMARY_WEAPON;
}
- m_filledWeaponSlotMask = 0;
- m_totalAntiMask = 0;
- m_totalDamageTypeMask.clear();
- m_hasPitchLimit = false;
- m_hasDamageWeapon = false;
for (Int i = WEAPONSLOT_COUNT - 1; i >= PRIMARY_WEAPON ; --i)
{
if (m_weapons[i] != NULL)
@@ -344,13 +380,6 @@ void WeaponSet::updateWeaponSet(const Object* obj)
{
m_weapons[i] = TheWeaponStore->allocateNewWeapon(set->getNth((WeaponSlotType)i), (WeaponSlotType)i);
m_weapons[i]->loadAmmoNow(obj); // start 'em all with full clips.
- m_filledWeaponSlotMask |= (1 << i);
- m_totalAntiMask |= m_weapons[i]->getAntiMask();
- m_totalDamageTypeMask.set(m_weapons[i]->getDamageType());
- if (m_weapons[i]->isPitchLimited())
- m_hasPitchLimit = true;
- if (m_weapons[i]->isDamageWeapon())
- m_hasDamageWeapon = true;
// no, do NOT do this; always start with the cur weapon being primary, even if there is no primary
// weapon. this is by design, to allow us to have units that have only "spell" weapons and no
@@ -359,10 +388,33 @@ void WeaponSet::updateWeaponSet(const Object* obj)
}
}
m_curWeaponTemplateSet = set;
+ recountWeapons();
//DEBUG_LOG(("WeaponSet::updateWeaponSet -- changed curweapon to %s\n",getCurWeapon()->getName().str()));
}
}
+//-------------------------------------------------------------------------------------------------
+void WeaponSet::recountWeapons()
+{
+ m_filledWeaponSlotMask = 0;
+ m_totalAntiMask = 0;
+ m_totalDamageTypeMask.clear();
+ m_hasPitchLimit = false;
+ m_hasDamageWeapon = false;
+ for (Int i = 0; i < WEAPONSLOT_COUNT; ++i)
+ {
+ if (m_weapons[i] == NULL)
+ continue;
+ m_filledWeaponSlotMask |= (1 << i);
+ m_totalAntiMask |= m_weapons[i]->getAntiMask();
+ m_totalDamageTypeMask.set(m_weapons[i]->getDamageType());
+ if (m_weapons[i]->isPitchLimited())
+ m_hasPitchLimit = true;
+ if (m_weapons[i]->isDamageWeapon())
+ m_hasDamageWeapon = true;
+ }
+}
+
//-------------------------------------------------------------------------------------------------
/*static*/ ModelConditionFlags WeaponSet::getModelConditionForWeaponSlot(WeaponSlotType wslot, WeaponSetConditionType a)
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp
index 986576356..0dadf05e4 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp
@@ -342,8 +342,12 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)
worth of distance. A pivot runs them against each other, a reverse runs them backwards. */
Real forward, turn;
stepGroundMotion(forward, turn);
- // undamaged top speed: a damaged tank is slower, and its treads still have to match the ground
- const Locomotor *loco = obj->getAIUpdateInterface()->getCurLocomotor();
+ // undamaged top speed: a damaged tank is slower, and its treads still have to match the ground.
+ // A thing with no AI has no locomotor and its treads stand still. No retail object pairs this
+ // module with no AI, but data that draws a hulk with it does, and EA only asked for the AI when
+ // the model had treads; v2.4.0 asked every frame and crashed (crash report 134).
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ const Locomotor *loco = ai ? ai->getCurLocomotor() : NULL;
Real maxSpeed = loco ? loco->getMaxSpeedForCondition(BODY_PRISTINE) : 0.0f;
if (m_treadCount && maxSpeed > 0.0f)
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp
index 69b425a8e..99b3b2ef6 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp
@@ -688,7 +688,8 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
#endif
//Update movement of treads: these vehicles steer with their wheels, so every tread runs over the
//distance driven, at TreadAnimationRate per top speed's worth of it, and backwards in reverse.
- const Locomotor *loco = obj->getAIUpdateInterface()->getCurLocomotor();
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface(); // none on a hulk drawn with this module
+ const Locomotor *loco = ai ? ai->getCurLocomotor() : NULL;
Real maxSpeed = loco ? loco->getMaxSpeedForCondition(BODY_PRISTINE) : 0.0f;
if (m_treadCount && maxSpeed > 0.0f)
{