1

Use SKSE::GetModCallbackEventSource() to receive the distribution event from KID

This commit is contained in:
Eddoursul 2022-07-03 13:58:41 +02:00
parent 550a185083
commit a3cdd32cae
8 changed files with 50 additions and 28 deletions

Binary file not shown.

View File

@ -1,8 +1,5 @@
; DB01Plate, NordWarHorn, ImperialWarHorn, DBTortureTools, DB06OlavaToken, dunUniqueBeeInJar, dunWaywardPassSkull01, dunUniqueFireflyInJar, dunUniqueDragonflyInJar, dunUniqueButterflyInJar, dunUniqueMothInJar, DancersFlute, BalbusForkNonEquip, MS11YsgramorsSoupSpoon ; 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 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 ; Treasure Maps
Keyword = ETR_ExtraArtifact|Book|0xEF07A,0xF33CD,0xF33CE,0xF33CF,0xF33D0,0xF33D1,0xF33D2,0xF33D3,0xF33D4,0xF33D5,0xF33E0 Keyword = ETR_ExtraArtifact|Book|0xEF07A,0xF33CD,0xF33CE,0xF33CF,0xF33D0,0xF33D1,0xF33D2,0xF33D3,0xF33D4,0xF33D5,0xF33E0

Binary file not shown.

View File

@ -12,7 +12,6 @@ namespace ArtifactTracker
RE::BGSListForm* g_listStored; RE::BGSListForm* g_listStored;
RE::BGSListForm* g_listFound; RE::BGSListForm* g_listFound;
RE::BGSListForm* g_persistentStorage; RE::BGSListForm* g_persistentStorage;
RE::BGSKeyword* g_extraArtifactKeyword;
RE::BGSKeyword* g_homeKeyword; RE::BGSKeyword* g_homeKeyword;
std::unordered_map<RE::FormID, RE::TESForm*> g_artifactMap; std::unordered_map<RE::FormID, RE::TESForm*> g_artifactMap;
std::unordered_set<RE::FormType> g_artifactFormTypes; std::unordered_set<RE::FormType> g_artifactFormTypes;
@ -36,14 +35,13 @@ namespace ArtifactTracker
g_listStored = dataHandler->LookupForm<RE::BGSListForm>(0x805, "Artifact Tracker.esp"); // ETR_ItemsStored g_listStored = dataHandler->LookupForm<RE::BGSListForm>(0x805, "Artifact Tracker.esp"); // ETR_ItemsStored
g_listFound = dataHandler->LookupForm<RE::BGSListForm>(0x806, "Artifact Tracker.esp"); // ETR_ItemsFound g_listFound = dataHandler->LookupForm<RE::BGSListForm>(0x806, "Artifact Tracker.esp"); // ETR_ItemsFound
g_persistentStorage = dataHandler->LookupForm<RE::BGSListForm>(0x807, "Artifact Tracker.esp"); // ETR_PersistentStorageList g_persistentStorage = dataHandler->LookupForm<RE::BGSListForm>(0x807, "Artifact Tracker.esp"); // ETR_PersistentStorageList
g_extraArtifactKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xDE3FD3, "Update.esm"); // ETR_ExtraArtifact
g_homeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xFC1A3, "Skyrim.esm"); // LocTypePlayerHouse g_homeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xFC1A3, "Skyrim.esm"); // LocTypePlayerHouse
const auto recipeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe const auto recipeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe
const auto excludeKeywords = dataHandler->LookupForm<RE::BGSListForm>(0x801, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords const auto excludeKeywords = dataHandler->LookupForm<RE::BGSListForm>(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"); 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."); RE::DebugMessageBox("Failed to load data from Artifact Tracker.esp, the mod is disabled.");
return; return;
@ -73,6 +71,15 @@ namespace ArtifactTracker
} }
} }
g_artifactFormTypes.insert(RE::FormType::Misc);
for (const auto& form : dataHandler->GetFormArray<RE::TESObjectMISC>()) {
if (form->GetPlayable() && !form->HasKeywordInList(excludeKeywords, false)) {
g_artifactMap[form->formID] = form;
}
}
g_artifactMap.erase(0xA); // Lockpick
g_artifactMap.erase(0xF); // Gold
// Fishing CC // Fishing CC
const auto plaqueFish = dataHandler->LookupForm<RE::BGSListForm>(0xF4B, "ccBGSSSE001-Fish.esm"); // ccBGSSSE001_FishPlaqueGiftFilterList const auto plaqueFish = dataHandler->LookupForm<RE::BGSListForm>(0xF4B, "ccBGSSSE001-Fish.esm"); // ccBGSSSE001_FishPlaqueGiftFilterList
if (plaqueFish) { if (plaqueFish) {
@ -84,55 +91,52 @@ namespace ArtifactTracker
OnGameLoad(); OnGameLoad();
EventListener::Install(); EventListener::Install();
g_bLoaded = true;
} }
void PreloadArtifactList() void OnKeywordDistribution()
{ {
if (g_bLoaded) { const auto dataHandler = RE::TESDataHandler::GetSingleton();
const auto extraArtifactKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xDE3FD3, "Update.esm"); // ETR_ExtraArtifact
if (!dataHandler || !extraArtifactKeyword) {
SKSE::log::error("Unable to load ETR_ExtraArtifact in OnKeywordDistribution");
return; return;
} }
const auto dataHandler = RE::TESDataHandler::GetSingleton();
const auto recipeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe
const auto excludeKeywords = dataHandler->LookupForm<RE::BGSListForm>(0x801, "Artifact Tracker.esp"); // ETR_ExcludeMiscKeywords
for (const auto& form : dataHandler->GetFormArray<RE::TESObjectBOOK>()) { for (const auto& form : dataHandler->GetFormArray<RE::TESObjectBOOK>()) {
if (form->HasKeyword(g_extraArtifactKeyword)) { if (form->HasKeyword(extraArtifactKeyword)) {
g_artifactMap[form->formID] = form; g_artifactMap[form->formID] = form;
} }
} }
g_artifactFormTypes.insert(RE::FormType::Misc);
for (const auto& form : dataHandler->GetFormArray<RE::TESObjectMISC>()) { for (const auto& form : dataHandler->GetFormArray<RE::TESObjectMISC>()) {
if (form->GetPlayable() && (form->HasKeyword(g_extraArtifactKeyword) || !form->HasKeywordInList(excludeKeywords, false))) { if (form->GetPlayable() && form->HasKeyword(extraArtifactKeyword)) {
g_artifactMap[form->formID] = form; g_artifactMap[form->formID] = form;
} }
} }
g_artifactMap.erase(0xA); // Lockpick
g_artifactMap.erase(0xF); // Gold
for (const auto& form : dataHandler->GetFormArray<RE::AlchemyItem>()) { for (const auto& form : dataHandler->GetFormArray<RE::AlchemyItem>()) {
if (form->HasKeyword(g_extraArtifactKeyword)) { if (form->HasKeyword(extraArtifactKeyword)) {
g_artifactMap[form->formID] = form; g_artifactMap[form->formID] = form;
g_artifactFormTypes.insert(RE::FormType::AlchemyItem); g_artifactFormTypes.insert(RE::FormType::AlchemyItem);
} }
} }
for (const auto& form : dataHandler->GetFormArray<RE::IngredientItem>()) { for (const auto& form : dataHandler->GetFormArray<RE::IngredientItem>()) {
if (form->HasKeyword(g_extraArtifactKeyword)) { if (form->HasKeyword(extraArtifactKeyword)) {
g_artifactMap[form->formID] = form; g_artifactMap[form->formID] = form;
g_artifactFormTypes.insert(RE::FormType::Ingredient); g_artifactFormTypes.insert(RE::FormType::Ingredient);
} }
} }
for (const auto& form : dataHandler->GetFormArray<RE::TESSoulGem>()) { for (const auto& form : dataHandler->GetFormArray<RE::TESSoulGem>()) {
if (form->HasKeyword(g_extraArtifactKeyword)) { if (form->HasKeyword(extraArtifactKeyword)) {
g_artifactMap[form->formID] = form; g_artifactMap[form->formID] = form;
g_artifactFormTypes.insert(RE::FormType::SoulGem); g_artifactFormTypes.insert(RE::FormType::SoulGem);
} }
} }
g_bLoaded = true;
} }
bool IsArtifact(RE::TESForm* a_form) bool IsArtifact(RE::TESForm* a_form)
@ -418,7 +422,7 @@ namespace ArtifactTracker
return; return;
} }
} else if (g_cellStorage) { } else if (g_cellStorage && !g_listNew->HasForm(form)) {
// Items picked up at home are handled in the perk // Items picked up at home are handled in the perk
return; return;
} }

View File

@ -9,7 +9,6 @@ namespace ArtifactTracker
extern RE::BGSListForm* g_listStored; extern RE::BGSListForm* g_listStored;
extern RE::BGSListForm* g_listFound; extern RE::BGSListForm* g_listFound;
extern RE::BGSListForm* g_persistentStorage; extern RE::BGSListForm* g_persistentStorage;
extern RE::BGSKeyword* g_extraArtifactKeyword;
extern RE::BGSKeyword* g_homeKeyword; extern RE::BGSKeyword* g_homeKeyword;
extern std::unordered_map<RE::FormID, RE::TESForm*> g_artifactMap; extern std::unordered_map<RE::FormID, RE::TESForm*> g_artifactMap;
extern std::unordered_set<RE::FormType> g_artifactFormTypes; extern std::unordered_set<RE::FormType> g_artifactFormTypes;
@ -18,7 +17,7 @@ namespace ArtifactTracker
void Init(); void Init();
void PreloadArtifactList(); void OnKeywordDistribution();
bool IsArtifact(RE::TESForm* a_item); bool IsArtifact(RE::TESForm* a_item);

View File

@ -13,6 +13,19 @@ void EventListener::Install()
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton()); RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton());
} }
auto EventListener::ProcessEvent(
const SKSE::ModCallbackEvent* a_event,
RE::BSTEventSource<SKSE::ModCallbackEvent>* a_eventSource)
-> RE::BSEventNotifyControl
{
if (a_event->eventName == "KID_KeywordDistributionDone") {
SKSE::GetModCallbackEventSource()->RemoveEventSink(EventListener::GetSingleton());
ArtifactTracker::OnKeywordDistribution();
}
return RE::BSEventNotifyControl::kContinue;
}
auto EventListener::ProcessEvent( auto EventListener::ProcessEvent(
const RE::TESContainerChangedEvent* a_event, const RE::TESContainerChangedEvent* a_event,
RE::BSTEventSource<RE::TESContainerChangedEvent>* a_eventSource) RE::BSTEventSource<RE::TESContainerChangedEvent>* a_eventSource)

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
class EventListener : class EventListener :
public RE::BSTEventSink<SKSE::ModCallbackEvent>,
public RE::BSTEventSink<RE::TESContainerChangedEvent>, public RE::BSTEventSink<RE::TESContainerChangedEvent>,
public RE::BSTEventSink<RE::TESCellFullyLoadedEvent>, public RE::BSTEventSink<RE::TESCellFullyLoadedEvent>,
public RE::BSTEventSink<RE::BGSActorCellEvent>, public RE::BSTEventSink<RE::BGSActorCellEvent>,
@ -36,6 +37,11 @@ public:
RE::BSTEventSource<RE::MenuOpenCloseEvent>* a_eventSource) RE::BSTEventSource<RE::MenuOpenCloseEvent>* a_eventSource)
-> RE::BSEventNotifyControl override; -> RE::BSEventNotifyControl override;
auto ProcessEvent(
const SKSE::ModCallbackEvent* a_event,
RE::BSTEventSource<SKSE::ModCallbackEvent>* a_eventSource)
-> RE::BSEventNotifyControl override;
private: private:
EventListener() = default; EventListener() = default;
}; };

View File

@ -1,5 +1,6 @@
#include "Papyrus.h" #include "Papyrus.h"
#include "ArtifactTracker.h" #include "ArtifactTracker.h"
#include "EventListener.h"
using namespace SKSE; using namespace SKSE;
using namespace SKSE::log; using namespace SKSE::log;
@ -28,12 +29,14 @@ namespace {
void InitializeMessaging() void InitializeMessaging()
{ {
GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) { 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(); ArtifactTracker::Init();
} else if (message->type == MessagingInterface::kPostLoadGame) { } else if (message->type == MessagingInterface::kPostLoadGame) {
SKSE::GetModCallbackEventSource()->RemoveEventSink(EventListener::GetSingleton());
ArtifactTracker::OnGameLoad(); ArtifactTracker::OnGameLoad();
} else if (message->type == MessagingInterface::kNewGame || message->type == MessagingInterface::kPreLoadGame) {
ArtifactTracker::PreloadArtifactList();
} }
}); });
} }