Implement UserMapHacks.

git-svn-id: https://svn.eduke32.com/eduke32@4884 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-01-08 15:14:00 +00:00
parent 3f846bdde3
commit 589c993c39
4 changed files with 88 additions and 13 deletions

View file

@ -649,6 +649,16 @@ typedef struct {
EXTERN int32_t guniqhudid; EXTERN int32_t guniqhudid;
EXTERN int32_t spritesortcnt; EXTERN int32_t spritesortcnt;
extern int32_t g_loadedMapVersion; extern int32_t g_loadedMapVersion;
extern uint8_t g_loadedMapMD4[16];
typedef struct {
char *mhkfile;
char *title;
uint8_t md4[16];
} usermaphack_t;
extern int32_t compare_usermaphacks(const void *, const void *);
extern usermaphack_t *usermaphacks;
extern int32_t num_usermaphacks;
#if !defined DEBUG_MAIN_ARRAYS #if !defined DEBUG_MAIN_ARRAYS
EXTERN spriteext_t *spriteext; EXTERN spriteext_t *spriteext;

View file

@ -273,7 +273,7 @@ static int32_t defsparser(scriptfile *script)
{ "cachesize", T_CACHESIZE }, { "cachesize", T_CACHESIZE },
{ "dummytilefrompic",T_IMPORTTILE }, { "dummytilefrompic",T_IMPORTTILE },
{ "tilefromtexture", T_TILEFROMTEXTURE }, { "tilefromtexture", T_TILEFROMTEXTURE },
{ "mapinfo", T_MAPINFO }, // dummy { "mapinfo", T_MAPINFO },
{ "echo", T_ECHO }, { "echo", T_ECHO },
}; };
@ -2134,7 +2134,7 @@ static int32_t defsparser(scriptfile *script)
case T_MAPINFO: case T_MAPINFO:
{ {
char *dummy, *dummy2; char *mapmd4string = NULL, *title = NULL, *mhkfile = NULL, *mapinfoend, *dummy;
static const tokenlist mapinfotokens[] = static const tokenlist mapinfotokens[] =
{ {
{ "mapfile", T_MAPFILE }, { "mapfile", T_MAPFILE },
@ -2142,25 +2142,47 @@ static int32_t defsparser(scriptfile *script)
{ "mapmd4", T_MAPMD4 }, { "mapmd4", T_MAPMD4 },
{ "mhkfile", T_MHKFILE }, { "mhkfile", T_MHKFILE },
}; };
int32_t previous_usermaphacks = num_usermaphacks;
if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&dummy))) break; if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&mapinfoend))) break;
while (script->textptr < dummy) while (script->textptr < mapinfoend)
{ {
switch (getatoken(script,mapinfotokens,ARRAY_SIZE(mapinfotokens))) switch (getatoken(script,mapinfotokens,ARRAY_SIZE(mapinfotokens)))
{ {
case T_MAPFILE: case T_MAPFILE:
scriptfile_getstring(script,&dummy2); scriptfile_getstring(script,&dummy);
break; break;
case T_MAPTITLE: case T_MAPTITLE:
scriptfile_getstring(script,&dummy2); scriptfile_getstring(script,&title);
break; break;
case T_MAPMD4: case T_MAPMD4:
scriptfile_getstring(script,&dummy2); {
break; scriptfile_getstring(script,&mapmd4string);
case T_MHKFILE:
scriptfile_getstring(script,&dummy2); num_usermaphacks++;
usermaphacks = (usermaphack_t *)Xrealloc(usermaphacks, num_usermaphacks*sizeof(usermaphack_t));
usermaphack_t *newusermaphack = &usermaphacks[num_usermaphacks - 1];
for (int i = 0; i < 16; i++)
{
char smallbuf[3] = { 0, 0, 0 };
smallbuf[0] = mapmd4string[2*i];
smallbuf[1] = mapmd4string[2*i+1];
newusermaphack->md4[i] = Bstrtol(smallbuf, NULL, 16);
}
break; break;
} }
case T_MHKFILE:
scriptfile_getstring(script,&mhkfile);
break;
}
}
for (; previous_usermaphacks < num_usermaphacks; previous_usermaphacks++)
{
usermaphacks[previous_usermaphacks].mhkfile = mhkfile ? Bstrdup(mhkfile) : NULL;
usermaphacks[previous_usermaphacks].title = title ? Bstrdup(title) : NULL;
} }
} }
break; break;
@ -2212,6 +2234,8 @@ int32_t loaddefinitionsfile(const char *fn)
DO_FREE_AND_NULL(faketilebuffer); DO_FREE_AND_NULL(faketilebuffer);
faketilebuffersiz = 0; faketilebuffersiz = 0;
qsort(usermaphacks, num_usermaphacks, sizeof(usermaphack_t), compare_usermaphacks);
if (!script) return -1; if (!script) return -1;
initprintf("\n"); initprintf("\n");

View file

@ -82,6 +82,14 @@ float debug1, debug2;
int32_t mapversion=7; // JBF 20040211: default mapversion to 7 int32_t mapversion=7; // JBF 20040211: default mapversion to 7
int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new) int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new)
uint8_t g_loadedMapMD4[16];
int32_t compare_usermaphacks(const void *a, const void *b)
{
return Bmemcmp(((usermaphack_t*) a)->md4, ((usermaphack_t*) b)->md4, 16);
}
usermaphack_t *usermaphacks;
int32_t num_usermaphacks;
static int32_t get_mapversion(void); static int32_t get_mapversion(void);
@ -9225,6 +9233,15 @@ void uninitengine(void)
#endif #endif
uninitsystem(); uninitsystem();
for (i = 0; i < num_usermaphacks; i++)
{
if (usermaphacks[i].mhkfile)
Bfree(usermaphacks[i].mhkfile);
if (usermaphacks[i].title)
Bfree(usermaphacks[i].title);
}
Bfree(usermaphacks);
} }
@ -10586,6 +10603,8 @@ static void check_sprite(int32_t i)
LUNATIC_CB int32_t (*loadboard_maptext)(int32_t fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum); LUNATIC_CB int32_t (*loadboard_maptext)(int32_t fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum);
#endif #endif
#include "md4.h"
// flags: 1, 2: former parameter "fromwhere" // flags: 1, 2: former parameter "fromwhere"
// 4: don't call polymer_loadboard // 4: don't call polymer_loadboard
// 8: don't autoexec <mapname>.cfg // 8: don't autoexec <mapname>.cfg
@ -10733,6 +10752,13 @@ int32_t loadboard(const char *filename, char flags, vec3_t *dapos, int16_t *daan
#ifdef NEW_MAP_FORMAT #ifdef NEW_MAP_FORMAT
skip_reading_mapbin: skip_reading_mapbin:
#endif #endif
klseek(fil, 0, SEEK_SET);
int32_t boardsize = kfilelength(fil);
uint8_t *fullboard = (uint8_t*)Xmalloc(boardsize);
kread(fil, fullboard, boardsize);
md4once(fullboard, boardsize, g_loadedMapMD4);
kclose(fil); kclose(fil);
// Done reading file. // Done reading file.
@ -10783,6 +10809,8 @@ skip_reading_mapbin:
E_MapArt_Setup(filename); E_MapArt_Setup(filename);
} }
// initprintf("Loaded map \"%s\" (md4sum: %08x%08x%08x%08x)\n", filename, B_BIG32(*((int32_t*)&md4out[0])), B_BIG32(*((int32_t*)&md4out[4])), B_BIG32(*((int32_t*)&md4out[8])), B_BIG32(*((int32_t*)&md4out[12])));
return finish_loadboard(dapos, dacursectnum, numsprites, myflags); return finish_loadboard(dapos, dacursectnum, numsprites, myflags);
} }
@ -18009,7 +18037,7 @@ void hash_add(hashtable_t *t, const char *s, intptr_t key, int32_t replace)
hashitem_t *cur, *prev=NULL; hashitem_t *cur, *prev=NULL;
int32_t code; int32_t code;
if (t->items == NULL) if (EDUKE32_PREDICT_FALSE(t->items == NULL))
{ {
initprintf("hash_add(): table not initialized!\n"); initprintf("hash_add(): table not initialized!\n");
return; return;

View file

@ -1695,6 +1695,15 @@ void G_FadeLoad(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int
} }
} }
static int32_t G_TryMapHack(const char *mhkfile)
{
int32_t retval = loadmaphack(mhkfile);
if (!retval)
initprintf("Loaded map hack file \"%s\"\n", mhkfile);
return retval;
}
static void G_LoadMapHack(char *outbuf, const char *filename) static void G_LoadMapHack(char *outbuf, const char *filename)
{ {
@ -1703,8 +1712,12 @@ static void G_LoadMapHack(char *outbuf, const char *filename)
append_ext_UNSAFE(outbuf, ".mhk"); append_ext_UNSAFE(outbuf, ".mhk");
if (!loadmaphack(outbuf)) if (G_TryMapHack(outbuf))
initprintf("Loaded map hack file \"%s\"\n",outbuf); {
usermaphack_t *mapinfo = (usermaphack_t*)bsearch(g_loadedMapMD4 - offsetof(usermaphack_t, md4), usermaphacks, num_usermaphacks, sizeof(usermaphack_t), compare_usermaphacks);
if (mapinfo)
G_TryMapHack(mapinfo->mhkfile);
}
} }
static void G_ReallocCopyMusicName(int32_t level_number, const char *levnamebuf, int32_t altp) static void G_ReallocCopyMusicName(int32_t level_number, const char *levnamebuf, int32_t altp)