Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 73 additions & 7 deletions include/RE/B/BGSTypedKeywordValueArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ namespace RE
class BGSTypedKeywordValue
{
public:
// members
std::uint16_t keywordIndex; // 0
std::uint16_t pad02; // 2
std::uint32_t pad04; // 4
};
static_assert(sizeof(BGSTypedKeywordValue<KeywordType::kNone>) == 0x8);

namespace detail
{
Expand All @@ -48,19 +50,83 @@ namespace RE
public:
[[nodiscard]] bool HasKeyword(BGSKeyword* a_keyword)
{
for (std::uint32_t i = 0; i < size; ++i) {
const auto kywd = detail::BGSKeywordGetTypedKeywordByIndex(TYPE, array[i].keywordIndex);
if (!a_keyword) {
return false;
}

for (auto it = begin; it != end; ++it) {
const auto kywd = detail::BGSKeywordGetTypedKeywordByIndex(TYPE, it->keywordIndex);
if (kywd == a_keyword) {
return true;
}
}
return false;
}

// members
BGSTypedKeywordValue<TYPE>* array; // 00
std::uint32_t size; // 08
std::uint64_t unk10; // 10
[[nodiscard]] bool AddKeyword(BGSKeyword* a_keyword)
{
if (!a_keyword) {
return false;
}

auto first = reinterpret_cast<BGSKeyword**>(begin);
auto last = reinterpret_cast<BGSKeyword**>(end);

for (auto it = first; it != last; ++it) {
if (*it && (*it)->formID == a_keyword->formID) {
return false;
}
}

const auto oldSize = static_cast<std::size_t>(last - first);
const auto newSize = oldSize + 1;

auto* newData = static_cast<BGSKeyword**>(
RE::MemoryManager::GetSingleton()->Allocate(sizeof(BGSKeyword*) * newSize, 0, false));

if (!newData) {
return false;
}

for (std::size_t i = 0; i < oldSize; ++i) {
newData[i] = first[i];
}

newData[oldSize] = a_keyword;
auto oldFirst = first;
auto oldLast = last;
auto oldCap = reinterpret_cast<BGSKeyword**>(capacityEnd);

begin = reinterpret_cast<BGSTypedKeywordValue<TYPE>*>(newData);
end = reinterpret_cast<BGSTypedKeywordValue<TYPE>*>(newData + newSize);
capacityEnd = reinterpret_cast<BGSTypedKeywordValue<TYPE>*>(newData + newSize);
return true;
}

[[nodiscard]] bool RemoveKeyword(BGSKeyword* a_keyword)
{
if (!a_keyword) {
return false;
}
auto first = reinterpret_cast<BGSKeyword**>(begin);
auto last = reinterpret_cast<BGSKeyword**>(end);
for (auto it = first; it != last; ++it) {
if (*it && (*it)->formID == a_keyword->formID) {
for (auto jt = it; jt + 1 != last; ++jt) {
*jt = *(jt + 1);
}
--last;
*last = nullptr;
end = reinterpret_cast<BGSTypedKeywordValue<TYPE>*>(last);
return true;
}
}
return false;
}

BGSTypedKeywordValue<TYPE>* begin; // 00
BGSTypedKeywordValue<TYPE>* end; // 08
BGSTypedKeywordValue<TYPE>* capacityEnd; // 10
};
static_assert(sizeof(BGSTypedKeywordValueArray<KeywordType::kNone>) == 0x18);
}
Loading