From 73e70badb77fd141fef653711d4b97ef9cbb9b25 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 17 Oct 2023 06:45:46 -0700 Subject: [PATCH] Entity: fix bad ldf key serialization (#1225) --- dGame/Entity.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index b3a0a3cc..80eec04f 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -704,12 +704,12 @@ void Entity::Initialize() { const Path* path = Game::zoneManager->GetZone()->GetPath(pathName); //Check to see if we have an attached path and add the appropiate component to handle it: - if (path){ + if (path) { // if we have a moving platform path, then we need a moving platform component if (path->pathType == PathType::MovingPlatform) { MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat)); - // else if we are a movement path + // else if we are a movement path } /*else if (path->pathType == PathType::Movement) { auto movementAIcomp = GetComponent(); if (movementAIcomp){ @@ -924,10 +924,20 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke outBitStream->Write1(); //ldf data RakNet::BitStream settingStream; - settingStream.Write(m_Settings.size()); + int32_t numberOfValidKeys = m_Settings.size(); + + // Writing keys value pairs the client does not expect to receive or interpret will result in undefined behavior, + // so we need to filter out any keys that are not valid and fix the number of valid keys to be correct. + // TODO should make this more efficient so that we dont waste loops evaluating the same condition twice + for (LDFBaseData* data : m_Settings) { + if (!data || data->GetValueType() == eLDFType::LDF_TYPE_UNKNOWN) { + numberOfValidKeys--; + } + } + settingStream.Write(numberOfValidKeys); for (LDFBaseData* data : m_Settings) { - if (data) { + if (data && data->GetValueType() != eLDFType::LDF_TYPE_UNKNOWN) { data->WriteToPacket(&settingStream); } } @@ -946,7 +956,6 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke RakNet::BitStream settingStream; settingStream.Write(ldfData.size()); - for (LDFBaseData* data : ldfData) { if (data) { data->WriteToPacket(&settingStream);