diff --git a/SKSE/Plugins/ArtifactTrackerFunctions.dll b/SKSE/Plugins/ArtifactTrackerFunctions.dll index ffbb2bc..3d98620 100644 Binary files a/SKSE/Plugins/ArtifactTrackerFunctions.dll and b/SKSE/Plugins/ArtifactTrackerFunctions.dll differ diff --git a/Scripts/ETR_Functions.pex b/Scripts/ETR_Functions.pex index be06c7b..fe8a42a 100644 Binary files a/Scripts/ETR_Functions.pex and b/Scripts/ETR_Functions.pex differ diff --git a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h index 98f3a94..cd5414a 100644 --- a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h +++ b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h @@ -52,17 +52,18 @@ namespace Papyrus::ArtifactTracker inline bool is_artifact(RE::TESForm* a_form) { - if (!a_form->GetPlayable()) { - return false; + switch (a_form->GetFormType()) { + case RE::FormType::Armor: + return a_form->GetPlayable(); + case RE::FormType::Weapon: + return a_form->GetPlayable() && a_form->formID != 0x000001F4; + case RE::FormType::Book: + return BookCheck::GetBookList().contains(a_form->formID); + case RE::FormType::Misc: + return MiscCheck::GetMiscList().contains(a_form->formID); + default: + return false; } - - const auto formType = a_form->GetFormType(); - - return ( - formType == RE::FormType::Armor - || (formType == RE::FormType::Weapon && a_form->formID != 0x000001F4) - || (formType == RE::FormType::Book && BookCheck::GetBookList().contains(a_form->formID)) - || (formType == RE::FormType::Misc && MiscCheck::GetMiscList().contains(a_form->formID))); } inline std::int32_t AddAllFormsToList(RE::StaticFunctionTag*, @@ -72,34 +73,43 @@ namespace Papyrus::ArtifactTracker { const auto formType = static_cast(a_formType); - if (formType == RE::FormType::Book) { - for (auto const& item : BookCheck::GetBookList()) { - if (!a_excludeForm || !is_excluded(item.second, a_excludeForm)) { - a_targetList->AddForm(item.second); + switch (formType) { + + case RE::FormType::Book: + for (auto const& item : BookCheck::GetBookList()) { + if (!a_excludeForm || !is_excluded(item.second, a_excludeForm)) { + a_targetList->AddForm(item.second); + } } - } - } else if (formType == RE::FormType::Misc) { - for (auto const& item : MiscCheck::GetMiscList()) { - if (!a_excludeForm || !is_excluded(item.second, a_excludeForm)) { - a_targetList->AddForm(item.second); + break; + + case RE::FormType::Misc: + for (auto const& item : MiscCheck::GetMiscList()) { + if (!a_excludeForm || !is_excluded(item.second, a_excludeForm)) { + a_targetList->AddForm(item.second); + } } - } - } else { - const auto dataHandler = RE::TESDataHandler::GetSingleton(); + break; - if (!dataHandler) { - return a_targetList->forms.size(); - } + case RE::FormType::None: + break; - for (const auto& form : dataHandler->GetFormArray(formType)) { - if (!form || !form->GetPlayable()) { - continue; + default: + const auto dataHandler = RE::TESDataHandler::GetSingleton(); + + if (!dataHandler) { + return a_targetList->forms.size(); } - if (a_excludeForm && is_excluded(form, a_excludeForm)) { - continue; + + for (const auto& form : dataHandler->GetFormArray(formType)) { + if (!form || !form->GetPlayable()) { + continue; + } + if (a_excludeForm && is_excluded(form, a_excludeForm)) { + continue; + } + a_targetList->AddForm(form); } - a_targetList->AddForm(form); - } } return a_targetList->forms.size(); @@ -111,11 +121,11 @@ namespace Papyrus::ArtifactTracker RE::TESForm* a_excludeForm = NULL) { if (!a_refOrList) { - a_vm->TraceStack("a_refOrList in AddItemsOfTypeAndKeywordToList is None", a_stackID); + a_vm->TraceStack("a_refOrList in AddArtifactsToList is None", a_stackID); return 0; } if (!a_targetList) { - a_vm->TraceStack("a_targetList in AddItemsOfTypeAndKeywordToList is None", a_stackID); + a_vm->TraceStack("a_targetList in AddArtifactsToList is None", a_stackID); return 0; } @@ -133,7 +143,7 @@ namespace Papyrus::ArtifactTracker const auto containerRef = a_refOrList->As(); if (!containerRef) { - a_vm->TraceStack("containerRef in AddItemsOfTypeAndKeywordToList is not a reference", a_stackID); + a_vm->TraceStack("containerRef in AddArtifactsToList is not a reference", a_stackID); return 0; } @@ -141,10 +151,9 @@ namespace Papyrus::ArtifactTracker return is_artifact(&a_exform) && !is_excluded(&a_exform, a_excludeForm); }); - for (const auto& [item, data] : inv) { - const auto& [count, entry] = data; - if (count > 0) { - a_targetList->AddForm(item); + for (const auto& item : inv) { + if (item.second.first > 0) { + a_targetList->AddForm(item.first); } } @@ -185,52 +194,6 @@ namespace Papyrus::ArtifactTracker return result; } - inline bool HasRefInCell(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, - RE::TESBoundObject* a_item, - RE::TESObjectCELL* a_cell = NULL, - bool a_checkInContainers = true, - RE::BGSListForm* a_excludeList = NULL) - { - bool bResult = false; - - if (!a_cell) { - a_cell = RE::PlayerCharacter::GetSingleton()->GetParentCell(); - } - - a_cell->ForEachReference([&](RE::TESObjectREFR& a_ref) { - const auto baseObj = a_ref.GetBaseObject(); - - if (a_item->formID == baseObj->formID) { - if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion()) { - return true; - } - if (a_excludeList && a_excludeList->HasForm(a_ref.formID)) { - return true; - } - bResult = true; - return false; - } else if (a_checkInContainers) { - if (baseObj->formType == RE::FormType::Container || (baseObj->formType == RE::FormType::NPC && !a_ref.IsDisabled() && baseObj->As()->GetRace()->formID == 0x0010760A)) { - if (a_excludeList && a_excludeList->HasForm(a_ref.formID)) { - return true; - } - const auto inv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool { - return a_item->formID == a_object.formID; - }); - const auto it = inv.find(a_item); - if (it != inv.end() ? it->second.first : 0) { - bResult = true; - return false; - } - } - } - - return true; - }); - - return bResult; - } - inline void SyncCellStorage(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, RE::TESObjectREFR* a_cellStorage, RE::TESForm* a_excludeForm = NULL) @@ -245,7 +208,7 @@ namespace Papyrus::ArtifactTracker const auto cell = a_cellStorage->GetParentCell(); const auto inv = a_cellStorage->GetInventory(); - for (const auto a_ref : cell->references) { + for (const RE::NiPointer a_ref : cell->references) { const auto baseObj = a_ref->GetBaseObject(); if (baseObj->formType == RE::FormType::Container || (baseObj->formType == RE::FormType::NPC && !a_ref->IsDisabled() && baseObj->As()->GetRace()->formID == 0x0010760A)) { @@ -258,8 +221,7 @@ namespace Papyrus::ArtifactTracker }); for (const auto& [item, data] : contInv) { - const auto& [count, entry] = data; - if (count > 0) { + if (data.first > 0) { cellItems[item->formID] = true; if (inv.find(item) == inv.end()) { if (is_artifact(item) && !is_excluded(item, a_excludeForm)) { @@ -311,8 +273,6 @@ namespace Papyrus::ArtifactTracker logger::info("Registered AddArtifactsToList"sv); BIND(GetCellStorage); logger::info("Registered GetCellStorage"sv); - BIND(HasRefInCell); - logger::info("Registered HasRefInCell"sv); BIND(SyncCellStorage); logger::info("Registered SyncCellStorage"sv); } diff --git a/Source/Scripts/ETR_Functions.psc b/Source/Scripts/ETR_Functions.psc index c86f307..3e4cc22 100644 --- a/Source/Scripts/ETR_Functions.psc +++ b/Source/Scripts/ETR_Functions.psc @@ -12,6 +12,4 @@ Actor[] function GetPlayerFollowers() native global ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) native global -bool function HasRefInCell(Form item, Cell currentCell = None, bool checkContainers = true, FormList excludeList = None) native global - function SyncCellStorage(ObjectReference cellStorage, Form excludeForm = None) native global