Skip to content

Commit

Permalink
Add TESForm::HasKeywordByEditorID
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Jan 9, 2024
1 parent bade6c1 commit 00d54d9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions include/RE/S/SendUIMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_t> func{ RELOCATION_ID(51911, 52849) };
return func(a_inventoryRef, a_updateObj);
}
void SendInventoryUpdateMessage(TESObjectREFR* a_inventoryRef, const TESBoundObject* a_updateObj);
}
}
11 changes: 2 additions & 9 deletions include/RE/T/TESForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace RE
[[nodiscard]] float GetWeight() const;
[[nodiscard]] bool HasKeywordInArray(const std::vector<BGSKeyword*>& a_keywords, bool a_matchAll) const;
[[nodiscard]] bool HasAnyKeywordByEditorID(const std::vector<std::string>& 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;
Expand All @@ -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 <class... Args>
Expand All @@ -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); }

Expand Down
14 changes: 14 additions & 0 deletions src/RE/S/SendUIMessage.cpp
Original file line number Diff line number Diff line change
@@ -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_t> func{ RELOCATION_ID(51911, 52849) };
return func(a_inventoryRef, a_updateObj);
}
}
}
34 changes: 19 additions & 15 deletions src/RE/T/TESForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BGSKeywordForm>();
if (!keywordForm) {
return false;
}

return false;
return keywordForm->HasKeywordString(a_editorID);
}

bool TESForm::HasKeywordInArray(const std::vector<BGSKeyword*>& a_keywords, bool a_matchAll) const
bool TESForm::HasKeywordInArray(const std::vector<BGSKeyword*>& a_keywords, bool a_matchAll) const
{
const auto keywordForm = As<BGSKeywordForm>();
if (!keywordForm) {
Expand Down

0 comments on commit 00d54d9

Please sign in to comment.