1
0
Fork 0
forked from fte/fteqw

Move model loaders over to variable-length file-magics.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6104 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2021-11-03 20:31:32 +00:00
parent ab2dc14f49
commit 022e42c6c7
15 changed files with 101 additions and 110 deletions

View file

@ -1168,11 +1168,11 @@ static qboolean CL_CheckModelResources (char *name)
{
return false; // couldn't load it
}
if (LittleLong(*(unsigned *)file) == MD2IDALIASHEADER)
if (!memcmp(file, MD2IDALIASHEADER))
ret = CL_CheckMD2Skins(file);
else if (LittleLong(*(unsigned *)file) == BSPVERSIONHL)
else if (!memcmp(file, BSPVERSIONHL))
ret = CL_CheckHLBspWads(file);
else if (LittleLong(*(unsigned *)file) == IDBSPHEADER)
else if (!memcmp(file, IDBSPHEADER))
ret = CL_CheckQ2BspWals(file);
else
ret = false;

View file

@ -151,8 +151,8 @@ typedef struct {
aliasskintype_t type;
} daliasskintype_t;
#define IDPOLYHEADER (('O'<<24)+('P'<<16)+('D'<<8)+'I') /*little-endian "IDPO"*/
#define RAPOLYHEADER (('O'<<24)+('P'<<16)+('A'<<8)+'R') /*used by hexen2 mp*/
#define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I') /*quake3, duh*/
#define IDPOLYHEADER "IDPO",4 /*little-endian "IDPO"*/
#define RAPOLYHEADER "RAPO",4 /*used by hexen2 mp*/
#define MD3_IDENT "IDP3",4 /*quake3, duh*/

View file

@ -565,7 +565,7 @@ void GLR_LoadSkys (void);
void R_BloomRegister(void);
int Mod_RegisterModelFormatText(void *module, const char *formatname, char *magictext, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
int Mod_RegisterModelFormatMagic(void *module, const char *formatname, unsigned int magic, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
int Mod_RegisterModelFormatMagic(void *module, const char *formatname, qbyte *magic, size_t magicsize, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
void Mod_UnRegisterModelFormat(void *module, int idx);
void Mod_UnRegisterAllModelFormats(void *module);
void Mod_ModelLoaded(void *ctx, void *data, size_t a, size_t b);

View file

@ -118,7 +118,7 @@ typedef struct {
spriteframetype_t type;
} dspriteframetype_t;
#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I')
#define IDSPRITEHEADER "IDSP",4
// little-endian "IDSP"
@ -129,7 +129,7 @@ typedef struct {
#define MAX_SKINNAME 64
#define IDSPRITE2HEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
#define IDSPRITE2HEADER "IDS2",4
// little-endian "IDS2"
#define SPRITE2_VERSION 2

View file

@ -67,14 +67,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//=============================================================================
#define BSPVERSIONQTEST 23
#define BSPVERSIONPREREL 28
#define BSPVERSION 29
//HalfLife support
#define BSPVERSIONHL 30
#define BSPVERSION_LONG1 (('B' << 24) | ('S' << 16) | ('P' << 8) | '2') /*RMQ support (2PSB). 32bits instead of shorts for all but bbox sizes*/
#define BSPVERSION_LONG2 (('B' << 0) | ('S' << 8) | ('P' << 16) | ('2'<<24)) /*BSP2 support. 32bits instead of shorts for everything*/
#define BSPVERSIONQ64 (('Q' << 24) | ('6' << 16) | ('4' << 8) | (' ' << 0)) /* Remastered BSP format used for Quake 64 addon */
#define BSPVERSIONQTEST "\x17\0\0\0",4 //qtest
#define BSPVERSIONPREREL "\x1C\0\0\0",4 //prerelease
#define BSPVERSION "\x1D\0\0\0",4 //vanilla
#define BSPVERSIONHL "\x1E\0\0\0",4 //HalfLife support
#define BSPVERSION_LONG1 "2PSB",4 /*RMQ support (2PSB). 32bits instead of shorts for all but bbox sizes*/
#define BSPVERSION_LONG2 "BSP2",4 /*BSP2 support. 32bits instead of shorts for everything*/
#define BSPVERSIONQ64 " 46Q",4 /* Remastered BSP format used for Quake 64 addon */
typedef struct
{
@ -379,7 +378,7 @@ typedef struct q2miptex_s
==============================================================================
*/
#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
#define IDBSPHEADER "IBSP",4
// little-endian "IBSP"
#define BSPVERSION_Q2 38

View file

@ -1742,7 +1742,11 @@ qboolean Alias_GAliasBuildMesh(mesh_t *mesh, vbo_t **vbop, galiasinfo_t *inf, in
mesh->snormals_array = meshcache.anorms;
mesh->tnormals_array = meshcache.anormt;
if (vbop)
{
*vbop = meshcache.vbop;
meshcache.vbo.indicies = inf->vboindicies;
meshcache.vbo.indexcount = inf->numindexes;
}
#ifndef SKELETALMODELS
return false;
@ -4357,7 +4361,7 @@ static int Mod_ReadFlagsFromMD1(char *name, int md3version)
pinmodel = (dmdl_t *)FS_LoadMallocFile(fname, &fsize);
if (pinmodel)
{
if (fsize >= sizeof(dmdl_t) && LittleLong(pinmodel->ident) == IDPOLYHEADER)
if (fsize >= sizeof(dmdl_t) && !memcmp(&pinmodel->ident, IDPOLYHEADER))
if (LittleLong(pinmodel->version) == ALIAS_VERSION)
result = LittleLong(pinmodel->flags);
BZ_Free(pinmodel);
@ -4718,7 +4722,7 @@ typedef struct
int offsetEnd;
} dmdxheader_t;
#define MDX_IDENT ('I'<<0)+('D'<<8)+('P'<<16)+('X'<<24)
#define MDX_IDENT "IDPX",4
#define MDX_VERSION 4
#define Q2NUMVERTEXNORMALS 162
@ -5931,7 +5935,7 @@ static galiasinfo_t *Mod_LoadQ3ModelLod(model_t *mod, int *surfcount, void *buff
surf = (md3Surface_t *)((qbyte *)header + LittleLong(header->ofsSurfaces));
for (s = 0; s < LittleLong(header->numSurfaces); s++, *surfcount+=1)
{
if (LittleLong(surf->ident) != MD3_IDENT)
if (memcmp(&surf->ident, MD3_IDENT))
Con_Printf(CON_WARNING "Warning: md3 sub-surface doesn't match ident\n");
if (!framegroups)
@ -9982,7 +9986,7 @@ void Alias_Register(void)
Cvar_Register(&dpcompat_nofloodfill, NULL);
#endif
Mod_RegisterModelFormatMagic(NULL, "Quake1 Model (mdl)", IDPOLYHEADER, Mod_LoadQ1Model);
Mod_RegisterModelFormatMagic(NULL, "QuakeForge 16bit Model", (('6'<<24)+('1'<<16)+('D'<<8)+'M'), Mod_LoadQ1Model);
Mod_RegisterModelFormatMagic(NULL, "QuakeForge 16bit Model", "MD16",4, Mod_LoadQ1Model);
#ifdef HEXEN2
Mod_RegisterModelFormatMagic(NULL, "Hexen2 Model (mdl)", RAPOLYHEADER, Mod_LoadQ1Model);
#endif
@ -9997,20 +10001,20 @@ void Alias_Register(void)
Mod_RegisterModelFormatMagic(NULL, "Quake3 Model (md3)", MD3_IDENT, Mod_LoadQ3Model);
#endif
#ifdef HALFLIFEMODELS
Mod_RegisterModelFormatMagic(NULL, "Half-Life Model (mdl)", (('T'<<24)+('S'<<16)+('D'<<8)+'I'), Mod_LoadHLModel);
Mod_RegisterModelFormatMagic(NULL, "Half-Life Model (mdl)", "IDST\x0a\0\0\0",8, Mod_LoadHLModel);
#endif
#ifdef ZYMOTICMODELS
Mod_RegisterModelFormatMagic(NULL, "Zymotic Model (zym)", (('O'<<24)+('M'<<16)+('Y'<<8)+'Z'), Mod_LoadZymoticModel);
Mod_RegisterModelFormatMagic(NULL, "Zymotic Model (zym)", "ZYMOTICMODEL",12, Mod_LoadZymoticModel);
#endif
#ifdef DPMMODELS
Mod_RegisterModelFormatMagic(NULL, "DarkPlaces Model (dpm)", (('K'<<24)+('R'<<16)+('A'<<8)+'D'), Mod_LoadDarkPlacesModel);
Mod_RegisterModelFormatMagic(NULL, "DarkPlaces Model (dpm)", "DARKPLACESMODEL\0",16, Mod_LoadDarkPlacesModel);
#endif
#ifdef PSKMODELS
Mod_RegisterModelFormatMagic(NULL, "Unreal Interchange Model (psk)", ('A'<<0)+('C'<<8)+('T'<<16)+('R'<<24), Mod_LoadPSKModel);
Mod_RegisterModelFormatMagic(NULL, "Unreal Interchange Model (psk)", "ACTR",4, Mod_LoadPSKModel);
#endif
#ifdef INTERQUAKEMODELS
Mod_RegisterModelFormatMagic(NULL, "Inter-Quake Model (iqm)", ('I'<<0)+('N'<<8)+('T'<<16)+('E'<<24), Mod_LoadInterQuakeModel);
Mod_RegisterModelFormatMagic(NULL, "Inter-Quake Model (iqm)", "INTERQUAKEMODEL\0",16, Mod_LoadInterQuakeModel);
#endif
#ifdef MD5MODELS
Cvar_Register(&mod_md5_singleanimation, NULL);
@ -10018,7 +10022,7 @@ void Alias_Register(void)
Mod_RegisterModelFormatText(NULL, "External Anim", "EXTERNALANIM", Mod_LoadCompositeAnim);
#endif
#ifdef MODELFMT_OBJ
Mod_RegisterModelFormatText(NULL, "Wavefront Object (obj)", ".obj", Mod_LoadObjModel);
Mod_RegisterModelFormatText(NULL, "Wavefront Object (obj)", ".obj", Mod_LoadObjModel);
Cvar_Register(&mod_obj_orientation, NULL);
#endif

View file

@ -229,12 +229,11 @@ typedef struct modplugfuncs_s
//format handling
int (QDECL *RegisterModelFormatText)(const char *formatname, char *magictext, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
int (QDECL *RegisterModelFormatMagic)(const char *formatname, unsigned int magic, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
int (QDECL *RegisterModelFormatMagic)(const char *formatname, qbyte *magic,size_t magicsize, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize));
void (QDECL *UnRegisterModelFormat)(int idx);
void (QDECL *UnRegisterAllModelFormats)(void);
//util
void *(QDECL *ZG_Malloc)(zonegroup_t *ctx, size_t size); //ctx=&mod->memgroup and the data will be freed when the model is freed.
void (QDECL *StripExtension) (const char *in, char *out, int outlen);
//matrix maths
@ -255,7 +254,7 @@ typedef struct modplugfuncs_s
model_t *(QDECL *GetModel)(const char *identifier, enum mlverbosity_e verbosity);
#define plugmodfuncs_name "Models"
} plugmodfuncs_t;
#define MODPLUGFUNCS_VERSION 1
#define MODPLUGFUNCS_VERSION 2
#ifdef SKELETALMODELS
void Alias_TransformVerticies(float *bonepose, galisskeletaltransforms_t *weights, int numweights, vecV_t *xyzout, vec3_t *normout);

View file

@ -56,10 +56,10 @@ static int QDECL Plug_RegisterModelFormatText(const char *formatname, char *magi
void *module = currentplug;
return Mod_RegisterModelFormatText(module, formatname, magictext, load);
}
static int QDECL Plug_RegisterModelFormatMagic(const char *formatname, unsigned int magic, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize))
static int QDECL Plug_RegisterModelFormatMagic(const char *formatname, qbyte *magic, size_t magicsize, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize))
{
void *module = currentplug;
return Mod_RegisterModelFormatMagic(module, formatname, magic, load);
return Mod_RegisterModelFormatMagic(module, formatname, magic, magicsize, load);
}
static void QDECL Plug_UnRegisterModelFormat(int idx)
{
@ -1871,6 +1871,7 @@ static void *QDECL PlugBI_GetEngineInterface(const char *interfacename, size_t s
wildcmp,
COM_CleanUpPath,
Com_BlockChecksum,
FS_LoadMallocFile,
};
if (structsize == sizeof(funcs))
return &funcs;
@ -2062,7 +2063,6 @@ static void *QDECL PlugBI_GetEngineInterface(const char *interfacename, size_t s
Plug_UnRegisterModelFormat,
Plug_UnRegisterAllModelFormats,
ZG_Malloc,
COM_StripExtension,
R_ConcatTransforms,

View file

@ -2610,7 +2610,7 @@ qboolean Mod_BSPXRW_Read(struct bspxrw *ctx, const char *fname)
ctx->lumpofs = 4;
ctx->corelumps = 0;
break;
case IDBSPHEADER:
case ('I'<<0)+('B'<<8)+('S'<<16)+('P'<<24):
i = LittleLong(*(int*)(ctx->origfile+4));
ctx->lumpofs = 8;
switch(i)

View file

@ -704,14 +704,14 @@ void Mod_Init (qboolean initial)
#endif
#endif
#ifdef RFBSPS
Mod_RegisterModelFormatMagic(NULL, "Raven Map (bsp)", ('R'<<0)+('B'<<8)+('S'<<16)+('P'<<24), Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "QFusion Map (bsp)", ('F'<<0)+('B'<<8)+('S'<<16)+('P'<<24), Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "Raven Map (bsp)", "RBSP",4, Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "QFusion Map (bsp)", "FBSP",4, Mod_LoadQ2BrushModel);
#endif
//doom maps
#ifdef MAP_DOOM
Mod_RegisterModelFormatMagic(NULL, "Doom IWad Map", (('D'<<24)+('A'<<16)+('W'<<8)+'I'), Mod_LoadDoomLevel);
Mod_RegisterModelFormatMagic(NULL, "Doom PWad Map", (('D'<<24)+('A'<<16)+('W'<<8)+'P'), Mod_LoadDoomLevel);
Mod_RegisterModelFormatMagic(NULL, "Doom IWad Map", "IWAD",4, Mod_LoadDoomLevel);
Mod_RegisterModelFormatMagic(NULL, "Doom PWad Map", "PWAD",4, Mod_LoadDoomLevel);
#endif
#ifdef MAP_PROC
@ -893,7 +893,8 @@ static struct
void *module;
char *formatname;
char *ident;
unsigned int magic;
qbyte *magic;
size_t magicsize;
qboolean (QDECL *load) (model_t *mod, void *buffer, size_t buffersize);
} modelloaders[64];
@ -925,18 +926,19 @@ int Mod_RegisterModelFormatText(void *module, const char *formatname, char *magi
modelloaders[free].module = module;
modelloaders[free].formatname = Z_StrDup(formatname);
modelloaders[free].magic = 0;
modelloaders[free].magic = NULL;
modelloaders[free].magicsize = 0;
modelloaders[free].ident = Z_StrDup(magictext);
modelloaders[free].load = load;
return free+1;
}
int Mod_RegisterModelFormatMagic(void *module, const char *formatname, unsigned int magic, qboolean (QDECL *load) (model_t *mod, void *buffer, size_t fsize))
int Mod_RegisterModelFormatMagic(void *module, const char *formatname, qbyte *magic, size_t magicsize, qboolean (QDECL *load) (model_t *mod, void *buffer, size_t fsize))
{
int i, free = -1;
for (i = 0; i < sizeof(modelloaders)/sizeof(modelloaders[0]); i++)
{
if (modelloaders[i].magic && modelloaders[i].magic == magic)
if (modelloaders[i].magic && modelloaders[i].magicsize == magicsize && !memcmp(modelloaders[i].magic, magic, magicsize))
{
free = i;
break; //extension match always replaces
@ -952,6 +954,7 @@ int Mod_RegisterModelFormatMagic(void *module, const char *formatname, unsigned
Z_Free(modelloaders[free].formatname);
modelloaders[free].formatname = Z_StrDup(formatname);
modelloaders[free].magic = magic;
modelloaders[free].magicsize = magicsize;
modelloaders[free].ident = NULL;
modelloaders[free].load = load;
@ -1077,7 +1080,7 @@ static void Mod_LoadModelWorker (void *ctx, void *data, size_t a, size_t b)
#ifdef DSPMODELS
qboolean doomsprite = false;
#endif
unsigned int magic, i;
unsigned int i;
size_t filesize;
char ext[8];
int basedepth;
@ -1267,10 +1270,6 @@ static void Mod_LoadModelWorker (void *ctx, void *data, size_t a, size_t b)
memset(&mod->funcs, 0, sizeof(mod->funcs)); //just in case...
if (filesize < 4)
magic = 0;
else
magic = LittleLong(*(unsigned *)buf);
//look for known extensions first, to try to avoid issues with specific formats
for(i = 0; i < countof(modelloaders); i++)
{
@ -1282,7 +1281,7 @@ static void Mod_LoadModelWorker (void *ctx, void *data, size_t a, size_t b)
{
for(i = 0; i < countof(modelloaders); i++)
{
if (modelloaders[i].load && modelloaders[i].magic == magic && !modelloaders[i].ident)
if (modelloaders[i].load && modelloaders[i].magic && filesize >= modelloaders[i].magicsize && !memcmp(buf, modelloaders[i].magic, modelloaders[i].magicsize) && !modelloaders[i].ident)
break;
}
}
@ -1312,7 +1311,7 @@ static void Mod_LoadModelWorker (void *ctx, void *data, size_t a, size_t b)
}
else
{
Con_Printf(CON_WARNING "Unrecognised model format 0x%x (%c%c%c%c)\n", magic, ((char*)buf)[0], ((char*)buf)[1], ((char*)buf)[2], ((char*)buf)[3]);
Con_Printf(CON_WARNING "Unrecognised model format %c%c%c%c\n", ((char*)buf)[0], ((char*)buf)[1], ((char*)buf)[2], ((char*)buf)[3]);
BZ_Free(buf);
continue;
}
@ -5284,33 +5283,22 @@ static qboolean QDECL Mod_LoadBrushModel (model_t *mod, void *buffer, size_t fsi
isnotmap = true;
#endif
switch(header.version)
{
case BSPVERSIONQ64:
subbsp = sb_quake64;
mod->fromgame = fg_quake;
mod->fromgame = fg_quake;
if (!memcmp(&header.version, BSPVERSION))
mod->engineflags |= MDLF_NEEDOVERBRIGHT;
break;
case BSPVERSION:
case BSPVERSIONPREREL:
mod->fromgame = fg_quake;
else if (!memcmp(&header.version, BSPVERSIONQ64))
mod->engineflags |= MDLF_NEEDOVERBRIGHT, subbsp = sb_quake64;
else if (!memcmp(&header.version, BSPVERSIONPREREL))
mod->engineflags |= MDLF_NEEDOVERBRIGHT;
break;
case BSPVERSION_LONG1:
subbsp = sb_long1;
mod->fromgame = fg_quake;
mod->engineflags |= MDLF_NEEDOVERBRIGHT;
break;
case BSPVERSION_LONG2:
subbsp = sb_long2;
mod->fromgame = fg_quake;
mod->engineflags |= MDLF_NEEDOVERBRIGHT;
break;
case BSPVERSIONHL: //halflife support
else if (!memcmp(&header.version, BSPVERSION_LONG1))
mod->engineflags |= MDLF_NEEDOVERBRIGHT, subbsp = sb_long1;
else if (!memcmp(&header.version, BSPVERSION_LONG2))
mod->engineflags |= MDLF_NEEDOVERBRIGHT, subbsp = sb_long2;
else if (!memcmp(&header.version, BSPVERSIONHL))
mod->fromgame = fg_halflife;
break;
default:
Con_Printf (CON_ERROR "Mod_LoadBrushModel: %s has wrong version number (%i should be %i)\n", mod->name, i, BSPVERSION);
else
{
Con_Printf (CON_ERROR "Mod_LoadBrushModel: %s has wrong version number (%i)\n", mod->name, i);
return false;
}

View file

@ -763,7 +763,7 @@ extern dtrivertx_t *poseverts[MAXALIASFRAMES];
// LordHavoc: grabbed this from the Q2 utility source,
// renamed a things to avoid conflicts
#define MD2IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
#define MD2IDALIASHEADER "IDP2",4
#define MD2ALIAS_VERSION 8
#define MD2MAX_SKINNAME 64 //part of the format

View file

@ -1600,11 +1600,11 @@ static void ImgTool_Enumerate(struct opts_s *args, const char *inname, void(*cal
}
}
else if (fsize >= sizeof(dheader_t) && (
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION ||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSIONHL ||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSIONPREREL||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION_LONG1||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION_LONG2))
!memcmp(indata, BSPVERSION) ||
!memcmp(indata, BSPVERSIONHL) ||
!memcmp(indata, BSPVERSIONPREREL)||
!memcmp(indata, BSPVERSION_LONG1)||
!memcmp(indata, BSPVERSION_LONG2)))
{ //q1bsp
dheader_t *bsp = (dheader_t*)indata;
dmiptexlump_t *texlump = (dmiptexlump_t*)(indata + bsp->lumps[LUMP_TEXTURES].fileofs);
@ -1635,7 +1635,7 @@ static void ImgTool_Enumerate(struct opts_s *args, const char *inname, void(*cal
}
}
else if (fsize >= sizeof(dmdl_t) && (
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == IDPOLYHEADER && (((dmdl_t*)indata)->version == ALIAS_VERSION || ((dmdl_t*)indata)->version == 50)))
!memcmp(indata,IDPOLYHEADER) && (((dmdl_t*)indata)->version == ALIAS_VERSION || ((dmdl_t*)indata)->version == 50)))
{ //quake's mdl format. also hexen2's missionpack format.
int i, j, numframes;
char skinname[256];
@ -2014,11 +2014,11 @@ static void ImgTool_WadExtract(struct opts_s *args, const char *wadname)
}
}
else if (fsize >= sizeof(dheader_t) && (
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION ||
// ((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSIONHL ||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSIONPREREL||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION_LONG1||
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == BSPVERSION_LONG2))
!memcmp(indata, BSPVERSION) ||
// !memcmp(indata, BSPVERSIONHL) ||
!memcmp(indata, BSPVERSIONPREREL)||
!memcmp(indata, BSPVERSION_LONG1)||
!memcmp(indata, BSPVERSION_LONG2)))
{ //q1bsp
dheader_t *bsp = (dheader_t*)indata;
dmiptexlump_t *texlump = (dmiptexlump_t*)(indata + bsp->lumps[LUMP_TEXTURES].fileofs);
@ -2039,7 +2039,7 @@ static void ImgTool_WadExtract(struct opts_s *args, const char *wadname)
}
}
else if (fsize >= sizeof(dmdl_t) && (
((indata[0])|(indata[1]<<8)|(indata[2]<<16)|(indata[3]<<24)) == IDPOLYHEADER && ((dmdl_t*)indata)->version == ALIAS_VERSION))
!memcmp(indata,IDPOLYHEADER) && ((dmdl_t*)indata)->version == ALIAS_VERSION))
{
char imgname[1024];
int i, j, numframes;

View file

@ -4004,11 +4004,11 @@ namespace fte
{ //called explicitly because we're lame.
return 0;
};
cppmodfuncs.RegisterModelFormatMagic = [](const char *formatname, unsigned int magic, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize))
cppmodfuncs.RegisterModelFormatMagic = [](const char *formatname, qbyte *magic, size_t magicsize, qboolean (QDECL *load) (struct model_s *mod, void *buffer, size_t fsize))
{ //called explicitly because we're lame.
return 0;
};
cppmodfuncs.ZG_Malloc = [](zonegroup_t *ctx, size_t size)
cppplugfuncs.GMalloc = [](zonegroup_t *ctx, size_t size)
{
/*leak the memory, because we're lazy*/
void *ret = malloc(size);
@ -4065,7 +4065,7 @@ namespace fte
cppmodfuncs.GetTexture = [](const char *identifier, const char *subpath, unsigned int flags, void *fallbackdata, void *fallbackpalette, int fallbackwidth, int fallbackheight, uploadfmt_t fallbackfmt)
{
image_t *img = (image_t*)cppmodfuncs.ZG_Malloc(NULL, sizeof(*img)+strlen(identifier)+1);
image_t *img = (image_t*)cppplugfuncs.GMalloc(NULL, sizeof(*img)+strlen(identifier)+1);
img->ident = (char*)(img+1);
strcpy(img->ident, identifier);
img->flags = flags;

View file

@ -1140,7 +1140,7 @@ static void *GLTF_AccessorToDataF(gltf_t *gltf, size_t outverts, unsigned int ou
if (ic > outcomponents)
ic = outcomponents;
if (!ret)
ret = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts);
ret = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts);
o = ret;
switch(a->componentType)
{
@ -1296,7 +1296,7 @@ static void *GLTF_AccessorToDataF(gltf_t *gltf, size_t outverts, unsigned int ou
}
static void *GLTF_AccessorToDataUB(gltf_t *gltf, size_t outverts, unsigned int outcomponents, struct gltf_accessor *a)
{ //only used for colour, with fallback to float, so only UNSIGNED_BYTE needs to work.
unsigned char *ret = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts), *o;
unsigned char *ret = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts), *o;
char *in = a->data;
size_t c, ic = a->type&0xff;
@ -1343,7 +1343,7 @@ static void *GLTF_AccessorToDataUB(gltf_t *gltf, size_t outverts, unsigned int o
static void *GLTF_AccessorToDataBone(gltf_t *gltf, size_t outverts, struct gltf_accessor *a)
{ //input should only be ubytes||ushorts.
const unsigned int outcomponents = 4;
boneidx_t *ret = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts), *o;
boneidx_t *ret = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*ret) * outcomponents * outverts), *o;
char *in = a->data;
@ -2027,7 +2027,7 @@ static void GLTF_LoadMaterial(gltf_t *gltf, json_t *materialid, galiasskin_t *re
ret->numframes = 1;
ret->skinspeed = 0.1;
ret->frame = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*ret->frame));
ret->frame = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*ret->frame));
{
int skip;
@ -2264,7 +2264,7 @@ static void GLTF_LoadMaterial(gltf_t *gltf, json_t *materialid, galiasskin_t *re
if (!ret->frame->texnums.base)
ret->frame->texnums.base = modfuncs->GetTexture("$whiteimage", NULL, IF_NOMIPMAP|IF_NOPICMIP|IF_NEAREST|IF_NOGAMMA, NULL, NULL, 0, 0, TF_INVALID);
ret->frame->defaultshader = memcpy(modfuncs->ZG_Malloc(&gltf->mod->memgroup, strlen(shader)+1), shader, strlen(shader)+1);
ret->frame->defaultshader = memcpy(plugfuncs->GMalloc(&gltf->mod->memgroup, strlen(shader)+1), shader, strlen(shader)+1);
Q_strlcpy(ret->name, ret->frame->shadername, sizeof(ret->name));
}
@ -2354,7 +2354,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
if (!vpos.count)
continue;
surf = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*surf) + (morphtargets*sizeof(float)));
surf = plugfuncs->GMalloc(&mod->memgroup, sizeof(*surf) + (morphtargets*sizeof(float)));
surf->surfaceid = JSON_GetInteger(prim, "extras.fte.surfaceid", meshidx);
surf->contents = JSON_GetInteger(prim, "extras.fte.contents", FTECONTENTS_BODY);
@ -2372,7 +2372,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
if (idx.data)
{
surf->numindexes = idx.count;
surf->ofs_indexes = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*surf->ofs_indexes) * idx.count);
surf->ofs_indexes = plugfuncs->GMalloc(&mod->memgroup, sizeof(*surf->ofs_indexes) * idx.count);
if (idx.componentType == 5123)
{ //unsigned shorts
for (i = 0; i < idx.count; i++)
@ -2394,7 +2394,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
else
{
surf->numindexes = surf->numverts;
surf->ofs_indexes = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*surf->ofs_indexes) * surf->numverts);
surf->ofs_indexes = plugfuncs->GMalloc(&mod->memgroup, sizeof(*surf->ofs_indexes) * surf->numverts);
for (i = 0; i < surf->numverts; i++)
surf->ofs_indexes[i] = i;
}
@ -2410,7 +2410,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
surf->AnimateMorphs = GLTF_AnimateMorphs;
memcpy((float*)(surf+1), morphweights, sizeof(float)*morphtargets);
surf->nummorphs = morphtargets;
surf->ofs_skel_xyz = modfuncs->ZG_Malloc(&mod->memgroup, (sizeof(*surf->ofs_skel_xyz)+sizeof(*surf->ofs_skel_norm)+sizeof(*surf->ofs_skel_svect)+sizeof(*surf->ofs_skel_tvect)) * surf->numverts * (1+morphtargets));
surf->ofs_skel_xyz = plugfuncs->GMalloc(&mod->memgroup, (sizeof(*surf->ofs_skel_xyz)+sizeof(*surf->ofs_skel_norm)+sizeof(*surf->ofs_skel_svect)+sizeof(*surf->ofs_skel_tvect)) * surf->numverts * (1+morphtargets));
surf->ofs_skel_norm = (vec3_t*)(surf->ofs_skel_xyz+surf->numverts*(1+morphtargets));
surf->ofs_skel_svect = (vec3_t*)(surf->ofs_skel_norm+surf->numverts*(1+morphtargets));
surf->ofs_skel_tvect = (vec3_t*)(surf->ofs_skel_svect+surf->numverts*(1+morphtargets));
@ -2437,7 +2437,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
surf->ofs_rgbaf = GLTF_AccessorToDataF(gltf, surf->numverts, countof(surf->ofs_rgbaf[0]), &col0, NULL);
/*else
{
surf->ofs_rgbaub = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*surf->ofs_rgbaub) * surf->numverts);
surf->ofs_rgbaub = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*surf->ofs_rgbaub) * surf->numverts);
memset(surf->ofs_rgbaub, 0xff, sizeof(*surf->ofs_rgbaub) * surf->numverts);
}*/
if (sidx.data && swgt.data)
@ -2456,8 +2456,8 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
}
else
{
surf->ofs_skel_idx = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(surf->ofs_skel_idx[0]) * surf->numverts);
surf->ofs_skel_weight = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(surf->ofs_skel_weight[0]) * surf->numverts);
surf->ofs_skel_idx = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(surf->ofs_skel_idx[0]) * surf->numverts);
surf->ofs_skel_weight = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(surf->ofs_skel_weight[0]) * surf->numverts);
for (i = 0; i < surf->numverts; i++)
{
Vector4Set(surf->ofs_skel_idx[i], basebone, 0, 0, 0);
@ -2493,7 +2493,7 @@ static qboolean GLTF_ProcessMesh(gltf_t *gltf, json_t *meshid, int basebone, dou
{
json_t *mapping, *var;
surf->numskins = 1+gltf->variations;
surf->ofsskins = modfuncs->ZG_Malloc(&gltf->mod->memgroup, sizeof(*surf->ofsskins)*surf->numskins);
surf->ofsskins = plugfuncs->GMalloc(&gltf->mod->memgroup, sizeof(*surf->ofsskins)*surf->numskins);
GLTF_LoadMaterial(gltf, JSON_FindChild(prim, "material"), surf->ofsskins, surf->ofs_rgbaub||surf->ofs_rgbaf);
for (i = 0; i < gltf->variations; i++)
surf->ofsskins[1+i] = surf->ofsskins[0]; //unspecified matches defaults...
@ -2813,7 +2813,7 @@ struct gltf_animsampler
static void GLTF_Animation_Persist(gltf_t *gltf, struct gltf_accessor *accessor)
{
model_t *mod = gltf->mod;
qbyte *newdata = modfuncs->ZG_Malloc(&mod->memgroup, accessor->length);
qbyte *newdata = plugfuncs->GMalloc(&mod->memgroup, accessor->length);
memcpy(newdata, accessor->data, accessor->length);
accessor->data = newdata;
}
@ -3373,9 +3373,9 @@ static qboolean GLTF_LoadModel(struct model_s *mod, char *json, size_t jsonsize,
GLTF_RewriteBoneTree(&gltf);
gltfbone = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*gltfbone)*gltf.numbones);
bone = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*bone)*gltf.numbones);
baseframe = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(float)*12*gltf.numbones);
gltfbone = plugfuncs->GMalloc(&mod->memgroup, sizeof(*gltfbone)*gltf.numbones);
bone = plugfuncs->GMalloc(&mod->memgroup, sizeof(*bone)*gltf.numbones);
baseframe = plugfuncs->GMalloc(&mod->memgroup, sizeof(float)*12*gltf.numbones);
for (j = 0; j < gltf.numbones; j++)
{
Q_strlcpy(bone[j].name, gltf.bones[j].name, sizeof(bone[j].name));
@ -3404,7 +3404,7 @@ static qboolean GLTF_LoadModel(struct model_s *mod, char *json, size_t jsonsize,
mergeanims = alloca(sizeof(*mergeanims)*gltf.numbones);
memset(mergeanims, 0, sizeof(mergeanims)*gltf.numbones);
}
framegroups = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*framegroups)*numframegroups);
framegroups = plugfuncs->GMalloc(&mod->memgroup, sizeof(*framegroups)*numframegroups);
anim = JSON_FindChild(gltf.r, "animations")->child;
for (k = 0; k < numframegroups; k++, anim = anim->sibling)
{
@ -3414,7 +3414,7 @@ static qboolean GLTF_LoadModel(struct model_s *mod, char *json, size_t jsonsize,
json_t *params = gltf.ver<=1?JSON_FindChild(anim, "parameters"):0; //gltf1
float maxtime = 0;
unsigned maxposes = 0;
struct galiasanimation_gltf_s *a = modfuncs->ZG_Malloc(&mod->memgroup, sizeof(*a)+sizeof(a->bone[0])*(gltf.numbones-1));
struct galiasanimation_gltf_s *a = plugfuncs->GMalloc(&mod->memgroup, sizeof(*a)+sizeof(a->bone[0])*(gltf.numbones-1));
anim->used = true;
if (!JSON_ReadBody(JSON_FindChild(anim, "name"), fg->name, sizeof(fg->name)))
@ -3663,7 +3663,7 @@ qboolean Plug_GLTF_Init(void)
if (modfuncs && filefuncs)
{
modfuncs->RegisterModelFormatText("glTF models (glTF)", ".gltf", Mod_LoadGLTFModel);
modfuncs->RegisterModelFormatMagic("glTF models (glb)", (('F'<<24)+('T'<<16)+('l'<<8)+'g'), Mod_LoadGLBModel);
modfuncs->RegisterModelFormatMagic("glTF models (glb)", "glTF",4, Mod_LoadGLBModel);
return true;
}
return false;

View file

@ -351,6 +351,7 @@ typedef struct //for plugins that need to read/write files...
F(int, WildCmp, (const char *wild, const char *string));
F(void, CleanUpPath, (char *str));
F(unsigned int,BlockChecksum,(const void *buffer, int length)); //mostly for pack hashes.
F(qbyte*, LoadFile, (const char *fname, size_t *fsize)); //plugfuncs->Free
#define plugfsfuncs_name "Filesystem"
} plugfsfuncs_t;