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

feat!: make plugin version return Version instead #129

Merged
merged 5 commits into from
Oct 1, 2023
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
19 changes: 17 additions & 2 deletions CommonLibSF/include/REL/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace REL
[[nodiscard]] constexpr value_type patch() const noexcept { return _impl[2]; }
[[nodiscard]] constexpr value_type build() const noexcept { return _impl[3]; }

[[nodiscard]] std::string string(std::string_view a_separator = "-"sv) const
[[nodiscard]] std::string string(std::string_view a_separator = "."sv) const
{
std::string result;
for (auto&& ver : _impl) {
Expand All @@ -66,7 +66,7 @@ namespace REL
return result;
}

[[nodiscard]] std::wstring wstring(std::wstring_view a_separator = L"-"sv) const
[[nodiscard]] std::wstring wstring(std::wstring_view a_separator = L"."sv) const
{
std::wstring result;
for (auto&& ver : _impl) {
Expand Down Expand Up @@ -147,3 +147,18 @@ namespace REL

[[nodiscard]] std::optional<Version> get_file_version(stl::zwstring a_filename);
}

#ifdef __cpp_lib_format
namespace std
{
template<class CharT>
struct formatter<REL::Version, CharT> : formatter<std::string, CharT>
{
template<class FormatContext>
auto format(const REL::Version a_version, FormatContext& a_ctx) const
{
return formatter<std::string, CharT>::format(a_version.string(), a_ctx);
}
};
}
#endif
21 changes: 10 additions & 11 deletions CommonLibSF/include/SFSE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ namespace SFSE
kVersion = 1
};

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

constexpr void PluginVersion(REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }

[[nodiscard]] constexpr std::uint32_t GetPluginVersion() const noexcept { return pluginVersion; }
[[nodiscard]] constexpr REL::Version GetPluginVersion() const noexcept { return REL::Version::unpack(pluginVersion); }

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

Expand All @@ -143,19 +141,22 @@ namespace SFSE

[[nodiscard]] constexpr std::string_view GetAuthorName() const noexcept { return std::string_view{ author }; }

constexpr void UsesSigScanning(bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 0, a_value); }
constexpr void UsesSigScanning(bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 0, a_value); }

constexpr void UsesAddressLibrary(bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 1, a_value); }
constexpr void UsesAddressLibrary(bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 1, a_value); }

constexpr void HasNoStructUse(bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 0, a_value); }
constexpr void HasNoStructUse(bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 0, a_value); }

constexpr void IsLayoutDependent(bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 1, a_value); }
constexpr void IsLayoutDependent(bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 1, 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(); });
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(); }
Expand All @@ -181,14 +182,12 @@ namespace SFSE
std::ranges::copy(a_src, a_dst.begin());
}

[[nodiscard]] static constexpr std::uint32_t SetOrClearBit(std::uint32_t a_data, std::uint32_t a_bit, bool a_set) noexcept
static constexpr void SetOrClearBit(std::uint32_t& a_data, std::uint32_t a_bit, bool a_set) noexcept
{
if (a_set)
a_data |= a_bit;
else
a_data &= ~a_bit;

return a_data;
}
};

Expand Down
4 changes: 2 additions & 2 deletions CommonLibSF/src/REL/ID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace REL
// sfse only loads plugins from { runtimeDirectory + "Data\\SFSE\\Plugins" }
auto file = std::filesystem::current_path();

file /= std::format("{}\\versionlib-{}", database::LookUpDir, version.string());
file /= std::format("{}\\versionlib-{}", database::LookUpDir, version.string("-"));

_platform = Platform::kUnknown;
for (auto& [vendor, registered] : database::VendorModule) {
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace REL
// kDatabaseVersion, runtimeVersion, runtimePlatform
"CommonLibSF-Offsets-v{}-{}-{}",
std::to_underlying(database::kDatabaseVersion),
a_version.string(),
a_version.string("-"),
std::to_underlying(_platform)));

stl_assert(mapname.has_value(),
Expand Down