Core/Entities: Fixed m_stringIds[0] invalidation when reloading creature_template with a gm command

This commit is contained in:
Shauren
2024-04-10 20:27:57 +02:00
parent 88bbd27f8d
commit bec5bdb61b
5 changed files with 23 additions and 22 deletions

View File

@@ -304,9 +304,12 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
}
Creature::Creature(bool isWorldObject) : Unit(isWorldObject), MapObject(), m_PlayerDamageReq(0), m_dontClearTapListOnEvade(false), _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(UI64LIT(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_creatureDifficulty(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(UI64LIT(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_creatureDifficulty(nullptr), m_stringIds(), _waypointPathId(0), _currentWaypointNodeInfo(0, 0),
m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(false), _lastDamagedTime(0),
_regenerateHealth(true), _creatureImmunitiesId(0), _gossipMenuId(0), _sparringHealthPct(0)
{
@@ -693,7 +696,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;
}
@@ -1920,7 +1923,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;
@@ -3148,7 +3151,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)
@@ -3156,12 +3159,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;
}
}

View File

@@ -258,8 +258,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 GetNameForLocaleIdx(LocaleConstant locale) const override;
@@ -521,7 +520,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
CreatureTemplate const* m_creatureInfo;
CreatureData const* m_creatureData;
CreatureDifficulty const* m_creatureDifficulty;
std::array<std::string_view, 3> m_stringIds;
std::array<std::string const*, 3> m_stringIds;
Optional<std::string> m_scriptStringId;
Optional<uint32> m_lootId;

View File

@@ -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;
}
}

View File

@@ -381,8 +381,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 m_gameObjectData->DisplayID; }
@@ -484,7 +483,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
GameObjectData const* m_goData;
std::unique_ptr<GameObjectTypeBase> m_goTypeImpl;
GameObjectValue m_goValue; // TODO: replace with m_goTypeImpl
std::array<std::string_view, 3> m_stringIds;
std::array<std::string const*, 3> m_stringIds;
Optional<std::string> m_scriptStringId;
int64 m_packedRotation;

View File

@@ -540,8 +540,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());