Skip to content

Commit

Permalink
game: fix load of Anachronox levant2 map
Browse files Browse the repository at this point in the history
Fields planenum, side, firstedge, numedges has made unsigned.
  • Loading branch information
0lvin committed Sep 21, 2024
1 parent ecb53ba commit 36011a5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/client/refresh/files/maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Mod_LoadQNodes(const char *name, cplane_t *planes, int numplanes, mleaf_t *leafs
out->minmaxs[3 + j] = in->maxs[j];
}

planenum = LittleLong(in->planenum);
planenum = LittleLong(in->planenum) & 0xFFFFFFFF;
if (planenum < 0 || planenum >= numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d < %d planenum.",
Expand Down Expand Up @@ -972,7 +972,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t

for (int surfnum = 0; surfnum < face_count; surfnum++, face_in++)
{
int numverts = face_in->numedges;
unsigned int numverts = face_in->numedges;
int ti = face_in->texinfo;
int texFlags = texinfo_in[ti].flags;
if ((ti < 0) || (ti >= texinfo_count))
Expand Down
7 changes: 4 additions & 3 deletions src/client/refresh/gl1/gl1_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,

for (surfnum = 0; surfnum < count; surfnum++, in++, out++)
{
int side, ti, planenum, lightofs;
unsigned int planenum;
int ti, side, lightofs;

out->firstedge = in->firstedge;
out->numedges = in->numedges;
Expand All @@ -234,14 +235,14 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->flags |= SURF_PLANEBACK;
}

if (planenum < 0 || planenum >= loadmodel->numplanes)
if (planenum >= loadmodel->numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;

ti = LittleLong(in->texinfo);
ti = in->texinfo;

if ((ti < 0) || (ti >= loadmodel->numtexinfo))
{
Expand Down
7 changes: 4 additions & 3 deletions src/client/refresh/gl3/gl3_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,

for (surfnum = 0; surfnum < count; surfnum++, in++, out++)
{
int side, ti, planenum, lightofs;
unsigned int planenum;
int ti, side, lightofs;

out->firstedge = in->firstedge;
out->numedges = in->numedges;
Expand All @@ -235,14 +236,14 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->flags |= SURF_PLANEBACK;
}

if (planenum < 0 || planenum >= loadmodel->numplanes)
if (planenum >= loadmodel->numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;

ti = LittleLong(in->texinfo);
ti = in->texinfo;

if ((ti < 0) || (ti >= loadmodel->numtexinfo))
{
Expand Down
7 changes: 4 additions & 3 deletions src/client/refresh/gl4/gl4_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l,

for (surfnum = 0; surfnum < count; surfnum++, in++, out++)
{
int side, ti, planenum, lightofs;
unsigned int planenum;
int ti, side, lightofs;

out->firstedge = in->firstedge;
out->numedges = in->numedges;
Expand All @@ -235,14 +236,14 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->flags |= SURF_PLANEBACK;
}

if (planenum < 0 || planenum >= loadmodel->numplanes)
if (planenum >= loadmodel->numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;

ti = LittleLong(in->texinfo);
ti = in->texinfo;

if ((ti < 0) || (ti >= loadmodel->numtexinfo))
{
Expand Down
7 changes: 4 additions & 3 deletions src/client/refresh/soft/sw_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,

for (surfnum = 0; surfnum < count; surfnum++, in++, out++)
{
int side, ti, planenum, lightofs;
unsigned int planenum;
int ti, side, lightofs;

out->firstedge = in->firstedge;
out->numedges = in->numedges;
Expand All @@ -228,14 +229,14 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->flags |= SURF_PLANEBACK;
}

if (planenum < 0 || planenum >= loadmodel->numplanes)
if (planenum >= loadmodel->numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;

ti = LittleLong(in->texinfo);
ti = in->texinfo;

if ((ti < 0) || (ti >= loadmodel->numtexinfo))
{
Expand Down
7 changes: 4 additions & 3 deletions src/client/refresh/vk/vk_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,

for (surfnum = 0; surfnum < count; surfnum++, in++, out++)
{
int side, ti, planenum, lightofs;
unsigned int planenum;
int ti, side, lightofs;

out->firstedge = in->firstedge;
out->numedges = in->numedges;
Expand All @@ -209,14 +210,14 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->flags |= SURF_PLANEBACK;
}

if (planenum < 0 || planenum >= loadmodel->numplanes)
if (planenum >= loadmodel->numplanes)
{
Com_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;

ti = LittleLong(in->texinfo);
ti = in->texinfo;

if ((ti < 0) || (ti >= loadmodel->numtexinfo))
{
Expand Down
22 changes: 11 additions & 11 deletions src/common/header/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ typedef struct

typedef struct
{
int planenum;
unsigned int planenum;
int children[2]; /* negative numbers are -(leafs+1), not nodes */
short mins[3]; /* for frustom culling */
short maxs[3];
Expand All @@ -794,7 +794,7 @@ typedef struct

typedef struct
{
int planenum;
unsigned int planenum;
int children[2]; /* negative numbers are -(leafs+1), not nodes */
float mins[3]; /* for frustom culling */
float maxs[3];
Expand Down Expand Up @@ -838,10 +838,10 @@ typedef struct
typedef struct
{
unsigned short planenum;
short side;
unsigned short side;

int firstedge; /* we must support > 64k edges */
short numedges;
unsigned int firstedge; /* we must support > 64k edges */
unsigned short numedges;
short texinfo;

/* lighting info */
Expand All @@ -852,10 +852,10 @@ typedef struct
typedef struct
{
unsigned int planenum;
int side;
unsigned int side;

int firstedge; /* we must support > 64k edges */
int numedges;
unsigned int firstedge; /* we must support > 64k edges */
unsigned int numedges;
int texinfo;

/* lighting info */
Expand Down Expand Up @@ -994,10 +994,10 @@ typedef struct texsininfo_s
typedef struct
{
unsigned short planenum;
short side;
unsigned short side;

int firstedge; /* we must support > 64k edges */
short numedges;
unsigned int firstedge; /* we must support > 64k edges */
unsigned short numedges;
short texinfo;

/* lighting info */
Expand Down
34 changes: 17 additions & 17 deletions src/common/maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Mod_Load2QBSP_IBSP_NODES(byte *outbuf, dheader_t *outheader,
out->maxs[j] = LittleShort(in->maxs[j]);
}

out->planenum = LittleLong(in->planenum);
out->planenum = LittleLong(in->planenum) & 0xFFFFFFFF;
out->firstface = LittleShort(in->firstface) & 0xFFFF;
out->numfaces = LittleShort(in->numfaces) & 0xFFFF;

Expand Down Expand Up @@ -241,7 +241,7 @@ Mod_Load2QBSP_QBSP_NODES(byte *outbuf, dheader_t *outheader,
out->maxs[j] = LittleFloat(in->maxs[j]);
}

out->planenum = LittleLong(in->planenum);
out->planenum = LittleLong(in->planenum) & 0xFFFFFFFF;
out->firstface = LittleLong(in->firstface) & 0xFFFFFFFF;
out->numfaces = LittleLong(in->numfaces) & 0xFFFFFFFF;

Expand Down Expand Up @@ -336,10 +336,10 @@ Mod_Load2QBSP_IBSP_FACES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleShort(in->planenum);
out->side = LittleShort(in->side);
out->firstedge = LittleLong(in->firstedge);
out->numedges = LittleShort(in->numedges);
out->planenum = LittleShort(in->planenum) & 0xFFFF;
out->side = LittleShort(in->side) & 0xFFFF;
out->firstedge = LittleLong(in->firstedge) & 0xFFFFFFFF;
out->numedges = LittleShort(in->numedges) & 0xFFFF;
out->texinfo = LittleShort(in->texinfo);
memcpy(out->styles, in->styles, Q_min(sizeof(out->styles), sizeof(in->styles)));
out->lightofs = LittleLong(in->lightofs);
Expand All @@ -364,10 +364,10 @@ Mod_Load2QBSP_RBSP_FACES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleShort(in->planenum);
out->side = LittleShort(in->side);
out->firstedge = LittleLong(in->firstedge);
out->numedges = LittleShort(in->numedges);
out->planenum = LittleShort(in->planenum) & 0xFFFF;
out->side = LittleShort(in->side) & 0xFFFF;
out->firstedge = LittleLong(in->firstedge) & 0xFFFFFFFF;
out->numedges = LittleShort(in->numedges) & 0xFFFF;
out->texinfo = LittleShort(in->texinfo);
memcpy(out->styles, in->styles, Q_min(sizeof(out->styles), sizeof(in->styles)));
out->lightofs = LittleLong(in->lightofs);
Expand All @@ -392,10 +392,10 @@ Mod_Load2QBSP_QBSP_FACES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleLong(in->planenum);
out->side = LittleLong(in->side);
out->firstedge = LittleLong(in->firstedge);
out->numedges = LittleLong(in->numedges);
out->planenum = LittleLong(in->planenum) & 0xFFFFFFFF;
out->side = LittleLong(in->side) & 0xFFFFFFFF;
out->firstedge = LittleLong(in->firstedge) & 0xFFFFFFFF;
out->numedges = LittleLong(in->numedges) & 0xFFFFFFFF;
out->texinfo = LittleLong(in->texinfo);
memcpy(out->styles, in->styles, Q_min(sizeof(out->styles), sizeof(in->styles)));
out->lightofs = LittleLong(in->lightofs);
Expand Down Expand Up @@ -699,7 +699,7 @@ Mod_Load2QBSP_IBSP_BRUSHSIDES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleShort(in->planenum);
out->planenum = LittleShort(in->planenum) & 0xFFFF;
out->texinfo = LittleShort(in->texinfo);

out++;
Expand All @@ -722,7 +722,7 @@ Mod_Load2QBSP_RBSP_BRUSHSIDES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleShort(in->planenum);
out->planenum = LittleShort(in->planenum) & 0xFFFF;
out->texinfo = LittleShort(in->texinfo);

out++;
Expand All @@ -744,7 +744,7 @@ Mod_Load2QBSP_QBSP_BRUSHSIDES(byte *outbuf, dheader_t *outheader,

for (i = 0; i < count; i++)
{
out->planenum = LittleLong(in->planenum);
out->planenum = LittleLong(in->planenum) & 0xFFFFFFFF;
out->texinfo = LittleLong(in->texinfo);

out++;
Expand Down

0 comments on commit 36011a5

Please sign in to comment.