From b3ac501ff19a0b6857257af0ca15d70a0936a869 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sun, 14 Sep 2025 01:29:03 +0200 Subject: [PATCH] Fix the ACS unarchival crash Map numbers are consistent between server and client, wadnums are not --- src/acs/environment.cpp | 13 ++++++++----- src/acs/interface.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/acs/environment.cpp b/src/acs/environment.cpp index 223ed74a9..4b73c08e1 100644 --- a/src/acs/environment.cpp +++ b/src/acs/environment.cpp @@ -225,21 +225,24 @@ void Environment::loadModule(ACSVM::Module *module) size_t lumpLen = 0; std::vector data; - if (name->i == (size_t)LUMPERROR) + I_Assert(name->i >= 0 && name->i < nummapheaders); + const lumpnum_t lumpnum = mapheaderinfo[name->i]->lumpnum; + + if (lumpnum == LUMPERROR) { // No lump given for module. throw ACSVM::ReadError("invalid lump"); } - lumpLen = W_LumpLength(name->i); + lumpLen = W_LumpLength(lumpnum); - if (W_IsLumpWad(name->i) == true || lumpLen == 0) + if (W_IsLumpWad(lumpnum) == true || lumpLen == 0) { CONS_Debug(DBG_SETUP, "Attempting to load ACS module from the BEHAVIOR lump of map '%s'...\n", name->s->str); // The lump given is a virtual resource. // Try to grab a BEHAVIOR lump from inside of it. - virtres_t *vRes = vres_GetMap(name->i); + virtres_t *vRes = vres_GetMap(lumpnum); auto _ = srb2::finally([vRes]() { vres_Free(vRes); }); virtlump_t *vLump = vres_Find(vRes, "BEHAVIOR"); @@ -261,7 +264,7 @@ void Environment::loadModule(ACSVM::Module *module) ACSVM::Byte *lump = static_cast(Z_Calloc(lumpLen, PU_STATIC, nullptr)); auto _ = srb2::finally([lump]() { Z_Free(lump); }); - W_ReadLump(name->i, lump); + W_ReadLump(lumpnum, lump); data.insert(data.begin(), lump, lump + lumpLen); } diff --git a/src/acs/interface.cpp b/src/acs/interface.cpp index 2e7908f24..91672731c 100644 --- a/src/acs/interface.cpp +++ b/src/acs/interface.cpp @@ -153,7 +153,7 @@ void ACS_LoadLevelScripts(size_t mapID) ACSVM::ModuleName name = ACSVM::ModuleName( env->getString( mapheaderinfo[mapID]->lumpname ), nullptr, - mapheaderinfo[mapID]->lumpnum + mapID ); modules.push_back(env->getModule(name));