summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/grfio.c23
-rw-r--r--src/common/grfio.h28
-rw-r--r--src/map/clif.c5
-rw-r--r--src/map/map.c18
-rw-r--r--src/plugins/HPMHooking.c1
-rw-r--r--src/tool/mapcache.c10
7 files changed, 57 insertions, 30 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 508a728f0..63123dfea 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -27,6 +27,7 @@
#include "common/console.h"
#include "common/db.h"
#include "common/des.h"
+#include "common/grfio.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
@@ -257,6 +258,7 @@ void core_defaults(void) {
showmsg_defaults();
cmdline_defaults();
des_defaults();
+ grfio_defaults(); // Note: grfio is lazily loaded. grfio->init() and grfio->final() are not automatically called.
#ifndef MINICORE
mutex_defaults();
libconfig_defaults();
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 7f860acc6..fdd599ae7 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -76,6 +76,9 @@ int gentry_maxentry = 0;
// the path to the data directory
char data_dir[1024] = "";
+struct grfio_interface grfio_s;
+struct grfio_interface *grfio;
+
// little endian char array to uint conversion
static unsigned int getlong(unsigned char* p)
{
@@ -472,7 +475,7 @@ void *grfio_reads(const char *fname, int *size)
uLongf len;
grf_decode(buf, fsize, entry->type, entry->srclen);
len = entry->declen;
- decode_zip(buf2, &len, buf, entry->srclen);
+ grfio->decode_zip(buf2, &len, buf, entry->srclen);
if (len != (uLong)entry->declen) {
ShowError("decode_zip size mismatch err: %d != %d\n", (int)len, entry->declen);
aFree(buf);
@@ -639,7 +642,7 @@ static int grfio_entryread(const char *grfname, int gentry)
}
fclose(fp);
grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size
- decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
+ grfio->decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
aFree(rBuf);
entrys = getlong(grf_header+0x26) - 7;
@@ -759,7 +762,7 @@ static void grfio_resourcecheck(void)
}
// read resnametable from loaded GRF's, only if it cannot be loaded from the data directory
- buf = (char *)grfio_reads("data\\resnametable.txt", &size);
+ buf = grfio->reads("data\\resnametable.txt", &size);
if( buf != NULL )
{
char *ptr;
@@ -871,3 +874,15 @@ void grfio_init(const char* fname)
// Resource check
grfio_resourcecheck();
}
+
+void grfio_defaults(void)
+{
+ grfio = &grfio_s;
+ grfio->init = grfio_init;
+ grfio->final = grfio_final;
+ grfio->reads = grfio_reads;
+ grfio->find_file = grfio_find_file;
+ grfio->crc32 = grfio_crc32;
+ grfio->decode_zip = decode_zip;
+ grfio->encode_zip = encode_zip;
+}
diff --git a/src/common/grfio.h b/src/common/grfio.h
index 36ed8fb39..72afad274 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -21,16 +21,24 @@
#ifndef COMMON_GRFIO_H
#define COMMON_GRFIO_H
-#ifdef HERCULES_CORE
-void grfio_init(const char* fname);
-void grfio_final(void);
-void* grfio_reads(const char* fname, int* size);
-char* grfio_find_file(const char* fname);
-#define grfio_read(fn) grfio_reads((fn), NULL)
+#include "common/hercules.h"
+
+struct grfio_interface {
+ void (*init) (const char *fname);
+ void (*final) (void);
+ void *(*reads) (const char *fname, int *size);
+ char *(*find_file) (const char *fname);
+
+ unsigned long (*crc32) (const unsigned char *buf, unsigned int len);
+ int (*decode_zip) (void *dest, unsigned long *destLen, const void *source, unsigned long sourceLen);
+ int (*encode_zip) (void *dest, unsigned long *destLen, const void *source, unsigned long sourceLen);
+};
-unsigned long grfio_crc32(const unsigned char *buf, unsigned int len);
-int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
-int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
+#define grfio_read(fn) grfio->reads((fn), NULL)
+
+#ifdef HERCULES_CORE
+void grfio_defaults(void);
#endif // HERCULES_CORE
+HPShared struct grfio_interface *grfio;
#endif /* COMMON_GRFIO_H */
diff --git a/src/map/clif.c b/src/map/clif.c
index 9619a7201..3069e95ad 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -12878,7 +12878,8 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
int header = 0, bitmap = 0, offbits = 0, palettesize = 0;
nullpo_retr(false, emblem);
- if( decode_zip(buf, &buf_len, emblem, emblem_len) != 0 || buf_len < BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE
+ if (grfio->decode_zip(buf, &buf_len, emblem, emblem_len) != 0
+ || buf_len < BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE
|| RBUFW(buf,0) != 0x4d42 // BITMAPFILEHEADER.bfType (signature)
|| RBUFL(buf,2) != buf_len // BITMAPFILEHEADER.bfSize (file size)
|| RBUFL(buf,14) != BITMAPINFOHEADER_SIZE // BITMAPINFOHEADER.biSize (other headers are not supported)
diff --git a/src/map/map.c b/src/map/map.c
index 30c849ed1..491f6fb59 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -2851,7 +2851,7 @@ void map_cellfromcache(struct map_data *m) {
size = (unsigned long)info->xs*(unsigned long)info->ys;
// TO-DO: Maybe handle the scenario, if the decoded buffer isn't the same size as expected? [Shinryo]
- decode_zip(decode_buffer, &size, m->cellPos+sizeof(struct map_cache_map_info), info->len);
+ grfio->decode_zip(decode_buffer, &size, m->cellPos+sizeof(struct map_cache_map_info), info->len);
CREATE(m->cell, struct mapcell, size);
// Set cell properties
@@ -3585,11 +3585,11 @@ int map_waterheight(char* mapname)
//Look up for the rsw
snprintf(fn, sizeof(fn), "data\\%s.rsw", mapname);
- if ( (found = grfio_find_file(fn)) )
+ if ((found = grfio->find_file(fn)))
safestrncpy(fn, found, sizeof(fn)); // replace with real name
// read & convert fn
- rsw = (char *) grfio_read (fn);
+ rsw = grfio_read(fn);
if (rsw) {
//Load water height from file
int wh = (int) *(float*)(rsw+166);
@@ -3613,7 +3613,7 @@ int map_readgat (struct map_data* m)
nullpo_ret(m);
sprintf(filename, "data\\%s.gat", m->name);
- gat = (uint8 *) grfio_read(filename);
+ gat = grfio_read(filename);
if (gat == NULL)
return 0;
@@ -5677,8 +5677,8 @@ int do_final(void) {
map->map_db->destroy(map->map_db, map->db_final);
mapindex->final();
- if(map->enable_grf)
- grfio_final();
+ if (map->enable_grf)
+ grfio->final();
db_destroy(map->id_db);
db_destroy(map->pc_db);
@@ -6122,8 +6122,8 @@ int do_init(int argc, char *argv[])
}
}
- if(map->enable_grf)
- grfio_init(map->GRF_PATH_FILENAME);
+ if (map->enable_grf)
+ grfio->init(map->GRF_PATH_FILENAME);
map->readallmaps();
diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c
index 97a36f4ce..0b98ea99f 100644
--- a/src/plugins/HPMHooking.c
+++ b/src/plugins/HPMHooking.c
@@ -97,6 +97,7 @@
#include "map/storage.h"
#include "map/trade.h"
#include "map/unit.h"
+#include "common/grfio.h"
#include "common/mapindex.h"
#else
#define HPM_SERVER_TYPE SERVER_TYPE_UNKNOWN
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index 41dfcf022..7bb2f4465 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -77,13 +77,13 @@ int read_map(char *name, struct map_data *m)
// Open map GAT
sprintf(filename,"data\\%s.gat", name);
- gat = (unsigned char *)grfio_read(filename);
+ gat = grfio_read(filename);
if (gat == NULL)
return 0;
// Open map RSW
sprintf(filename,"data\\%s.rsw", name);
- rsw = (unsigned char *)grfio_read(filename);
+ rsw = grfio_read(filename);
// Read water height
if (rsw) {
@@ -139,7 +139,7 @@ bool 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);
+ grfio->encode_zip(write_buf, &len, m->cells, m->xs*m->ys);
// Fill the map header
safestrncpy(info.name, name, MAP_NAME_LENGTH);
@@ -286,7 +286,7 @@ int do_init(int argc, char** argv)
cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
ShowStatus("Initializing grfio with %s\n", grf_list_file);
- grfio_init(grf_list_file);
+ grfio->init(grf_list_file);
// Attempt to open the map cache file and force rebuild if not found
ShowStatus("Opening map cache: %s\n", map_cache_file);
@@ -360,7 +360,7 @@ int do_init(int argc, char** argv)
fclose(map_cache_fp);
ShowStatus("Finalizing grfio\n");
- grfio_final();
+ grfio->final();
ShowInfo("%d maps now in cache\n", header.map_count);