From bfe1a253dad1661820e6b3f7cbbccf1a787ee3df Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Tue, 18 Feb 2025 21:19:22 +0100 Subject: [PATCH] Palette texture hack for palremap --- src/r_textures.c | 18 ++++++++++++++++++ src/w_wad.c | 11 +++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/r_textures.c b/src/r_textures.c index dfff08149..5a56e80f5 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -2030,6 +2030,20 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) Z_Free((void *)texturesText); } +static void PaletteTextureHack(const char **name) +{ + static char uberhack[5]; + if (!udmf) + { + unsigned num; + if (sscanf(*name, "~%03u", &num) && num < 256) + { + snprintf(uberhack, 5, "~%03u", R_GetPaletteRemap(num)); + *name = uberhack; + } + } +} + // Search for flat name. lumpnum_t R_GetFlatNumForName(const char *name) { @@ -2038,6 +2052,8 @@ lumpnum_t R_GetFlatNumForName(const char *name) lumpnum_t start; lumpnum_t end; + PaletteTextureHack(&name); + // Scan wad files backwards so patched flats take preference. for (i = numwadfiles - 1; i >= 0; i--) { @@ -2102,6 +2118,8 @@ INT32 R_CheckTextureNumForName(const char *name) if (name[0] == '-') return 0; + PaletteTextureHack(&name); + hash = quickncasehash(name, 8); for (i = 0; i < tidcachelen; i++) diff --git a/src/w_wad.c b/src/w_wad.c index 52b8a00f0..9d458a5f3 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1681,12 +1681,19 @@ void zerr(int ret) } #endif -// returns true if the given lump is not cached, AND comes from a compatmode file +// returns true if the given lump is not cached, AND comes from a compatmode file (AND isn't special-cased) boolean W_NeedPaletteRemapPwad(UINT16 wad, UINT16 lump, boolean ignorecache) { if (!wadfiles[wad]->lumpcache[lump] || ignorecache) { - return wadfiles[wad]->compatmode; + // ugh, palette textures... + // never do remapping on them; PaletteTextureHack handles that + unsigned num; + const char *name = (wadfiles[wad]->lumpinfo + lump)->longname; + if (sscanf(name, "~%03u", &num) && num < 256) + return false; + else + return wadfiles[wad]->compatmode; } return false; }