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): single-player cheats in the console
Olcay Seygana3e03978ea6a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e55d28fc9..bae9908d2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -682,7 +682,8 @@ 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. Nothing it does yet touches the rules of a game, so it is safe to leave open while one runs.+- 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.- 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/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex 078cfe081..a1360285d 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -647,6 +647,7 @@ public:MSG_DO_FORMATION_FORCEATTACK, ///< (location...) the same curve, each unit force firing its own point (fork)MSG_DO_FORMATION_GUARD, ///< (location...) the same curve, each unit guarding its own point (fork)MSG_PLACE_SIGNAL, ///< (location, Int SignalKind) smoke only the sender's allies are shown (fork)+ MSG_CHEAT, ///< (Int CheatKind, Int amount) a console cheat, refused in a network game (fork)MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 50c11b7e2..88fecb2f8 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -67,6 +67,25 @@// ----------------------------------------------------------------------------------------------+/// what a MSG_CHEAT asks for. The first five act once, the rest toggle a bit on the Player.+enum CheatKind+{+ CHEAT_MONEY,+ CHEAT_GENERAL_POINTS,+ CHEAT_RANK_UP,+ CHEAT_HEROIC,+ CHEAT_REVEAL_MAP,+ CHEAT_INFINITE_POWER,+ CHEAT_NO_COOLDOWN,+ CHEAT_GOD_MODE,+ CHEAT_INSTANT_BUILD,+ CHEAT_ONE_HIT_KILL,++ CHEAT_KIND_COUNT+};++// ----------------------------------------------------------------------------------------------+class BuildListInfo;class PolygonTrigger;class ThingTemplate;@@ -439,11 +458,13 @@ public:#endif-#if defined(_DEBUG) || defined(_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)+ /// the console's single-player cheats; only the toggles are kept here, the one-shots just act+ Bool hasCheat( CheatKind kind ) const { return BitTest( m_cheats, 1 << kind ); }+ void toggleCheat( CheatKind kind ) { m_cheats ^= 1 << kind; }+/// No time building cheat key- void toggleInstantBuild(){ m_DEMO_instantBuild = !m_DEMO_instantBuild; }- Bool buildsInstantly() const { return m_DEMO_instantBuild; }-#endif+ void toggleInstantBuild(){ toggleCheat( CHEAT_INSTANT_BUILD ); }+ Bool buildsInstantly() const { return hasCheat( CHEAT_INSTANT_BUILD ); }///< Power just changed at all. Didn't make two functions so you can't forget to undo something you didin one of them.///< @todo Can't do edge trigger until after demo; make things check for power on creation@@ -919,9 +940,7 @@ private:Bool m_DEMO_freeBuild; ///< Can I build everything for no money?#endif-#if defined(_DEBUG) || defined(_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)- Bool m_DEMO_instantBuild; ///< Can I build anything in one frame?-#endif+ UnsignedInt m_cheats; ///< one bit per toggled CheatKind; not saved, a load starts cleanScoreKeeper m_scoreKeeper; ///< The local scorekeeper for this playerdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex 44156c30f..a606fc4eb 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -657,6 +657,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_DO_FORMATION_FORCEATTACK)CHECK_IF(MSG_DO_FORMATION_GUARD)CHECK_IF(MSG_PLACE_SIGNAL)+ CHECK_IF(MSG_CHEAT)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cppindex f09022e75..55adc408d 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp@@ -90,6 +90,9 @@ Real Energy::getEnergySupplyRatio() constreturn 0.0f;}+ if( m_owner->hasCheat( CHEAT_INFINITE_POWER ) && m_energyProduction < m_energyConsumption )+ return 1.0f;+if (m_energyConsumption == 0)return (Real)m_energyProduction;@@ -104,6 +107,8 @@ Bool Energy::hasSufficientPower(void) const//Power sabotaged, therefore no power.return FALSE;}+ if( m_owner->hasCheat( CHEAT_INFINITE_POWER ) )+ return TRUE;return m_energyProduction >= m_energyConsumption;}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex e65e445ac..1d40f6a11 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -474,9 +474,7 @@ void Player::init(const PlayerTemplate* pt)m_DEMO_freeBuild = FALSE;#endif-#if defined(_DEBUG) || defined(_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)- m_DEMO_instantBuild = FALSE;-#endif+ m_cheats = 0;if (pt){diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cppindex 78f3ec993..b187d2919 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp@@ -157,12 +157,10 @@ UpgradeTemplate::~UpgradeTemplate( void )//-------------------------------------------------------------------------------------------------Int UpgradeTemplate::calcTimeToBuild( Player *player ) const{-#if defined(_DEBUG) || defined(_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)if( player->buildsInstantly() ){return 1;}-#endif///@todo modify this by power state of playerreturn m_buildTime * LOGICFRAMES_PER_SECOND;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cppindex 18dc7d650..27b9eb00a 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp@@ -1555,12 +1555,10 @@ Int ThingTemplate::calcTimeToBuild( const Player* player) constReal factionModifier = 1 + player->getProductionTimeChangePercent( getName() );buildTime *= factionModifier;-#if defined (_DEBUG) || defined (_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)if( player->buildsInstantly() ){buildTime = 1;}-#endif// Adjust build time based on energy supply.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cppindex 184bad171..bc96e4b58 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp@@ -25,6 +25,12 @@#include "GameClient/GameConsole.h"+#include "Common/MessageStream.h"+#include "Common/Player.h"+#include "Common/PlayerList.h"+#include "Common/Recorder.h"+#include "GameLogic/GameLogic.h"+#include "GameClient/Color.h"#include "GameClient/Display.h"#include "GameClient/DisplayString.h"@@ -58,6 +64,54 @@ 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 );+struct ConsoleCheat+{+ const char *name;+ CheatKind kind;+ Int defaultAmount; ///< what a bare command gives; zero marks a toggle+ const char *help;+};++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" },+};++static const Int CONSOLE_CHEAT_COUNT = sizeof( CONSOLE_CHEATS ) / sizeof( CONSOLE_CHEATS[ 0 ] );++//-------------------------------------------------------------------------------------------------+/** 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() );++ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CHEAT );+ msg->appendIntegerArgument( cheat.kind );+ msg->appendIntegerArgument( amount );++ AsciiString result;+ if( isToggle )+ result.format( "%s %s", cheat.name, ThePlayerList->getLocalPlayer()->hasCheat( cheat.kind ) ? "off" : "on" );+ else+ result.format( "%s done", cheat.name );+ return result;+}+//-------------------------------------------------------------------------------------------------GameConsole::GameConsole(): m_isOpen( FALSE ),@@ -220,9 +274,26 @@ 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" ) );+ return;+ }++ if( 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 )+ {+ if( command == CONSOLE_CHEATS[ i ].name )+ {+ printLine( runCheat( CONSOLE_CHEATS[ i ], arguments ) );+ return;+ }+ }+if( command == "clear" ){m_scrollback.clear();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cppindex 1d98f5ce6..a7a0abfec 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp@@ -379,6 +379,13 @@ void ActiveBody::attemptDamage( DamageInfo *damageInfo )&& TheGameLogic->peaceTimeForbids( damager, obj ) )return;+ // God mode stops every hit but an explicit kill (a script, a sale) and a unit's own suicide+ // weapon, so a terrorist or a demo trap still goes off.+ Player *victimPlayer = obj->getControllingPlayer();+ if( damageInfo->in.m_damageType != DAMAGE_HEALING && !damageInfo->in.m_kill && damager != obj+ && victimPlayer && victimPlayer->hasCheat( CHEAT_GOD_MODE ) )+ return;+Bool alreadyHandled = FALSE;Bool allowModifier = TRUE;Real amount = m_curArmor.adjustDamage(damageInfo->in.m_damageType, damageInfo->in.m_amount);@@ -550,6 +557,12 @@ void ActiveBody::attemptDamage( DamageInfo *damageInfo )// And remember not to adjust unresistable damage, just like the armor code can't.amount *= m_damageScalar;}++ // one hit kill: anything that got through the armour at all takes the whole bar+ Player *damagerPlayer = damager ? damager->getControllingPlayer() : NULL;+ if( amount > 0.0f && damagerPlayer && damagerPlayer != victimPlayer+ && damagerPlayer->hasCheat( CHEAT_ONE_HIT_KILL ) )+ amount = m_maxHealth;}// sanity check the damage value -- can't apply negative damagediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cppindex ef11fcbd4..8f215930b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp@@ -322,6 +322,9 @@ Bool SpecialPowerModule::isReady() constPlayer *player = getObject()->getControllingPlayer();if ( player ){+ if ( player->hasCheat( CHEAT_NO_COOLDOWN ) )+ return TRUE;+if ( modData->m_specialPowerTemplate->isSharedNSync())return (TheGameLogic->getFrame() >= player->getOrStartSpecialPowerReadyFrame( modData->m_specialPowerTemplate ) );}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex c304321c2..4826fbb44 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -51,12 +51,13 @@#include "Common/Radar.h"#include "GameLogic/AIPathfind.h"+#include "GameLogic/ExperienceTracker.h"#include "GameLogic/GameLogic.h"#include "GameLogic/Locomotor.h"#include "GameLogic/Object.h"#include "GameLogic/ObjectCreationList.h"#include "GameLogic/ObjectIter.h"-//#include "GameLogic/PartitionManager.h"+#include "GameLogic/PartitionManager.h"#include "GameLogic/AI.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/DozerAIUpdate.h"@@ -448,6 +449,16 @@ Bool Signal_isThrottled( UnsignedInt now, UnsignedInt lastSignalFrame )return now >= lastSignalFrame && now - lastSignalFrame < SIGNAL_COOLDOWN_FRAMES;}+//-------------------------------------------------------------------------------------------------+/** The heroic cheat: buildings and anything else that never ranks up are left alone. */+//-------------------------------------------------------------------------------------------------+static void makeObjectHeroic( Object *obj, void *userData )+{+ ExperienceTracker *tracker = obj->getExperienceTracker();+ if( tracker->isTrainable() )+ tracker->setVeterancyLevel( LEVEL_HEROIC );+}+//-------------------------------------------------------------------------------------------------/** This message handles dispatches object command messages to the* appropriate objects.@@ -2154,6 +2165,53 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )break;}+ // --------------------------------------------------------------------------------------------+ // The console's cheats come through here rather than acting from the console, so a replay of+ // a game that used them records them and plays back the same. A network game never takes one.+ case GameMessage::MSG_CHEAT:+ {+ if( isInMultiplayerGame() )+ break;++ CheatKind kind = (CheatKind)msg->getArgument( 0 )->integer;+ Int amount = msg->getArgument( 1 )->integer;+ switch( kind )+ {+ case CHEAT_MONEY:+ thisPlayer->getMoney()->deposit( amount );+ break;++ case CHEAT_GENERAL_POINTS:+ thisPlayer->addSciencePurchasePoints( amount );+ break;++ case CHEAT_RANK_UP:+ thisPlayer->setRankLevel( thisPlayer->getRankLevel() + amount );+ break;++ case CHEAT_HEROIC:+ thisPlayer->iterateObjects( makeObjectHeroic, NULL );+ break;++ case CHEAT_REVEAL_MAP:+ ThePartitionManager->revealMapForPlayerPermanently( thisPlayer->getPlayerIndex() );+ break;++ case CHEAT_INFINITE_POWER:+ thisPlayer->toggleCheat( kind );+ thisPlayer->onPowerBrownOutChange( !thisPlayer->getEnergy()->hasSufficientPower() );+ break;++ case CHEAT_NO_COOLDOWN:+ case CHEAT_GOD_MODE:+ case CHEAT_INSTANT_BUILD:+ case CHEAT_ONE_HIT_KILL:+ thisPlayer->toggleCheat( kind );+ break;+ }+ break;+ }+// --------------------------------------------------------------------------------------------case GameMessage::MSG_REMOVE_BEACON:{