diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 1bbde147a..52d832329 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -434,16 +434,16 @@ void CStateManager::SetActorAreaId(CActor& actor, TAreaId aid) { CGameArea* area = x850_world->GetArea(actorAid); if (area->IsPostConstructed()) - area->GetAreaObjects().RemoveObject(actor.GetUniqueId()); + area->GetAreaObjects()->RemoveObject(actor.GetUniqueId()); } if (aid == kInvalidAreaId) return; CGameArea* area = x850_world->GetArea(aid); - if (!area->IsPostConstructed() || area->GetAreaObjects().GetValidObjectById(actor.GetUniqueId())) + if (!area->IsPostConstructed() || area->GetAreaObjects()->GetValidObjectById(actor.GetUniqueId())) return; - area->GetAreaObjects().AddObject(actor); + area->GetAreaObjects()->AddObject(actor); } void CStateManager::TouchSky() const @@ -2300,7 +2300,7 @@ void CStateManager::RemoveObject(TUniqueId uid) { CGameArea* area = x850_world->GetArea(ent->GetAreaIdAlways()); if (area->IsPostConstructed()) - area->GetAreaObjects().RemoveObject(uid); + area->GetAreaObjects()->RemoveObject(uid); } if (TCastToPtr act = ent) x874_sortedListManager->Remove(act.GetPtr()); @@ -2470,7 +2470,7 @@ void CStateManager::AddObject(CEntity& ent) { CGameArea* area = x850_world->GetArea(ent.GetAreaIdAlways()); if (area->IsPostConstructed()) - area->GetAreaObjects().AddObject(ent); + area->GetAreaObjects()->AddObject(ent); } if (TCastToPtr act = ent) diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index eb1940c66..6d91b470a 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -360,15 +360,20 @@ public: s32 GetDockCount() const { return xcc_docks.size(); } Dock* DockNC(s32 dock) { return &xcc_docks[dock]; } - bool IsPostConstructed() const {return xf0_24_postConstructed;} - const CPostConstructed* GetPostConstructed() const {return x12c_postConstructed.get();} + bool IsPostConstructed() const { return xf0_24_postConstructed && x12c_postConstructed; } + const CPostConstructed* GetPostConstructed() const + { + if (!x12c_postConstructed) + return nullptr; + return x12c_postConstructed.get(); + } bool IsValidated() const { return xf0_28_validated; } void SetAreaAttributes(const CScriptAreaAttributes* areaAttributes); bool GetActive() const { return xf0_25_active; } void SetActive(bool active) { xf0_25_active = active; } - CObjectList& GetAreaObjects() const { return *GetPostConstructed()->x10c0_areaObjs.get(); } + CObjectList* GetAreaObjects() const { return GetPostConstructed()->x10c0_areaObjs.get(); } CGameArea* GetNext() const { return x130_next; } diff --git a/Runtime/World/CScriptDock.cpp b/Runtime/World/CScriptDock.cpp index b543581c2..fba12be3f 100644 --- a/Runtime/World/CScriptDock.cpp +++ b/Runtime/World/CScriptDock.cpp @@ -72,12 +72,15 @@ void CScriptDock::Think(float dt, CStateManager& mgr) mgr.SetCurrentAreaId(aid); s32 otherDock = dock->GetOtherDockNumber(dock->GetReferenceCount()); - CObjectList& objs = mgr.WorldNC()->GetArea(aid)->GetAreaObjects(); - for (CEntity* ent : objs) + CObjectList* objs = mgr.WorldNC()->GetArea(aid)->GetAreaObjects(); + if (objs) { - TCastToPtr dock(ent); - if (dock && dock->GetDockId() == otherDock) - dock->SetLoadConnected(mgr, true); + for (CEntity* ent : *objs) + { + TCastToPtr dock(ent); + if (dock && dock->GetDockId() == otherDock) + dock->SetLoadConnected(mgr, true); + } } } }