Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove leftover interfaces #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 21 additions & 55 deletions CommonLibSF/include/SFSE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ namespace SFSE
enum : std::uint32_t
{
kInvalid = 0,
kScaleform,
kPapyrus,
kSerialization,
kTask,
kMessaging,
kObject,
kTrampoline,

kTotal
};

Expand Down Expand Up @@ -109,74 +105,44 @@ namespace SFSE
kVersion = 1,
};

constexpr void PluginVersion(std::uint32_t a_version) noexcept
{
pluginVersion = a_version;
}

constexpr void PluginName(std::string_view a_plugin) noexcept
{
SetCharBuffer(a_plugin, std::span{ pluginName });
}

constexpr void AuthorName(std::string_view a_name) noexcept
{
SetCharBuffer(a_name, std::span{ author });
}

constexpr void UsesSigScanning(bool a_value) noexcept
{
addressIndependence = !a_value;
}

constexpr void UsesAddressLibrary(bool a_value) noexcept
{
addressIndependence = a_value;
}

constexpr void HasNoStructUse(bool a_value) noexcept
{
structureCompatibility = !a_value;
}

constexpr void IsLayoutDependent(bool a_value) noexcept
{
structureCompatibility = a_value;
}

constexpr void PluginVersion(std::uint32_t a_version) noexcept { pluginVersion = a_version; }
constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); }
constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); }
constexpr void UsesSigScanning(bool a_value) noexcept { addressIndependence = !a_value; }
constexpr void UsesAddressLibrary(bool a_value) noexcept { addressIndependence = a_value; }
constexpr void HasNoStructUse(bool a_value) noexcept { structureCompatibility = !a_value; }
constexpr void IsLayoutDependent(bool a_value) noexcept { structureCompatibility = a_value; }
constexpr void CompatibleVersions(std::initializer_list<REL::Version> a_versions) noexcept
{
// must be zero-terminated
assert(a_versions.size() < std::size(compatibleVersions) - 1);
std::ranges::transform(a_versions, std::begin(compatibleVersions),
[](const REL::Version& a_version) noexcept { return a_version.pack(); });
}

constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept
{
xseMinimum = a_version.pack();
std::ranges::transform(
a_versions, std::begin(compatibleVersions),
[](const REL::Version& a_version) noexcept { return a_version.pack(); });
}
constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }

const std::uint32_t dataVersion{ kVersion };
std::uint32_t pluginVersion = 0;
std::uint32_t pluginVersion = 0;
char pluginName[256] = {};
char author[256] = {};
char author[256] = {};
std::uint32_t addressIndependence;
std::uint32_t structureCompatibility;
std::uint32_t compatibleVersions[16] = {};
std::uint32_t xseMinimum = 0;
const std::uint32_t reservedNonBreaking = 0;
const std::uint32_t reservedBreaking = 0;
std::uint32_t xseMinimum = 0;
const std::uint32_t reservedNonBreaking = 0;
const std::uint32_t reservedBreaking = 0;

private:
static constexpr void SetCharBuffer(std::string_view a_src, std::span<char> a_dst) noexcept
static constexpr void SetCharBuffer(
std::string_view a_src,
std::span<char> a_dst) noexcept
{
assert(a_src.size() < a_dst.size());
std::ranges::fill(a_dst, '\0');
std::ranges::copy(a_src, a_dst.begin());
}
};

static_assert(offsetof(PluginVersionData, dataVersion) == 0x000);
static_assert(offsetof(PluginVersionData, pluginVersion) == 0x004);
static_assert(offsetof(PluginVersionData, pluginName) == 0x008);
Expand All @@ -188,4 +154,4 @@ namespace SFSE
static_assert(offsetof(PluginVersionData, reservedNonBreaking) == 0x254);
static_assert(offsetof(PluginVersionData, reservedBreaking) == 0x258);
static_assert(sizeof(PluginVersionData) == 0x25C);
} // namespace SFSE
} // namespace SFSE
35 changes: 15 additions & 20 deletions CommonLibSF/src/SFSE/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@ namespace SFSE
bool apiInit{ false };

private:
APIStorage() noexcept = default;
APIStorage() noexcept = default;
APIStorage(const APIStorage&) = delete;
APIStorage(APIStorage&&) = delete;
APIStorage(APIStorage&&) = delete;

~APIStorage() noexcept = default;

APIStorage& operator=(const APIStorage&) = delete;
APIStorage& operator=(APIStorage&&) = delete;
APIStorage& operator=(APIStorage&&) = delete;
};

template <class T>
T* QueryInterface(const LoadInterface* a_intfc, std::uint32_t a_id)
{
auto result = static_cast<T*>(a_intfc->QueryInterface(a_id));
if (result && result->Version() > T::kVersion)
{
if (result && result->Version() > T::kVersion) {
log::warn("interface definition is out of date"sv);
}
return result;
}
} // namespace detail
}

void Init(const LoadInterface* a_intfc) noexcept
{
Expand All @@ -55,20 +54,18 @@ namespace SFSE
(void)REL::Module::get();

auto& storage = detail::APIStorage::get();
const auto& intfc = *a_intfc;
const auto& intfc = *a_intfc;

const std::scoped_lock l(storage.apiLock);
if (!storage.apiInit)
{
if (!storage.apiInit) {
storage.pluginHandle = intfc.GetPluginHandle();

storage.messagingInterface = detail::QueryInterface<MessagingInterface>(a_intfc, LoadInterface::kMessaging);
storage.trampolineInterface = detail::QueryInterface<TrampolineInterface>(a_intfc, LoadInterface::kTrampoline);
storage.messagingInterface = detail::QueryInterface<MessagingInterface>(a_intfc, LoadInterface::kMessaging);

storage.apiInit = true;
auto& regs = storage.apiInitRegs;
for (const auto& reg : regs)
{
auto& regs = storage.apiInitRegs;
for (const auto& reg : regs) {
reg();
}
regs.clear();
Expand All @@ -81,8 +78,7 @@ namespace SFSE
{
auto& storage = detail::APIStorage::get();
const std::scoped_lock l(storage.apiLock);
if (!storage.apiInit)
{
if (!storage.apiInit) {
storage.apiInitRegs.push_back(a_fn);
return;
}
Expand Down Expand Up @@ -120,16 +116,15 @@ namespace SFSE
void AllocTrampoline(std::size_t a_size, bool a_trySFSEReserve)
{
auto& trampoline = GetTrampoline();
if (auto intfc = GetTrampolineInterface(); intfc && a_trySFSEReserve)
{
if (auto intfc = GetTrampolineInterface();
intfc && a_trySFSEReserve) {
auto memory = intfc->AllocateFromBranchPool(a_size);
if (memory)
{
if (memory) {
trampoline.set_trampoline(memory, a_size);
return;
}
}

trampoline.create(a_size);
}
} // namespace SFSE
}
Loading