Skip to content

Commit 71fcc3c

Browse files
committed
feat: add REL::VersionBase, OBSE::Version
reverts the hardcoded changes to REL::Version to support OBSE's alternative version pack method, while maintaining support with new OBSE::Version specialization
1 parent 1468b24 commit 71fcc3c

File tree

6 files changed

+76
-42
lines changed

6 files changed

+76
-42
lines changed

CommonLibOB64/include/OBSE/API.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ namespace OBSE
2525
void Init(const PreLoadInterface* a_intfc, InitInfo a_info = {}) noexcept;
2626
void Init(const LoadInterface* a_intfc, InitInfo a_info = {}) noexcept;
2727

28-
[[nodiscard]] REL::Version GetOBSEVersion() noexcept;
28+
[[nodiscard]] OBSE::Version GetOBSEVersion() noexcept;
2929
[[nodiscard]] std::string_view GetPluginName() noexcept;
3030
[[nodiscard]] std::string_view GetPluginAuthor() noexcept;
31-
[[nodiscard]] REL::Version GetPluginVersion() noexcept;
31+
[[nodiscard]] OBSE::Version GetPluginVersion() noexcept;
3232
[[nodiscard]] PluginHandle GetPluginHandle() noexcept;
3333
[[nodiscard]] const PluginInfo* GetPluginInfo(std::string_view a_plugin) noexcept;
3434
[[nodiscard]] std::uint32_t GetReleaseIndex() noexcept;

CommonLibOB64/include/OBSE/Impl/PCH.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,23 @@ namespace REL
533533

534534
#include "REL/REL.h"
535535

536+
namespace OBSE
537+
{
538+
struct VersionPackInfo
539+
{
540+
static constexpr auto AND_MAJOR{ 0x00F };
541+
static constexpr auto AND_MINOR{ 0xFFF };
542+
static constexpr auto AND_PATCH{ 0xFFF };
543+
static constexpr auto AND_BUILD{ 0x00F };
544+
static constexpr auto SHL_MAJOR{ 28 };
545+
static constexpr auto SHL_MINOR{ 16 };
546+
static constexpr auto SHL_PATCH{ 4 };
547+
static constexpr auto SHL_BUILD{ 0 };
548+
};
549+
550+
using Version = REL::VersionBase<VersionPackInfo>;
551+
}
552+
536553
#include "RE/IDs.h"
537554
#include "RE/NiRTTI_IDs.h"
538555
#include "RE/RTTI_IDs.h"

CommonLibOB64/include/OBSE/Interfaces.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace OBSE
4848
}
4949

5050
private:
51-
[[nodiscard]] constexpr static REL::Version MakeVersion(std::uint32_t a_version) noexcept
51+
[[nodiscard]] constexpr static OBSE::Version MakeVersion(std::uint32_t a_version) noexcept
5252
{
5353
return {
5454
static_cast<std::uint16_t>((a_version >> 28) & 0x00F),
@@ -59,14 +59,14 @@ namespace OBSE
5959
}
6060

6161
public:
62-
[[nodiscard]] REL::Version EditorVersion() const noexcept { return MakeVersion(GetProxy().editorVersion); }
62+
[[nodiscard]] OBSE::Version EditorVersion() const noexcept { return MakeVersion(GetProxy().editorVersion); }
6363
[[nodiscard]] PluginHandle GetPluginHandle() const { return GetProxy().GetPluginHandle(); }
6464
[[nodiscard]] std::uint32_t GetReleaseIndex() const { return GetProxy().GetReleaseIndex(); }
6565
[[nodiscard]] std::string_view GetSaveFolderName() const { return GetProxy().GetSaveFolderName(); }
66-
[[nodiscard]] REL::Version InterfaceVersion() const noexcept { return MakeVersion(GetProxy().interfaceVersion); }
66+
[[nodiscard]] OBSE::Version InterfaceVersion() const noexcept { return MakeVersion(GetProxy().interfaceVersion); }
6767
[[nodiscard]] bool IsEditor() const noexcept { return GetProxy().isEditor != 0; }
68-
[[nodiscard]] REL::Version OBSEVersion() const noexcept { return MakeVersion(GetProxy().obse64Version); }
69-
[[nodiscard]] REL::Version RuntimeVersion() const noexcept { return MakeVersion(GetProxy().runtimeVersion); }
68+
[[nodiscard]] OBSE::Version OBSEVersion() const noexcept { return MakeVersion(GetProxy().obse64Version); }
69+
[[nodiscard]] OBSE::Version RuntimeVersion() const noexcept { return MakeVersion(GetProxy().runtimeVersion); }
7070
};
7171

7272
class PreLoadInterface :
@@ -191,9 +191,9 @@ namespace OBSE
191191
kVersion = 1
192192
};
193193

194-
constexpr void PluginVersion(const REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }
194+
constexpr void PluginVersion(const OBSE::Version a_version) noexcept { pluginVersion = a_version.pack(); }
195195

196-
[[nodiscard]] constexpr REL::Version GetPluginVersion() const noexcept { return REL::Version::unpack(pluginVersion); }
196+
[[nodiscard]] constexpr OBSE::Version GetPluginVersion() const noexcept { return OBSE::Version::unpack(pluginVersion); }
197197

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

@@ -213,16 +213,16 @@ namespace OBSE
213213
// 1 << 1 is for runtime 0.411.140 and later
214214
constexpr void IsLayoutDependent(const bool a_value) noexcept { SetOrClearBit(structureIndependence, 1 << 1, a_value); }
215215

216-
constexpr void CompatibleVersions(std::initializer_list<REL::Version> a_versions) noexcept
216+
constexpr void CompatibleVersions(std::initializer_list<OBSE::Version> a_versions) noexcept
217217
{
218218
// must be zero-terminated
219219
assert(a_versions.size() < std::size(compatibleVersions) - 1);
220-
std::ranges::transform(a_versions, std::begin(compatibleVersions), [](const REL::Version& a_version) noexcept {
220+
std::ranges::transform(a_versions, std::begin(compatibleVersions), [](const OBSE::Version& a_version) noexcept {
221221
return a_version.pack();
222222
});
223223
}
224224

225-
constexpr void MinimumRequiredXSEVersion(const REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }
225+
constexpr void MinimumRequiredXSEVersion(const OBSE::Version a_version) noexcept { xseMinimum = a_version.pack(); }
226226

227227
[[nodiscard]] static const PluginVersionData* GetSingleton() noexcept;
228228

CommonLibOB64/include/OBSE/Version.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace OBSE
44
{
5-
inline constexpr REL::Version RUNTIME_0_411_140{ 0, 411, 140, 0 };
5+
inline constexpr OBSE::Version RUNTIME_0_411_140{ 0, 411, 140, 0 };
6+
inline constexpr OBSE::Version RUNTIME_0_411_141{ 0, 411, 141, 0 };
7+
inline constexpr OBSE::Version RUNTIME_0_411_142{ 0, 411, 142, 0 };
68

79
inline constexpr auto RUNTIME_LATEST = RUNTIME_0_411_140;
810
}

CommonLibOB64/include/REL/Version.h

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
namespace REL
44
{
5-
class Version
5+
template<typename T>
6+
class VersionBase
67
{
78
public:
89
using value_type = std::uint16_t;
910
using reference = value_type&;
1011
using const_reference = const value_type&;
1112

12-
constexpr Version() noexcept = default;
13+
constexpr VersionBase() noexcept = default;
1314

14-
explicit constexpr Version(std::array<value_type, 4> a_version) noexcept :
15+
explicit constexpr VersionBase(std::array<value_type, 4> a_version) noexcept :
1516
_impl(a_version)
1617
{}
1718

18-
constexpr Version(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept :
19+
constexpr VersionBase(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept :
1920
_impl{ a_v1, a_v2, a_v3, a_v4 }
2021
{}
2122

@@ -27,7 +28,7 @@ namespace REL
2728
[[nodiscard]] constexpr decltype(auto) end() const noexcept { return _impl.end(); }
2829
[[nodiscard]] constexpr decltype(auto) cend() const noexcept { return _impl.cend(); }
2930

30-
[[nodiscard]] std::strong_ordering constexpr compare(const Version& a_rhs) const noexcept
31+
[[nodiscard]] std::strong_ordering constexpr compare(const VersionBase& a_rhs) const noexcept
3132
{
3233
for (std::size_t i = 0; i < _impl.size(); ++i) {
3334
if ((*this)[i] != a_rhs[i]) {
@@ -40,10 +41,10 @@ namespace REL
4041
[[nodiscard]] constexpr std::uint32_t pack() const noexcept
4142
{
4243
return static_cast<std::uint32_t>(
43-
(_impl[0] & 0x00F) << 28u |
44-
(_impl[1] & 0xFFF) << 16u |
45-
(_impl[2] & 0xFFF) << 4u |
46-
(_impl[3] & 0x00F) << 0u);
44+
(_impl[0] & T::AND_MAJOR) << T::SHL_MAJOR |
45+
(_impl[1] & T::AND_MINOR) << T::SHL_MINOR |
46+
(_impl[2] & T::AND_PATCH) << T::SHL_PATCH |
47+
(_impl[3] & T::AND_BUILD) << T::SHL_BUILD);
4748
}
4849

4950
[[nodiscard]] constexpr value_type major() const noexcept { return _impl[0]; }
@@ -73,22 +74,22 @@ namespace REL
7374
return result;
7475
}
7576

76-
[[nodiscard]] static constexpr Version unpack(const std::uint32_t a_packedVersion) noexcept
77+
[[nodiscard]] static constexpr VersionBase unpack(const std::uint32_t a_packedVersion) noexcept
7778
{
78-
return Version{
79-
static_cast<value_type>((a_packedVersion >> 28) & 0x00F),
80-
static_cast<value_type>((a_packedVersion >> 16) & 0xFFF),
81-
static_cast<value_type>((a_packedVersion >> 4) & 0xFFF),
82-
static_cast<value_type>(a_packedVersion & 0x0F)
79+
return VersionBase{
80+
static_cast<value_type>((a_packedVersion >> T::SHL_MAJOR) & T::AND_MAJOR),
81+
static_cast<value_type>((a_packedVersion >> T::SHL_MINOR) & T::AND_MINOR),
82+
static_cast<value_type>((a_packedVersion >> T::SHL_PATCH) & T::AND_PATCH),
83+
static_cast<value_type>((a_packedVersion >> T::SHL_BUILD) & T::AND_BUILD)
8384
};
8485
}
8586

86-
[[nodiscard]] friend constexpr bool operator==(const Version& a_lhs, const Version& a_rhs) noexcept
87+
[[nodiscard]] friend constexpr bool operator==(const VersionBase& a_lhs, const VersionBase& a_rhs) noexcept
8788
{
8889
return a_lhs.compare(a_rhs) == 0;
8990
}
9091

91-
[[nodiscard]] friend constexpr std::strong_ordering operator<=>(const Version& a_lhs, const Version& a_rhs) noexcept
92+
[[nodiscard]] friend constexpr std::strong_ordering operator<=>(const VersionBase& a_lhs, const VersionBase& a_rhs) noexcept
9293
{
9394
return a_lhs.compare(a_rhs);
9495
}
@@ -97,26 +98,40 @@ namespace REL
9798
std::array<value_type, 4> _impl{ 0, 0, 0, 0 };
9899
};
99100

101+
struct VersionPackInfo
102+
{
103+
static constexpr auto AND_MAJOR{ 0x0FF };
104+
static constexpr auto AND_MINOR{ 0x0FF };
105+
static constexpr auto AND_PATCH{ 0xFFF };
106+
static constexpr auto AND_BUILD{ 0x00F };
107+
static constexpr auto SHL_MAJOR{ 8 * 3 };
108+
static constexpr auto SHL_MINOR{ 8 * 2 };
109+
static constexpr auto SHL_PATCH{ 8 / 2 };
110+
static constexpr auto SHL_BUILD{ 8 * 0 };
111+
};
112+
113+
using Version = VersionBase<VersionPackInfo>;
114+
100115
[[nodiscard]] std::optional<Version> GetFileVersion(std::string_view a_filename);
101116
[[nodiscard]] std::optional<Version> GetFileVersion(std::wstring_view a_filename);
102117
}
103118

104-
template <class CharT>
105-
struct std::formatter<REL::Version, CharT> : formatter<std::string, CharT>
119+
template <typename T, class CharT>
120+
struct std::formatter<REL::VersionBase<T>, CharT> : formatter<std::string, CharT>
106121
{
107122
template <class FormatContext>
108-
constexpr auto format(const REL::Version& a_version, FormatContext& a_ctx) const
123+
constexpr auto format(const REL::VersionBase<T>& a_version, FormatContext& a_ctx) const
109124
{
110125
return formatter<std::string, CharT>::format(a_version.string(), a_ctx);
111126
}
112127
};
113128

114129
#ifdef FMT_VERSION
115-
template <class CharT>
116-
struct fmt::formatter<REL::Version, CharT> : formatter<std::string, CharT>
130+
template <typename T, class CharT>
131+
struct fmt::formatter<REL::VersionBase<T>, CharT> : formatter<std::string, CharT>
117132
{
118133
template <class FormatContext>
119-
auto format(const REL::Version& a_version, FormatContext& a_ctx) const
134+
auto format(const REL::VersionBase<T>& a_version, FormatContext& a_ctx) const
120135
{
121136
return formatter<std::string, CharT>::format(a_version.string(), a_ctx);
122137
}

CommonLibOB64/src/OBSE/API.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ namespace OBSE
2424

2525
InitInfo info;
2626

27-
std::string pluginName{};
28-
std::string pluginAuthor{};
29-
REL::Version pluginVersion{};
27+
std::string pluginName{};
28+
std::string pluginAuthor{};
29+
OBSE::Version pluginVersion{};
3030

31-
REL::Version obse64Version{};
31+
OBSE::Version obse64Version{};
3232
PluginHandle pluginHandle{ static_cast<PluginHandle>(-1) };
3333
std::uint32_t releaseIndex{ 0 };
3434
std::function<const void*(OBSEAPI)(const char*)> pluginInfoAccessor;
@@ -172,7 +172,7 @@ namespace OBSE
172172
});
173173
}
174174

175-
REL::Version GetOBSEVersion() noexcept
175+
OBSE::Version GetOBSEVersion() noexcept
176176
{
177177
return Impl::API::GetSingleton()->obse64Version;
178178
}
@@ -187,7 +187,7 @@ namespace OBSE
187187
return Impl::API::GetSingleton()->pluginAuthor;
188188
}
189189

190-
REL::Version GetPluginVersion() noexcept
190+
OBSE::Version GetPluginVersion() noexcept
191191
{
192192
return Impl::API::GetSingleton()->pluginVersion;
193193
}

0 commit comments

Comments
 (0)