summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-05-05 13:57:07 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-05-05 13:57:07 +0000
commit9dc87bf9db25237ae4d904f92311352e6171d372 (patch)
treefe58100dd34d6ee12120f5a2d165b84cdb5a3ab2 /src
parent0782cabc543c151f724f38f5132ab948f6346af4 (diff)
downloadhercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.gz
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.bz2
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.xz
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.zip
- imported the latest working grfio code from stable
- re-added usage of managed allocation routines in grfio - eol-styled some new files - some cosmetic fixes here and there git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10468 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/common/grfio.c457
-rw-r--r--src/common/grfio.h2
-rw-r--r--src/common/mapindex.c4
-rw-r--r--src/login_sql/login.c2
-rw-r--r--src/map/map.c19
-rw-r--r--src/map/map.h11
-rw-r--r--src/map/npc.c8
-rw-r--r--src/map/pc.c2
-rw-r--r--src/map/status.h48
-rw-r--r--src/map/trade.c2
-rw-r--r--src/tool/mapcache.c4
11 files changed, 212 insertions, 347 deletions
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 79978f3ac..314581abc 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -1,90 +1,61 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-/*********************************************************************
- *
- * Ragnarok Online Emulator : grfio.c -- grf file I/O Module
- *--------------------------------------------------------------------
- * special need library : zlib
- *********************************************************************
- * $Id: grfio.c,v 1.2 2004/09/29 17:31:49 kalaspuff Exp $
- *
- * 2002/12/18... the original edition
- * 2003/01/23 ... Code correction
- * 2003/02/01 ... An addition and decryption processing are improved for LocalFile and two or more GRF(s) check processing.
- * 2003/02/02 ... Even if there is no grf it does not stop -- as -- correction
- * 2003/02/02... grf reading specification can be added later -- as -- correction (grfio_add function addition)
- * 2003/02 / 03... at the time of grfio_resourcecheck processing the entry addition processing method -- correction
- * 2003/02/05... change of the processing in grfio_init
- * 2003/02/23... a local file check -- GRFIO_LOCAL -- switch (Defoe -- Function Off)
- * 2003/10/21 ... The data of alpha client was read.
- * 2003/11/10 ... Ready new grf format.
- * 2003/11/11 ... version check fix & bug fix
- * 2006/04/16 ... fixed crash grfio_find_file when file is not found.
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
+#include <sys/stat.h>
#include "grfio.h"
-#include <sys/stat.h>
#include <zlib.h>
-#include "../common/mmo.h"
+
+#include "../common/cbasetypes.h"
#include "../common/showmsg.h"
#include "../common/malloc.h"
-typedef unsigned char BYTE;
-typedef unsigned short WORD;
-typedef unsigned long DWORD;
-
-//static char data_file[1024] = ""; // "data.grf";
-//static char sdata_file[1024] = ""; // "sdata.grf";
-//static char adata_file[1024] = ""; // "adata.grf";
-static char data_dir[1024] = ""; // "../";
//----------------------------
// file entry table struct
//----------------------------
-typedef struct {
- int srclen; // compressed size
- int srclen_aligned; //
+typedef struct _FILELIST {
+ int srclen; // compressed size
+ int srclen_aligned;
int declen; // original size
- int srcpos;
- int next; //[blackhole89] - like there can be only 2^15 files
- int cycle;
+ int srcpos; // position of entry in grf
+ int next; // index of next filelist entry with same hash (-1: end of entry chain)
+ int cycle;
char type;
char fn[128-4*5]; // file name
- char *fnd;
- signed char gentry; // read grf file select
+ char* fnd; // if the file was cloned, contains name of original file
+ char gentry; // read grf file select
} FILELIST;
-//gentry ... 0 : It acquires from a local file.
-// It acquires from the resource file of 1>=:gentry_table[gentry-1].
-// 1<=: Check a local file.
-// If it is, after re-setting to 0, it acquires from a local file.
-// If there is nothing, mark reversal will be carried out, and it will re-set, and will acquire from a resource file as well as 1>=.
-
-//Since char defines *FILELIST.gentry, the maximum which can be added by grfio_add becomes by 127 pieces.
-#define GENTRY_LIMIT 512
-#define FILELIST_LIMIT 1048576 // temporary maximum, and a theory top maximum are 2G.
+//gentry ... > 0 : data read from a grf file (gentry_table[gentry-1])
+//gentry ... 0 : data read from a local file (data directory)
+//gentry ... < 0 : entry "-(gentry)" is marked for a local file check
+// - if local file exists, gentry will be set to 0 (thus using the local file)
+// - if local file doesn't exist, sign is inverted (thus using the original file inside a grf)
+// (NOTE: this case is only used once (during startup) and only if GRFIO_LOCAL is enabled)
+// (NOTE: probably meant to be used to override grf contents by files in the data directory)
+//#define GRFIO_LOCAL
-//[blackhole89]
-#define malloc_tsetdword(a,b,c) memset(a,b,c)
+// stores info about every loaded file
+FILELIST* filelist = NULL;
+int filelist_entrys = 0;
+int filelist_maxentry = 0;
-static FILELIST *filelist = NULL;
-static int filelist_entrys = 0;
-static int filelist_maxentry = 0;
+// stores grf file names
+char** gentry_table = NULL;
+int gentry_entrys = 0;
+int gentry_maxentry = 0;
-static char **gentry_table = NULL;
-static int gentry_entrys = 0;
-static int gentry_maxentry = 0;
+// the path to the data directory
+char data_dir[1024] = "";
//----------------------------
// file list hash table
//----------------------------
-static int filelist_hash[256];
+int filelist_hash[256];
//----------------------------
// grf decode data table
@@ -133,50 +104,41 @@ static unsigned char NibbleData[4][64]={
0xa0, 0x9f, 0xf6, 0x5c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb,
}
};
-/*-----------------
- * long data get
- */
-static unsigned int getlong(unsigned char *p)
+
+// little endian char array to uint conversion
+static unsigned int getlong(unsigned char* p)
{
-// return *p+p[1]*256+(p[2]+p[3]*256)*65536;
- return p[0]
- | p[1] << 0x08
- | p[2] << 0x10
- | p[3] << 0x18; // Shinomori
+ return (p[0] | p[1] << 0x08 | p[2] << 0x10 | p[3] << 0x18);
}
/*==========================================
* Grf data decode : Subs
- *------------------------------------------
- */
-static void NibbleSwap(BYTE *Src, int len)
+ *------------------------------------------*/
+static void NibbleSwap(unsigned char* Src, int len)
{
for(;0<len;len--,Src++) {
*Src = (*Src>>4) | (*Src<<4);
}
}
-static void BitConvert(BYTE *Src,char *BitSwapTable)
+static void BitConvert(unsigned char* Src, char* BitSwapTable)
{
int lop,prm;
- BYTE tmp[8];
-// *(DWORD*)tmp=*(DWORD*)(tmp+4)=0;
- malloc_tsetdword(tmp,0,8);
+ unsigned char tmp[8];
+ memset(tmp,0,8);
for(lop=0;lop!=64;lop++) {
prm = BitSwapTable[lop]-1;
if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) {
tmp[(lop >> 3) & 7] |= BitMaskTable[lop & 7];
}
}
-// *(DWORD*)Src = *(DWORD*)tmp;
-// *(DWORD*)(Src+4) = *(DWORD*)(tmp+4);
memcpy(Src,tmp,8);
}
-static void BitConvert4(BYTE *Src)
+static void BitConvert4(unsigned char* Src)
{
int lop,prm;
- BYTE tmp[8];
+ unsigned char tmp[8];
tmp[0] = ((Src[7]<<5) | (Src[4]>>3)) & 0x3f; // ..0 vutsr
tmp[1] = ((Src[4]<<1) | (Src[5]>>7)) & 0x3f; // ..srqpo n
tmp[2] = ((Src[4]<<5) | (Src[5]>>3)) & 0x3f; // ..o nmlkj
@@ -191,39 +153,38 @@ static void BitConvert4(BYTE *Src)
| (NibbleData[lop][tmp[lop*2+1]] & 0x0f);
}
- *(DWORD*)(tmp+4)=0;
+ memset(tmp+4,0,4);
for(lop=0;lop!=32;lop++) {
prm = BitSwapTable3[lop]-1;
if (tmp[prm >> 3] & BitMaskTable[prm & 7]) {
tmp[(lop >> 3) + 4] |= BitMaskTable[lop & 7];
}
}
-// *(DWORD*)Src ^= *(DWORD*)(tmp+4);
Src[0] ^= tmp[4];
Src[1] ^= tmp[5];
Src[2] ^= tmp[6];
Src[3] ^= tmp[7];
}
-static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
+static void decode_des_etc(unsigned char* buf, size_t len, int type, int cycle)
{
- int lop,cnt=0;
+ size_t lop,cnt=0;
if(cycle<3) cycle=3;
else if(cycle<5) cycle++;
else if(cycle<7) cycle+=9;
else cycle+=15;
- for(lop=0;lop*8<len;lop++,buf+=8) {
- if(lop<20 || (type==0 && lop%cycle==0)){ // des
+ for(lop=0; lop*8<len; lop++, buf+=8)
+ {
+ if(lop<20 || (type==0 && lop%cycle==0)) { // des
BitConvert(buf,BitSwapTable1);
BitConvert4(buf);
BitConvert(buf,BitSwapTable2);
} else {
- if(cnt==7 && type==0){
- int a;
- BYTE tmp[8];
- *(DWORD*)tmp = *(DWORD*)buf;
- *(DWORD*)(tmp+4) = *(DWORD*)(buf+4);
+ if(cnt==7 && type==0) {
+ unsigned char a;
+ unsigned char tmp[8];
+ memcpy(tmp,buf,8);
cnt=0;
buf[0]=tmp[3];
buf[1]=tmp[4];
@@ -255,9 +216,8 @@ static void decode_des_etc(BYTE *buf,int 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)
+ *------------------------------------------*/
+int decode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
{
z_stream stream;
int err;
@@ -288,7 +248,8 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
return err;
}
-int encode_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)
+{
z_stream stream;
int err;
memset(&stream, 0, sizeof(stream));
@@ -318,7 +279,7 @@ int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
return err;
}
-unsigned long grfio_crc32 (const unsigned char *buf, unsigned int len)
+unsigned long grfio_crc32 (const unsigned char* buf, unsigned int len)
{
return crc32(crc32(0L, Z_NULL, 0), buf, len);
}
@@ -327,80 +288,65 @@ unsigned long grfio_crc32 (const unsigned char *buf, unsigned int len)
*** File List Subroutines ***
***********************************************************/
-/*==========================================
- * File List : Hash make
- *------------------------------------------
- */
-static int filehash(unsigned char *fname)
+// initializes the table that holds the first elements of all hash chains
+static void hashinit(void)
+{
+ int i;
+ for (i = 0; i < 256; i++)
+ filelist_hash[i] = -1;
+}
+
+// hashes a filename string into a number from {0..255}
+static int filehash(char* fname)
{
- unsigned int hash=0;
+ unsigned int hash = 0;
while(*fname) {
- hash = ((hash<<1)+(hash>>7)*9+tolower(*fname));
+ hash = (hash<<1) + (hash>>7)*9 + TOLOWER(*fname);
fname++;
}
return hash & 255;
}
-/*==========================================
- * File List : Hash initalize
- *------------------------------------------
- */
-static void hashinit(void)
-{
- int lop;
- for (lop = 0; lop < 256; lop++)
- filelist_hash[lop] = -1;
-}
-
-/*==========================================
- * File List : File find
- *------------------------------------------
- */
-static FILELIST *filelist_find(char *fname)
+// finds a FILELIST entry with the specified file name
+static FILELIST* filelist_find(char* fname)
{
- int hash;
+ int hash, index;
if (!filelist)
return NULL;
- for (hash = filelist_hash[filehash((unsigned char *) fname)]; hash >= 0; hash = filelist[hash].next) {
- if(strcmpi(filelist[hash].fn, fname) == 0)
+ hash = filelist_hash[filehash(fname)];
+ for (index = hash; index != -1; index = filelist[index].next)
+ if(!strcmpi(filelist[index].fn, fname))
break;
- }
- return (hash >= 0) ? &filelist[hash] : NULL;
+ return (index >= 0) ? &filelist[index] : NULL;
}
-char *grfio_find_file(char *fname){
+// returns the original file name
+char* grfio_find_file(char* fname)
+{
FILELIST *filelist = filelist_find(fname);
if (!filelist) return NULL;
- return (!filelist->fnd?filelist->fn:filelist->fnd);
+ return (!filelist->fnd ? filelist->fn : filelist->fnd);
}
-/*==========================================
- * File List : Filelist add
- *------------------------------------------
- */
-#define FILELIST_ADDS 1024 // number increment of file lists `
-
-static FILELIST* filelist_add(FILELIST *entry)
+// adds a FILELIST entry into the list of loaded files
+static FILELIST* filelist_add(FILELIST* entry)
{
int hash;
- if (filelist_entrys >= FILELIST_LIMIT) {
- ShowFatalError("GRF filelist limit reached (filelist_add)!\n");
- exit(1);
- }
+ #define FILELIST_ADDS 1024 // number increment of file lists `
if (filelist_entrys >= filelist_maxentry) {
filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
- malloc_tsetdword(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
+ memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
filelist_maxentry += FILELIST_ADDS;
}
memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
- hash = filehash((unsigned char *) entry->fn);
+ hash = filehash(entry->fn);
filelist[filelist_entrys].next = filelist_hash[hash];
filelist_hash[hash] = filelist_entrys;
@@ -409,10 +355,11 @@ static FILELIST* filelist_add(FILELIST *entry)
return &filelist[filelist_entrys - 1];
}
-static FILELIST* filelist_modify(FILELIST *entry)
+// adds a new FILELIST entry or overwrites an existing one
+static FILELIST* filelist_modify(FILELIST* entry)
{
- FILELIST *fentry;
- if ((fentry = filelist_find(entry->fn)) != NULL) {
+ FILELIST* fentry = filelist_find(entry->fn);
+ if (fentry != NULL) {
int tmp = fentry->next;
memcpy(fentry, entry, sizeof(FILELIST));
fentry->next = tmp;
@@ -422,18 +369,15 @@ static FILELIST* filelist_modify(FILELIST *entry)
return fentry;
}
-/*==========================================
- * File List : filelist size adjust
- *------------------------------------------
- */
+// shrinks the file list array if too long
static void filelist_adjust(void)
{
- if (filelist != NULL) {
- if (filelist_maxentry > filelist_entrys) {
- filelist = (FILELIST *)aRealloc(
- filelist, filelist_entrys * sizeof(FILELIST));
- filelist_maxentry = filelist_entrys;
- }
+ if (filelist == NULL)
+ return;
+
+ if (filelist_entrys < filelist_maxentry) {
+ filelist = (FILELIST *)aRealloc(filelist, filelist_entrys * sizeof(FILELIST));
+ filelist_maxentry = filelist_entrys;
}
}
@@ -441,13 +385,11 @@ static void filelist_adjust(void)
*** Grfio Sobroutines ***
***********************************************************/
-/*==========================================
- * Grfio : Resource file size get
- *------------------------------------------
- */
-int grfio_size(char *fname)
+// returns a file's size
+/*
+int grfio_size(char* fname)
{
- FILELIST *entry;
+ FILELIST* entry;
entry = filelist_find(fname);
@@ -459,7 +401,7 @@ int grfio_size(char *fname)
sprintf(lfname, "%s%s", data_dir, fname);
for (p = &lfname[0]; *p != 0; p++)
- if (*p=='\\') *p = '/'; // * At the time of Unix
+ if (*p=='\\') *p = '/';
if (stat(lfname, &st) == 0) {
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
@@ -469,22 +411,19 @@ int grfio_size(char *fname)
entry = filelist_modify(&lentry);
} else if (entry == NULL) {
ShowError("%s not found (grfio_size)\n", fname);
- //exit(1);
return -1;
}
}
return entry->declen;
}
+*/
-/*==========================================
- * Grfio : Resource file read & size get
- *------------------------------------------
- */
-void* grfio_reads(char *fname, int *size)
+// reads a file into a newly allocated buffer (from grf or data directory)
+void* grfio_reads(char* fname, int* size)
{
- FILE *in;
- FILELIST *entry;
- unsigned char *buf2 = NULL;
+ FILE* in;
+ FILELIST* entry;
+ unsigned char* buf2 = NULL;
entry = filelist_find(fname);
@@ -495,18 +434,18 @@ void* grfio_reads(char *fname, int *size)
sprintf(lfname, "%s%s", data_dir, fname);
for (p = &lfname[0]; *p != 0; p++)
- if (*p == '\\') *p = '/'; // * At the time of Unix
+ if (*p == '\\') *p = '/';
in = fopen(lfname, "rb");
if (in != NULL) {
if (entry != NULL && entry->gentry == 0) {
lentry.declen = entry->declen;
} else {
- fseek(in,0,2); // SEEK_END
+ fseek(in,0,SEEK_END);
lentry.declen = ftell(in);
}
- fseek(in,0,0); // SEEK_SET
- buf2 = (unsigned char *)aMallocA(lentry.declen + 1024);
+ fseek(in,0,SEEK_SET);
+ buf2 = (unsigned char *)malloc(lentry.declen + 1024);
fread(buf2, 1, lentry.declen, in);
fclose(in);
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
@@ -523,8 +462,8 @@ void* grfio_reads(char *fname, int *size)
}
}
if (entry != NULL && entry->gentry > 0) { // Archive[GRF] File Read
- char *gfname = gentry_table[entry->gentry - 1];
- in = fopen(gfname, "rb");
+ char* grfname = gentry_table[entry->gentry - 1];
+ in = fopen(grfname, "rb");
if(in != NULL) {
unsigned char *buf = (unsigned char *)aMallocA(entry->srclen_aligned + 1024);
fseek(in, entry->srcpos, 0);
@@ -537,8 +476,8 @@ void* grfio_reads(char *fname, int *size)
decode_des_etc(buf, entry->srclen_aligned, entry->cycle == 0, entry->cycle);
len = entry->declen;
decode_zip(buf2, &len, buf, entry->srclen);
- if (len != entry->declen) {
- ShowError("decode_zip size miss match err: %d != %d\n", (int)len, entry->declen);
+ if (len != (uLong)entry->declen) {
+ ShowError("decode_zip size mismatch err: %d != %d\n", (int)len, entry->declen);
aFree(buf);
aFree(buf2);
return NULL;
@@ -548,7 +487,7 @@ void* grfio_reads(char *fname, int *size)
}
aFree(buf);
} else {
- ShowError("%s not found (grfio_reads - grf file %s)\n", fname, gfname);
+ ShowError("%s not found (grfio_reads - GRF file %s)\n", fname, grfname);
return NULL;
}
}
@@ -560,9 +499,8 @@ void* grfio_reads(char *fname, int *size)
/*==========================================
* Resource filename decode
- *------------------------------------------
- */
-static char * decode_filename(unsigned char *buf,int len)
+ *------------------------------------------*/
+static char* decode_filename(unsigned char* buf, int len)
{
int lop;
for(lop=0;lop<len;lop+=8) {
@@ -574,34 +512,33 @@ static char * decode_filename(unsigned char *buf,int len)
return (char*)buf;
}
-/*==========================================
- * Grfio : Entry table read
- *------------------------------------------
- */
-static int grfio_entryread(char *gfname,int gentry)
+// loads all entries in the specified grf file into the filelist
+// gentry - index of the grf file name in the gentry_table
+static int grfio_entryread(char* grfname, int gentry)
{
- FILE *fp;
+ FILE* fp;
long grf_size,list_size;
unsigned char grf_header[0x2e];
int lop,entry,entrys,ofs,grf_version;
char *fname;
unsigned char *grf_filelist;
- fp = fopen(gfname, "rb");
+ fp = fopen(grfname, "rb");
if (fp == NULL) {
- ShowWarning("GRF Data File not found: '"CL_WHITE"%s"CL_RESET"'.\n",gfname);
+ ShowWarning("GRF data file not found: '%s'\n",grfname);
return 1; // 1:not found error
- }
+ } else
+ ShowInfo("GRF data file found: '%s'\n",grfname);
- fseek(fp,0,2); // SEEK_END
+ fseek(fp,0,SEEK_END);
grf_size = ftell(fp);
- fseek(fp,0,0); // SEEK_SET
+ fseek(fp,0,SEEK_SET);
fread(grf_header,1,0x2e,fp);
if (strcmp((const char *) grf_header,"Master of Magic") ||
- fseek(fp,getlong(grf_header+0x1e),1)) // SEEK_CUR
+ fseek(fp,getlong(grf_header+0x1e),SEEK_CUR))
{
fclose(fp);
- ShowError("GRF %s read error\n",gfname);
+ ShowError("GRF %s read error\n", grfname);
return 2; // 2:file format error
}
@@ -610,11 +547,6 @@ static int grfio_entryread(char *gfname,int gentry)
if (grf_version == 0x01) { //****** Grf version 01xx ******
list_size = grf_size - ftell(fp);
grf_filelist = (unsigned char *) aMallocA(list_size);
- /*if (grf_filelist == NULL){
- fclose(fp);
- ShowError("out of memory : grf_filelist\n");
- return 3; // 3:memory alloc error
- }*/
fread(grf_filelist,1,list_size,fp);
fclose(fp);
@@ -622,8 +554,9 @@ static int grfio_entryread(char *gfname,int gentry)
// Get an entry
for (entry = 0,ofs = 0; entry < entrys; entry++) {
- int ofs2, srclen, srccount, type;
- char *period_ptr;
+ int ofs2, srclen, srccount;
+ unsigned char type;
+ char* period_ptr;
FILELIST aentry;
ofs2 = ofs+getlong(grf_filelist+ofs)+4;
@@ -679,25 +612,14 @@ static int grfio_entryread(char *gfname,int gentry)
rSize = getlong(eheader); // Read Size
eSize = getlong(eheader+4); // Extend Size
- if ((long)rSize > grf_size-ftell(fp)) { // Warning fix [Lance]
+ if ((long)rSize > grf_size-ftell(fp)) {
fclose(fp);
- ShowError("Illegal data format : grf compress entry size\n");
+ ShowError("Illegal data format: GRF compress entry size\n");
return 4;
}
rBuf = (unsigned char *)aMallocA(rSize); // Get a Read Size
- /*if (rBuf==NULL) {
- fclose(fp);
- ShowError("out of memory : grf compress entry table buffer\n");
- return 3;
- }*/
grf_filelist = (unsigned char *)aMallocA(eSize); // Get a Extend Size
- /*if (grf_filelist==NULL) {
- aFree(rBuf);
- fclose(fp);
- ShowError("out of memory : grf extract entry table buffer\n");
- return 3;
- }*/
fread(rBuf,1,rSize,fp);
fclose(fp);
decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
@@ -707,7 +629,7 @@ static int grfio_entryread(char *gfname,int gentry)
entrys = getlong(grf_header+0x26) - 7;
// Get an entry
- for(entry = 0, ofs = 0; entry < entrys; entry++){
+ for(entry = 0, ofs = 0; entry < entrys; entry++) {
int ofs2, srclen, srccount, type;
FILELIST aentry;
@@ -717,8 +639,7 @@ static int grfio_entryread(char *gfname,int gentry)
aFree(grf_filelist);
exit(1);
}
- //ofs2 = ofs+strlen((char*)(grf_filelist+ofs))+1;
- ofs2 = ofs + strlen(fname)+1;
+ ofs2 = ofs + (int)strlen(fname)+1;
type = grf_filelist[ofs2+12];
if (type == 1 || type == 3 || type == 5) {
srclen = getlong(grf_filelist+ofs2);
@@ -762,27 +683,27 @@ static int grfio_entryread(char *gfname,int gentry)
/*==========================================
* Grfio : Resource file check
- *------------------------------------------
- */
+ *------------------------------------------*/
static void grfio_resourcecheck(void)
{
char w1[256], w2[256], src[256], dst[256], restable[256], line[256];
char *ptr, *buf;
- FILELIST *entry;
- int size, i = 0;
- FILE *fp;
+ FILELIST* entry;
+ int size;
+ FILE* fp;
+ int i = 0;
// read resnametable from data directory and return if successful
sprintf(restable, "%sdata\\resnametable.txt", data_dir);
for (ptr = &restable[0]; *ptr != 0; ptr++)
if (*ptr == '\\') *ptr = '/';
- fp = fopen(restable,"rb");
+ fp = fopen(restable, "rb");
if (fp) {
while (fgets(line, sizeof(line) - 1, fp)) {
if (sscanf(line, "%[^#]#%[^#]#", w1, w2) == 2 &&
- // we only need the map names and text files
- (strstr(w2, ".gat") || strstr(w2, ".txt")))
+ // we only need the maps' GAT and RSW files
+ (strstr(w2, ".gat") || strstr(w2, ".rsw")))
{
sprintf(src, "data\\%s", w1);
sprintf(dst, "data\\%s", w2);
@@ -792,7 +713,7 @@ static void grfio_resourcecheck(void)
FILELIST fentry;
memcpy(&fentry, entry, sizeof(FILELIST));
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
- fentry.fnd = grfio_alloc_ptr(dst);
+ fentry.fnd = strdup(dst);
filelist_modify(&fentry);
i++;
}
@@ -803,16 +724,15 @@ static void grfio_resourcecheck(void)
return; // we're done here!
}
- // read resnametable from loaded GRF's, only if it cannot be
- // loaded from the data directory
+ // read resnametable from loaded GRF's, only if it cannot be loaded from the data directory
buf = (char *)grfio_reads("data\\resnametable.txt", &size);
if (buf) {
buf[size] = 0;
- ptr = buf;
+ ptr = buf;
while (ptr - buf < size) {
if (sscanf(ptr, "%[^#]#%[^#]#", w1, w2) == 2 &&
- (strstr(w2, ".gat") || strstr(w2, ".txt")))
+ (strstr(w2, ".gat") || strstr(w2, ".rsw")))
{
sprintf(src, "data\\%s", w1);
sprintf(dst, "data\\%s", w2);
@@ -821,12 +741,12 @@ static void grfio_resourcecheck(void)
FILELIST fentry;
memcpy(&fentry, entry, sizeof(FILELIST));
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
- fentry.fnd = grfio_alloc_ptr(dst);
+ fentry.fnd = strdup(dst);
filelist_modify(&fentry);
i++;
}
}
- ptr = strchr(ptr,'\n'); // Next line
+ ptr = strchr(ptr, '\n'); // Next line
if (!ptr) break;
ptr++;
}
@@ -835,49 +755,25 @@ static void grfio_resourcecheck(void)
return;
}
- //ShowWarning("GRF: No resnametable found! Panic?\n");
-}
-
-/*==========================================
- * Grfio : Resource add
- *------------------------------------------
- */
-#define GENTRY_ADDS 4 // The number increment of gentry_table entries
-
-static int grfio_add(char *fname)
-{
- grfio_alloc_ptr(fname);
-
- return grfio_entryread(fname, gentry_entrys - 1);
}
-char *grfio_alloc_ptr(char *fname)
+// reads a grf file and adds it to the list
+static int grfio_add(char* fname)
{
- int len;
- char *buf;
-
- if (gentry_entrys >= GENTRY_LIMIT) {
- ShowFatalError("gentrys limit : grfio_add\n");
- exit(1);
- }
+ #define GENTRY_ADDS 4 // The number increment of gentry_table entries
if (gentry_entrys >= gentry_maxentry) {
gentry_maxentry += GENTRY_ADDS;
gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*));
- malloc_tsetdword(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
+ memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
}
- len = strlen( fname );
- buf = (char*)aMallocA(len + 1);
- strcpy(buf, fname);
- gentry_table[gentry_entrys++] = buf;
- return buf;
+ gentry_table[gentry_entrys++] = strdup(fname);
+
+ return grfio_entryread(fname, gentry_entrys - 1);
}
-/*==========================================
- * Grfio : Finalize
- *------------------------------------------
- */
+// removes all entries
void grfio_final(void)
{
if (filelist != NULL)
@@ -886,10 +782,10 @@ void grfio_final(void)
filelist_entrys = filelist_maxentry = 0;
if (gentry_table != NULL) {
- int lop;
- for (lop = 0; lop < gentry_entrys; lop++) {
- if (gentry_table[lop] != NULL)
- aFree(gentry_table[lop]);
+ int i;
+ for (i = 0; i < gentry_entrys; i++) {
+ if (gentry_table[i] != NULL)
+ aFree(gentry_table[i]);
}
aFree(gentry_table);
}
@@ -899,13 +795,12 @@ void grfio_final(void)
/*==========================================
* Grfio : Initialize
- *------------------------------------------
- */
-void grfio_init(char *fname)
+ *------------------------------------------*/
+void grfio_init(char* fname)
{
- FILE *data_conf;
+ FILE* data_conf;
char line[1024], w1[1024], w2[1024];
- int result = 0;
+ int grf_num = 0;
hashinit(); // hash table initialization
@@ -918,27 +813,23 @@ void grfio_init(char *fname)
if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
continue;
// Entry table reading
- if(strcmp(w1, "grf") == 0 ||
- strcmp(w1, "data") == 0 || // Primary data file
- strcmp(w1, "sdata") == 0 || // Sakray data file
- strcmp(w1, "adata") == 0) // Alpha version data file
- // increment if successfully loaded
- result += (grfio_add(w2) == 0);
- else if(strcmp(w1,"data_dir") == 0) // Data directory
+ if(strcmp(w1, "grf") == 0) // GRF file
+ grf_num += (grfio_add(w2) == 0);
+ else if(strcmp(w1,"data_dir") == 0) { // Data directory
strcpy(data_dir, w2);
+ }
}
-
fclose(data_conf);
ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n", fname);
} // end of reading grf-files.txt
- if (result == 0) {
- ShowInfo("No grf's loaded.. using default data directory\n");
- //exit(1); // It ends, if a resource cannot read one.
+ if (grf_num == 0) {
+ ShowInfo("No GRF loaded, using default data directory\n");
}
- // Unnecessary area release of filelist
+ // Unneccessary area release of filelist
filelist_adjust();
+
// Resource check
grfio_resourcecheck();
diff --git a/src/common/grfio.h b/src/common/grfio.h
index 408dafd1b..57439b16d 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -8,7 +8,6 @@ void grfio_init(char*); // GRFIO Initialize
void grfio_final(void); // GRFIO Finalize
void* grfio_reads(char*,int*); // GRFIO data file read & size get
char *grfio_find_file(char *fname);
-char *grfio_alloc_ptr(char *fname);
#define grfio_read(fn) grfio_reads(fn, NULL)
@@ -17,6 +16,5 @@ 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);
-int deflate_file (const char *source, const char *filename);
#endif /* _GRFIO_H_ */
diff --git a/src/common/mapindex.c b/src/common/mapindex.c
index b8bb12c18..37afcad3d 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -29,9 +29,7 @@ char *mapindex_normalize_name(char *mapname)
if (ptr) { //Check and remove extension.
while (ptr[1] && (ptr2 = strchr(ptr+1, '.')))
ptr = ptr2; //Skip to the last dot.
- if(stricmp(ptr,".gat") == 0 ||
- stricmp(ptr,".afm") == 0 ||
- stricmp(ptr,".af2") == 0)
+ if(stricmp(ptr,".gat") == 0)
*ptr = '\0'; //Remove extension.
}
return mapname;
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index b8e57544a..bff047492 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -513,7 +513,7 @@ int mmo_auth(struct mmo_account* account, int fd)
char t_uid[256];
char user_password[256], password[256];
long connect_until;
- int encpasswdok = 0, state;
+ int state;
char ip[16];
uint32 ipl = session[fd]->client_addr;
diff --git a/src/map/map.c b/src/map/map.c
index c65e49d21..ca2fd6565 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2856,24 +2856,17 @@ int map_config_read(char *cfgName) {
} else if(strcmpi(w1,"db_path") == 0) {
strncpy(db_path,w2,255);
} else if (strcmpi(w1, "console") == 0) {
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 ) {
- console = 1;
+ console = config_switch(w2);
+ if (console)
ShowNotice("Console Commands are enabled.\n");
- }
} else if (strcmpi(w1, "enable_spy") == 0) {
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
- enable_spy = 1;
- else
- enable_spy = 0;
- } else if (strcmpi(w1, "use_grf") == 0) { //[blackhole89]
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
- enable_grf = 1;
- else
- enable_grf = 0;
+ enable_spy = config_switch(w2);
+ } else if (strcmpi(w1, "use_grf") == 0) {
+ enable_grf = config_switch(w2);
} else if (strcmpi(w1, "import") == 0) {
map_config_read(w2);
} else
- ShowWarning("Unknown setting [%s] in file %s\n", w1, cfgName);
+ ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
}
}
fclose(fp);
diff --git a/src/map/map.h b/src/map/map.h
index a2bf8d455..6178b364d 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1271,12 +1271,6 @@ extern char db_path[256];
int map_getcell(int,int,int,cell_t);
int map_getcellp(struct map_data*,int,int,cell_t);
void map_setcell(int,int,int,int);
-extern int map_read_flag; // 0: grfիE1: ëE2: ëE?)
-enum {
- READ_FROM_GAT, READ_FROM_AFM,
- READ_FROM_BITMAP, CREATE_BITMAP,
- READ_FROM_BITMAP_COMPRESSED, CREATE_BITMAP_COMPRESSED
-};
extern char motd_txt[];
extern char help_txt[];
@@ -1356,11 +1350,6 @@ int map_check_dir(int s_dir,int t_dir);
int map_calc_dir( struct block_list *src,int x,int y);
int map_random_dir(struct block_list *bl, short *x, short *y); // [Skotlex]
-// Water functions...
-//
-int map_setwaterheight(int m, char *mapname, int height);
-int map_waterheight(char *mapname);
-
// path.c
int path_search_real(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1,int flag,cell_t flag2);
#define path_search(wpd,m,x0,y0,x1,y1,flag) path_search_real(wpd,m,x0,y0,x1,y1,flag,CELL_CHKNOPASS)
diff --git a/src/map/npc.c b/src/map/npc.c
index 97034402e..49cb4f1a0 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2930,7 +2930,6 @@ static int npc_read_event_script_sub(DBKey key,void *data,va_list ap)
void npc_read_event_script(void)
{
int i;
- unsigned char buf[64]="::";
struct {
char *name;
char *event_name;
@@ -2946,15 +2945,14 @@ void npc_read_event_script(void)
};
for (i = 0; i < NPCE_MAX; i++) {
- if (script_event[i].nd)
- script_event[i].nd = NULL;
- if (script_event[i].event_count)
- script_event[i].event_count = 0;
+ script_event[i].nd = NULL;
+ script_event[i].event_count = 0;
if (!script_config.event_script_type) {
//Use a single NPC as event source.
script_event[i].nd = npc_name2id(config[i].event_name);
} else {
//Use an array of Events
+ char buf[64]="::";
strncpy(buf+2,config[i].event_name,62);
ev_db->foreach(ev_db,npc_read_event_script_sub,buf,
&script_event[i].event,
diff --git a/src/map/pc.c b/src/map/pc.c
index ae2914b6f..dd031aadb 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -2966,7 +2966,7 @@ int pc_isUseitem(struct map_session_data *sd,int n)
//Butterfly Wing (can't use noreturn flag is on)
if(nameid == 602 && map[sd->bl.m].flag.noreturn)
return 0;
- //Dead Branch & Red Pouch & Bloody Branch & Porings Box (can't use at GVG and when nobranch flag is on)
+ //Dead Branch & Red Pouch & Bloody Branch & Poring Box (can't use at GVG and when nobranch flag is on)
if((nameid == 604 || nameid == 12024 || nameid == 12103 || nameid == 12109) && (map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m)))
return 0;
diff --git a/src/map/status.h b/src/map/status.h
index 0ea31cdec..380694eba 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -258,14 +258,14 @@ enum {
SC_CHANGE,
SC_BLOODLUST,
SC_FLEET,
- SC_SPEED, //[orn]
- SC_DEFENCE, //[orn]
+ SC_SPEED,
+ SC_DEFENCE,
SC_INCAGIRATE,
SC_INCDEXRATE,
SC_JAILED,
SC_ENCHANTARMS, //250
SC_MAGICALATTACK,
- SC_MAX, //Automatically updated max, used in for's and at startup to check we are within bounds. [Skotlex]
+ SC_MAX, //Automatically updated max, used in for's to check we are within bounds.
};
int SkillStatusChangeTable(int skill);
extern int StatusSkillChangeTable[SC_MAX];
@@ -314,8 +314,8 @@ enum {
//38: Again Aspd Potion
//39: Again Aspd Potion
//40: Again Aspd Potion
- SI_SPEEDPOTION1 = 41,
- SI_SPEEDPOTION2 = 42,
+ SI_SPEEDPOTION1 = 41,
+ SI_SPEEDPOTION2 = 42,
SI_STRIPWEAPON = 50,
SI_STRIPSHIELD = 51,
SI_STRIPARMOR = 52,
@@ -336,7 +336,7 @@ enum {
SI_WATERWEAPON = 91,
SI_WINDWEAPON = 92,
SI_EARTHWEAPON = 93,
- SI_UNDEAD = 97,
+ SI_UNDEAD = 97,
// 102 = again gloria - from what I saw on screenshots, I wonder if it isn't gospel... [DracoRPG]
SI_AURABLADE = 103,
SI_PARRYING = 104,
@@ -344,7 +344,7 @@ enum {
SI_TENSIONRELAX = 106,
SI_BERSERK = 107,
SI_ASSUMPTIO = 110,
- SI_LANDENDOW = 112,
+ SI_LANDENDOW = 112,
SI_MAGICPOWER = 113,
SI_EDP = 114,
SI_TRUESIGHT = 115,
@@ -359,7 +359,7 @@ enum {
SI_BLEEDING = 124,
SI_JOINTBEAT = 125,
SI_BABY = 130,
- SI_AUTOBERSERK = 132,
+ SI_AUTOBERSERK = 132,
SI_RUN = 133,
SI_BUMP = 134,
SI_READYSTORM = 135,
@@ -368,7 +368,7 @@ enum {
SI_READYCOUNTER = 141,
SI_DODGE = 143,
//SI_RUN = 144, //is not RUN. need info on what this is.
- SI_SPURT = 145,
+ SI_SPURT = 145,
SI_SHADOWWEAPON = 146,
SI_ADRENALINE2 = 147,
SI_GHOSTWEAPON = 148,
@@ -378,7 +378,7 @@ enum {
SI_KAIZEL = 156,
SI_KAAHI = 157,
SI_KAUPE = 158,
- SI_SMA = 159,
+ SI_SMA = 159,
SI_NIGHT = 160,
SI_ONEHAND = 161,
SI_WARM = 165,
@@ -388,8 +388,8 @@ enum {
SI_MOON_COMFORT = 170,
SI_STAR_COMFORT = 171,
SI_PRESERVE = 181,
- SI_INCSTR = 182,
- SI_INTRAVISION = 184,
+ SI_INCSTR = 182,
+ SI_INTRAVISION = 184,
SI_DOUBLECAST = 186,
SI_MAXOVERTHRUST = 188,
SI_TAROT = 191, // the icon allows no doubt... but what is it really used for ?? [DracoRPG]
@@ -401,20 +401,20 @@ enum {
SI_MADNESSCANCEL = 203, //[blackhole89]
SI_GATLINGFEVER = 204,
SI_TKREST = 205, // 205 = Gloria again (but TK- Happy State looks like it)
- SI_UTSUSEMI = 206,
+ SI_UTSUSEMI = 206,
SI_BUNSINJYUTSU = 207,
- SI_NEN = 208,
+ SI_NEN = 208,
SI_ADJUSTMENT = 209,
- SI_ACCURACY = 210,
- SI_FOODSTR = 241,
- SI_FOODAGI = 242,
- SI_FOODVIT = 243,
- SI_FOODDEX = 244,
- SI_FOODINT = 245,
- SI_FOODLUK = 246,
- SI_FOODFLEE = 247,
- SI_FOODHIT = 248,
- SI_FOODCRI = 249,
+ SI_ACCURACY = 210,
+ SI_FOODSTR = 241,
+ SI_FOODAGI = 242,
+ SI_FOODVIT = 243,
+ SI_FOODDEX = 244,
+ SI_FOODINT = 245,
+ SI_FOODLUK = 246,
+ SI_FOODFLEE = 247,
+ SI_FOODHIT = 248,
+ SI_FOODCRI = 249,
};
// JOINTBEAT stackable ailments
diff --git a/src/map/trade.c b/src/map/trade.c
index 41d919daa..f8c939424 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -54,7 +54,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta
}
if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
- clif_tradestart(sd, 2); // person is in another trade
+ clif_tradestart(sd, 2); // person is in another trade
return;
}
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index aa0ab0c94..5db46c123 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -218,9 +218,7 @@ char *remove_extension(char *mapname)
if (ptr) { //Check and remove extension.
while (ptr[1] && (ptr2 = strchr(ptr+1, '.')))
ptr = ptr2; //Skip to the last dot.
- if (strcmp(ptr,".gat") == 0 ||
- strcmp(ptr,".afm") == 0 ||
- strcmp(ptr,".af2") == 0)
+ if (strcmp(ptr,".gat") == 0)
*ptr = '\0'; //Remove extension.
}
return mapname;