diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index f4ad52f36..e9e4b4e88 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -198,11 +198,12 @@ Entity::~Entity() { } void Entity::Initialize() { - RegisterMsg(this, &Entity::MsgRequestServerObjectInfo); - RegisterMsg(this, &Entity::MsgDropClientLoot); - RegisterMsg(this, &Entity::MsgGetFactionTokenType); - RegisterMsg(this, &Entity::MsgPickupItem); - RegisterMsg(this, &Entity::MsgChildRemoved); + RegisterMsg(&Entity::MsgRequestServerObjectInfo); + RegisterMsg(&Entity::MsgDropClientLoot); + RegisterMsg(&Entity::MsgGetFactionTokenType); + RegisterMsg(&Entity::MsgPickupItem); + RegisterMsg(&Entity::MsgChildRemoved); + RegisterMsg(&Entity::MsgGetFlag); /** * Setup trigger */ @@ -2251,8 +2252,7 @@ void Entity::RegisterMsg(const MessageType::Game msgId, std::function(msg); +bool Entity::MsgRequestServerObjectInfo(GameMessages::RequestServerObjectInfo& requestInfo) { AMFArrayValue response; response.Insert("visible", true); response.Insert("objectID", std::to_string(m_ObjectID)); @@ -2288,9 +2288,7 @@ bool Entity::MsgRequestServerObjectInfo(GameMessages::GameMsg& msg) { return true; } -bool Entity::MsgDropClientLoot(GameMessages::GameMsg& msg) { - auto& dropLootMsg = static_cast(msg); - +bool Entity::MsgDropClientLoot(GameMessages::DropClientLoot& dropLootMsg) { if (dropLootMsg.item != LOT_NULL && dropLootMsg.item != 0) { Loot::Info info{ .id = dropLootMsg.lootID, @@ -2307,13 +2305,11 @@ bool Entity::MsgDropClientLoot(GameMessages::GameMsg& msg) { return true; } -bool Entity::MsgGetFlag(GameMessages::GameMsg& msg) { - auto& flagMsg = static_cast(msg); +bool Entity::MsgGetFlag(GameMessages::GetFlag& flagMsg) { if (m_Character) flagMsg.flag = m_Character->GetPlayerFlag(flagMsg.flagID); return true; } -bool Entity::MsgGetFactionTokenType(GameMessages::GameMsg& msg) { - auto& tokenMsg = static_cast(msg); +bool Entity::MsgGetFactionTokenType(GameMessages::GetFactionTokenType& tokenMsg) { GameMessages::GetFlag getFlagMsg{}; getFlagMsg.flagID = ePlayerFlag::ASSEMBLY_FACTION; @@ -2336,8 +2332,7 @@ bool Entity::MsgGetFactionTokenType(GameMessages::GameMsg& msg) { return tokenMsg.tokenType != LOT_NULL; } -bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) { - auto& pickupItemMsg = static_cast(msg); +bool Entity::MsgPickupItem(GameMessages::PickupItem& pickupItemMsg) { if (GetObjectID() == pickupItemMsg.lootOwnerID) { PickupItem(pickupItemMsg.lootID); } else { @@ -2358,7 +2353,7 @@ bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) { return true; } -bool Entity::MsgChildRemoved(GameMessages::GameMsg& msg) { - GetScript()->OnChildRemoved(*this, static_cast(msg)); +bool Entity::MsgChildRemoved(GameMessages::ChildRemoved& msg) { + GetScript()->OnChildRemoved(*this, msg); return true; } diff --git a/dGame/Entity.h b/dGame/Entity.h index 5310cd0f1..565c906cd 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -20,6 +20,12 @@ namespace GameMessages { struct ShootingGalleryFire; struct ChildLoaded; struct PlayerResurrectionFinished; + struct RequestServerObjectInfo; + struct DropClientLoot; + struct GetFlag; + struct GetFactionTokenType; + struct PickupItem; + struct ChildRemoved; }; namespace MessageType { @@ -175,12 +181,12 @@ class Entity { void AddComponent(eReplicaComponentType componentId, Component* component); - bool MsgRequestServerObjectInfo(GameMessages::GameMsg& msg); - bool MsgDropClientLoot(GameMessages::GameMsg& msg); - bool MsgGetFlag(GameMessages::GameMsg& msg); - bool MsgGetFactionTokenType(GameMessages::GameMsg& msg); - bool MsgPickupItem(GameMessages::GameMsg& msg); - bool MsgChildRemoved(GameMessages::GameMsg& msg); + bool MsgRequestServerObjectInfo(GameMessages::RequestServerObjectInfo& msg); + bool MsgDropClientLoot(GameMessages::DropClientLoot& msg); + bool MsgGetFlag(GameMessages::GetFlag& msg); + bool MsgGetFactionTokenType(GameMessages::GetFactionTokenType& msg); + bool MsgPickupItem(GameMessages::PickupItem& msg); + bool MsgChildRemoved(GameMessages::ChildRemoved& msg); // This is expceted to never return nullptr, an assert checks this. CppScripts::Script* const GetScript() const; @@ -343,14 +349,19 @@ class Entity { bool HandleMsg(GameMessages::GameMsg& msg) const; - void RegisterMsg(const MessageType::Game msgId, auto* self, const auto handler) { - RegisterMsg(msgId, std::bind(handler, self, std::placeholders::_1)); - } - - template - inline void RegisterMsg(auto* self, const auto handler) { - T msg; - RegisterMsg(msg.msgId, self, handler); + // Provided a function that has a derived GameMessage as its only argument and returns a boolean, + // this will register it as a handler for that message type. Casting is done automatically to the type + // of the message in the first argument. This object is expected to exist as long as the handler can be called. + template + inline void RegisterMsg(bool (Entity::* handler)(DerivedGameMsg&)) { + static_assert(std::is_base_of_v, "DerivedGameMsg must inherit from GameMsg"); + const auto boundFunction = std::bind(handler, this, std::placeholders::_1); + // This is the actual function that will be registered, which casts the base GameMsg to the derived type + const auto castWrapper = [boundFunction](GameMessages::GameMsg& msg) { + return boundFunction(static_cast(msg)); + }; + DerivedGameMsg msg; + RegisterMsg(msg.msgId, castWrapper); } /** diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 7567e20b6..60d1f999e 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -31,8 +31,7 @@ #include "Amf3.h" ActivityComponent::ActivityComponent(Entity* parent, int32_t componentID) : Component(parent, componentID) { - using namespace GameMessages; - RegisterMsg(this, &ActivityComponent::OnGetObjectReportInfo); + RegisterMsg(&ActivityComponent::OnGetObjectReportInfo); /* * This is precisely what the client does functionally * Use the component id as the default activity id and load its data from the database @@ -591,9 +590,7 @@ Entity* LobbyPlayer::GetEntity() const { return Game::entityManager->GetEntity(entityID); } -bool ActivityComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportInfo = static_cast(msg); - +bool ActivityComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { auto& activityInfo = reportInfo.info->PushDebug("Activity"); auto& instances = activityInfo.PushDebug("Instances: " + std::to_string(m_Instances.size())); diff --git a/dGame/dComponents/ActivityComponent.h b/dGame/dComponents/ActivityComponent.h index dc249068e..178ac6071 100644 --- a/dGame/dComponents/ActivityComponent.h +++ b/dGame/dComponents/ActivityComponent.h @@ -343,7 +343,7 @@ class ActivityComponent : public Component { private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& msg); /** * The database information for this activity */ diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 73118e362..2bad800b0 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -30,10 +30,7 @@ #include "Amf3.h" BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { - { - using namespace GameMessages; - RegisterMsg(this, &BaseCombatAIComponent::MsgGetObjectReportInfo); - } + RegisterMsg(&BaseCombatAIComponent::MsgGetObjectReportInfo); m_Target = LWOOBJID_EMPTY; m_DirtyStateOrTarget = true; m_State = AiState::spawn; @@ -845,10 +842,9 @@ void BaseCombatAIComponent::IgnoreThreat(const LWOOBJID threat, const float valu m_Target = LWOOBJID_EMPTY; } -bool BaseCombatAIComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) { +bool BaseCombatAIComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { using enum AiState; - auto& reportMsg = static_cast(msg); - auto& cmptType = reportMsg.info->PushDebug("Base Combat AI"); + auto& cmptType = reportInfo.info->PushDebug("Base Combat AI"); cmptType.PushDebug("Component ID") = GetComponentID(); auto& targetInfo = cmptType.PushDebug("Current Target Info"); targetInfo.PushDebug("Current Target ID") = std::to_string(m_Target); diff --git a/dGame/dComponents/BaseCombatAIComponent.h b/dGame/dComponents/BaseCombatAIComponent.h index 009a96d2c..95eb75ced 100644 --- a/dGame/dComponents/BaseCombatAIComponent.h +++ b/dGame/dComponents/BaseCombatAIComponent.h @@ -234,7 +234,7 @@ class BaseCombatAIComponent final : public Component { // Ignore a threat for a certain amount of time void IgnoreThreat(const LWOOBJID target, const float time); - bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg); + bool MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); private: /** diff --git a/dGame/dComponents/BouncerComponent.cpp b/dGame/dComponents/BouncerComponent.cpp index 3c535e436..3f0ffc9a5 100644 --- a/dGame/dComponents/BouncerComponent.cpp +++ b/dGame/dComponents/BouncerComponent.cpp @@ -31,10 +31,7 @@ BouncerComponent::BouncerComponent(Entity* parent, const int32_t componentID) : LookupPetSwitch(); } - { - using namespace GameMessages; - RegisterMsg(this, &BouncerComponent::MsgGetObjectReportInfo); - } + RegisterMsg(&BouncerComponent::MsgGetObjectReportInfo); } BouncerComponent::~BouncerComponent() { @@ -113,9 +110,8 @@ void BouncerComponent::LookupPetSwitch() { } } -bool BouncerComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportMsg = static_cast(msg); - auto& cmptType = reportMsg.info->PushDebug("Bouncer"); +bool BouncerComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + auto& cmptType = reportInfo.info->PushDebug("Bouncer"); cmptType.PushDebug("Component ID") = GetComponentID(); auto& destPos = cmptType.PushDebug("Destination Position"); if (m_Destination != NiPoint3Constant::ZERO) { diff --git a/dGame/dComponents/BouncerComponent.h b/dGame/dComponents/BouncerComponent.h index b3221e121..f0493ee92 100644 --- a/dGame/dComponents/BouncerComponent.h +++ b/dGame/dComponents/BouncerComponent.h @@ -51,7 +51,7 @@ class BouncerComponent final : public Component { */ void LookupPetSwitch(); - bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg); + bool MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); private: /** diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 54708226b..dda9d5599 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -49,11 +49,10 @@ CharacterComponent::CharacterComponent(Entity* parent, const int32_t componentID m_LastUpdateTimestamp = std::time(nullptr); m_SystemAddress = systemAddress; - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &CharacterComponent::OnGetObjectReportInfo); + RegisterMsg(&CharacterComponent::OnGetObjectReportInfo); } -bool CharacterComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportInfo = static_cast(msg); +bool CharacterComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { auto& cmptType = reportInfo.info->PushDebug("Character"); diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index c1f107b54..6f5eeaab3 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -17,6 +17,10 @@ enum class eGameActivity : uint32_t; class Item; +namespace GameMessages { + struct GetObjectReportInfo; +} + /** * The statistics that can be achieved per zone */ @@ -331,7 +335,7 @@ class CharacterComponent final : public Component { void LoadVisitedLevelsXml(const tinyxml2::XMLElement& doc); private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); /** * The map of active venture vision effects diff --git a/dGame/dComponents/CollectibleComponent.cpp b/dGame/dComponents/CollectibleComponent.cpp index fce32e931..10b50c2d3 100644 --- a/dGame/dComponents/CollectibleComponent.cpp +++ b/dGame/dComponents/CollectibleComponent.cpp @@ -6,16 +6,14 @@ CollectibleComponent::CollectibleComponent(Entity* parentEntity, const int32_t componentID, const int32_t collectibleId) : Component(parentEntity, componentID), m_CollectibleId(collectibleId) { - using namespace GameMessages; - RegisterMsg(this, &CollectibleComponent::MsgGetObjectReportInfo); + RegisterMsg(&CollectibleComponent::MsgGetObjectReportInfo); } void CollectibleComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) { outBitStream.Write(GetCollectibleId()); } -bool CollectibleComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportMsg = static_cast(msg); +bool CollectibleComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportMsg) { auto& cmptType = reportMsg.info->PushDebug("Collectible"); auto collectibleID = static_cast(m_CollectibleId) + static_cast(Game::server->GetZoneID() << 8); diff --git a/dGame/dComponents/CollectibleComponent.h b/dGame/dComponents/CollectibleComponent.h index ba1a3f286..5c9b5ea05 100644 --- a/dGame/dComponents/CollectibleComponent.h +++ b/dGame/dComponents/CollectibleComponent.h @@ -12,7 +12,7 @@ class CollectibleComponent final : public Component { int16_t GetCollectibleId() const { return m_CollectibleId; } void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) override; - bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg); + bool MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); private: int16_t m_CollectibleId = 0; }; diff --git a/dGame/dComponents/Component.h b/dGame/dComponents/Component.h index b54a8fab4..094ed9f39 100644 --- a/dGame/dComponents/Component.h +++ b/dGame/dComponents/Component.h @@ -55,17 +55,18 @@ class Component { virtual void LoadFromXml(const tinyxml2::XMLDocument& doc) {} virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {} - protected: - - inline void RegisterMsg(const MessageType::Game msgId, auto* self, const auto handler) { - m_Parent->RegisterMsg(msgId, std::bind(handler, self, std::placeholders::_1)); - } - - template - inline void RegisterMsg(auto* self, const auto handler) { - T msg; - RegisterMsg(msg.msgId, self, handler); + template + inline void RegisterMsg(bool (GameObjClass::*handler)(DerivedMsg&)) { + static_assert(std::is_base_of_v, "DerivedMsg must inherit from GameMsg"); + static_assert(std::is_base_of_v, "GameObjClass must inherit from Component"); + const auto handlerBound = std::bind(handler, static_cast(this), std::placeholders::_1); + const auto castWrapper = [handlerBound](GameMessages::GameMsg& msg) { + return handlerBound(static_cast(msg)); + }; + + DerivedMsg msg; + m_Parent->RegisterMsg(msg.msgId, castWrapper); } /** diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index b2a41358c..2b26368f7 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -18,7 +18,7 @@ #include "Amf3.h" ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity, const int32_t componentID) : PhysicsComponent(entity, componentID) { - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &ControllablePhysicsComponent::OnGetObjectReportInfo); + RegisterMsg(&ControllablePhysicsComponent::OnGetObjectReportInfo); m_Velocity = {}; m_AngularVelocity = {}; @@ -359,9 +359,8 @@ void ControllablePhysicsComponent::SetStunImmunity( ); } -bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - PhysicsComponent::OnGetObjectReportInfo(msg); - auto& reportInfo = static_cast(msg); +bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + PhysicsComponent::OnGetObjectReportInfo(reportInfo); auto& info = reportInfo.subCategory->PushDebug("Controllable Info"); auto& vel = info.PushDebug("Velocity"); diff --git a/dGame/dComponents/ControllablePhysicsComponent.h b/dGame/dComponents/ControllablePhysicsComponent.h index 419e92509..76de5b516 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.h +++ b/dGame/dComponents/ControllablePhysicsComponent.h @@ -284,7 +284,7 @@ class ControllablePhysicsComponent : public PhysicsComponent { private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); /** * The entity that owns this component */ diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 47aa0c906..398bcb429 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -48,7 +48,6 @@ Implementation DestroyableComponent::IsEnemyImplentation; Implementation DestroyableComponent::IsFriendImplentation; DestroyableComponent::DestroyableComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { - using namespace GameMessages; m_iArmor = 0; m_fMaxArmor = 0.0f; m_iImagination = 0; @@ -86,8 +85,9 @@ DestroyableComponent::DestroyableComponent(Entity* parent, const int32_t compone m_DamageCooldownTimer = 0.0f; - RegisterMsg(this, &DestroyableComponent::OnGetObjectReportInfo); - RegisterMsg(this, &DestroyableComponent::OnSetFaction); + RegisterMsg(&DestroyableComponent::OnGetObjectReportInfo); + RegisterMsg(&DestroyableComponent::OnSetFaction); + RegisterMsg(&DestroyableComponent::OnIsDead); } DestroyableComponent::~DestroyableComponent() { @@ -1061,8 +1061,7 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source) { } } -bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportInfo = static_cast(msg); +bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { auto& destroyableInfo = reportInfo.info->PushDebug("Destroyable"); destroyableInfo.PushDebug("DestructibleComponent DB Table Template ID") = m_ComponentID; @@ -1184,10 +1183,14 @@ bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { return true; } -bool DestroyableComponent::OnSetFaction(GameMessages::GameMsg& msg) { - auto& modifyFaction = static_cast(msg); +bool DestroyableComponent::OnSetFaction(GameMessages::SetFaction& setFaction) { m_DirtyHealth = true; Game::entityManager->SerializeEntity(m_Parent); - SetFaction(modifyFaction.factionID, modifyFaction.bIgnoreChecks); + SetFaction(setFaction.factionID, setFaction.bIgnoreChecks); + return true; +} + +bool DestroyableComponent::OnIsDead(GameMessages::IsDead& isDead) { + isDead.bDead = m_IsDead || (GetHealth() == 0 && GetArmor() == 0); return true; } diff --git a/dGame/dComponents/DestroyableComponent.h b/dGame/dComponents/DestroyableComponent.h index 9b3e46af3..7ef55a210 100644 --- a/dGame/dComponents/DestroyableComponent.h +++ b/dGame/dComponents/DestroyableComponent.h @@ -11,6 +11,8 @@ namespace GameMessages { struct GetObjectReportInfo; + struct SetFaction; + struct IsDead; }; namespace CppScripts { @@ -470,8 +472,9 @@ class DestroyableComponent final : public Component { // handle hardcode mode drops void DoHardcoreModeDrops(const LWOOBJID source); - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); - bool OnSetFaction(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); + bool OnSetFaction(GameMessages::SetFaction& setFaction); + bool OnIsDead(GameMessages::IsDead& isDead); void SetIsDead(const bool value) { m_IsDead = value; } diff --git a/dGame/dComponents/GhostComponent.cpp b/dGame/dComponents/GhostComponent.cpp index 96283de38..3c21e5404 100644 --- a/dGame/dComponents/GhostComponent.cpp +++ b/dGame/dComponents/GhostComponent.cpp @@ -12,10 +12,10 @@ GhostComponent::GhostComponent(Entity* parent, const int32_t componentID) : Comp m_GhostReferencePoint = NiPoint3Constant::ZERO; m_GhostOverridePoint = NiPoint3Constant::ZERO; m_GhostOverride = false; - - RegisterMsg(this, &GhostComponent::OnToggleGMInvis); - RegisterMsg(this, &GhostComponent::OnGetGMInvis); - RegisterMsg(this, &GhostComponent::MsgGetObjectReportInfo); + + RegisterMsg(&GhostComponent::OnToggleGMInvis); + RegisterMsg(&GhostComponent::OnGetGMInvis); + RegisterMsg(&GhostComponent::MsgGetObjectReportInfo); } GhostComponent::~GhostComponent() { @@ -87,8 +87,7 @@ void GhostComponent::GhostEntity(LWOOBJID id) { m_ObservedEntities.erase(id); } -bool GhostComponent::OnToggleGMInvis(GameMessages::GameMsg& msg) { - auto& gmInvisMsg = static_cast(msg); +bool GhostComponent::OnToggleGMInvis(GameMessages::ToggleGMInvis& gmInvisMsg) { gmInvisMsg.bStateOut = !m_IsGMInvisible; m_IsGMInvisible = !m_IsGMInvisible; LOG_DEBUG("GM Invisibility toggled to: %s", m_IsGMInvisible ? "true" : "false"); @@ -114,15 +113,13 @@ bool GhostComponent::OnToggleGMInvis(GameMessages::GameMsg& msg) { return true; } -bool GhostComponent::OnGetGMInvis(GameMessages::GameMsg& msg) { +bool GhostComponent::OnGetGMInvis(GameMessages::GetGMInvis& gmInvisMsg) { LOG_DEBUG("GM Invisibility requested: %s", m_IsGMInvisible ? "true" : "false"); - auto& gmInvisMsg = static_cast(msg); gmInvisMsg.bGMInvis = m_IsGMInvisible; return gmInvisMsg.bGMInvis; } -bool GhostComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportMsg = static_cast(msg); +bool GhostComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportMsg) { auto& cmptType = reportMsg.info->PushDebug("Ghost"); cmptType.PushDebug("Component ID") = GetComponentID(); cmptType.PushDebug("Is GM Invis") = false; diff --git a/dGame/dComponents/GhostComponent.h b/dGame/dComponents/GhostComponent.h index 01443c1be..d8ea3dcca 100644 --- a/dGame/dComponents/GhostComponent.h +++ b/dGame/dComponents/GhostComponent.h @@ -45,11 +45,11 @@ class GhostComponent final : public Component { void GhostEntity(const LWOOBJID id); - bool OnToggleGMInvis(GameMessages::GameMsg& msg); + bool OnToggleGMInvis(GameMessages::ToggleGMInvis& msg); - bool OnGetGMInvis(GameMessages::GameMsg& msg); + bool OnGetGMInvis(GameMessages::GetGMInvis& msg); - bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg); + bool MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& msg); private: diff --git a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp index afec4427b..52819657d 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp @@ -3,7 +3,7 @@ #include "Amf3.h" HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) { - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &HavokVehiclePhysicsComponent::OnGetObjectReportInfo); + RegisterMsg(&HavokVehiclePhysicsComponent::OnGetObjectReportInfo); m_Velocity = NiPoint3Constant::ZERO; m_AngularVelocity = NiPoint3Constant::ZERO; @@ -102,9 +102,8 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo outBitStream.Write0(); } -bool HavokVehiclePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - PhysicsComponent::OnGetObjectReportInfo(msg); - auto& reportInfo = static_cast(msg); +bool HavokVehiclePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + PhysicsComponent::OnGetObjectReportInfo(reportInfo); if (!reportInfo.subCategory) { return false; } diff --git a/dGame/dComponents/HavokVehiclePhysicsComponent.h b/dGame/dComponents/HavokVehiclePhysicsComponent.h index 3a84adcaa..3b2aba786 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.h +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.h @@ -68,7 +68,7 @@ class HavokVehiclePhysicsComponent : public PhysicsComponent { void SetRemoteInputInfo(const RemoteInputInfo&); private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); NiPoint3 m_Velocity; NiPoint3 m_AngularVelocity; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 212572ae4..2ff827d8c 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -44,8 +44,7 @@ #include InventoryComponent::InventoryComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { - using namespace GameMessages; - RegisterMsg(this, &InventoryComponent::OnGetObjectReportInfo); + RegisterMsg(&InventoryComponent::OnGetObjectReportInfo); this->m_Dirty = true; this->m_Equipped = {}; this->m_Pushed = {}; @@ -1847,9 +1846,8 @@ std::string DebugInvToString(const eInventoryType inv, bool verbose) { return ""; } -bool InventoryComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& report = static_cast(msg); - auto& cmpt = report.info->PushDebug("Inventory"); +bool InventoryComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + auto& cmpt = reportInfo.info->PushDebug("Inventory"); cmpt.PushDebug("Component ID") = GetComponentID(); uint32_t numItems = 0; for (auto* inventory : m_Inventories | std::views::values) numItems += inventory->GetItems().size(); @@ -1859,7 +1857,7 @@ bool InventoryComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { for (const auto& [id, inventoryMut] : m_Inventories) { if (!inventoryMut) continue; const auto* const inventory = inventoryMut; - auto& curInv = itemsInBags.PushDebug(DebugInvToString(id, report.bVerbose) + " - " + std::to_string(id)); + auto& curInv = itemsInBags.PushDebug(DebugInvToString(id, reportInfo.bVerbose) + " - " + std::to_string(id)); for (uint32_t i = 0; i < inventory->GetSize(); i++) { const auto* const item = inventory->FindItemBySlot(i); if (!item) continue; diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index 3728c428d..beaf0efb1 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -31,6 +31,10 @@ typedef std::map EquipmentMap; enum class eItemType : int32_t; +namespace GameMessages { + struct GetObjectReportInfo; +} + /** * Handles the inventory of entity, including the items they possess and have equipped. An entity can have inventories * of different types, each type representing a different group of items, see `eInventoryType` for a list of @@ -411,7 +415,7 @@ class InventoryComponent final : public Component { // Used to migrate a character version, no need to call outside of that context void RegenerateItemIDs(); - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); ~InventoryComponent() override; diff --git a/dGame/dComponents/MissionComponent.cpp b/dGame/dComponents/MissionComponent.cpp index b3a503d56..41a2eda6f 100644 --- a/dGame/dComponents/MissionComponent.cpp +++ b/dGame/dComponents/MissionComponent.cpp @@ -27,12 +27,11 @@ std::unordered_map> MissionComponent: //! Initializer MissionComponent::MissionComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { - using namespace GameMessages; m_LastUsedMissionOrderUID = Game::zoneManager->GetUniqueMissionIdStartingValue(); - RegisterMsg(this, &MissionComponent::OnGetObjectReportInfo); - RegisterMsg(this, &MissionComponent::OnGetMissionState); - RegisterMsg(this, &MissionComponent::OnMissionNeedsLot); + RegisterMsg(&MissionComponent::OnGetObjectReportInfo); + RegisterMsg(&MissionComponent::OnGetMissionState); + RegisterMsg(&MissionComponent::OnMissionNeedsLot); } //! Destructor @@ -706,9 +705,8 @@ void PushMissions(const std::map& missions, AMFArrayValue& V } } -bool MissionComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportMsg = static_cast(msg); - auto& missionInfo = reportMsg.info->PushDebug("Mission (Laggy)"); +bool MissionComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + auto& missionInfo = reportInfo.info->PushDebug("Mission (Laggy)"); missionInfo.PushDebug("Component ID") = GetComponentID(); // Sort the missions so they are easier to parse and present to the end user std::map achievements; @@ -724,26 +722,24 @@ bool MissionComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { // None of these should be empty, but if they are dont print the field if (!achievements.empty() || !missions.empty()) { auto& incompleteMissions = missionInfo.PushDebug("Incomplete Missions"); - PushMissions(achievements, incompleteMissions, reportMsg.bVerbose); - PushMissions(missions, incompleteMissions, reportMsg.bVerbose); + PushMissions(achievements, incompleteMissions, reportInfo.bVerbose); + PushMissions(missions, incompleteMissions, reportInfo.bVerbose); } if (!doneMissions.empty()) { auto& completeMissions = missionInfo.PushDebug("Completed Missions"); - PushMissions(doneMissions, completeMissions, reportMsg.bVerbose); + PushMissions(doneMissions, completeMissions, reportInfo.bVerbose); } return true; } -bool MissionComponent::OnGetMissionState(GameMessages::GameMsg& msg) { - auto misState = static_cast(msg); - misState.missionState = GetMissionState(misState.missionID); +bool MissionComponent::OnGetMissionState(GameMessages::GetMissionState& getMissionState) { + getMissionState.missionState = GetMissionState(getMissionState.missionID); return true; } -bool MissionComponent::OnMissionNeedsLot(GameMessages::GameMsg& msg) { - const auto& needMsg = static_cast(msg); - return RequiresItem(needMsg.item); +bool MissionComponent::OnMissionNeedsLot(GameMessages::MissionNeedsLot& missionNeedsLot) { + return RequiresItem(missionNeedsLot.item); } diff --git a/dGame/dComponents/MissionComponent.h b/dGame/dComponents/MissionComponent.h index a5cd058ad..19267a6d3 100644 --- a/dGame/dComponents/MissionComponent.h +++ b/dGame/dComponents/MissionComponent.h @@ -171,9 +171,9 @@ class MissionComponent final : public Component { void ResetMission(const int32_t missionId); private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); - bool OnGetMissionState(GameMessages::GameMsg& msg); - bool OnMissionNeedsLot(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); + bool OnGetMissionState(GameMessages::GetMissionState& getMissionState); + bool OnMissionNeedsLot(GameMessages::MissionNeedsLot& missionNeedsLot); /** * All the missions owned by this entity, mapped by mission ID */ diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 2c975136a..1df3dd896 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -15,20 +15,18 @@ #include "DluAssert.h" ModelComponent::ModelComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { - using namespace GameMessages; m_OriginalPosition = m_Parent->GetDefaultPosition(); m_OriginalRotation = m_Parent->GetDefaultRotation(); m_IsPaused = false; m_NumListeningInteract = 0; m_userModelID = m_Parent->GetVarAs(u"userModelID"); - RegisterMsg(this, &ModelComponent::OnRequestUse); - RegisterMsg(this, &ModelComponent::OnResetModelToDefaults); - RegisterMsg(this, &ModelComponent::OnGetObjectReportInfo); + RegisterMsg(&ModelComponent::OnRequestUse); + RegisterMsg(&ModelComponent::OnResetModelToDefaults); + RegisterMsg(&ModelComponent::OnGetObjectReportInfo); } -bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) { - auto& reset = static_cast(msg); +bool ModelComponent::OnResetModelToDefaults(GameMessages::ResetModelToDefaults& reset) { if (reset.bResetBehaviors) for (auto& behavior : m_Behaviors) behavior.HandleMsg(reset); if (reset.bUnSmash) { @@ -59,10 +57,9 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) { return true; } -bool ModelComponent::OnRequestUse(GameMessages::GameMsg& msg) { +bool ModelComponent::OnRequestUse(GameMessages::RequestUse& requestUse) { bool toReturn = false; if (!m_IsPaused) { - auto& requestUse = static_cast(msg); for (auto& behavior : m_Behaviors) behavior.HandleMsg(requestUse); toReturn = true; } @@ -343,10 +340,9 @@ void ModelComponent::RemoveAttack() { } } -bool ModelComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportMsg = static_cast(msg); - if (!reportMsg.info) return false; - auto& cmptInfo = reportMsg.info->PushDebug("Model Behaviors (Mutable)"); +bool ModelComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + if (!reportInfo.info) return false; + auto& cmptInfo = reportInfo.info->PushDebug("Model Behaviors (Mutable)"); cmptInfo.PushDebug("Component ID") = GetComponentID(); cmptInfo.PushDebug("Name") = "Objects_" + std::to_string(m_Parent->GetLOT()) + "_name"; diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 97b165cbf..700f43f4f 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -32,9 +32,9 @@ class ModelComponent final : public Component { void LoadBehaviors(); void Update(float deltaTime) override; - bool OnRequestUse(GameMessages::GameMsg& msg); - bool OnResetModelToDefaults(GameMessages::GameMsg& msg); - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnRequestUse(GameMessages::RequestUse& requestUse); + bool OnResetModelToDefaults(GameMessages::ResetModelToDefaults& resetModelToDefaults); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override; diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index faedc8483..3519712a1 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -16,6 +16,7 @@ #include "CDComponentsRegistryTable.h" #include "QuickBuildComponent.h" #include "CDPhysicsComponentTable.h" +#include "Amf3.h" #include "dNavMesh.h" @@ -57,6 +58,8 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component m_SavedVelocity = NiPoint3Constant::ZERO; m_IsBounced = false; + RegisterMsg(&MovementAIComponent::OnGetObjectReportInfo); + if (!m_Parent->GetComponent()) SetPath(m_Parent->GetVarAsString(u"attached_path")); } @@ -422,3 +425,63 @@ void MovementAIComponent::SetMaxSpeed(const float value) { m_MaxSpeed = value; m_Acceleration = value / 5; } + +bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + + auto& movementInfo = reportInfo.info->PushDebug("MovementAI"); + if (m_Path) { + movementInfo.PushDebug("Path") = m_Path->pathName; + } + + auto& movementAiInfo = movementInfo.PushDebug("Movement AI Info"); + movementAiInfo.PushDebug("Movement Type") = m_Info.movementType; + movementAiInfo.PushDebug("Wander Radius") = m_Info.wanderRadius; + movementAiInfo.PushDebug("Wander Speed") = m_Info.wanderSpeed; + movementAiInfo.PushDebug("Wander Chance") = m_Info.wanderChance; + movementAiInfo.PushDebug("Wander Delay Min") = m_Info.wanderDelayMin; + movementAiInfo.PushDebug("Wander Delay Max") = m_Info.wanderDelayMax; + + auto& speedInfo = movementInfo.PushDebug("Speed Info"); + speedInfo.PushDebug("Base Speed") = m_BaseSpeed; + speedInfo.PushDebug("Max Speed") = m_MaxSpeed; + speedInfo.PushDebug("Current Speed") = m_CurrentSpeed; + speedInfo.PushDebug("Acceleration") = m_Acceleration; + + movementInfo.PushDebug("Halt Distance") = m_HaltDistance; + movementInfo.PushDebug("Time To Travel") = m_TimeToTravel; + movementInfo.PushDebug("Time Travelled") = m_TimeTravelled; + movementInfo.PushDebug("Lock Rotation") = m_LockRotation; + movementInfo.PushDebug("Paused") = m_Paused; + movementInfo.PushDebug("Pulling To Point") = m_PullingToPoint; + + auto& pullPointInfo = movementInfo.PushDebug("Pull Point"); + pullPointInfo.PushDebug("X") = m_PullPoint.x; + pullPointInfo.PushDebug("Y") = m_PullPoint.y; + pullPointInfo.PushDebug("Z") = m_PullPoint.z; + + // movementInfo.PushDebug("Delay") = m_Delay; + + auto& waypoints = movementInfo.PushDebug("Interpolated Waypoints"); + int i = 0; + for (const auto& point : m_InterpolatedWaypoints) { + auto& waypoint = waypoints.PushDebug("Waypoint " + std::to_string(++i)); + waypoint.PushDebug("X") = point.x; + waypoint.PushDebug("Y") = point.y; + waypoint.PushDebug("Z") = point.z; + } + + i = 0; + auto& currentPath = movementInfo.PushDebug("Current Path"); + auto pathCopy = m_CurrentPath; // Copy to avoid modifying the original stack + while (!pathCopy.empty()) { + const auto& waypoint = pathCopy.top(); + auto& pathWaypoint = currentPath.PushDebug("Waypoint " + std::to_string(++i)); + pathWaypoint.PushDebug("X") = waypoint.position.x; + pathWaypoint.PushDebug("Y") = waypoint.position.y; + pathWaypoint.PushDebug("Z") = waypoint.position.z; + + pathCopy.pop(); + } + + return true; +} diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index 72ff45e83..2a0957164 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -211,6 +211,7 @@ class MovementAIComponent final : public Component { bool IsPaused() const { return m_Paused; } + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); private: /** diff --git a/dGame/dComponents/PhantomPhysicsComponent.cpp b/dGame/dComponents/PhantomPhysicsComponent.cpp index 4ba95f5f1..01ef7dfdf 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.cpp +++ b/dGame/dComponents/PhantomPhysicsComponent.cpp @@ -29,7 +29,7 @@ #include "dpShapeSphere.h" PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) { - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &PhantomPhysicsComponent::OnGetObjectReportInfo); + RegisterMsg(&PhantomPhysicsComponent::OnGetObjectReportInfo); m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); @@ -242,9 +242,8 @@ void PhantomPhysicsComponent::SetRotation(const NiQuaternion& rot) { if (m_dpEntity) m_dpEntity->SetRotation(rot); } -bool PhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - PhysicsComponent::OnGetObjectReportInfo(msg); - auto& reportInfo = static_cast(msg); +bool PhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + PhysicsComponent::OnGetObjectReportInfo(reportInfo); if (!reportInfo.subCategory) { return false; } diff --git a/dGame/dComponents/PhantomPhysicsComponent.h b/dGame/dComponents/PhantomPhysicsComponent.h index ac42dca3a..115783aca 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -116,7 +116,7 @@ class PhantomPhysicsComponent final : public PhysicsComponent { void SetMax(uint32_t max); private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); /** * A scale to apply to the size of the physics object diff --git a/dGame/dComponents/PhysicsComponent.cpp b/dGame/dComponents/PhysicsComponent.cpp index 7d3014760..16722c541 100644 --- a/dGame/dComponents/PhysicsComponent.cpp +++ b/dGame/dComponents/PhysicsComponent.cpp @@ -31,11 +31,11 @@ PhysicsComponent::PhysicsComponent(Entity* parent, const int32_t componentID) : if (m_Parent->HasVar(u"CollisionGroupID")) m_CollisionGroup = m_Parent->GetVar(u"CollisionGroupID"); - RegisterMsg(MessageType::Game::GET_POSITION, this, &PhysicsComponent::OnGetPosition); + RegisterMsg(&PhysicsComponent::OnGetPosition); } -bool PhysicsComponent::OnGetPosition(GameMessages::GameMsg& msg) { - static_cast(msg).pos = GetPosition(); +bool PhysicsComponent::OnGetPosition(GameMessages::GetPosition& msg) { + msg.pos = GetPosition(); return true; } @@ -245,8 +245,7 @@ void PhysicsComponent::SpawnVertices(dpEntity* entity) const { } } -bool PhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& reportInfo = static_cast(msg); +bool PhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { auto& info = reportInfo.info->PushDebug("Physics"); reportInfo.subCategory = &info; diff --git a/dGame/dComponents/PhysicsComponent.h b/dGame/dComponents/PhysicsComponent.h index 67a4a0a5c..066451da9 100644 --- a/dGame/dComponents/PhysicsComponent.h +++ b/dGame/dComponents/PhysicsComponent.h @@ -7,6 +7,7 @@ namespace GameMessages { struct GetObjectReportInfo; + struct GetPosition; }; namespace Raknet { @@ -33,7 +34,7 @@ class PhysicsComponent : public Component { int32_t GetCollisionGroup() const noexcept { return m_CollisionGroup; } void SetCollisionGroup(int32_t group) noexcept { m_CollisionGroup = group; } protected: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& msg); dpEntity* CreatePhysicsEntity(eReplicaComponentType type); @@ -41,7 +42,7 @@ class PhysicsComponent : public Component { void SpawnVertices(dpEntity* entity) const; - bool OnGetPosition(GameMessages::GameMsg& msg); + bool OnGetPosition(GameMessages::GetPosition& msg); NiPoint3 m_Position; diff --git a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp index 8f8df0add..fde91d00c 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp @@ -14,7 +14,7 @@ #include "Amf3.h" RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) { - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo); + RegisterMsg(&RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo); m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); @@ -59,9 +59,8 @@ void RigidbodyPhantomPhysicsComponent::SpawnVertices() const { PhysicsComponent::SpawnVertices(m_dpEntity); } -bool RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - PhysicsComponent::OnGetObjectReportInfo(msg); - auto& reportInfo = static_cast(msg); +bool RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + PhysicsComponent::OnGetObjectReportInfo(reportInfo); auto& info = reportInfo.subCategory->PushDebug("Rigidbody Phantom Info"); info.PushDebug("Scale") = m_Scale; return true; diff --git a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h index dc18da493..75cb11cda 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h @@ -29,7 +29,7 @@ class RigidbodyPhantomPhysicsComponent : public PhysicsComponent { void SpawnVertices() const; private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); float m_Scale{}; diff --git a/dGame/dComponents/ScriptComponent.cpp b/dGame/dComponents/ScriptComponent.cpp index c91233772..87b6e6e1c 100644 --- a/dGame/dComponents/ScriptComponent.cpp +++ b/dGame/dComponents/ScriptComponent.cpp @@ -9,13 +9,12 @@ #include "Amf3.h" ScriptComponent::ScriptComponent(Entity* parent, const int32_t componentID, const std::string& scriptName, bool serialized, bool client) : Component(parent, componentID) { - using namespace GameMessages; m_Serialized = serialized; m_Client = client; m_ScriptName = scriptName; SetScript(scriptName); - RegisterMsg(this, &ScriptComponent::OnGetObjectReportInfo); + RegisterMsg(&ScriptComponent::OnGetObjectReportInfo); } void ScriptComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) { @@ -52,10 +51,9 @@ void ScriptComponent::SetScript(const std::string& scriptName) { m_Script = CppScripts::GetScript(m_Parent, scriptName); } -bool ScriptComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - auto& infoMsg = static_cast(msg); +bool ScriptComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { - auto& scriptInfo = infoMsg.info->PushDebug("Script"); + auto& scriptInfo = reportInfo.info->PushDebug("Script"); scriptInfo.PushDebug("Script Name") = m_ScriptName.empty() ? "None" : m_ScriptName; auto& networkSettings = scriptInfo.PushDebug("Network Settings"); for (const auto* const setting : m_Parent->GetNetworkSettings()) { diff --git a/dGame/dComponents/ScriptComponent.h b/dGame/dComponents/ScriptComponent.h index cf4b2537a..e79b8e91e 100644 --- a/dGame/dComponents/ScriptComponent.h +++ b/dGame/dComponents/ScriptComponent.h @@ -43,7 +43,7 @@ class ScriptComponent final : public Component { */ void SetScript(const std::string& scriptName); - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); private: diff --git a/dGame/dComponents/SimplePhysicsComponent.cpp b/dGame/dComponents/SimplePhysicsComponent.cpp index c0efa5440..dcb870215 100644 --- a/dGame/dComponents/SimplePhysicsComponent.cpp +++ b/dGame/dComponents/SimplePhysicsComponent.cpp @@ -16,7 +16,7 @@ #include "Amf3.h" SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) { - RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &SimplePhysicsComponent::OnGetObjectReportInfo); + RegisterMsg(&SimplePhysicsComponent::OnGetObjectReportInfo); m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); @@ -76,9 +76,8 @@ void SimplePhysicsComponent::SetPhysicsMotionState(uint32_t value) { m_PhysicsMotionState = value; } -bool SimplePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { - PhysicsComponent::OnGetObjectReportInfo(msg); - auto& reportInfo = static_cast(msg); +bool SimplePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) { + PhysicsComponent::OnGetObjectReportInfo(reportInfo); auto& info = reportInfo.subCategory->PushDebug("Simple Physics Info"); auto& velocity = info.PushDebug("Velocity"); velocity.PushDebug("x") = m_Velocity.x; diff --git a/dGame/dComponents/SimplePhysicsComponent.h b/dGame/dComponents/SimplePhysicsComponent.h index d928e489d..402689221 100644 --- a/dGame/dComponents/SimplePhysicsComponent.h +++ b/dGame/dComponents/SimplePhysicsComponent.h @@ -86,7 +86,7 @@ class SimplePhysicsComponent : public PhysicsComponent { void SetClimbableType(const eClimbableType& value) { m_ClimbableType = value; } private: - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo); /** * The current velocity of the entity diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 3ae9ffce0..b7558d4bf 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -936,6 +936,12 @@ namespace GameMessages { LWOOBJID lootOwnerID{}; }; + struct IsDead : public GameMsg { + IsDead() : GameMsg(MessageType::Game::IS_DEAD) {} + + bool bDead{}; + }; + struct ToggleGMInvis : public GameMsg { ToggleGMInvis() : GameMsg(MessageType::Game::TOGGLE_GM_INVIS) {}