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): clamp the crc interval to 1..100

Olcay Seygan927152ed36f9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 042ea0b2d..7c36a1f67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -816,6 +816,7 @@ found and fixed, EA's own, not port damage.**
- A shell's flight path is worked out the same way on every machine. The game borrowed that sum from a DirectX library that, going by its code, picks how to do it by processor: one way on Intel chips, another on everyone else's. The two answers differ in the last digits, and when both were run over half a million calculations shaped like the game's own shell paths, nearly half came out slightly different. That is enough for two machines to disagree about where a shell is. Nobody has reported it in a match, but every machine now uses the same sum whatever its processor. A replay recorded on an Intel machine with an earlier version may not play back exactly.
- A unit that was waiting for its route when you saved moves again after the load. The queue of route requests is not in the save, so it came back waiting for an answer nobody was going to give and stood there for the rest of the match.
- Every player's bank and the map script's counters, timers and flags are part of the check machines compare each step, so a match that starts to disagree is caught the moment it does, before the difference reaches a unit.
+- A room or a replay that asks for that check every 0 steps no longer crashes everyone who joins or watches it, and a host started with `-NetCRCInterval 0` no longer crashes itself. The interval is held between 1 and 100 now, so a host given a number outside that checks at the same rate as the players who join.
## Sharper textures, for free
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h
index f5af22ba9..6f07c21a9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h
@@ -273,7 +273,8 @@ public:
virtual void closeOpenSlots(void); ///< close all slots that are currently unoccupied.
// CRC checking hack
- void setCRCInterval( Int val ) { m_crcInterval = (val<100)?val:100; }
+ // [1,100]: a lobby or replay string saying C=0 (or less) made GameLogic take m_frame % 0
+ void setCRCInterval( Int val ) { m_crcInterval = (val<1)?1:((val<100)?val:100); }
inline Int getCRCInterval( void ) const { return m_crcInterval; }
Bool haveWeSurrendered(void) { return m_surrendered; }
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
index 0c934f734..442faa842 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
@@ -533,7 +533,7 @@ void GameInfo::init( void )
void GameInfo::reset( void )
{
- m_crcInterval = NET_CRC_INTERVAL;
+ setCRCInterval(NET_CRC_INTERVAL);
m_inGame = false;
m_inProgress = false;
m_gameID = 0;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index a7d96f07c..ca26cc834 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -7684,6 +7684,36 @@ TEST(bitflags_crc_covers_every_word_of_the_flag_set)
CHECK_NE( crcOfStatusMask( full ), crcOfStatusMask( fullMinusOne ) );
}
+// A lobby or replay string carrying C=0 used to reach GameLogic's m_frame % interval and crash.
+extern Int NET_CRC_INTERVAL;
+TEST(crc_interval_is_held_between_1_and_100)
+{
+ GlobalData *saved = TheWritableGlobalData;
+ TheWritableGlobalData = NEW GlobalData; // GameInfo::reset reads the default starting cash
+
+ SkirmishGameInfo game;
+ game.setCRCInterval( 0 );
+ CHECK_EQ( game.getCRCInterval(), 1 );
+ game.setCRCInterval( -7 );
+ CHECK_EQ( game.getCRCInterval(), 1 );
+ game.setCRCInterval( 1 );
+ CHECK_EQ( game.getCRCInterval(), 1 );
+ game.setCRCInterval( 37 );
+ CHECK_EQ( game.getCRCInterval(), 37 );
+ game.setCRCInterval( 5000 );
+ CHECK_EQ( game.getCRCInterval(), 100 );
+
+ // -NetCRCInterval writes NET_CRC_INTERVAL raw, and a host takes it through reset(), not the lobby string
+ Int savedInterval = NET_CRC_INTERVAL;
+ NET_CRC_INTERVAL = 0;
+ game.reset();
+ CHECK_EQ( game.getCRCInterval(), 1 );
+ NET_CRC_INTERVAL = savedInterval;
+
+ delete TheWritableGlobalData;
+ TheWritableGlobalData = saved;
+}
+
// ---------------------------------------------------------------------------------------------
// Network command ids are sixteen bits and wrap. NetCommandList insert-sorts by them, so the
// comparison has to survive the wrap or a player's own orders come out of order - and, because a