engine/EngineCommon.c
/*	johnfitz -- modified based on topaz's tutorial

	Takes an explicit (not game tree related) path to a pak file.

	Loads the header and directory, adding the files at the beginning
	of the list so they override previous pack files.
*/
- modified based on topaz's tutorial
Takes an explicit (not game tree related) path to a pak file.

Loads the header and directory, adding the files at the beginning
of the list so they override previous pack files.
- modified based on topaz ' s tutorial Takes an explicit ( not game tree related ) path to a pak file . Loads the header and directory adding the files at the beginning of the list so they override previous pack files .
pack_t *FileSystem_LoadPackage(char *packfile)
{
	dpackheader_t   header;
	int                             i;
	packfile_t              *newfiles;
	int                             numpackfiles;
	pack_t                  *pack;
	int                             packhandle;
	dpackfile_t             *info;
	unsigned short          crc;
	if (Sys_FileOpenRead (packfile, &packhandle) == -1)
		return NULL;
	Sys_FileRead (packhandle, (void *)&header, sizeof(header));
	if (header.id[0] != 'P' || header.id[1] != 'A' || header.id[2] != 'C' || header.id[3] != 'K')
		Sys_Error ("%s is not a packfile", packfile);
	header.dirofs = LittleLong (header.dirofs);
	header.dirlen = LittleLong (header.dirlen);
	numpackfiles = header.dirlen / sizeof(dpackfile_t);
	if (numpackfiles > MAX_FILES_IN_PACK)
		Sys_Error ("%s has %i files", packfile, numpackfiles);
	newfiles = (packfile_t*)calloc_or_die(numpackfiles, sizeof(packfile_t));
	info = (dpackfile_t*)malloc(MAX_FILES_IN_PACK);
	if (!info)
		Sys_Error("Failed to allocate array!\n");
	Sys_FileSeek (packhandle, header.dirofs);
	Sys_FileRead (packhandle, (void *)info, header.dirlen);
	CRC_Init (&crc);
	for (i = 0; i < header.dirlen ; i++)
		CRC_ProcessByte(&crc, ((uint8_t *)info)[i]);
	for (i = 0; i < numpackfiles ; i++)
	{
#ifdef _MSC_VER
#pragma warning(suppress: 6011)	// We checked this already!
#endif
		strcpy(newfiles[i].name, info[i].name);
		newfiles[i].filepos = LittleLong(info[i].filepos);
		newfiles[i].filelen = LittleLong(info[i].filelen);
	}
	pack = (pack_t*)malloc_or_die(sizeof(pack_t));
	strcpy(pack->filename, packfile);
	pack->handle = packhandle;
	pack->numfiles = numpackfiles;
	pack->files = newfiles;
	free(info);
	return pack;
}
pack_t * FileSystem_LoadPackage ( char * packfile ) { dpackheader_t header ; int i ; packfile_t * newfiles ; int numpackfiles ; pack_t * pack ; int packhandle ; dpackfile_t * info ; unsigned short crc ; if ( Sys_FileOpenRead ( packfile , & packhandle ) == -1 ) return NULL ; Sys_FileRead ( packhandle , ( void * ) & header , sizeof ( header ) ) ; if ( header . id [ 0 ] != ' ' || header . id [ 1 ] != ' ' || header . id [ 2 ] != ' ' || header . id [ 3 ] != ' ' ) Sys_Error ( " " , packfile ) ; header . dirofs = LittleLong ( header . dirofs ) ; header . dirlen = LittleLong ( header . dirlen ) ; numpackfiles = header . dirlen / sizeof ( dpackfile_t ) ; if ( numpackfiles > MAX_FILES_IN_PACK ) Sys_Error ( " " , packfile , numpackfiles ) ; newfiles = ( packfile_t * ) calloc_or_die ( numpackfiles , sizeof ( packfile_t ) ) ; info = ( dpackfile_t * ) malloc ( MAX_FILES_IN_PACK ) ; if ( ! info ) Sys_Error ( " \n " ) ; Sys_FileSeek ( packhandle , header . dirofs ) ; Sys_FileRead ( packhandle , ( void * ) info , header . dirlen ) ; CRC_Init ( & crc ) ; for ( i = 0 ; i < header . dirlen ; i ++ ) CRC_ProcessByte ( & crc , ( ( uint8_t * ) info ) [ i ] ) ; for ( i = 0 ; i < numpackfiles ; i ++ ) { #ifdef _MSC_VER #pragma  warning(suppress: 6011)	// We checked this already! #endif strcpy ( newfiles [ i ] . name , info [ i ] . name ) ; newfiles [ i ] . filepos = LittleLong ( info [ i ] . filepos ) ; newfiles [ i ] . filelen = LittleLong ( info [ i ] . filelen ) ; } pack = ( pack_t * ) malloc_or_die ( sizeof ( pack_t ) ) ; strcpy ( pack -> filename , packfile ) ; pack -> handle = packhandle ; pack -> numfiles = numpackfiles ; pack -> files = newfiles ; free ( info ) ; return pack ; }
johnfitz -- modified based on topaz's tutorial
Takes an explicit (not game tree related) path to a pak file.
johnfitz -- modified based on topaz ' s tutorial Takes an explicit ( not game tree related ) path to a pak file .
//johnfitz -- dynamic gamedir loading //johnfitz // crc the directory to check for modifications // parse the directory //johnfitz -- dynamic gamedir loading //johnfitz