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
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

Binary file not shown.

View File

@ -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<RE::FormID, RE::TESForm*> g_artifactMap;
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_listFound = dataHandler->LookupForm<RE::BGSListForm>(0x806, "Artifact Tracker.esp"); // ETR_ItemsFound
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
const auto recipeKeyword = dataHandler->LookupForm<RE::BGSKeyword>(0xF5CB0, "Skyrim.esm"); // VendorItemRecipe
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");
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<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
const auto plaqueFish = dataHandler->LookupForm<RE::BGSListForm>(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<RE::BGSKeyword>(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<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>()) {
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<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.erase(0xA); // Lockpick
g_artifactMap.erase(0xF); // Gold
for (const auto& form : dataHandler->GetFormArray<RE::AlchemyItem>()) {
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<RE::IngredientItem>()) {
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<RE::TESSoulGem>()) {
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;
}

View File

@ -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<RE::FormID, RE::TESForm*> g_artifactMap;
extern std::unordered_set<RE::FormType> g_artifactFormTypes;
@ -18,7 +17,7 @@ namespace ArtifactTracker
void Init();
void PreloadArtifactList();
void OnKeywordDistribution();
bool IsArtifact(RE::TESForm* a_item);

View File

@ -13,6 +13,19 @@ void EventListener::Install()
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(
const RE::TESContainerChangedEvent* a_event,
RE::BSTEventSource<RE::TESContainerChangedEvent>* a_eventSource)

View File

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

View File

@ -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();
}
});
}