diff --git a/SKSE/Plugins/ArtifactTracker.dll b/SKSE/Plugins/ArtifactTracker.dll index 7c34b9c..9217e3a 100644 Binary files a/SKSE/Plugins/ArtifactTracker.dll and b/SKSE/Plugins/ArtifactTracker.dll differ diff --git a/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp b/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp index 5231a19..6fee0ed 100644 --- a/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp +++ b/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp @@ -24,21 +24,21 @@ namespace ArtifactTracker const auto dataHandler = RE::TESDataHandler::GetSingleton(); if (!dataHandler) { - SKSE::log::warn("Failed to call RE::TESDataHandler::GetSingleton()"); + SKSE::log::error("Failed to call RE::TESDataHandler::GetSingleton()"); return; } - g_cellContainer = dataHandler->LookupForm(0x800, "Artifact Tracker.esp")->As(); + g_cellContainer = dataHandler->LookupForm(0x800, "Artifact Tracker.esp")->As(); // ETR_CellStorageContainer - g_listNew = dataHandler->LookupForm(0x803, "Artifact Tracker.esp"); - g_listStored = dataHandler->LookupForm(0x805, "Artifact Tracker.esp"); - g_listFound = dataHandler->LookupForm(0x806, "Artifact Tracker.esp"); - g_persistentStorage = dataHandler->LookupForm(0x807, "Artifact Tracker.esp"); + g_listNew = dataHandler->LookupForm(0x803, "Artifact Tracker.esp"); // ETR_ItemsNew + g_listStored = dataHandler->LookupForm(0x805, "Artifact Tracker.esp"); // ETR_ItemsStored + g_listFound = dataHandler->LookupForm(0x806, "Artifact Tracker.esp"); // ETR_ItemsFound + g_persistentStorage = dataHandler->LookupForm(0x807, "Artifact Tracker.esp"); // ETR_PersistentStorageList - g_homeKeyword = dataHandler->LookupForm(0xFC1A3, "Skyrim.esm"); + g_homeKeyword = dataHandler->LookupForm(0xFC1A3, "Skyrim.esm"); // LocTypePlayerHouse - const RE::BGSKeyword* recipeKeyword = dataHandler->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe - RE::BGSListForm* excludeKeywords = dataHandler->LookupForm(0x801, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords + const auto recipeKeyword = dataHandler->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe + const auto excludeKeywords = dataHandler->LookupForm(0x801, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords if (!g_cellContainer || !g_listNew || !g_listStored || !g_listFound || !g_persistentStorage || !g_homeKeyword || !recipeKeyword || !excludeKeywords) { SKSE::log::warn("Failed to load data from Artifact Tracker.esp"); @@ -49,7 +49,7 @@ namespace ArtifactTracker // Preloading item lists for (const auto& form : dataHandler->GetFormArray()) { - if (form && !form->TeachesSpell() && (!form->HasKeyword(recipeKeyword) || BookCheck::IsBook(form))) { + if (form && !form->TeachesSpell() && (form->HasKeyword(recipeKeyword) || BookCheck::IsBook(form))) { g_artifactMap[form->formID] = form; } } @@ -130,7 +130,7 @@ namespace ArtifactTracker g_bHomeContainer = IsHome() && refr && refr.get()->GetParentCell() == RE::PlayerCharacter::GetSingleton()->GetParentCell() - && !g_persistentStorage->HasForm(refr.get()); + && !g_persistentMap.contains(refr.get()->formID); #ifdef _DEBUG if (g_bHomeContainer) { @@ -248,7 +248,7 @@ namespace ArtifactTracker g_persistentMap[cellStorage->formID] = cellStorage; ToggleHomeMode(cellStorage); } else { - SKSE::log::warn("Failed to create cell storage in OnCellEnter"); + SKSE::log::error("Failed to create cell storage in OnCellEnter"); ToggleHomeMode(nullptr); } } @@ -410,8 +410,8 @@ namespace ArtifactTracker if (!RefHasItem(g_cellStorage, form->formID)) { #ifdef _DEBUG SKSE::log::info("Added dropped {} to cell storage", form->GetName()); + RE::DebugNotification("Adding to cell storage"); #endif - RE::DebugNotification("adding to cell storage"); g_cellStorage->AddObjectToContainer(form->As(), nullptr, 1, nullptr); } ListRemoveItem(g_listFound, form); diff --git a/Source/ArtifactTrackerDLL/src/EventListener.cpp b/Source/ArtifactTrackerDLL/src/EventListener.cpp index 2b8c8e5..bcaa1c0 100644 --- a/Source/ArtifactTrackerDLL/src/EventListener.cpp +++ b/Source/ArtifactTrackerDLL/src/EventListener.cpp @@ -33,7 +33,14 @@ auto EventListener::ProcessEvent( RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { + // Fires on every cell change, loaded or not. + // If it's new and not loaded, we can't add a new cell storage. + // In this case, it registers TESCellFullyLoadedEvent, which ensures a new ref can be added. if (a_event->flags == RE::BGSActorCellEvent::CellFlag::kEnter) { + #ifdef _DEBUG + SKSE::log::info("BGSActorCellEvent"); + #endif + ArtifactTracker::OnCellEnter(a_event->cellID); } @@ -59,7 +66,11 @@ auto EventListener::ProcessEvent( RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { + // This listener is expected to be unregistered outside of home. if (ArtifactTracker::IsHome() && a_event->menuName == "ContainerMenu") { + #ifdef _DEBUG + SKSE::log::info("MenuOpenCloseEvent"); + #endif ArtifactTracker::SetContainerMode(a_event->opening); } diff --git a/Source/ArtifactTrackerDLL/src/Main.cpp b/Source/ArtifactTrackerDLL/src/Main.cpp index 02d22c2..b1760cb 100644 --- a/Source/ArtifactTrackerDLL/src/Main.cpp +++ b/Source/ArtifactTrackerDLL/src/Main.cpp @@ -1,7 +1,6 @@ #include "Papyrus.h" #include "ArtifactTracker.h" -using namespace ArtifactTracker; using namespace RE::BSScript; using namespace SKSE; using namespace SKSE::log;