From 1517ba4d89b5cb45a4801a84d12eb831ac5f7425 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 18 Sep 2025 12:36:34 +0100 Subject: [PATCH 1/3] Fix mainwads-dependent calculations - sounds.pk3 was being considered a mainwad in some spots due to use of <= instead of < - fileneeded material was manually skipping over base musicwads when it didn't have to --- src/d_netcmd.c | 4 ++-- src/d_netfil.c | 8 ++++---- src/r_textures.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index db1fc8f9b..6672f995e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4639,10 +4639,10 @@ static void Command_ListWADS_f(void) nameonly(tempname = va("%s", wadfiles[i]->filename)); if (!i) CONS_Printf("\x82 IWAD\x80: %s\n", tempname); - else if (i <= mainwads) + else if (i < mainwads) CONS_Printf("\x82 * %.2d\x80: %s\n", i, tempname); else if (!wadfiles[i]->important) - CONS_Printf("\x86 %c %.2d: %s\n", ((i <= mainwads + musicwads) ? '*' : ' '), i, tempname); + CONS_Printf("\x86 %c %.2d: %s\n", ((i < mainwads + musicwads) ? '*' : ' '), i, tempname); else CONS_Printf(" %.2d: %s\n", i, tempname); } diff --git a/src/d_netfil.c b/src/d_netfil.c index f1e7e31dc..58587db10 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -163,10 +163,10 @@ UINT8 *PutFileNeeded(UINT16 firstfile) #ifdef DEVELOP i = 0; #else - i = mainwads + 1; + i = mainwads + musicwads; #endif - for (; i < numwadfiles; i++) //mainwads+1, otherwise we start on the first mainwad + for (; i < numwadfiles; i++) //mainwads+musicwads, otherwise we start on the first mainwad { // If it has only music/sound lumps, don't put it in the list if (!wadfiles[i]->important) @@ -197,7 +197,7 @@ UINT8 *PutFileNeeded(UINT16 firstfile) /* don't send mainwads!! */ #ifdef DEVELOP - if (i <= mainwads) + if (i < mainwads) filestatus += (2 << 4); #endif @@ -565,7 +565,7 @@ INT32 CL_CheckFiles(void) #ifdef DEVELOP j = 0; #else - j = mainwads + 1; + j = mainwads + musicwads; #endif for (i = 0; i < fileneedednum || j < numwadfiles;) { diff --git a/src/r_textures.cpp b/src/r_textures.cpp index f582f50d4..57ca9303c 100644 --- a/src/r_textures.cpp +++ b/src/r_textures.cpp @@ -1293,7 +1293,7 @@ Rloadtextures (INT32 i, INT32 w) } INT32 sizeLimit = 2048; - if (w <= mainwads) + if (w < mainwads) { // TODO: we ran out of time to do this properly. // 4096 limit on textures may be incompatible with some older graphics cards (circa 2005-2008?). From a01300cd54c4356f678f838bdf4f7b62dc384474 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 18 Sep 2025 12:37:44 +0100 Subject: [PATCH 2/3] w_wad for lumpnums: Use bitwise and instead of addition Makes the mathematical logic of what's being done clearer --- src/w_wad.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 972b99af8..b188c2a00 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1397,7 +1397,7 @@ lumpnum_t W_CheckNumForName(const char *name) lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME); strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8); - lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check; + lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check; lumpnumcache[lumpnumcacheindex].lumphash = hash; return lumpnumcache[lumpnumcacheindex].lumpnum; @@ -1454,11 +1454,11 @@ lumpnum_t W_CheckNumForLongName(const char *name) lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME); strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME); - lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check; + lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check; lumpnumcache[lumpnumcacheindex].lumphash = hash; } - return (i << 16) + check; + return (i << 16) | check; } } @@ -1505,11 +1505,11 @@ lumpnum_t W_CheckNumForMap(const char *name, boolean checktofirst) lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME); strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME); - lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check; + lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check; lumpnumcache[lumpnumcacheindex].lumphash = hash; } - return (i << 16) + check; + return (i << 16) | check; } } @@ -1608,7 +1608,7 @@ lumpnum_t W_CheckNumForNameInFolder(const char *lump, const char *folder) check = W_CheckNumForLongNamePwad(lump, (UINT16)i, fsid); if (check < feid) { - return (i<<16) + check; // found it, in our constraints + return (i<<16) | check; // found it, in our constraints } } } From 9411ce53876f45d75febbe6ba0a96650bef357a0 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 18 Sep 2025 12:45:22 +0100 Subject: [PATCH 3/3] Environment::read/writeModuleName: Convert lumpnums to a netsafe form for transit - Introduces new functions - W_LumpIntoNetSave - W_LumpFromNetSave - Essentially shims the upper 16 bits to account for unimportant files --- src/acs/vm/ACSVM/Environment.cpp | 10 +++- src/w_wad.cpp | 87 ++++++++++++++++++++++++++++++++ src/w_wad.h | 3 ++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/acs/vm/ACSVM/Environment.cpp b/src/acs/vm/ACSVM/Environment.cpp index 6461ec514..3a2af3c40 100644 --- a/src/acs/vm/ACSVM/Environment.cpp +++ b/src/acs/vm/ACSVM/Environment.cpp @@ -25,6 +25,7 @@ #include "Script.hpp" #include "Serial.hpp" #include "Thread.hpp" +#include "../../../w_wad.h" #include #include @@ -596,7 +597,12 @@ namespace ACSVM ModuleName Environment::readModuleName(Serial &in) const { auto s = readString(in); - auto i = ReadVLN(in); + size_t i = ReadVLN(in); + + if ((i = W_LumpFromNetSave(i)) == LUMPERROR) + { + CONS_Debug(DBG_GAMELOGIC, "lumpnum not found for ACS module '%s'\n", s->str); + } return {s, nullptr, i}; } @@ -768,7 +774,7 @@ namespace ACSVM void Environment::writeModuleName(Serial &out, ModuleName const &in) const { writeString(out, in.s); - WriteVLN(out, in.i); + WriteVLN(out, W_LumpIntoNetSave(in.i)); } // diff --git a/src/w_wad.cpp b/src/w_wad.cpp index b188c2a00..e69d4b36d 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1634,6 +1634,93 @@ UINT8 W_LumpExists(const char *name) return false; } +// Thanks to the introduction of "client side WAD files", +// a notion which is insanity in any other branch of DOOM, +// any direct wadnum ID is not a guaranteed index (and +// lumpnum_t, which has it in their upper bits, suffer too) +// We can do an O(n) conversion back and forth, which is +// better than nothing, but still kind of annoying to do. +// It was either this or killing musicwads lmao ~toast 180925 + +lumpnum_t W_LumpIntoNetSave(lumpnum_t lump) +{ + UINT32 wad = (lump >> 16); + if (lump == LUMPERROR // Bad already + || wad < mainwads) // Same between client/server + { + // Give what we get. + return lump; + } + + if (wad >= numwadfiles // Outside of range + || !wadfiles[wad]->important) // Can't convert local lumpnum + { + // No good return result! + return LUMPERROR; + } + + // Count previous local files the client might not have. + UINT32 i = (mainwads + musicwads), localoffset = 0; + for (; i < wad; i++) + { + if (wadfiles[i]->important) + continue; + + localoffset++; + } + + if (!localoffset) + { + // No local files, return unchanged. + return lump; + } + + if (localoffset <= wad) + { + // Success, return with the conversion. + return ((wad - localoffset) << 16) | (lump & UINT16_MAX); + } + + // Death!! + return LUMPERROR; +} + +lumpnum_t W_LumpFromNetSave(lumpnum_t lump) +{ + UINT32 netwad = (lump >> 16); + if (lump == LUMPERROR // Bad already + || netwad < mainwads) // Same between client/server + { + // Give what we get. + return lump; + } + + // Count previous local files the server would ignore. + UINT32 i = (mainwads + musicwads), localoffset = 0; + for (; (i - localoffset) <= netwad && i < numwadfiles; i++) + { + if (wadfiles[i]->important) + continue; + + localoffset++; + } + + if (!localoffset) + { + // No local files, return unchanged. + return lump; + } + + if (netwad + localoffset < numwadfiles) + { + // Success, return with the conversion. + return ((netwad + localoffset) << 16) | (lump & UINT16_MAX); + } + + // Death!! + return LUMPERROR; +} + size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump) { if (!TestValidLump(wad, lump)) diff --git a/src/w_wad.h b/src/w_wad.h index 06553ea28..7024826dc 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -188,6 +188,9 @@ lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, con lumpnum_t W_CheckNumForNameInFolder(const char *lump, const char *folder); UINT8 W_LumpExists(const char *name); // Lua uses this. +lumpnum_t W_LumpIntoNetSave(lumpnum_t lump); +lumpnum_t W_LumpFromNetSave(lumpnum_t lump); + size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump); size_t W_LumpLength(lumpnum_t lumpnum);