file system start-up will now verify the presence and integrity of baseq3/pak0-8.pk3

This commit is contained in:
myT 2017-03-07 22:56:53 +01:00
parent 82994d21f8
commit e567ed84d0

View file

@ -170,11 +170,6 @@ or configs will never get loaded from disk!
*/ */
// every time a new demo pk3 file is built, this checksum must be updated.
// the easiest way to get it is to just run the game and see what it spits out
#define DEMO_PAK0_CHECKSUM 2985612116u
#define PAK0_CHECKSUM 1566731103u
#define MAX_ZPATH 256 #define MAX_ZPATH 256
#define MAX_SEARCH_PATHS 4096 #define MAX_SEARCH_PATHS 4096
#define MAX_FILEHASH_SIZE 1024 #define MAX_FILEHASH_SIZE 1024
@ -2585,50 +2580,84 @@ static void FS_Startup( const char *gameName )
QSUBSYSTEM_INIT_DONE( "FileSystem" ); QSUBSYSTEM_INIT_DONE( "FileSystem" );
} }
#define DEFAULT_PAK_COUNT 9
static const int DefaultPakChecksums[DEFAULT_PAK_COUNT] = {
1566731103,
298122907,
412165236,
-1303471980,
1197932710,
-207895723,
-585902437,
908855077,
977125798
};
/* /*
=================== ===================
FS_CheckPak0 FS_CheckPaks
Checks that pak0.pk3 is present and its checksum is correct Checks that pak0.pk3 to pakN.pk3 are present and
their checksums correct, N being DEFAULT_PAK_COUNT
Note: If you're building a game that doesn't depend on the Note: If you're building a game that doesn't depend on the
Q3 media pak0.pk3, you'll want to remove this function Q3 media pak0-N.pk3, you'll want to remove this function
=================== ===================
*/ */
static void FS_CheckPak0() static void FS_CheckPaks()
{ {
searchpath_t *path; enum defaultPakStatus_t {
qbool foundPak0 = qfalse; DPS_FOUND = 1,
DPS_VALID = 2
};
for( path = fs_searchpaths; path; path = path->next ) { int status[DEFAULT_PAK_COUNT] = { 0 };
if( path->pack && int badChecksums[DEFAULT_PAK_COUNT] = { 0 };
!Q_stricmpn( path->pack->pakBasename, "pak0", MAX_OSPATH ) && int found = 0;
(!Q_stricmpn( path->pack->pakGamename, BASEGAME, MAX_OSPATH ) ||
!Q_stricmpn( path->pack->pakGamename, "demoq3", MAX_OSPATH ))) {
foundPak0 = qtrue;
if( path->pack->checksum == DEMO_PAK0_CHECKSUM ) { for( searchpath_t* path = fs_searchpaths; path; path = path->next ) {
Com_Printf( "\n\n" for ( int i = 0; i < DEFAULT_PAK_COUNT; ++i ) {
"**************************************************\n" if ( status[i] & DPS_FOUND )
"WARNING: It looks like you're using pak0.pk3\n" continue;
"from the demo. This may work fine, but it is not\n"
"guaranteed or supported.\n" if ( path->pack &&
"**************************************************\n\n\n" ); !Q_stricmpn(path->pack->pakBasename, va("pak%d", i), MAX_OSPATH) &&
} else if( path->pack->checksum != PAK0_CHECKSUM ) { !Q_stricmpn(path->pack->pakGamename, BASEGAME, MAX_OSPATH) ) {
Com_Printf( "\n\n" ++found;
"**************************************************\n" status[i] |= DPS_FOUND;
"WARNING: pak0.pk3 is present but its checksum (%u)\n" if ( path->pack->checksum == DefaultPakChecksums[i] )
"is not correct. Please re-copy pak0.pk3 from your\n" status[i] |= DPS_VALID;
"legitimate Q3 CDROM.\n" else
"**************************************************\n\n\n", badChecksums[i] = path->pack->checksum;
path->pack->checksum );
} }
} }
if ( found == DEFAULT_PAK_COUNT )
break;
} }
if( !foundPak0 ) { if ( found < DEFAULT_PAK_COUNT ) {
Com_Error( ERR_FATAL, "Couldn't find pak0.pk3. Check that your Q3\n" int firstMissing = 0;
"executable is in the correct place and that every file\n" for ( int i = 0; i < DEFAULT_PAK_COUNT; ++i ) {
"in the %s directory is present and readable.", BASEGAME); if ( !(status[i] & DPS_FOUND) ) {
firstMissing = i;
break;
}
}
Com_Error( ERR_FATAL, "pak%d.pk3 is missing or unreadable! Check that CNQ3 is in the correct place "
"and that every file in the %s directory is present and readable.", firstMissing, BASEGAME );
return;
}
for ( int i = 0; i < DEFAULT_PAK_COUNT; ++i ) {
if ( !(status[i] & DPS_VALID) ) {
Com_Error( ERR_FATAL, "pak%d.pk3 is corrupt! Please re-copy pak%d.pk3 "
"from your legitimate Q3 CD-ROM. Got checksum %X, expected %X.",
i, i, (unsigned int)badChecksums[i], (unsigned int)DefaultPakChecksums[i] );
return;
}
} }
} }
@ -2963,7 +2992,7 @@ void FS_InitFilesystem()
// try to start up normally // try to start up normally
FS_Startup( BASEGAME ); FS_Startup( BASEGAME );
FS_CheckPak0(); FS_CheckPaks();
// if we can't find default.cfg, assume that the paths are busted // if we can't find default.cfg, assume that the paths are busted
// and error out now, rather than getting an unreadable // and error out now, rather than getting an unreadable
@ -2995,7 +3024,7 @@ void FS_Restart( int checksumFeed ) {
// try to start up normally // try to start up normally
FS_Startup( BASEGAME ); FS_Startup( BASEGAME );
FS_CheckPak0(); FS_CheckPaks();
// if we can't find default.cfg, assume that the paths are // if we can't find default.cfg, assume that the paths are
// busted and error out now, rather than getting an unreadable // busted and error out now, rather than getting an unreadable