From 673d3daee663eeae525834bb82cb5f6fde2143c2 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:43:57 -0500 Subject: [PATCH 1/5] feat: make log default to true --- include/SKSE/API.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SKSE/API.h b/include/SKSE/API.h index 830307c7d..d099a7944 100644 --- a/include/SKSE/API.h +++ b/include/SKSE/API.h @@ -12,7 +12,7 @@ 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); PluginHandle GetPluginHandle() noexcept; From 2839cb701544b2794f1454fcac0449dfaec49144 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:44:33 -0500 Subject: [PATCH 2/5] fix: global logger name is case sensitive --- src/SKSE/Logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SKSE/Logger.cpp b/src/SKSE/Logger.cpp index bf3809246..ab0e99aa5 100644 --- a/src/SKSE/Logger.cpp +++ b/src/SKSE/Logger.cpp @@ -132,7 +132,7 @@ namespace SKSE 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); From c34f51e203d0881d0bdc08de44c3fd6ad9e2a2af Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:53:24 -0500 Subject: [PATCH 3/5] fix: only allow default log if 1.6.x support is enabled --- src/SKSE/API.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SKSE/API.cpp b/src/SKSE/API.cpp index 5587a9579..0a80f1096 100644 --- a/src/SKSE/API.cpp +++ b/src/SKSE/API.cpp @@ -76,7 +76,10 @@ namespace SKSE } if (a_log) { + // remove ifdef once 1.5.x support is removed +#ifdef SKYRIM_SUPPORT_AE log::init(); +#endif } (void)REL::Module::get(); From 9fe9130d9e04f7e79740566efb2dbf3df428c113 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:23:41 -0500 Subject: [PATCH 4/5] fix: support non-ae --- include/SKSE/Interfaces.h | 1 + src/SKSE/API.cpp | 4 +--- src/SKSE/Interfaces.cpp | 2 ++ src/SKSE/Logger.cpp | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) 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 0a80f1096..3ad841b85 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 @@ -76,10 +77,7 @@ namespace SKSE } if (a_log) { - // remove ifdef once 1.5.x support is removed -#ifdef SKYRIM_SUPPORT_AE log::init(); -#endif } (void)REL::Module::get(); 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 ab0e99aa5..21784b4a6 100644 --- a/src/SKSE/Logger.cpp +++ b/src/SKSE/Logger.cpp @@ -119,6 +119,8 @@ namespace SKSE void init() { + // remove ifdef if 1.5.x support is removed +#ifdef SKYRIM_SUPPORT_AE auto path = log_directory(); if (!path) { return; @@ -142,6 +144,7 @@ namespace SKSE #endif spdlog::set_default_logger(std::move(logger)); spdlog::set_pattern("[%T.%e] [%=5t] [%L] %v"); +#endif } } } From 692f213d79a2049fa7b1ad7dc46d47bf06ac8416 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:26:23 -0500 Subject: [PATCH 5/5] feat: port api helpers from commonlibf4 --- include/SKSE/API.h | 6 ++++++ src/SKSE/API.cpp | 29 +++++++++++++++++++++++++++++ src/SKSE/Logger.cpp | 3 +-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/SKSE/API.h b/include/SKSE/API.h index d099a7944..95657cba9 100644 --- a/include/SKSE/API.h +++ b/include/SKSE/API.h @@ -15,6 +15,12 @@ namespace SKSE 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/src/SKSE/API.cpp b/src/SKSE/API.cpp index 3ad841b85..ff5506187 100644 --- a/src/SKSE/API.cpp +++ b/src/SKSE/API.cpp @@ -16,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 }; @@ -87,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(); @@ -138,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/Logger.cpp b/src/SKSE/Logger.cpp index 21784b4a6..3209b4a17 100644 --- a/src/SKSE/Logger.cpp +++ b/src/SKSE/Logger.cpp @@ -126,8 +126,7 @@ namespace SKSE 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),