diff --git a/Artifact Tracker.esp b/Artifact Tracker.esp index 5d5814d..d683f8d 100644 Binary files a/Artifact Tracker.esp and b/Artifact Tracker.esp differ diff --git a/Artifact Tracker_KID.ini b/Artifact Tracker_KID.ini index eb3a348..2a3f9c3 100644 --- a/Artifact Tracker_KID.ini +++ b/Artifact Tracker_KID.ini @@ -1,8 +1,5 @@ ; DB01Plate, NordWarHorn, ImperialWarHorn, DBTortureTools, DB06OlavaToken, dunUniqueBeeInJar, dunWaywardPassSkull01, dunUniqueFireflyInJar, dunUniqueDragonflyInJar, dunUniqueButterflyInJar, dunUniqueMothInJar, DancersFlute, BalbusForkNonEquip, MS11YsgramorsSoupSpoon Keyword = ETR_ExtraArtifact|Misc Item|0x1F6D4,0x200B6,0x200BA,0x20949,0x59654,0xB08C7,0xF6767,0xFBC3A,0xFBC3B,0xFBC3C,0xFBC3D,0x105109,0x1058AA,0x105A4E -; Soul Gem Fragments -Keyword = VendorItemClutter|Misc Item|0x67181,0x67182,0x67183,0x67184,0x67185 - ; Treasure Maps Keyword = ETR_ExtraArtifact|Book|0xEF07A,0xF33CD,0xF33CE,0xF33CF,0xF33D0,0xF33D1,0xF33D2,0xF33D3,0xF33D4,0xF33D5,0xF33E0 diff --git a/SKSE/Plugins/ArtifactTracker.dll b/SKSE/Plugins/ArtifactTracker.dll index e509eb6..09492a9 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 685551d..9edb7a1 100644 --- a/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp +++ b/Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp @@ -12,7 +12,6 @@ namespace ArtifactTracker RE::BGSListForm* g_listStored; RE::BGSListForm* g_listFound; RE::BGSListForm* g_persistentStorage; - RE::BGSKeyword* g_extraArtifactKeyword; RE::BGSKeyword* g_homeKeyword; std::unordered_map g_artifactMap; std::unordered_set g_artifactFormTypes; @@ -36,14 +35,13 @@ namespace ArtifactTracker 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_extraArtifactKeyword = dataHandler->LookupForm(0xDE3FD3, "Update.esm"); // ETR_ExtraArtifact g_homeKeyword = dataHandler->LookupForm(0xFC1A3, "Skyrim.esm"); // LocTypePlayerHouse 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 || !g_extraArtifactKeyword || !recipeKeyword || !excludeKeywords) { + 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"); RE::DebugMessageBox("Failed to load data from Artifact Tracker.esp, the mod is disabled."); return; @@ -73,6 +71,15 @@ namespace ArtifactTracker } } + g_artifactFormTypes.insert(RE::FormType::Misc); + for (const auto& form : dataHandler->GetFormArray()) { + if (form->GetPlayable() && !form->HasKeywordInList(excludeKeywords, false)) { + g_artifactMap[form->formID] = form; + } + } + g_artifactMap.erase(0xA); // Lockpick + g_artifactMap.erase(0xF); // Gold + // Fishing CC const auto plaqueFish = dataHandler->LookupForm(0xF4B, "ccBGSSSE001-Fish.esm"); // ccBGSSSE001_FishPlaqueGiftFilterList if (plaqueFish) { @@ -84,55 +91,52 @@ namespace ArtifactTracker OnGameLoad(); EventListener::Install(); + + g_bLoaded = true; } - void PreloadArtifactList() + void OnKeywordDistribution() { - if (g_bLoaded) { + const auto dataHandler = RE::TESDataHandler::GetSingleton(); + const auto extraArtifactKeyword = dataHandler->LookupForm(0xDE3FD3, "Update.esm"); // ETR_ExtraArtifact + + if (!dataHandler || !extraArtifactKeyword) { + SKSE::log::error("Unable to load ETR_ExtraArtifact in OnKeywordDistribution"); return; } - const auto dataHandler = RE::TESDataHandler::GetSingleton(); - const auto recipeKeyword = dataHandler->LookupForm(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe - const auto excludeKeywords = dataHandler->LookupForm(0x801, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords - for (const auto& form : dataHandler->GetFormArray()) { - if (form->HasKeyword(g_extraArtifactKeyword)) { + if (form->HasKeyword(extraArtifactKeyword)) { g_artifactMap[form->formID] = form; } } - g_artifactFormTypes.insert(RE::FormType::Misc); for (const auto& form : dataHandler->GetFormArray()) { - if (form->GetPlayable() && (form->HasKeyword(g_extraArtifactKeyword) || !form->HasKeywordInList(excludeKeywords, false))) { + if (form->GetPlayable() && form->HasKeyword(extraArtifactKeyword)) { g_artifactMap[form->formID] = form; } } - g_artifactMap.erase(0xA); // Lockpick - g_artifactMap.erase(0xF); // Gold for (const auto& form : dataHandler->GetFormArray()) { - if (form->HasKeyword(g_extraArtifactKeyword)) { + if (form->HasKeyword(extraArtifactKeyword)) { g_artifactMap[form->formID] = form; g_artifactFormTypes.insert(RE::FormType::AlchemyItem); } } for (const auto& form : dataHandler->GetFormArray()) { - if (form->HasKeyword(g_extraArtifactKeyword)) { + if (form->HasKeyword(extraArtifactKeyword)) { g_artifactMap[form->formID] = form; g_artifactFormTypes.insert(RE::FormType::Ingredient); } } for (const auto& form : dataHandler->GetFormArray()) { - if (form->HasKeyword(g_extraArtifactKeyword)) { + if (form->HasKeyword(extraArtifactKeyword)) { g_artifactMap[form->formID] = form; g_artifactFormTypes.insert(RE::FormType::SoulGem); } } - - g_bLoaded = true; } bool IsArtifact(RE::TESForm* a_form) @@ -418,7 +422,7 @@ namespace ArtifactTracker return; } - } else if (g_cellStorage) { + } else if (g_cellStorage && !g_listNew->HasForm(form)) { // Items picked up at home are handled in the perk return; } diff --git a/Source/ArtifactTrackerDLL/src/ArtifactTracker.h b/Source/ArtifactTrackerDLL/src/ArtifactTracker.h index 25b9cc5..2a88d68 100644 --- a/Source/ArtifactTrackerDLL/src/ArtifactTracker.h +++ b/Source/ArtifactTrackerDLL/src/ArtifactTracker.h @@ -9,7 +9,6 @@ namespace ArtifactTracker extern RE::BGSListForm* g_listStored; extern RE::BGSListForm* g_listFound; extern RE::BGSListForm* g_persistentStorage; - extern RE::BGSKeyword* g_extraArtifactKeyword; extern RE::BGSKeyword* g_homeKeyword; extern std::unordered_map g_artifactMap; extern std::unordered_set g_artifactFormTypes; @@ -18,7 +17,7 @@ namespace ArtifactTracker void Init(); - void PreloadArtifactList(); + void OnKeywordDistribution(); bool IsArtifact(RE::TESForm* a_item); diff --git a/Source/ArtifactTrackerDLL/src/EventListener.cpp b/Source/ArtifactTrackerDLL/src/EventListener.cpp index bcaa1c0..f10af6e 100644 --- a/Source/ArtifactTrackerDLL/src/EventListener.cpp +++ b/Source/ArtifactTrackerDLL/src/EventListener.cpp @@ -13,6 +13,19 @@ void EventListener::Install() RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink(EventListener::GetSingleton()); } +auto EventListener::ProcessEvent( + const SKSE::ModCallbackEvent* a_event, + RE::BSTEventSource* a_eventSource) + -> RE::BSEventNotifyControl +{ + if (a_event->eventName == "KID_KeywordDistributionDone") { + SKSE::GetModCallbackEventSource()->RemoveEventSink(EventListener::GetSingleton()); + ArtifactTracker::OnKeywordDistribution(); + } + + return RE::BSEventNotifyControl::kContinue; +} + auto EventListener::ProcessEvent( const RE::TESContainerChangedEvent* a_event, RE::BSTEventSource* a_eventSource) diff --git a/Source/ArtifactTrackerDLL/src/EventListener.h b/Source/ArtifactTrackerDLL/src/EventListener.h index 8b1f0a4..e155efc 100644 --- a/Source/ArtifactTrackerDLL/src/EventListener.h +++ b/Source/ArtifactTrackerDLL/src/EventListener.h @@ -1,6 +1,7 @@ #pragma once class EventListener : + public RE::BSTEventSink, public RE::BSTEventSink, public RE::BSTEventSink, public RE::BSTEventSink, @@ -35,6 +36,11 @@ public: const RE::MenuOpenCloseEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl override; + + auto ProcessEvent( + const SKSE::ModCallbackEvent* a_event, + RE::BSTEventSource* a_eventSource) + -> RE::BSEventNotifyControl override; private: EventListener() = default; diff --git a/Source/ArtifactTrackerDLL/src/Main.cpp b/Source/ArtifactTrackerDLL/src/Main.cpp index 6208df6..70f881c 100644 --- a/Source/ArtifactTrackerDLL/src/Main.cpp +++ b/Source/ArtifactTrackerDLL/src/Main.cpp @@ -1,5 +1,6 @@ #include "Papyrus.h" #include "ArtifactTracker.h" +#include "EventListener.h" using namespace SKSE; using namespace SKSE::log; @@ -28,12 +29,14 @@ namespace { void InitializeMessaging() { GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) { - if (message->type == MessagingInterface::kDataLoaded) { + + if (message->type == MessagingInterface::kPostPostLoad) { + SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton()); + } else if (message->type == MessagingInterface::kDataLoaded) { ArtifactTracker::Init(); } else if (message->type == MessagingInterface::kPostLoadGame) { + SKSE::GetModCallbackEventSource()->RemoveEventSink(EventListener::GetSingleton()); ArtifactTracker::OnGameLoad(); - } else if (message->type == MessagingInterface::kNewGame || message->type == MessagingInterface::kPreLoadGame) { - ArtifactTracker::PreloadArtifactList(); } }); }