#include "ArtifactTracker.h" #include "EventListener.h" using namespace SKSE; using namespace SKSE::log; using namespace SKSE::stl; namespace { void InitializeLogging() { auto path = logger::log_directory(); if (!path) { stl::report_and_fail("Failed to find standard logging directory"sv); } *path /= "ArtifactTracker.log"sv; auto sink = std::make_shared(path->string(), true); auto log = std::make_shared("global log"s, std::move(sink)); log->set_level(spdlog::level::info); log->flush_on(spdlog::level::info); spdlog::set_default_logger(std::move(log)); spdlog::set_pattern("[%l] %v"s); } void InitializeMessaging() { GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) { if (message->type == MessagingInterface::kPostLoad) { SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton()); // runs, if KID is installed } else if (message->type == MessagingInterface::kDataLoaded) { if (const auto pluginInfo = ArtifactTracker::g_loadInterface->GetPluginInfo("po3_KeywordItemDistributor"); !pluginInfo) { ArtifactTracker::Init(); // if KID is not installed } } else if (message->type == MessagingInterface::kPreLoadGame) { ArtifactTracker::g_bSaveLoaded = false; // block cell load events } else if (message->type == MessagingInterface::kPostLoadGame) { SKSE::GetTaskInterface()->AddTask([]() { ArtifactTracker::OnGameLoad(); // save-specific updates ArtifactTracker::g_bSaveLoaded = true; const auto cell = RE::PlayerCharacter::GetSingleton()->GetParentCell(); ArtifactTracker::OnCellEnter(cell->GetLocation(), cell); }); } }); } } SKSEPluginLoad(const LoadInterface* skse) { InitializeLogging(); auto* plugin = PluginDeclaration::GetSingleton(); auto version = plugin->GetVersion(); log::info("{} {} is loading...", plugin->GetName(), version); Init(skse); InitializeMessaging(); ArtifactTracker::g_loadInterface = skse; log::info("{} has finished loading.", plugin->GetName()); return true; }