From 119e1f69934378f73f13227fe93520ac47013acd Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 20 Apr 2024 13:07:19 +0300 Subject: [PATCH] cmodels: extend texture name size to 64 --- src/client/refresh/files/maps.c | 4 +-- src/common/cmodels.c | 43 +++++++++++++++++++++++++++------ src/common/collision.c | 4 +-- src/common/header/files.h | 12 ++++++++- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/client/refresh/files/maps.c b/src/client/refresh/files/maps.c index 73173f6b..9a8ea8a0 100644 --- a/src/client/refresh/files/maps.c +++ b/src/client/refresh/files/maps.c @@ -332,7 +332,7 @@ Mod_LoadTexinfoQ2(const char *name, mtexinfo_t **texinfo, int *numtexinfo, const byte *mod_base, const lump_t *l, findimage_t find_image, struct image_s *notexture) { - texinfo_t *in; + xtexinfo_t *in; mtexinfo_t *out; int i, count; @@ -946,7 +946,7 @@ static int calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl) { dqface_t* face_in = (void *)(mod_base + fl->fileofs); - const texinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); + const xtexinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); if (fl->filelen % sizeof(*face_in) || tl->filelen % sizeof(*texinfo_in)) { diff --git a/src/common/cmodels.c b/src/common/cmodels.c index 1c2131cb..cc7da68a 100644 --- a/src/common/cmodels.c +++ b/src/common/cmodels.c @@ -359,12 +359,13 @@ static void Mod_Load2QBSP_IBSP_TEXINFO(byte *outbuf, dheader_t *outheader, const byte *inbuf, const dheader_t *inheader, size_t rule_size, maptype_t maptype) { - texinfo_t *in, *out; + texinfo_t *in; + xtexinfo_t *out; int i, count; count = inheader->lumps[LUMP_TEXINFO].filelen / rule_size; in = (texinfo_t *)(inbuf + inheader->lumps[LUMP_TEXINFO].fileofs); - out = (texinfo_t *)(outbuf + outheader->lumps[LUMP_TEXINFO].fileofs); + out = (xtexinfo_t *)(outbuf + outheader->lumps[LUMP_TEXINFO].fileofs); for (i = 0; i < count; i++) { @@ -391,12 +392,12 @@ Mod_Load2QBSP_RBSP_TEXINFO(byte *outbuf, dheader_t *outheader, const byte *inbuf const dheader_t *inheader, size_t rule_size, maptype_t maptype) { texrinfo_t *in; - texinfo_t *out; + xtexinfo_t *out; int i, count; count = inheader->lumps[LUMP_TEXINFO].filelen / rule_size; in = (texrinfo_t *)(inbuf + inheader->lumps[LUMP_TEXINFO].fileofs); - out = (texinfo_t *)(outbuf + outheader->lumps[LUMP_TEXINFO].fileofs); + out = (xtexinfo_t *)(outbuf + outheader->lumps[LUMP_TEXINFO].fileofs); for (i = 0; i < count; i++) { @@ -1014,6 +1015,29 @@ static const rule_t qbsplumps[HEADER_LUMPS] = { {sizeof(dareaportal_t), Mod_Load2QBSP_IBSP_AREAPORTALS}, }; +/* custom format with extended texture name */ +static const rule_t xbsplumps[HEADER_LUMPS] = { + {sizeof(char), Mod_Load2QBSP_IBSP_ENTITIES}, + {sizeof(dplane_t), Mod_Load2QBSP_IBSP_PLANES}, + {sizeof(dvertex_t), Mod_Load2QBSP_IBSP_VERTEXES}, + {sizeof(char), Mod_Load2QBSP_IBSP_VISIBILITY}, + {sizeof(dqnode_t), Mod_Load2QBSP_QBSP_NODES}, + {sizeof(xtexinfo_t), Mod_Load2QBSP_IBSP_TEXINFO}, + {sizeof(dqface_t), Mod_Load2QBSP_QBSP_FACES}, + {sizeof(char), Mod_Load2QBSP_IBSP_LIGHTING}, + {sizeof(dqleaf_t), Mod_Load2QBSP_QBSP_LEAFS}, + {sizeof(int), Mod_Load2QBSP_QBSP_LEAFFACES}, + {sizeof(int), Mod_Load2QBSP_QBSP_LEAFBRUSHES}, + {sizeof(dqedge_t), Mod_Load2QBSP_QBSP_EDGES}, + {sizeof(int), Mod_Load2QBSP_IBSP_SURFEDGES}, + {sizeof(dmodel_t), Mod_Load2QBSP_IBSP_MODELS}, + {sizeof(dbrush_t), Mod_Load2QBSP_IBSP_BRUSHES}, + {sizeof(dqbrushside_t), Mod_Load2QBSP_QBSP_BRUSHSIDES}, + {0, NULL}, // LUMP_POP + {sizeof(darea_t), Mod_Load2QBSP_IBSP_AREAS}, + {sizeof(dareaportal_t), Mod_Load2QBSP_IBSP_AREAPORTALS}, +}; + static const char* Mod_MaptypeName(maptype_t maptype) { @@ -1122,7 +1146,7 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len, } result_size += ( - qbsplumps[s].size * header.lumps[s].filelen / rules[s].size + xbsplumps[s].size * header.lumps[s].filelen / rules[s].size ); } } @@ -1189,13 +1213,13 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len, { outheader->lumps[s].fileofs = ofs; outheader->lumps[s].filelen = ( - qbsplumps[s].size * header.lumps[s].filelen / rules[s].size + xbsplumps[s].size * header.lumps[s].filelen / rules[s].size ); ofs += outheader->lumps[s].filelen; } } - if ((filesize - xofs) > 0) + if (filesize > xofs) { bspx_header_t *bspx_header; bspx_lump_t *lump; @@ -1209,6 +1233,11 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len, /* fix positions */ numlumps = LittleLong(bspx_header->numlumps); + if ((numlumps * sizeof(*lump)) >= (filesize - xofs)) + { + Com_Error(ERR_DROP, "%s: Map %s has incorrect bspx lumps", + __func__, name); + } lump = (bspx_lump_t*)(bspx_header + 1); for (i = 0; i < numlumps; i++, lump++) diff --git a/src/common/collision.c b/src/common/collision.c index 55b4a7bb..978d157f 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -1343,7 +1343,7 @@ static void CMod_LoadSurfaces(const char *name, mapsurface_t **map_surfaces, int *numtexinfo, const byte *cmod_base, const lump_t *l) { - texinfo_t *in; + xtexinfo_t *in; mapsurface_t *out; int i, count; @@ -1765,7 +1765,7 @@ CM_LoadCachedMap(const char *name, model_t *mod) strcpy(mod->name, name); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_TEXINFO], - sizeof(texinfo_t), sizeof(mapsurface_t), EXTRA_LUMP_TEXINFO); + sizeof(xtexinfo_t), sizeof(mapsurface_t), EXTRA_LUMP_TEXINFO); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dqleaf_t), sizeof(cleaf_t), 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFBRUSHES], diff --git a/src/common/header/files.h b/src/common/header/files.h index 86fa68e0..d69ac451 100644 --- a/src/common/header/files.h +++ b/src/common/header/files.h @@ -801,7 +801,7 @@ typedef struct unsigned int numfaces; /* counting both sides */ } dqnode_t; -typedef struct texinfo_s +typedef struct { float vecs[2][4]; /* [s/t][xyz offset] */ int flags; /* miptex flags + overrides light emission, etc */ @@ -810,6 +810,16 @@ typedef struct texinfo_s int nexttexinfo; /* for animations, -1 = end of chain */ } texinfo_t; +/* custom extended textinfo */ +typedef struct +{ + float vecs[2][4]; /* [s/t][xyz offset] */ + int flags; /* miptex flags + overrides light emission, etc */ + int value; /* used with some flags, unused in Quake2 */ + char texture[64]; /* texture name (textures*.wal) */ + int nexttexinfo; /* for animations, -1 = end of chain */ +} xtexinfo_t; + /* note that edge 0 is never used, because negative edge nums are used for counterclockwise use of the edge in a face */