- loadsize = len;
-
-// extract the filename base name for hunk tag
- COM_FileBase (path, base);
-
- buf = Mem_Alloc(tempmempool, len+1);
- if (!buf)
- Sys_Error ("COM_LoadFile: not enough available memory for %s (size %i)", path, len);
-
- ((qbyte *)buf)[len] = 0;
-
- Qread (h, buf, len);
- Qclose (h);
-
- return buf;
-}
-
-/*
-=================
-COM_LoadPackFile
-
-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 *COM_LoadPackFile (char *packfile)
-{
- dpackheader_t header;
- int i;
- int numpackfiles;
- pack_t *pack;
- int packhandle;
- // LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
- dpackfile_t *info;
-
- if (Sys_FileOpenRead (packfile, &packhandle) == -1)
- return NULL;
-
- Sys_FileRead (packhandle, (void *)&header, sizeof(header));
- if (memcmp(header.id, "PACK", 4))
- Sys_Error ("%s is not a packfile", packfile);
- header.dirofs = LittleLong (header.dirofs);
- header.dirlen = LittleLong (header.dirlen);
-
- if (header.dirlen % sizeof(dpackfile_t))
- Sys_Error ("%s has an invalid directory size", packfile);
-
- numpackfiles = header.dirlen / sizeof(dpackfile_t);
-
- if (numpackfiles > MAX_FILES_IN_PACK)
- Sys_Error ("%s has %i files", packfile, numpackfiles);
-
- pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
- strcpy (pack->filename, packfile);
- pack->handle = packhandle;
- pack->numfiles = numpackfiles;
- pack->mempool = Mem_AllocPool(packfile);
- pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
- pack->next = packlist;
- packlist = pack;
-
- info = Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
- Sys_FileSeek (packhandle, header.dirofs);
- Sys_FileRead (packhandle, (void *)info, header.dirlen);
-
-// parse the directory
- for (i = 0;i < numpackfiles;i++)