diff --git a/include/SFSE/API.h b/include/SFSE/API.h index f4a49d22..2a01d466 100644 --- a/include/SFSE/API.h +++ b/include/SFSE/API.h @@ -17,14 +17,15 @@ namespace SFSE void RegisterForAPIInitEvent(const std::function& a_fn); + std::string_view GetPluginName() noexcept; + std::string_view GetPluginAuthor() noexcept; + REL::Version GetPluginVersion() noexcept; + PluginHandle GetPluginHandle() noexcept; const TrampolineInterface* GetTrampolineInterface() noexcept; - const MessagingInterface* GetMessagingInterface() noexcept; - const MenuInterface* GetMenuInterface() noexcept; - const TaskInterface* GetTaskInterface() noexcept; Trampoline& GetTrampoline(); diff --git a/src/SFSE/API.cpp b/src/SFSE/API.cpp index a1b47636..d3ceb5a1 100644 --- a/src/SFSE/API.cpp +++ b/src/SFSE/API.cpp @@ -15,6 +15,10 @@ namespace SFSE return singleton; } + std::string_view pluginName{}; + std::string_view pluginAuthor{}; + REL::Version pluginVersion{}; + PluginHandle pluginHandle{ static_cast(-1) }; TrampolineInterface* trampolineInterface{}; @@ -55,15 +59,23 @@ namespace SFSE { stl_assert(a_intfc, "interface is null"sv); - if (a_log) - log::init(); - (void)REL::Module::get(); auto& storage = detail::APIStorage::get(); const auto& intfc = *a_intfc; const std::scoped_lock l(storage.apiLock); + if (const auto pluginVersionData = PluginVersionData::GetSingleton()) { + storage.pluginName = pluginVersionData->GetPluginName(); + storage.pluginAuthor = pluginVersionData->GetAuthorName(); + storage.pluginVersion = pluginVersionData->GetPluginVersion(); + } + + if (a_log) { + log::init(); + log::info("{} v{}", GetPluginName(), GetPluginVersion()); + } + if (!storage.apiInit) { storage.pluginHandle = intfc.GetPluginHandle(); @@ -96,6 +108,21 @@ namespace SFSE a_fn(); } + 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; + } + PluginHandle GetPluginHandle() noexcept { return detail::APIStorage::get().pluginHandle; diff --git a/src/SFSE/Logger.cpp b/src/SFSE/Logger.cpp index abc02206..d5cab213 100644 --- a/src/SFSE/Logger.cpp +++ b/src/SFSE/Logger.cpp @@ -28,15 +28,14 @@ namespace SFSE::log if (!path) return; - const auto data = PluginVersionData::GetSingleton(); - *path /= std::format("{}.log", data->GetPluginName()); + *path /= std::format("{}.log", SFSE::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);