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
fix(gameengine): CRC every word of a flag set, not the first
Olcay Seygan6961dfde7526
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3838aacf6..4e0c6ac6a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -195,6 +195,14 @@ map. Ctrl+A is still everything at once.agreeing — all three had bugs that made one side quietly diverge from the other, and thefingerprint itself was checking the same number 128 times instead of the wall it was supposed tobe checking. Fixed. This is groundwork: network play is still not something this build claims.+- **The mismatch alarm can see all of a unit now.** Every so often each machine boils the whole+ world down to a single number and the machines compare notes; if two numbers differ the match+ stops and says so. That summary was being taken from the first thirty-two switches of each thing+ it looked at and no further. A unit that was immobilised, disguised, deployed or carrying a+ different rider on one screen and not on another added up to exactly the same number, and+ thirty-six of the game's sixty-eight special powers never counted at all. The summary covers the+ whole of it now. This does not stop two machines drifting apart; it stops them drifting apart+ quietly, and moves the report back to the frame it actually started on.- **A network game runs at the speed it says it does.** Playing against other people, thesimulation was gated by two separate clocks at once — the network's and the game's own — and adiff --git a/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h b/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.hindex 3557aab3e..f18792e78 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h@@ -216,8 +216,10 @@ void BitFlags<NUMBITS>::xfer(Xfer* xfer)else if( xfer->getXferMode() == XFER_CRC ){- // just call the xfer implementation on the data values- xfer->xferUser( this, sizeof( this ) );+ // just call the xfer implementation on the data values.+ // sizeof(this) is the size of the pointer - four bytes - so every flag word past the first+ // was outside the CRC. ObjectStatusMaskType alone carries fifteen bits past that boundary.+ xfer->xferUser( this, sizeof( *this ) );} // end else if, crcelsediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.hindex 8648231f7..61312e568 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h@@ -133,7 +133,7 @@ private: \return The##ARGCLASS##Pool; \} \protected: \- virtual int glueEnforcer() const { return sizeof(this); } \+ virtual void glueEnforcer() const { } \public: \inline void* operator new(size_t s) { return allocateFromW3DMemPool(getClassMemoryPool(), s); } \inline void operator delete(void *p) { freeFromW3DMemPool(getClassMemoryPool(), p); } \@@ -151,7 +151,7 @@ private:}protected:// we never call this; it is present to cause compile errors in descendent classes- virtual int glueEnforcer() const = 0;+ virtual void glueEnforcer() const = 0;public:virtual ~W3DMPO() { /* nothing */ }};diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 7c4c9619e..28974d77f 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -57,6 +57,8 @@#include "GameLogic/PolygonTrigger.h"#include "Common/TunnelTracker.h"#include "Common/StateMachine.h"+#include "Common/XferCRC.h"+#include "Common/ObjectStatusTypes.h"#include <stdio.h>#include <string.h>@@ -3450,3 +3452,58 @@ TEST(gameslot_restores_the_pre_randomization_setup_on_a_restart)CHECK( !fixed.hasSavedOriginalSetup() );CHECK_EQ( fixed.getOriginalColor(), -1 );}++// The game's fingerprint over a BitFlags used to be taken with sizeof(this) - the size of the+// pointer - so only the first four bytes of any flag set were in it. ObjectStatusMaskType is 47+// bits wide, so everything from RIDER1 upwards could differ between two machines without the CRC+// ever noticing.+static UnsignedInt crcOfStatusMask( ObjectStatusMaskType mask )+{+ XferCRC xfer;+ xfer.open( "test" );+ mask.xfer( &xfer );+ xfer.close();+ return xfer.getCRC();+}++TEST(bitflags_crc_covers_every_word_of_the_flag_set)+{+ ObjectStatusMaskType empty;+ empty.clear();++ // a bit inside the first word has always been covered+ ObjectStatusMaskType low;+ low.clear();+ low.set( OBJECT_STATUS_DESTROYED );+ CHECK_NE( crcOfStatusMask( low ), crcOfStatusMask( empty ) );++ // ...and so is everything past it now+ CHECK( (Int)OBJECT_STATUS_IMMOBILE >= 32 );+ ObjectStatusMaskType high;+ high.clear();+ high.set( OBJECT_STATUS_IMMOBILE );+ CHECK_NE( crcOfStatusMask( high ), crcOfStatusMask( empty ) );++ ObjectStatusMaskType deployed;+ deployed.clear();+ deployed.set( OBJECT_STATUS_DEPLOYED );+ CHECK_NE( crcOfStatusMask( deployed ), crcOfStatusMask( empty ) );++ // two different high bits are two different fingerprints, not one+ CHECK_NE( crcOfStatusMask( high ), crcOfStatusMask( deployed ) );++ // and the same mask still fingerprints the same way twice+ CHECK_EQ( crcOfStatusMask( high ), crcOfStatusMask( high ) );++ // the whole set is hashed, not a prefix of it: clearing a high bit off a full mask changes it+ ObjectStatusMaskType full, fullMinusOne;+ full.clear();+ fullMinusOne.clear();+ for( Int i = 0; i < (Int)OBJECT_STATUS_COUNT; ++i )+ {+ full.set( i );+ if( i != (Int)OBJECT_STATUS_DEPLOYED )+ fullMinusOne.set( i );+ }+ CHECK_NE( crcOfStatusMask( full ), crcOfStatusMask( fullMinusOne ) );+}