Fix stupid zip decompression error.

This commit is contained in:
Shpoike 2023-07-07 12:10:53 +01:00
parent c52a165ca5
commit 49822069a3
3 changed files with 8 additions and 8 deletions

View file

@ -2095,7 +2095,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
if (f) if (f)
{ {
fseek (f, pak->files[i].filepos, SEEK_SET); fseek (f, pak->files[i].filepos, SEEK_SET);
f = FSZIP_Deflate(f, pak->files[i].deflatedsize, pak->files[i].filelen); f = FSZIP_Deflate(f, pak->files[i].deflatedsize, pak->files[i].filelen, pak->files[i].name);
if (f) if (f)
*handle = Sys_FileOpenStdio(f); *handle = Sys_FileOpenStdio(f);
else else
@ -2124,7 +2124,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
{ {
fseek (*file, pak->files[i].filepos, SEEK_SET); fseek (*file, pak->files[i].filepos, SEEK_SET);
if (pak->files[i].deflatedsize) if (pak->files[i].deflatedsize)
*file = FSZIP_Deflate(*file, pak->files[i].deflatedsize, pak->files[i].filelen); *file = FSZIP_Deflate(*file, pak->files[i].deflatedsize, pak->files[i].filelen, pak->files[i].name);
} }
return com_filesize; return com_filesize;
} }

View file

@ -352,7 +352,7 @@ const char *COM_GetGameNames(qboolean full);
qboolean COM_GameDirMatches(const char *tdirs); qboolean COM_GameDirMatches(const char *tdirs);
pack_t *FSZIP_LoadArchive (const char *packfile); pack_t *FSZIP_LoadArchive (const char *packfile);
FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize); FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize, const char *entryname);
void COM_WriteFile (const char *filename, const void *data, int len); void COM_WriteFile (const char *filename, const void *data, int len);
int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id); int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id);

View file

@ -744,7 +744,7 @@ pack_t *FSZIP_LoadArchive (const char *packfile)
return pack; return pack;
} }
FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize, const char *entryname)
{ {
#ifdef USE_ZLIB #ifdef USE_ZLIB
byte inbuffer[65536]; byte inbuffer[65536];
@ -773,6 +773,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize)
memset(&strm, 0, sizeof(strm)); memset(&strm, 0, sizeof(strm));
strm.data_type = Z_UNKNOWN; strm.data_type = Z_UNKNOWN;
strm.next_out = outbuffer;
inflateInit2(&strm, -MAX_WBITS); inflateInit2(&strm, -MAX_WBITS);
while ((ret=inflate(&strm, Z_SYNC_FLUSH)) != Z_STREAM_END) while ((ret=inflate(&strm, Z_SYNC_FLUSH)) != Z_STREAM_END)
{ {
@ -787,9 +788,8 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize)
} }
if (strm.avail_out == 0) if (strm.avail_out == 0)
{ {
fwrite(outbuffer, 1, strm.next_out - outbuffer, of);
strm.next_out = outbuffer; strm.next_out = outbuffer;
fwrite(outbuffer, 1, strm.total_out, of);
strm.total_out = 0;
strm.avail_out = sizeof(outbuffer); strm.avail_out = sizeof(outbuffer);
} }
continue; continue;
@ -801,7 +801,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize)
inflateEnd(&strm); inflateEnd(&strm);
fclose(src); fclose(src);
fclose(of); fclose(of);
Con_Printf("Couldn't decompress file, corrupt?\n"); Con_Printf("Couldn't decompress file \"%s\", corrupt?\n", entryname);
return NULL; return NULL;
} }
} }
@ -811,7 +811,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize)
if (strm.total_out != outsize) if (strm.total_out != outsize)
{ {
Con_Printf("Decompressed %u bytes, expected %u\n", (unsigned int)strm.total_out, (unsigned int)outsize); Con_Printf("%s: Decompressed %u bytes, expected %u\n", entryname, (unsigned int)strm.total_out, (unsigned int)outsize);
fclose(of); fclose(of);
return NULL; return NULL;
} }