Skip to content

Commit 1aa5077

Browse files
authored
[GEN][ZH] Fix untimely Exe CRC generation in GlobalData (#1197)
1 parent 7e18d29 commit 1aa5077

File tree

4 files changed

+160
-138
lines changed

4 files changed

+160
-138
lines changed

Generals/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class CommandLineData
7474
/** Global data container class
7575
* Defines all global game data used by the system
7676
* @todo Change this entire system. Otherwise this will end up a huge class containing tons of variables,
77-
* and will cause re-compilation dependancies throughout the codebase. */
77+
* and will cause re-compilation dependencies throughout the code base. */
7878
//-------------------------------------------------------------------------------------------------
7979
class GlobalData : public SubsystemInterface
8080
{
@@ -536,6 +536,8 @@ class GlobalData : public SubsystemInterface
536536

537537
private:
538538

539+
static UnsignedInt generateExeCRC();
540+
539541
static const FieldParse s_GlobalDataFieldParseTable[];
540542

541543
// this is private, since we read the info from Windows and cache it for

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -987,73 +987,6 @@ GlobalData::GlobalData()
987987
m_iniCRC = 0;
988988
m_exeCRC = 0;
989989

990-
// lets CRC the executable! Whee!
991-
const Int blockSize = 65536;
992-
CRC exeCRC;
993-
File *fp;
994-
// TheSuperHackers @tweak SkyAero/xezon 27/05/2025
995-
// Simulate the EXE's CRC value to force Network and Replay compatibility with another build.
996-
#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC
997-
998-
#define GENERALS_108_CD_EXE_CRC 0x93d1eab4u
999-
#define GENERALS_108_STEAM_EXE_CRC 0x8d6e4dd7u
1000-
#define GENERALS_108_EAAPP_EXE_CRC 0xb07fbd50u
1001-
1002-
exeCRC.set(GENERALS_108_CD_EXE_CRC);
1003-
DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get()));
1004-
1005-
#else
1006-
{
1007-
Char buffer[ _MAX_PATH ];
1008-
GetModuleFileName( NULL, buffer, sizeof( buffer ) );
1009-
fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY);
1010-
if (fp != NULL) {
1011-
unsigned char crcBlock[blockSize];
1012-
Int amtRead = 0;
1013-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1014-
{
1015-
exeCRC.computeCRC(crcBlock, amtRead);
1016-
}
1017-
DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get()));
1018-
fp->close();
1019-
fp = NULL;
1020-
}
1021-
}
1022-
#endif
1023-
1024-
UnsignedInt version = 0;
1025-
if (TheVersion)
1026-
{
1027-
version = TheVersion->getVersionNumber();
1028-
exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
1029-
}
1030-
// Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
1031-
fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY);
1032-
if (fp != NULL) {
1033-
unsigned char crcBlock[blockSize];
1034-
Int amtRead = 0;
1035-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1036-
{
1037-
exeCRC.computeCRC(crcBlock, amtRead);
1038-
}
1039-
fp->close();
1040-
fp = NULL;
1041-
}
1042-
fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY);
1043-
if (fp != NULL) {
1044-
unsigned char crcBlock[blockSize];
1045-
Int amtRead = 0;
1046-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1047-
{
1048-
exeCRC.computeCRC(crcBlock, amtRead);
1049-
}
1050-
fp->close();
1051-
fp = NULL;
1052-
}
1053-
1054-
m_exeCRC = exeCRC.get();
1055-
DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, m_exeCRC));
1056-
1057990
m_movementPenaltyDamageState = BODY_REALLYDAMAGED;
1058991

1059992
m_shouldUpdateTGAToDDS = FALSE;
@@ -1144,7 +1077,7 @@ GlobalData *GlobalData::newOverride( void )
11441077
//-------------------------------------------------------------------------------------------------
11451078
void GlobalData::init( void )
11461079
{
1147-
// nothing
1080+
m_exeCRC = generateExeCRC();
11481081
}
11491082

11501083
//-------------------------------------------------------------------------------------------------
@@ -1256,3 +1189,79 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12561189
TheWritableGlobalData->m_yResolution = yres;
12571190
}
12581191

1192+
1193+
UnsignedInt GlobalData::generateExeCRC()
1194+
{
1195+
DEBUG_ASSERTCRASH(TheFileSystem != NULL, ("TheFileSystem is NULL"));
1196+
1197+
// lets CRC the executable! Whee!
1198+
const Int blockSize = 65536;
1199+
CRC exeCRC;
1200+
File *fp;
1201+
// TheSuperHackers @tweak SkyAero/xezon 27/05/2025
1202+
// Simulate the EXE's CRC value to force Network and Replay compatibility with another build.
1203+
#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC
1204+
1205+
#define GENERALS_108_CD_EXE_CRC 0x93d1eab4u
1206+
#define GENERALS_108_STEAM_EXE_CRC 0x8d6e4dd7u
1207+
#define GENERALS_108_EAAPP_EXE_CRC 0xb07fbd50u
1208+
1209+
exeCRC.set(GENERALS_108_CD_EXE_CRC);
1210+
DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get()));
1211+
1212+
#else
1213+
{
1214+
Char buffer[ _MAX_PATH ];
1215+
GetModuleFileName( NULL, buffer, sizeof( buffer ) );
1216+
fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY);
1217+
if (fp != NULL) {
1218+
unsigned char crcBlock[blockSize];
1219+
Int amtRead = 0;
1220+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1221+
{
1222+
exeCRC.computeCRC(crcBlock, amtRead);
1223+
}
1224+
DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get()));
1225+
fp->close();
1226+
fp = NULL;
1227+
}
1228+
else {
1229+
DEBUG_CRASH(("Executable file has failed to open"));
1230+
}
1231+
}
1232+
#endif
1233+
1234+
UnsignedInt version = 0;
1235+
if (TheVersion)
1236+
{
1237+
version = TheVersion->getVersionNumber();
1238+
exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
1239+
}
1240+
// Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
1241+
fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY);
1242+
if (fp != NULL) {
1243+
unsigned char crcBlock[blockSize];
1244+
Int amtRead = 0;
1245+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1246+
{
1247+
exeCRC.computeCRC(crcBlock, amtRead);
1248+
}
1249+
fp->close();
1250+
fp = NULL;
1251+
}
1252+
fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY);
1253+
if (fp != NULL) {
1254+
unsigned char crcBlock[blockSize];
1255+
Int amtRead = 0;
1256+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1257+
{
1258+
exeCRC.computeCRC(crcBlock, amtRead);
1259+
}
1260+
fp->close();
1261+
fp = NULL;
1262+
}
1263+
1264+
DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, exeCRC.get()));
1265+
1266+
return exeCRC.get();
1267+
}

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CommandLineData
7676
/** Global data container class
7777
* Defines all global game data used by the system
7878
* @todo Change this entire system. Otherwise this will end up a huge class containing tons of variables,
79-
* and will cause re-compilation dependancies throughout the codebase.
79+
* and will cause re-compilation dependencies throughout the code base.
8080
* OOPS -- TOO LATE! :) */
8181
//-------------------------------------------------------------------------------------------------
8282
class GlobalData : public SubsystemInterface
@@ -553,6 +553,8 @@ class GlobalData : public SubsystemInterface
553553

554554
private:
555555

556+
static UnsignedInt generateExeCRC();
557+
556558
static const FieldParse s_GlobalDataFieldParseTable[];
557559

558560
// this is private, since we read the info from Windows and cache it for

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -996,73 +996,6 @@ GlobalData::GlobalData()
996996
m_iniCRC = 0;
997997
m_exeCRC = 0;
998998

999-
// lets CRC the executable! Whee!
1000-
const Int blockSize = 65536;
1001-
CRC exeCRC;
1002-
File *fp;
1003-
// TheSuperHackers @tweak SkyAero/xezon 27/05/2025
1004-
// Simulate the EXE's CRC value to force Network and Replay compatibility with another build.
1005-
#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC
1006-
1007-
#define GENERALSMD_104_CD_EXE_CRC 0x3b6fb2cfu
1008-
#define GENERALSMD_104_STEAM_EXE_CRC 0xf6a4221bu
1009-
#define GENERALSMD_104_EAAPP_EXE_CRC 0xc4181eb9u
1010-
1011-
exeCRC.set(GENERALSMD_104_CD_EXE_CRC);
1012-
DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get()));
1013-
1014-
#else
1015-
{
1016-
Char buffer[ _MAX_PATH ];
1017-
GetModuleFileName( NULL, buffer, sizeof( buffer ) );
1018-
fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY);
1019-
if (fp != NULL) {
1020-
unsigned char crcBlock[blockSize];
1021-
Int amtRead = 0;
1022-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1023-
{
1024-
exeCRC.computeCRC(crcBlock, amtRead);
1025-
}
1026-
DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get()));
1027-
fp->close();
1028-
fp = NULL;
1029-
}
1030-
}
1031-
#endif
1032-
1033-
UnsignedInt version = 0;
1034-
if (TheVersion)
1035-
{
1036-
version = TheVersion->getVersionNumber();
1037-
exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
1038-
}
1039-
// Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
1040-
fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY);
1041-
if (fp != NULL) {
1042-
unsigned char crcBlock[blockSize];
1043-
Int amtRead = 0;
1044-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1045-
{
1046-
exeCRC.computeCRC(crcBlock, amtRead);
1047-
}
1048-
fp->close();
1049-
fp = NULL;
1050-
}
1051-
fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY);
1052-
if (fp != NULL) {
1053-
unsigned char crcBlock[blockSize];
1054-
Int amtRead = 0;
1055-
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1056-
{
1057-
exeCRC.computeCRC(crcBlock, amtRead);
1058-
}
1059-
fp->close();
1060-
fp = NULL;
1061-
}
1062-
1063-
m_exeCRC = exeCRC.get();
1064-
DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, m_exeCRC));
1065-
1066999
m_movementPenaltyDamageState = BODY_REALLYDAMAGED;
10671000

10681001
m_shouldUpdateTGAToDDS = FALSE;
@@ -1182,7 +1115,7 @@ GlobalData *GlobalData::newOverride( void )
11821115
//-------------------------------------------------------------------------------------------------
11831116
void GlobalData::init( void )
11841117
{
1185-
// nothing
1118+
m_exeCRC = generateExeCRC();
11861119
}
11871120

11881121
//-------------------------------------------------------------------------------------------------
@@ -1284,3 +1217,79 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12841217
TheWritableGlobalData->m_yResolution = yres;
12851218
}
12861219

1220+
1221+
UnsignedInt GlobalData::generateExeCRC()
1222+
{
1223+
DEBUG_ASSERTCRASH(TheFileSystem != NULL, ("TheFileSystem is NULL"));
1224+
1225+
// lets CRC the executable! Whee!
1226+
const Int blockSize = 65536;
1227+
CRC exeCRC;
1228+
File *fp;
1229+
// TheSuperHackers @tweak SkyAero/xezon 27/05/2025
1230+
// Simulate the EXE's CRC value to force Network and Replay compatibility with another build.
1231+
#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC
1232+
1233+
#define GENERALSMD_104_CD_EXE_CRC 0x3b6fb2cfu
1234+
#define GENERALSMD_104_STEAM_EXE_CRC 0xf6a4221bu
1235+
#define GENERALSMD_104_EAAPP_EXE_CRC 0xc4181eb9u
1236+
1237+
exeCRC.set(GENERALSMD_104_CD_EXE_CRC);
1238+
DEBUG_LOG(("Fake EXE CRC is 0x%8.8X\n", exeCRC.get()));
1239+
1240+
#else
1241+
{
1242+
Char buffer[ _MAX_PATH ];
1243+
GetModuleFileName( NULL, buffer, sizeof( buffer ) );
1244+
fp = TheFileSystem->openFile(buffer, File::READ | File::BINARY);
1245+
if (fp != NULL) {
1246+
unsigned char crcBlock[blockSize];
1247+
Int amtRead = 0;
1248+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1249+
{
1250+
exeCRC.computeCRC(crcBlock, amtRead);
1251+
}
1252+
DEBUG_LOG(("EXE CRC is 0x%8.8X\n", exeCRC.get()));
1253+
fp->close();
1254+
fp = NULL;
1255+
}
1256+
else {
1257+
DEBUG_CRASH(("Executable file has failed to open"));
1258+
}
1259+
}
1260+
#endif
1261+
1262+
UnsignedInt version = 0;
1263+
if (TheVersion)
1264+
{
1265+
version = TheVersion->getVersionNumber();
1266+
exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
1267+
}
1268+
// Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
1269+
fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY);
1270+
if (fp != NULL) {
1271+
unsigned char crcBlock[blockSize];
1272+
Int amtRead = 0;
1273+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1274+
{
1275+
exeCRC.computeCRC(crcBlock, amtRead);
1276+
}
1277+
fp->close();
1278+
fp = NULL;
1279+
}
1280+
fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY);
1281+
if (fp != NULL) {
1282+
unsigned char crcBlock[blockSize];
1283+
Int amtRead = 0;
1284+
while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
1285+
{
1286+
exeCRC.computeCRC(crcBlock, amtRead);
1287+
}
1288+
fp->close();
1289+
fp = NULL;
1290+
}
1291+
1292+
DEBUG_LOG(("EXE+Version(%d.%d)+SCB CRC is 0x%8.8X\n", version >> 16, version & 0xffff, exeCRC.get()));
1293+
1294+
return exeCRC.get();
1295+
}

0 commit comments

Comments
 (0)