chore: Change LDFFormat to use BitStream references (#1467)

This commit is contained in:
jadebenn 2024-02-26 08:15:29 -06:00 committed by GitHub
parent c3743877df
commit 94a467b361
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 31 deletions

View File

@ -31,7 +31,7 @@ public:
virtual ~LDFBaseData() {} virtual ~LDFBaseData() {}
virtual void WriteToPacket(RakNet::BitStream* packet) = 0; virtual void WriteToPacket(RakNet::BitStream& packet) = 0;
virtual const std::u16string& GetKey() = 0; virtual const std::u16string& GetKey() = 0;
@ -62,17 +62,17 @@ private:
T value; T value;
//! Writes the key to the packet //! Writes the key to the packet
void WriteKey(RakNet::BitStream* packet) { void WriteKey(RakNet::BitStream& packet) {
packet->Write<uint8_t>(this->key.length() * sizeof(uint16_t)); packet.Write<uint8_t>(this->key.length() * sizeof(uint16_t));
for (uint32_t i = 0; i < this->key.length(); ++i) { for (uint32_t i = 0; i < this->key.length(); ++i) {
packet->Write<uint16_t>(this->key[i]); packet.Write<uint16_t>(this->key[i]);
} }
} }
//! Writes the value to the packet //! Writes the value to the packet
void WriteValue(RakNet::BitStream* packet) { void WriteValue(RakNet::BitStream& packet) {
packet->Write<uint8_t>(this->GetValueType()); packet.Write<uint8_t>(this->GetValueType());
packet->Write(this->value); packet.Write(this->value);
} }
public: public:
@ -108,7 +108,7 @@ public:
/*! /*!
\param packet The packet \param packet The packet
*/ */
void WriteToPacket(RakNet::BitStream* packet) override { void WriteToPacket(RakNet::BitStream& packet) override {
this->WriteKey(packet); this->WriteKey(packet);
this->WriteValue(packet); this->WriteValue(packet);
} }
@ -178,31 +178,31 @@ template<> inline eLDFType LDFData<std::string>::GetValueType(void) { return LDF
// The specialized version for std::u16string (UTF-16) // The specialized version for std::u16string (UTF-16)
template<> template<>
inline void LDFData<std::u16string>::WriteValue(RakNet::BitStream* packet) { inline void LDFData<std::u16string>::WriteValue(RakNet::BitStream& packet) {
packet->Write<uint8_t>(this->GetValueType()); packet.Write<uint8_t>(this->GetValueType());
packet->Write<uint32_t>(this->value.length()); packet.Write<uint32_t>(this->value.length());
for (uint32_t i = 0; i < this->value.length(); ++i) { for (uint32_t i = 0; i < this->value.length(); ++i) {
packet->Write<uint16_t>(this->value[i]); packet.Write<uint16_t>(this->value[i]);
} }
} }
// The specialized version for bool // The specialized version for bool
template<> template<>
inline void LDFData<bool>::WriteValue(RakNet::BitStream* packet) { inline void LDFData<bool>::WriteValue(RakNet::BitStream& packet) {
packet->Write<uint8_t>(this->GetValueType()); packet.Write<uint8_t>(this->GetValueType());
packet->Write<uint8_t>(this->value); packet.Write<uint8_t>(this->value);
} }
// The specialized version for std::string (UTF-8) // The specialized version for std::string (UTF-8)
template<> template<>
inline void LDFData<std::string>::WriteValue(RakNet::BitStream* packet) { inline void LDFData<std::string>::WriteValue(RakNet::BitStream& packet) {
packet->Write<uint8_t>(this->GetValueType()); packet.Write<uint8_t>(this->GetValueType());
packet->Write<uint32_t>(this->value.length()); packet.Write<uint32_t>(this->value.length());
for (uint32_t i = 0; i < this->value.length(); ++i) { for (uint32_t i = 0; i < this->value.length(); ++i) {
packet->Write<uint8_t>(this->value[i]); packet.Write<uint8_t>(this->value[i]);
} }
} }

View File

@ -943,7 +943,7 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke
for (LDFBaseData* data : m_Settings) { for (LDFBaseData* data : m_Settings) {
if (data && data->GetValueType() != eLDFType::LDF_TYPE_UNKNOWN) { if (data && data->GetValueType() != eLDFType::LDF_TYPE_UNKNOWN) {
data->WriteToPacket(&settingStream); data->WriteToPacket(settingStream);
} }
} }
@ -963,7 +963,7 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke
settingStream.Write<uint32_t>(ldfData.size()); settingStream.Write<uint32_t>(ldfData.size());
for (LDFBaseData* data : ldfData) { for (LDFBaseData* data : ldfData) {
if (data) { if (data) {
data->WriteToPacket(&settingStream); data->WriteToPacket(settingStream);
} }
} }

View File

@ -730,10 +730,10 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
std::string newRocketStr = data->GetValueAsString() + ";"; std::string newRocketStr = data->GetValueAsString() + ";";
GeneralUtils::ReplaceInString(newRocketStr, "+", ";"); GeneralUtils::ReplaceInString(newRocketStr, "+", ";");
LDFData<std::u16string>* ldf_data = new LDFData<std::u16string>(u"assemblyPartLOTs", GeneralUtils::ASCIIToUTF16(newRocketStr)); LDFData<std::u16string>* ldf_data = new LDFData<std::u16string>(u"assemblyPartLOTs", GeneralUtils::ASCIIToUTF16(newRocketStr));
ldf_data->WriteToPacket(&ldfStream); ldf_data->WriteToPacket(ldfStream);
delete ldf_data; delete ldf_data;
} else { } else {
data->WriteToPacket(&ldfStream); data->WriteToPacket(ldfStream);
} }
} }
outBitStream->Write(ldfStream.GetNumberOfBytesUsed() + 1); outBitStream->Write(ldfStream.GetNumberOfBytesUsed() + 1);

View File

@ -87,13 +87,13 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t rep
std::unique_ptr<LDFData<int32_t>> chatmode(new LDFData<int32_t>(u"chatmode", static_cast<int32_t>(gm))); std::unique_ptr<LDFData<int32_t>> chatmode(new LDFData<int32_t>(u"chatmode", static_cast<int32_t>(gm)));
std::unique_ptr<LDFData<int64_t>> reputationLdf(new LDFData<int64_t>(u"reputation", reputation)); std::unique_ptr<LDFData<int64_t>> reputationLdf(new LDFData<int64_t>(u"reputation", reputation));
objid->WriteToPacket(&data); objid->WriteToPacket(data);
lot->WriteToPacket(&data); lot->WriteToPacket(data);
name->WriteToPacket(&data); name->WriteToPacket(data);
gmlevel->WriteToPacket(&data); gmlevel->WriteToPacket(data);
chatmode->WriteToPacket(&data); chatmode->WriteToPacket(data);
xmlConfigData->WriteToPacket(&data); xmlConfigData->WriteToPacket(data);
reputationLdf->WriteToPacket(&data); reputationLdf->WriteToPacket(data);
//Compress the data before sending: //Compress the data before sending:
const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed()); const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed());

View File

@ -31,7 +31,7 @@ void ScriptComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitial
ldfData.Write<uint32_t>(networkSettings.size()); ldfData.Write<uint32_t>(networkSettings.size());
for (auto* networkSetting : networkSettings) { for (auto* networkSetting : networkSettings) {
networkSetting->WriteToPacket(&ldfData); networkSetting->WriteToPacket(ldfData);
} }
// Finally write everything to the stream // Finally write everything to the stream