From bec5bdb61b1b78ae7f750019b9a187b489ebb496 Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 10 Apr 2024 20:27:57 +0200 Subject: Core/Entities: Fixed m_stringIds[0] invalidation when reloading creature_template with a gm command --- src/server/game/Entities/GameObject/GameObject.cpp | 12 ++++++------ src/server/game/Entities/GameObject/GameObject.h | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/server/game/Entities/GameObject') diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index f40c86eece6..eaa8c05f0dc 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -813,7 +813,7 @@ void SetControlZoneValue::Execute(GameObjectTypeBase& type) const } GameObject::GameObject() : WorldObject(false), MapObject(), - m_model(nullptr), m_goValue(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0) + m_model(nullptr), m_goValue(), m_stringIds(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0) { m_objectType |= TYPEMASK_GAMEOBJECT; m_objectTypeId = TYPEID_GAMEOBJECT; @@ -1160,7 +1160,7 @@ bool GameObject::Create(uint32 entry, Map* map, Position const& pos, QuaternionD LastUsedScriptID = GetGOInfo()->ScriptId; - m_stringIds[AsUnderlyingType(StringIdType::Template)] = goInfo->StringId; + m_stringIds[AsUnderlyingType(StringIdType::Template)] = &goInfo->StringId; AIM_Initialize(); @@ -1980,7 +1980,7 @@ bool GameObject::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap m_goData = data; - m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = data->StringId; + m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = &data->StringId; if (addToMap && !GetMap()->AddToMap(this)) return false; @@ -3508,7 +3508,7 @@ void GameObject::InheritStringIds(GameObject const* parent) bool GameObject::HasStringId(std::string_view id) const { - return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end(); + return std::ranges::any_of(m_stringIds, [id](std::string const* stringId) { return stringId && *stringId == id; }); } void GameObject::SetScriptStringId(std::string id) @@ -3516,12 +3516,12 @@ void GameObject::SetScriptStringId(std::string id) if (!id.empty()) { m_scriptStringId.emplace(std::move(id)); - m_stringIds[AsUnderlyingType(StringIdType::Script)] = *m_scriptStringId; + m_stringIds[AsUnderlyingType(StringIdType::Script)] = &*m_scriptStringId; } else { m_scriptStringId.reset(); - m_stringIds[AsUnderlyingType(StringIdType::Script)] = {}; + m_stringIds[AsUnderlyingType(StringIdType::Script)] = nullptr; } } diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index c194e44fa9d..86ebd9bb14d 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -381,8 +381,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject void InheritStringIds(GameObject const* parent); bool HasStringId(std::string_view id) const; void SetScriptStringId(std::string id); - std::array const& GetStringIds() const { return m_stringIds; } - std::string_view GetStringId(StringIdType type) const { return m_stringIds[size_t(type)]; } + std::string_view GetStringId(StringIdType type) const { return m_stringIds[size_t(type)] ? std::string_view(*m_stringIds[size_t(type)]) : std::string_view(); } void SetDisplayId(uint32 displayid); uint32 GetDisplayId() const { return m_gameObjectData->DisplayID; } @@ -484,7 +483,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject GameObjectData const* m_goData; std::unique_ptr m_goTypeImpl; GameObjectValue m_goValue; // TODO: replace with m_goTypeImpl - std::array m_stringIds; + std::array m_stringIds; Optional m_scriptStringId; int64 m_packedRotation; -- cgit v1.2.3