summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorhemagx <hemagx2@gmail.com>2016-03-01 08:16:37 +0200
committerHaru <haru@dotalux.com>2016-07-12 20:58:44 +0200
commitd0358265beff02fd9c094ba480f1a9583035cf64 (patch)
tree6c8433dfda39ba19a721e66f70b0f11fce45eeeb /src/common
parentb0a4a441f582810c91aeec458fdbe7cc6cc78db9 (diff)
downloadhercules-d0358265beff02fd9c094ba480f1a9583035cf64.tar.gz
hercules-d0358265beff02fd9c094ba480f1a9583035cf64.tar.bz2
hercules-d0358265beff02fd9c094ba480f1a9583035cf64.tar.xz
hercules-d0358265beff02fd9c094ba480f1a9583035cf64.zip
Interface grfio.c
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/grfio.c23
-rw-r--r--src/common/grfio.h28
3 files changed, 39 insertions, 14 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 */