generated from Ryan-rsm-McKenzie/ExamplePlugin-CommonLibSSE
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
100 lines (81 loc) · 2.32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "Data.h"
#include "Listeners/Hooks.h"
namespace
{
void InitializeLog()
{
#ifndef NDEBUG
auto sink = std::make_shared<spdlog::sinks::msvc_sink_mt>();
#else
auto path = logger::log_directory();
if (!path) {
util::report_and_fail("Failed to find standard logging directory"sv);
}
*path /= fmt::format("{}.log"sv, Plugin::NAME);
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
#endif
#ifndef NDEBUG
const auto level = spdlog::level::trace;
#else
const auto level = spdlog::level::info;
#endif
auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink));
log->set_level(level);
log->flush_on(level);
spdlog::set_default_logger(std::move(log));
spdlog::set_pattern("%g(%#): [%^%l%$] %v"s);
}
void MessageHandler(SKSE::MessagingInterface::Message* a_msg)
{
switch (a_msg->type) {
case SKSE::MessagingInterface::kDataLoaded:
Data::Initialize();
break;
case SKSE::MessagingInterface::kNewGame:
case SKSE::MessagingInterface::kPostLoadGame:
Hooks::Initialize();
break;
}
}
}
#ifdef VERSION_SE
extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Query(const SKSE::QueryInterface* a_skse, SKSE::PluginInfo* a_info)
{
a_info->infoVersion = SKSE::PluginInfo::kVersion;
a_info->name = Plugin::NAME.data();
a_info->version = Plugin::VERSION[0];
if (a_skse->IsEditor()) {
logger::critical("Loaded in editor, marking as incompatible"sv);
return false;
}
const auto ver = a_skse->RuntimeVersion();
if (ver < SKSE::RUNTIME_1_5_39) {
logger::critical(FMT_STRING("Unsupported runtime version {}"sv), ver.string());
return false;
}
return true;
}
#else
extern "C" DLLEXPORT constinit auto SKSEPlugin_Version = []() {
SKSE::PluginVersionData v;
v.PluginVersion(Plugin::VERSION);
v.PluginName(Plugin::NAME);
v.UsesAddressLibrary(true);
v.CompatibleVersions({ SKSE::RUNTIME_LATEST });
return v;
}();
#endif
extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Load(const SKSE::LoadInterface* a_skse)
{
#ifndef NDEBUG
while (!IsDebuggerPresent()) Sleep(10);
Sleep(3000);
#endif
InitializeLog();
logger::info("{} v{}"sv, Plugin::NAME, Plugin::VERSION.string());
SKSE::Init(a_skse);
auto message_interface = SKSE::GetMessagingInterface();
if (!message_interface->RegisterListener(MessageHandler)) return false;
Hooks::Install();
return true;
}