CommonLibSSE NG
Offset.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "REL/Module.h"
4 
5 namespace REL
6 {
7  class Offset
8  {
9  public:
10  constexpr Offset() noexcept = default;
11 
12  explicit constexpr Offset(std::size_t a_offset) noexcept:
13  _offset(a_offset)
14  {}
15 
16  constexpr Offset& operator=(std::size_t a_offset) noexcept
17  {
18  _offset = a_offset;
19  return *this;
20  }
21 
22  [[nodiscard]] std::uintptr_t address() const { return base() + offset(); }
23 
24  [[nodiscard]] constexpr std::size_t offset() const noexcept { return _offset; }
25 
26  private:
27  [[nodiscard]] static std::uintptr_t base() { return Module::get().base(); }
28 
29  std::size_t _offset{0};
30  };
31 
33  {
34  public:
35  constexpr VariantOffset() noexcept = default;
36 
37  explicit constexpr VariantOffset(
38  [[maybe_unused]] std::size_t a_seOffset,
39  [[maybe_unused]] std::size_t a_aeOffset,
40  [[maybe_unused]] std::size_t a_vrOffset) noexcept
41  {
42 #ifdef ENABLE_SKYRIM_SE
43  _seOffset = a_seOffset;
44 #endif
45 #ifdef ENABLE_SKYRIM_AE
46  _aeOffset = a_aeOffset;
47 #endif
48 #ifdef ENABLE_SKYRIM_VR
49  _vrOffset = a_vrOffset;
50 #endif
51  }
52 
53  [[nodiscard]] std::uintptr_t address() const
54  {
55  auto thisOffset = offset();
56  return thisOffset ? base() + thisOffset : 0;
57  }
58 
59  [[nodiscard]] SKYRIM_REL std::size_t offset() const noexcept
60  {
61  switch (Module::GetRuntime()) {
62 #ifdef ENABLE_SKYRIM_AE
64  return _aeOffset;
65 #endif
66 #ifdef ENABLE_SKYRIM_SE
68  return _seOffset;
69 #endif
70 #ifdef ENABLE_SKYRIM_VR
72  return _vrOffset;
73 #endif
74  default:
75  return 0;
76  }
77  }
78 
79  [[nodiscard]] SKYRIM_REL explicit operator Offset() const noexcept { return Offset(offset()); }
80 
81  private:
82  [[nodiscard]] static std::uintptr_t base() { return Module::get().base(); }
83 
84 #ifdef ENABLE_SKYRIM_SE
85  std::size_t _seOffset{0};
86 #endif
87 #ifdef ENABLE_SKYRIM_AE
88  std::size_t _aeOffset{0};
89 #endif
90 #ifdef ENABLE_SKYRIM_VR
91  std::size_t _vrOffset{0};
92 #endif
93  };
94 }
#define SKYRIM_REL
Definition: Common.h:38
static Module & get()
Definition: Module.h:82
std::uintptr_t base() const noexcept
Definition: Module.h:201
static SKYRIM_REL Runtime GetRuntime() noexcept
Definition: Module.h:222
Definition: Offset.h:8
constexpr Offset() noexcept=default
std::uintptr_t address() const
Definition: Offset.h:22
constexpr Offset & operator=(std::size_t a_offset) noexcept
Definition: Offset.h:16
constexpr std::size_t offset() const noexcept
Definition: Offset.h:24
Definition: Offset.h:33
std::uintptr_t address() const
Definition: Offset.h:53
SKYRIM_REL std::size_t offset() const noexcept
Definition: Offset.h:59
constexpr VariantOffset() noexcept=default
Definition: ID.h:6
Definition: ActorValueList.h:28