diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index 0c59aa0fe5261..a68968b72565b 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 ObjectGuid::GetRawValue() const +std::array ObjectGuid::GetRawValue() const { - std::vector raw(16); - memcpy(raw.data(), this, sizeof(*this)); + std::array raw; + memcpy(raw.data(), _data.data(), BytesSize); return raw; } -void ObjectGuid::SetRawValue(std::vector const& guid) +void ObjectGuid::SetRawValue(std::span 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 6aac313029e86..337c2d808bdf2 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -263,8 +264,6 @@ class TC_GAME_API ObjectGuidFactory 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 GetRawValue() const; - void SetRawValue(std::vector const& guid); + std::array GetRawValue() const; + void SetRawValue(std::span 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 _data = { }; }; -#pragma pack(pop) - // Some Shared defines using GuidSet = std::set; using GuidList = std::list; diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index d7c846607474e..eefb334999543 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 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 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 4a0d9ec36bb6a..9919786456129 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 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 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 e668953bdc557..35dc8e811409b 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 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)