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.

feat(gameclient): hotkeys.ini switch for the keys as shipped

Andreas Berger2b6df40f4a05
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95ea7880c..6697e82f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,7 +58,7 @@ found and fixed — EA's own, not port damage.**
- Buildings select together again, which the one interface had taken away. Shift-click them, drag a box over them, or double-click one for every building of its kind on the screen; select four War Factories and each tank you click goes to whichever has the shortest queue. Double-click a unit and every one of that kind whose feet sit in the picture is taken, including the ones sitting past the camera's far clip that used to be skipped. A building and a unit still never share a selection.
- Formation lines are back for everyone. With move, attack move or guard armed, a left drag spreads the selection along the line you draw again; since the one interface it drew a selection box instead, because the line was switched off for the Classic mouse that every player now runs. A drag with no order armed is still the selection box.
- Every key is yours to move. The launcher's Hotkeys page draws the command bar of every building and unit each general can field, cameos and letters as the game shows them, and a click and a keypress gives any button a new letter or none. Two buttons on one bar that would share a letter are marked before you play. The keyboard commands are there too, from bookmarks and team keys to the camera, along with the ones Zero Hour never bound: select every fighting unit, vehicle or aircraft, every barracks, war factory or airfield, the next idle worker or unit, pause, the general's promotions, the three signals to your allies and the general's powers. Your keys are yours alone; the other players in a match keep theirs, and a match never refuses you for them. Every mod you install brings its own generals to the page, ShockWave's fifteen next to Zero Hour's thirteen, and a key you give a ShockWave button stays with ShockWave.
-- Some keys now mean one thing on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA worker's switch to fake buildings. Sell sits on its own key, so emptying a bunker can never sell it. The 188 buttons Zero Hour had put on one of those letters take another, kept off the 18 letters under your left hand where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it. Those letters are still yours to hand out: the Hotkeys page gives A or H to any other button you pick, and marks the clash. On a bar that has the order as well, the order keeps its key: a Barracks button on A fires from A, and a tank's A is still attack move.
+- Some keys now mean one thing on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA worker's switch to fake buildings. Sell sits on its own key, so emptying a bunker can never sell it. The 188 buttons Zero Hour had put on one of those letters take another, kept off the 18 letters under your left hand where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it. Those letters are still yours to hand out: the Hotkeys page gives A or H to any other button you pick, and marks the clash. On a bar that has the order as well, the order keeps its key: a Barracks button on A fires from A, and a tank's A is still attack move. A `FixedOrderKeys` block with `Enabled = No` in Hotkeys.ini turns the fixed keys off and gives every button the letter the game's own text gives it, the orders included, as the game shipped: in the German game guard is W and the rally point U again, and the 179 German buttons on one of those letters, the Humvee on V and the supply center on N among them, have their keys back.
- The Hotkeys page is in the game as well, as the last tab of the options screen, so a key can move without quitting to the launcher: from the main menu, or from Esc in the middle of a match. Every command sits on the left with its key. On the right you pick a general and one of his buildings or units, and its command bar is listed button by button, each with its cameo and its letter. Double-click a line, or press Enter or Change, and then the key; Esc lets go. Two buttons of one bar on one letter, or two commands on one key, turn red, and the line under the lists names them. Accept writes the file the launcher writes, so a key set in either place is there in the other, and a key changed in a match works from the next press.
- Export and Import on the Hotkeys page take your keys to a file and back, for another PC or a fresh install. Before an import the page tells you how many keys it changes and how many would clash; a file with a line it cannot read changes nothing and quotes that line. Keys for a mod you have not installed come along and wait for it.
- Grid keys are gone. The switch that made a button's key its place on the bar, Q for the first button of every building, is off the Hotkeys page, and the game no longer moves buttons around to give them a place's letter. Each button wears the letter you gave it or the game's own, and the fixed keys above still hold. A hotkeys file saved with grid keys on loads as before, with the switch ignored, so a player who had them on finds the letters of their own buttons back on the bar.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
index a92dee73a..26d2caeee 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
@@ -288,6 +288,7 @@ public:
static void parseMetaMapDefinition( INI *ini );
static void parseCommandButtonHotKeyDefinition( INI *ini );
static void parseCommandBarGridDefinition( INI *ini );
+ static void parseFixedOrderKeysDefinition( INI *ini );
static void parseFXListDefinition( INI *ini );
static void parseObjectCreationListDefinition( INI* ini );
static void parseMultiplayerSettingsDefinition( INI* ini );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
index ebe66b91b..22f58aad1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
@@ -124,6 +124,9 @@ public:
static WideChar buttonKeyIn( const AsciiString& button, WideChar labelKey, Int commandType,
const std::map< std::string, WideChar >& keys );
static WideChar fixedKey( const AsciiString& button, Int commandType ); ///< the bar's fixed letter, or 0
+ /// FixedOrderKeys in Hotkeys.ini: FALSE gives the orders their labels' letters, as shipped
+ static Bool fixedOrderKeys( void );
+ static void setFixedOrderKeys( Bool fixed );
/** The name Hotkeys.ini gives a button: a mod's own (-modfactions' "M<n>~") or, under a plain
* -mod, the last mod's as "<scope>:<button>", retail's as it is; what findPlayerKey looks up. */
static std::string fileButtonName( const AsciiString& button );
@@ -178,6 +181,8 @@ struct HotkeysFile
std::map< std::string, std::string > buttons; ///< button name to its letter, "" for none
std::map< std::string, HotkeyBinding > commands; ///< command to its key, key "" for none
std::string launcherPart; ///< what followed HOTKEYS_LAUNCHER_PART, verbatim; empty when the file had none
+ Bool fixedOrderKeys; ///< FixedOrderKeys' Enabled; written only when off
+ HotkeysFile() : fixedOrderKeys( TRUE ) {}
};
/** The rows of the shipped Data\<language>\CommandMap.ini text, then the commands it leaves unbound
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
index 9543770a0..3aff85d0b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
@@ -100,6 +100,7 @@ static const BlockParse theTypeTable[] =
{ "CommandButton", INI::parseCommandButtonDefinition },
{ "CommandButtonHotKey", INI::parseCommandButtonHotKeyDefinition },
{ "CommandBarGrid", INI::parseCommandBarGridDefinition },
+ { "FixedOrderKeys", INI::parseFixedOrderKeysDefinition },
{ "CommandMap", INI::parseMetaMapDefinition },
{ "CommandSet", INI::parseCommandSetDefinition },
{ "ControlBarScheme", INI::parseControlBarSchemeDefinition },
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
index 18ada4f1b..0c3dcddff 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
@@ -339,6 +339,10 @@ static std::map< std::string, WideChar > s_playerButtonKeys;
* the fixed order stands too, the order gets the key (addHotKey). The launcher holds the same
* table (hotkeys.js, FIXED_KEYS). */
static const WideChar FIXED_KEYS[] = { 'A', 'S', 'G', 'Y', 'V', 'N', 'C', 'H' };
+/** FixedOrderKeys in Hotkeys.ini: with Enabled = No none of the above holds, and every button, the
+ * orders included, wears its label's letter or the player's, as in the game as shipped. Read with
+ * the button keys, back to on before each read. */
+static Bool s_fixedOrderKeys = TRUE;
static const char *const FIXED_H_BUTTONS[] =
{
"command_upgradechinamines", "command_upgradeempmines", "command_upgradecamonetting", "command_upgradeglacamonetting",
@@ -348,6 +352,8 @@ static const char FIXED_H_PREFIX[] = "command_becomerealgla"; ///< a fake buildi
static WideChar fixedButtonKey( const AsciiString& lowerName, Int commandType )
{
+ if( !s_fixedOrderKeys )
+ return 0;
if( strncmp( lowerName.str(), FIXED_H_PREFIX, sizeof( FIXED_H_PREFIX ) - 1 ) == 0 )
return 'H';
for( Int each = 0; each < (Int)( sizeof( FIXED_H_BUTTONS ) / sizeof( FIXED_H_BUTTONS[ 0 ] ) ); each++ )
@@ -497,11 +503,37 @@ WideChar HotKeyManager::buttonKeyIn( const AsciiString& button, WideChar labelKe
letter -= 'a' - 'A';
// a label's own fixed letter gives way; one the player chose stays, and the bar's fixed order
// still takes it first (addHotKey)
- if( !chosen && isOneOf( letter, FIXED_KEYS, (Int)( sizeof( FIXED_KEYS ) / sizeof( FIXED_KEYS[ 0 ] ) ) ) )
+ if( !chosen && s_fixedOrderKeys && isOneOf( letter, FIXED_KEYS, (Int)( sizeof( FIXED_KEYS ) / sizeof( FIXED_KEYS[ 0 ] ) ) ) )
return 0;
return letter;
}
+//-----------------------------------------------------------------------------
+Bool HotKeyManager::fixedOrderKeys( void )
+{
+ return s_fixedOrderKeys;
+}
+
+void HotKeyManager::setFixedOrderKeys( Bool fixed )
+{
+ s_fixedOrderKeys = fixed;
+}
+
+//-----------------------------------------------------------------------------
+/** FixedOrderKeys, Enabled = Yes or No, End: whether the orders hold their fixed letters (FIXED_KEYS). */
+/*static*/ void INI::parseFixedOrderKeysDefinition( INI *ini )
+{
+ static const FieldParse fields[] =
+ {
+ { "Enabled", INI::parseBool, NULL, 0 },
+ { NULL, NULL, NULL, 0 }
+ };
+ Bool enabled = TRUE;
+ ini->initFromINI( &enabled, fields );
+ s_fixedOrderKeys = enabled;
+ DEBUG_LOG(( "HOTKEYS: fixed order keys %s\n", enabled ? "on" : "off" ));
+}
+
//-----------------------------------------------------------------------------
/** CommandBarGrid, Enabled = Yes or No, End: the grid keys a launcher before 2026-10-15 wrote into
* Hotkeys.ini. Grid keys are gone, so the block is read and ignored. */
@@ -546,6 +578,7 @@ WideChar HotKeyManager::buttonKeyIn( const AsciiString& button, WideChar labelKe
void HotKeyManager::loadPlayerKeys( void )
{
s_playerButtonKeys.clear();
+ s_fixedOrderKeys = TRUE;
AsciiString hotkeys = TheGlobalData->getPath_UserData();
hotkeys.concat( "Hotkeys.ini" );
if( !TheFileSystem->doesFileExist( hotkeys.str() ) )
@@ -819,7 +852,12 @@ HotkeysFile Hotkeys_parse( const std::string& text, const std::vector< HotkeyCom
{
const HotkeyIniBlock& block = blocks[ each ];
const std::string key = block.field( "Key", "" );
- if( block.type == "CommandButtonHotKey" )
+ if( block.type == "FixedOrderKeys" )
+ {
+ const std::string enabled = lowered( block.field( "Enabled", "yes" ) );
+ file.fixedOrderKeys = !( enabled == "no" || enabled == "false" );
+ }
+ else if( block.type == "CommandButtonHotKey" )
{
const Bool letter = key.size() == 1 && isalpha( (unsigned char)key[ 0 ] );
file.buttons[ block.name ] = letter ? std::string( 1, (char)toupper( (unsigned char)key[ 0 ] ) ) : std::string();
@@ -940,6 +978,8 @@ std::string Hotkeys_format( const HotkeysFile& file, const std::vector< HotkeyCo
"; Zero Hour Reforged hotkeys, written by the launcher's Hotkeys page. Only what differs from the\r\n"
"; game is here. The game reads it at start; it is not part of the multiplayer checksum.\r\n"
"\r\n";
+ if( !file.fixedOrderKeys )
+ out += "FixedOrderKeys\r\n Enabled = No\r\nEnd\r\n\r\n";
std::map< std::string, Bool > named;
std::vector< std::string > ids = sortedNames( file.commands );
for( size_t each = 0; each < ids.size(); each++ )
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 936d08782..a0bef4e4b 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -4402,6 +4402,36 @@ TEST(controlbar_force_attack_slot_is_under_attack_move)
GUI_COMMAND_FORCE_ATTACK ), 0 );
}
+/* FixedOrderKeys, Enabled = No: the keys as shipped. The German Guard is W and its rally point U, and
+ a Humvee (V) or Nachschublager (N) keeps the letter the fixed keys took from it */
+TEST(hotkeys_fixed_order_keys_switch_off_gives_the_labels_letters)
+{
+ const std::map< std::string, WideChar > none;
+ CHECK( HotKeyManager::fixedOrderKeys() );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_Guard" ), 'W', GUI_COMMAND_GUARD, none ), (WideChar)'G' );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_ConstructAmericaVehicleHumvee" ), 'V',
+ GUI_COMMAND_UNIT_BUILD, none ), 0 );
+
+ HotKeyManager::setFixedOrderKeys( FALSE );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_Guard" ), 'W', GUI_COMMAND_GUARD, none ), (WideChar)'W' );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_SetRallyPoint" ), 'u', GUI_COMMAND_SET_RALLY_POINT, none ), (WideChar)'U' );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_UpgradeChinaMines" ), 'L', GUI_COMMAND_PLAYER_UPGRADE, none ), (WideChar)'L' );
+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_ConstructAmericaVehicleHumvee" ), 'V',
+ GUI_COMMAND_UNIT_BUILD, none ), (WideChar)'V' );
+ CHECK_EQ( HotKeyManager::fixedKey( AsciiString( "Command_Stop" ), GUI_COMMAND_STOP ), 0 );
+ HotKeyManager::setFixedOrderKeys( TRUE );
+
+ // the file carries the switch through the options page's Accept, and leaves it out when on
+ const std::vector< HotkeyCommandRow > rows = Hotkeys_commandRows( HOTKEYS_COMMAND_MAP );
+ HotkeysFile file = Hotkeys_parse( "FixedOrderKeys\r\n Enabled = No\r\nEnd\r\n", rows );
+ CHECK( !file.fixedOrderKeys );
+ const std::string text = Hotkeys_format( file, rows );
+ CHECK( text.find( "FixedOrderKeys\r\n Enabled = No\r\nEnd\r\n" ) != std::string::npos );
+ CHECK( !Hotkeys_parse( text, rows ).fixedOrderKeys );
+ file.fixedOrderKeys = TRUE;
+ CHECK( Hotkeys_format( file, rows ).find( "FixedOrderKeys" ) == std::string::npos );
+}
+
TEST(metamap_format_chord_names_the_hold)
{
CHECK( MetaMap_formatChord( MK_NONE, CTRL, COMMANDUSABLE_GAME ) == UnicodeString( u"Ctrl" ) );
diff --git a/README.md b/README.md
index 6651e8196..0a13b3cd2 100644
--- a/README.md
+++ b/README.md
@@ -211,6 +211,16 @@ Almost everything is on the seven pages of the options screen. These still live
| `ShowAllyCursors = no` | stops sending your mouse position to allies and stops drawing theirs |
| `EdgeScrollInWindowedMode = yes` | scrolls at the screen edge in a window too |
+`Hotkeys.ini`, beside it, takes a block that brings back the command bar's keys as the game shipped
+them: attack move, stop, guard, rally point, evacuate, sell and combat drop on their own labels'
+letters, and every button that lost its letter to one of them keeping it.
+
+```ini
+FixedOrderKeys
+ Enabled = No
+End
+```
+
On the command line, `-d3d9` starts the old renderer and `-dx11post off` gives the Direct3D 11 picture
without its finishing passes. `-nologo` skips the EA logo and `-novideo` every movie, and `-loadsave
<name>` opens a save game the way `-replay` opens a replay.