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.

fix(gamenetwork): refuse a LAN join from a machine with different data

Olcay Seyganc2320535562f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1c95b8d5..fe4bbd996 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -200,6 +200,11 @@ map. Ctrl+A is still everything at once.
and writes it out on both machines when the check fails. Lining up the two files points at the
single unit, building or projectile that went its own way, which is the difference between fixing
a desync and guessing at it.
+- **A LAN game refuses to start between two machines with different game files.** Two people whose
+ data files differ cannot play the same match, however well the connection behaves — one hand-edited
+ file and the two simulations part company a few minutes in, with nothing on screen to say why. The
+ check for this was written and then switched off before release; it is back on, so a mismatched
+ join is turned away in the lobby with a reason, instead of becoming a ruined game.
## Sharper textures, for free
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameDataMatch.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameDataMatch.h
new file mode 100644
index 000000000..ca562a49c
--- /dev/null
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameDataMatch.h
@@ -0,0 +1,53 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// FILE: GameDataMatch.h //////////////////////////////////////////////////////////////////////////
+// Do two machines have the same simulation inputs?
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#ifndef _GAME_DATA_MATCH_H_
+#define _GAME_DATA_MATCH_H_
+
+#include "Lib/BaseType.h"
+
+/* A lockstep game only stays in step if both machines feed the same numbers into it. Two CRCs say
+ whether they do: TheGlobalData->m_exeCRC over the executable, the version and the multiplayer
+ scripts, and TheGlobalData->m_iniCRC over the text of every INI file the simulation reads - as
+ resolved, so a loose file under Run/Data that shadows an archive is what gets CRCed, which is
+ exactly the case this fork has to catch (FileSystem::openFile asks TheLocalFileSystem first).
+ Both are exchanged when joining a game. Comparing them is the last moment at which a data
+ mismatch is a refused join instead of a desynced match. */
+
+enum GameDataMatchResult
+{
+ GAMEDATA_MATCHES = 0, ///< same executable, same INI set: the game may start
+ GAMEDATA_EXE_DIFFERS, ///< different build, or different multiplayer scripts
+ GAMEDATA_INI_DIFFERS, ///< same build, different INI set - the usual case, and the fixable one
+ GAMEDATA_UNKNOWN, ///< the other machine did not tell us what it has
+};
+
+/** Compare what the other machine reports against what we have. */
+GameDataMatchResult compareGameData( UnsignedInt theirExeCRC, UnsignedInt theirIniCRC,
+ UnsignedInt ourExeCRC, UnsignedInt ourIniCRC );
+
+/** A word for the log; never shown to the player. */
+const char *gameDataMatchName( GameDataMatchResult result );
+
+#endif // _GAME_DATA_MATCH_H_
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameDataMatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameDataMatch.cpp
new file mode 100644
index 000000000..91be6871d
--- /dev/null
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameDataMatch.cpp
@@ -0,0 +1,55 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// FILE: GameDataMatch.cpp ////////////////////////////////////////////////////////////////////////
+
+#include "PreRTS.h"
+#include "GameNetwork/GameDataMatch.h"
+
+GameDataMatchResult compareGameData( UnsignedInt theirExeCRC, UnsignedInt theirIniCRC,
+ UnsignedInt ourExeCRC, UnsignedInt ourIniCRC )
+{
+ /* Zero is not a CRC anybody computes - the executable CRC always folds in the version number,
+ and the INI CRC always folds in several megabytes of text. A machine that reports zero has
+ not checked its data at all, which is not something to start a lockstep game on. */
+ if( theirExeCRC == 0 || theirIniCRC == 0 )
+ return GAMEDATA_UNKNOWN;
+
+ /* Report the executable first when both differ: a different build reads the same INI files into
+ different code, so its INI CRC agreeing would prove nothing and its disagreeing explains
+ nothing. The INI difference is the one a player can actually go and fix. */
+ if( theirExeCRC != ourExeCRC )
+ return GAMEDATA_EXE_DIFFERS;
+
+ if( theirIniCRC != ourIniCRC )
+ return GAMEDATA_INI_DIFFERS;
+
+ return GAMEDATA_MATCHES;
+}
+
+const char *gameDataMatchName( GameDataMatchResult result )
+{
+ switch( result )
+ {
+ case GAMEDATA_MATCHES: return "same data";
+ case GAMEDATA_EXE_DIFFERS: return "different executable or multiplayer scripts";
+ case GAMEDATA_INI_DIFFERS: return "different INI set";
+ case GAMEDATA_UNKNOWN: return "data not reported";
+ }
+ return "unknown result";
+}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
index aeae19d93..7412a14c5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
@@ -36,6 +36,7 @@
#include "Common/GlobalData.h"
#include "Common/QuotedPrintable.h"
#include "Common/UserPreferences.h"
+#include "GameNetwork/GameDataMatch.h"
#include "GameNetwork/LANAPI.h"
#include "GameNetwork/LANAPICallbacks.h"
#include "GameClient/MapUtil.h"
@@ -231,14 +232,21 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
int player;
Bool canJoin = true;
- // see if the CRCs match
+ /* See if the CRCs match. EA wrote this check and then commented it out, so a LAN game
+ between two machines with different data started happily and desynced a few minutes in,
+ with nothing to tell either player why. It is back: the join request already carries
+ both CRCs, RET_CRC_MISMATCH already exists, and the string it maps to is already
+ translated. A dev build with -netMinPlayers still skips it, the way EA left it. */
#if defined(_DEBUG) || defined(_INTERNAL)
if (TheGlobalData->m_netMinPlayers > 0) {
#endif
-/* if (msg->GameToJoin.iniCRC != TheGlobalData->m_iniCRC ||
- msg->GameToJoin.exeCRC != TheGlobalData->m_exeCRC)
+ GameDataMatchResult dataMatch = compareGameData(
+ msg->GameToJoin.exeCRC, msg->GameToJoin.iniCRC,
+ TheGlobalData->m_exeCRC, TheGlobalData->m_iniCRC );
+ if (dataMatch != GAMEDATA_MATCHES)
{
- DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of CRC mismatch. CRCs are them/us INI:%X/%X exe:%X/%X\n",
+ DEBUG_LOG(("LANAPI::handleRequestJoin - join denied, %s. CRCs are them/us INI:%X/%X exe:%X/%X\n",
+ gameDataMatchName(dataMatch),
msg->GameToJoin.iniCRC, TheGlobalData->m_iniCRC,
msg->GameToJoin.exeCRC, TheGlobalData->m_exeCRC));
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
@@ -247,7 +255,6 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
reply.GameNotJoined.playerIP = senderIP;
canJoin = false;
}
-*/
#if defined(_DEBUG) || defined(_INTERNAL)
}
#endif
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 5140e4478..a43ed9429 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -29,6 +29,7 @@
#include "Common/StackDump.h"
#include "GameNetwork/Connection.h"
#include "GameLogic/CRCSnapshotRing.h"
+#include "GameNetwork/GameDataMatch.h"
#include "GameClient/Water.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "GameClient/ParticleSys.h"
@@ -2036,3 +2037,47 @@ TEST(crcsnapshotring_never_hands_back_a_half_written_frame)
ring.addObject( 1, 2, 0.0f, 0.0f, 0.0f, 0.0f );
CHECK_EQ( ring.getNumSnapshots(), 0 );
}
+
+/* --------------------------------------------------------------------------------------------
+ A lockstep game only stays in step if both machines feed the same numbers into it, and the
+ join request is the last moment at which that is a refused join instead of a desynced match.
+ EA wrote the LAN check and left it commented out; it is back, and this pins what it decides. */
+
+TEST(gamedatamatch_lets_identical_data_through_and_stops_everything_else)
+{
+ // same build, same INI set: the only case that may start a game
+ CHECK_EQ( compareGameData( 0xAABBCCDD, 0x11223344, 0xAABBCCDD, 0x11223344 ), GAMEDATA_MATCHES );
+
+ // a different INI set is the usual case, and the one a player can go and fix
+ CHECK_EQ( compareGameData( 0xAABBCCDD, 0x11223345, 0xAABBCCDD, 0x11223344 ), GAMEDATA_INI_DIFFERS );
+
+ // a different build reads the same INI files into different code
+ CHECK_EQ( compareGameData( 0xAABBCCDE, 0x11223344, 0xAABBCCDD, 0x11223344 ), GAMEDATA_EXE_DIFFERS );
+
+ // one bit is a mismatch: this is a data check, not a similarity score
+ CHECK_EQ( compareGameData( 0x11223344, 0x00000001, 0x11223344, 0x00000003 ), GAMEDATA_INI_DIFFERS );
+}
+
+TEST(gamedatamatch_blames_the_executable_when_both_differ)
+{
+ /* Both CRCs differ. Saying "different INI set" would send the player off to compare data
+ files that their build would read differently anyway. */
+ CHECK_EQ( compareGameData( 1, 2, 3, 4 ), GAMEDATA_EXE_DIFFERS );
+}
+
+TEST(gamedatamatch_refuses_a_machine_that_reports_no_data_at_all)
+{
+ /* Nothing computes zero - the executable CRC always folds in the version number and the INI
+ CRC always folds in megabytes of text. Zero means the other machine never checked. */
+ CHECK_EQ( compareGameData( 0, 0x11223344, 0xAABBCCDD, 0x11223344 ), GAMEDATA_UNKNOWN );
+ CHECK_EQ( compareGameData( 0xAABBCCDD, 0, 0xAABBCCDD, 0x11223344 ), GAMEDATA_UNKNOWN );
+
+ // and it outranks the CRCs that do match, rather than being reported as a plain match
+ CHECK_EQ( compareGameData( 0, 0, 0, 0 ), GAMEDATA_UNKNOWN );
+
+ // every result names itself for the log
+ CHECK_STR( gameDataMatchName( GAMEDATA_MATCHES ), "same data" );
+ CHECK_STR( gameDataMatchName( GAMEDATA_EXE_DIFFERS ), "different executable or multiplayer scripts" );
+ CHECK_STR( gameDataMatchName( GAMEDATA_INI_DIFFERS ), "different INI set" );
+ CHECK_STR( gameDataMatchName( GAMEDATA_UNKNOWN ), "data not reported" );
+}