Skip to content

Commit

Permalink
feat: port api helpers from commonlibf4
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Sep 7, 2024
1 parent 9fe9130 commit 692f213
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/SKSE/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace SKSE
void Init(const LoadInterface* a_intfc, const bool a_log = true) noexcept;
void RegisterForAPIInitEvent(std::function<void()> 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;

Expand Down
29 changes: 29 additions & 0 deletions src/SKSE/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace SKSE
return singleton;
}

std::string_view pluginName{};
std::string_view pluginAuthor{};
REL::Version pluginVersion{};

PluginHandle pluginHandle{ static_cast<PluginHandle>(-1) };
std::uint32_t releaseIndex{ 0 };

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/SKSE/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::sink_ptr> sinks{
std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true),
Expand Down

0 comments on commit 692f213

Please sign in to comment.