From e412adef331dd083e6b0be74905a421e150de207 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Tue, 8 Nov 2022 17:42:55 +0200 Subject: [PATCH] Decomp fixes for CScriptShadowProjector --- Runtime/World/CScriptCoverPoint.cpp | 2 +- Runtime/World/CScriptShadowProjector.cpp | 55 +++++++++++++----------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Runtime/World/CScriptCoverPoint.cpp b/Runtime/World/CScriptCoverPoint.cpp index f5210d578..b6e055d96 100644 --- a/Runtime/World/CScriptCoverPoint.cpp +++ b/Runtime/World/CScriptCoverPoint.cpp @@ -75,7 +75,7 @@ float CScriptCoverPoint::GetSinSqVerticalAngle() const { return xf0_sinVerticalA void CScriptCoverPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { CActor::AcceptScriptMsg(msg, uid, mgr); - if (msg == EScriptObjectMessage::WorldInitialized) { + if (msg == EScriptObjectMessage::InitializedInArea) { for (const SConnection& con : x20_conns) if (con.x0_state == EScriptObjectState::Retreat) { xfc_retreating = mgr.GetIdForScript(con.x8_objId); diff --git a/Runtime/World/CScriptShadowProjector.cpp b/Runtime/World/CScriptShadowProjector.cpp index 914a1ea2c..356f7f287 100644 --- a/Runtime/World/CScriptShadowProjector.cpp +++ b/Runtime/World/CScriptShadowProjector.cpp @@ -29,11 +29,11 @@ void CScriptShadowProjector::Think(float dt, CStateManager& mgr) { return; } - xfc_opacity = (x100_opacityRecip * xfc_opacity) - dt; - if (dt > 0.f) { + xfc_opacity = -(x100_opacityRecip * dt - xfc_opacity); + if (xfc_opacity > 0.f) { return; } - + xfc_opacity = 0.f; x108_projectedShadow.reset(); x110_25_shadowInvalidated = false; @@ -50,41 +50,44 @@ void CScriptShadowProjector::CreateProjectedShadow() { void CScriptShadowProjector::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { CActor::AcceptScriptMsg(msg, uid, mgr); - if (msg == EScriptObjectMessage::Decrement) { - if (x110_24_persistent) { - return; - } - if (xfc_opacity <= 0.f) { - return; - } - - x110_25_shadowInvalidated = true; - } else if (msg == EScriptObjectMessage::InitializedInArea) { + switch (msg) { + case EScriptObjectMessage::InitializedInArea: for (const SConnection& conn : x20_conns) { if (conn.x0_state != EScriptObjectState::Play) { continue; } - const CActor* act = TCastToConstPtr(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId))); - if (!act) { - continue; + if (act) { + const CModelData* mData = act->GetModelData(); + if (mData && (mData->GetAnimationData() || mData->HasNormalModel())) { + x104_target = act->GetUniqueId(); + break; + } } - - const CModelData* mData = act->GetModelData(); - if (!mData || (!mData->GetAnimationData() && !mData->GetNormalModel())) { - continue; - } - - x104_target = act->GetUniqueId(); } if (x104_target == kInvalidUniqueId) { mgr.FreeScriptObject(GetUniqueId()); - } else { - CreateProjectedShadow(); + break; } - } else if (msg == EScriptObjectMessage::Activate) { + [[fallthrough]]; + case EScriptObjectMessage::Deactivate: + case EScriptObjectMessage::Activate: CreateProjectedShadow(); + break; + + case EScriptObjectMessage::Decrement: + if (!GetActive()) { + return; + } + + if (xfc_opacity > 0.f) { + x110_25_shadowInvalidated = true; + } + break; + + default: + break; } }