From 1c33caa84e0506727eb48404025af5353998f43e Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Wed, 17 Sep 2025 18:24:53 +0200 Subject: [PATCH] Attempt number two at fixing ACS unarchiving Can't use map numbers, can't use lump numbers... so don't use numbers! --- src/acs/environment.cpp | 26 +++++++++++++++++++------- src/acs/interface.cpp | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/acs/environment.cpp b/src/acs/environment.cpp index 99a4a908e..69dfea0ef 100644 --- a/src/acs/environment.cpp +++ b/src/acs/environment.cpp @@ -260,9 +260,8 @@ ACSVM::Thread *Environment::allocThread() ACSVM::ModuleName Environment::getModuleName(char const *str, size_t len) { ACSVM::String *name = getString(str, len); - lumpnum_t lump = W_CheckNumForNameInFolder(str, "ACS/"); - return { name, nullptr, static_cast(lump) }; + return { name, nullptr, static_cast(false) }; } void Environment::loadModule(ACSVM::Module *module) @@ -272,21 +271,34 @@ void Environment::loadModule(ACSVM::Module *module) size_t lumpLen = 0; std::vector data; - if (name->i == (size_t)LUMPERROR) + lumpnum_t lumpnum = LUMPERROR; + + if (name->i) // this module is from a map! + { + INT32 mapnum = G_MapNumber(name->s->str); + if (mapnum < NEXTMAP_INVALID) + lumpnum = mapheaderinfo[mapnum]->lumpnum; + } + else // just a lump + { + lumpnum = W_CheckNumForNameInFolder(name->s->str, "ACS/"); + } + + 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"); @@ -308,7 +320,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 5858fad40..c4f501296 100644 --- a/src/acs/interface.cpp +++ b/src/acs/interface.cpp @@ -154,7 +154,7 @@ void ACS_LoadLevelScripts(size_t mapID) ACSVM::ModuleName name = ACSVM::ModuleName( env->getString( mapheaderinfo[mapID]->lumpname ), nullptr, - mapheaderinfo[mapID]->lumpnum + static_cast(true) ); modules.push_back(env->getModule(name));