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
feat(gameengine): player keys from hotkeys.ini, outside the ini crc
Olcay Seygan4d69e69e3054
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bcc50a72b..95f40f27f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -32,6 +32,7 @@ found and fixed — EA's own, not port damage.**## One interface- The choice between a Classic and a Reforged interface is gone. There is one, laid out the way Zero Hour shipped, and the orders Reforged added now live on the keys you already know: A attack-moves, holding Ctrl fires on whatever is under the cursor as it did in 2003, a guard order can cover a patch of ground instead of one spot, and orders queue up one after another. Everything your base is building stands on the screen as a line of text each, the six closest to done first and "+N more" for the rest. Superweapon countdowns are listed the same way, up to eighteen. Whether the right button gives orders, or the left as in 1.04, is a setting in the launcher.+- 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.## The command bar moves to the middlediff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.hindex 2c3b3fec6..560fea9b3 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h@@ -280,6 +280,7 @@ public:static void parseTerrainRoadDefinition( INI *ini );static void parseTerrainBridgeDefinition( INI *ini );static void parseMetaMapDefinition( INI *ini );+ static void parseCommandButtonHotKeyDefinition( 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.hindex bd73535ea..200b37671 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h@@ -109,6 +109,12 @@ public:* would land. */GameWindow *findHotKey( const AsciiString& key, Bool *pressable ) const;+ /** The key a command button gets: the one the player gave it in Hotkeys.ini (the launcher's+ * Hotkeys page writes it, INI::parseCommandButtonHotKeyDefinition reads it), 0 where the player+ * took the key away, and labelKey, the letter after the label's '&', where the player left the+ * button alone. */+ static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey );+private:typedef std::map<AsciiString, HotKey> HotKeyMap;HotKeyMap m_hotKeyMap;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 8d9bdbdeb..94a2d30ac 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -1253,6 +1253,28 @@ void GameEngine::init( int argc, char *argv[] )ini.load("Data\\INI\\CommandMapDemo.ini", INI_LOAD_MULTIFILE, NULL);#endif+ // The player's own keys, which the launcher's Hotkeys page writes beside Options.ini:+ // CommandMap blocks laid over the ones above, and CommandButtonHotKey blocks for the command+ // bar. Client only and never in the INI CRC, so a key here changes nothing for anyone else in+ // a match. The file is the player's to edit by hand, and a broken one costs the keys from the+ // broken block on, not the start.+ {+ AsciiString hotkeys = TheGlobalData->getPath_UserData();+ hotkeys.concat( "Hotkeys.ini" );+ if( TheFileSystem->doesFileExist( hotkeys.str() ) )+ {+ try+ {+ ini.load( hotkeys, INI_LOAD_MULTIFILE, NULL );+ DEBUG_LOG(( "HOTKEYS: read %s\n", hotkeys.str() ));+ }+ catch( ... )+ {+ DEBUG_LOG(( "HOTKEYS: %s stopped at a block it could not read; the keys before it stand\n", hotkeys.str() ));+ }+ }+ }+initSubsystem(TheActionManager,"TheActionManager", MSGNEW("GameEngineSubsystem") ActionManager(), NULL);//initSubsystem((CComObject<WebBrowser> *)TheWebBrowser,"(CComObject<WebBrowser> *)TheWebBrowser", (CComObject<WebBrowser> *)createWebBrowser(), NULL);initSubsystem(TheGameStateMap,"TheGameStateMap", MSGNEW("GameEngineSubsystem") GameStateMap, NULL, NULL, NULL );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cppindex 8f9c35412..882697791 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp@@ -98,6 +98,7 @@ static const BlockParse theTypeTable[] ={ "Campaign", INI::parseCampaignDefinition },{ "ChallengeGenerals", INI::parseChallengeModeDefinition },{ "CommandButton", INI::parseCommandButtonDefinition },+ { "CommandButtonHotKey", INI::parseCommandButtonHotKeyDefinition },{ "CommandMap", INI::parseMetaMapDefinition },{ "CommandSet", INI::parseCommandSetDefinition },{ "ControlBarScheme", INI::parseControlBarSchemeDefinition },diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 9bc4c984d..d0c91e768 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -4491,12 +4491,14 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *comsetCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());- // the key is the game's own, the letter after the '&' in the button's label - the English- // label's in every language, so a Turkish or German player presses what an English one does -- // and the button wears it in its top left corner+ // the key is the one the player gave the button on the launcher's Hotkeys page, or else the+ // game's own, the letter after the '&' in the button's label - the English label's in every+ // language, so a Turkish or German player presses what an English one does - and the button+ // wears it in its top left cornerif( TheHotKeyManager ){- WideChar letter = TheGameText ? TheGameText->fetchEnglishHotKey( commandButton->getTextLabel() ) : 0;+ WideChar letter = HotKeyManager::playerButtonKey( commandButton->getName(),+ TheGameText ? TheGameText->fetchEnglishHotKey( commandButton->getTextLabel() ) : 0 );if( letter >= u'a' && letter <= u'z' )letter -= ( u'a' - u'A' );if( letter != 0 )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex 6f3cf7032..2a153c05e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -60,6 +60,12 @@#include "GameClient/Keyboard.h"#include "GameClient/GameText.h"#include "Common/AudioEventRTS.h"+#include "Common/INI.h"+#include "Common/ThingTemplate.h"+#include "GameClient/ControlBar.h"+#include "GameClient/Drawable.h"+#include "GameClient/GadgetPushButton.h"+#include "GameClient/InGameUI.h"//-----------------------------------------------------------------------------// DEFINES //////////////////////////////////////////////////////////////////////-----------------------------------------------------------------------------@@ -207,6 +213,11 @@ Bool HotKeyManager::executeHotKey( const AsciiString& keyIn ){if( BitTest( win->winGetStatus(), WIN_STATUS_ENABLED ) ){+ // what a player's own key (Hotkeys.ini) pressed can be read back from the log+ const CommandButton *command = (const CommandButton *)GadgetButtonGetData( win );+ const DrawableList *selected = TheInGameUI ? TheInGameUI->getAllSelectedDrawables() : NULL;+ DEBUG_LOG(( "HOTKEYS: %s pressed %s, selection led by %s\n", key.str(), command ? command->getName().str() : "a window",+ ( selected && !selected->empty() ) ? selected->front()->getTemplate()->getName().str() : "nothing" ));TheWindowManager->winSendSystemMsg( win->winGetParent(), GBM_SELECTED, (WindowMsgData)win, win->winGetWindowId() );// here we make the same click sound that the GUI uses when you click a button@@ -285,6 +296,47 @@ AsciiString HotKeyManager::searchHotKey( const UnicodeString& uStr )return AsciiString::TheEmptyString;}+//-----------------------------------------------------------------------------+/** The player's command button keys from Hotkeys.ini, by button name in lower case: an upper case+ * letter, or 0 for a button the player wants without a key. Read once while the engine starts and+ * kept for the whole run, so it lives outside the manager, which every game client rebuilds. */+static std::map< std::string, WideChar > s_playerButtonKeys;++//-----------------------------------------------------------------------------+WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar labelKey )+{+ AsciiString name = button;+ name.toLower();+ std::map< std::string, WideChar >::const_iterator it = s_playerButtonKeys.find( name.str() );+ return it == s_playerButtonKeys.end() ? labelKey : it->second;+}++//-----------------------------------------------------------------------------+/** CommandButtonHotKey <button name>, Key = one letter or NONE, End. Only the player's own+ * Hotkeys.ini carries these, and nothing in it reaches the INI CRC. */+/*static*/ void INI::parseCommandButtonHotKeyDefinition( INI *ini )+{+ AsciiString name = ini->getNextToken();+ name.toLower();++ static const FieldParse fields[] =+ {+ { "Key", INI::parseAsciiString, NULL, 0 },+ { NULL, NULL, NULL, 0 }+ };+ AsciiString key;+ ini->initFromINI( &key, fields );++ WideChar letter = 0;+ if( key.getLength() == 1 && isalpha( (unsigned char)key.getCharAt( 0 ) ) )+ letter = (WideChar)toupper( (unsigned char)key.getCharAt( 0 ) );+ else if( key.compareNoCase( "NONE" ) != 0 )+ throw INI_INVALID_DATA;++ s_playerButtonKeys[ name.str() ] = letter;+ DEBUG_LOG(( "HOTKEYS: button %s key %s\n", name.str(), key.str() ));+}+//-----------------------------------------------------------------------------HotKeyManager *TheHotKeyManager = NULL;