diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-04-10 20:27:57 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-10-05 18:05:44 +0200 |
commit | ae6b9bd8e8a55dd38d644cec888363f80f597bba (patch) | |
tree | 57978d3892c01bc50b5b37a1986c82b753b340e5 /src | |
parent | 5655aa4fd840ecaad73872566c5827e3446ed50e (diff) |
Core/Entities: Fixed m_stringIds[0] invalidation when reloading creature_template with a gm command
(cherry picked from commit bec5bdb61b1b78ae7f750019b9a187b489ebb496)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 19 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 5 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 12 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.h | 5 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_npc.cpp | 4 |
5 files changed, 23 insertions, 22 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 79e97628aa9..56cfb3713e8 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -251,9 +251,12 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) } Creature::Creature(bool isWorldObject): Unit(isWorldObject), MapObject(), m_groupLootTimer(0), lootingGroupLowGUID(0), m_PlayerDamageReq(0), m_lootRecipient(), m_lootRecipientGroup(0), _pickpocketLootRestore(0), - m_corpseRemoveTime(0), m_respawnTime(0), m_respawnDelay(300), m_corpseDelay(60), m_ignoreCorpseDecayRatio(false), m_wanderDistance(0.0f), m_boundaryCheckTime(2500), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE), - m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_cannotReachTarget(false), m_cannotReachTimer(0), - m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), _waypointPathId(0), _currentWaypointNodeInfo(0, 0), + m_corpseRemoveTime(0), m_respawnTime(0), m_respawnDelay(300), m_corpseDelay(60), m_ignoreCorpseDecayRatio(false), m_wanderDistance(0.0f), + m_boundaryCheckTime(2500), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE), + m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), + m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_cannotReachTarget(false), m_cannotReachTimer(0), + m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_homePosition(), m_transportHomePosition(), + m_creatureInfo(nullptr), m_creatureData(nullptr), m_stringIds(), _waypointPathId(0), _currentWaypointNodeInfo(0, 0), m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(false), _lastDamagedTime(0), _regenerateHealth(true), _regenerateHealthLock(false), _isMissingCanSwimFlagOutOfCombat(false) { @@ -635,7 +638,7 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/, //We must update last scriptId or it looks like we reloaded a script, breaking some things such as gossip temporarily LastUsedScriptID = GetScriptId(); - m_stringIds[AsUnderlyingType(StringIdType::Template)] = cInfo->StringId; + m_stringIds[AsUnderlyingType(StringIdType::Template)] = &cInfo->StringId; return true; } @@ -1687,7 +1690,7 @@ bool Creature::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, // checked at creature_template loading m_defaultMovementType = MovementGeneratorType(data->movementType); - m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = data->StringId; + m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = &data->StringId; if (addToMap && !GetMap()->AddToMap(this)) return false; @@ -2787,7 +2790,7 @@ void Creature::InheritStringIds(Creature const* parent) bool Creature::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 Creature::SetScriptStringId(std::string id) @@ -2795,12 +2798,12 @@ void Creature::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/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index b2768a45643..1c1504d74e3 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -201,8 +201,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma void InheritStringIds(Creature const* parent); bool HasStringId(std::string_view id) const; void SetScriptStringId(std::string id); - std::array<std::string_view, 3> 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(); } // override WorldObject function for proper name localization std::string const& GetNameForLocaleIdx(LocaleConstant locale_idx) const override; @@ -426,7 +425,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma CreatureTemplate const* m_creatureInfo; // Can differ from sObjectMgr->GetCreatureTemplate(GetEntry()) in difficulty mode > 0 CreatureData const* m_creatureData; - std::array<std::string_view, 3> m_stringIds; + std::array<std::string const*, 3> m_stringIds; Optional<std::string> m_scriptStringId; uint16 m_LootMode; // Bitmask (default: LOOT_MODE_DEFAULT) that determines what loot will be lootable diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 2e2b11b2e62..db28b515d04 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -108,7 +108,7 @@ QuaternionData QuaternionData::fromEulerAnglesZYX(float Z, float Y, float X) } GameObject::GameObject() : WorldObject(false), MapObject(), - m_model(nullptr), m_goValue(), m_AI(nullptr), m_respawnCompatibilityMode(false) + m_model(nullptr), m_goValue(), m_stringIds(), m_AI(nullptr), m_respawnCompatibilityMode(false) { m_objectType |= TYPEMASK_GAMEOBJECT; m_objectTypeId = TYPEID_GAMEOBJECT; @@ -418,7 +418,7 @@ bool GameObject::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* map, u LastUsedScriptID = GetGOInfo()->ScriptId; - m_stringIds[AsUnderlyingType(StringIdType::Template)] = goinfo->StringId; + m_stringIds[AsUnderlyingType(StringIdType::Template)] = &goinfo->StringId; AIM_Initialize(); @@ -1145,7 +1145,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; @@ -2286,7 +2286,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) @@ -2294,12 +2294,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 7c412f01477..a73e6ce8fff 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -277,8 +277,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> void InheritStringIds(GameObject const* parent); bool HasStringId(std::string_view id) const; void SetScriptStringId(std::string id); - std::array<std::string_view, 3> 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 GetUInt32Value(GAMEOBJECT_DISPLAYID); } @@ -345,7 +344,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> GameObjectTemplateAddon const* m_goTemplateAddon; GameObjectData const* m_goData; GameObjectValue m_goValue; - std::array<std::string_view, 3> m_stringIds; + std::array<std::string const*, 3> m_stringIds; Optional<std::string> m_scriptStringId; int64 m_packedRotation; diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index eacccbbdd8d..15150eea1c5 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -507,8 +507,8 @@ public: handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor()); handler->PSendSysMessage(LANG_NPCINFO_POSITION, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ()); handler->PSendSysMessage(LANG_OBJECTINFO_AIINFO, target->GetAIName().c_str(), target->GetScriptName().c_str()); - handler->PSendSysMessage(LANG_OBJECTINFO_STRINGIDS, STRING_VIEW_FMT_ARG(target->GetStringIds()[0]), - STRING_VIEW_FMT_ARG(target->GetStringIds()[1]), STRING_VIEW_FMT_ARG(target->GetStringIds()[2])); + handler->PSendSysMessage(LANG_OBJECTINFO_STRINGIDS, STRING_VIEW_FMT_ARG(target->GetStringId(StringIdType::Template)), + STRING_VIEW_FMT_ARG(target->GetStringId(StringIdType::Spawn)), STRING_VIEW_FMT_ARG(target->GetStringId(StringIdType::Script))); handler->PSendSysMessage(LANG_NPCINFO_REACTSTATE, DescribeReactState(target->GetReactState())); if (CreatureAI const* ai = target->AI()) handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, Trinity::GetTypeName(*ai).c_str()); |