- packfile = &search->pack->files[i];
-
- // If we don't have the true offset, get it now
- if (! (packfile->flags & FILE_FLAG_TRUEOFFS))
- PK3_GetTrueFileOffset (packfile, search->pack);
-
- // No Zlib DLL = no compressed files
- if (!zlib_dll && (packfile->flags & FILE_FLAG_DEFLATED))
- {
- Con_Printf("WARNING: can't open the compressed file %s\n"
- "You need the Zlib DLL to use compressed files\n",
- filename);
- fs_filesize = -1;
- return NULL;
- }
-
- // open a new file in the pakfile
- file = FS_OpenRead (search->pack->filename, packfile->offset, packfile->packsize);
- fs_filesize = packfile->realsize;
-
- if (packfile->flags & FILE_FLAG_DEFLATED)
- {
- ztoolkit_t *ztk;
-
- file->flags |= FS_FLAG_DEFLATED;
-
- // We need some more variables
- ztk = Mem_Alloc (fs_mempool, sizeof (*file->z));
-
- ztk->real_length = packfile->realsize;
-
- // Initialize zlib stream
- ztk->zstream.next_in = ztk->input;
- ztk->zstream.avail_in = 0;
-
- /* From Zlib's "unzip.c":
- *
- * windowBits is passed < 0 to tell that there is no zlib header.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END.
- * In unzip, i don't wait absolutely Z_STREAM_END because I known the
- * size of both compressed and uncompressed data
- */
- if (qz_inflateInit2 (&ztk->zstream, -MAX_WBITS) != Z_OK)
- Sys_Error ("inflate init error (file: %s)", filename);
-
- ztk->zstream.next_out = ztk->output;
- ztk->zstream.avail_out = sizeof (ztk->output);
-
- file->z = ztk;
- }
-
- return file;