71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
#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 /= PluginDeclaration::GetSingleton()->GetName();
|
|
*path += ".log"sv;
|
|
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
|
|
|
|
auto log = std::make_shared<spdlog::logger>("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::kDataLoaded) {
|
|
const auto kidSE = ArtifactTracker::g_loadInterface->GetPluginInfo("po3_KeywordItemDistributor");
|
|
const auto kidAE = ArtifactTracker::g_loadInterface->GetPluginInfo("Keyword Item Distributor"); // KID 2.0 for AE has a different internal name
|
|
if (!kidSE && !kidAE) {
|
|
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 && message->data) {
|
|
const auto cell = RE::PlayerCharacter::GetSingleton()->GetParentCell();
|
|
if (cell) {
|
|
SKSE::GetTaskInterface()->AddTask([cell]() {
|
|
ArtifactTracker::OnGameLoad(); // save-specific updates
|
|
ArtifactTracker::g_bSaveLoaded = true;
|
|
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;
|
|
|
|
SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton()); // runs when KID is installed
|
|
|
|
log::info("{} has finished loading.", plugin->GetName());
|
|
return true;
|
|
}
|