From c5c70dc082aa346693261269dac038309f4061f7 Mon Sep 17 00:00:00 2001 From: DK Date: Fri, 8 Sep 2023 05:28:54 +0800 Subject: [PATCH] fix: remove leftover interfaces --- CommonLibSF/include/SFSE/Interfaces.h | 76 ++++++++------------------- CommonLibSF/src/SFSE/API.cpp | 35 ++++++------ 2 files changed, 36 insertions(+), 75 deletions(-) diff --git a/CommonLibSF/include/SFSE/Interfaces.h b/CommonLibSF/include/SFSE/Interfaces.h index 7e4cf040..f33b2ad4 100644 --- a/CommonLibSF/include/SFSE/Interfaces.h +++ b/CommonLibSF/include/SFSE/Interfaces.h @@ -23,13 +23,9 @@ namespace SFSE enum : std::uint32_t { kInvalid = 0, - kScaleform, - kPapyrus, - kSerialization, - kTask, kMessaging, - kObject, kTrampoline, + kTotal }; @@ -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 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 a_dst) noexcept + static constexpr void SetCharBuffer( + std::string_view a_src, + std::span 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); @@ -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 diff --git a/CommonLibSF/src/SFSE/API.cpp b/CommonLibSF/src/SFSE/API.cpp index ba3e0853..0f8feb20 100644 --- a/CommonLibSF/src/SFSE/API.cpp +++ b/CommonLibSF/src/SFSE/API.cpp @@ -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 T* QueryInterface(const LoadInterface* a_intfc, std::uint32_t a_id) { auto result = static_cast(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 { @@ -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(a_intfc, LoadInterface::kMessaging); storage.trampolineInterface = detail::QueryInterface(a_intfc, LoadInterface::kTrampoline); - storage.messagingInterface = detail::QueryInterface(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(); @@ -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; } @@ -120,11 +116,10 @@ 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; } @@ -132,4 +127,4 @@ namespace SFSE trampoline.create(a_size); } -} // namespace SFSE +}