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): trainer panel, every console cheat one click away
Olcay Seygan99a66f1df4a4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 617acf90c..67d89b5be 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -945,6 +945,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- `help` lists what it takes, `clear` empties it, `echo` says a line back. The up and down arrows walk back through the last thirty-two things you typed.- It opens in the main menu as well as in a match.- Cheats for campaign and skirmish, listed by `cheats`: `money` and `points` hand over cash and general's points, `rankup` raises the general's rank, `heroic` makes every unit you own heroic and `reveal` lifts the shroud for good. `power`, `nocooldown`, `god`, `instantbuild` and `onehitkill` switch on and off: power that never runs short, general's powers and superweapons always ready, your side taking no damage, anything built or trained in an instant, and every hit you land a kill. `money 50000` takes an amount. They are recorded in the replay like any order. In a LAN or online game, a replay or the main menu the console does not offer them at all.+- `trainer` puts every cheat on a steel panel down the left of the screen, the way a trainer would. The on-and-off ones light up green while they are on, cash comes in 1,000, 10,000 and 100,000 at a click, general's points in 1, 5 and 10. A click counts exactly like typing the cheat, replay included. `trainer` again, the X in its corner or Escape puts it away.- With `god` on, an EMP no longer blows your helicopters out of the sky and drops the pilot. The helicopter goes dark, sinks to the ground, sits there until the EMP wears off and lifts back up to where it was. A plane that needs a runway flies straight through the blast instead, since it would have nowhere to take off from.- The general's promotion screen moved off that key onto the backslash beside it.- One press is one letter. Holding a key repeats it, and the game timed that wait in frames: a third of a second at the 30 frames a second it was written for, 70 milliseconds on a 144 Hz screen, which is shorter than an ordinary keypress. It waits 0.4 seconds now whatever the frame rate, in the console, the chat box and every text field.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 4d0f03ed8..fcb2a6f65 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1300,6 +1300,63 @@ GUI:HudFog"Fog of war"END+// The cheat panel the console's "trainer" command opens, Window/Html/Cheats.html.+GUI:CheatPanelTitle+"Cheats"+END++GUI:CheatMoney+"Cash"+END++GUI:CheatPoints+"General's points"+END++GUI:CheatRankUp+"Rank up"+END++GUI:CheatHeroic+"Heroic units"+END++GUI:CheatReveal+"Reveal the map"+END++GUI:CheatPower+"Unlimited power"+END++GUI:CheatNoCooldown+"No cooldowns"+END++GUI:CheatGod+"God mode"+END++GUI:CheatInstantBuild+"Instant build"+END++GUI:CheatOneHitKill+"One-hit kills"+END++GUI:CheatOn+"ON"+END++GUI:CheatOff+"OFF"+END++GUI:CheatApply+"GO"+END+// after a superweapon's name in the event feed over the radar, the moment it can fireGUI:HudSuperweaponReady"ready to fire"diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 40526c42b..54615da68 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15797,6 +15797,62 @@ GUI:HudFog"Savaş sisi"END+GUI:CheatPanelTitle+"Hileler"+END++GUI:CheatMoney+"Para"+END++GUI:CheatPoints+"General Puanı"+END++GUI:CheatRankUp+"Rütbe atla"+END++GUI:CheatHeroic+"Kahraman birlikler"+END++GUI:CheatReveal+"Haritayı aç"+END++GUI:CheatPower+"Sınırsız elektrik"+END++GUI:CheatNoCooldown+"Bekleme yok"+END++GUI:CheatGod+"Ölümsüzlük"+END++GUI:CheatInstantBuild+"Anında inşa"+END++GUI:CheatOneHitKill+"Tek vuruşta öldür"+END++GUI:CheatOn+"AÇIK"+END++GUI:CheatOff+"KAPALI"+END++GUI:CheatApply+"YAP"+END+GUI:HudSuperweaponReady"ateşe hazır"ENDdiff --git a/GeneralsMD/Code/Data/Window/Html/Cheats.html b/GeneralsMD/Code/Data/Window/Html/Cheats.htmlnew file mode 100644index 000000000..c6073db8e--- /dev/null+++ b/GeneralsMD/Code/Data/Window/Html/Cheats.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<!--+ The cheat panel the console's "trainer" command opens: every console cheat as a row, a toggle+ lit while it is on, an amount cheat with its ready amounts. Same steel as+ Window/Html/QuitMenu.html. A click runs the cheat through the console, so it is a MSG_CHEAT like+ a typed one: recorded in the replay, refused in a network game.++ The game fills in (GameClient/GameConsole.cpp):+ {{side}} "america", "china" or "gla": the side whose command bar is on screen+ {{text:Label}} a string table label, in the player's language+ data-each="cells" every cell of the panel in reading order: a {{kind}} "name" entry with the+ cheat's {{label}} opens each row, then its keys, {{kind}} "key" and "key on"+ for a toggle that is on, each with its {{label}} and the {{click}} it sends+ All in the page's pixels, a pixel of an 800x600 screen. data-click="close" shuts the panel.+-->+<html>+<head>+<meta charset="utf-8">+<title>Cheats</title>+<style>+ html, body { margin: 0; padding: 0; }+ body { background-color: #3b4a36; font-size: 10px; color: #e8eef2; }++ .plate { position: absolute; left: 10px; top: 60px; width: 307px; padding: 4px 6px 7px 6px;+ background: linear-gradient(to bottom, #9aa3ad, #5a626c 12%, #353c45); border: 1px solid #0c1114;+ border-top-color: #dde4ea; border-left-color: #b3bbc4; }+ .china .plate { background: linear-gradient(to bottom, #c06a52, #7a3120 12%, #3f160f); border-top-color: #f0b8a4; border-left-color: #d58a70; }+ .gla .plate { background: linear-gradient(to bottom, #b8ab6e, #766a3a 12%, #3c3519); border-top-color: #ebe2b4; border-left-color: #cabe86; }++ .title { height: 16px; line-height: 16px; font-weight: bold; color: #f2cf4a; }++ .well { padding: 3px 4px 4px 4px; border: 2px solid #06090b; border-bottom-color: #b4bec8; border-right-color: #b4bec8;+ background-color: #3a414a; }+ .china .well { border-bottom-color: #d98a72; border-right-color: #d98a72; background-color: #45190f; }+ .gla .well { border-bottom-color: #cbbf82; border-right-color: #cbbf82; background-color: #423a1c; }+ .end { clear: left; height: 0; }++ /* the well is exactly one name and three keys wide, so each row's keys stay on its line */+ .name { float: left; clear: left; white-space: nowrap; width: 124px; height: 14px; line-height: 14px; margin-top: 3px; }+ .key { float: left; white-space: nowrap; width: 52px; height: 12px; line-height: 12px; margin: 3px 0 0 3px; text-align: center; font-weight: bold;+ border: 1px solid #06090b; border-bottom-color: #9aa4ae; border-right-color: #9aa4ae; background-color: rgba(4, 8, 10, 0.9); }+ .china .key { border-bottom-color: #d98a72; border-right-color: #d98a72; }+ .gla .key { border-bottom-color: #cbbf82; border-right-color: #cbbf82; }+ .key:hover { background: linear-gradient(to bottom, #b3bbc4, #5a626c); border-color: #e8d27a; color: #ffffff; }+ .china .key:hover { background: linear-gradient(to bottom, #d58a70, #7a3120); }+ .gla .key:hover { background: linear-gradient(to bottom, #cabe86, #766a3a); }+ /* a toggle that is on stays lit in the power bar's green */+ .key.on { background: linear-gradient(to bottom, #9be07a, #2f7a1c); border-color: #e8d27a; color: #ffffff; }++ .close { position: absolute; right: 6px; top: 4px; width: 14px; height: 12px; line-height: 12px; }+</style>+</head>+<body>+<div class="{{side}}">+ <div class="plate">+ <div class="title">{{text:GUI:CheatPanelTitle}}</div>+ <div class="key close" data-click="close">X</div>+ <div class="well">+ <div class="{{kind}}" data-each="cells" data-click="{{click}}">{{label}}</div>+ <div class="end"></div>+ </div>+ </div>+</div>+</body>+</html>diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.hindex 35d8b22e7..04660c4da 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h@@ -31,10 +31,12 @@#include "Common/UnicodeString.h"#include <deque>+#include <string>#include <vector>class DisplayString;class GameFont;+class HtmlOverlay;/*** The console's own scrollback, input line and command table. One global, TheGameConsole,@@ -61,11 +63,18 @@ public:/// Draw the panel. Called from the display's 2D overlay pass.void render( void );+ /// The cheat panel, Window/Html/Cheats.html, that "trainer" opens: every cheat a click away.+ Bool isCheatPanelOpen( void ) const { return m_cheatPanelOpen; }+ void closeCheatPanel( void ) { m_cheatPanelOpen = FALSE; }+ /// TRUE when the pointer is on the panel; with `act`, a click there runs what it was on.+ Bool handleCheatPanelMouse( const ICoord2D &mouse, Bool act );+private:void submitInputLine( void );void runCommand( AsciiString commandLine );void recallHistory( Int direction );+ void renderCheatPanel( void );typedef std::deque<UnicodeString> ScrollbackLines;typedef std::vector<AsciiString> CommandHistory;@@ -79,6 +88,12 @@ private:GameFont *m_font;DisplayString **m_lineStrings; ///< one per drawable row, reused every frameInt m_lineStringCount;++ Bool m_cheatPanelOpen;+ Bool m_cheatPanelShown; ///< drawn this frame, so its clicks are real+ Bool m_cheatPanelLogged; ///< its keys' places written to the log once for each opening+ std::string m_cheatPage; ///< Window/Html/Cheats.html as read, empty until the first opening+ HtmlOverlay *m_cheatOverlay;};extern GameConsole *TheGameConsole;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cppindex e99553ca3..3fb036904 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp@@ -764,6 +764,30 @@ static void handleCommand( const AsciiString &command )return;}+ /* click <x> <y>+ A left press and release at that screen pixel, carried the way Mouse.cpp carries a real one,+ for what lies over the world and reads the click's own position, the cheat panel among them.+ The cursor itself does not move. */+ if (strncmp( command.str(), "click ", 6 ) == 0)+ {+ ICoord2D pixel;+ if (sscanf( command.str() + 6, "%d %d", &pixel.x, &pixel.y ) != 2)+ {+ replyError( "click wants two screen pixels, x then y" );+ return;+ }+ const GameMessage::Type halves[] = { GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN, GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP };+ for (Int half = 0; half < 2; ++half)+ {+ GameMessage *msg = TheMessageStream->appendMessage( halves[ half ] );+ msg->appendPixelArgument( pixel );+ msg->appendIntegerArgument( KEY_STATE_NONE );+ msg->appendIntegerArgument( 0 );+ }+ replyOk( "\"clicked\":true" );+ return;+ }+/* spectator <action>What a data-click on the spectator's page does, without finding its pixel: camera:director,follow:3, fog, flip:camera and the rest of the actions Window/Html/Spectator.html names. */diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cppindex 5cca341e6..5d1adc71e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp@@ -25,20 +25,29 @@#include "GameClient/GameConsole.h"+#include "Common/file.h"+#include "Common/FileSystem.h"#include "Common/GameEngine.h"#include "Common/MessageStream.h"#include "Common/Player.h"#include "Common/PlayerList.h"#include "Common/Recorder.h"#include "GameLogic/GameLogic.h"+#include "GameNetwork/GameSpy/ThreadUtils.h"#include "GameClient/Color.h"+#include "GameClient/ControlBar.h"+#include "GameClient/ControlBarScheme.h"#include "GameClient/Display.h"#include "GameClient/DisplayString.h"#include "GameClient/DisplayStringManager.h"#include "GameClient/GameFont.h"+#include "GameClient/GameText.h"+#include "GameClient/HtmlOverlay.h"+#include "GameClient/HtmlTemplate.h"#include "GameClient/KeyDefs.h"#include "GameClient/Keyboard.h"+#include "GameClient/Mouse.h"GameConsole *TheGameConsole = NULL;@@ -65,28 +74,36 @@ static const Color CONSOLE_INPUT_COLOR = GameMakeColor( 255, 255, 255, 255 );static const Color CONSOLE_TEXT_COLOR = GameMakeColor( 190, 190, 190, 255 );static const Color CONSOLE_SHADOW_COLOR = GameMakeColor( 0, 0, 0, 0 );+static const Int CHEAT_PANEL_AMOUNTS = 3; ///< the most ready amounts a row of the panel offers+struct ConsoleCheat{const char *name;CheatKind kind;Int defaultAmount; ///< what a bare command gives; zero marks a toggleconst char *help;+ const char *label; ///< its row on the cheat panel+ Int amounts[ CHEAT_PANEL_AMOUNTS ]; ///< the panel's keys for it, zero for none; a toggle has one on/off key};static const ConsoleCheat CONSOLE_CHEATS[] ={- { "money", CHEAT_MONEY, 10000, "money [n] add cash, 10000 by default" },- { "points", CHEAT_GENERAL_POINTS, 1, "points [n] add general's points" },- { "rankup", CHEAT_RANK_UP, 1, "rankup [n] raise the general's rank" },- { "heroic", CHEAT_HEROIC, 1, "heroic every unit you have goes heroic" },- { "reveal", CHEAT_REVEAL_MAP, 1, "reveal lift the shroud for good" },- { "power", CHEAT_INFINITE_POWER, 0, "power never run short of power" },- { "nocooldown", CHEAT_NO_COOLDOWN, 0, "nocooldown generals powers and superweapons always ready" },- { "god", CHEAT_GOD_MODE, 0, "god your side takes no damage" },- { "instantbuild", CHEAT_INSTANT_BUILD, 0, "instantbuild build, train and upgrade in one frame" },- { "onehitkill", CHEAT_ONE_HIT_KILL, 0, "onehitkill every hit you land kills" },+ { "money", CHEAT_MONEY, 10000, "money [n] add cash, 10000 by default", "GUI:CheatMoney", { 1000, 10000, 100000 } },+ { "points", CHEAT_GENERAL_POINTS, 1, "points [n] add general's points", "GUI:CheatPoints", { 1, 5, 10 } },+ { "rankup", CHEAT_RANK_UP, 1, "rankup [n] raise the general's rank", "GUI:CheatRankUp", { 1 } },+ { "heroic", CHEAT_HEROIC, 1, "heroic every unit you have goes heroic", "GUI:CheatHeroic", { 1 } },+ { "reveal", CHEAT_REVEAL_MAP, 1, "reveal lift the shroud for good", "GUI:CheatReveal", { 1 } },+ { "power", CHEAT_INFINITE_POWER, 0, "power never run short of power", "GUI:CheatPower", { 0 } },+ { "nocooldown", CHEAT_NO_COOLDOWN, 0, "nocooldown generals powers and superweapons always ready", "GUI:CheatNoCooldown", { 0 } },+ { "god", CHEAT_GOD_MODE, 0, "god your side takes no damage", "GUI:CheatGod", { 0 } },+ { "instantbuild", CHEAT_INSTANT_BUILD, 0, "instantbuild build, train and upgrade in one frame", "GUI:CheatInstantBuild", { 0 } },+ { "onehitkill", CHEAT_ONE_HIT_KILL, 0, "onehitkill every hit you land kills", "GUI:CheatOneHitKill", { 0 } },};+static const char *const CHEAT_PANEL_PAGE = "Window\\Html\\Cheats.html";+static const char *const CHEAT_PANEL_FONT = "Arial"; ///< what the page's text is where its CSS names no font+static const std::string CHEAT_PANEL_CLOSE = "close";+static const Int CONSOLE_CHEAT_COUNT = sizeof( CONSOLE_CHEATS ) / sizeof( CONSOLE_CHEATS[ 0 ] );//-------------------------------------------------------------------------------------------------@@ -156,7 +173,11 @@ GameConsole::GameConsole()m_historyCursor( 0 ),m_font( NULL ),m_lineStrings( NULL ),- m_lineStringCount( 0 )+ m_lineStringCount( 0 ),+ m_cheatPanelOpen( FALSE ),+ m_cheatPanelShown( FALSE ),+ m_cheatPanelLogged( FALSE ),+ m_cheatOverlay( NULL ){m_font = TheFontLibrary->getFont( AsciiString( CONSOLE_FONT_NAME ),CONSOLE_FONT_POINT_SIZE,@@ -182,6 +203,9 @@ GameConsole::~GameConsole()delete [] m_lineStrings;m_lineStrings = NULL;m_lineStringCount = 0;++ delete m_cheatOverlay;+ m_cheatOverlay = NULL;}//-------------------------------------------------------------------------------------------------@@ -314,7 +338,10 @@ void GameConsole::runCommand( AsciiString commandLine )printLine( AsciiString( "echo <text> print the text back" ) );printLine( AsciiString( "speed [n] game speed in percent, 100 is normal, 'reset' goes back" ) );if( areCheatsAvailable() )+ {printLine( AsciiString( "cheats single-player cheats" ) );+ printLine( AsciiString( "trainer the cheats on a panel, one click each" ) );+ }return;}@@ -323,6 +350,17 @@ void GameConsole::runCommand( AsciiString commandLine ){for( Int i = 0; i < CONSOLE_CHEAT_COUNT; ++i )printLine( AsciiString( CONSOLE_CHEATS[ i ].help ) );+ printLine( AsciiString( "trainer all of these on a panel; trainer again, X or Esc closes it" ) );+ return;+ }++ // the console drops out of the way so the panel is under the pointer at once+ if( cheatsAvailable && command == "trainer" )+ {+ m_cheatPanelOpen = !m_cheatPanelOpen;+ m_cheatPanelLogged = FALSE;+ if( m_cheatPanelOpen )+ close();return;}@@ -363,6 +401,8 @@ void GameConsole::runCommand( AsciiString commandLine )//-------------------------------------------------------------------------------------------------void GameConsole::render( void ){+ renderCheatPanel(); // under the console, which covers it when it drops+if( !m_isOpen )return;@@ -398,6 +438,170 @@ void GameConsole::render( void )}}+//-------------------------------------------------------------------------------------------------+/** The side whose command bar is on screen, for the panel's steel: the same three the other pages+ * under Window/Html are drawn in. */+//-------------------------------------------------------------------------------------------------+static std::string cheatPanelSide( void )+{+ ControlBarSchemeManager *schemes = TheControlBar ? TheControlBar->getControlBarSchemeManager() : NULL;+ const AsciiString side = schemes ? schemes->getCurrentSide() : AsciiString::TheEmptyString;+ if( side.startsWith( "China" ) || side == "Boss" )+ return "china";+ if( side.startsWith( "GLA" ) )+ return "gla";+ return "america";+}++static std::string gameText( const char *label )+{+ return WideCharStringToMultiByte( TheGameText->fetch( label ).str() );+}++/** {{text:Label}}: a string table label, in the player's language. */+static Bool lookupCheatPanelText( const std::string &name, std::string &value )+{+ static const std::string TEXT_LOOKUP = "text:";+ if( name.compare( 0, TEXT_LOOKUP.size(), TEXT_LOOKUP ) != 0 )+ return FALSE;+ value = gameText( name.substr( TEXT_LOOKUP.size() ).c_str() );+ return TRUE;+}++//-------------------------------------------------------------------------------------------------+/** Every cheat a row: its name, then a toggle's one key, lit while it is on, or an amount cheat's+ * ready amounts. `clicks` gets what each key sends, in the order the page lays the keys out. */+//-------------------------------------------------------------------------------------------------+static void fillCheatPanelCells( std::vector< HtmlValues > &cells, std::vector< std::string > &clicks )+{+ const Player *local = ThePlayerList->getLocalPlayer();+ clicks.push_back( CHEAT_PANEL_CLOSE );++ for( Int i = 0; i < CONSOLE_CHEAT_COUNT; ++i )+ {+ const ConsoleCheat &cheat = CONSOLE_CHEATS[ i ];+ HtmlValues name;+ name[ "kind" ] = "name";+ name[ "label" ] = gameText( cheat.label );+ cells.push_back( name );++ if( cheat.defaultAmount == 0 )+ {+ const Bool on = local->hasCheat( cheat.kind );+ HtmlValues key;+ key[ "kind" ] = on ? "key on" : "key";+ key[ "label" ] = gameText( on ? "GUI:CheatOn" : "GUI:CheatOff" );+ key[ "click" ] = cheat.name;+ cells.push_back( key );+ clicks.push_back( key[ "click" ] );+ continue;+ }++ const Bool oneAmount = cheat.amounts[ 1 ] == 0;+ for( Int each = 0; each < CHEAT_PANEL_AMOUNTS && cheat.amounts[ each ] != 0; ++each )+ {+ char text[ 64 ];+ HtmlValues key;+ key[ "kind" ] = "key";+ sprintf( text, "+%d", cheat.amounts[ each ] );+ key[ "label" ] = oneAmount ? gameText( "GUI:CheatApply" ) : std::string( text );+ sprintf( text, "%s %d", cheat.name, cheat.amounts[ each ] );+ key[ "click" ] = text;+ cells.push_back( key );+ clicks.push_back( key[ "click" ] );+ }+ }+}++//-------------------------------------------------------------------------------------------------+/** Window/Html/Cheats.html over the battlefield while it is open. It shuts itself wherever the+ * cheats are refused, so a panel left open does not follow the player into a replay. */+//-------------------------------------------------------------------------------------------------+void GameConsole::renderCheatPanel( void )+{+ m_cheatPanelShown = FALSE;+ if( !m_cheatPanelOpen )+ return;+ if( !areCheatsAvailable() )+ {+ m_cheatPanelOpen = FALSE;+ return;+ }++ if( m_cheatPage.empty() )+ {+ File *file = TheFileSystem->openFile( CHEAT_PANEL_PAGE, File::READ | File::BINARY );+ if( file == NULL )+ {+ printLine( AsciiString( "trainer: Window/Html/Cheats.html is missing" ) );+ m_cheatPanelOpen = FALSE;+ return;+ }+ const Int size = file->size();+ char *text = file->readEntireAndClose();+ m_cheatPage.assign( text, size );+ delete [] text;+ }+ if( m_cheatOverlay == NULL )+ m_cheatOverlay = new HtmlOverlay( AsciiString( CHEAT_PANEL_FONT ) );++ HtmlValues values;+ values[ "side" ] = cheatPanelSide();+ HtmlLists lists;+ std::vector< std::string > clicks;+ fillCheatPanelCells( lists[ "cells" ], clicks );++ m_cheatOverlay->setPage( HtmlTemplate_expand( m_cheatPage, values, lists, lookupCheatPanelText ) );+ m_cheatOverlay->hover( TheMouse->getMouseStatus()->pos );+ m_cheatOverlay->draw();+ m_cheatPanelShown = TRUE;++ // where each key landed, so a script driving the game over -control knows where to click+ if( !m_cheatPanelLogged )+ {+ m_cheatPanelLogged = TRUE;+ std::vector< IRegion2D > keys;+ m_cheatOverlay->rectsOf( ".key", keys );+ for( size_t each = 0; each < keys.size() && each < clicks.size(); ++each )+ DEBUG_LOG(( "Cheat panel: \"%s\" at %d %d\n", clicks[ each ].c_str(),+ ( keys[ each ].lo.x + keys[ each ].hi.x ) / 2, ( keys[ each ].lo.y + keys[ each ].hi.y ) / 2 ));+ }+}++//-------------------------------------------------------------------------------------------------+/** A press anywhere on the panel is the panel's, so it never turns into an order for the ground+ * under it. Only a left press does anything: it runs the key's cheat the way typing it would. */+//-------------------------------------------------------------------------------------------------+Bool GameConsole::handleCheatPanelMouse( const ICoord2D &mouse, Bool act )+{+ if( !m_cheatPanelShown || !m_cheatOverlay->hover( mouse ) )+ return FALSE;+ if( !act )+ return TRUE;++ const std::string action = m_cheatOverlay->click( mouse );+ if( action == CHEAT_PANEL_CLOSE )+ {+ closeCheatPanel();+ return TRUE;+ }++ AsciiString arguments( action.c_str() );+ AsciiString name;+ arguments.nextToken( &name );+ arguments.trim();+ for( Int i = 0; !name.isEmpty() && areCheatsAvailable() && i < CONSOLE_CHEAT_COUNT; ++i )+ {+ if( name == CONSOLE_CHEATS[ i ].name )+ {+ const AsciiString result = runCheat( CONSOLE_CHEATS[ i ], arguments );+ printLine( result );+ DEBUG_LOG(( "Cheat panel: %s\n", result.str() ));+ }+ }+ return TRUE;+}+//-------------------------------------------------------------------------------------------------GameMessageDisposition GameConsoleTranslator::translateGameMessage( const GameMessage *msg ){@@ -420,10 +624,51 @@ GameMessageDisposition GameConsoleTranslator::translateGameMessage( const GameMereturn DESTROY_MESSAGE;}- if( !TheGameConsole->isOpen() )- return KEEP_MESSAGE;+ if( TheGameConsole->isOpen() )+ {+ TheGameConsole->handleKey( key, keyState );+ return DESTROY_MESSAGE;+ }++ // Esc shuts the cheat panel rather than opening the quit menu: the press is eaten, and the+ // release shuts it so that release is not left to open the menu either+ if( key == KEY_ESC && TheGameConsole->isCheatPanelOpen() )+ {+ if( !BitTest( keyState, KEY_STATE_DOWN ) )+ TheGameConsole->closeCheatPanel();+ return DESTROY_MESSAGE;+ }+ return KEEP_MESSAGE;+ }++ // the wheel carries no position, and the cursor's moves are everybody's+ case GameMessage::MSG_RAW_MOUSE_POSITION:+ case GameMessage::MSG_RAW_MOUSE_WHEEL:+ return KEEP_MESSAGE;+ }- TheGameConsole->handleKey( key, keyState );+ // A press on the cheat panel is the panel's, and so is everything that button does until it is+ // let go, wherever the pointer has gone by then: nothing after this sees a press it never saw+ // start. A press that started off the panel is left alone to its release, so a drag box pulled+ // over the panel still ends.+ static Bool pressTaken = FALSE;+ const GameMessage::Type type = msg->getType();+ if( type > GameMessage::MSG_RAW_MOUSE_BEGIN && type < GameMessage::MSG_RAW_MOUSE_END )+ {+ const Bool left = type == GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN || type == GameMessage::MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK;+ const Bool press = left+ || type == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN || type == GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK+ || type == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN || type == GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK;+ if( press )+ {+ pressTaken = TheGameConsole->handleCheatPanelMouse( msg->getArgument( 0 )->pixel, left );+ return pressTaken ? DESTROY_MESSAGE : KEEP_MESSAGE;+ }+ if( pressTaken )+ {+ if( type == GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP || type == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP+ || type == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP )+ pressTaken = FALSE;return DESTROY_MESSAGE;}}