diff --git a/Artifact Tracker.esp b/Artifact Tracker.esp index f4198e0..29d3b96 100644 Binary files a/Artifact Tracker.esp and b/Artifact Tracker.esp differ diff --git a/SKSE/Plugins/ArtifactTrackerFunctions.dll b/SKSE/Plugins/ArtifactTrackerFunctions.dll index 7f351c9..ffbb2bc 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 2d8a26c..be06c7b 100644 Binary files a/Scripts/ETR_Functions.pex and b/Scripts/ETR_Functions.pex differ diff --git a/Scripts/ETR_TrackFoundItems.pex b/Scripts/ETR_TrackFoundItems.pex index 746e8eb..b2a1e83 100644 Binary files a/Scripts/ETR_TrackFoundItems.pex and b/Scripts/ETR_TrackFoundItems.pex differ diff --git a/Scripts/ETR_TrackNewItems.pex b/Scripts/ETR_TrackNewItems.pex index 157bb16..66091b2 100644 Binary files a/Scripts/ETR_TrackNewItems.pex and b/Scripts/ETR_TrackNewItems.pex differ diff --git a/Scripts/ETR_TrackStoredItems.pex b/Scripts/ETR_TrackStoredItems.pex index b4e2f15..d38026a 100644 Binary files a/Scripts/ETR_TrackStoredItems.pex and b/Scripts/ETR_TrackStoredItems.pex differ diff --git a/Source/ArtifactTrackerDLL/CMakeLists.txt b/Source/ArtifactTrackerDLL/CMakeLists.txt index 7558afe..e77bcc9 100644 --- a/Source/ArtifactTrackerDLL/CMakeLists.txt +++ b/Source/ArtifactTrackerDLL/CMakeLists.txt @@ -24,6 +24,7 @@ set(sources src/Main.cpp src/Papyrus.cpp src/BookCheck.cpp + src/MiscCheck.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.rc) diff --git a/Source/ArtifactTrackerDLL/src/BookCheck.cpp b/Source/ArtifactTrackerDLL/src/BookCheck.cpp index 5d8a598..d96e4f2 100644 --- a/Source/ArtifactTrackerDLL/src/BookCheck.cpp +++ b/Source/ArtifactTrackerDLL/src/BookCheck.cpp @@ -13,10 +13,10 @@ namespace BookCheck return; } - RE::BGSKeyword* recipeKeyword = dataHandler->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe + const RE::BGSKeyword* recipeKeyword = dataHandler->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe for (const auto& form : dataHandler->GetFormArray()) { - if (!form || form->TeachesSpell()) { + if (!form || !form->GetPlayable() || form->TeachesSpell()) { continue; } if (form->HasKeyword(recipeKeyword) || IsBook(form)) { diff --git a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h index 287d7f4..98f3a94 100644 --- a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h +++ b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h @@ -50,19 +50,19 @@ namespace Papyrus::ArtifactTracker return false; } - inline bool is_artifact(RE::TESForm* a_form, RE::TESForm* a_excludeForm = NULL) + inline bool is_artifact(RE::TESForm* a_form) { - const auto formType = a_form->GetFormType(); - - if (formType != RE::FormType::Armor && formType != RE::FormType::Weapon && formType != RE::FormType::Book && formType != RE::FormType::Misc) { + if (!a_form->GetPlayable()) { return false; } - if (!a_form->GetPlayable() || is_excluded(a_form, a_excludeForm)) { - return false; - } + const auto formType = a_form->GetFormType(); - return true; + 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*, @@ -70,22 +70,36 @@ namespace Papyrus::ArtifactTracker short a_formType, RE::TESForm* a_excludeForm = NULL) { - const auto dataHandler = RE::TESDataHandler::GetSingleton(); - - if (!dataHandler) { - return a_targetList->forms.size(); - } - const auto formType = static_cast(a_formType); - for (const auto& form : dataHandler->GetFormArray(formType)) { - if (!form || !form->GetPlayable()) { - continue; + 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); + } } - if (a_excludeForm && is_excluded(form, a_excludeForm)) { - continue; + } 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); + } + } + } else { + const auto dataHandler = RE::TESDataHandler::GetSingleton(); + + if (!dataHandler) { + return a_targetList->forms.size(); + } + + 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(); @@ -94,8 +108,7 @@ namespace Papyrus::ArtifactTracker inline std::int32_t AddArtifactsToList(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, RE::TESForm* a_refOrList, RE::BGSListForm* a_targetList, - RE::TESForm* a_excludeForm = NULL, - bool excludeOnlyMisc = false) + RE::TESForm* a_excludeForm = NULL) { if (!a_refOrList) { a_vm->TraceStack("a_refOrList in AddItemsOfTypeAndKeywordToList is None", a_stackID); @@ -110,7 +123,7 @@ namespace Papyrus::ArtifactTracker a_refOrList->As()->ForEachForm([&](RE::TESForm& a_exform) { const auto refrItem = a_exform.As(); if (refrItem) { - AddArtifactsToList(a_vm, a_stackID, {}, refrItem, a_targetList, a_excludeForm, excludeOnlyMisc); + AddArtifactsToList(a_vm, a_stackID, {}, refrItem, a_targetList, a_excludeForm); } return true; }); @@ -124,17 +137,8 @@ namespace Papyrus::ArtifactTracker return 0; } - RE::BGSKeyword* recipeKeyword = RE::TESDataHandler::GetSingleton()->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe - auto inv = containerRef->GetInventory([&](RE::TESBoundObject& a_exform) { - return a_exform.GetPlayable() - && ( - a_exform.formType == RE::FormType::Armor - || (a_exform.formType == RE::FormType::Weapon && a_exform.formID != 0x000001F4) - || a_exform.formType == RE::FormType::Misc - || (a_exform.formType == RE::FormType::Book && BookCheck::GetBookList().contains(a_exform.formID)) - ) - && (excludeOnlyMisc ? (a_exform.formType != RE::FormType::Misc || !is_excluded(&a_exform, a_excludeForm)) : !is_excluded(&a_exform, a_excludeForm)); + return is_artifact(&a_exform) && !is_excluded(&a_exform, a_excludeForm); }); for (const auto& [item, data] : inv) { @@ -258,7 +262,7 @@ namespace Papyrus::ArtifactTracker if (count > 0) { cellItems[item->formID] = true; if (inv.find(item) == inv.end()) { - if (is_artifact(item, a_excludeForm)) { + if (is_artifact(item) && !is_excluded(item, a_excludeForm)) { a_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr); } } @@ -278,12 +282,14 @@ namespace Papyrus::ArtifactTracker cellItems[baseObj->formID] = true; - if (!is_artifact(baseObj, a_excludeForm)) { + if (!is_artifact(baseObj)) { continue; } if (inv.find(baseObj) == inv.end()) { - a_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); + if (!a_excludeForm || !is_excluded(baseObj, a_excludeForm)) { + a_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); + } } } @@ -297,30 +303,6 @@ namespace Papyrus::ArtifactTracker cellItems.clear(); } - inline std::int32_t AddAllBooksToList(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, - RE::BGSListForm* a_targetList, - RE::TESForm* a_excludeForm = NULL) - { - if (!a_targetList) { - a_vm->TraceStack("a_targetList in AddItemsOfTypeAndKeywordToList is None", a_stackID); - return 0; - } - - if (a_excludeForm) { - for (auto const& item : BookCheck::GetBookList()) { - if (!is_excluded(item.second, a_excludeForm)) { - a_targetList->AddForm(item.second); - } - } - } else { - for (const auto& item : BookCheck::GetBookList()) { - a_targetList->AddForm(item.second); - } - } - - return a_targetList->forms.size(); - } - inline void Bind(VM& a_vm) { BIND(AddAllFormsToList); @@ -333,7 +315,5 @@ namespace Papyrus::ArtifactTracker logger::info("Registered HasRefInCell"sv); BIND(SyncCellStorage); logger::info("Registered SyncCellStorage"sv); - BIND(AddAllBooksToList); - logger::info("Registered AddAllBooksToList"sv); } } diff --git a/Source/ArtifactTrackerDLL/src/Main.cpp b/Source/ArtifactTrackerDLL/src/Main.cpp index 11eb148..a1467eb 100644 --- a/Source/ArtifactTrackerDLL/src/Main.cpp +++ b/Source/ArtifactTrackerDLL/src/Main.cpp @@ -1,5 +1,6 @@ #include "Papyrus.h" #include "BookCheck.h" +#include "MiscCheck.h" using namespace RE::BSScript; using namespace SKSE; @@ -30,6 +31,7 @@ namespace { GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) { if (message->type == MessagingInterface::kDataLoaded) { BookCheck::PreloadBookList(); + MiscCheck::PreloadMiscList(); } }); } diff --git a/Source/ArtifactTrackerDLL/src/MiscCheck.cpp b/Source/ArtifactTrackerDLL/src/MiscCheck.cpp new file mode 100644 index 0000000..8903f7c --- /dev/null +++ b/Source/ArtifactTrackerDLL/src/MiscCheck.cpp @@ -0,0 +1,29 @@ +#include "MiscCheck.h" + +namespace MiscCheck +{ + std::unordered_map validMisc; + + void PreloadMiscList() + { + const auto dataHandler = RE::TESDataHandler::GetSingleton(); + + if (!dataHandler) { + return; + } + + RE::BGSListForm* excludeForms = dataHandler->LookupForm(0x809, "Artifact Tracker.esp"); // ETR_ExcludeMiscForms + RE::BGSListForm* excludeKeywords = dataHandler->LookupForm(0x808, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords + + for (const auto& form : dataHandler->GetFormArray()) { + if (form->GetPlayable() && !excludeForms->HasForm(form) && !form->HasKeywordInList(excludeKeywords, false)) { + validMisc[form->formID] = form; + } + } + } + + std::unordered_map GetMiscList() + { + return validMisc; + } +} diff --git a/Source/ArtifactTrackerDLL/src/MiscCheck.h b/Source/ArtifactTrackerDLL/src/MiscCheck.h new file mode 100644 index 0000000..c0db170 --- /dev/null +++ b/Source/ArtifactTrackerDLL/src/MiscCheck.h @@ -0,0 +1,8 @@ +#pragma once + +namespace MiscCheck +{ + void PreloadMiscList(); + + std::unordered_map GetMiscList(); +} diff --git a/Source/ArtifactTrackerDLL/src/Papyrus.cpp b/Source/ArtifactTrackerDLL/src/Papyrus.cpp index d069be7..6fcf0ef 100644 --- a/Source/ArtifactTrackerDLL/src/Papyrus.cpp +++ b/Source/ArtifactTrackerDLL/src/Papyrus.cpp @@ -1,5 +1,6 @@ #include "Papyrus.h" #include "BookCheck.h" +#include "MiscCheck.h" #include "Functions/ObjectReference.h" #include "Functions/ArtifactTracker.h" diff --git a/Source/Scripts/ETR_Functions.psc b/Source/Scripts/ETR_Functions.psc index 84b92f4..c86f307 100644 --- a/Source/Scripts/ETR_Functions.psc +++ b/Source/Scripts/ETR_Functions.psc @@ -2,9 +2,7 @@ Scriptname ETR_Functions Hidden int function AddAllFormsToList(FormList targetList, int formType, Form excludeForm = None) native global -int function AddAllBooksToList(FormList targetList, Form excludeForm = None) native global - -int function AddArtifactsToList(Form refOrList, FormList targetList, Form excludeForm = None, bool excludeOnlyMisc = false) native global +int function AddArtifactsToList(Form refOrList, FormList targetList, Form excludeForm = None) native global int function GetItemCountInList(FormList refList, Form baseForm) native global diff --git a/Source/Scripts/ETR_TrackFoundItems.psc b/Source/Scripts/ETR_TrackFoundItems.psc index 01972f2..84e2e78 100644 --- a/Source/Scripts/ETR_TrackFoundItems.psc +++ b/Source/Scripts/ETR_TrackFoundItems.psc @@ -6,7 +6,6 @@ FormList Property ETR_ItemsNew Auto FormList Property ETR_ItemsFound Auto FormList Property ETR_ItemsStored Auto FormList Property ETR_PersistentStorageList Auto -FormList Property ETR_ExcludeFromNew Auto FormList Property ETR_ExcludeMisc Auto Container Property ETR_CellStorageContainer Auto @@ -89,7 +88,7 @@ Event OnUpdate() endif bRescanHome = false ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer) - ETR_Functions.SyncCellStorage(cellStorage, ETR_ExcludeMisc) + ETR_Functions.SyncCellStorage(cellStorage) if ! bRescanPersistent ETR_Functions.AddArtifactsToList(cellStorage, ETR_ItemsStored) endif @@ -101,18 +100,18 @@ Event OnUpdate() int n = aContainers.length while n > 0 n -= 1 - ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored, ETR_ExcludeMisc, true) + ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored) endwhile endif ETR_ItemsFound.Revert() - ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() int i = aFollowers.length while i > 0 i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) endwhile bBusy = false diff --git a/Source/Scripts/ETR_TrackNewItems.psc b/Source/Scripts/ETR_TrackNewItems.psc index a0ed67a..6249c91 100644 --- a/Source/Scripts/ETR_TrackNewItems.psc +++ b/Source/Scripts/ETR_TrackNewItems.psc @@ -47,23 +47,23 @@ event OnPlayerLoadGame() ; Rebuild all lists to avoid discrepancies, stale data, and broken records ETR_ItemsStored.Revert() - ETR_Functions.AddArtifactsToList(ETR_PersistentStorageList, ETR_ItemsStored, ETR_ExcludeMisc, true) + ETR_Functions.AddArtifactsToList(ETR_PersistentStorageList, ETR_ItemsStored) ETR_ItemsFound.Revert() - ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() int i = aFollowers.length while i > 0 i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) endwhile ETR_ItemsNew.Revert() ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 41, ETR_FoundAndStored) - ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 32, ETR_ExcludeFromNew) - ETR_Functions.AddAllBooksToList(ETR_ItemsNew, ETR_FoundAndStored) + ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 32, ETR_FoundAndStored) + ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 27, ETR_FoundAndStored) endevent diff --git a/Source/Scripts/ETR_TrackStoredItems.psc b/Source/Scripts/ETR_TrackStoredItems.psc index c090bb5..c70ece4 100644 --- a/Source/Scripts/ETR_TrackStoredItems.psc +++ b/Source/Scripts/ETR_TrackStoredItems.psc @@ -80,7 +80,7 @@ Event OnUpdate() return endif ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer) - ETR_Functions.SyncCellStorage(cellStorage, ETR_ExcludeMisc) + ETR_Functions.SyncCellStorage(cellStorage) endif if bRescanPersistent @@ -90,17 +90,17 @@ Event OnUpdate() int n = aContainers.length while n > 0 n -= 1 - ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored, ETR_ExcludeMisc, true) + ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored) endwhile ETR_ItemsFound.Revert() - ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() int i = aFollowers.length while i > 0 i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ExcludeFromNew) + ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) endwhile endif @@ -126,7 +126,7 @@ event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemRefere elseif bAtHome ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer) if cellStorage.GetItemCount(akBaseItem) - ETR_Functions.SyncCellStorage(cellStorage, ETR_ExcludeMisc) + ETR_Functions.SyncCellStorage(cellStorage) if ETR_Functions.GetItemCountInList(ETR_PersistentStorageList, akBaseItem) == 0 ETR_ItemsStored.RemoveAddedForm(akBaseItem) ETR_ItemsFound.AddForm(akBaseItem)