From 00d54d9b6f2f03530ebfa0e9acc6419c98a64017 Mon Sep 17 00:00:00 2001 From: powerof3 <32599957+powerof3@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:09:20 +0530 Subject: [PATCH] Add `TESForm::HasKeywordByEditorID` --- cmake/sourcelist.cmake | 1 + include/RE/S/SendUIMessage.h | 7 +------ include/RE/T/TESForm.h | 11 ++--------- src/RE/S/SendUIMessage.cpp | 14 ++++++++++++++ src/RE/T/TESForm.cpp | 34 +++++++++++++++++++--------------- 5 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 src/RE/S/SendUIMessage.cpp diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index 338c78755..e94d783bb 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -1900,6 +1900,7 @@ set(SOURCES src/RE/S/ScrapHeap.cpp src/RE/S/Script.cpp src/RE/S/ScriptEventSourceHolder.cpp + src/RE/S/SendUIMessage.cpp src/RE/S/Setting.cpp src/RE/S/ShoutAttack.cpp src/RE/S/SkillIncrease.cpp diff --git a/include/RE/S/SendUIMessage.h b/include/RE/S/SendUIMessage.h index c01a01327..ec6ad5d1c 100644 --- a/include/RE/S/SendUIMessage.h +++ b/include/RE/S/SendUIMessage.h @@ -7,11 +7,6 @@ namespace RE namespace SendUIMessage { - void SendInventoryUpdateMessage(TESObjectREFR* a_inventoryRef, const TESBoundObject* a_updateObj) - { - using func_t = decltype(&SendUIMessage::SendInventoryUpdateMessage); - static REL::Relocation func{ RELOCATION_ID(51911, 52849) }; - return func(a_inventoryRef, a_updateObj); - } + void SendInventoryUpdateMessage(TESObjectREFR* a_inventoryRef, const TESBoundObject* a_updateObj); } } diff --git a/include/RE/T/TESForm.h b/include/RE/T/TESForm.h index 5141fd0ba..7884cb423 100644 --- a/include/RE/T/TESForm.h +++ b/include/RE/T/TESForm.h @@ -302,6 +302,7 @@ namespace RE [[nodiscard]] float GetWeight() const; [[nodiscard]] bool HasKeywordInArray(const std::vector& a_keywords, bool a_matchAll) const; [[nodiscard]] bool HasAnyKeywordByEditorID(const std::vector& editorIDs) const; + [[nodiscard]] bool HasKeywordByEditorID(std::string_view a_editorID); [[nodiscard]] bool HasKeywordInList(BGSListForm* a_keywordList, bool a_matchAll) const; [[nodiscard]] bool HasVMAD() const; [[nodiscard]] bool HasWorldModel() const noexcept; @@ -327,15 +328,6 @@ namespace RE [[nodiscard]] bool IsInitialized() const noexcept { return (GetFormFlags() & RecordFlags::kInitialized) != 0; } [[nodiscard]] bool IsKey() const noexcept { return Is(FormType::KeyMaster); } [[nodiscard]] bool IsLockpick() const noexcept { return GetFormID() == 0x0000000A; } - /** - * @brief Checks if the Form represents Skooma. - * - * Determines whether the FormID matches one of the known form IDs for Skooma. - * - * @return True if the FormID is either 0x00057A7A or 0x0201391D, indicating that it is Skooma or RedWater Skooma. - * - */ - [[nodiscard]] bool IsSkooma() const noexcept { return (GetFormID() == 0x00057A7A || GetFormID() == 0x0201391D); } [[nodiscard]] bool IsNot(FormType a_type) const noexcept { return !Is(a_type); } template @@ -348,6 +340,7 @@ namespace RE [[nodiscard]] bool IsNote() const noexcept { return Is(FormType::Note); } [[nodiscard]] bool IsPlayer() const noexcept { return GetFormID() == 0x00000007; } [[nodiscard]] bool IsPlayerRef() const noexcept { return GetFormID() == 0x00000014; } + [[nodiscard]] bool IsSkooma() const noexcept { return (GetFormID() == 0x00057A7A || GetFormID() == 0x0201391D); } [[nodiscard]] bool IsSoulGem() const noexcept { return Is(FormType::SoulGem); } [[nodiscard]] bool IsWeapon() const noexcept { return Is(FormType::Weapon); } diff --git a/src/RE/S/SendUIMessage.cpp b/src/RE/S/SendUIMessage.cpp new file mode 100644 index 000000000..66391a510 --- /dev/null +++ b/src/RE/S/SendUIMessage.cpp @@ -0,0 +1,14 @@ +#include "RE/S/SendUIMessage.h" + +namespace RE +{ + namespace SendUIMessage + { + void SendInventoryUpdateMessage(TESObjectREFR* a_inventoryRef, const TESBoundObject* a_updateObj) + { + using func_t = decltype(&SendInventoryUpdateMessage); + static REL::Relocation func{ RELOCATION_ID(51911, 52849) }; + return func(a_inventoryRef, a_updateObj); + } + } +} diff --git a/src/RE/T/TESForm.cpp b/src/RE/T/TESForm.cpp index ac034abff..41d88a701 100644 --- a/src/RE/T/TESForm.cpp +++ b/src/RE/T/TESForm.cpp @@ -67,26 +67,30 @@ namespace RE } // Iterate through the keywords - for (std::uint32_t i = 0; i < keywordForm->GetNumKeywords(); ++i) { - auto keywordOpt = keywordForm->GetKeywordAt(i); - if (keywordOpt) { - auto keyword = *keywordOpt; - if (keyword) { - const char* keywordEditorID = keyword->GetFormEditorID(); - if (keywordEditorID) { - // Check if the keywordEditorID is in the given editorIDs vector - if (std::find(editorIDs.begin(), editorIDs.end(), keywordEditorID) != editorIDs.end()) { - return true; - } - } - } + bool hasKeyword = false; + + keywordForm->ForEachKeyword([&](const BGSKeyword& a_keyword) { + if (std::ranges::find(editorIDs, a_keyword.GetFormEditorID()) != editorIDs.end()) { + hasKeyword = true; + return BSContainer::ForEachResult::kStop; } + return BSContainer::ForEachResult::kContinue; + }); + + return hasKeyword; + } + + bool TESForm::HasKeywordByEditorID(std::string_view a_editorID) + { + const auto keywordForm = As(); + if (!keywordForm) { + return false; } - return false; + return keywordForm->HasKeywordString(a_editorID); } - bool TESForm::HasKeywordInArray(const std::vector& a_keywords, bool a_matchAll) const + bool TESForm::HasKeywordInArray(const std::vector& a_keywords, bool a_matchAll) const { const auto keywordForm = As(); if (!keywordForm) {