Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions dGame/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ Entity::~Entity() {
}

void Entity::Initialize() {
RegisterMsg<GameMessages::RequestServerObjectInfo>(this, &Entity::MsgRequestServerObjectInfo);
RegisterMsg<GameMessages::DropClientLoot>(this, &Entity::MsgDropClientLoot);
RegisterMsg<GameMessages::GetFactionTokenType>(this, &Entity::MsgGetFactionTokenType);
RegisterMsg<GameMessages::PickupItem>(this, &Entity::MsgPickupItem);
RegisterMsg<GameMessages::ChildRemoved>(this, &Entity::MsgChildRemoved);
RegisterMsg(&Entity::MsgRequestServerObjectInfo);
RegisterMsg(&Entity::MsgDropClientLoot);
RegisterMsg(&Entity::MsgGetFactionTokenType);
RegisterMsg(&Entity::MsgPickupItem);
RegisterMsg(&Entity::MsgChildRemoved);
/**
* Setup trigger
*/
Expand Down Expand Up @@ -2251,8 +2251,7 @@ void Entity::RegisterMsg(const MessageType::Game msgId, std::function<bool(GameM
m_MsgHandlers.emplace(msgId, handler);
}

bool Entity::MsgRequestServerObjectInfo(GameMessages::GameMsg& msg) {
auto& requestInfo = static_cast<GameMessages::RequestServerObjectInfo&>(msg);
bool Entity::MsgRequestServerObjectInfo(GameMessages::RequestServerObjectInfo& requestInfo) {
AMFArrayValue response;
response.Insert("visible", true);
response.Insert("objectID", std::to_string(m_ObjectID));
Expand Down Expand Up @@ -2288,9 +2287,7 @@ bool Entity::MsgRequestServerObjectInfo(GameMessages::GameMsg& msg) {
return true;
}

bool Entity::MsgDropClientLoot(GameMessages::GameMsg& msg) {
auto& dropLootMsg = static_cast<GameMessages::DropClientLoot&>(msg);

bool Entity::MsgDropClientLoot(GameMessages::DropClientLoot& dropLootMsg) {
if (dropLootMsg.item != LOT_NULL && dropLootMsg.item != 0) {
Loot::Info info{
.id = dropLootMsg.lootID,
Expand All @@ -2307,13 +2304,11 @@ bool Entity::MsgDropClientLoot(GameMessages::GameMsg& msg) {
return true;
}

bool Entity::MsgGetFlag(GameMessages::GameMsg& msg) {
auto& flagMsg = static_cast<GameMessages::GetFlag&>(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<GameMessages::GetFactionTokenType&>(msg);
bool Entity::MsgGetFactionTokenType(GameMessages::GetFactionTokenType& tokenMsg) {
GameMessages::GetFlag getFlagMsg{};

getFlagMsg.flagID = ePlayerFlag::ASSEMBLY_FACTION;
Expand All @@ -2336,8 +2331,7 @@ bool Entity::MsgGetFactionTokenType(GameMessages::GameMsg& msg) {
return tokenMsg.tokenType != LOT_NULL;
}

bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) {
auto& pickupItemMsg = static_cast<GameMessages::PickupItem&>(msg);
bool Entity::MsgPickupItem(GameMessages::PickupItem& pickupItemMsg) {
if (GetObjectID() == pickupItemMsg.lootOwnerID) {
PickupItem(pickupItemMsg.lootID);
} else {
Expand All @@ -2358,7 +2352,7 @@ bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) {
return true;
}

bool Entity::MsgChildRemoved(GameMessages::GameMsg& msg) {
GetScript()->OnChildRemoved(*this, static_cast<GameMessages::ChildRemoved&>(msg));
bool Entity::MsgChildRemoved(GameMessages::ChildRemoved& msg) {
GetScript()->OnChildRemoved(*this, msg);
return true;
}
39 changes: 25 additions & 14 deletions dGame/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
struct ShootingGalleryFire;
struct ChildLoaded;
struct PlayerResurrectionFinished;
struct RequestServerObjectInfo;
struct DropClientLoot;
struct GetFlag;
struct GetFactionTokenType;
struct PickupItem;
struct ChildRemoved;
};

namespace MessageType {
Expand Down Expand Up @@ -175,12 +181,12 @@

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;
Expand Down Expand Up @@ -343,14 +349,19 @@

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<typename T>
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<typename DerivedGameMsg>
inline void RegisterMsg(bool (Entity::* handler)(DerivedGameMsg&)) {
static_assert(std::is_base_of_v<GameMessages::GameMsg, DerivedMsg>, "DerivedMsg must inherit from GameMsg");

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

use of undeclared identifier 'DerivedMsg'

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

'DerivedMsg': undeclared identifier [D:\a\DarkflameServer\DarkflameServer\build\msvc\dNavigation\dNavigation.vcxproj]

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

'DerivedMsg': identifier not found [D:\a\DarkflameServer\DarkflameServer\build\msvc\dNavigation\dNavigation.vcxproj]

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

'DerivedMsg': undeclared identifier [D:\a\DarkflameServer\DarkflameServer\build\msvc\dGame\dGameBase.vcxproj]

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

'DerivedMsg': identifier not found [D:\a\DarkflameServer\DarkflameServer\build\msvc\dGame\dGameBase.vcxproj]

Check failure on line 357 in dGame/Entity.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

‘DerivedMsg’ was not declared in this scope; did you mean ‘DerivedGameMsg’?
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<DerivedGameMsg&>(msg));
};
DerivedGameMsg msg;
RegisterMsg(msg.msgId, castWrapper);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions dGame/dComponents/ActivityComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "Amf3.h"

ActivityComponent::ActivityComponent(Entity* parent, int32_t componentID) : Component(parent, componentID) {
using namespace GameMessages;
RegisterMsg<GetObjectReportInfo>(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
Expand Down Expand Up @@ -591,9 +590,7 @@ Entity* LobbyPlayer::GetEntity() const {
return Game::entityManager->GetEntity(entityID);
}

bool ActivityComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
auto& reportInfo = static_cast<GameMessages::GetObjectReportInfo&>(msg);

bool ActivityComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
auto& activityInfo = reportInfo.info->PushDebug("Activity");

auto& instances = activityInfo.PushDebug("Instances: " + std::to_string(m_Instances.size()));
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/ActivityComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 3 additions & 7 deletions dGame/dComponents/BaseCombatAIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
#include "Amf3.h"

BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
{
using namespace GameMessages;
RegisterMsg<GetObjectReportInfo>(this, &BaseCombatAIComponent::MsgGetObjectReportInfo);
}
RegisterMsg(&BaseCombatAIComponent::MsgGetObjectReportInfo);
m_Target = LWOOBJID_EMPTY;
m_DirtyStateOrTarget = true;
m_State = AiState::spawn;
Expand Down Expand Up @@ -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<GameMessages::GetObjectReportInfo&>(msg);
auto& cmptType = reportMsg.info->PushDebug("Base Combat AI");
auto& cmptType = reportInfo.info->PushDebug("Base Combat AI");
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
auto& targetInfo = cmptType.PushDebug("Current Target Info");
targetInfo.PushDebug<AMFStringValue>("Current Target ID") = std::to_string(m_Target);
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/BaseCombatAIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/**
Expand Down
10 changes: 3 additions & 7 deletions dGame/dComponents/BouncerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ BouncerComponent::BouncerComponent(Entity* parent, const int32_t componentID) :
LookupPetSwitch();
}

{
using namespace GameMessages;
RegisterMsg<GetObjectReportInfo>(this, &BouncerComponent::MsgGetObjectReportInfo);
}
RegisterMsg(&BouncerComponent::MsgGetObjectReportInfo);
}

BouncerComponent::~BouncerComponent() {
Expand Down Expand Up @@ -113,9 +110,8 @@ void BouncerComponent::LookupPetSwitch() {
}
}

bool BouncerComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
auto& cmptType = reportMsg.info->PushDebug("Bouncer");
bool BouncerComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
auto& cmptType = reportInfo.info->PushDebug("Bouncer");
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
auto& destPos = cmptType.PushDebug("Destination Position");
if (m_Destination != NiPoint3Constant::ZERO) {
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/BouncerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BouncerComponent final : public Component {
*/
void LookupPetSwitch();

bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
bool MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo);

private:
/**
Expand Down
5 changes: 2 additions & 3 deletions dGame/dComponents/CharacterComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GameMessages::GetObjectReportInfo&>(msg);
bool CharacterComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {

auto& cmptType = reportInfo.info->PushDebug("Character");

Expand Down
6 changes: 5 additions & 1 deletion dGame/dComponents/CharacterComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ enum class eGameActivity : uint32_t;

class Item;

namespace GameMessages {
struct GetObjectReportInfo;
}

/**
* The statistics that can be achieved per zone
*/
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions dGame/dComponents/CollectibleComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetObjectReportInfo>(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<GameMessages::GetObjectReportInfo&>(msg);
bool CollectibleComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportMsg) {
auto& cmptType = reportMsg.info->PushDebug("Collectible");
auto collectibleID = static_cast<uint32_t>(m_CollectibleId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);

Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/CollectibleComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
21 changes: 11 additions & 10 deletions dGame/dComponents/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
inline void RegisterMsg(auto* self, const auto handler) {
T msg;
RegisterMsg(msg.msgId, self, handler);
template<typename GameObjClass, typename DerivedMsg>
inline void RegisterMsg(bool (GameObjClass::*handler)(DerivedMsg&)) {
static_assert(std::is_base_of_v<GameMessages::GameMsg, DerivedMsg>, "DerivedMsg must inherit from GameMsg");
static_assert(std::is_base_of_v<Component, GameObjClass>, "GameObjClass must inherit from Component");
const auto handlerBound = std::bind(handler, static_cast<GameObjClass*>(this), std::placeholders::_1);
const auto castWrapper = [handlerBound](GameMessages::GameMsg& msg) {
return handlerBound(static_cast<DerivedMsg&>(msg));
};

DerivedMsg msg;
m_Parent->RegisterMsg(msg.msgId, castWrapper);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions dGame/dComponents/ControllablePhysicsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -359,9 +359,8 @@ void ControllablePhysicsComponent::SetStunImmunity(
);
}

bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
PhysicsComponent::OnGetObjectReportInfo(msg);
auto& reportInfo = static_cast<GameMessages::GetObjectReportInfo&>(msg);
bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
PhysicsComponent::OnGetObjectReportInfo(reportInfo);
auto& info = reportInfo.subCategory->PushDebug("Controllable Info");

auto& vel = info.PushDebug("Velocity");
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/ControllablePhysicsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
19 changes: 11 additions & 8 deletions dGame/dComponents/DestroyableComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Implementation<bool, const Entity*> DestroyableComponent::IsEnemyImplentation;
Implementation<bool, const Entity*> 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;
Expand Down Expand Up @@ -86,8 +85,9 @@ DestroyableComponent::DestroyableComponent(Entity* parent, const int32_t compone

m_DamageCooldownTimer = 0.0f;

RegisterMsg<GetObjectReportInfo>(this, &DestroyableComponent::OnGetObjectReportInfo);
RegisterMsg<GameMessages::SetFaction>(this, &DestroyableComponent::OnSetFaction);
RegisterMsg(&DestroyableComponent::OnGetObjectReportInfo);
RegisterMsg(&DestroyableComponent::OnSetFaction);
RegisterMsg(&DestroyableComponent::OnIsDead);
}

DestroyableComponent::~DestroyableComponent() {
Expand Down Expand Up @@ -1061,8 +1061,7 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source) {
}
}

bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
auto& reportInfo = static_cast<GameMessages::GetObjectReportInfo&>(msg);
bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
auto& destroyableInfo = reportInfo.info->PushDebug("Destroyable");
destroyableInfo.PushDebug<AMFIntValue>("DestructibleComponent DB Table Template ID") = m_ComponentID;

Expand Down Expand Up @@ -1184,10 +1183,14 @@ bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
return true;
}

bool DestroyableComponent::OnSetFaction(GameMessages::GameMsg& msg) {
auto& modifyFaction = static_cast<GameMessages::SetFaction&>(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;
}
Loading
Loading