mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
Implement UserMapHacks.
git-svn-id: https://svn.eduke32.com/eduke32@4884 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
3f846bdde3
commit
589c993c39
4 changed files with 88 additions and 13 deletions
|
@ -649,6 +649,16 @@ typedef struct {
|
|||
EXTERN int32_t guniqhudid;
|
||||
EXTERN int32_t spritesortcnt;
|
||||
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
|
||||
EXTERN spriteext_t *spriteext;
|
||||
|
|
|
@ -273,7 +273,7 @@ static int32_t defsparser(scriptfile *script)
|
|||
{ "cachesize", T_CACHESIZE },
|
||||
{ "dummytilefrompic",T_IMPORTTILE },
|
||||
{ "tilefromtexture", T_TILEFROMTEXTURE },
|
||||
{ "mapinfo", T_MAPINFO }, // dummy
|
||||
{ "mapinfo", T_MAPINFO },
|
||||
{ "echo", T_ECHO },
|
||||
};
|
||||
|
||||
|
@ -2134,7 +2134,7 @@ static int32_t defsparser(scriptfile *script)
|
|||
|
||||
case T_MAPINFO:
|
||||
{
|
||||
char *dummy, *dummy2;
|
||||
char *mapmd4string = NULL, *title = NULL, *mhkfile = NULL, *mapinfoend, *dummy;
|
||||
static const tokenlist mapinfotokens[] =
|
||||
{
|
||||
{ "mapfile", T_MAPFILE },
|
||||
|
@ -2142,25 +2142,47 @@ static int32_t defsparser(scriptfile *script)
|
|||
{ "mapmd4", T_MAPMD4 },
|
||||
{ "mhkfile", T_MHKFILE },
|
||||
};
|
||||
int32_t previous_usermaphacks = num_usermaphacks;
|
||||
|
||||
if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&dummy))) break;
|
||||
while (script->textptr < dummy)
|
||||
if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&mapinfoend))) break;
|
||||
while (script->textptr < mapinfoend)
|
||||
{
|
||||
switch (getatoken(script,mapinfotokens,ARRAY_SIZE(mapinfotokens)))
|
||||
{
|
||||
case T_MAPFILE:
|
||||
scriptfile_getstring(script,&dummy2);
|
||||
scriptfile_getstring(script,&dummy);
|
||||
break;
|
||||
case T_MAPTITLE:
|
||||
scriptfile_getstring(script,&dummy2);
|
||||
scriptfile_getstring(script,&title);
|
||||
break;
|
||||
case T_MAPMD4:
|
||||
scriptfile_getstring(script,&dummy2);
|
||||
break;
|
||||
case T_MHKFILE:
|
||||
scriptfile_getstring(script,&dummy2);
|
||||
{
|
||||
scriptfile_getstring(script,&mapmd4string);
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
@ -2212,6 +2234,8 @@ int32_t loaddefinitionsfile(const char *fn)
|
|||
DO_FREE_AND_NULL(faketilebuffer);
|
||||
faketilebuffersiz = 0;
|
||||
|
||||
qsort(usermaphacks, num_usermaphacks, sizeof(usermaphack_t), compare_usermaphacks);
|
||||
|
||||
if (!script) return -1;
|
||||
|
||||
initprintf("\n");
|
||||
|
|
|
@ -82,6 +82,14 @@ float debug1, debug2;
|
|||
|
||||
int32_t mapversion=7; // JBF 20040211: default mapversion to 7
|
||||
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);
|
||||
|
||||
|
@ -9225,6 +9233,15 @@ void uninitengine(void)
|
|||
#endif
|
||||
|
||||
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);
|
||||
#endif
|
||||
|
||||
#include "md4.h"
|
||||
|
||||
// flags: 1, 2: former parameter "fromwhere"
|
||||
// 4: don't call polymer_loadboard
|
||||
// 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
|
||||
skip_reading_mapbin:
|
||||
#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);
|
||||
// Done reading file.
|
||||
|
||||
|
@ -10783,6 +10809,8 @@ skip_reading_mapbin:
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -18009,7 +18037,7 @@ void hash_add(hashtable_t *t, const char *s, intptr_t key, int32_t replace)
|
|||
hashitem_t *cur, *prev=NULL;
|
||||
int32_t code;
|
||||
|
||||
if (t->items == NULL)
|
||||
if (EDUKE32_PREDICT_FALSE(t->items == NULL))
|
||||
{
|
||||
initprintf("hash_add(): table not initialized!\n");
|
||||
return;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -1703,8 +1712,12 @@ static void G_LoadMapHack(char *outbuf, const char *filename)
|
|||
|
||||
append_ext_UNSAFE(outbuf, ".mhk");
|
||||
|
||||
if (!loadmaphack(outbuf))
|
||||
initprintf("Loaded map hack file \"%s\"\n",outbuf);
|
||||
if (G_TryMapHack(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)
|
||||
|
|
Loading…
Reference in a new issue