Skip to content

Commit

Permalink
Merge pull request #133 from qudix/devex
Browse files Browse the repository at this point in the history
feat: misc
  • Loading branch information
powerof3 authored Sep 7, 2024
2 parents 8a38010 + 692f213 commit acfe77f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
8 changes: 7 additions & 1 deletion include/SKSE/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
1 change: 1 addition & 0 deletions include/SKSE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ namespace SKSE
const char* name;
std::uint32_t version;
};

#ifdef SKYRIM_SUPPORT_AE
struct PluginVersionData
{
Expand Down
30 changes: 30 additions & 0 deletions src/SKSE/API.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SKSE/API.h"

#include "SKSE/Interfaces.h"
#include "SKSE/Logger.h"

namespace SKSE
Expand All @@ -15,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 @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/SKSE/Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ namespace SKSE
return reinterpret_cast<const detail::SKSETrampolineInterface*>(this);
}

#ifdef SKYRIM_SUPPORT_AE
const PluginVersionData* PluginVersionData::GetSingleton() noexcept
{
return reinterpret_cast<const PluginVersionData*>(REX::W32::GetProcAddress(REX::W32::GetCurrentModule(), "SKSEPlugin_Version"));
}
#endif
}
8 changes: 5 additions & 3 deletions src/SKSE/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::sink_ptr> sinks{
std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true),
std::make_shared<spdlog::sinks::msvc_sink_mt>()
};

auto logger = std::make_shared<spdlog::logger>("Global", sinks.begin(), sinks.end());
auto logger = std::make_shared<spdlog::logger>("global", sinks.begin(), sinks.end());
#ifndef NDEBUG
logger->set_level(spdlog::level::debug);
logger->flush_on(spdlog::level::debug);
Expand All @@ -142,6 +143,7 @@ namespace SKSE
#endif
spdlog::set_default_logger(std::move(logger));
spdlog::set_pattern("[%T.%e] [%=5t] [%L] %v");
#endif
}
}
}

0 comments on commit acfe77f

Please sign in to comment.