diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-01-03 13:47:24 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-01-03 13:47:24 +0100 |
commit | c72de2fbbcdf5b416d78b9e455aced43517033a8 (patch) | |
tree | 37f5ae48e795aff0f5a01a772bad2ee3c024dd91 /src | |
parent | 27860c3316b7354c6bf17cac82992085d2905934 (diff) |
Core/Objects: Use span/array instead of vector for raw ObjectGuid manipulations
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.cpp | 12 | ||||
-rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.h | 11 | ||||
-rw-r--r-- | src/server/game/Entities/Pet/Pet.cpp | 12 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 26 | ||||
-rw-r--r-- | src/server/game/Groups/Group.cpp | 13 |
5 files changed, 47 insertions, 27 deletions
diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index 0c59aa0fe52..a68968b7256 100644 --- a/src/server/game/Entities/Object/ObjectGuid.cpp +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -797,17 +797,17 @@ std::size_t ObjectGuid::GetHash() const return hashVal; } -std::vector<uint8> ObjectGuid::GetRawValue() const +std::array<uint8, 16> ObjectGuid::GetRawValue() const { - std::vector<uint8> raw(16); - memcpy(raw.data(), this, sizeof(*this)); + std::array<uint8, 16> raw; + memcpy(raw.data(), _data.data(), BytesSize); return raw; } -void ObjectGuid::SetRawValue(std::vector<uint8> const& guid) +void ObjectGuid::SetRawValue(std::span<uint8 const> rawBytes) { - ASSERT(guid.size() == sizeof(*this)); - memcpy(this, guid.data(), sizeof(*this)); + ASSERT(rawBytes.size() == BytesSize, SZFMTD " == " SZFMTD, rawBytes.size(), BytesSize); + memcpy(_data.data(), rawBytes.data(), BytesSize); } static inline uint32 GetRealmIdForObjectGuid(uint32 realmId) diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h index 6aac313029e..337c2d808bd 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -25,6 +25,7 @@ #include <functional> #include <list> #include <set> +#include <span> #include <stdexcept> #include <string> #include <type_traits> @@ -263,8 +264,6 @@ public: static ObjectGuid CreateLMMLobby(uint32 realmId, uint32 arg2, uint8 arg3, uint8 arg4, uint64 counter); }; -#pragma pack(push, 1) - class TC_GAME_API ObjectGuid { friend class ObjectGuidFactory; @@ -277,13 +276,15 @@ class TC_GAME_API ObjectGuid static ObjectGuid const FromStringFailed; static ObjectGuid const TradeItem; + static constexpr std::size_t BytesSize = 16; + using LowType = uint64; ObjectGuid() = default; uint64 GetRawValue(std::size_t i) const { return _data[i]; } - std::vector<uint8> GetRawValue() const; - void SetRawValue(std::vector<uint8> const& guid); + std::array<uint8, 16> GetRawValue() const; + void SetRawValue(std::span<uint8 const> rawBytes); void SetRawValue(uint64 high, uint64 low) { _data[0] = low; _data[1] = high; } void Clear() { _data = { }; } @@ -387,8 +388,6 @@ class TC_GAME_API ObjectGuid std::array<uint64, 2> _data = { }; }; -#pragma pack(pop) - // Some Shared defines using GuidSet = std::set<ObjectGuid>; using GuidList = std::list<ObjectGuid>; diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index d7c84660747..eefb3349995 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -1189,7 +1189,11 @@ void Pet::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectR uint32 effectIndex = fields[3].GetUInt8(); if (effectIndex < MAX_SPELL_EFFECTS) { - casterGuid.SetRawValue(fields[0].GetBinary()); + std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + casterGuid.SetRawValue(rawGuidBytes); if (casterGuid.IsEmpty()) casterGuid = GetGUID(); @@ -1211,7 +1215,11 @@ void Pet::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectR { Field* fields = auraResult->Fetch(); // NULL guid stored - pet is the caster of the spell - see Pet::_SaveAuras - casterGuid.SetRawValue(fields[0].GetBinary()); + std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + casterGuid.SetRawValue(rawGuidBytes); if (casterGuid.IsEmpty()) casterGuid = GetGUID(); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 4a0d9ec36bb..99197864561 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -18733,8 +18733,17 @@ void Player::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effe uint32 effectIndex = fields[4].GetUInt8(); if (effectIndex < MAX_SPELL_EFFECTS) { - casterGuid.SetRawValue(fields[0].GetBinary()); - itemGuid.SetRawValue(fields[1].GetBinary()); + std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + casterGuid.SetRawValue(rawGuidBytes); + + rawGuidBytes = fields[1].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + itemGuid.SetRawValue(rawGuidBytes); AuraKey key{ casterGuid, itemGuid, fields[2].GetUInt32(), fields[3].GetUInt32() }; AuraLoadEffectInfo& info = effectInfo[key]; info.Amounts[effectIndex] = fields[5].GetInt32(); @@ -18753,8 +18762,17 @@ void Player::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effe do { Field* fields = auraResult->Fetch(); - casterGuid.SetRawValue(fields[0].GetBinary()); - itemGuid.SetRawValue(fields[1].GetBinary()); + std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + casterGuid.SetRawValue(rawGuidBytes); + + rawGuidBytes = fields[1].GetBinaryView(); + if (rawGuidBytes.size() != ObjectGuid::BytesSize) + continue; + + itemGuid.SetRawValue(rawGuidBytes); AuraKey key{ casterGuid, itemGuid, fields[2].GetUInt32(), fields[3].GetUInt32() }; uint32 recalculateMask = fields[4].GetUInt32(); Difficulty difficulty = Difficulty(fields[5].GetUInt8()); diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index e668953bdc5..35dc8e81140 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -185,14 +185,8 @@ bool Group::Create(Player* leader) stmt->setUInt8(index++, uint8(m_lootMethod)); stmt->setUInt64(index++, m_looterGuid.GetCounter()); stmt->setUInt8(index++, uint8(m_lootThreshold)); - stmt->setBinary(index++, m_targetIcons[0].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[1].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[2].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[3].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[4].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[5].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[6].GetRawValue()); - stmt->setBinary(index++, m_targetIcons[7].GetRawValue()); + for (uint8 i = 0; i < TARGET_ICONS_COUNT; ++i) + stmt->setBinary(index++, m_targetIcons[i].GetRawValue()); stmt->setUInt16(index++, m_groupFlags); stmt->setUInt32(index++, uint8(m_dungeonDifficulty)); stmt->setUInt32(index++, uint8(m_raidDifficulty)); @@ -232,7 +226,8 @@ void Group::LoadGroupFromDB(Field* fields) m_lootThreshold = ItemQualities(fields[3].GetUInt8()); for (uint8 i = 0; i < TARGET_ICONS_COUNT; ++i) - m_targetIcons[i].SetRawValue(fields[4 + i].GetBinary()); + if (std::span<uint8 const> rawGuidBytes = fields[4 + i].GetBinaryView(); rawGuidBytes.size() == ObjectGuid::BytesSize) + m_targetIcons[i].SetRawValue(rawGuidBytes); m_groupFlags = GroupFlags(fields[12].GetUInt16()); if (m_groupFlags & GROUP_FLAG_RAID) |