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): console hides cheats where they cannot run

Olcay Seyganf79597f71269
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bae9908d2..fcaaf6e65 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -683,7 +683,7 @@ found and fixed — EA's own, not port damage.**
- Press the key above Tab and a black panel drops over the top of the screen with a prompt waiting at the bottom of it. Type into it and the game ignores the keys it would otherwise have read as orders, so a word starting with Q does not queue a tank. Escape or the same key again puts it away.
- `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, and a LAN or online game refuses them.
+- 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.
- 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/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
index bc96e4b58..24fe68565 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
@@ -88,15 +88,22 @@ static const ConsoleCheat CONSOLE_CHEATS[] =
static const Int CONSOLE_CHEAT_COUNT = sizeof( CONSOLE_CHEATS ) / sizeof( CONSOLE_CHEATS[ 0 ] );
+//-------------------------------------------------------------------------------------------------
+/** Cheats exist only in a campaign or skirmish match being played; anywhere else the console does
+ * not mention them at all. */
+//-------------------------------------------------------------------------------------------------
+static Bool areCheatsAvailable( void )
+{
+ return TheGameLogic->isInGame() && !TheGameLogic->isInMultiplayerGame()
+ && TheRecorder->getMode() != RECORDERMODETYPE_PLAYBACK;
+}
+
//-------------------------------------------------------------------------------------------------
/** Hands the cheat to the logic as a message and says what it will do. A toggle reads the local
* player's bit before the message lands, which is safe because only this machine sends one. */
//-------------------------------------------------------------------------------------------------
static AsciiString runCheat( const ConsoleCheat &cheat, AsciiString arguments )
{
- if( !TheGameLogic->isInGame() || TheGameLogic->isInMultiplayerGame() || TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK )
- return AsciiString( "cheats work only in a campaign or skirmish game" );
-
const Bool isToggle = cheat.defaultAmount == 0;
const Int amount = arguments.isEmpty() ? cheat.defaultAmount : atoi( arguments.str() );
@@ -274,18 +281,20 @@ void GameConsole::runCommand( AsciiString commandLine )
printLine( AsciiString( "help this list" ) );
printLine( AsciiString( "clear empty the scrollback" ) );
printLine( AsciiString( "echo <text> print the text back" ) );
- printLine( AsciiString( "cheats single-player cheats" ) );
+ if( areCheatsAvailable() )
+ printLine( AsciiString( "cheats single-player cheats" ) );
return;
}
- if( command == "cheats" )
+ const Bool cheatsAvailable = areCheatsAvailable();
+ if( cheatsAvailable && command == "cheats" )
{
for( Int i = 0; i < CONSOLE_CHEAT_COUNT; ++i )
printLine( AsciiString( CONSOLE_CHEATS[ i ].help ) );
return;
}
- for( Int i = 0; i < CONSOLE_CHEAT_COUNT; ++i )
+ for( Int i = 0; cheatsAvailable && i < CONSOLE_CHEAT_COUNT; ++i )
{
if( command == CONSOLE_CHEATS[ i ].name )
{