Fix the ACS unarchival crash

Map numbers are consistent between server and client, wadnums are not
This commit is contained in:
GenericHeroGuy 2025-09-14 01:29:03 +02:00 committed by NepDisk
parent f4dd4a1be7
commit b3ac501ff1
2 changed files with 9 additions and 6 deletions

View file

@ -225,21 +225,24 @@ void Environment::loadModule(ACSVM::Module *module)
size_t lumpLen = 0;
std::vector<ACSVM::Byte> 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<ACSVM::Byte *>(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);
}

View file

@ -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));