diff options
Diffstat (limited to 'mpq-file.c')
-rw-r--r-- | mpq-file.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -1,5 +1,6 @@ #include <stdlib.h> #include <memory.h> +#include <zlib.h> #include "mpq-bios.h" #include "mpq-file.h" #include "mpq-errors.h" @@ -142,8 +143,29 @@ static int cache_sector(struct mpq_file_t * mpq_f, int sector) { mpq_f->current_sector = sector; il = ol = sector == (mpq_f->number_of_sectors - 1) ? mpq_f->remaining_bytes : mpq_f->sector_size; - - r = __mpqlib_multi_decompress(mpq_f->buffer, &ol, in_buf, mpq_f->sizes[sector]); + + if (ol == mpq_f->sizes[sector]) { + memcpy(mpq_f->buffer, in_buf, ol); + } else { + char * cursor = in_buf; + r = 0; + if ((*cursor++) == 2) { + z_stream z; + z.next_in = (Bytef *) cursor; + z.avail_in = mpq_f->sizes[sector]; + z.total_in = mpq_f->sizes[sector]; + z.next_out = (Bytef *) mpq_f->buffer; + z.avail_out = ol; + z.total_out = 0; + z.zalloc = NULL; + z.zfree = NULL; + if (inflateInit(&z) == 0) { + r = inflate(&z, Z_FINISH) == 0 ? 1 : 0; + ol = z.total_out; + inflateEnd(&z); + } + } + } if (il != ol) r = 0; |