From 557cffcf6c4be455f0f65706cb496786755aabca Mon Sep 17 00:00:00 2001 From: Cjreek Date: Tue, 8 Aug 2023 19:47:43 +0200 Subject: [PATCH 1/3] Added NWNX_Player_GetTurd() --- CHANGELOG.md | 1 + Plugins/Player/NWScript/nwnx_player.nss | 15 +++++++++++++++ Plugins/Player/Player.cpp | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa8c1f25b7..5d428a3c40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ https://github.com/nwnxee/unified/compare/build8193.35.40...HEAD - Creature: {Get|Set}AbilityIncreaseByLevel() - Util: GetModuleFile() - Creature: NWNX_Creature_GetMaxAttackRange() +- Player: GetTURD() ### Changed - Creature: Added an argument for passing a class package to `NWNX_Creature_LevelUp()` diff --git a/Plugins/Player/NWScript/nwnx_player.nss b/Plugins/Player/NWScript/nwnx_player.nss index 775d46b844..dfb7e3d716 100644 --- a/Plugins/Player/NWScript/nwnx_player.nss +++ b/Plugins/Player/NWScript/nwnx_player.nss @@ -440,6 +440,11 @@ void NWNX_Player_SetObjectUiDiscoveryMaskOverride(object oPlayer, object oObject /// @param bHideDialog TRUE: Does not show the party invitation dialog void NWNX_Player_SendPartyInvite(object oPlayer, object oInviter, int bForceInvite = FALSE, int bHideDialog = FALSE); +/// @brief Get the TURD for oPlayer +/// @param oPlayer The offline player to get the TURD from +/// @return the TURD object of oPlayer, or OBJECT_INVALID if no TURD exists +object NWNX_Player_GetTURD(object oPlayer); + /// @} void NWNX_Player_ForcePlaceableExamineWindow(object player, object placeable) @@ -1119,3 +1124,13 @@ void NWNX_Player_SendPartyInvite(object oPlayer, object oInviter, int bForceInvi NWNX_CallFunction(NWNX_Player, sFunc); } + +object NWNX_Player_GetTURD(object oPlayer) +{ + string sFunc = "GetTURD"; + + NWNX_PushArgumentObject(oPlayer); + NWNX_CallFunction(NWNX_Player, sFunc); + + return NWNX_GetReturnValueObject(); +} diff --git a/Plugins/Player/Player.cpp b/Plugins/Player/Player.cpp index a0c340f432..6a5c2688c1 100644 --- a/Plugins/Player/Player.cpp +++ b/Plugins/Player/Player.cpp @@ -1952,3 +1952,18 @@ NWNX_EXPORT ArgumentStack SendPartyInvite(ArgumentStack&& args) return {}; } + +NWNX_EXPORT ArgumentStack GetTURD(ArgumentStack&& args) +{ + const auto oidPlayer = args.extract(); + + CExoLinkedListInternal* pTURDS = Utils::GetModule()->m_lstTURDList.m_pcExoLinkedListInternal; + for (CExoLinkedListPosition pNode = pTURDS->pHead; pNode; pNode = pNode->pNext) + { + auto* pTURD = static_cast(pNode->pObject); + if (pTURD->m_oidPlayer == oidPlayer) + return pTURD->m_idSelf; + } + + return Constants::OBJECT_INVALID; +} From 1e736cc056babf342361e2a03e0344b4a231e010 Mon Sep 17 00:00:00 2001 From: Cjreek Date: Tue, 8 Aug 2023 23:34:28 +0200 Subject: [PATCH 2/3] Null-pointer-proof code --- Plugins/Player/Player.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Plugins/Player/Player.cpp b/Plugins/Player/Player.cpp index 6a5c2688c1..9960d40729 100644 --- a/Plugins/Player/Player.cpp +++ b/Plugins/Player/Player.cpp @@ -1958,11 +1958,14 @@ NWNX_EXPORT ArgumentStack GetTURD(ArgumentStack&& args) const auto oidPlayer = args.extract(); CExoLinkedListInternal* pTURDS = Utils::GetModule()->m_lstTURDList.m_pcExoLinkedListInternal; - for (CExoLinkedListPosition pNode = pTURDS->pHead; pNode; pNode = pNode->pNext) + if (pTURDS) { - auto* pTURD = static_cast(pNode->pObject); - if (pTURD->m_oidPlayer == oidPlayer) - return pTURD->m_idSelf; + for (CExoLinkedListPosition pNode = pTURDS->pHead; pNode; pNode = pNode->pNext) + { + auto* pTURD = static_cast(pNode->pObject); + if ((pTURD) && (pTURD->m_oidPlayer == oidPlayer)) + return pTURD->m_idSelf; + } } return Constants::OBJECT_INVALID; From 6cc5c455d94740f0a6089cf7e34509c216ec04d2 Mon Sep 17 00:00:00 2001 From: Cjreek Date: Tue, 8 Aug 2023 23:39:52 +0200 Subject: [PATCH 3/3] C++ified the code --- Plugins/Player/Player.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Plugins/Player/Player.cpp b/Plugins/Player/Player.cpp index 9960d40729..31dab454ef 100644 --- a/Plugins/Player/Player.cpp +++ b/Plugins/Player/Player.cpp @@ -1956,9 +1956,8 @@ NWNX_EXPORT ArgumentStack SendPartyInvite(ArgumentStack&& args) NWNX_EXPORT ArgumentStack GetTURD(ArgumentStack&& args) { const auto oidPlayer = args.extract(); - - CExoLinkedListInternal* pTURDS = Utils::GetModule()->m_lstTURDList.m_pcExoLinkedListInternal; - if (pTURDS) + + if (CExoLinkedListInternal* pTURDS = Utils::GetModule()->m_lstTURDList.m_pcExoLinkedListInternal) { for (CExoLinkedListPosition pNode = pTURDS->pHead; pNode; pNode = pNode->pNext) {