mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Refactor: Amf3 implementation (#998)
* Update AMFDeserializeTests.cpp Redo Amf3 functionality Overhaul the whole thing due to it being outdated and clunky to use Sometimes you want to keep the value Update AMFDeserializeTests.cpp * Fix enum and constructors Correct enum to a class and simplify names. Add a proper default constructor * Update MasterServer.cpp * Fix bugs and add more tests * Refactor: AMF with templates in mind - Remove hard coded bodge - Use templates and generics to allow for much looser typing and strengthened implementation - Move code into header only implementation for portability Refactor: Convert AMF implementation to templates - Rip out previous implementation - Remove all extraneous terminology - Add proper overloads for all types of inserts - Fix up tests and codebase * Fix compiler errors * Check for null first * Add specialization for const char* * Update tests for new template specialization * Switch BitStream to use references * Rename files * Check enum bounds on deserialize I did this on a phone
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include "VehiclePhysicsComponent.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Item.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "eGameActivity.h"
|
||||
|
||||
@@ -734,6 +734,6 @@ void CharacterComponent::RemoveVentureVisionEffect(std::string ventureVisionType
|
||||
void CharacterComponent::UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const {
|
||||
if (!m_Parent) return;
|
||||
AMFArrayValue arrayToSend;
|
||||
arrayToSend.InsertValue(ventureVisionType, showFaction ? static_cast<AMFValue*>(new AMFTrueValue()) : static_cast<AMFValue*>(new AMFFalseValue()));
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", &arrayToSend);
|
||||
arrayToSend.Insert(ventureVisionType, showFaction);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", arrayToSend);
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@
|
||||
#include "Game.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "AMFFormat_BitStream.h"
|
||||
#include "Amf3.h"
|
||||
#include "AmfSerialize.h"
|
||||
#include "GameMessages.h"
|
||||
#include "User.h"
|
||||
#include "CDClientManager.h"
|
||||
@@ -245,16 +245,12 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(difference));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("health");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(difference));
|
||||
args.Insert("type", "health");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
@@ -290,16 +286,12 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(value));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("armor");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(value));
|
||||
args.Insert("type", "armor");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
@@ -334,16 +326,12 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(difference));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("imagination");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(difference));
|
||||
args.Insert("type", "imagination");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@
|
||||
#include "InventoryComponent.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Game.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Mail.h"
|
||||
#include "MissionPrerequisites.h"
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#include "CharacterComponent.h"
|
||||
#include "UserManager.h"
|
||||
#include "dLogger.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "eObjectBits.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
|
||||
@@ -36,12 +36,9 @@ void PropertyEntranceComponent::OnUse(Entity* entity) {
|
||||
|
||||
AMFArrayValue args;
|
||||
|
||||
auto* state = new AMFStringValue();
|
||||
state->SetStringValue("property_menu");
|
||||
args.Insert("state", "property_menu");
|
||||
|
||||
args.InsertValue("state", state);
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||
}
|
||||
|
||||
void PropertyEntranceComponent::OnEnterProperty(Entity* entity, uint32_t index, bool returnToZone, const SystemAddress& sysAddr) {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "eUnequippableActiveType.h"
|
||||
#include "eMovementPlatformState.h"
|
||||
#include "LeaderboardManager.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "Loot.h"
|
||||
#include "eRacingTaskParam.h"
|
||||
#include "eMissionTaskType.h"
|
||||
@@ -87,7 +87,7 @@
|
||||
#include "AMFDeserialize.h"
|
||||
#include "eBlueprintSaveResponseType.h"
|
||||
#include "eAninmationFlags.h"
|
||||
#include "AMFFormat_BitStream.h"
|
||||
#include "AmfSerialize.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "eClientMessageType.h"
|
||||
#include "eGameMessageType.h"
|
||||
@@ -596,14 +596,14 @@ void GameMessages::SendModifyLEGOScore(Entity* entity, const SystemAddress& sysA
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void GameMessages::SendUIMessageServerToSingleClient(Entity* entity, const SystemAddress& sysAddr, const std::string& message, AMFValue* args) {
|
||||
void GameMessages::SendUIMessageServerToSingleClient(Entity* entity, const SystemAddress& sysAddr, const std::string& message, AMFBaseValue& args) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(entity->GetObjectID());
|
||||
bitStream.Write((uint16_t)eGameMessageType::UI_MESSAGE_SERVER_TO_SINGLE_CLIENT);
|
||||
|
||||
bitStream.Write(args);
|
||||
bitStream.Write<AMFBaseValue&>(args);
|
||||
uint32_t strMessageNameLength = message.size();
|
||||
bitStream.Write(strMessageNameLength);
|
||||
|
||||
@@ -614,7 +614,7 @@ void GameMessages::SendUIMessageServerToSingleClient(Entity* entity, const Syste
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void GameMessages::SendUIMessageServerToAllClients(const std::string& message, AMFValue* args) {
|
||||
void GameMessages::SendUIMessageServerToAllClients(const std::string& message, AMFBaseValue& args) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
@@ -622,7 +622,7 @@ void GameMessages::SendUIMessageServerToAllClients(const std::string& message, A
|
||||
bitStream.Write(empty);
|
||||
bitStream.Write((uint16_t)eGameMessageType::UI_MESSAGE_SERVER_TO_ALL_CLIENTS);
|
||||
|
||||
bitStream.Write(args);
|
||||
bitStream.Write<AMFBaseValue&>(args);
|
||||
uint32_t strMessageNameLength = message.size();
|
||||
bitStream.Write(strMessageNameLength);
|
||||
|
||||
@@ -2486,8 +2486,8 @@ void GameMessages::SendUnSmash(Entity* entity, LWOOBJID builderID, float duratio
|
||||
|
||||
void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
AMFDeserialize reader;
|
||||
std::unique_ptr<AMFValue> amfArguments(reader.Read(inStream));
|
||||
if (amfArguments->GetValueType() != AMFValueType::AMFArray) return;
|
||||
std::unique_ptr<AMFBaseValue> amfArguments(reader.Read(inStream));
|
||||
if (amfArguments->GetValueType() != eAmf::Array) return;
|
||||
|
||||
uint32_t commandLength{};
|
||||
inStream->Read(commandLength);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include "eLootSourceType.h"
|
||||
#include "Brick.h"
|
||||
|
||||
class AMFValue;
|
||||
class AMFBaseValue;
|
||||
class Entity;
|
||||
class Item;
|
||||
class NiQuaternion;
|
||||
@@ -88,8 +88,8 @@ namespace GameMessages {
|
||||
void NotifyLevelRewards(LWOOBJID objectID, const SystemAddress& sysAddr, int level, bool sending_rewards);
|
||||
|
||||
void SendModifyLEGOScore(Entity* entity, const SystemAddress& sysAddr, int64_t score, eLootSourceType sourceType);
|
||||
void SendUIMessageServerToSingleClient(Entity* entity, const SystemAddress& sysAddr, const std::string& message, AMFValue* args);
|
||||
void SendUIMessageServerToAllClients(const std::string& message, AMFValue* args);
|
||||
void SendUIMessageServerToSingleClient(Entity* entity, const SystemAddress& sysAddr, const std::string& message, AMFBaseValue& args);
|
||||
void SendUIMessageServerToAllClients(const std::string& message, AMFBaseValue& args);
|
||||
|
||||
void SendPlayEmbeddedEffectOnAllClientsNearObject(Entity* entity, std::u16string effectName, const LWOOBJID& fromObjectID, float radius);
|
||||
void SendPlayFXEffect(Entity* entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary, float priority = 1, float scale = 1, bool serialize = true);
|
||||
|
@@ -12,19 +12,19 @@ Action::Action(AMFArrayValue* arguments) {
|
||||
valueParameterName = "";
|
||||
valueParameterString = "";
|
||||
valueParameterDouble = 0.0;
|
||||
for (auto& typeValueMap : arguments->GetAssociativeMap()) {
|
||||
for (auto& typeValueMap : arguments->GetAssociative()) {
|
||||
if (typeValueMap.first == "Type") {
|
||||
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
|
||||
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
|
||||
if (typeValueMap.second->GetValueType() != eAmf::String) continue;
|
||||
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetValue();
|
||||
} else {
|
||||
valueParameterName = typeValueMap.first;
|
||||
// Message is the only known string parameter
|
||||
if (valueParameterName == "Message") {
|
||||
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
|
||||
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
|
||||
if (typeValueMap.second->GetValueType() != eAmf::String) continue;
|
||||
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetValue();
|
||||
} else {
|
||||
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
|
||||
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
|
||||
if (typeValueMap.second->GetValueType() != eAmf::Double) continue;
|
||||
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
|
||||
ActionContext::ActionContext() {
|
||||
stripId = 0;
|
||||
@@ -17,15 +17,15 @@ ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKe
|
||||
}
|
||||
|
||||
BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
||||
auto* stateIDValue = arguments->FindValue<AMFDoubleValue>(key);
|
||||
auto* stateIDValue = arguments->Get<double>(key);
|
||||
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
|
||||
|
||||
return static_cast<BehaviorState>(stateIDValue->GetDoubleValue());
|
||||
return static_cast<BehaviorState>(stateIDValue->GetValue());
|
||||
}
|
||||
|
||||
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
||||
auto* stripIdValue = arguments->FindValue<AMFDoubleValue>(key);
|
||||
auto* stripIdValue = arguments->Get<double>(key);
|
||||
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
|
||||
|
||||
return static_cast<StripId>(stripIdValue->GetDoubleValue());
|
||||
return static_cast<StripId>(stripIdValue->GetValue());
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBa
|
||||
actionContext = ActionContext(arguments);
|
||||
actionIndex = GetActionIndexFromArgument(arguments);
|
||||
|
||||
auto* actionValue = arguments->FindValue<AMFArrayValue>("action");
|
||||
auto* actionValue = arguments->GetArray("action");
|
||||
if (!actionValue) return;
|
||||
|
||||
action = Action(actionValue);
|
||||
|
@@ -2,10 +2,10 @@
|
||||
|
||||
AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
behaviorIndex = 0;
|
||||
auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex");
|
||||
auto* behaviorIndexValue = arguments->Get<double>("BehaviorIndex");
|
||||
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue());
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
Game::logger->LogDebug("AddMessage", "behaviorId %i index %i", behaviorId, behaviorIndex);
|
||||
}
|
||||
|
@@ -4,17 +4,16 @@
|
||||
|
||||
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
actionContext = ActionContext(arguments);
|
||||
|
||||
position = StripUiPosition(arguments);
|
||||
|
||||
auto* strip = arguments->FindValue<AMFArrayValue>("strip");
|
||||
auto* strip = arguments->GetArray("strip");
|
||||
if (!strip) return;
|
||||
|
||||
auto* actions = strip->FindValue<AMFArrayValue>("actions");
|
||||
auto* actions = strip->GetArray("actions");
|
||||
if (!actions) return;
|
||||
|
||||
for (uint32_t actionNumber = 0; actionNumber < actions->GetDenseValueSize(); actionNumber++) {
|
||||
auto* actionValue = actions->GetValueAt<AMFArrayValue>(actionNumber);
|
||||
for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) {
|
||||
auto* actionValue = actions->GetArray(actionNumber);
|
||||
if (!actionValue) continue;
|
||||
|
||||
actionsToAdd.push_back(Action(actionValue));
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "BehaviorMessageBase.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "BehaviorStates.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
@@ -11,12 +11,12 @@ BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) {
|
||||
|
||||
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) {
|
||||
const auto* key = "BehaviorID";
|
||||
auto* behaviorIDValue = arguments->FindValue<AMFStringValue>(key);
|
||||
auto* behaviorIDValue = arguments->Get<std::string>(key);
|
||||
int32_t behaviorID = -1;
|
||||
|
||||
if (behaviorIDValue) {
|
||||
behaviorID = std::stoul(behaviorIDValue->GetStringValue());
|
||||
} else if (!arguments->FindValue<AMFUndefinedValue>(key)) {
|
||||
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
|
||||
behaviorID = std::stoul(behaviorIDValue->GetValue());
|
||||
} else if (arguments->Get(key)->GetValueType() != eAmf::Undefined) {
|
||||
throw std::invalid_argument("Unable to find behavior ID");
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments)
|
||||
}
|
||||
|
||||
uint32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) {
|
||||
auto* actionIndexAmf = arguments->FindValue<AMFDoubleValue>(keyName);
|
||||
auto* actionIndexAmf = arguments->Get<double>(keyName);
|
||||
if (!actionIndexAmf) {
|
||||
throw std::invalid_argument("Unable to find actionIndex");
|
||||
}
|
||||
|
||||
return static_cast<uint32_t>(actionIndexAmf->GetDoubleValue());
|
||||
return static_cast<uint32_t>(actionIndexAmf->GetValue());
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
#include "Game.h"
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "MoveToInventoryMessage.h"
|
||||
|
||||
MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex");
|
||||
auto* behaviorIndexValue = arguments->Get<double>("BehaviorIndex");
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue());
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
Game::logger->LogDebug("MoveToInventoryMessage", "behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex);
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "RenameMessage.h"
|
||||
|
||||
RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
auto* nameAmf = arguments->FindValue<AMFStringValue>("Name");
|
||||
auto* nameAmf = arguments->Get<std::string>("Name");
|
||||
if (!nameAmf) return;
|
||||
|
||||
name = nameAmf->GetStringValue();
|
||||
name = nameAmf->GetValue();
|
||||
Game::logger->LogDebug("RenameMessage", "behaviorId %i n %s", behaviorId, name.c_str());
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "StripUiPosition.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
|
||||
StripUiPosition::StripUiPosition() {
|
||||
xPosition = 0.0;
|
||||
@@ -10,13 +10,13 @@ StripUiPosition::StripUiPosition() {
|
||||
StripUiPosition::StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName) {
|
||||
xPosition = 0.0;
|
||||
yPosition = 0.0;
|
||||
auto* uiArray = arguments->FindValue<AMFArrayValue>(uiKeyName);
|
||||
auto* uiArray = arguments->GetArray(uiKeyName);
|
||||
if (!uiArray) return;
|
||||
|
||||
auto* xPositionValue = uiArray->FindValue<AMFDoubleValue>("x");
|
||||
auto* yPositionValue = uiArray->FindValue<AMFDoubleValue>("y");
|
||||
auto* xPositionValue = uiArray->Get<double>("x");
|
||||
auto* yPositionValue = uiArray->Get<double>("y");
|
||||
if (!xPositionValue || !yPositionValue) return;
|
||||
|
||||
yPosition = yPositionValue->GetDoubleValue();
|
||||
xPosition = xPositionValue->GetDoubleValue();
|
||||
yPosition = yPositionValue->GetValue();
|
||||
xPosition = xPositionValue->GetValue();
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
actionContext = ActionContext(arguments);
|
||||
|
||||
auto* actionValue = arguments->FindValue<AMFArrayValue>("action");
|
||||
auto* actionValue = arguments->GetArray("action");
|
||||
if (!actionValue) return;
|
||||
|
||||
action = Action(actionValue);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "ControlBehaviors.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "Entity.h"
|
||||
#include "Game.h"
|
||||
#include "GameMessages.h"
|
||||
@@ -43,11 +43,11 @@ void ControlBehaviors::RequestUpdatedID(int32_t behaviorID, ModelComponent* mode
|
||||
// AMFArrayValue args;
|
||||
|
||||
// AMFStringValue* behaviorIDString = new AMFStringValue();
|
||||
// behaviorIDString->SetStringValue(std::to_string(persistentId));
|
||||
// behaviorIDString->SetValue(std::to_string(persistentId));
|
||||
// args.InsertValue("behaviorID", behaviorIDString);
|
||||
|
||||
// AMFStringValue* objectIDAsString = new AMFStringValue();
|
||||
// objectIDAsString->SetStringValue(std::to_string(modelComponent->GetParent()->GetObjectID()));
|
||||
// objectIDAsString->SetValue(std::to_string(modelComponent->GetParent()->GetObjectID()));
|
||||
// args.InsertValue("objectID", objectIDAsString);
|
||||
|
||||
// GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorID", &args);
|
||||
@@ -63,8 +63,6 @@ void ControlBehaviors::SendBehaviorListToClient(Entity* modelEntity, const Syste
|
||||
|
||||
AMFArrayValue behaviorsToSerialize;
|
||||
|
||||
AMFArrayValue* behaviors = new AMFArrayValue(); // Empty for now
|
||||
|
||||
/**
|
||||
* The behaviors AMFArray will have up to 5 elements in the dense portion.
|
||||
* Each element in the dense portion will be made up of another AMFArray
|
||||
@@ -75,20 +73,17 @@ void ControlBehaviors::SendBehaviorListToClient(Entity* modelEntity, const Syste
|
||||
* "name": The name of the behavior formatted as an AMFString
|
||||
*/
|
||||
|
||||
behaviorsToSerialize.InsertValue("behaviors", behaviors);
|
||||
behaviorsToSerialize.Insert("behaviors");
|
||||
behaviorsToSerialize.Insert("objectID", std::to_string(modelComponent->GetParent()->GetObjectID()));
|
||||
|
||||
AMFStringValue* amfStringValueForObjectID = new AMFStringValue();
|
||||
amfStringValueForObjectID->SetStringValue(std::to_string(modelComponent->GetParent()->GetObjectID()));
|
||||
|
||||
behaviorsToSerialize.InsertValue("objectID", amfStringValueForObjectID);
|
||||
GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorList", &behaviorsToSerialize);
|
||||
GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorList", behaviorsToSerialize);
|
||||
}
|
||||
|
||||
void ControlBehaviors::ModelTypeChanged(AMFArrayValue* arguments, ModelComponent* ModelComponent) {
|
||||
auto* modelTypeAmf = arguments->FindValue<AMFDoubleValue>("ModelType");
|
||||
auto* modelTypeAmf = arguments->Get<double>("ModelType");
|
||||
if (!modelTypeAmf) return;
|
||||
|
||||
uint32_t modelType = static_cast<uint32_t>(modelTypeAmf->GetDoubleValue());
|
||||
uint32_t modelType = static_cast<uint32_t>(modelTypeAmf->GetValue());
|
||||
|
||||
//TODO Update the model type here
|
||||
}
|
||||
@@ -179,7 +174,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// AMFArrayValue* state = new AMFArrayValue();
|
||||
|
||||
// AMFDoubleValue* stateAsDouble = new AMFDoubleValue();
|
||||
// stateAsDouble->SetDoubleValue(it->first);
|
||||
// stateAsDouble->SetValue(it->first);
|
||||
// state->InsertValue("id", stateAsDouble);
|
||||
|
||||
// AMFArrayValue* strips = new AMFArrayValue();
|
||||
@@ -189,16 +184,16 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// AMFArrayValue* thisStrip = new AMFArrayValue();
|
||||
|
||||
// AMFDoubleValue* stripID = new AMFDoubleValue();
|
||||
// stripID->SetDoubleValue(strip->first);
|
||||
// stripID->SetValue(strip->first);
|
||||
// thisStrip->InsertValue("id", stripID);
|
||||
|
||||
// AMFArrayValue* uiArray = new AMFArrayValue();
|
||||
// AMFDoubleValue* yPosition = new AMFDoubleValue();
|
||||
// yPosition->SetDoubleValue(strip->second->GetYPosition());
|
||||
// yPosition->SetValue(strip->second->GetYPosition());
|
||||
// uiArray->InsertValue("y", yPosition);
|
||||
|
||||
// AMFDoubleValue* xPosition = new AMFDoubleValue();
|
||||
// xPosition->SetDoubleValue(strip->second->GetXPosition());
|
||||
// xPosition->SetValue(strip->second->GetXPosition());
|
||||
// uiArray->InsertValue("x", xPosition);
|
||||
|
||||
// thisStrip->InsertValue("ui", uiArray);
|
||||
@@ -211,19 +206,19 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// AMFArrayValue* thisAction = new AMFArrayValue();
|
||||
|
||||
// AMFStringValue* actionName = new AMFStringValue();
|
||||
// actionName->SetStringValue(behaviorAction->actionName);
|
||||
// actionName->SetValue(behaviorAction->actionName);
|
||||
// thisAction->InsertValue("Type", actionName);
|
||||
|
||||
// if (behaviorAction->parameterValueString != "")
|
||||
// {
|
||||
// AMFStringValue* valueAsString = new AMFStringValue();
|
||||
// valueAsString->SetStringValue(behaviorAction->parameterValueString);
|
||||
// valueAsString->SetValue(behaviorAction->parameterValueString);
|
||||
// thisAction->InsertValue(behaviorAction->parameterName, valueAsString);
|
||||
// }
|
||||
// else if (behaviorAction->parameterValueDouble != 0.0)
|
||||
// {
|
||||
// AMFDoubleValue* valueAsDouble = new AMFDoubleValue();
|
||||
// valueAsDouble->SetDoubleValue(behaviorAction->parameterValueDouble);
|
||||
// valueAsDouble->SetValue(behaviorAction->parameterValueDouble);
|
||||
// thisAction->InsertValue(behaviorAction->parameterName, valueAsDouble);
|
||||
// }
|
||||
// stripSerialize->PushBackValue(thisAction);
|
||||
@@ -237,11 +232,11 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// behaviorInfo.InsertValue("states", stateSerialize);
|
||||
|
||||
// AMFStringValue* objectidAsString = new AMFStringValue();
|
||||
// objectidAsString->SetStringValue(std::to_string(targetObjectID));
|
||||
// objectidAsString->SetValue(std::to_string(targetObjectID));
|
||||
// behaviorInfo.InsertValue("objectID", objectidAsString);
|
||||
|
||||
// AMFStringValue* behaviorIDAsString = new AMFStringValue();
|
||||
// behaviorIDAsString->SetStringValue(std::to_string(behaviorID));
|
||||
// behaviorIDAsString->SetValue(std::to_string(behaviorID));
|
||||
// behaviorInfo.InsertValue("BehaviorID", behaviorIDAsString);
|
||||
|
||||
// GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorBlocks", &behaviorInfo);
|
||||
@@ -275,10 +270,9 @@ void ControlBehaviors::MoveToInventory(ModelComponent* modelComponent, const Sys
|
||||
// This closes the UI menu should it be open while the player is removing behaviors
|
||||
AMFArrayValue args;
|
||||
|
||||
AMFFalseValue* stateToPop = new AMFFalseValue();
|
||||
args.InsertValue("visible", stateToPop);
|
||||
args.Insert("visible", false);
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(modelOwner, modelOwner->GetParentUser()->GetSystemAddress(), "ToggleBehaviorEditor", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(modelOwner, modelOwner->GetParentUser()->GetSystemAddress(), "ToggleBehaviorEditor", args);
|
||||
|
||||
MoveToInventoryMessage moveToInventoryMessage(arguments);
|
||||
|
||||
|
@@ -69,7 +69,7 @@
|
||||
#include "BinaryPathFinder.h"
|
||||
#include "dConfig.h"
|
||||
#include "eBubbleType.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "MovingPlatformComponent.h"
|
||||
#include "eMissionState.h"
|
||||
#include "TriggerComponent.h"
|
||||
@@ -251,26 +251,20 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
{
|
||||
AMFArrayValue args;
|
||||
|
||||
auto* state = new AMFStringValue();
|
||||
state->SetStringValue("Story");
|
||||
args.Insert("state", "Story");
|
||||
|
||||
args.InsertValue("state", state);
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||
}
|
||||
|
||||
entity->AddCallbackTimer(0.5f, [customText, entity]() {
|
||||
AMFArrayValue args;
|
||||
|
||||
auto* text = new AMFStringValue();
|
||||
text->SetStringValue(customText);
|
||||
|
||||
args.InsertValue("visible", new AMFTrueValue());
|
||||
args.InsertValue("text", text);
|
||||
args.Insert("visible", true);
|
||||
args.Insert("text", customText);
|
||||
|
||||
Game::logger->Log("SlashCommandHandler", "Sending %s", customText.c_str());
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
|
||||
});
|
||||
|
||||
return;
|
||||
@@ -530,12 +524,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
}
|
||||
|
||||
if (chatCommand == "setuistate" && args.size() == 1 && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
|
||||
AMFStringValue* value = new AMFStringValue();
|
||||
value->SetStringValue(args[0]);
|
||||
AMFArrayValue uiState;
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("state", value);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "pushGameState", &args);
|
||||
uiState.Insert("state", args.at(0));
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "pushGameState", uiState);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Switched UI state.");
|
||||
|
||||
@@ -543,11 +536,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
}
|
||||
|
||||
if (chatCommand == "toggle" && args.size() == 1 && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
|
||||
AMFTrueValue* value = new AMFTrueValue();
|
||||
|
||||
AMFArrayValue amfArgs;
|
||||
amfArgs.InsertValue("visible", value);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, args[0], &amfArgs);
|
||||
|
||||
amfArgs.Insert("visible", true);
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, args[0], amfArgs);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Toggled UI state.");
|
||||
|
||||
@@ -1617,7 +1610,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
if ((chatCommand == "debugui") && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Opening UIDebugger...");
|
||||
AMFArrayValue args;
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "ToggleUIDebugger;", nullptr);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "ToggleUIDebugger;", args);
|
||||
}
|
||||
|
||||
if ((chatCommand == "boost") && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
|
||||
@@ -2023,15 +2016,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
|
||||
void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) {
|
||||
AMFArrayValue args;
|
||||
auto* titleValue = new AMFStringValue();
|
||||
titleValue->SetStringValue(title);
|
||||
auto* messageValue = new AMFStringValue();
|
||||
messageValue->SetStringValue(message);
|
||||
|
||||
args.InsertValue("title", titleValue);
|
||||
args.InsertValue("message", messageValue);
|
||||
args.Insert("title", title);
|
||||
args.Insert("message", message);
|
||||
|
||||
GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", &args);
|
||||
GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args);
|
||||
|
||||
//Notify chat about it
|
||||
CBITSTREAM;
|
||||
|
Reference in New Issue
Block a user