Do not load invalid ACS modules

BEHAVIOR being optional is now handled from our side, because using getModule or loadModule on an invalid file is supposed to be an error condition for the VM.
This commit is contained in:
Sally Coolatta 2024-10-18 11:05:40 -04:00
parent 001ae4a05b
commit 3b898c528e
2 changed files with 10 additions and 5 deletions

View file

@ -228,8 +228,7 @@ void Environment::loadModule(ACSVM::Module *module)
if (name->i == (size_t)LUMPERROR) if (name->i == (size_t)LUMPERROR)
{ {
// No lump given for module. // No lump given for module.
CONS_Alert(CONS_WARNING, "Could not find ACS module \"%s\"; scripts will not function properly!\n", name->s->str); throw ACSVM::ReadError("invalid lump");
return; //throw ACSVM::ReadError("file open failure");
} }
lumpLen = W_LumpLength(name->i); lumpLen = W_LumpLength(name->i);
@ -280,9 +279,7 @@ void Environment::loadModule(ACSVM::Module *module)
} }
else else
{ {
// Unlike Hexen, a BEHAVIOR lump is not required. throw ACSVM::ReadError("file empty");
// Simply ignore in this instance.
CONS_Debug(DBG_SETUP, "ACS module has no data, ignoring...\n");
} }
} }

View file

@ -142,6 +142,13 @@ void ACS_LoadLevelScripts(size_t mapID)
map->active = true; map->active = true;
// Insert BEHAVIOR lump into the list. // Insert BEHAVIOR lump into the list.
virtres_t *vRes = vres_GetMap(mapheaderinfo[mapID]->lumpnum);
auto _ = srb2::finally([vRes]() { vres_Free(vRes); });
// Unlike Hexen, a BEHAVIOR lump is not required.
// Simply ignore in this instance.
virtlump_t *vLump = vres_Find(vRes, "BEHAVIOR");
if (vLump != nullptr && vLump->size > 0)
{ {
ACSVM::ModuleName name = ACSVM::ModuleName( ACSVM::ModuleName name = ACSVM::ModuleName(
env->getString( mapheaderinfo[mapID]->lumpname ), env->getString( mapheaderinfo[mapID]->lumpname ),
@ -150,6 +157,7 @@ void ACS_LoadLevelScripts(size_t mapID)
); );
modules.push_back(env->getModule(name)); modules.push_back(env->getModule(name));
CONS_Debug(DBG_SETUP, "Found BEHAVIOR lump.\n");
} }
if (modules.empty() == false) if (modules.empty() == false)