squash commits (#1479)

This commit is contained in:
jadebenn 2024-02-27 01:29:51 -06:00 committed by GitHub
parent b261e63233
commit 424d54b98c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 132 additions and 130 deletions

View File

@ -128,10 +128,10 @@ AMFBaseValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream& inStream) {
auto arrayValue = new AMFArrayValue(); auto arrayValue = new AMFArrayValue();
// Read size of dense array // Read size of dense array
auto sizeOfDenseArray = (ReadU29(inStream) >> 1); const auto sizeOfDenseArray = (ReadU29(inStream) >> 1);
// Then read associative portion // Then read associative portion
while (true) { while (true) {
auto key = ReadString(inStream); const auto key = ReadString(inStream);
// No more associative values when we encounter an empty string key // No more associative values when we encounter an empty string key
if (key.size() == 0) break; if (key.size() == 0) break;
arrayValue->Insert(key, Read(inStream)); arrayValue->Insert(key, Read(inStream));

View File

@ -23,7 +23,7 @@ private:
* @param inStream bitstream to read data from * @param inStream bitstream to read data from
* @return The number as an unsigned 29 bit integer * @return The number as an unsigned 29 bit integer
*/ */
uint32_t ReadU29(RakNet::BitStream& inStream); static uint32_t ReadU29(RakNet::BitStream& inStream);
/** /**
* @brief Reads a string from a bitstream * @brief Reads a string from a bitstream

View File

@ -42,6 +42,7 @@ class AMFValue : public AMFBaseValue {
public: public:
AMFValue() = default; AMFValue() = default;
AMFValue(const ValueType value) : m_Data{ value } {} AMFValue(const ValueType value) : m_Data{ value } {}
virtual ~AMFValue() override = default; virtual ~AMFValue() override = default;
[[nodiscard]] constexpr eAmf GetValueType() const noexcept override; [[nodiscard]] constexpr eAmf GetValueType() const noexcept override;

View File

@ -61,7 +61,7 @@ public:
* @param args the arguments of the message to be deserialized * @param args the arguments of the message to be deserialized
*/ */
template<typename Msg> template<typename Msg>
void HandleControlBehaviorsMsg(AMFArrayValue* args) { void HandleControlBehaviorsMsg(const AMFArrayValue& args) {
static_assert(std::is_base_of_v<BehaviorMessageBase, Msg>, "Msg must be a BehaviorMessageBase"); static_assert(std::is_base_of_v<BehaviorMessageBase, Msg>, "Msg must be a BehaviorMessageBase");
Msg msg(args); Msg msg(args);
for (auto& behavior : m_Behaviors) { for (auto& behavior : m_Behaviors) {

View File

@ -2489,23 +2489,24 @@ void GameMessages::SendUnSmash(Entity* entity, LWOOBJID builderID, float duratio
void GameMessages::HandleControlBehaviors(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) { void GameMessages::HandleControlBehaviors(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
AMFDeserialize reader; AMFDeserialize reader;
std::unique_ptr<AMFBaseValue> amfArguments(reader.Read(inStream)); std::unique_ptr<AMFArrayValue> amfArguments{ static_cast<AMFArrayValue*>(reader.Read(inStream)) };
if (amfArguments->GetValueType() != eAmf::Array) return; if (amfArguments->GetValueType() != eAmf::Array) return;
uint32_t commandLength{}; uint32_t commandLength{};
inStream.Read(commandLength); inStream.Read(commandLength);
std::string command; std::string command;
for (uint32_t i = 0; i < commandLength; i++) { command.reserve(commandLength);
for (uint32_t i = 0; i < commandLength; ++i) {
unsigned char character; unsigned char character;
inStream.Read(character); inStream.Read(character);
command.push_back(character); command.push_back(character);
} }
auto owner = PropertyManagementComponent::Instance()->GetOwner(); auto* const owner = PropertyManagementComponent::Instance()->GetOwner();
if (!owner) return; if (!owner) return;
ControlBehaviors::Instance().ProcessCommand(entity, static_cast<AMFArrayValue*>(amfArguments.get()), command, owner); ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments, command, owner);
} }
void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) { void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {

View File

@ -1,8 +1,8 @@
#include "Action.h" #include "Action.h"
#include "Amf3.h" #include "Amf3.h"
Action::Action(const AMFArrayValue* arguments) { Action::Action(const AMFArrayValue& arguments) {
for (const auto& [paramName, paramValue] : arguments->GetAssociative()) { for (const auto& [paramName, paramValue] : arguments.GetAssociative()) {
if (paramName == "Type") { if (paramName == "Type") {
if (paramValue->GetValueType() != eAmf::String) continue; if (paramValue->GetValueType() != eAmf::String) continue;
m_Type = static_cast<AMFStringValue*>(paramValue)->GetValue(); m_Type = static_cast<AMFStringValue*>(paramValue)->GetValue();

View File

@ -12,7 +12,7 @@ class AMFArrayValue;
class Action { class Action {
public: public:
Action() = default; Action() = default;
Action(const AMFArrayValue* arguments); Action(const AMFArrayValue& arguments);
[[nodiscard]] const std::string& GetType() const { return m_Type; }; [[nodiscard]] const std::string& GetType() const { return m_Type; };
[[nodiscard]] const std::string& GetValueParameterName() const { return m_ValueParameterName; }; [[nodiscard]] const std::string& GetValueParameterName() const { return m_ValueParameterName; };
[[nodiscard]] const std::string& GetValueParameterString() const { return m_ValueParameterString; }; [[nodiscard]] const std::string& GetValueParameterString() const { return m_ValueParameterString; };

View File

@ -4,20 +4,20 @@
#include "Amf3.h" #include "Amf3.h"
ActionContext::ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey, const std::string& customStripKey) ActionContext::ActionContext(const AMFArrayValue& arguments, const std::string& customStateKey, const std::string& customStripKey)
: m_StripId{ GetStripIdFromArgument(arguments, customStripKey) } : m_StripId{ GetStripIdFromArgument(arguments, customStripKey) }
, m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } { , m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } {
} }
BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const { BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string& key) const {
const auto* const stateIDValue = arguments->Get<double>(key); const auto* const stateIDValue = arguments.Get<double>(key);
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
return static_cast<BehaviorState>(stateIDValue->GetValue()); return static_cast<BehaviorState>(stateIDValue->GetValue());
} }
StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const { StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string& key) const {
const auto* const stripIdValue = arguments->Get<double>(key); const auto* const stripIdValue = arguments.Get<double>(key);
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
return static_cast<StripId>(stripIdValue->GetValue()); return static_cast<StripId>(stripIdValue->GetValue());

View File

@ -13,13 +13,13 @@ class AMFArrayValue;
class ActionContext { class ActionContext {
public: public:
ActionContext() noexcept = default; ActionContext() noexcept = default;
ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey = "stateID", const std::string& customStripKey = "stripID"); ActionContext(const AMFArrayValue& arguments, const std::string& customStateKey = "stateID", const std::string& customStripKey = "stripID");
[[nodiscard]] StripId GetStripId() const noexcept { return m_StripId; }; [[nodiscard]] StripId GetStripId() const noexcept { return m_StripId; };
[[nodiscard]] BehaviorState GetStateId() const noexcept { return m_StateId; }; [[nodiscard]] BehaviorState GetStateId() const noexcept { return m_StateId; };
private: private:
[[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const; [[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string& key) const;
[[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const; [[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string& key) const;
StripId m_StripId{ 0 }; StripId m_StripId{ 0 };
BehaviorState m_StateId{ BehaviorState::HOME_STATE }; BehaviorState m_StateId{ BehaviorState::HOME_STATE };
}; };

View File

@ -1,14 +1,14 @@
#include "AddActionMessage.h" #include "AddActionMessage.h"
AddActionMessage::AddActionMessage(const AMFArrayValue* arguments) AddActionMessage::AddActionMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {
const auto* const actionValue = arguments->GetArray("action"); const auto* const actionValue = arguments.GetArray("action");
if (!actionValue) return; if (!actionValue) return;
m_Action = Action{ actionValue }; m_Action = Action{ *actionValue };
LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %i", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId); LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %i", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId);
} }

View File

@ -13,7 +13,7 @@ class AMFArrayValue;
*/ */
class AddActionMessage : public BehaviorMessageBase { class AddActionMessage : public BehaviorMessageBase {
public: public:
AddActionMessage(const AMFArrayValue* arguments); AddActionMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }; [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; };

View File

@ -1,7 +1,7 @@
#include "AddMessage.h" #include "AddMessage.h"
AddMessage::AddMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { AddMessage::AddMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } {
const auto* const behaviorIndexValue = arguments->Get<double>("BehaviorIndex"); const auto* const behaviorIndexValue = arguments.Get<double>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue()); m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());

View File

@ -9,7 +9,7 @@
*/ */
class AddMessage : public BehaviorMessageBase { class AddMessage : public BehaviorMessageBase {
public: public:
AddMessage(const AMFArrayValue* arguments); AddMessage(const AMFArrayValue& arguments);
[[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; };
private: private:

View File

@ -2,22 +2,22 @@
#include "Action.h" #include "Action.h"
AddStripMessage::AddStripMessage(const AMFArrayValue* arguments) AddStripMessage::AddStripMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_Position{ arguments } , m_Position{ arguments }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {
const auto* const strip = arguments->GetArray("strip"); const auto* const strip = arguments.GetArray("strip");
if (!strip) return; if (!strip) return;
const auto* const actions = strip->GetArray("actions"); const auto* const actions = strip->GetArray("actions");
if (!actions) return; if (!actions) return;
for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) { for (size_t actionNumber = 0; actionNumber < actions->GetDense().size(); ++actionNumber) {
const auto* const actionValue = actions->GetArray(actionNumber); const auto* const actionValue = actions->GetArray(actionNumber);
if (!actionValue) continue; if (!actionValue) continue;
m_ActionsToAdd.emplace_back(actionValue); m_ActionsToAdd.emplace_back(*actionValue);
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().c_str(), m_ActionsToAdd.back().GetValueParameterName().c_str(), m_ActionsToAdd.back().GetValueParameterString().c_str(), m_ActionsToAdd.back().GetValueParameterDouble()); LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().c_str(), m_ActionsToAdd.back().GetValueParameterName().c_str(), m_ActionsToAdd.back().GetValueParameterString().c_str(), m_ActionsToAdd.back().GetValueParameterDouble());
} }

View File

@ -18,7 +18,7 @@ class AMFArrayValue;
*/ */
class AddStripMessage : public BehaviorMessageBase { class AddStripMessage : public BehaviorMessageBase {
public: public:
AddStripMessage(const AMFArrayValue* arguments); AddStripMessage(const AMFArrayValue& arguments);
[[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; } [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }

View File

@ -4,23 +4,23 @@
#include "BehaviorStates.h" #include "BehaviorStates.h"
#include "dCommonVars.h" #include "dCommonVars.h"
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue* arguments) { int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) {
static constexpr const char* key = "BehaviorID"; static constexpr const char* key = "BehaviorID";
const auto* const behaviorIDValue = arguments->Get<std::string>(key); const auto* const behaviorIDValue = arguments.Get<std::string>(key);
int32_t behaviorId = DefaultBehaviorId; int32_t behaviorId = DefaultBehaviorId;
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
behaviorId = behaviorId =
GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(behaviorId); GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(behaviorId);
} else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) { } else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) {
throw std::invalid_argument("Unable to find behavior ID"); throw std::invalid_argument("Unable to find behavior ID");
} }
return behaviorId; return behaviorId;
} }
int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName) const { int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string& keyName) const {
const auto* const actionIndexAmf = arguments->Get<double>(keyName); const auto* const actionIndexAmf = arguments.Get<double>(keyName);
if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex"); if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");
return static_cast<int32_t>(actionIndexAmf->GetValue()); return static_cast<int32_t>(actionIndexAmf->GetValue());

View File

@ -16,13 +16,13 @@ enum class BehaviorState : uint32_t;
class BehaviorMessageBase { class BehaviorMessageBase {
public: public:
static constexpr int32_t DefaultBehaviorId{ -1 }; static constexpr int32_t DefaultBehaviorId{ -1 };
BehaviorMessageBase(const AMFArrayValue* arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {} BehaviorMessageBase(const AMFArrayValue& arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {}
[[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; } [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; }
[[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; } [[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; }
protected: protected:
[[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue* arguments); [[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName = "actionIndex") const; [[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string& keyName = "actionIndex") const;
int32_t m_BehaviorId{ DefaultBehaviorId }; int32_t m_BehaviorId{ DefaultBehaviorId };
}; };

View File

@ -1,6 +1,6 @@
#include "MergeStripsMessage.h" #include "MergeStripsMessage.h"
MergeStripsMessage::MergeStripsMessage(const AMFArrayValue* arguments) MergeStripsMessage::MergeStripsMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }

View File

@ -13,7 +13,7 @@ class AMFArrayValue;
*/ */
class MergeStripsMessage : public BehaviorMessageBase { class MergeStripsMessage : public BehaviorMessageBase {
public: public:
MergeStripsMessage(const AMFArrayValue* arguments); MergeStripsMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; }

View File

@ -1,6 +1,6 @@
#include "MigrateActionsMessage.h" #include "MigrateActionsMessage.h"
MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue* arguments) MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }

View File

@ -13,7 +13,7 @@ class AMFArrayValue;
*/ */
class MigrateActionsMessage : public BehaviorMessageBase { class MigrateActionsMessage : public BehaviorMessageBase {
public: public:
MigrateActionsMessage(const AMFArrayValue* arguments); MigrateActionsMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }

View File

@ -1,7 +1,7 @@
#include "MoveToInventoryMessage.h" #include "MoveToInventoryMessage.h"
MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } {
const auto* const behaviorIndexValue = arguments->Get<double>("BehaviorIndex"); const auto* const behaviorIndexValue = arguments.Get<double>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue()); m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());

View File

@ -11,7 +11,7 @@ class AMFArrayValue;
#pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.") #pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.")
class MoveToInventoryMessage : public BehaviorMessageBase { class MoveToInventoryMessage : public BehaviorMessageBase {
public: public:
MoveToInventoryMessage(const AMFArrayValue* arguments); MoveToInventoryMessage(const AMFArrayValue& arguments);
[[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; };
private: private:

View File

@ -1,6 +1,6 @@
#include "RearrangeStripMessage.h" #include "RearrangeStripMessage.h"
RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue* arguments) RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }

View File

@ -10,7 +10,7 @@
*/ */
class RearrangeStripMessage : public BehaviorMessageBase { class RearrangeStripMessage : public BehaviorMessageBase {
public: public:
RearrangeStripMessage(const AMFArrayValue* arguments); RearrangeStripMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }
[[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; }

View File

@ -1,6 +1,6 @@
#include "RemoveActionsMessage.h" #include "RemoveActionsMessage.h"
RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue* arguments) RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {

View File

@ -12,7 +12,7 @@ class AMFArrayValue;
*/ */
class RemoveActionsMessage : public BehaviorMessageBase { class RemoveActionsMessage : public BehaviorMessageBase {
public: public:
RemoveActionsMessage(const AMFArrayValue* arguments); RemoveActionsMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }

View File

@ -1,6 +1,6 @@
#include "RemoveStripMessage.h" #include "RemoveStripMessage.h"
RemoveStripMessage::RemoveStripMessage(const AMFArrayValue* arguments) RemoveStripMessage::RemoveStripMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {

View File

@ -10,7 +10,7 @@
*/ */
class RemoveStripMessage : public BehaviorMessageBase { class RemoveStripMessage : public BehaviorMessageBase {
public: public:
RemoveStripMessage(const AMFArrayValue* arguments); RemoveStripMessage(const AMFArrayValue& arguments);
const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }

View File

@ -1,7 +1,7 @@
#include "RenameMessage.h" #include "RenameMessage.h"
RenameMessage::RenameMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { RenameMessage::RenameMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } {
const auto* const nameAmf = arguments->Get<std::string>("Name"); const auto* const nameAmf = arguments.Get<std::string>("Name");
if (!nameAmf) return; if (!nameAmf) return;
m_Name = nameAmf->GetValue(); m_Name = nameAmf->GetValue();

View File

@ -10,7 +10,7 @@ class AMFArrayValue;
*/ */
class RenameMessage : public BehaviorMessageBase { class RenameMessage : public BehaviorMessageBase {
public: public:
RenameMessage(const AMFArrayValue* arguments); RenameMessage(const AMFArrayValue& arguments);
[[nodiscard]] const std::string& GetName() const { return m_Name; }; [[nodiscard]] const std::string& GetName() const { return m_Name; };
private: private:

View File

@ -1,6 +1,6 @@
#include "SplitStripMessage.h" #include "SplitStripMessage.h"
SplitStripMessage::SplitStripMessage(const AMFArrayValue* arguments) SplitStripMessage::SplitStripMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }

View File

@ -14,7 +14,7 @@ class AMFArrayValue;
*/ */
class SplitStripMessage : public BehaviorMessageBase { class SplitStripMessage : public BehaviorMessageBase {
public: public:
SplitStripMessage(const AMFArrayValue* arguments); SplitStripMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }

View File

@ -2,8 +2,8 @@
#include "Amf3.h" #include "Amf3.h"
StripUiPosition::StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName) { StripUiPosition::StripUiPosition(const AMFArrayValue& arguments, const std::string& uiKeyName) {
const auto* const uiArray = arguments->GetArray(uiKeyName); const auto* const uiArray = arguments.GetArray(uiKeyName);
if (!uiArray) return; if (!uiArray) return;
const auto* const xPositionValue = uiArray->Get<double>("x"); const auto* const xPositionValue = uiArray->Get<double>("x");

View File

@ -10,7 +10,7 @@ class AMFArrayValue;
class StripUiPosition { class StripUiPosition {
public: public:
StripUiPosition() noexcept = default; StripUiPosition() noexcept = default;
StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName = "ui"); StripUiPosition(const AMFArrayValue& arguments, const std::string& uiKeyName = "ui");
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
[[nodiscard]] double GetX() const noexcept { return m_XPosition; } [[nodiscard]] double GetX() const noexcept { return m_XPosition; }
[[nodiscard]] double GetY() const noexcept { return m_YPosition; } [[nodiscard]] double GetY() const noexcept { return m_YPosition; }

View File

@ -2,15 +2,15 @@
#include "Action.h" #include "Action.h"
UpdateActionMessage::UpdateActionMessage(const AMFArrayValue* arguments) UpdateActionMessage::UpdateActionMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {
const auto* const actionValue = arguments->GetArray("action"); const auto* const actionValue = arguments.GetArray("action");
if (!actionValue) return; if (!actionValue) return;
m_Action = Action{ actionValue }; m_Action = Action{ *actionValue };
LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId()); LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
} }

View File

@ -13,7 +13,7 @@ class AMFArrayValue;
*/ */
class UpdateActionMessage : public BehaviorMessageBase { class UpdateActionMessage : public BehaviorMessageBase {
public: public:
UpdateActionMessage(const AMFArrayValue* arguments); UpdateActionMessage(const AMFArrayValue& arguments);
[[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }

View File

@ -1,6 +1,6 @@
#include "UpdateStripUiMessage.h" #include "UpdateStripUiMessage.h"
UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue* arguments) UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue& arguments)
: BehaviorMessageBase{ arguments } : BehaviorMessageBase{ arguments }
, m_Position{ arguments } , m_Position{ arguments }
, m_ActionContext{ arguments } { , m_ActionContext{ arguments } {

View File

@ -13,7 +13,7 @@ class AMFArrayValue;
*/ */
class UpdateStripUiMessage : public BehaviorMessageBase { class UpdateStripUiMessage : public BehaviorMessageBase {
public: public:
UpdateStripUiMessage(const AMFArrayValue* arguments); UpdateStripUiMessage(const AMFArrayValue& arguments);
[[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }; [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; };

View File

@ -71,7 +71,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& contex
GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior); GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior);
} }
void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) { void ControlBehaviors::UpdateAction(const AMFArrayValue& arguments) {
UpdateActionMessage updateActionMessage{ arguments }; UpdateActionMessage updateActionMessage{ arguments };
auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType()); auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType());
@ -95,8 +95,8 @@ void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) {
} }
} }
void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner) { void ControlBehaviors::ProcessCommand(Entity* const modelEntity, const AMFArrayValue& arguments, const std::string& command, Entity* const modelOwner) {
if (!isInitialized || !modelEntity || !modelOwner || !arguments) return; if (!isInitialized || !modelEntity || !modelOwner) return;
auto* const modelComponent = modelEntity->GetComponent<ModelComponent>(); auto* const modelComponent = modelEntity->GetComponent<ModelComponent>();
if (!modelComponent) return; if (!modelComponent) return;
@ -106,7 +106,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* argume
if (command == "sendBehaviorListToClient") { if (command == "sendBehaviorListToClient") {
SendBehaviorListToClient(context); SendBehaviorListToClient(context);
} else if (command == "modelTypeChanged") { } else if (command == "modelTypeChanged") {
auto* const modelType = arguments->Get<double>("ModelType"); const auto* const modelType = arguments.Get<double>("ModelType");
if (!modelType) return; if (!modelType) return;
modelEntity->SetVar<int>(u"modelType", modelType->GetValue()); modelEntity->SetVar<int>(u"modelType", modelType->GetValue());

View File

@ -19,15 +19,15 @@ class SystemAddress;
typedef std::string BlockName; //! A block name typedef std::string BlockName; //! A block name
struct ControlBehaviorContext { struct ControlBehaviorContext {
ControlBehaviorContext(AMFArrayValue* args, ModelComponent* modelComponent, Entity* modelOwner) noexcept ControlBehaviorContext(const AMFArrayValue& args, ModelComponent* modelComponent, Entity* modelOwner) noexcept
: arguments{ args }, modelComponent{ modelComponent }, modelOwner{ modelOwner } { : arguments{ args }, modelComponent{ modelComponent }, modelOwner{ modelOwner } {
}; };
operator bool() const { operator bool() const {
return arguments != nullptr && modelComponent != nullptr && modelOwner != nullptr; return modelComponent != nullptr && modelOwner != nullptr;
} }
AMFArrayValue* arguments; std::reference_wrapper<const AMFArrayValue> arguments;
ModelComponent* modelComponent; ModelComponent* modelComponent;
Entity* modelOwner; Entity* modelOwner;
}; };
@ -43,7 +43,7 @@ public:
* @param command The command to perform * @param command The command to perform
* @param modelOwner The owner of the model which sent this command * @param modelOwner The owner of the model which sent this command
*/ */
void ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner); void ProcessCommand(Entity* const modelEntity, const AMFArrayValue& arguments, const std::string& command, Entity* const modelOwner);
/** /**
* @brief Gets a blocks parameter values by the name * @brief Gets a blocks parameter values by the name
@ -58,7 +58,7 @@ private:
void RequestUpdatedID(ControlBehaviorContext& context); void RequestUpdatedID(ControlBehaviorContext& context);
void SendBehaviorListToClient(const ControlBehaviorContext& context); void SendBehaviorListToClient(const ControlBehaviorContext& context);
void SendBehaviorBlocksToClient(ControlBehaviorContext& context); void SendBehaviorBlocksToClient(ControlBehaviorContext& context);
void UpdateAction(const AMFArrayValue* arguments); void UpdateAction(const AMFArrayValue& arguments);
std::map<BlockName, BlockDefinition, std::less<>> blockTypes{}; std::map<BlockName, BlockDefinition, std::less<>> blockTypes{};
// If false, property behaviors will not be able to be edited. // If false, property behaviors will not be able to be edited.

View File

@ -11,10 +11,10 @@
/** /**
* Helper method that all tests use to get their respective AMF. * Helper method that all tests use to get their respective AMF.
*/ */
AMFBaseValue* ReadFromBitStream(RakNet::BitStream& bitStream) { std::unique_ptr<AMFBaseValue> ReadFromBitStream(RakNet::BitStream& bitStream) {
AMFDeserialize deserializer; AMFDeserialize deserializer;
AMFBaseValue* returnValue(deserializer.Read(bitStream)); AMFBaseValue* returnValue(deserializer.Read(bitStream));
return returnValue; return std::unique_ptr<AMFBaseValue>{ returnValue };
} }
/** /**
@ -23,7 +23,7 @@ AMFBaseValue* ReadFromBitStream(RakNet::BitStream& bitStream) {
TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) { TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) {
CBITSTREAM; CBITSTREAM;
bitStream.Write<uint8_t>(0x00); bitStream.Write<uint8_t>(0x00);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Undefined); ASSERT_EQ(res->GetValueType(), eAmf::Undefined);
} }
@ -34,7 +34,7 @@ TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) {
TEST(dCommonTests, AMFDeserializeAMFNullTest) { TEST(dCommonTests, AMFDeserializeAMFNullTest) {
CBITSTREAM; CBITSTREAM;
bitStream.Write<uint8_t>(0x01); bitStream.Write<uint8_t>(0x01);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Null); ASSERT_EQ(res->GetValueType(), eAmf::Null);
} }
@ -44,7 +44,7 @@ TEST(dCommonTests, AMFDeserializeAMFNullTest) {
TEST(dCommonTests, AMFDeserializeAMFFalseTest) { TEST(dCommonTests, AMFDeserializeAMFFalseTest) {
CBITSTREAM; CBITSTREAM;
bitStream.Write<uint8_t>(0x02); bitStream.Write<uint8_t>(0x02);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::False); ASSERT_EQ(res->GetValueType(), eAmf::False);
} }
@ -54,7 +54,7 @@ TEST(dCommonTests, AMFDeserializeAMFFalseTest) {
TEST(dCommonTests, AMFDeserializeAMFTrueTest) { TEST(dCommonTests, AMFDeserializeAMFTrueTest) {
CBITSTREAM; CBITSTREAM;
bitStream.Write<uint8_t>(0x03); bitStream.Write<uint8_t>(0x03);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::True); ASSERT_EQ(res->GetValueType(), eAmf::True);
} }
@ -67,7 +67,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) {
bitStream.Write<uint8_t>(0x04); bitStream.Write<uint8_t>(0x04);
// 127 == 01111111 // 127 == 01111111
bitStream.Write<uint8_t>(127); bitStream.Write<uint8_t>(127);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Integer); ASSERT_EQ(res->GetValueType(), eAmf::Integer);
// Check that the max value of a byte can be read correctly // Check that the max value of a byte can be read correctly
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 127); ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 127);
@ -76,7 +76,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) {
{ {
bitStream.Write<uint8_t>(0x04); bitStream.Write<uint8_t>(0x04);
bitStream.Write<uint32_t>(UINT32_MAX); bitStream.Write<uint32_t>(UINT32_MAX);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Integer); ASSERT_EQ(res->GetValueType(), eAmf::Integer);
// Check that we can read the maximum value correctly // Check that we can read the maximum value correctly
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 536870911); ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 536870911);
@ -90,7 +90,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) {
bitStream.Write<uint8_t>(255); bitStream.Write<uint8_t>(255);
// 127 == 01111111 // 127 == 01111111
bitStream.Write<uint8_t>(127); bitStream.Write<uint8_t>(127);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Integer); ASSERT_EQ(res->GetValueType(), eAmf::Integer);
// Check that short max can be read correctly // Check that short max can be read correctly
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), UINT16_MAX); ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), UINT16_MAX);
@ -102,7 +102,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) {
bitStream.Write<uint8_t>(255); bitStream.Write<uint8_t>(255);
// 127 == 01111111 // 127 == 01111111
bitStream.Write<uint8_t>(127); bitStream.Write<uint8_t>(127);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Integer); ASSERT_EQ(res->GetValueType(), eAmf::Integer);
// Check that 2 byte max can be read correctly // Check that 2 byte max can be read correctly
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 16383); ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 16383);
@ -116,7 +116,7 @@ TEST(dCommonTests, AMFDeserializeAMFDoubleTest) {
CBITSTREAM; CBITSTREAM;
bitStream.Write<uint8_t>(0x05); bitStream.Write<uint8_t>(0x05);
bitStream.Write<double>(25346.4f); bitStream.Write<double>(25346.4f);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Double); ASSERT_EQ(res->GetValueType(), eAmf::Double);
ASSERT_EQ(static_cast<AMFDoubleValue*>(res.get())->GetValue(), 25346.4f); ASSERT_EQ(static_cast<AMFDoubleValue*>(res.get())->GetValue(), 25346.4f);
} }
@ -130,7 +130,7 @@ TEST(dCommonTests, AMFDeserializeAMFStringTest) {
bitStream.Write<uint8_t>(0x0F); bitStream.Write<uint8_t>(0x0F);
std::string toWrite = "stateID"; std::string toWrite = "stateID";
for (auto e : toWrite) bitStream.Write<char>(e); for (auto e : toWrite) bitStream.Write<char>(e);
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::String); ASSERT_EQ(res->GetValueType(), eAmf::String);
ASSERT_EQ(static_cast<AMFStringValue*>(res.get())->GetValue(), "stateID"); ASSERT_EQ(static_cast<AMFStringValue*>(res.get())->GetValue(), "stateID");
} }
@ -145,7 +145,7 @@ TEST(dCommonTests, AMFDeserializeAMFArrayTest) {
bitStream.Write<uint8_t>(0x01); bitStream.Write<uint8_t>(0x01);
bitStream.Write<uint8_t>(0x01); bitStream.Write<uint8_t>(0x01);
{ {
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Array); ASSERT_EQ(res->GetValueType(), eAmf::Array);
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 0); ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 0);
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 0); ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 0);
@ -164,7 +164,7 @@ TEST(dCommonTests, AMFDeserializeAMFArrayTest) {
bitStream.Write<uint8_t>(0x0B); bitStream.Write<uint8_t>(0x0B);
for (auto e : "10447") if (e != '\0') bitStream.Write<char>(e); for (auto e : "10447") if (e != '\0') bitStream.Write<char>(e);
{ {
std::unique_ptr<AMFBaseValue> res(ReadFromBitStream(bitStream)); std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
ASSERT_EQ(res->GetValueType(), eAmf::Array); ASSERT_EQ(res->GetValueType(), eAmf::Array);
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 1); ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 1);
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 1); ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 1);
@ -238,107 +238,107 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) {
testFileStream.close(); testFileStream.close();
std::unique_ptr<AMFBaseValue> resultFromFn(ReadFromBitStream(testBitStream)); std::unique_ptr<AMFBaseValue> resultFromFn{ ReadFromBitStream(testBitStream) };
auto result = static_cast<AMFArrayValue*>(resultFromFn.get()); auto* result = static_cast<AMFArrayValue*>(resultFromFn.get());
// Test the outermost array // Test the outermost array
ASSERT_EQ(result->Get<std::string>("BehaviorID")->GetValue(), "10447"); ASSERT_EQ(result->Get<std::string>("BehaviorID")->GetValue(), "10447");
ASSERT_EQ(result->Get<std::string>("objectID")->GetValue(), "288300744895913279"); ASSERT_EQ(result->Get<std::string>("objectID")->GetValue(), "288300744895913279");
// Test the execution state array // Test the execution state array
auto executionState = result->GetArray("executionState"); auto* executionState = result->GetArray("executionState");
ASSERT_NE(executionState, nullptr); ASSERT_NE(executionState, nullptr);
auto strips = executionState->GetArray("strips")->GetDense(); auto& strips = executionState->GetArray("strips")->GetDense();
ASSERT_EQ(strips.size(), 1); ASSERT_EQ(strips.size(), 1);
auto stripsPosition0 = dynamic_cast<AMFArrayValue*>(strips[0]); auto* stripsPosition0 = dynamic_cast<AMFArrayValue*>(strips[0]);
auto actionIndex = stripsPosition0->Get<double>("actionIndex"); auto* actionIndex = stripsPosition0->Get<double>("actionIndex");
ASSERT_EQ(actionIndex->GetValue(), 0.0f); ASSERT_EQ(actionIndex->GetValue(), 0.0f);
auto stripIdExecution = stripsPosition0->Get<double>("id"); auto* stripIdExecution = stripsPosition0->Get<double>("id");
ASSERT_EQ(stripIdExecution->GetValue(), 0.0f); ASSERT_EQ(stripIdExecution->GetValue(), 0.0f);
auto stateIdExecution = executionState->Get<double>("stateID"); auto* stateIdExecution = executionState->Get<double>("stateID");
ASSERT_EQ(stateIdExecution->GetValue(), 0.0f); ASSERT_EQ(stateIdExecution->GetValue(), 0.0f);
auto states = result->GetArray("states")->GetDense(); auto& states = result->GetArray("states")->GetDense();
ASSERT_EQ(states.size(), 1); ASSERT_EQ(states.size(), 1);
auto firstState = dynamic_cast<AMFArrayValue*>(states[0]); auto* firstState = dynamic_cast<AMFArrayValue*>(states[0]);
auto stateID = firstState->Get<double>("id"); auto* stateID = firstState->Get<double>("id");
ASSERT_EQ(stateID->GetValue(), 0.0f); ASSERT_EQ(stateID->GetValue(), 0.0f);
auto stripsInState = firstState->GetArray("strips")->GetDense(); auto& stripsInState = firstState->GetArray("strips")->GetDense();
ASSERT_EQ(stripsInState.size(), 1); ASSERT_EQ(stripsInState.size(), 1);
auto firstStrip = dynamic_cast<AMFArrayValue*>(stripsInState[0]); auto* firstStrip = dynamic_cast<AMFArrayValue*>(stripsInState[0]);
auto actionsInFirstStrip = firstStrip->GetArray("actions")->GetDense(); auto& actionsInFirstStrip = firstStrip->GetArray("actions")->GetDense();
ASSERT_EQ(actionsInFirstStrip.size(), 3); ASSERT_EQ(actionsInFirstStrip.size(), 3);
auto actionID = firstStrip->Get<double>("id"); auto* actionID = firstStrip->Get<double>("id");
ASSERT_EQ(actionID->GetValue(), 0.0f); ASSERT_EQ(actionID->GetValue(), 0.0f);
auto uiArray = firstStrip->GetArray("ui"); auto* uiArray = firstStrip->GetArray("ui");
auto xPos = uiArray->Get<double>("x"); auto* xPos = uiArray->Get<double>("x");
auto yPos = uiArray->Get<double>("y"); auto* yPos = uiArray->Get<double>("y");
ASSERT_EQ(xPos->GetValue(), 103.0f); ASSERT_EQ(xPos->GetValue(), 103.0f);
ASSERT_EQ(yPos->GetValue(), 82.0f); ASSERT_EQ(yPos->GetValue(), 82.0f);
auto stripId = firstStrip->Get<double>("id"); auto* stripId = firstStrip->Get<double>("id");
ASSERT_EQ(stripId->GetValue(), 0.0f); ASSERT_EQ(stripId->GetValue(), 0.0f);
auto firstAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[0]); auto* firstAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[0]);
auto firstType = firstAction->Get<std::string>("Type"); auto* firstType = firstAction->Get<std::string>("Type");
ASSERT_EQ(firstType->GetValue(), "OnInteract"); ASSERT_EQ(firstType->GetValue(), "OnInteract");
auto firstCallback = firstAction->Get<std::string>("__callbackID__"); auto* firstCallback = firstAction->Get<std::string>("__callbackID__");
ASSERT_EQ(firstCallback->GetValue(), ""); ASSERT_EQ(firstCallback->GetValue(), "");
auto secondAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[1]); auto* secondAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[1]);
auto secondType = secondAction->Get<std::string>("Type"); auto* secondType = secondAction->Get<std::string>("Type");
ASSERT_EQ(secondType->GetValue(), "FlyUp"); ASSERT_EQ(secondType->GetValue(), "FlyUp");
auto secondCallback = secondAction->Get<std::string>("__callbackID__"); auto* secondCallback = secondAction->Get<std::string>("__callbackID__");
ASSERT_EQ(secondCallback->GetValue(), ""); ASSERT_EQ(secondCallback->GetValue(), "");
auto secondDistance = secondAction->Get<double>("Distance"); auto* secondDistance = secondAction->Get<double>("Distance");
ASSERT_EQ(secondDistance->GetValue(), 25.0f); ASSERT_EQ(secondDistance->GetValue(), 25.0f);
auto thirdAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[2]); auto* thirdAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[2]);
auto thirdType = thirdAction->Get<std::string>("Type"); auto* thirdType = thirdAction->Get<std::string>("Type");
ASSERT_EQ(thirdType->GetValue(), "FlyDown"); ASSERT_EQ(thirdType->GetValue(), "FlyDown");
auto thirdCallback = thirdAction->Get<std::string>("__callbackID__"); auto* thirdCallback = thirdAction->Get<std::string>("__callbackID__");
ASSERT_EQ(thirdCallback->GetValue(), ""); ASSERT_EQ(thirdCallback->GetValue(), "");
auto thirdDistance = thirdAction->Get<double>("Distance"); auto* thirdDistance = thirdAction->Get<double>("Distance");
ASSERT_EQ(thirdDistance->GetValue(), 25.0f); ASSERT_EQ(thirdDistance->GetValue(), 25.0f);
} }

View File

@ -38,11 +38,11 @@ protected:
} }
return readFile; return readFile;
} }
AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream& inStream) { const AMFArrayValue& ReadArrayFromBitStream(RakNet::BitStream& inStream) {
AMFDeserialize des; AMFDeserialize des;
AMFBaseValue* readArray = des.Read(inStream); AMFBaseValue* readArray = des.Read(inStream);
EXPECT_EQ(readArray->GetValueType(), eAmf::Array); EXPECT_EQ(readArray->GetValueType(), eAmf::Array);
return static_cast<AMFArrayValue*>(readArray); return static_cast<AMFArrayValue&>(*readArray);
} }
}; };
@ -93,7 +93,7 @@ TEST_F(GameMessageTests, ControlBehaviorAddStrip) {
ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05);
ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0); ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(addStrip.GetActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(addStrip.GetActionContext().GetStateId()), 0);
ASSERT_EQ(addStrip.GetBehaviorId(), -1); ASSERT_EQ(addStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
ASSERT_EQ(addStrip.GetActionsToAdd().front().GetType(), "DropImagination"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetType(), "DropImagination");
ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterName(), "Amount"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterName(), "Amount");
ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterString(), ""); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterString(), "");
@ -106,7 +106,7 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) {
RemoveStripMessage removeStrip(ReadArrayFromBitStream(inStream)); RemoveStripMessage removeStrip(ReadArrayFromBitStream(inStream));
ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStripId()), 1); ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStripId()), 1);
ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStateId()), 0);
ASSERT_EQ(removeStrip.GetBehaviorId(), -1); ASSERT_EQ(removeStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { TEST_F(GameMessageTests, ControlBehaviorMergeStrips) {
@ -118,7 +118,7 @@ TEST_F(GameMessageTests, ControlBehaviorMergeStrips) {
ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetSourceActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetSourceActionContext().GetStateId()), 0);
ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetDestinationActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetDestinationActionContext().GetStateId()), 0);
ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0); ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0);
ASSERT_EQ(mergeStrips.GetBehaviorId(), -1); ASSERT_EQ(mergeStrips.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { TEST_F(GameMessageTests, ControlBehaviorSplitStrip) {
@ -144,7 +144,7 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) {
ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35);
ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0); ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(updateStripUi.GetActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(updateStripUi.GetActionContext().GetStateId()), 0);
ASSERT_EQ(updateStripUi.GetBehaviorId(), -1); ASSERT_EQ(updateStripUi.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorAddAction) { TEST_F(GameMessageTests, ControlBehaviorAddAction) {
@ -158,7 +158,7 @@ TEST_F(GameMessageTests, ControlBehaviorAddAction) {
ASSERT_EQ(addAction.GetAction().GetValueParameterName(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterName(), "");
ASSERT_EQ(addAction.GetAction().GetValueParameterString(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterString(), "");
ASSERT_EQ(addAction.GetAction().GetValueParameterDouble(), 0.0); ASSERT_EQ(addAction.GetAction().GetValueParameterDouble(), 0.0);
ASSERT_EQ(addAction.GetBehaviorId(), -1); ASSERT_EQ(addAction.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { TEST_F(GameMessageTests, ControlBehaviorMigrateActions) {
@ -171,7 +171,7 @@ TEST_F(GameMessageTests, ControlBehaviorMigrateActions) {
ASSERT_EQ(migrateActions.GetDestinationActionContext().GetStripId(), 0); ASSERT_EQ(migrateActions.GetDestinationActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetSourceActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetSourceActionContext().GetStateId()), 0);
ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetDestinationActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetDestinationActionContext().GetStateId()), 0);
ASSERT_EQ(migrateActions.GetBehaviorId(), -1); ASSERT_EQ(migrateActions.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) {
@ -181,7 +181,7 @@ TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) {
ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2); ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2);
ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1); ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1);
ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0); ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0);
ASSERT_EQ(rearrangeStrip.GetBehaviorId(), -1); ASSERT_EQ(rearrangeStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
ASSERT_EQ(static_cast<uint32_t>(rearrangeStrip.GetActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(rearrangeStrip.GetActionContext().GetStateId()), 0);
} }
@ -208,7 +208,7 @@ TEST_F(GameMessageTests, ControlBehaviorRename) {
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
RenameMessage rename(ReadArrayFromBitStream(inStream)); RenameMessage rename(ReadArrayFromBitStream(inStream));
ASSERT_EQ(rename.GetName(), "test"); ASSERT_EQ(rename.GetName(), "test");
ASSERT_EQ(rename.GetBehaviorId(), -1); ASSERT_EQ(rename.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
} }
TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { TEST_F(GameMessageTests, ControlBehaviorUpdateAction) {
@ -219,7 +219,7 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateAction) {
ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance"); ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance");
ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), ""); ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), "");
ASSERT_EQ(updateAction.GetAction().GetValueParameterDouble(), 50.0); ASSERT_EQ(updateAction.GetAction().GetValueParameterDouble(), 50.0);
ASSERT_EQ(updateAction.GetBehaviorId(), -1); ASSERT_EQ(updateAction.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId);
ASSERT_EQ(updateAction.GetActionIndex(), 1); ASSERT_EQ(updateAction.GetActionIndex(), 1);
ASSERT_EQ(updateAction.GetActionContext().GetStripId(), 0); ASSERT_EQ(updateAction.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(updateAction.GetActionContext().GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(updateAction.GetActionContext().GetStateId()), 0);