From b963ce1e850334a5b5b17bff922b3b00fa365250 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 21 Oct 2020 15:55:45 -0700 Subject: [PATCH] Attempt 4 to fix ScriptLayerController for Tom --- Runtime/CMemoryCardSys.cpp | 2 +- Runtime/CMemoryCardSys.hpp | 4 ++-- Runtime/CStateManager.cpp | 2 +- Runtime/Character/CActorLights.cpp | 6 +++--- Runtime/World/CGameArea.cpp | 17 ++++++++++------- Runtime/World/CGameArea.hpp | 10 +++++----- Runtime/World/CMorphBallShadow.cpp | 4 ++-- Runtime/World/CScriptDoor.cpp | 2 +- Runtime/World/IGameArea.hpp | 2 +- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Runtime/CMemoryCardSys.cpp b/Runtime/CMemoryCardSys.cpp index 7d4f7e78b..47e12ef08 100644 --- a/Runtime/CMemoryCardSys.cpp +++ b/Runtime/CMemoryCardSys.cpp @@ -35,7 +35,7 @@ bool CSaveWorldIntermediate::InitializePump() { xc_areaIds.reserve(areaCount); for (u32 i = 0; i < areaCount; ++i) { const IGameArea* area = wld.IGetAreaAlways(i); - xc_areaIds.emplace_back(area->IGetAreaId()); + xc_areaIds.emplace_back(area->IGetAreaSaveId()); } CAssetId mlvlId = wld.IGetWorldAssetId(); diff --git a/Runtime/CMemoryCardSys.hpp b/Runtime/CMemoryCardSys.hpp index ca4a74105..ce4c8387a 100644 --- a/Runtime/CMemoryCardSys.hpp +++ b/Runtime/CMemoryCardSys.hpp @@ -24,7 +24,7 @@ class CSaveWorldMemory { CAssetId x0_strgId; CAssetId x4_savwId; u32 x8_areaCount; - std::vector xc_areaIds; + std::vector xc_areaIds; std::vector x1c_defaultLayerStates; TLockedToken x2c_worldName; /* used to be optional */ TLockedToken x3c_saveWorld; /* used to be optional */ @@ -48,7 +48,7 @@ class CSaveWorldIntermediate { CAssetId x0_mlvlId; CAssetId x4_strgId; CAssetId x8_savwId; - std::vector xc_areaIds; + std::vector xc_areaIds; std::vector x1c_defaultLayerStates; std::unique_ptr x2c_dummyWorld; TLockedToken x34_saveWorld; /* Used to be auto_ptr */ diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 24d06449f..d37afdc8d 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -2004,7 +2004,7 @@ void CStateManager::UpdateAreaSounds() { occState = area.GetOcclusionState(); } if (occState == CGameArea::EOcclusionState::Visible) { - areas.push_back(area.GetAreaIndex()); + areas.push_back(area.GetAreaId()); } } CSfxManager::SetActiveAreas(areas); diff --git a/Runtime/Character/CActorLights.cpp b/Runtime/Character/CActorLights.cpp index 3365ae2f1..70530aebf 100644 --- a/Runtime/Character/CActorLights.cpp +++ b/Runtime/Character/CActorLights.cpp @@ -183,7 +183,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& } zeus::CVector3f vec; - if (!x298_24_dirty && x294_aid == area.GetAreaIndex()) { + if (!x298_24_dirty && x294_aid == area.GetAreaId()) { /* Early return if not ready for update */ if (mgr.GetInputFrameIdx() - x2a4_lastUpdateFrame < x2a8_areaUpdateFramePeriod) return false; @@ -193,7 +193,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& return false; x2c0_lastActorPos = vec; } else { - if (x294_aid != area.GetAreaIndex()) + if (x294_aid != area.GetAreaId()) x2d8_brightLightIdx = -1; x2a4_lastUpdateFrame = sFrameSchedulerCount + mgr.GetInputFrameIdx(); vec = aabb.center() + x2ac_actorPosBias; @@ -203,7 +203,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& /* Reset lighting state */ x2d4_worldLightingLevel = worldLightingLevel; x298_24_dirty = false; - x294_aid = area.GetAreaIndex(); + x294_aid = area.GetAreaId(); x29c_shadowLightArrIdx = -1; x288_ambientColor = zeus::skClear; diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index 696ed5b22..458728de9 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -305,8 +305,11 @@ CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion) { zeus::CAABox aabb; aabb.readBoundingBoxBig(in); xc_mrea = in.readUint32Big(); - if (mlvlVersion > 15) - x10_areaId = CAssetId(in); + if (mlvlVersion > 15) { + x10_areaId = in.readUint32Big(); + } else { + x10_areaId = -1; + } u32 attachAreaCount = in.readUint32Big(); x44_attachedAreaIndices.reserve(attachAreaCount); @@ -332,7 +335,7 @@ std::pair, s32> CDummyGameArea::IGetScriptingMemoryAlways( return GetScriptingMemoryAlways(*this); } -CAssetId CDummyGameArea::IGetAreaId() const { return x10_areaId; } +s32 CDummyGameArea::IGetAreaSaveId() const { return x10_areaId; } CAssetId CDummyGameArea::IGetAreaAssetId() const { return xc_mrea; } @@ -354,9 +357,9 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(id x84_mrea = in.readUint32Big(); if (mlvlVersion > 15) - x88_areaId = CAssetId(in); + x88_areaId = in.readUint32Big(); else - x88_areaId = CAssetId(); + x88_areaId = INT_MAX; const u32 attachedCount = in.readUint32Big(); x8c_attachedAreaIndices.reserve(attachedCount); @@ -782,7 +785,7 @@ bool CGameArea::Invalidate(CStateManager* mgr) { } if (mgr) - mgr->PrepareAreaUnload(GetAreaIndex()); + mgr->PrepareAreaUnload(GetAreaId()); #if 0 dword_805a8eb0 -= GetPostConstructedSize(); @@ -797,7 +800,7 @@ bool CGameArea::Invalidate(CStateManager* mgr) { KillmAreaData(); ClearTokenList(); if (mgr) - mgr->AreaUnloaded(GetAreaIndex()); + mgr->AreaUnloaded(GetAreaId()); return true; } diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index 477c582e4..eb9fdfa6a 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -47,7 +47,7 @@ class CDummyGameArea final : public IGameArea { int x4_mlvlVersion; CAssetId x8_nameSTRG; CAssetId xc_mrea; - CAssetId x10_areaId; + s32 x10_areaId; zeus::CTransform x14_transform; std::vector x44_attachedAreaIndices; std::vector x54_docks; @@ -56,7 +56,7 @@ public: CDummyGameArea(CInputStream& in, int idx, int mlvlVersion); std::pair, s32> IGetScriptingMemoryAlways() const override; - CAssetId IGetAreaId() const override; + s32 IGetAreaSaveId() const override; CAssetId IGetAreaAssetId() const override; bool IIsActive() const override; TAreaId IGetAttachedAreaId(int) const override; @@ -104,7 +104,7 @@ class CGameArea final : public IGameArea { zeus::CTransform x3c_invTransform; zeus::CAABox x6c_aabb; CAssetId x84_mrea; - CAssetId x88_areaId; + s32 x88_areaId; std::vector x8c_attachedAreaIndices; std::vector x9c_deps1; std::vector xac_deps2; @@ -278,8 +278,8 @@ public: void SetLoadPauseState(bool paused); std::pair, s32> IGetScriptingMemoryAlways() const override; - TAreaId GetAreaIndex() const { return x4_selfIdx; } - CAssetId IGetAreaId() const override { return x88_areaId; } + TAreaId GetAreaId() const { return x4_selfIdx; } + s32 IGetAreaSaveId() const override { return x88_areaId; } CAssetId IGetAreaAssetId() const override { return x84_mrea; } bool IIsActive() const override; TAreaId IGetAttachedAreaId(int) const override; diff --git a/Runtime/World/CMorphBallShadow.cpp b/Runtime/World/CMorphBallShadow.cpp index e9c3886e4..0d60b55e0 100644 --- a/Runtime/World/CMorphBallShadow.cpp +++ b/Runtime/World/CMorphBallShadow.cpp @@ -16,7 +16,7 @@ void CMorphBallShadow::GatherAreas(const CStateManager& mgr) { if (area.IsPostConstructed()) occState = area.GetPostConstructed()->x10dc_occlusionState; if (occState == CGameArea::EOcclusionState::Visible) - x18_areas.push_back(area.GetAreaIndex()); + x18_areas.push_back(area.GetAreaId()); } } @@ -105,7 +105,7 @@ bool CMorphBallShadow::AreasValid(const CStateManager& mgr) const { continue; if (it == x18_areas.end()) return false; - if (*it != area.GetAreaIndex()) + if (*it != area.GetAreaId()) return false; ++it; } diff --git a/Runtime/World/CScriptDoor.cpp b/Runtime/World/CScriptDoor.cpp index a0ec4b435..78384e62b 100644 --- a/Runtime/World/CScriptDoor.cpp +++ b/Runtime/World/CScriptDoor.cpp @@ -364,7 +364,7 @@ CScriptDoor::EDoorOpenCondition CScriptDoor::GetDoorOpenCondition(CStateManager& } for (const CGameArea& aliveArea : *world) { - if (aliveArea.GetAreaIndex() == area->GetAreaIndex()) { + if (aliveArea.GetAreaId() == area->GetAreaId()) { continue; } diff --git a/Runtime/World/IGameArea.hpp b/Runtime/World/IGameArea.hpp index 9dd8a7579..a896bb5c9 100644 --- a/Runtime/World/IGameArea.hpp +++ b/Runtime/World/IGameArea.hpp @@ -49,7 +49,7 @@ public: }; virtual std::pair, s32> IGetScriptingMemoryAlways() const = 0; - virtual CAssetId IGetAreaId() const = 0; + virtual s32 IGetAreaSaveId() const = 0; virtual CAssetId IGetAreaAssetId() const = 0; virtual bool IIsActive() const = 0; virtual TAreaId IGetAttachedAreaId(int) const = 0;