mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-01-10 23:07:07 +00:00
memcpy and template deduction guide
This commit is contained in:
parent
3a0e37ee8a
commit
5aa8b1395b
@ -1,5 +1,5 @@
|
|||||||
#ifndef __AMF3__H__
|
#ifndef AMF3_H
|
||||||
#define __AMF3__H__
|
#define AMF3_H
|
||||||
|
|
||||||
#include "dCommonVars.h"
|
#include "dCommonVars.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
@ -64,10 +64,6 @@ template class AMFValue<uint32_t>;
|
|||||||
template class AMFValue<std::string>;
|
template class AMFValue<std::string>;
|
||||||
template class AMFValue<double>;
|
template class AMFValue<double>;
|
||||||
|
|
||||||
// Blank specialization to make sure AMFValue<const char*> fails
|
|
||||||
template <>
|
|
||||||
class AMFValue<const char*> {};
|
|
||||||
|
|
||||||
// AMFValue template class member function instantiations
|
// AMFValue template class member function instantiations
|
||||||
template <> [[nodiscard]] constexpr eAmf AMFValue<std::nullptr_t>::GetValueType() const noexcept { return eAmf::Null; }
|
template <> [[nodiscard]] constexpr eAmf AMFValue<std::nullptr_t>::GetValueType() const noexcept { return eAmf::Null; }
|
||||||
template <> [[nodiscard]] constexpr eAmf AMFValue<bool>::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }
|
template <> [[nodiscard]] constexpr eAmf AMFValue<bool>::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }
|
||||||
@ -85,6 +81,10 @@ using AMFIntValue = AMFValue<int32_t>;
|
|||||||
using AMFStringValue = AMFValue<std::string>;
|
using AMFStringValue = AMFValue<std::string>;
|
||||||
using AMFDoubleValue = AMFValue<double>;
|
using AMFDoubleValue = AMFValue<double>;
|
||||||
|
|
||||||
|
// Template deduction guide to ensure string literals deduce
|
||||||
|
template <size_t N>
|
||||||
|
AMFValue(const char (&)[N]) -> AMFStringValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AMFArrayValue object holds 2 types of lists:
|
* The AMFArrayValue object holds 2 types of lists:
|
||||||
* An associative list where a key maps to a value
|
* An associative list where a key maps to a value
|
||||||
@ -345,4 +345,4 @@ private:
|
|||||||
AMFDense m_Dense;
|
AMFDense m_Dense;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__AMF3__H__
|
#endif //!AMF3_H
|
||||||
|
@ -258,8 +258,8 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
|
|||||||
if (!characterComponent) return;
|
if (!characterComponent) return;
|
||||||
|
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
args.Insert<std::string>("amount", std::to_string(difference));
|
args.Insert("amount", std::to_string(difference));
|
||||||
args.Insert<std::string>("type", "health");
|
args.Insert("type", "health");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||||
}
|
}
|
||||||
@ -300,8 +300,8 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
|||||||
if (!characterComponent) return;
|
if (!characterComponent) return;
|
||||||
|
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
args.Insert<std::string>("amount", std::to_string(value));
|
args.Insert("amount", std::to_string(value));
|
||||||
args.Insert<std::string>("type", "armor");
|
args.Insert("type", "armor");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||||
}
|
}
|
||||||
@ -341,8 +341,8 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
|||||||
if (!characterComponent) return;
|
if (!characterComponent) return;
|
||||||
|
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
args.Insert<std::string>("amount", std::to_string(difference));
|
args.Insert("amount", std::to_string(difference));
|
||||||
args.Insert<std::string>("type", "imagination");
|
args.Insert("type", "imagination");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ void PropertyEntranceComponent::OnUse(Entity* entity) {
|
|||||||
|
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "property_menu");
|
args.Insert("state", "property_menu");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ namespace GMZeroCommands {
|
|||||||
{
|
{
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "Story");
|
args.Insert("state", "Story");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ namespace GMZeroCommands {
|
|||||||
{
|
{
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "Story");
|
args.Insert("state", "Story");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
void BankInteractServer::OnUse(Entity* self, Entity* user) {
|
void BankInteractServer::OnUse(Entity* self, Entity* user) {
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "bank");
|
args.Insert("state", "bank");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
void MailBoxServer::OnUse(Entity* self, Entity* user) {
|
void MailBoxServer::OnUse(Entity* self, Entity* user) {
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "Mail");
|
args.Insert("state", "Mail");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ void StoryBoxInteractServer::OnUse(Entity* self, Entity* user) {
|
|||||||
{
|
{
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "Story");
|
args.Insert("state", "Story");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
||||||
}
|
}
|
||||||
|
@ -13,27 +13,27 @@ void NsLegoClubDoor::OnStartup(Entity* self) {
|
|||||||
args = {};
|
args = {};
|
||||||
|
|
||||||
args.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
args.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
||||||
args.Insert<std::string>("strIdentifier", "choiceDoor");
|
args.Insert("strIdentifier", "choiceDoor");
|
||||||
args.Insert<std::string>("title", "%[UI_CHOICE_DESTINATION]");
|
args.Insert("title", "%[UI_CHOICE_DESTINATION]");
|
||||||
|
|
||||||
AMFArrayValue* choiceOptions = args.InsertArray("options");
|
AMFArrayValue* choiceOptions = args.InsertArray("options");
|
||||||
|
|
||||||
{
|
{
|
||||||
AMFArrayValue* nsArgs = choiceOptions->PushArray();
|
AMFArrayValue* nsArgs = choiceOptions->PushArray();
|
||||||
|
|
||||||
nsArgs->Insert<std::string>("image", "textures/ui/zone_thumnails/Nimbus_Station.dds");
|
nsArgs->Insert("image", "textures/ui/zone_thumnails/Nimbus_Station.dds");
|
||||||
nsArgs->Insert<std::string>("caption", "%[UI_CHOICE_NS]");
|
nsArgs->Insert("caption", "%[UI_CHOICE_NS]");
|
||||||
nsArgs->Insert<std::string>("identifier", "zoneID_1200");
|
nsArgs->Insert("identifier", "zoneID_1200");
|
||||||
nsArgs->Insert<std::string>("tooltipText", "%[UI_CHOICE_NS_HOVER]");
|
nsArgs->Insert("tooltipText", "%[UI_CHOICE_NS_HOVER]");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
AMFArrayValue* ntArgs = choiceOptions->PushArray();
|
AMFArrayValue* ntArgs = choiceOptions->PushArray();
|
||||||
|
|
||||||
ntArgs->Insert<std::string>("image", "textures/ui/zone_thumnails/Nexus_Tower.dds");
|
ntArgs->Insert("image", "textures/ui/zone_thumnails/Nexus_Tower.dds");
|
||||||
ntArgs->Insert<std::string>("caption", "%[UI_CHOICE_NT]");
|
ntArgs->Insert("caption", "%[UI_CHOICE_NT]");
|
||||||
ntArgs->Insert<std::string>("identifier", "zoneID_1900");
|
ntArgs->Insert("identifier", "zoneID_1900");
|
||||||
ntArgs->Insert<std::string>("tooltipText", "%[UI_CHOICE_NT_HOVER]");
|
ntArgs->Insert("tooltipText", "%[UI_CHOICE_NT_HOVER]");
|
||||||
}
|
}
|
||||||
|
|
||||||
options = choiceOptions;
|
options = choiceOptions;
|
||||||
@ -46,8 +46,8 @@ void NsLegoClubDoor::OnUse(Entity* self, Entity* user) {
|
|||||||
AMFArrayValue multiArgs;
|
AMFArrayValue multiArgs;
|
||||||
|
|
||||||
multiArgs.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
multiArgs.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
||||||
multiArgs.Insert<std::string>("strIdentifier", "choiceDoor");
|
multiArgs.Insert("strIdentifier", "choiceDoor");
|
||||||
multiArgs.Insert<std::string>("title", "%[UI_CHOICE_DESTINATION]");
|
multiArgs.Insert("title", "%[UI_CHOICE_DESTINATION]");
|
||||||
multiArgs.Insert("options", static_cast<AMFBaseValue*>(options));
|
multiArgs.Insert("options", static_cast<AMFBaseValue*>(options));
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "QueueChoiceBox", multiArgs);
|
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "QueueChoiceBox", multiArgs);
|
||||||
@ -55,13 +55,13 @@ void NsLegoClubDoor::OnUse(Entity* self, Entity* user) {
|
|||||||
multiArgs.Remove("options", false); // We do not want the local amf to delete the options!
|
multiArgs.Remove("options", false); // We do not want the local amf to delete the options!
|
||||||
} else if (self->GetVar<int32_t>(u"currentZone") != m_ChoiceZoneID) {
|
} else if (self->GetVar<int32_t>(u"currentZone") != m_ChoiceZoneID) {
|
||||||
AMFArrayValue multiArgs;
|
AMFArrayValue multiArgs;
|
||||||
multiArgs.Insert<std::string>("state", "Lobby");
|
multiArgs.Insert("state", "Lobby");
|
||||||
|
|
||||||
AMFArrayValue* context = multiArgs.InsertArray("context");
|
AMFArrayValue* context = multiArgs.InsertArray("context");
|
||||||
context->Insert("user", std::to_string(player->GetObjectID()));
|
context->Insert("user", std::to_string(player->GetObjectID()));
|
||||||
context->Insert("callbackObj", std::to_string(self->GetObjectID()));
|
context->Insert("callbackObj", std::to_string(self->GetObjectID()));
|
||||||
context->Insert<std::string>("HelpVisible", "show");
|
context->Insert("HelpVisible", "show");
|
||||||
context->Insert<std::string>("type", "Lego_Club_Valid");
|
context->Insert("type", "Lego_Club_Valid");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "pushGameState", multiArgs);
|
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "pushGameState", multiArgs);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,27 +13,27 @@ void NsLupTeleport::OnStartup(Entity* self) {
|
|||||||
args = {};
|
args = {};
|
||||||
|
|
||||||
args.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
args.Insert("callbackClient", std::to_string(self->GetObjectID()));
|
||||||
args.Insert<std::string>("strIdentifier", "choiceDoor");
|
args.Insert("strIdentifier", "choiceDoor");
|
||||||
args.Insert<std::string>("title", "%[UI_CHOICE_DESTINATION]");
|
args.Insert("title", "%[UI_CHOICE_DESTINATION]");
|
||||||
|
|
||||||
AMFArrayValue* choiceOptions = args.InsertArray("options");
|
AMFArrayValue* choiceOptions = args.InsertArray("options");
|
||||||
|
|
||||||
{
|
{
|
||||||
AMFArrayValue* nsArgs = choiceOptions->PushArray();
|
AMFArrayValue* nsArgs = choiceOptions->PushArray();
|
||||||
|
|
||||||
nsArgs->Insert<std::string>("image", "textures/ui/zone_thumnails/Nimbus_Station.dds");
|
nsArgs->Insert("image", "textures/ui/zone_thumnails/Nimbus_Station.dds");
|
||||||
nsArgs->Insert<std::string>("caption", "%[UI_CHOICE_NS]");
|
nsArgs->Insert("caption", "%[UI_CHOICE_NS]");
|
||||||
nsArgs->Insert<std::string>("identifier", "zoneID_1200");
|
nsArgs->Insert("identifier", "zoneID_1200");
|
||||||
nsArgs->Insert<std::string>("tooltipText", "%[UI_CHOICE_NS_HOVER]");
|
nsArgs->Insert("tooltipText", "%[UI_CHOICE_NS_HOVER]");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
AMFArrayValue* ntArgs = choiceOptions->PushArray();
|
AMFArrayValue* ntArgs = choiceOptions->PushArray();
|
||||||
|
|
||||||
ntArgs->Insert<std::string>("image", "textures/ui/zone_thumnails/Nexus_Tower.dds");
|
ntArgs->Insert("image", "textures/ui/zone_thumnails/Nexus_Tower.dds");
|
||||||
ntArgs->Insert<std::string>("caption", "%[UI_CHOICE_NT]");
|
ntArgs->Insert("caption", "%[UI_CHOICE_NT]");
|
||||||
ntArgs->Insert<std::string>("identifier", "zoneID_1900");
|
ntArgs->Insert("identifier", "zoneID_1900");
|
||||||
ntArgs->Insert<std::string>("tooltipText", "%[UI_CHOICE_NT_HOVER]");
|
ntArgs->Insert("tooltipText", "%[UI_CHOICE_NT_HOVER]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ void PropertyBankInteract::OnUse(Entity* self, Entity* user) {
|
|||||||
|
|
||||||
AMFArrayValue args;
|
AMFArrayValue args;
|
||||||
|
|
||||||
args.Insert<std::string>("state", "bank");
|
args.Insert("state", "bank");
|
||||||
|
|
||||||
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", args);
|
||||||
|
|
||||||
|
@ -1396,7 +1396,10 @@ void HandlePacket(Packet* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
const auto messageId = static_cast<MessageType::World>(packet->data[3]);
|
// Need to use memcpy instead of reinterpret_cast to avoid UB
|
||||||
|
MessageType::World messageId;
|
||||||
|
std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World));
|
||||||
|
|
||||||
const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
|
const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
|
||||||
LOG("Unknown world packet received: %4i, %s", messageId, messageIdString.data());
|
LOG("Unknown world packet received: %4i, %s", messageId, messageIdString.data());
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ TEST(dCommonTests, AMF3AssociativeArrayTest) {
|
|||||||
|
|
||||||
TEST(dCommonTests, AMF3InsertionAssociativeTest) {
|
TEST(dCommonTests, AMF3InsertionAssociativeTest) {
|
||||||
AMFArrayValue array;
|
AMFArrayValue array;
|
||||||
array.Insert<std::string>("CString", "string");
|
array.Insert("CString", "string");
|
||||||
array.Insert<std::string>("String", std::string("string"));
|
array.Insert("String", std::string("string"));
|
||||||
array.Insert("False", false);
|
array.Insert("False", false);
|
||||||
array.Insert("True", true);
|
array.Insert("True", true);
|
||||||
array.Insert<int32_t>("Integer", 42U);
|
array.Insert<int32_t>("Integer", 42U);
|
||||||
@ -71,6 +71,7 @@ TEST(dCommonTests, AMF3InsertionAssociativeTest) {
|
|||||||
array.Insert<std::vector<uint32_t>>("Undefined", {});
|
array.Insert<std::vector<uint32_t>>("Undefined", {});
|
||||||
array.Insert("Null", nullptr);
|
array.Insert("Null", nullptr);
|
||||||
|
|
||||||
|
ASSERT_EQ(array.Get<const char*>("CString")->GetValueType(), eAmf::String);
|
||||||
ASSERT_EQ(array.Get<std::string>("String")->GetValueType(), eAmf::String);
|
ASSERT_EQ(array.Get<std::string>("String")->GetValueType(), eAmf::String);
|
||||||
ASSERT_EQ(array.Get<bool>("False")->GetValueType(), eAmf::False);
|
ASSERT_EQ(array.Get<bool>("False")->GetValueType(), eAmf::False);
|
||||||
ASSERT_EQ(array.Get<bool>("True")->GetValueType(), eAmf::True);
|
ASSERT_EQ(array.Get<bool>("True")->GetValueType(), eAmf::True);
|
||||||
@ -84,7 +85,7 @@ TEST(dCommonTests, AMF3InsertionAssociativeTest) {
|
|||||||
TEST(dCommonTests, AMF3InsertionDenseTest) {
|
TEST(dCommonTests, AMF3InsertionDenseTest) {
|
||||||
AMFArrayValue array;
|
AMFArrayValue array;
|
||||||
array.Push<std::string>("string");
|
array.Push<std::string>("string");
|
||||||
array.Push<std::string>("CString");
|
array.Push("CString");
|
||||||
array.Push(false);
|
array.Push(false);
|
||||||
array.Push(true);
|
array.Push(true);
|
||||||
array.Push<int32_t>(42U);
|
array.Push<int32_t>(42U);
|
||||||
@ -94,6 +95,7 @@ TEST(dCommonTests, AMF3InsertionDenseTest) {
|
|||||||
array.Push<std::vector<uint32_t>>({});
|
array.Push<std::vector<uint32_t>>({});
|
||||||
|
|
||||||
ASSERT_EQ(array.Get<std::string>(0)->GetValueType(), eAmf::String);
|
ASSERT_EQ(array.Get<std::string>(0)->GetValueType(), eAmf::String);
|
||||||
|
ASSERT_EQ(array.Get<const char*>(1)->GetValueType(), eAmf::String);
|
||||||
ASSERT_EQ(array.Get<bool>(2)->GetValueType(), eAmf::False);
|
ASSERT_EQ(array.Get<bool>(2)->GetValueType(), eAmf::False);
|
||||||
ASSERT_EQ(array.Get<bool>(3)->GetValueType(), eAmf::True);
|
ASSERT_EQ(array.Get<bool>(3)->GetValueType(), eAmf::True);
|
||||||
ASSERT_EQ(array.Get<int32_t>(4)->GetValueType(), eAmf::Integer);
|
ASSERT_EQ(array.Get<int32_t>(4)->GetValueType(), eAmf::Integer);
|
||||||
|
Loading…
Reference in New Issue
Block a user