- buf = NULL; // quiet compiler warning
- loadsize = 0;
-
-// look for it in the filesystem or pack files
- len = COM_FOpenFile (path, &h, quiet, true);
- if (!h)
- return NULL;
-
- 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++)
- {
- strcpy (pack->files[i].name, info[i].name);
- pack->files[i].filepos = LittleLong(info[i].filepos);
- pack->files[i].filelen = LittleLong(info[i].filelen);
- }
-
- Mem_Free(info);
-
- Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
- return pack;
-}
-
-
-/*
-================
-COM_AddGameDirectory
-
-Sets com_gamedir, adds the directory to the head of the path,
-then loads and adds pak1.pak pak2.pak ...
-================
-*/
-void COM_AddGameDirectory (char *dir)
-{
- stringlist_t *list, *current;
- searchpath_t *search;
- pack_t *pak;
- char pakfile[MAX_OSPATH];
-
- strcpy (com_gamedir, dir);
-
-//
-// add the directory to the search path
-//
- search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- strcpy (search->filename, dir);
- search->next = com_searchpaths;
- com_searchpaths = search;
-
- // add any paks in the directory
- list = listdirectory(dir);
- for (current = list;current;current = current->next)
- {
- if (matchpattern(current->text, "*.pak"))