From 647e1399f13606f65207320d1254d3fc318b71a7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 15 Nov 2016 00:18:57 +0100 Subject: [PATCH] - added runtime checks for the state usage flags. --- src/p_actionfunctions.cpp | 7 +++++++ src/p_mobj.cpp | 8 ++++++++ src/p_pspr.cpp | 10 ++++++++++ src/scripting/zscript/zcc_compile.cpp | 1 + 4 files changed, 26 insertions(+) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index d56c7ee64..1c0f846b9 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -128,6 +128,13 @@ bool ACustomInventory::CallStateChain (AActor *actor, FState *state) while (state != NULL) { + if (!(state->UseFlags & SUF_ITEM)) + { + auto so = FState::StaticFindStateOwner(state); + Printf("State %s.%d not flagged for use in CustomInventory state chains.\n", so->TypeName.GetChars(), int(state - so->OwnedStates)); + return false; + } + this->state = state; nextstate = NULL; // assume no jump diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 05cfb7cc4..c7f181838 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -626,6 +626,14 @@ bool AActor::SetState (FState *newstate, bool nofunction) { prevsprite = -1; } + if (!(newstate->UseFlags & SUF_ACTOR)) + { + auto so = FState::StaticFindStateOwner(newstate); + Printf("State %s.%d in %s not flagged for use as an actor sprite\n", so->TypeName.GetChars(), int(newstate - so->OwnedStates), GetClass()->TypeName.GetChars()); + state = nullptr; + Destroy(); + return false; + } state = newstate; tics = GetTics(newstate); renderflags = (renderflags & ~RF_FULLBRIGHT) | ActorRenderFlags::FromInt (newstate->GetFullbright()); diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index f371c6888..1d39d907e 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -296,6 +296,16 @@ void DPSprite::SetState(FState *newstate, bool pending) Destroy(); return; } + + if (!(newstate->UseFlags & (SUF_OVERLAY|SUF_WEAPON))) // Weapon and overlay are mostly the same, the main difference is that weapon states restrict the self pointer to class Actor. + { + auto so = FState::StaticFindStateOwner(newstate); + Printf("State %s.%d not flagged for use in overlays or weapons\n", so->TypeName.GetChars(), int(newstate - so->OwnedStates)); + State = nullptr; + Destroy(); + return; + } + State = newstate; if (newstate->sprite != SPR_FIXED) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 2603fea7d..48be582cf 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2437,6 +2437,7 @@ void ZCCCompiler::CompileStates() auto sl = static_cast(st); FState state; memset(&state, 0, sizeof(state)); + state.UseFlags = flags; if (sl->Sprite->Len() != 4) { Error(sl, "Sprite name must be exactly 4 characters. Found '%s'", sl->Sprite->GetChars());