From 6baa1634affe3974fe33d2f2f7f47e25cc0251f7 Mon Sep 17 00:00:00 2001 From: Jhobean Date: Wed, 9 Oct 2024 22:31:57 -0400 Subject: [PATCH 1/5] Add @DisplayName to be able control the name other player see. --- src/game/CObjBase.h | 1 + src/game/chars/CChar.cpp | 1 + src/network/send.cpp | 50 ++++++++++++++++++++++++++++++++++++---- src/network/send.h | 2 +- src/tables/triggers.tbl | 1 + 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/game/CObjBase.h b/src/game/CObjBase.h index 7a94ef5e1..efaf2930d 100644 --- a/src/game/CObjBase.h +++ b/src/game/CObjBase.h @@ -1072,6 +1072,7 @@ enum CTRIG_TYPE : short CTRIG_DelMulti, // Delete the given multi to the CMultiStorage of this char (player). CTRIG_Destroy, // I am nearly destroyed. CTRIG_Dismount, // I'm dismounting. + CTRIG_DisplayName, // Paperdoll and status is sent and I can change the display name CTRIG_Drink, // I'm drinking something. CTRIG_DYE, CTRIG_Eat, // I'm eating something. diff --git a/src/game/chars/CChar.cpp b/src/game/chars/CChar.cpp index cf14716cc..f8ec388d6 100644 --- a/src/game/chars/CChar.cpp +++ b/src/game/chars/CChar.cpp @@ -71,6 +71,7 @@ lpctstr const CChar::sm_szTrigName[CTRIG_QTY+1] = // static "@DelMulti", // Removing a multi to the MultiStorage, "@Destroy", //+I am nearly destroyed "@Dismount", // I am trying to get rid of my ride right now + "@DisplayName", // Name Show on the paperdoll and status bar "@Drink", // I am drinking something. "@Dye", // My color has been changed "@Eat", diff --git a/src/network/send.cpp b/src/network/send.cpp index b70bc8527..8d88bc10d 100644 --- a/src/network/send.cpp +++ b/src/network/send.cpp @@ -18,6 +18,7 @@ #include "../game/uo_files/uofiles_enums_creid.h" #include "../game/CServer.h" #include "../game/CWorldGameTime.h" +#include "../game/triggers.h" #include "CNetworkManager.h" #include "send.h" @@ -25,6 +26,8 @@ namespace zlib { #include } #include +#include "../game/components/CCChampion.h" +#include "../common/resource/sections/CRegionResourceDef.h" /*************************************************************************** @@ -142,7 +145,26 @@ PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) initLength(); writeInt32(object->GetUID()); - writeStringFixedASCII(object->GetName(), 30); + + bool bCustomName=0; + lpctstr ShowName; + if (objectChar != nullptr && + objectChar->IsClientType() && + IsTrigUsed(TRIGGER_DISPLAYNAME) && + (objectChar != character)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = object->GetName(); + + CChar* pCharBase = const_cast(character); // Remove the const to be able to use on OnTrigger + if (objectChar->OnTrigger(CTRIG_DisplayName, pCharBase, &args) == TRIGRET_RET_TRUE) + { + bCustomName = 1; + ShowName = args.m_s1; + } + } + + writeStringFixedASCII(bCustomName ? ShowName : object->GetName(), 30); if (state->isClientVersionNumber(MINCLIVER_STATUS_V6)) version = 6; @@ -2604,7 +2626,7 @@ PacketCharacterListUpdate::PacketCharacterListUpdate(CClient* target, const CCha * * ***************************************************************************/ -PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) : PacketSend(XCMD_PaperDoll, 66, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) +PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : PacketSend(XCMD_PaperDoll, 66, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) { ADDTOCALLSTACK("PacketPaperdoll::PacketPaperdoll"); @@ -2619,15 +2641,34 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) writeInt32(character->GetUID()); + bool bCustomName = 0; + CSString ShowName; + + + if (IsTrigUsed(TRIGGER_DISPLAYNAME) && (target->GetChar() != character)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = character->GetName(); + if (character->OnTrigger(CTRIG_DisplayName, target->GetChar(), &args) == TRIGRET_RET_TRUE) + { + bCustomName = 1; + ShowName = args.m_s1; + } + } + if (character->IsStatFlag(STATF_INCOGNITO)) { writeStringFixedASCII(character->GetName(), 60); - } + } + else if (bCustomName) + { + writeStringFixedASCII(ShowName, 60); + } else { tchar* text = Str_GetTemp(); - int len = 0; + int len = 0; const CStoneMember* guildMember = character->Guild_FindMember(MEMORY_GUILD); if (guildMember != nullptr && guildMember->IsAbbrevOn() && guildMember->GetParentStone()->GetAbbrev()[0]) { @@ -2651,6 +2692,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) } writeByte((byte)mode); + push(target); } diff --git a/src/network/send.h b/src/network/send.h index 52f5d41a2..7b9d59617 100644 --- a/src/network/send.h +++ b/src/network/send.h @@ -948,7 +948,7 @@ class PacketCharacterListUpdate : public PacketSend class PacketPaperdoll : public PacketSend { public: - PacketPaperdoll(const CClient* target, const CChar* character); + PacketPaperdoll(const CClient* target, CChar* character); }; /*************************************************************************** diff --git a/src/tables/triggers.tbl b/src/tables/triggers.tbl index b81dc78ff..274eb1d4f 100644 --- a/src/tables/triggers.tbl +++ b/src/tables/triggers.tbl @@ -49,6 +49,7 @@ ADD(DELREDCANDLE) ADD(DELWHITECANDLE) ADD(DESTROY) ADD(DISMOUNT) +ADD(DISPLAYNAME) ADD(DRINK) ADD(DROPON_CHAR) ADD(DROPON_GROUND) From 4183b8459d244ff5682d66ca5fc7a8bf291cb789 Mon Sep 17 00:00:00 2001 From: Jhobean <51728381+Jhobean@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:19:58 -0400 Subject: [PATCH 2/5] Add changelog and fix string bug --- Changelog.txt | 7 +++++++ src/network/send.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 210e47371..f7b671a30 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3902,3 +3902,10 @@ Added: 'H' shortcut for variables to get the value as hexadecimal. - Changed: added desired FollowerSlots as a second argument to CURFOLLOWER.ADD. Default value: its FollowerSlots. - Changed: @FollowerUpdate ARGN1 and ARGN2 are now read-only. Having them RW and actually get them working would have meant many other changes, breaking script compatibility. - Fixed: CURFOLLOWER.DEL/DELETE/CLEAR not working properly. + +11-10-2024, Jhobean +- Added: @DisplayName give possibility to change the name other player see on the paperdoll and on status bar. Could be use on RP server where unknow person don't know your name before presentation. + src.: The player requesting to view the name on the paperdoll or status + i: The player stalked by the src. + ARGS (R/W): The name to display + RETURN 1 : Change the name to the new value of ARGS diff --git a/src/network/send.cpp b/src/network/send.cpp index 8d88bc10d..3d7b3080b 100644 --- a/src/network/send.cpp +++ b/src/network/send.cpp @@ -26,8 +26,6 @@ namespace zlib { #include } #include -#include "../game/components/CCChampion.h" -#include "../common/resource/sections/CRegionResourceDef.h" /*************************************************************************** @@ -147,7 +145,7 @@ PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) writeInt32(object->GetUID()); bool bCustomName=0; - lpctstr ShowName; + CSString sShowName; if (objectChar != nullptr && objectChar->IsClientType() && IsTrigUsed(TRIGGER_DISPLAYNAME) && @@ -160,11 +158,13 @@ PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) if (objectChar->OnTrigger(CTRIG_DisplayName, pCharBase, &args) == TRIGRET_RET_TRUE) { bCustomName = 1; - ShowName = args.m_s1; + sShowName = args.m_s1; } } - - writeStringFixedASCII(bCustomName ? ShowName : object->GetName(), 30); + if (bCustomName) + writeStringFixedASCII(sShowName, 30); + else + writeStringFixedASCII(object->GetName(), 30); if (state->isClientVersionNumber(MINCLIVER_STATUS_V6)) version = 6; @@ -2642,7 +2642,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : Pack writeInt32(character->GetUID()); bool bCustomName = 0; - CSString ShowName; + CSString sShowName; if (IsTrigUsed(TRIGGER_DISPLAYNAME) && (target->GetChar() != character)) //Avoid launch trigger if the target is the same character @@ -2652,7 +2652,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : Pack if (character->OnTrigger(CTRIG_DisplayName, target->GetChar(), &args) == TRIGRET_RET_TRUE) { bCustomName = 1; - ShowName = args.m_s1; + sShowName = args.m_s1; } } @@ -2662,7 +2662,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : Pack } else if (bCustomName) { - writeStringFixedASCII(ShowName, 60); + writeStringFixedASCII(sShowName, 60); } else { From 56d5f1fe937520a765cda1647fdabbe1b108d3eb Mon Sep 17 00:00:00 2001 From: Jhobean <51728381+Jhobean@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:28:39 -0400 Subject: [PATCH 3/5] Change the const_cast by removing const --- src/network/send.cpp | 7 +++---- src/network/send.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/network/send.cpp b/src/network/send.cpp index 3d7b3080b..5b8880984 100644 --- a/src/network/send.cpp +++ b/src/network/send.cpp @@ -128,13 +128,13 @@ PacketCombatDamage::PacketCombatDamage(const CClient* target, word damage, CUID * * ***************************************************************************/ -PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) : PacketSend(XCMD_Status, 7, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) +PacketObjectStatus::PacketObjectStatus(CClient* target, CObjBase* object) : PacketSend(XCMD_Status, 7, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) { ADDTOCALLSTACK("PacketObjectStatus::PacketObjectStatus"); ASSERT(object); const CNetState * state = target->GetNetState(); - const CChar *character = target->GetChar(); + CChar *character = target->GetChar(); CChar *objectChar = object->IsChar() ? static_cast(object) : nullptr; bool fCanRename = false; @@ -154,8 +154,7 @@ PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) CScriptTriggerArgs args; args.m_s1 = object->GetName(); - CChar* pCharBase = const_cast(character); // Remove the const to be able to use on OnTrigger - if (objectChar->OnTrigger(CTRIG_DisplayName, pCharBase, &args) == TRIGRET_RET_TRUE) + if (objectChar->OnTrigger(CTRIG_DisplayName, character, &args) == TRIGRET_RET_TRUE) { bCustomName = 1; sShowName = args.m_s1; diff --git a/src/network/send.h b/src/network/send.h index 7b9d59617..b0f732131 100644 --- a/src/network/send.h +++ b/src/network/send.h @@ -111,7 +111,7 @@ class PacketCombatDamage : public PacketSend class PacketObjectStatus : public PacketSend { public: - PacketObjectStatus(const CClient* target, CObjBase* object); + PacketObjectStatus(CClient* target, CObjBase* object); private: void WriteVersionSpecific(const CClient* target, CChar* other, byte version); From 6cabb6a568a4799674b3993dcf5719d9df249e49 Mon Sep 17 00:00:00 2001 From: Jhobean Date: Tue, 15 Oct 2024 20:14:52 -0400 Subject: [PATCH 4/5] Add trigger on tooltip --- Changelog.txt | 5 ++++- src/game/clients/CClientMsg_AOSTooltip.cpp | 18 +++++++++++++++++- src/network/send.cpp | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index d4308c216..45083454d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3913,12 +3913,15 @@ Added: 'H' shortcut for variables to get the value as hexadecimal. - Added: spells with SPELLFLAG_SUMMON now accept LOCAL.FollowerSlotsOverride in the triggers @Success and @SpellSuccess. Default value (do not override): -1. 13-10-2024, Jhobean +- Added: @PetRelease trigger work like @petdesert and return 1 to prevent the pet from being released. - Added: @DisplayName give possibility to change the name other player see on the paperdoll and on status bar. Could be use on RP server where unknow person don't know your name before presentation. + Since the name is use at many place, this trigger happen on 3 differents place in the source. + If you use tooltip, you must set TooltipCache=0 on ini to avoid other player see the tooltip you generate for a particular player. src.: The player requesting to view the name on the paperdoll or status i: The player stalked by the src. ARGS (R/W): The name to display + ARGN (R): Tell if trigger is launch on 1:Paperdoll 2:Status 3: Tooltip RETURN 1 : Change the name to the new value of ARGS -- Added: @PetRelease trigger work like @petdesert and return 1 to prevent the pet from being released. diff --git a/src/game/clients/CClientMsg_AOSTooltip.cpp b/src/game/clients/CClientMsg_AOSTooltip.cpp index 15d3bfc0a..e41a28527 100644 --- a/src/game/clients/CClientMsg_AOSTooltip.cpp +++ b/src/game/clients/CClientMsg_AOSTooltip.cpp @@ -35,7 +35,6 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) if (PacketPropertyList::CanSendTo(GetNetState()) == false) return false; - // Enhanced and KR clients always need the tooltips (but they can't be enabled without FEATURE_AOS_UPDATE_B, since this has to be sent to the client via the packet 0xB9). // Shop items use tooltips whether they're disabled or not, // so we can just send a basic tooltip with the item name @@ -246,6 +245,22 @@ void CClient::AOSTooltip_addName(CObjBase* pObj) } else if (pChar) { + CChar* pClient = static_cast(GetChar()); + if (IsTrigUsed(TRIGGER_DISPLAYNAME) && pChar->IsClientType() && (pChar != pClient)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = pChar->GetName(); + args.m_iN1 = 3;//Trigger use on tooltip + + if (pChar->OnTrigger(CTRIG_DisplayName, pClient, &args) == TRIGRET_RET_TRUE) + { + /*To make it work correctly TooltipCache must be set to 0 on ini or other player will use wrong tooltip*/ + /*Maybe a beter way can be done*/ + PUSH_FRONT_TOOLTIP(pChar, new CClientTooltip(1070722, args.m_s1)); // ~1_NOTHING~ + return; //Avoid to show the prefix and suffix. Show only the name you want + } + } + lpctstr lpPrefix = pChar->GetKeyStr("NAME.PREFIX"); if (!*lpPrefix) @@ -254,6 +269,7 @@ void CClient::AOSTooltip_addName(CObjBase* pObj) if (!*lpPrefix) lpPrefix = " "; + tchar * lpSuffix = Str_GetTemp(); Str_CopyLimitNull(lpSuffix, pChar->GetKeyStr("NAME.SUFFIX"), Str_TempLength()); diff --git a/src/network/send.cpp b/src/network/send.cpp index 793e0ffd1..ef069b021 100644 --- a/src/network/send.cpp +++ b/src/network/send.cpp @@ -155,6 +155,7 @@ PacketObjectStatus::PacketObjectStatus(CClient* target, CObjBase* object) : Pack { CScriptTriggerArgs args; args.m_s1 = object->GetName(); + args.m_iN1 =2;//Trigger use on status if (objectChar->OnTrigger(CTRIG_DisplayName, character, &args) == TRIGRET_RET_TRUE) { @@ -2650,6 +2651,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : Pack { CScriptTriggerArgs args; args.m_s1 = character->GetName(); + args.m_iN1 = 1;//Trigger use on paperdoll if (character->OnTrigger(CTRIG_DisplayName, target->GetChar(), &args) == TRIGRET_RET_TRUE) { bCustomName = 1; From facf2c91079a3ef6f428a5561061b27e2f734563 Mon Sep 17 00:00:00 2001 From: Jhobean Date: Wed, 16 Oct 2024 07:25:39 -0400 Subject: [PATCH 5/5] Always new tooltips for player --- Changelog.txt | 1 - src/game/clients/CClientMsg_AOSTooltip.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 45083454d..4da42259d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3917,7 +3917,6 @@ Added: 'H' shortcut for variables to get the value as hexadecimal. - Added: @DisplayName give possibility to change the name other player see on the paperdoll and on status bar. Could be use on RP server where unknow person don't know your name before presentation. Since the name is use at many place, this trigger happen on 3 differents place in the source. - If you use tooltip, you must set TooltipCache=0 on ini to avoid other player see the tooltip you generate for a particular player. src.: The player requesting to view the name on the paperdoll or status i: The player stalked by the src. ARGS (R/W): The name to display diff --git a/src/game/clients/CClientMsg_AOSTooltip.cpp b/src/game/clients/CClientMsg_AOSTooltip.cpp index e41a28527..1e3bafaec 100644 --- a/src/game/clients/CClientMsg_AOSTooltip.cpp +++ b/src/game/clients/CClientMsg_AOSTooltip.cpp @@ -67,14 +67,17 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) PacketPropertyList* propertyList = pObj->GetPropertyList(); - if (propertyList == nullptr || propertyList->hasExpired(g_Cfg.m_iTooltipCache)) + CItem* pItem = pObj->IsItem() ? static_cast(pObj) : nullptr; + CChar* pChar = pObj->IsChar() ? static_cast(pObj) : nullptr; + + //If pChar is a client we avoid to use cache because we always generate new tooltip for player. + if ((pChar && pChar->IsClientActive()) || propertyList == nullptr || propertyList->hasExpired(g_Cfg.m_iTooltipCache)) { pObj->m_TooltipData.clear(); pObj->FreePropertyList(); CClientTooltip* t = nullptr; - CItem *pItem = pObj->IsItem() ? static_cast(pObj) : nullptr; - CChar *pChar = pObj->IsChar() ? static_cast(pObj) : nullptr; + //DEBUG_MSG(("Preparing tooltip for 0%x (%s)\n", (dword)pObj->GetUID(), pObj->GetName())); if (fNameOnly) // if we only want to display the name