From 5a176fdf3da1c9a656e7d0f373391b816ac44701 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Nov 2023 13:37:34 +0100 Subject: [PATCH] Exhumed: sanitize stupid implementation of UpdateEnemy and fixed bad use of it for the queen's eggs. --- source/games/exhumed/src/aistuff.h | 2 +- source/games/exhumed/src/move.cpp | 12 ++++++------ source/games/exhumed/src/mummy.cpp | 5 ++--- source/games/exhumed/src/queen.cpp | 6 ++---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index 5d36c43d8..9371d93f0 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -210,7 +210,7 @@ void MoveThings(); void InitChunks(); void InitPushBlocks(); void Gravity(DExhumedActor* actor); -DExhumedActor* UpdateEnemy(DExhumedActor** ppEnemy); +DExhumedActor* UpdateEnemy(DExhumedActor* ppEnemy); Collision MoveCreature(DExhumedActor* nSprite); Collision MoveCreatureWithCaution(DExhumedActor* actor); DVector3 WheresMyMouth(DExhumedPlayer* const pPlayer, sectortype** sectnum); diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index e295d9f24..f3a426c1a 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -1286,15 +1286,15 @@ void AICreatureChunk::Tick(RunListEvent* ev) // //--------------------------------------------------------------------------- -DExhumedActor* UpdateEnemy(DExhumedActor** ppEnemy) +DExhumedActor* UpdateEnemy(DExhumedActor* ppEnemy) { - if (*ppEnemy) + if (ppEnemy) { - if (!((*ppEnemy)->spr.cstat & CSTAT_SPRITE_BLOCK_ALL)) { - *ppEnemy = nullptr; + if (!(ppEnemy->spr.cstat & CSTAT_SPRITE_BLOCK_ALL)) + { + return nullptr; } } - - return *ppEnemy; + return ppEnemy; } END_PS_NS diff --git a/source/games/exhumed/src/mummy.cpp b/source/games/exhumed/src/mummy.cpp index 37c01760f..5df76ab14 100644 --- a/source/games/exhumed/src/mummy.cpp +++ b/source/games/exhumed/src/mummy.cpp @@ -133,9 +133,8 @@ void AIMummy::Tick(RunListEvent* ev) auto pActor = ev->pObjActor; if (!pActor) return; - DExhumedActor* targ = pActor->pTarget; - auto pTarget = UpdateEnemy(&targ); - pActor->pTarget = targ; + auto pTarget = UpdateEnemy(pActor->pTarget); + pActor->pTarget = pTarget; int nAction = pActor->nAction; diff --git a/source/games/exhumed/src/queen.cpp b/source/games/exhumed/src/queen.cpp index c8bcefadc..d59ea889a 100644 --- a/source/games/exhumed/src/queen.cpp +++ b/source/games/exhumed/src/queen.cpp @@ -563,10 +563,7 @@ void AIQueenEgg::Tick(RunListEvent* ev) bVal = true; } - DExhumedActor* enemy = pEgg->pActor; - pTarget = UpdateEnemy(&enemy); - pEgg->pActor = enemy; - pEgg->pTarget = pTarget; + pTarget = UpdateEnemy(pEgg->pTarget); if (pTarget && (pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) == 0) { @@ -734,6 +731,7 @@ void AIQueenEgg::Draw(RunListEvent* ev) const auto nEgg = RunData[ev->nRun].nObjIndex; const auto pEgg = &QueenEgg[nEgg]; const auto eggSeq = &EggSeq[pEgg->nAction]; + if (pEgg->pActor == nullptr) return; seq_PlotSequence(ev->nParam, pEgg->pActor->nSeqFile, eggSeq->nSeqId, pEgg->nFrame, eggSeq->nFlags); }