Skip to content

Commit

Permalink
Draw_ValidateCustomLogo: Minor refactoring & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Mar 18, 2024
1 parent 05f4a27 commit 174414d
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions rehlds/engine/decals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
texture_t tex;
miptex_t *mip;
miptex_t tmp;
int pix;
int pixoffset;
int paloffset;
int palettesize;
int nPalleteCount;
int nSize;
miptex_t *mip, tmp;
int i, pix, paloffset, palettesize;
int size;

if (wad->cacheExtra != DECAL_EXTRASIZE)
{
Expand All @@ -734,58 +729,54 @@ qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_

tex = *(texture_t *)data;
mip = (miptex_t *)(data + wad->cacheExtra);
tmp = *mip;

// Copy mip texture data
tmp = *mip;
tex.width = LittleLong(tmp.width);
tex.height = LittleLong(tmp.height);
tex.anim_max = 0;
tex.anim_min = 0;
tex.anim_total = 0;
tex.alternate_anims = NULL;
tex.anim_next = NULL;
tex.anim_total = tex.anim_min = tex.anim_max = 0;
tex.alternate_anims = tex.anim_next = NULL;

if (!tex.width || tex.width > 256 || tex.height > 256)
for (i = 0; i < MIPLEVELS; 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 wad dimensions %s\n", __func__, wad->name);
Con_Printf("%s: Bad cached wad tex size %ux%u on %s\n", __func__, tex.width, tex.height, wad->name);
return FALSE;
}

for (int i = 0; i < MIPLEVELS; i++)
tex.offsets[i] = wad->cacheExtra + LittleLong(tmp.offsets[i]);

pix = tex.width * tex.height;
pixoffset = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);
size = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);

#ifdef REHLDS_FIXES
// 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))
if ((unsigned)(size + sizeof(miptex_t)) >= (unsigned)(lump->size + wad->cacheExtra))
{
Con_Printf("%s: Bad wad payload size %s\n", __func__, wad->name);
return FALSE;
Con_Printf("%s: Bad cached wad size %i/%i on %s\n", __func__, size + sizeof(miptex_t), lump->size + wad->cacheExtra, wad->name);
}
#endif

paloffset = (pix >> 2) + tmp.offsets[0] + pix;
palettesize = (pix >> 4) + paloffset;
paloffset = size + sizeof(lumpinfo_t) + sizeof(miptex_t);
palettesize = *(u_short *)(data + paloffset); // Get palette size

if ((tmp.offsets[0] + pix != tmp.offsets[1])
|| paloffset != tmp.offsets[2]
|| palettesize != tmp.offsets[3])
for (i = 0; i < 3; i++)
{
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
return FALSE;
// 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;
}

nPalleteCount = *(u_short *)(data + pixoffset + sizeof(texture_t));
if (nPalleteCount > 256)
if (palettesize > 256)
{
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, nPalleteCount, wad->name);
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, palettesize, wad->name);
return FALSE;
}

nSize = pixoffset + LittleLong(tmp.offsets[0]) + 3 * nPalleteCount + 2;
if (nSize > lump->disksize)
if ((palettesize + 2 * (palettesize + 1) + size + LittleLong(tmp.offsets[0])) > lump->disksize)
{
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
return FALSE;
Expand Down

8 comments on commit 174414d

@SmilexGamer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom logos that I had no longer draw due to the refactoring done in this commit. Might be worthwhile checking this.

@s1lentq
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SmilexGamer send me your {gamedir}/tempdecal.wad to mail

@SmilexGamer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s1lentq can I instead send the website which I use to convert images to tempdecal.wad? I used to do my custom logos manually, but the transparency was always a tedious task, so I began using a website.

@s1lentq
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to have both

@SmilexGamer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll send the website (and source code of it) and an example tempdecal.wad.

@anzz1
Copy link
Contributor

@anzz1 anzz1 commented on 174414d Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A great additional feature would be a CVAR to allow blocking such custom decals, either by blocking them by palette size (block colored) or by size (anything over standard 64x64).

As some number of players exploit this possibility to make irritating very large and colorful custom tempdecals due to an oversight in the check code which was always supposed to only accept single color and maximum of 64x64 sprays.

The original intention is clear by looking the original logos, the additional ones in Half-Life: Further Data, or when making custom sprays by adding them to the "logos" folder. The code transforming BMP to tempdecal.wad works fine and only allows single color and max 64x64 sprites, and only by use of external tools is possible to make much larger sprays and make them multicolor. Thus, large colorful tempdecals is unintended behaviour allowed by shoddy coding in the validation process.

Something like
sv_logos_allow_nonstandard 0/1

or for finer control
sv_logos_allow_largesize 0/1
sv_logos_allow_multicolor 0/1

@SmilexGamer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A great additional feature would be a CVAR to allow blocking such custom decals, either by blocking them by palette size (block colored) or by size (anything over standard 64x64).

As some number of players exploit this possibility to make irritating very large and colorful custom tempdecals due to an oversight in the check code which was always supposed to only accept single color and maximum of 64x64 sprays.

The original intention is clear by looking the original logos, the additional ones in Half-Life: Further Data, or when making custom sprays by adding them to the "logos" folder. The code transforming BMP to tempdecal.wad works fine and only allows single color and max 64x64 sprites, and only by use of external tools is possible to make much larger sprays and make them multicolor. Thus, large colorful tempdecals is unintended behaviour allowed by shoddy coding in the validation process.

Something like sv_logos_allow_nonstandard 0/1

or for finer control sv_logos_allow_largesize 0/1 sv_logos_allow_multicolor 0/1

You are right, but we have to be careful with such changes. This has been a default behavior that noone questioned for years, so if such cvar is implemented, it should follow default behavior by default.

@anzz1
Copy link
Contributor

@anzz1 anzz1 commented on 174414d Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but we have to be careful with such changes. This has been a default behavior that noone questioned for years, so if such cvar is implemented, it should follow default behavior by default.

I think that has been the design principle the whole time, that by default ReHLDS is just what it says on a tin, a reverse-engineered HLDS and nothing else, just like many other reverse-engineering projects. Every non-default behaviour and fix has been wrapped in either a runtime cvar or compile-time #ifdef REHLDS_FIXES. So following that principle, I agree with you, that the default value for allow nonstandard sprays should be 1.

Please sign in to comment.