diff options
author | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2004-12-27 19:22:37 +0000 |
---|---|---|
committer | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2004-12-27 19:22:37 +0000 |
commit | 7737e73dd299e813ba03d227b6113df4d5b557df (patch) | |
tree | 35bff01363a0e250a446111995c45b851e0fa797 /src/common | |
parent | a51c01c18d3130d54dc3f032a22bbbf88ffdc8c1 (diff) | |
download | hercules-7737e73dd299e813ba03d227b6113df4d5b557df.tar.gz hercules-7737e73dd299e813ba03d227b6113df4d5b557df.tar.bz2 hercules-7737e73dd299e813ba03d227b6113df4d5b557df.tar.xz hercules-7737e73dd299e813ba03d227b6113df4d5b557df.zip |
* Updated map cache system from jA
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@824 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/grfio.c | 73 | ||||
-rw-r--r-- | src/common/grfio.h | 3 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/common/grfio.c b/src/common/grfio.c index ea5bba6ab..37cf2b9ee 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -33,6 +33,30 @@ #include "showmsg.h" #include "malloc.h" +#ifdef _WIN32 + #include <windows.h> + #include "zlib_win32.h" + HINSTANCE zlib_dll; + #define zlib_inflateInit(strm) zlib_inflateInit_((strm),ZLIB_VERSION, sizeof(z_stream)) + #define zlib_deflateInit(strm, level) zlib_deflateInit_((strm),(level),ZLIB_VERSION,sizeof(z_stream)) + + int (WINAPI* zlib_inflateInit_) (z_streamp strm, const char *version, int stream_size); + int (WINAPI* zlib_inflate) (z_streamp strm, int flush); + int (WINAPI* zlib_inflateEnd) (z_streamp strm); + + int (WINAPI* zlib_deflateInit_) (z_streamp strm, int level, const char *version, int stream_size); + int (WINAPI* zlib_deflate) (z_streamp strm, int flush); + int (WINAPI* zlib_deflateEnd) (z_streamp strm); +#else + #include <zlib.h> + #define zlib_inflateInit inflateInit + #define zlib_inflate inflate + #define zlib_inflateEnd inflateEnd + #define zlib_deflateInit deflateInit + #define zlib_deflate deflate + #define zlib_deflateEnd deflateEnd +#endif + #ifdef MEMWATCH #include "memwatch.h" #endif @@ -260,7 +284,7 @@ static void decode_des_etc(BYTE *buf,int len,int type,int cycle) * Grf data decode sub : zip *------------------------------------------ */ -static int decode_zip(Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLen) +int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen) { z_stream stream; int err; @@ -290,6 +314,37 @@ static int decode_zip(Bytef* dest, uLongf* destLen, const Bytef* source, uLong s err = inflateEnd(&stream); return err; } + +int encode_zip(char *dest, unsigned long* destLen, const 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 = 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 = zlib_deflateInit(&stream,Z_DEFAULT_COMPRESSION); + if (err != Z_OK) return err; + + err = zlib_deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + zlib_inflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = zlib_deflateEnd(&stream); + return err; +} + /*********************************************************** *** File List Sobroutines *** ***********************************************************/ @@ -924,6 +979,22 @@ void grfio_init(char *fname) char line[1024], w1[1024], w2[1024]; int result = 0, result2 = 0, result3 = 0, result4 = 0; +#ifdef _WIN32 + if(!zlib_dll) { + zlib_dll = LoadLibrary("zlib.dll"); + (FARPROC)zlib_inflateInit_ = GetProcAddress(zlib_dll,"inflateInit_"); + (FARPROC)zlib_inflate = GetProcAddress(zlib_dll,"inflate"); + (FARPROC)zlib_inflateEnd = GetProcAddress(zlib_dll,"inflateEnd"); + (FARPROC)zlib_deflateInit_ = GetProcAddress(zlib_dll,"deflateInit_"); + (FARPROC)zlib_deflate = GetProcAddress(zlib_dll,"deflate"); + (FARPROC)zlib_deflateEnd = GetProcAddress(zlib_dll,"deflateEnd"); + if(zlib_dll == NULL) { + MessageBox(NULL,"Can't load zlib.dll","grfio.c",MB_OK); + exit(1); + } + } +#endif + data_conf = fopen(fname, "r"); // It will read, if there is grf-files.txt. diff --git a/src/common/grfio.h b/src/common/grfio.h index 53b9da8d4..f39e9af1b 100644 --- a/src/common/grfio.h +++ b/src/common/grfio.h @@ -8,6 +8,9 @@ void* grfio_read(char*); // GRFIO data file read void* grfio_reads(char*,int*); // GRFIO data file read & size get int grfio_size(char*); // GRFIO data file size get +int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen); +int encode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen); + // Accessor to GRF filenames char *grfio_setdatafile(const char *str); char *grfio_setadatafile(const char *str); |