From 27999d818ce8b308e30a24526b7705335d5b3dbc Mon Sep 17 00:00:00 2001 From: killerwife Date: Sat, 13 Jan 2024 15:35:17 +0100 Subject: [PATCH] Chat: Fix linking of dynguid objects --- sql/base/mangos.sql | 2 +- src/game/Chat/Chat.cpp | 20 ++++++++++++++++ src/game/Chat/Chat.h | 1 + src/game/Chat/Level2.cpp | 50 ++++++++++++++-------------------------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/sql/base/mangos.sql b/sql/base/mangos.sql index d6e78498452..254c0369a61 100644 --- a/sql/base/mangos.sql +++ b/sql/base/mangos.sql @@ -4774,7 +4774,7 @@ INSERT INTO `mangos_string` VALUES (514,'%d - |cffffffff|Hcreature_entry:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (515,'%d%s - |cffffffff|Hcreature:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (516,'%d - |cffffffff|Hgameobject_entry:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), -(517,'%d%s, Entry %d - |cffffffff|Hgameobject:%d|h[%s X:%f Y:%f Z:%f MapId:%d]SpawnGroup:%u|h|r',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(517,'%d%s, Entry %d - |cffffffff|Hgameobject:%d:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r SpawnGroup:%u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (518,'%d - |cffffffff|Hitemset:%d|h[%s %s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (519,'|cffffffff|Htele:%s|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (520,'%d - |cffffffff|Hspell:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index 80299d1f0ab..01801773bf4 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -3006,6 +3006,26 @@ bool ChatHandler::ExtractUint32KeyFromLink(char** text, char const* linkType, ui return ExtractUInt32(&arg, value); } +bool ChatHandler::ExtractUint32KeysFromLink(char** text, char const* linkType1, char const* linkType2, uint32& value1, uint32& value2) +{ + char const* linkTypes[2]; + linkTypes[0] = linkType1; + linkTypes[1] = linkType2; + + int foundIdx; + char something1[100]; + char* something1Pointer = &something1[0]; + + char* arg = ExtractKeyFromLink(text, linkTypes, &foundIdx, &something1Pointer); + if (!arg) + return false; + + if (foundIdx == -1) + return ExtractUInt32(&arg, value1) && ExtractUInt32(text, value2); + + return ExtractUInt32(&arg, value1) && ExtractUInt32(&something1Pointer, value2); +} + GameObject* ChatHandler::GetGameObjectWithGuid(uint32 lowguid, uint32 entry) const { if (!m_session) diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h index 7b6db1911cf..b58e75ec425 100644 --- a/src/game/Chat/Chat.h +++ b/src/game/Chat/Chat.h @@ -153,6 +153,7 @@ class ChatHandler char* ExtractKeyFromLink(char** text, char const* linkType, char** something1 = nullptr); static char* ExtractKeyFromLink(char** text, char const* const* linkTypes, int* found_idx = nullptr, char** something1 = nullptr); bool ExtractUint32KeyFromLink(char** text, char const* linkType, uint32& value); + bool ExtractUint32KeysFromLink(char** text, char const* linkType1, char const* linkType2, uint32& value1, uint32& value2); uint32 ExtractAccountId(char** args, std::string* accountName = nullptr, Player** targetIfNullArg = nullptr); uint32 ExtractSpellIdFromLink(char** text); diff --git a/src/game/Chat/Level2.cpp b/src/game/Chat/Level2.cpp index cf5bf0dd6b5..3a3c55e89a2 100644 --- a/src/game/Chat/Level2.cpp +++ b/src/game/Chat/Level2.cpp @@ -1025,18 +1025,14 @@ bool ChatHandler::HandleGameObjectDeleteCommand(char* args) bool ChatHandler::HandleGameObjectTurnCommand(char* args) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r - uint32 lowguid; - if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid)) + uint32 lowguid, entry; + if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry)) return false; - if (!lowguid) + if (!lowguid || !entry) return false; - GameObject* obj = nullptr; - - // by DB guid - if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid)) - obj = GetGameObjectWithGuid(lowguid, go_data->id); + GameObject* obj = GetGameObjectWithGuid(lowguid, entry); if (!obj) { @@ -1059,18 +1055,14 @@ bool ChatHandler::HandleGameObjectTurnCommand(char* args) bool ChatHandler::HandleGameObjectMoveCommand(char* args) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r - uint32 lowguid; - if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid)) + uint32 lowguid, entry; + if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry)) return false; - if (!lowguid) + if (!lowguid || !entry) return false; - GameObject* obj = nullptr; - - // by DB guid - if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid)) - obj = GetGameObjectWithGuid(lowguid, go_data->id); + GameObject* obj = GetGameObjectWithGuid(lowguid, entry); if (!obj) { @@ -1208,18 +1200,14 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args) bool ChatHandler::HandleGameObjectPhaseCommand(char* args) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r - uint32 lowguid; - if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid)) + uint32 lowguid, entry; + if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry)) return false; - if (!lowguid) + if (!lowguid || !entry) return false; - GameObject* obj = nullptr; - - // by DB guid - if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid)) - obj = GetGameObjectWithGuid(lowguid, go_data->id); + GameObject* obj = GetGameObjectWithGuid(lowguid, entry); if (!obj) { @@ -1320,18 +1308,14 @@ bool ChatHandler::HandleGameObjectRespawnCommand(char* args) bool ChatHandler::HandleGameObjectActivateCommand(char* args) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r - uint32 lowguid; - if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid)) + uint32 lowguid, entry; + if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry)) return false; - if (!lowguid) + if (!lowguid || !entry) return false; - GameObject* obj = nullptr; - - // by DB guid - if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid)) - obj = GetGameObjectWithGuid(lowguid, go_data->id); + GameObject* obj = GetGameObjectWithGuid(lowguid, entry); if (!obj) { @@ -1405,7 +1389,7 @@ bool ChatHandler::HandleGameObjectNearSpawnedCommand(char* args) uint32 spawnGroupId = 0; if (SpawnGroupEntry* groupEntry = player->GetMap()->GetMapDataContainer().GetSpawnGroupByGuid(guid, TYPEID_GAMEOBJECT)) spawnGroupId = groupEntry->Id; - PSendSysMessage(LANG_GO_MIXED_LIST_CHAT, guid.GetCounter(), PrepareStringNpcOrGoSpawnInformation(guid).c_str(), entry, guid, goInfo->name, x, y, z, go->GetMapId(), spawnGroupId); + PSendSysMessage(LANG_GO_MIXED_LIST_CHAT, guid.GetCounter(), PrepareStringNpcOrGoSpawnInformation(guid).c_str(), entry, guid.GetCounter(), entry, goInfo->name, x, y, z, go->GetMapId(), spawnGroupId); } PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, gameobjects.size());