From 4ef9f4326679803dd1ea8317736f4717366b4c5d Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 19 May 2026 11:42:56 -0700 Subject: [PATCH] feat: make gm registration simpler and safer (#1932) * gm registration re-work * fix errors Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove duplicate message * Remove duplicate function * add null check --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- dGame/Entity.cpp | 31 ++++----- dGame/Entity.h | 39 +++++++----- dGame/dComponents/ActivityComponent.cpp | 7 +-- dGame/dComponents/ActivityComponent.h | 2 +- dGame/dComponents/BaseCombatAIComponent.cpp | 10 +-- dGame/dComponents/BaseCombatAIComponent.h | 2 +- dGame/dComponents/BouncerComponent.cpp | 10 +-- dGame/dComponents/BouncerComponent.h | 2 +- dGame/dComponents/CharacterComponent.cpp | 5 +- dGame/dComponents/CharacterComponent.h | 6 +- dGame/dComponents/CollectibleComponent.cpp | 6 +- dGame/dComponents/CollectibleComponent.h | 2 +- dGame/dComponents/Component.h | 19 +++--- .../ControllablePhysicsComponent.cpp | 7 +-- .../ControllablePhysicsComponent.h | 2 +- dGame/dComponents/DestroyableComponent.cpp | 20 +++--- dGame/dComponents/DestroyableComponent.h | 8 ++- dGame/dComponents/GhostComponent.cpp | 22 +++---- dGame/dComponents/GhostComponent.h | 6 +- .../HavokVehiclePhysicsComponent.cpp | 7 +-- .../HavokVehiclePhysicsComponent.h | 2 +- dGame/dComponents/InventoryComponent.cpp | 10 ++- dGame/dComponents/InventoryComponent.h | 6 +- dGame/dComponents/MissionComponent.cpp | 28 ++++----- dGame/dComponents/MissionComponent.h | 6 +- dGame/dComponents/ModelComponent.cpp | 20 +++--- dGame/dComponents/ModelComponent.h | 6 +- dGame/dComponents/MovementAIComponent.cpp | 63 +++++++++++++++++++ dGame/dComponents/MovementAIComponent.h | 1 + dGame/dComponents/PhantomPhysicsComponent.cpp | 7 +-- dGame/dComponents/PhantomPhysicsComponent.h | 2 +- dGame/dComponents/PhysicsComponent.cpp | 9 ++- dGame/dComponents/PhysicsComponent.h | 5 +- .../RigidbodyPhantomPhysicsComponent.cpp | 7 +-- .../RigidbodyPhantomPhysicsComponent.h | 2 +- dGame/dComponents/ScriptComponent.cpp | 8 +-- dGame/dComponents/ScriptComponent.h | 2 +- dGame/dComponents/SimplePhysicsComponent.cpp | 7 +-- dGame/dComponents/SimplePhysicsComponent.h | 2 +- dGame/dGameMessages/GameMessages.h | 12 ++-- 40 files changed, 232 insertions(+), 186 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index f4ad52f3..e9e4b4e8 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 5310cd0f..565c906c 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 @@ public: 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 @@ public: 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 c5436df8..2dfd5e95 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 @@ -590,9 +589,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 bcaa5bfc..4f423d8e 100644 --- a/dGame/dComponents/ActivityComponent.h +++ b/dGame/dComponents/ActivityComponent.h @@ -347,7 +347,7 @@ public: 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 73118e36..2bad800b 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 009a96d2..95eb75ce 100644 --- a/dGame/dComponents/BaseCombatAIComponent.h +++ b/dGame/dComponents/BaseCombatAIComponent.h @@ -234,7 +234,7 @@ public: // 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 3c535e43..3f0ffc9a 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 b3221e12..f0493ee9 100644 --- a/dGame/dComponents/BouncerComponent.h +++ b/dGame/dComponents/BouncerComponent.h @@ -51,7 +51,7 @@ public: */ 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 54708226..dda9d559 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 c1f107b5..6f5eeaab 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 @@ public: 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 fce32e93..10b50c2d 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 ba1a3f28..5c9b5ea0 100644 --- a/dGame/dComponents/CollectibleComponent.h +++ b/dGame/dComponents/CollectibleComponent.h @@ -12,7 +12,7 @@ public: 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 b54a8fab..094ed9f3 100644 --- a/dGame/dComponents/Component.h +++ b/dGame/dComponents/Component.h @@ -55,17 +55,18 @@ public: virtual void LoadFromXml(const tinyxml2::XMLDocument& doc) {} virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {} - protected: + 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)); + }; - 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); + DerivedMsg msg; + m_Parent->RegisterMsg(msg.msgId, castWrapper); } /** diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index b2a41358..2b26368f 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 419e9250..76de5b51 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.h +++ b/dGame/dComponents/ControllablePhysicsComponent.h @@ -284,7 +284,7 @@ public: 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 0f886d84..b4250966 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,9 +85,9 @@ DestroyableComponent::DestroyableComponent(Entity* parent, const int32_t compone m_DamageCooldownTimer = 0.0f; - RegisterMsg(this, &DestroyableComponent::OnGetObjectReportInfo); - RegisterMsg(this, &DestroyableComponent::OnSetFaction); - RegisterMsg(this, &DestroyableComponent::OnIsDead); + RegisterMsg(&DestroyableComponent::OnGetObjectReportInfo); + RegisterMsg(&DestroyableComponent::OnSetFaction); + RegisterMsg(&DestroyableComponent::OnIsDead); } DestroyableComponent::~DestroyableComponent() { @@ -1061,8 +1060,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,16 +1182,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::GameMsg& msg) { - auto& isDeadMsg = static_cast(msg); - isDeadMsg.bDead = m_IsDead || (GetHealth() == 0 && GetArmor() == 0); +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 0b4d2ba8..7ef55a21 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,9 +472,9 @@ public: // handle hardcode mode drops void DoHardcoreModeDrops(const LWOOBJID source); - bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); - bool OnSetFaction(GameMessages::GameMsg& msg); - bool OnIsDead(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 d5f3b9bc..8223080d 100644 --- a/dGame/dComponents/GhostComponent.cpp +++ b/dGame/dComponents/GhostComponent.cpp @@ -13,9 +13,9 @@ GhostComponent::GhostComponent(Entity* parent, const int32_t componentID) : Comp 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() { @@ -88,15 +88,17 @@ void GhostComponent::GhostEntity(LWOOBJID id) { m_ObservedEntities.erase(id); } -bool GhostComponent::OnToggleGMInvis(GameMessages::GameMsg& msg) { - // TODO: disabled for now while bugs are fixed - return false; - 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"); gmInvisMsg.Send(UNASSIGNED_SYSTEM_ADDRESS); auto* thisUser = UserManager::Instance()->GetUser(m_Parent->GetSystemAddress()); + if (!thisUser) { + LOG("Unable to find user for entity %llu when toggling GM invisibility!", m_Parent->GetObjectID()); + return false; + } + for (const auto& player : PlayerManager::GetAllPlayers()) { if (!player || player->GetObjectID() == m_Parent->GetObjectID()) continue; auto* toUser = UserManager::Instance()->GetUser(player->GetSystemAddress()); @@ -117,9 +119,8 @@ 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); // TODO: disabled for now while bugs are fixed // gmInvisMsg.bGMInvis = m_IsGMInvisible; // return gmInvisMsg.bGMInvis; @@ -127,8 +128,7 @@ bool GhostComponent::OnGetGMInvis(GameMessages::GameMsg& msg) { return false; } -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 8ea05397..4bd3318a 100644 --- a/dGame/dComponents/GhostComponent.h +++ b/dGame/dComponents/GhostComponent.h @@ -45,11 +45,11 @@ public: 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 afec4427..52819657 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 3a84adca..3b2aba78 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.h +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.h @@ -68,7 +68,7 @@ public: 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 212572ae..2ff827d8 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 3728c428..beaf0efb 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 @@ public: // 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 e99b1f5e..e7c03379 100644 --- a/dGame/dComponents/MissionComponent.cpp +++ b/dGame/dComponents/MissionComponent.cpp @@ -28,12 +28,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 @@ -649,9 +648,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; @@ -667,28 +665,26 @@ 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); } void MissionComponent::FixRacingMetaMissions() { diff --git a/dGame/dComponents/MissionComponent.h b/dGame/dComponents/MissionComponent.h index f31fac8e..8545b171 100644 --- a/dGame/dComponents/MissionComponent.h +++ b/dGame/dComponents/MissionComponent.h @@ -172,9 +172,9 @@ public: void FixRacingMetaMissions(); 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 35fc2532..14093b15 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -17,20 +17,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) { @@ -61,10 +59,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; } @@ -351,10 +348,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 240ddc71..e821406b 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -32,9 +32,9 @@ public: 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 faedc848..3519712a 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 72ff45e8..2a095716 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -211,6 +211,7 @@ public: 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 4ba95f5f..01ef7dfd 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 ac42dca3..115783ac 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -116,7 +116,7 @@ public: 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 7d301476..16722c54 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 67a4a0a5..066451da 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 @@ public: 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 @@ protected: 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 8f8df0ad..fde91d00 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 dc18da49..75cb11cd 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h @@ -29,7 +29,7 @@ public: 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 c9123377..87b6e6e1 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 cf4b2537..e79b8e91 100644 --- a/dGame/dComponents/ScriptComponent.h +++ b/dGame/dComponents/ScriptComponent.h @@ -43,7 +43,7 @@ public: */ 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 c0efa544..dcb87021 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 d928e489..40268922 100644 --- a/dGame/dComponents/SimplePhysicsComponent.h +++ b/dGame/dComponents/SimplePhysicsComponent.h @@ -86,7 +86,7 @@ public: 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 3b27b9f1..b7558d4b 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) {} @@ -955,11 +961,5 @@ namespace GameMessages { LWOOBJID childID{}; }; - - struct IsDead : public GameMsg { - IsDead() : GameMsg(MessageType::Game::IS_DEAD) {} - - bool bDead{}; - }; }; #endif // GAMEMESSAGES_H