diff options
-rw-r--r-- | Changelog-Trunk.txt | 1 | ||||
-rw-r--r-- | src/common/grfio.c | 71 | ||||
-rw-r--r-- | src/common/grfio.h | 5 | ||||
-rw-r--r-- | src/map/map.c | 2 | ||||
-rw-r--r-- | src/tool/mapcache.c | 2 |
5 files changed, 8 insertions, 73 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 24abef588..b81de37a7 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -1,6 +1,7 @@ Date Added 2011/05/01 + * Removed functions 'decode_zip' (ancient) and 'encode_zip' (from r824) from grfio. These were outdated copies of zlib's 'uncompress' and 'compress' respectively (related r1530 and r5152). [Ai4rei] * Removed auto-add feature from mapindex code, as map indexes are used for save data, thus need to be constant across server starts (since r4726). [Ai4rei] 2011/04/28 * Fixed @makehomun not checking for existing homunculus properly and thus allowing to create a homunculus when one is already present but inactive (bugreport:4879, since r10272). [Ai4rei] diff --git a/src/common/grfio.c b/src/common/grfio.c index 3c0960f30..e7549ecb4 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -7,7 +7,6 @@ #include <sys/stat.h> #include "grfio.h" -#include <zlib.h> #include "../common/cbasetypes.h" #include "../common/showmsg.h" @@ -216,70 +215,6 @@ static void decode_des_etc(unsigned char* buf, size_t len, int type, int cycle) } } } -/*========================================== - * Grf data decode sub : zip - *------------------------------------------*/ -int decode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = (Bytef*) dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} - -int encode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) -{ - z_stream stream; - int err; - memset(&stream, 0, sizeof(stream)); - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = (Bytef*) dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = deflateInit(&stream,Z_DEFAULT_COMPRESSION); - if (err != Z_OK) return err; - - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = deflateEnd(&stream); - return err; -} unsigned long grfio_crc32 (const unsigned char* buf, unsigned int len) { @@ -496,9 +431,9 @@ void* grfio_reads(char* fname, int* size) if (entry->cycle >= 0) decode_des_etc(buf, entry->srclen_aligned, entry->cycle == 0, entry->cycle); len = entry->declen; - decode_zip(buf2, &len, buf, entry->srclen); + uncompress(buf2, &len, buf, entry->srclen); if (len != (uLong)entry->declen) { - ShowError("decode_zip size mismatch err: %d != %d\n", (int)len, entry->declen); + ShowError("uncompress size mismatch err: %d != %d\n", (int)len, entry->declen); aFree(buf); aFree(buf2); return NULL; @@ -645,7 +580,7 @@ static int grfio_entryread(char* grfname, int gentry) grf_filelist = (unsigned char *)aMallocA(eSize); // Get a Extend Size fread(rBuf,1,rSize,fp); fclose(fp); - decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function + uncompress(grf_filelist, &eSize, rBuf, rSize); // Decode function list_size = eSize; aFree(rBuf); diff --git a/src/common/grfio.h b/src/common/grfio.h index 57439b16d..d5334ccf3 100644 --- a/src/common/grfio.h +++ b/src/common/grfio.h @@ -4,6 +4,8 @@ #ifndef _GRFIO_H_ #define _GRFIO_H_ +#include <zlib.h> + void grfio_init(char*); // GRFIO Initialize void grfio_final(void); // GRFIO Finalize void* grfio_reads(char*,int*); // GRFIO data file read & size get @@ -14,7 +16,4 @@ char *grfio_find_file(char *fname); int grfio_size(char*); // GRFIO data file size get unsigned long grfio_crc32(const unsigned char *buf, unsigned int len); -int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen); -int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen); - #endif /* _GRFIO_H_ */ diff --git a/src/map/map.c b/src/map/map.c index 5ee01bc6d..12c805ef3 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2705,7 +2705,7 @@ int map_readfromcache(struct map_data *m, char *buffer, char *decode_buffer) } // TO-DO: Maybe handle the scenario, if the decoded buffer isn't the same size as expected? [Shinryo] - decode_zip(decode_buffer, &size, p+sizeof(struct map_cache_map_info), info->len); + uncompress(decode_buffer, &size, p+sizeof(struct map_cache_map_info), info->len); CREATE(m->cell, struct mapcell, size); diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c index f782331ca..deec27c4c 100644 --- a/src/tool/mapcache.c +++ b/src/tool/mapcache.c @@ -171,7 +171,7 @@ void cache_map(char *name, struct map_data *m) len = (unsigned long)m->xs*(unsigned long)m->ys*2; write_buf = (unsigned char *)aMalloc(len); // Compress the cells and get the compressed length - encode_zip(write_buf, &len, m->cells, m->xs*m->ys); + compress(write_buf, &len, m->cells, m->xs*m->ys); // Fill the map header strncpy(info.name, name, MAP_NAME_LENGTH); |