#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()); } else if (message->type == MessagingInterface::kNewGame || message->type == MessagingInterface::kPreLoadGame) { ArtifactTracker::Init(); // if KID is not installed } else if (message->type == MessagingInterface::kPostLoadGame) { ArtifactTracker::OnGameLoad(); // refresh g_persistentMap from savegame } }); } } 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; }