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(gameengine): control socket presses, picks and reads shell windows

Olcay Seygan3088388dfce8
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
index cb61e5e4b..ae974d8de 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
@@ -37,7 +37,10 @@
#include "Common/Money.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
+#include "Common/NameKeyGenerator.h"
#include "GameClient/Display.h"
+#include "GameClient/GadgetListBox.h"
+#include "GameClient/GameWindowManager.h"
#include "GameClient/InGameUI.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/Shell.h"
@@ -708,6 +711,59 @@ static void handleCommand( const AsciiString &command )
return;
}
+ /* press, select and uitext reach a shell window by its layout name (MainMenu.wnd:ButtonOnline), so a
+ script walks the menus without knowing where anything is on the screen. press sends what a mouse
+ up on a push button sends its owner, select picks a list box row, uitext reads what a window shows. */
+ if (strncmp( command.str(), "press ", 6 ) == 0 || strncmp( command.str(), "select ", 7 ) == 0 || strncmp( command.str(), "uitext ", 7 ) == 0)
+ {
+ const Bool isPress = command.str()[ 0 ] == 'p';
+ const Bool isSelect = command.str()[ 0 ] == 's';
+ AsciiString name( command.str() + (isPress ? 6 : 7) );
+ Int row = 0;
+ if (isSelect)
+ {
+ const char *space = strrchr( name.str(), ' ' );
+ if (space == NULL)
+ {
+ replyError( "select wants a window name and a row" );
+ return;
+ }
+ row = atoi( space + 1 );
+ AsciiString nameOnly;
+ nameOnly.format( "%.*s", (Int)(space - name.str()), name.str() );
+ name = nameOnly;
+ }
+ name.trim();
+
+ const NameKeyType key = TheNameKeyGenerator->nameToKey( name );
+ GameWindow *window = TheWindowManager->winGetWindowFromId( NULL, key );
+ if (window == NULL)
+ {
+ replyError( "no such window" );
+ return;
+ }
+
+ if (isPress)
+ {
+ TheWindowManager->winSendSystemMsg( window->winGetOwner(), GBM_SELECTED, (WindowMsgData)window, key );
+ replyOk( "\"pressed\":true" );
+ }
+ else if (isSelect)
+ {
+ GadgetListBoxSetSelected( window, row );
+ replyOk( "\"selected\":true" );
+ }
+ else
+ {
+ AsciiString text;
+ text.translate( window->winGetText() );
+ AsciiString field;
+ field.format( "\"text\":\"%s\"", text.str() );
+ replyOk( field.str() );
+ }
+ return;
+ }
+
/* save <name>: the save menu's Save, into <name>.sav in the save directory, so a script can make
the file -loadsave opens. Letters, digits, - and _ only, since it becomes a path. */
if (strncmp( command.str(), "save ", 5 ) == 0)