diff --git a/Generals/Code/GameEngine/Include/Common/GlobalData.h b/Generals/Code/GameEngine/Include/Common/GlobalData.h index 5cbd6975ef4..c0b8ef93ea9 100644 --- a/Generals/Code/GameEngine/Include/Common/GlobalData.h +++ b/Generals/Code/GameEngine/Include/Common/GlobalData.h @@ -74,7 +74,7 @@ class CommandLineData /** Global data container class * Defines all global game data used by the system * @todo Change this entire system. Otherwise this will end up a huge class containing tons of variables, - * and will cause re-compilation dependancies throughout the codebase. */ + * and will cause re-compilation dependencies throughout the code base. */ //------------------------------------------------------------------------------------------------- class GlobalData : public SubsystemInterface { @@ -536,6 +536,8 @@ class GlobalData : public SubsystemInterface private: + static UnsignedInt generateExeCRC(); + static const FieldParse s_GlobalDataFieldParseTable[]; // this is private, since we read the info from Windows and cache it for diff --git a/Generals/Code/GameEngine/Source/Common/GlobalData.cpp b/Generals/Code/GameEngine/Source/Common/GlobalData.cpp index 5f9e9cd2942..6bb08c3bd9a 100644 --- a/Generals/Code/GameEngine/Source/Common/GlobalData.cpp +++ b/Generals/Code/GameEngine/Source/Common/GlobalData.cpp @@ -987,73 +987,6 @@ GlobalData::GlobalData() m_iniCRC = 0; m_exeCRC = 0; - // lets CRC the executable! Whee! - const Int blockSize = 65536; - CRC exeCRC; - File *fp; - // TheSuperHackers @tweak SkyAero/xezon 27/05/2025 - // Simulate the EXE's CRC value to force Network and Replay compatibility with another build. -#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC - -#define GENERALS_108_CD_EXE_CRC 0x93d1eab4u -#define GENERALS_108_STEAM_EXE_CRC 0x8d6e4dd7u -#define GENERALS_108_EAAPP_EXE_CRC 0xb07fbd50u - - exeCRC.set(GENERALS_108_CD_EXE_CRC); - DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get())); - -#else - { - Char buffer[ _MAX_PATH ]; - GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get())); - fp->close(); - fp = NULL; - } - } -#endif - - UnsignedInt version = 0; - if (TheVersion) - { - version = TheVersion->getVersionNumber(); - exeCRC.computeCRC( &version, sizeof(UnsignedInt) ); - } - // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change - fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - fp->close(); - fp = NULL; - } - fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - fp->close(); - fp = NULL; - } - - m_exeCRC = exeCRC.get(); - DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, m_exeCRC)); - m_movementPenaltyDamageState = BODY_REALLYDAMAGED; m_shouldUpdateTGAToDDS = FALSE; @@ -1144,7 +1077,7 @@ GlobalData *GlobalData::newOverride( void ) //------------------------------------------------------------------------------------------------- void GlobalData::init( void ) { - // nothing + m_exeCRC = generateExeCRC(); } //------------------------------------------------------------------------------------------------- @@ -1256,3 +1189,79 @@ void GlobalData::parseGameDataDefinition( INI* ini ) TheWritableGlobalData->m_yResolution = yres; } + +UnsignedInt GlobalData::generateExeCRC() +{ + DEBUG_ASSERTCRASH(TheFileSystem != NULL, ("TheFileSystem is NULL")); + + // lets CRC the executable! Whee! + const Int blockSize = 65536; + CRC exeCRC; + File *fp; + // TheSuperHackers @tweak SkyAero/xezon 27/05/2025 + // Simulate the EXE's CRC value to force Network and Replay compatibility with another build. +#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC + +#define GENERALS_108_CD_EXE_CRC 0x93d1eab4u +#define GENERALS_108_STEAM_EXE_CRC 0x8d6e4dd7u +#define GENERALS_108_EAAPP_EXE_CRC 0xb07fbd50u + + exeCRC.set(GENERALS_108_CD_EXE_CRC); + DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get())); + +#else + { + Char buffer[ _MAX_PATH ]; + GetModuleFileName( NULL, buffer, sizeof( buffer ) ); + fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get())); + fp->close(); + fp = NULL; + } + else { + DEBUG_CRASH(("Executable file has failed to open")); + } + } +#endif + + UnsignedInt version = 0; + if (TheVersion) + { + version = TheVersion->getVersionNumber(); + exeCRC.computeCRC( &version, sizeof(UnsignedInt) ); + } + // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change + fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + fp->close(); + fp = NULL; + } + fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + fp->close(); + fp = NULL; + } + + DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, exeCRC.get())); + + return exeCRC.get(); +} diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h index c4e33a69620..0f5f15b5fc7 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h @@ -76,7 +76,7 @@ class CommandLineData /** Global data container class * Defines all global game data used by the system * @todo Change this entire system. Otherwise this will end up a huge class containing tons of variables, - * and will cause re-compilation dependancies throughout the codebase. + * and will cause re-compilation dependencies throughout the code base. * OOPS -- TOO LATE! :) */ //------------------------------------------------------------------------------------------------- class GlobalData : public SubsystemInterface @@ -553,6 +553,8 @@ class GlobalData : public SubsystemInterface private: + static UnsignedInt generateExeCRC(); + static const FieldParse s_GlobalDataFieldParseTable[]; // this is private, since we read the info from Windows and cache it for diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp index 11af51a8109..4ef49c0e36e 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp @@ -996,73 +996,6 @@ GlobalData::GlobalData() m_iniCRC = 0; m_exeCRC = 0; - // lets CRC the executable! Whee! - const Int blockSize = 65536; - CRC exeCRC; - File *fp; - // TheSuperHackers @tweak SkyAero/xezon 27/05/2025 - // Simulate the EXE's CRC value to force Network and Replay compatibility with another build. -#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC - -#define GENERALSMD_104_CD_EXE_CRC 0x3b6fb2cfu -#define GENERALSMD_104_STEAM_EXE_CRC 0xf6a4221bu -#define GENERALSMD_104_EAAPP_EXE_CRC 0xc4181eb9u - - exeCRC.set(GENERALSMD_104_CD_EXE_CRC); - DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get())); - -#else - { - Char buffer[ _MAX_PATH ]; - GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get())); - fp->close(); - fp = NULL; - } - } -#endif - - UnsignedInt version = 0; - if (TheVersion) - { - version = TheVersion->getVersionNumber(); - exeCRC.computeCRC( &version, sizeof(UnsignedInt) ); - } - // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change - fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - fp->close(); - fp = NULL; - } - fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY); - if (fp != NULL) { - unsigned char crcBlock[blockSize]; - Int amtRead = 0; - while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) - { - exeCRC.computeCRC(crcBlock, amtRead); - } - fp->close(); - fp = NULL; - } - - m_exeCRC = exeCRC.get(); - DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, m_exeCRC)); - m_movementPenaltyDamageState = BODY_REALLYDAMAGED; m_shouldUpdateTGAToDDS = FALSE; @@ -1182,7 +1115,7 @@ GlobalData *GlobalData::newOverride( void ) //------------------------------------------------------------------------------------------------- void GlobalData::init( void ) { - // nothing + m_exeCRC = generateExeCRC(); } //------------------------------------------------------------------------------------------------- @@ -1284,3 +1217,79 @@ void GlobalData::parseGameDataDefinition( INI* ini ) TheWritableGlobalData->m_yResolution = yres; } + +UnsignedInt GlobalData::generateExeCRC() +{ + DEBUG_ASSERTCRASH(TheFileSystem != NULL, ("TheFileSystem is NULL")); + + // lets CRC the executable! Whee! + const Int blockSize = 65536; + CRC exeCRC; + File *fp; + // TheSuperHackers @tweak SkyAero/xezon 27/05/2025 + // Simulate the EXE's CRC value to force Network and Replay compatibility with another build. +#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC + +#define GENERALSMD_104_CD_EXE_CRC 0x3b6fb2cfu +#define GENERALSMD_104_STEAM_EXE_CRC 0xf6a4221bu +#define GENERALSMD_104_EAAPP_EXE_CRC 0xc4181eb9u + + exeCRC.set(GENERALSMD_104_CD_EXE_CRC); + DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get())); + +#else + { + Char buffer[ _MAX_PATH ]; + GetModuleFileName( NULL, buffer, sizeof( buffer ) ); + fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get())); + fp->close(); + fp = NULL; + } + else { + DEBUG_CRASH(("Executable file has failed to open")); + } + } +#endif + + UnsignedInt version = 0; + if (TheVersion) + { + version = TheVersion->getVersionNumber(); + exeCRC.computeCRC( &version, sizeof(UnsignedInt) ); + } + // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change + fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + fp->close(); + fp = NULL; + } + fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY); + if (fp != NULL) { + unsigned char crcBlock[blockSize]; + Int amtRead = 0; + while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 ) + { + exeCRC.computeCRC(crcBlock, amtRead); + } + fp->close(); + fp = NULL; + } + + DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, exeCRC.get())); + + return exeCRC.get(); +}