summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-07-06 19:36:18 +0000
committerflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-07-06 19:36:18 +0000
commit37377cfe2c7a46d23e44d0f67606c360008167b2 (patch)
treebd8ca3767ed8393f54f0a4e4999a080b3ccf608b
parent39bece2eb2c650540bec4c23801338f4fd7c7291 (diff)
downloadhercules-37377cfe2c7a46d23e44d0f67606c360008167b2.tar.gz
hercules-37377cfe2c7a46d23e44d0f67606c360008167b2.tar.bz2
hercules-37377cfe2c7a46d23e44d0f67606c360008167b2.tar.xz
hercules-37377cfe2c7a46d23e44d0f67606c360008167b2.zip
* Merged decode_zip/encode_zip from eapp's grfio to replace our direct use of zlib's uncompress/compress.
* Fixed strict-aliasing warning in mapcache's GetFloat. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14888 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt2
-rw-r--r--src/common/grfio.c75
-rw-r--r--src/common/grfio.h3
-rw-r--r--src/map/map.c2
-rw-r--r--src/tool/mapcache.c4
5 files changed, 80 insertions, 6 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 03f408b19..55b382539 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -2,6 +2,8 @@ Date Added
2011/07/06
* Changed grfio.c include order and moved zlib include from the header to the source. [FlavioJS]
+ * Merged decode_zip/encode_zip from eapp's grfio to replace our direct use of zlib's uncompress/compress.
+ * Fixed strict-aliasing warning in mapcache's GetFloat.
2011/07/05
* CMake: split txt and sql variants of login-server and map-server. [FlavioJS]
2011/07/04
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 7e8aa38d0..e31451af1 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -220,6 +220,75 @@ unsigned long grfio_crc32 (const unsigned char* buf, unsigned int len)
return crc32(crc32(0L, Z_NULL, 0), buf, len);
}
+
+///////////////////////////////////////////////////////////////////////////////
+/// Grf data sub : zip decode
+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 ((unsigned long)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;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// Grf data sub : zip encode
+int encode_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 = 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;
+}
+
+
/***********************************************************
*** File List Subroutines ***
***********************************************************/
@@ -430,9 +499,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;
- uncompress(buf2, &len, buf, entry->srclen);
+ decode_zip(buf2, &len, buf, entry->srclen);
if (len != (uLong)entry->declen) {
- ShowError("uncompress size mismatch err: %d != %d\n", (int)len, entry->declen);
+ ShowError("decode_zip size mismatch err: %d != %d\n", (int)len, entry->declen);
aFree(buf);
aFree(buf2);
return NULL;
@@ -579,7 +648,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);
- uncompress(grf_filelist, &eSize, rBuf, rSize); // Decode function
+ decode_zip(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 5d46771b9..d0baa6609 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -14,4 +14,7 @@ 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 b8edabfe6..bc9465781 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2727,7 +2727,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]
- uncompress(decode_buffer, &size, p+sizeof(struct map_cache_map_info), info->len);
+ decode_zip(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 deec27c4c..f1a7559f1 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -98,7 +98,7 @@ int32 GetLong(const unsigned char* buf)
float GetFloat(const unsigned char* buf)
{
uint32 val = GetULong(buf);
- return *((float*)&val);
+ return *((float*)(void*)&val);
}
@@ -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
- compress(write_buf, &len, m->cells, m->xs*m->ys);
+ encode_zip(write_buf, &len, m->cells, m->xs*m->ys);
// Fill the map header
strncpy(info.name, name, MAP_NAME_LENGTH);