diff --git a/include/SKSE/API.h b/include/SKSE/API.h index 830307c7d..95657cba9 100644 --- a/include/SKSE/API.h +++ b/include/SKSE/API.h @@ -12,9 +12,15 @@ namespace SKSE { - void Init(const LoadInterface* a_intfc, const bool a_log = false) noexcept; + void Init(const LoadInterface* a_intfc, const bool a_log = true) noexcept; void RegisterForAPIInitEvent(std::function a_fn); +#ifdef SKYRIM_SUPPORT_AE + std::string_view GetPluginName() noexcept; + std::string_view GetPluginAuthor() noexcept; + REL::Version GetPluginVersion() noexcept; +#endif + PluginHandle GetPluginHandle() noexcept; std::uint32_t GetReleaseIndex() noexcept; diff --git a/include/SKSE/Interfaces.h b/include/SKSE/Interfaces.h index 4a1086ad4..a204360cf 100644 --- a/include/SKSE/Interfaces.h +++ b/include/SKSE/Interfaces.h @@ -360,6 +360,7 @@ namespace SKSE const char* name; std::uint32_t version; }; + #ifdef SKYRIM_SUPPORT_AE struct PluginVersionData { diff --git a/src/SKSE/API.cpp b/src/SKSE/API.cpp index 5587a9579..ff5506187 100644 --- a/src/SKSE/API.cpp +++ b/src/SKSE/API.cpp @@ -1,5 +1,6 @@ #include "SKSE/API.h" +#include "SKSE/Interfaces.h" #include "SKSE/Logger.h" namespace SKSE @@ -15,6 +16,10 @@ namespace SKSE return singleton; } + std::string_view pluginName{}; + std::string_view pluginAuthor{}; + REL::Version pluginVersion{}; + PluginHandle pluginHandle{ static_cast(-1) }; std::uint32_t releaseIndex{ 0 }; @@ -86,6 +91,14 @@ namespace SKSE const auto& intfc = *a_intfc; const std::scoped_lock l(storage.apiLock); +#ifdef SKYRIM_SUPPORT_AE + if (const auto pluginVersionData = PluginVersionData::GetSingleton()) { + storage.pluginName = pluginVersionData->GetPluginName(); + storage.pluginAuthor = pluginVersionData->GetAuthorName(); + storage.pluginVersion = pluginVersionData->GetPluginVersion(); + } +#endif + if (!storage.apiInit) { storage.pluginHandle = intfc.GetPluginHandle(); storage.releaseIndex = intfc.GetReleaseIndex(); @@ -137,6 +150,23 @@ namespace SKSE a_fn(); } +#ifdef SKYRIM_SUPPORT_AE + std::string_view GetPluginName() noexcept + { + return detail::APIStorage::get().pluginName; + } + + std::string_view GetPluginAuthor() noexcept + { + return detail::APIStorage::get().pluginAuthor; + } + + REL::Version GetPluginVersion() noexcept + { + return detail::APIStorage::get().pluginVersion; + } +#endif + PluginHandle GetPluginHandle() noexcept { return detail::APIStorage::get().pluginHandle; diff --git a/src/SKSE/Interfaces.cpp b/src/SKSE/Interfaces.cpp index 6cf961398..0308c34ac 100644 --- a/src/SKSE/Interfaces.cpp +++ b/src/SKSE/Interfaces.cpp @@ -342,8 +342,10 @@ namespace SKSE return reinterpret_cast(this); } +#ifdef SKYRIM_SUPPORT_AE const PluginVersionData* PluginVersionData::GetSingleton() noexcept { return reinterpret_cast(REX::W32::GetProcAddress(REX::W32::GetCurrentModule(), "SKSEPlugin_Version")); } +#endif } diff --git a/src/SKSE/Logger.cpp b/src/SKSE/Logger.cpp index bf3809246..3209b4a17 100644 --- a/src/SKSE/Logger.cpp +++ b/src/SKSE/Logger.cpp @@ -119,20 +119,21 @@ namespace SKSE void init() { + // remove ifdef if 1.5.x support is removed +#ifdef SKYRIM_SUPPORT_AE auto path = log_directory(); if (!path) { return; } - const auto data = PluginVersionData::GetSingleton(); - *path /= std::format("{}.log", data->GetPluginName()); + *path /= std::format("{}.log", SKSE::GetPluginName()); std::vector sinks{ std::make_shared(path->string(), true), std::make_shared() }; - auto logger = std::make_shared("Global", sinks.begin(), sinks.end()); + auto logger = std::make_shared("global", sinks.begin(), sinks.end()); #ifndef NDEBUG logger->set_level(spdlog::level::debug); logger->flush_on(spdlog::level::debug); @@ -142,6 +143,7 @@ namespace SKSE #endif spdlog::set_default_logger(std::move(logger)); spdlog::set_pattern("[%T.%e] [%=5t] [%L] %v"); +#endif } } }