Skip to content

Commit

Permalink
Merge branch 'vr' of github.com:alandtse/CommonLibVR into vr
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jul 6, 2024
2 parents 71d2a73 + 6b0750a commit db1e020
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
15 changes: 12 additions & 3 deletions include/RE/P/PlayerCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ namespace RE
kInvalidMarker
};

enum VR_Bow_State : std::uint32_t
{
kNone,
kNoAmmo,
kIdle,
kArrowKnocked,
};

struct CrimeGoldStruct
{
public:
Expand Down Expand Up @@ -700,7 +708,7 @@ namespace RE
std::uint32_t unk5B0; // 5B0
std::uint32_t unk5B4; // 5B4
std::uint64_t unk5B8; // 5B8
std::uint32_t unk5C0; // 5C0
VR_Bow_State bowState; // 5C0
std::uint32_t unk5C4; // 5C4
NiPointer<NiNode> BowAimNode; // 5C8
NiPointer<NiNode> BowRotationNode; // 5D0
Expand All @@ -711,9 +719,10 @@ namespace RE
NiPointer<NiNode> ArrowHoldOffsetNode; // 5F8
NiPointer<NiNode> ArrowHoldNode; // 600
NiPointer<NiNode> unk608; // 608
float unkFloat610; // 610
float currentArrowSnapDistance; // 610
std::uint32_t unk614; // 614
std::uint64_t unk618; // 618
float currentBowDrawAmount; // 618 - 0 to 1
float lastRumbleBowDrawAmount; // 61C - 0 to 1
std::uint64_t unk620; // 620
std::uint64_t unk628; // 628
std::uint64_t unk630; // 630
Expand Down
22 changes: 22 additions & 0 deletions include/REL/ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ namespace REL
return static_cast<std::size_t>(it->offset);
}

#ifdef SKYRIMVR
bool IsVRAddressLibraryAtLeastVersion(const char* pluginName, const char* minimalVRAddressLibVersion, bool showWindowsMessage = false) const
{
const auto minimalVersion = REL::Version(minimalVRAddressLibVersion);

bool validVersion = minimalVersion <= _vrAddressLibraryVersion;

if (!validVersion && showWindowsMessage) {
REX::W32::MessageBoxA(NULL, std::format("You need version: {} of VR Address Library for SKSEVR, you have version: {}", minimalVersion.string(), _vrAddressLibraryVersion.string()).c_str(), pluginName, 0x00000000L | 0x00000030L);
REX::W32::TerminateProcess(REX::W32::GetCurrentProcess(), 0);
return false;
}

return validVersion;
}
#endif // SKYRIMVR

private:
friend Offset2ID;

Expand Down Expand Up @@ -249,6 +266,7 @@ namespace REL
auto mapname = L"CommonLibSSEOffsets-v2-"s;
mapname += a_version.wstring();
in.read_row(address_count, version);
_vrAddressLibraryVersion = Version(version);
const auto byteSize = static_cast<std::size_t>(address_count * sizeof(mapping_t));
if (!_mmap.open(mapname, byteSize) &&
!_mmap.create(mapname, byteSize)) {
Expand Down Expand Up @@ -399,6 +417,10 @@ namespace REL

detail::memory_map _mmap;
std::span<mapping_t> _id2offset;

#ifdef SKYRIMVR
Version _vrAddressLibraryVersion;
#endif // SKYRIMVR
};

class ID
Expand Down
26 changes: 26 additions & 0 deletions include/REL/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ namespace REL
_impl{ a_v1, a_v2, a_v3, a_v4 }
{}

explicit constexpr Version(std::string_view a_version)
{
std::array<value_type, 4> powers{ 1, 1, 1, 1 };
std::size_t position = 0;
for (std::size_t i = 0; i < a_version.size(); ++i) {
if (a_version[i] == '.') {
if (++position == powers.size()) {
throw std::invalid_argument("Too many parts in version number.");
}
} else {
powers[position] *= 10;
}
}
position = 0;
for (std::size_t i = 0; i < a_version.size(); ++i) {
if (a_version[i] == '.') {
++position;
} else if (a_version[i] < '0' || a_version[i] > '9') {
throw std::invalid_argument("Invalid character in version number.");
} else {
powers[position] /= 10;
_impl[position] += static_cast<value_type>((a_version[i] - '0') * powers[position]);
}
}
}

[[nodiscard]] constexpr reference operator[](std::size_t a_idx) noexcept { return _impl[a_idx]; }
[[nodiscard]] constexpr const_reference operator[](std::size_t a_idx) const noexcept { return _impl[a_idx]; }

Expand Down

0 comments on commit db1e020

Please sign in to comment.