#include "cmdlib.h" #define MAX_FILES 4096 #define MAX_DATA_PATH 512 char precache_files[MAX_FILES][MAX_DATA_PATH]; int precache_files_block[MAX_FILES]; int numfiles; typedef struct { char name[56]; int filepos, filelen; } packfile_t; typedef struct { char id[4]; int dirofs; int dirlen; } packheader_t; packfile_t pfiles[4096], *pf; FILE *packhandle; int packbytes; /* =========== PackFile Copy a file into the pak file =========== */ void PackFile (char *src, char *name) { FILE *in; int remaining, count; char buf[4096]; if ( (byte *)pf - (byte *)pfiles > sizeof(pfiles) ) Error ("Too many files in pak file"); in = SafeOpenRead (src); remaining = filelength (in); pf->filepos = LittleLong (ftell (packhandle)); pf->filelen = LittleLong (remaining); strcpy (pf->name, name); printf ("%64s : %7i\n", pf->name, remaining); packbytes += remaining; while (remaining) { if (remaining < sizeof(buf)) count = remaining; else count = sizeof(buf); SafeRead (in, buf, count); SafeWrite (packhandle, buf, count); remaining -= count; } fclose (in); pf++; } /* =========== CopyQFiles =========== */ void CopyQFiles (int blocknum) { int i, p; char srcfile[1024]; char destfile[1024]; char name[1024]; packheader_t header; int dirlen; unsigned short crc; // create a pak file pf = pfiles; sprintf (destfile, "%spak%i.pak", gamedir, blocknum); packhandle = SafeOpenWrite (destfile); SafeWrite (packhandle, &header, sizeof(header)); blocknum++; for (i=0 ; i : build a .pak file\n"); exit (1); } SetQdirFromPath (""); ReadFiles (); if (!strcmp (argv[1], "-pak")) { CopyQFiles (atoi(argv[2])); } else Error ("unknown command: %s", argv[1]); return 0; }