Partially deobfuscated the grfio module
git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10271 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
2216188890
commit
a5407d3948
@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
|
|||||||
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
|
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
|
||||||
|
|
||||||
2007/04/17
|
2007/04/17
|
||||||
|
* Partially deobfuscated the grfio module
|
||||||
* Finally fixed mingw problems, managed to build both TXT and SQL
|
* Finally fixed mingw problems, managed to build both TXT and SQL
|
||||||
* Fixed the uint32 platform problem (Microsoft failed so I removed it :)
|
* Fixed the uint32 platform problem (Microsoft failed so I removed it :)
|
||||||
* Removed the cbasetypes.h dependency from the mapcache generator
|
* Removed the cbasetypes.h dependency from the mapcache generator
|
||||||
|
211
src/tool/grfio.c
211
src/tool/grfio.c
@ -1,28 +1,6 @@
|
|||||||
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
||||||
// For more information, see LICENCE in the main folder
|
// 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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -37,9 +15,7 @@
|
|||||||
#include "../zlib/zlib.h"
|
#include "../zlib/zlib.h"
|
||||||
#include "../zlib/iowin32.h"
|
#include "../zlib/iowin32.h"
|
||||||
#else
|
#else
|
||||||
#ifndef __FREEBSD__
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#endif
|
|
||||||
#define strcmpi strcasecmp
|
#define strcmpi strcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -54,31 +30,32 @@ static char data_dir[1024] = ""; // "../";
|
|||||||
//----------------------------
|
//----------------------------
|
||||||
typedef struct _FILELIST {
|
typedef struct _FILELIST {
|
||||||
int srclen; // compressed size
|
int srclen; // compressed size
|
||||||
int srclen_aligned; //
|
int srclen_aligned;
|
||||||
int declen; // original size
|
int declen; // original size
|
||||||
int srcpos;
|
int srcpos; // position of entry in grf
|
||||||
int next;
|
int next; // index of next filelist entry with same hash (-1: end of entry chain)
|
||||||
int cycle;
|
int cycle;
|
||||||
char type;
|
char type;
|
||||||
char fn[128-4*5]; // file name
|
char fn[128-4*5]; // file name
|
||||||
char *fnd;
|
char* fnd; // if the file was cloned, contains name of original file
|
||||||
signed char gentry; // read grf file select
|
char gentry; // read grf file select
|
||||||
} FILELIST;
|
} 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.
|
//gentry ... > 0 : data read from a grf file (gentry_table[gentry-1])
|
||||||
|
//gentry ... 0 : data read from a local file (data directory)
|
||||||
#define GENTRY_LIMIT 512
|
//gentry ... < 0 : entry "-(gentry)" is marked for a local file check
|
||||||
#define FILELIST_LIMIT 1048576 // temporary maximum, and a theory top maximum are 2G.
|
// - 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
|
||||||
|
|
||||||
|
// stores info about every loaded file
|
||||||
static FILELIST* filelist = NULL;
|
static FILELIST* filelist = NULL;
|
||||||
static int filelist_entrys = 0;
|
static int filelist_entrys = 0;
|
||||||
static int filelist_maxentry = 0;
|
static int filelist_maxentry = 0;
|
||||||
|
|
||||||
|
// stores grf file names
|
||||||
static char** gentry_table = NULL;
|
static char** gentry_table = NULL;
|
||||||
static int gentry_entrys = 0;
|
static int gentry_entrys = 0;
|
||||||
static int gentry_maxentry = 0;
|
static int gentry_maxentry = 0;
|
||||||
@ -148,8 +125,7 @@ static unsigned int getlong(unsigned char *p)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grf data decode : Subs
|
* Grf data decode : Subs
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
static void NibbleSwap(BYTE* Src, int len)
|
static void NibbleSwap(BYTE* Src, int len)
|
||||||
{
|
{
|
||||||
for(;0<len;len--,Src++) {
|
for(;0<len;len--,Src++) {
|
||||||
@ -252,8 +228,7 @@ static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
|
|||||||
}
|
}
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grf data decode sub : zip
|
* 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;
|
z_stream stream;
|
||||||
@ -285,7 +260,8 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
|
|||||||
return err;
|
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;
|
z_stream stream;
|
||||||
int err;
|
int err;
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
@ -320,8 +296,7 @@ int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
|
|||||||
* Adapted from miniunz.c [Celest]
|
* Adapted from miniunz.c [Celest]
|
||||||
* Version 1.01b, May 30th, 2004
|
* Version 1.01b, May 30th, 2004
|
||||||
* Copyright (C) 1998-2004 Gilles Vollant
|
* Copyright (C) 1998-2004 Gilles Vollant
|
||||||
* -------------------------------------
|
* -------------------------------------*/
|
||||||
*/
|
|
||||||
int deflate_file (const char* source, const char* filename)
|
int deflate_file (const char* source, const char* filename)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -389,13 +364,12 @@ unsigned long grfio_crc32 (const unsigned char *buf, unsigned int len)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* File List : Hash make
|
* File List : Hash make
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
static int filehash(char* fname)
|
||||||
static int filehash(unsigned char *fname)
|
|
||||||
{
|
{
|
||||||
unsigned int hash = 0;
|
unsigned int hash = 0;
|
||||||
while(*fname) {
|
while(*fname) {
|
||||||
hash = ((hash<<1)+(hash>>7)*9+tolower(*fname));
|
hash = ((hash<<1) + (hash>>7)*9 + (unsigned int)tolower((unsigned char)(*fname)));
|
||||||
fname++;
|
fname++;
|
||||||
}
|
}
|
||||||
return hash & 255;
|
return hash & 255;
|
||||||
@ -403,55 +377,51 @@ static int filehash(unsigned char *fname)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* File List : Hash initalize
|
* File List : Hash initalize
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
static void hashinit(void)
|
static void hashinit(void)
|
||||||
{
|
{
|
||||||
int lop;
|
int i;
|
||||||
for (lop = 0; lop < 256; lop++)
|
for (i = 0; i < 256; i++)
|
||||||
filelist_hash[lop] = -1;
|
filelist_hash[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* File List : File find
|
* File List : File find
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
static FILELIST* filelist_find(char* fname)
|
static FILELIST* filelist_find(char* fname)
|
||||||
{
|
{
|
||||||
int hash;
|
int hash, index;
|
||||||
|
|
||||||
if (!filelist)
|
if (!filelist)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (hash = filelist_hash[filehash((unsigned char *) fname)]; hash >= 0; hash = filelist[hash].next) {
|
hash = filelist_hash[filehash(fname)];
|
||||||
if(strcmpi(filelist[hash].fn, fname) == 0)
|
for (index = hash; index != -1; index = filelist[index].next)
|
||||||
|
if(!strcmpi(filelist[index].fn, fname))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
return (index >= 0) ? &filelist[index] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (hash >= 0) ? &filelist[hash] : NULL;
|
// returns the original file name
|
||||||
}
|
/*
|
||||||
|
char* grfio_find_file(char* fname)
|
||||||
char *grfio_find_file(char *fname){
|
{
|
||||||
FILELIST *filelist = filelist_find(fname);
|
FILELIST *filelist = filelist_find(fname);
|
||||||
if (!filelist) return NULL;
|
if (!filelist) return NULL;
|
||||||
return (!filelist->fnd ? filelist->fn : filelist->fnd);
|
return (!filelist->fnd ? filelist->fn : filelist->fnd);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* File List : Filelist add
|
* File List : Filelist add
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
#define FILELIST_ADDS 1024 // number increment of file lists `
|
#define FILELIST_ADDS 1024 // number increment of file lists `
|
||||||
|
|
||||||
static FILELIST* filelist_add(FILELIST* entry)
|
static FILELIST* filelist_add(FILELIST* entry)
|
||||||
{
|
{
|
||||||
int hash;
|
int hash;
|
||||||
|
|
||||||
if (filelist_entrys >= FILELIST_LIMIT) {
|
|
||||||
printf("GRF filelist limit reached!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filelist_entrys >= filelist_maxentry) {
|
if (filelist_entrys >= filelist_maxentry) {
|
||||||
filelist = (FILELIST *)realloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
|
filelist = (FILELIST *)realloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
|
||||||
memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
|
memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
|
||||||
@ -460,7 +430,7 @@ static FILELIST* filelist_add(FILELIST *entry)
|
|||||||
|
|
||||||
memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
|
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[filelist_entrys].next = filelist_hash[hash];
|
||||||
filelist_hash[hash] = filelist_entrys;
|
filelist_hash[hash] = filelist_entrys;
|
||||||
|
|
||||||
@ -469,10 +439,11 @@ static FILELIST* filelist_add(FILELIST *entry)
|
|||||||
return &filelist[filelist_entrys - 1];
|
return &filelist[filelist_entrys - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds a new entry or overwrites an existing one
|
||||||
static FILELIST* filelist_modify(FILELIST* entry)
|
static FILELIST* filelist_modify(FILELIST* entry)
|
||||||
{
|
{
|
||||||
FILELIST *fentry;
|
FILELIST* fentry = filelist_find(entry->fn);
|
||||||
if ((fentry = filelist_find(entry->fn)) != NULL) {
|
if (fentry != NULL) {
|
||||||
int tmp = fentry->next;
|
int tmp = fentry->next;
|
||||||
memcpy(fentry, entry, sizeof(FILELIST));
|
memcpy(fentry, entry, sizeof(FILELIST));
|
||||||
fentry->next = tmp;
|
fentry->next = tmp;
|
||||||
@ -482,29 +453,24 @@ static FILELIST* filelist_modify(FILELIST *entry)
|
|||||||
return fentry;
|
return fentry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
// shrinks the file list array if too long
|
||||||
* File List : filelist size adjust
|
|
||||||
*------------------------------------------
|
|
||||||
*/
|
|
||||||
static void filelist_adjust(void)
|
static void filelist_adjust(void)
|
||||||
{
|
{
|
||||||
if (filelist != NULL) {
|
if (filelist == NULL)
|
||||||
if (filelist_maxentry > filelist_entrys) {
|
return;
|
||||||
filelist = (FILELIST *)realloc(
|
|
||||||
filelist, filelist_entrys * sizeof(FILELIST));
|
if (filelist_entrys < filelist_maxentry) {
|
||||||
|
filelist = (FILELIST *)realloc(filelist, filelist_entrys * sizeof(FILELIST));
|
||||||
filelist_maxentry = filelist_entrys;
|
filelist_maxentry = filelist_entrys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
*** Grfio Sobroutines ***
|
*** Grfio Sobroutines ***
|
||||||
***********************************************************/
|
***********************************************************/
|
||||||
|
|
||||||
/*==========================================
|
// returns a file's size
|
||||||
* Grfio : Resource file size get
|
/*
|
||||||
*------------------------------------------
|
|
||||||
*/
|
|
||||||
int grfio_size(char* fname)
|
int grfio_size(char* fname)
|
||||||
{
|
{
|
||||||
FILELIST* entry;
|
FILELIST* entry;
|
||||||
@ -519,7 +485,7 @@ int grfio_size(char *fname)
|
|||||||
sprintf(lfname, "%s%s", data_dir, fname);
|
sprintf(lfname, "%s%s", data_dir, fname);
|
||||||
|
|
||||||
for (p = &lfname[0]; *p != 0; p++)
|
for (p = &lfname[0]; *p != 0; p++)
|
||||||
if (*p=='\\') *p = '/'; // * At the time of Unix
|
if (*p=='\\') *p = '/';
|
||||||
|
|
||||||
if (stat(lfname, &st) == 0) {
|
if (stat(lfname, &st) == 0) {
|
||||||
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
|
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
|
||||||
@ -529,17 +495,16 @@ int grfio_size(char *fname)
|
|||||||
entry = filelist_modify(&lentry);
|
entry = filelist_modify(&lentry);
|
||||||
} else if (entry == NULL) {
|
} else if (entry == NULL) {
|
||||||
printf("%s not found (grfio_size)\n", fname);
|
printf("%s not found (grfio_size)\n", fname);
|
||||||
//exit(1);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return entry->declen;
|
return entry->declen;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Resource file read & size get
|
* Grfio : Resource file read & size get
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
void* grfio_reads(char* fname, int* size)
|
void* grfio_reads(char* fname, int* size)
|
||||||
{
|
{
|
||||||
FILE* in;
|
FILE* in;
|
||||||
@ -555,7 +520,7 @@ void* grfio_reads(char *fname, int *size)
|
|||||||
sprintf(lfname, "%s%s", data_dir, fname);
|
sprintf(lfname, "%s%s", data_dir, fname);
|
||||||
|
|
||||||
for (p = &lfname[0]; *p != 0; p++)
|
for (p = &lfname[0]; *p != 0; p++)
|
||||||
if (*p == '\\') *p = '/'; // * At the time of Unix
|
if (*p == '\\') *p = '/';
|
||||||
|
|
||||||
in = fopen(lfname, "rb");
|
in = fopen(lfname, "rb");
|
||||||
if (in != NULL) {
|
if (in != NULL) {
|
||||||
@ -582,8 +547,8 @@ void* grfio_reads(char *fname, int *size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entry != NULL && entry->gentry > 0) { // Archive[GRF] File Read
|
if (entry != NULL && entry->gentry > 0) { // Archive[GRF] File Read
|
||||||
char *gfname = gentry_table[entry->gentry - 1];
|
char* grfname = gentry_table[entry->gentry - 1];
|
||||||
in = fopen(gfname, "rb");
|
in = fopen(grfname, "rb");
|
||||||
if(in != NULL) {
|
if(in != NULL) {
|
||||||
unsigned char *buf = (unsigned char *)malloc(entry->srclen_aligned + 1024);
|
unsigned char *buf = (unsigned char *)malloc(entry->srclen_aligned + 1024);
|
||||||
fseek(in, entry->srcpos, 0);
|
fseek(in, entry->srcpos, 0);
|
||||||
@ -607,7 +572,7 @@ void* grfio_reads(char *fname, int *size)
|
|||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
} else {
|
} else {
|
||||||
printf("%s not found (grfio_reads - GRF file %s)\n", fname, gfname);
|
printf("%s not found (grfio_reads - GRF file %s)\n", fname, grfname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,8 +584,7 @@ void* grfio_reads(char *fname, int *size)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Resource filename decode
|
* Resource filename decode
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
static char* decode_filename(unsigned char* buf, int len)
|
static char* decode_filename(unsigned char* buf, int len)
|
||||||
{
|
{
|
||||||
int lop;
|
int lop;
|
||||||
@ -635,9 +599,8 @@ static char * decode_filename(unsigned char *buf,int len)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Entry table read
|
* Grfio : Entry table read
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
static int grfio_entryread(char* grfname, int gentry)
|
||||||
static int grfio_entryread(char *gfname,int gentry)
|
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
long grf_size,list_size;
|
long grf_size,list_size;
|
||||||
@ -646,12 +609,12 @@ static int grfio_entryread(char *gfname,int gentry)
|
|||||||
char *fname;
|
char *fname;
|
||||||
unsigned char *grf_filelist;
|
unsigned char *grf_filelist;
|
||||||
|
|
||||||
fp = fopen(gfname, "rb");
|
fp = fopen(grfname, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("GRF data file not found: '%s'\n",gfname);
|
printf("GRF data file not found: '%s'\n",grfname);
|
||||||
return 1; // 1:not found error
|
return 1; // 1:not found error
|
||||||
} else
|
} else
|
||||||
printf("GRF data file found: '%s'\n",gfname);
|
printf("GRF data file found: '%s'\n",grfname);
|
||||||
|
|
||||||
fseek(fp,0,2); // SEEK_END
|
fseek(fp,0,2); // SEEK_END
|
||||||
grf_size = ftell(fp);
|
grf_size = ftell(fp);
|
||||||
@ -661,7 +624,7 @@ static int grfio_entryread(char *gfname,int gentry)
|
|||||||
fseek(fp,getlong(grf_header+0x1e),1)) // SEEK_CUR
|
fseek(fp,getlong(grf_header+0x1e),1)) // SEEK_CUR
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
printf("GRF %s read error\n",gfname);
|
printf("GRF %s read error\n", grfname);
|
||||||
return 2; // 2:file format error
|
return 2; // 2:file format error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,14 +770,13 @@ static int grfio_entryread(char *gfname,int gentry)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Resource file check
|
* Grfio : Resource file check
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
static void grfio_resourcecheck(void)
|
static void grfio_resourcecheck(void)
|
||||||
{
|
{
|
||||||
char w1[256], w2[256], src[256], dst[256], restable[256], line[256];
|
char w1[256], w2[256], src[256], dst[256], restable[256], line[256];
|
||||||
char *ptr, *buf;
|
char *ptr, *buf;
|
||||||
FILELIST* entry;
|
FILELIST* entry;
|
||||||
int size, i = 0;
|
int size;
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
// read resnametable from data directory and return if successful
|
// read resnametable from data directory and return if successful
|
||||||
@ -839,7 +801,6 @@ static void grfio_resourcecheck(void)
|
|||||||
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
|
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
|
||||||
fentry.fnd = grfio_alloc_ptr(dst);
|
fentry.fnd = grfio_alloc_ptr(dst);
|
||||||
filelist_modify(&fentry);
|
filelist_modify(&fentry);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -867,7 +828,6 @@ static void grfio_resourcecheck(void)
|
|||||||
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
|
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
|
||||||
fentry.fnd = grfio_alloc_ptr(dst);
|
fentry.fnd = grfio_alloc_ptr(dst);
|
||||||
filelist_modify(&fentry);
|
filelist_modify(&fentry);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, '\n'); // Next line
|
ptr = strchr(ptr, '\n'); // Next line
|
||||||
@ -882,8 +842,7 @@ static void grfio_resourcecheck(void)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Resource add
|
* Grfio : Resource add
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
#define GENTRY_ADDS 4 // The number increment of gentry_table entries
|
#define GENTRY_ADDS 4 // The number increment of gentry_table entries
|
||||||
|
|
||||||
static int grfio_add(char* fname)
|
static int grfio_add(char* fname)
|
||||||
@ -893,33 +852,23 @@ static int grfio_add(char *fname)
|
|||||||
return grfio_entryread(fname, gentry_entrys - 1);
|
return grfio_entryread(fname, gentry_entrys - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds a copy of 'fname' into the gentry_table
|
||||||
char* grfio_alloc_ptr(char* fname)
|
char* grfio_alloc_ptr(char* fname)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
if (gentry_entrys >= GENTRY_LIMIT) {
|
|
||||||
printf("GRF file entry limit reached!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gentry_entrys >= gentry_maxentry) {
|
if (gentry_entrys >= gentry_maxentry) {
|
||||||
gentry_maxentry += GENTRY_ADDS;
|
gentry_maxentry += GENTRY_ADDS;
|
||||||
gentry_table = (char**)realloc(gentry_table, gentry_maxentry * sizeof(char*));
|
gentry_table = (char**)realloc(gentry_table, gentry_maxentry * sizeof(char*));
|
||||||
memset(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*)malloc(len + 1);
|
|
||||||
strcpy(buf, fname);
|
|
||||||
gentry_table[gentry_entrys++] = buf;
|
|
||||||
|
|
||||||
return buf;
|
gentry_table[gentry_entrys++] = strdup(fname);
|
||||||
|
|
||||||
|
return gentry_table[gentry_entrys - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Finalize
|
* Grfio : Finalize
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
void grfio_final(void)
|
void grfio_final(void)
|
||||||
{
|
{
|
||||||
if (filelist != NULL)
|
if (filelist != NULL)
|
||||||
@ -928,10 +877,10 @@ void grfio_final(void)
|
|||||||
filelist_entrys = filelist_maxentry = 0;
|
filelist_entrys = filelist_maxentry = 0;
|
||||||
|
|
||||||
if (gentry_table != NULL) {
|
if (gentry_table != NULL) {
|
||||||
int lop;
|
int i;
|
||||||
for (lop = 0; lop < gentry_entrys; lop++) {
|
for (i = 0; i < gentry_entrys; i++) {
|
||||||
if (gentry_table[lop] != NULL)
|
if (gentry_table[i] != NULL)
|
||||||
free(gentry_table[lop]);
|
free(gentry_table[i]);
|
||||||
}
|
}
|
||||||
free(gentry_table);
|
free(gentry_table);
|
||||||
}
|
}
|
||||||
@ -941,8 +890,7 @@ void grfio_final(void)
|
|||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Grfio : Initialize
|
* Grfio : Initialize
|
||||||
*------------------------------------------
|
*------------------------------------------*/
|
||||||
*/
|
|
||||||
void grfio_init(char* fname)
|
void grfio_init(char* fname)
|
||||||
{
|
{
|
||||||
FILE* data_conf;
|
FILE* data_conf;
|
||||||
@ -976,6 +924,7 @@ void grfio_init(char *fname)
|
|||||||
|
|
||||||
// Unnecessary area release of filelist
|
// Unnecessary area release of filelist
|
||||||
filelist_adjust();
|
filelist_adjust();
|
||||||
|
|
||||||
// Resource check
|
// Resource check
|
||||||
grfio_resourcecheck();
|
grfio_resourcecheck();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user