mirror of
https://github.com/rehlds/rehlds.git
synced 2025-02-26 21:41:06 +03:00
Draw_ValidateCustomLogo: Minor refactoring & cleanup
This commit is contained in:
parent
05f4a279f9
commit
174414db81
@ -717,14 +717,9 @@ NOXREF qboolean Draw_CacheReload(cachewad_t *wad, int i, lumpinfo_t *pLump, cach
|
|||||||
qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_t *lump)
|
qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_t *lump)
|
||||||
{
|
{
|
||||||
texture_t tex;
|
texture_t tex;
|
||||||
miptex_t *mip;
|
miptex_t *mip, tmp;
|
||||||
miptex_t tmp;
|
int i, pix, paloffset, palettesize;
|
||||||
int pix;
|
int size;
|
||||||
int pixoffset;
|
|
||||||
int paloffset;
|
|
||||||
int palettesize;
|
|
||||||
int nPalleteCount;
|
|
||||||
int nSize;
|
|
||||||
|
|
||||||
if (wad->cacheExtra != DECAL_EXTRASIZE)
|
if (wad->cacheExtra != DECAL_EXTRASIZE)
|
||||||
{
|
{
|
||||||
@ -734,58 +729,54 @@ qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_
|
|||||||
|
|
||||||
tex = *(texture_t *)data;
|
tex = *(texture_t *)data;
|
||||||
mip = (miptex_t *)(data + wad->cacheExtra);
|
mip = (miptex_t *)(data + wad->cacheExtra);
|
||||||
tmp = *mip;
|
|
||||||
|
|
||||||
|
// Copy mip texture data
|
||||||
|
tmp = *mip;
|
||||||
tex.width = LittleLong(tmp.width);
|
tex.width = LittleLong(tmp.width);
|
||||||
tex.height = LittleLong(tmp.height);
|
tex.height = LittleLong(tmp.height);
|
||||||
tex.anim_max = 0;
|
tex.anim_total = tex.anim_min = tex.anim_max = 0;
|
||||||
tex.anim_min = 0;
|
tex.alternate_anims = tex.anim_next = NULL;
|
||||||
tex.anim_total = 0;
|
|
||||||
tex.alternate_anims = NULL;
|
|
||||||
tex.anim_next = NULL;
|
|
||||||
|
|
||||||
if (!tex.width || tex.width > 256 || tex.height > 256)
|
for (i = 0; i < MIPLEVELS; i++)
|
||||||
{
|
|
||||||
Con_Printf("%s: Bad wad dimensions %s\n", __func__, wad->name);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MIPLEVELS; i++)
|
|
||||||
tex.offsets[i] = wad->cacheExtra + LittleLong(tmp.offsets[i]);
|
tex.offsets[i] = wad->cacheExtra + LittleLong(tmp.offsets[i]);
|
||||||
|
|
||||||
|
if (tex.width <= 0 || tex.height <= 0 ||
|
||||||
|
// Check if texture dimensions exceed limits
|
||||||
|
tex.width > 256 || tex.height > 256)
|
||||||
|
{
|
||||||
|
Con_Printf("%s: Bad cached wad tex size %ux%u on %s\n", __func__, tex.width, tex.height, wad->name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
pix = tex.width * tex.height;
|
pix = tex.width * tex.height;
|
||||||
pixoffset = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);
|
size = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);
|
||||||
|
|
||||||
#ifdef REHLDS_FIXES
|
if ((unsigned)(size + sizeof(miptex_t)) >= (unsigned)(lump->size + wad->cacheExtra))
|
||||||
// Ensure that pixoffset won't be exceed the pre allocated buffer
|
|
||||||
// This can happen when there are no color palettes in payload
|
|
||||||
if ((pixoffset + sizeof(texture_t)) >= (unsigned)(wad->cacheExtra + lump->size))
|
|
||||||
{
|
{
|
||||||
Con_Printf("%s: Bad wad payload size %s\n", __func__, wad->name);
|
Con_Printf("%s: Bad cached wad size %i/%i on %s\n", __func__, size + sizeof(miptex_t), lump->size + wad->cacheExtra, wad->name);
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
paloffset = (pix >> 2) + tmp.offsets[0] + pix;
|
paloffset = size + sizeof(lumpinfo_t) + sizeof(miptex_t);
|
||||||
palettesize = (pix >> 4) + paloffset;
|
palettesize = *(u_short *)(data + paloffset); // Get palette size
|
||||||
|
|
||||||
if ((tmp.offsets[0] + pix != tmp.offsets[1])
|
for (i = 0; i < 3; i++)
|
||||||
|| paloffset != tmp.offsets[2]
|
|
||||||
|| palettesize != tmp.offsets[3])
|
|
||||||
{
|
{
|
||||||
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
|
// Check if offsets are valid for mip levels
|
||||||
|
if (pix + tmp.offsets[i] != tmp.offsets[i + 1])
|
||||||
|
{
|
||||||
|
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
pix >>= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (palettesize > 256)
|
||||||
|
{
|
||||||
|
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, palettesize, wad->name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nPalleteCount = *(u_short *)(data + pixoffset + sizeof(texture_t));
|
if ((palettesize + 2 * (palettesize + 1) + size + LittleLong(tmp.offsets[0])) > lump->disksize)
|
||||||
if (nPalleteCount > 256)
|
|
||||||
{
|
|
||||||
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, nPalleteCount, wad->name);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
nSize = pixoffset + LittleLong(tmp.offsets[0]) + 3 * nPalleteCount + 2;
|
|
||||||
if (nSize > lump->disksize)
|
|
||||||
{
|
{
|
||||||
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
|
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user