Fix LoadMarksurfaces loads

This commit is contained in:
Denis Pauk 2023-10-14 17:17:03 +03:00
parent c91dc0b9b2
commit b54dc5559d
4 changed files with 51 additions and 25 deletions

View file

@ -2126,7 +2126,7 @@ Mod_LoadMarksurfaces(const char *name, msurface_t ***marksurfaces, unsigned int
{
int j;
j = LittleShort(in[i]);
j = LittleShort(in[i]) & 0xFFFF;
if ((j < 0) || (j >= numsurfaces))
{
@ -2163,7 +2163,7 @@ Mod_LoadQMarksurfaces(const char *name, msurface_t ***marksurfaces, unsigned int
for (i = 0; i < count; i++)
{
int j;
j = LittleLong(in[i]);
j = LittleLong(in[i]) & 0xFFFFFFFF;
if ((j < 0) || (j >= numsurfaces))
{
@ -2209,7 +2209,7 @@ Mod_LoadLeafs(const char *name, mleaf_t **leafs, int *numleafs,
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
out = Hunk_Alloc((count + EXTRA_LUMP_LEAFS) * sizeof(*out));
*leafs = out;
*numleafs = count;
@ -2259,7 +2259,7 @@ Mod_LoadQLeafs(const char *name, mleaf_t **leafs, int *numleafs,
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
out = Hunk_Alloc((count + EXTRA_LUMP_LEAFS) * sizeof(*out));
*leafs = out;
*numleafs = count;

View file

@ -68,6 +68,7 @@ LM_UploadBlock(qboolean dynamic)
{
if (vk_state.lightmap_textures[texture].resource.image != VK_NULL_HANDLE)
{
/* FIXME: Incorrect lightmap load: mgu3m2 */
QVk_UpdateTextureData(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT);
}
else

View file

@ -618,7 +618,7 @@ CM_TransformedPointContents(vec3_t p, int headnode,
l = CM_PointLeafnum_r(p_l, headnode);
if (!cmod.map_leafs || l > cmod.numleafs || l < 0)
if (!cmod.map_leafs || l >= (cmod.numleafs + EXTRA_LUMP_LEAFS) || l < 0)
{
return 0;
}
@ -849,11 +849,15 @@ CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
static void
CM_TraceToLeaf(int leafnum)
{
int k;
int brushnum;
int k, maxleaf, brushnum;
cleaf_t *leaf;
cbrush_t *b;
if (leafnum >= (cmod.numleafs + EXTRA_LUMP_LEAFS) || leafnum < 0)
{
Com_DPrintf("%s: Incorrect leaf number!\n", __func__);
}
leaf = &cmod.map_leafs[leafnum];
if (!(leaf->contents & trace_contents) || !cmod.numleafbrushes)
@ -861,15 +865,23 @@ CM_TraceToLeaf(int leafnum)
return;
}
maxleaf = leaf->firstleafbrush + leaf->numleafbrushes;
if (maxleaf >= (cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES))
{
Com_Error(ERR_FATAL, "%s: broken leaf! %d > %d\n",
__func__, maxleaf, cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES);
}
/* trace line against all brushes in the leaf */
for (k = 0; k < leaf->numleafbrushes; k++)
{
if ((leaf->firstleafbrush + k) > (cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES))
brushnum = cmod.map_leafbrushes[leaf->firstleafbrush + k];
if (brushnum < 0 || brushnum >= (cmod.numbrushes + EXTRA_LUMP_BRUSHES))
{
Com_Error(ERR_FATAL, "%s: broken leaf!\n", __func__);
Com_Error(ERR_FATAL, "%s: incorrect brushnum in leaf!\n", __func__);
}
brushnum = cmod.map_leafbrushes[leaf->firstleafbrush + k];
b = &cmod.map_brushes[brushnum];
if (b->checkcount == checkcount)
@ -897,11 +909,15 @@ CM_TraceToLeaf(int leafnum)
static void
CM_TestInLeaf(int leafnum)
{
int k;
int brushnum;
int k, maxleaf, brushnum;
cleaf_t *leaf;
cbrush_t *b;
if (leafnum > (cmod.numleafs + EXTRA_LUMP_LEAFS) || leafnum < 0)
{
Com_DPrintf("%s: Incorrect leaf number!\n", __func__);
}
leaf = &cmod.map_leafs[leafnum];
if (!(leaf->contents & trace_contents) || !cmod.numleafbrushes)
@ -909,15 +925,23 @@ CM_TestInLeaf(int leafnum)
return;
}
maxleaf = leaf->firstleafbrush + leaf->numleafbrushes;
if (maxleaf >= (cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES))
{
Com_Error(ERR_FATAL, "%s: broken leaf! %d > %d\n",
__func__, maxleaf, cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES);
}
/* trace line against all brushes in the leaf */
for (k = 0; k < leaf->numleafbrushes; k++)
{
if ((leaf->firstleafbrush + k) > (cmod.numleafbrushes + EXTRA_LUMP_LEAFBRUSHES))
brushnum = cmod.map_leafbrushes[leaf->firstleafbrush + k];
if (brushnum < 0 || brushnum >= (cmod.numbrushes + EXTRA_LUMP_BRUSHES))
{
Com_Error(ERR_FATAL, "%s: broken leaf!\n", __func__);
Com_Error(ERR_FATAL, "%s: incorrect brushnum in leaf!\n", __func__);
}
brushnum = cmod.map_leafbrushes[leaf->firstleafbrush + k];
b = &cmod.map_brushes[brushnum];
if (b->checkcount == checkcount)
@ -1453,7 +1477,7 @@ CMod_LoadLeafs(const char *name, cleaf_t **map_leafs, int *numleafs, int *emptyl
Com_Error(ERR_DROP, "%s: Map %s with no leafs", __func__, name);
}
out = *map_leafs = Hunk_Alloc(count * sizeof(*out));
out = *map_leafs = Hunk_Alloc((count + EXTRA_LUMP_LEAFS) * sizeof(*out));
*numleafs = count;
*numclusters = 0;
@ -1462,8 +1486,8 @@ CMod_LoadLeafs(const char *name, cleaf_t **map_leafs, int *numleafs, int *emptyl
out->contents = LittleLong(in->contents);
out->cluster = LittleShort(in->cluster);
out->area = LittleShort(in->area);
out->firstleafbrush = LittleShort(in->firstleafbrush);
out->numleafbrushes = LittleShort(in->numleafbrushes);
out->firstleafbrush = LittleShort(in->firstleafbrush) & 0xFFFF;
out->numleafbrushes = LittleShort(in->numleafbrushes) & 0xFFFF;
if (out->cluster >= *numclusters)
{
@ -1516,7 +1540,7 @@ CMod_LoadQLeafs(const char *name, cleaf_t **map_leafs, int *numleafs, int *empty
Com_Error(ERR_DROP, "%s: Map with no leafs", __func__);
}
out = *map_leafs = Hunk_Alloc(count * sizeof(*out));
out = *map_leafs = Hunk_Alloc((count + EXTRA_LUMP_LEAFS) * sizeof(*out));
*numleafs = count;
*numclusters = 0;
@ -1525,8 +1549,8 @@ CMod_LoadQLeafs(const char *name, cleaf_t **map_leafs, int *numleafs, int *empty
out->contents = LittleLong(in->contents);
out->cluster = LittleLong(in->cluster);
out->area = LittleLong(in->area);
out->firstleafbrush = LittleLong(in->firstleafbrush);
out->numleafbrushes = LittleLong(in->numleafbrushes);
out->firstleafbrush = LittleLong(in->firstleafbrush) & 0xFFFFFFFF;
out->numleafbrushes = LittleLong(in->numleafbrushes) & 0xFFFFFFFF;
if (out->cluster >= *numclusters)
{
@ -2105,7 +2129,7 @@ CM_EntityString(void)
int
CM_LeafContents(int leafnum)
{
if ((leafnum < 0) || (leafnum >= cmod.numleafs))
if ((leafnum < 0) || (leafnum >= (cmod.numleafs + EXTRA_LUMP_LEAFS)))
{
Com_Error(ERR_DROP, "%s: bad number", __func__);
}
@ -2116,7 +2140,7 @@ CM_LeafContents(int leafnum)
int
CM_LeafCluster(int leafnum)
{
if ((leafnum < 0) || (leafnum >= cmod.numleafs))
if ((leafnum < 0) || (leafnum >= (cmod.numleafs + EXTRA_LUMP_LEAFS)))
{
Com_Error(ERR_DROP, "%s: bad number", __func__);
}
@ -2127,7 +2151,7 @@ CM_LeafCluster(int leafnum)
int
CM_LeafArea(int leafnum)
{
if ((leafnum < 0) || (leafnum >= cmod.numleafs))
if ((leafnum < 0) || (leafnum >= (cmod.numleafs + EXTRA_LUMP_LEAFS)))
{
Com_Error(ERR_DROP, "%s: bad number", __func__);
}

View file

@ -33,10 +33,11 @@
#define EXTRA_LUMP_EDGES 13
#define EXTRA_LUMP_FACES 6
#define EXTRA_LUMP_PLANES 12
#define EXTRA_LUMP_LEAFBRUSHES 1
#define EXTRA_LUMP_LEAFBRUSHES 2
#define EXTRA_LUMP_BRUSHES 1
#define EXTRA_LUMP_NODES 6
#define EXTRA_LUMP_BRUSHSIDES 6
#define EXTRA_LUMP_LEAFS 1
extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra);
extern void Mod_LoadVisibility(const char *name, dvis_t **vis, int *numvisibility,