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(gameclient): skip a command set button that does not exist

Olcay Seygane01af729cb11
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2b15a39a..a688bfe14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1677,6 +1677,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.
+- 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 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/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index dfbba4d19..c9c4f7d0a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1353,9 +1353,10 @@ void CommandSet::parseCommandButton( INI* ini, void *instance, void *store, cons
{
/* A mod's CommandButton.ini can lack a button the fork's CommandSetReforged.ini names: Contra X
Beta 2 has no Early_Command_ChinaCarpetBomb, and slot 2 of Infa_ChinaCommandCenterCommandSetUpgrade
- threw and stopped the game at start. The slot keeps what it held, which for a patched set is
- empty, since parseCommandSetDefinition clears it first, and every reader already passes over an
- empty slot. The outcome depends only on the files, which are in the INI checksum. */
+ threw and stopped the game at start. The slot keeps what it held: empty for a new set and for a
+ patched one, which parseCommandSetDefinition clears first, the parent's button for a map.ini
+ override, which starts as a copy. Every reader already passes over an empty slot, and the
+ outcome depends only on the files, which are in the INI and map checksums. */
DEBUG_LOG(( "[LINE: %d - FILE: '%s'] CommandSet %s slot %d names unknown button '%s'; the slot is skipped.\n",
ini->getLineNum(), ini->getFilename().str(), ((CommandSet *)instance)->getName().str(),
buttonIndex + 1, token ));
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 7cef0e7bd..42a79c816 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -14396,6 +14396,42 @@ TEST(the_bars_windows_can_be_torn_down_twice_without_taking_the_bar_with_them)
CHECK( bar.findCommandButton( AsciiString( "NoSuchCommandButton" ) ) == NULL );
}
+/* CommandSetReforged.ini names EA's Early_Command_ChinaCarpetBomb in slot 2 of a China command center
+ set. Contra X Beta 2 has no such button, and CommandSet::parseCommandButton threw and stopped the
+ game at start. The slot is skipped now: it stays empty and the slots after it still parse. */
+TEST(command_set_slot_naming_an_unknown_button_is_skipped)
+{
+ CHECK( bootOnce() );
+
+ ControlBar bar;
+ ControlBar *savedBar = TheControlBar;
+ TheControlBar = &bar;
+
+ writeFile( TEST_INI,
+ "CommandButton ProbeButton\r\n"
+ "End\r\n"
+ "CommandSet ProbeCommandSet\r\n"
+ " 1 = ProbeButton\r\n"
+ " 2 = NoSuchCommandButton\r\n"
+ " 3 = ProbeButton\r\n"
+ "End\r\n" );
+ CHECK( loadIni( TEST_INI ) );
+
+ const CommandButton *probe = bar.findCommandButton( AsciiString( "ProbeButton" ) );
+ const CommandSet *set = bar.findCommandSet( AsciiString( "ProbeCommandSet" ) );
+ CHECK( probe != NULL );
+ CHECK( set != NULL );
+ if( set != NULL )
+ {
+ CHECK( set->getCommandButton( 0 ) == probe );
+ CHECK( set->getCommandButton( 1 ) == NULL );
+ CHECK( set->getCommandButton( 2 ) == probe );
+ }
+
+ remove( TEST_INI );
+ TheControlBar = savedBar;
+}
+
/* ControlBarScheme.cpp: the scheme places the money readout, the two general's tabs and the toolbar
column by reading their parent's screen position and subtracting it, and layoutPanels then runs
over the answer. Asking for the panels back is not the same as having them back - the slide is