CommonLibSSE NG
Loading...
Searching...
No Matches
RTTI.h
Go to the documentation of this file.
1#pragma once
2
3struct __type_info_node;
4
5namespace RE
6{
7 namespace msvc
8 {
9 class __declspec(novtable) type_info
10 {
11 public:
12 virtual ~type_info(); // 00
13
14 [[nodiscard]] const char* mangled_name() const noexcept { return _name; }
15
16 private:
17 // members
18 void* _data; // 08
19 char _name[1]; // 10
20 };
21 static_assert(sizeof(type_info) == 0x18);
22 }
23
24 namespace RTTI
25 {
26 template <class T>
27 class RVA
28 {
29 public:
30 using value_type = T;
33
34 constexpr RVA() noexcept = default;
35
36 constexpr RVA(std::uint32_t a_rva) noexcept :
37 _rva(a_rva)
38 {}
39
40 [[nodiscard]] pointer get() const { return is_good() ? REL::Relocation<T*>{ REL::Offset(_rva) }.get() : nullptr; }
41 [[nodiscard]] std::uint32_t offset() const noexcept { return _rva; }
42 [[nodiscard]] reference operator*() const { return *get(); }
43 [[nodiscard]] pointer operator->() const { return get(); }
44 [[nodiscard]] explicit constexpr operator bool() const noexcept { return is_good(); }
45
46 protected:
47 [[nodiscard]] constexpr bool is_good() const noexcept { return _rva != 0; }
48
49 // members
50 std::uint32_t _rva{ 0 }; // 00
51 };
52 static_assert(sizeof(RVA<void*>) == 0x4);
53
54 using TypeDescriptor = msvc::type_info;
55
56 struct PMD
57 {
58 public:
59 // members
60 std::int32_t mDisp; // 0
61 std::int32_t pDisp; // 4
62 std::int32_t vDisp; // 8
63 };
64 static_assert(sizeof(PMD) == 0xC);
65
67 {
68 public:
69 enum class Attribute : std::uint32_t
70 {
71 kNone = 0,
72 kNotVisible = 1 << 0,
73 kAmbiguous = 1 << 1,
74 kPrivate = 1 << 2,
76 kVirtual = 1 << 4,
77 kNonPolymorphic = 1 << 5,
79 };
80
81 // members
83 std::uint32_t numContainedBases; // 04
84 PMD pmd; // 08
86 };
87 static_assert(sizeof(BaseClassDescriptor) == 0x18);
88
90 {
91 public:
92 enum class Attribute
93 {
95 kMultipleInheritance = 1 << 0,
96 kVirtualInheritance = 1 << 1,
98 };
99
100 // members
101 std::uint32_t signature; // 00
103 std::uint32_t numBaseClasses; // 08
105 };
106 static_assert(sizeof(ClassHierarchyDescriptor) == 0x10);
107
109 {
110 public:
111 enum class Signature
112 {
113 x86 = 0,
114 x64 = 1
115 };
116
117 // members
119 std::uint32_t offset; // 04
120 std::uint32_t ctorDispOffset; // 08
123 };
124 static_assert(sizeof(CompleteObjectLocator) == 0x14);
125 }
126
127 inline void* RTDynamicCast(void* a_inptr, std::int32_t a_vfDelta, void* a_srcType, void* a_targetType, std::int32_t a_isReference)
128 {
129 using func_t = decltype(&RTDynamicCast);
130 REL::Relocation<func_t> func{ RELOCATION_ID(102238, 109689) };
131 return func(a_inptr, a_vfDelta, a_srcType, a_targetType, a_isReference);
132 }
133
134 namespace detail
135 {
136 template <class T>
138 std::remove_cv_t<
139 std::remove_pointer_t<
140 std::remove_reference_t<T>>>;
141
142 template <class T>
144 std::disjunction<
145 std::is_polymorphic<
146 remove_cvpr_t<T>>,
147 std::is_same<
148 void*,
149 std::remove_cv_t<T>>>
150 {};
151
152 template <class, class>
154 std::false_type
155 {};
156
157 template <class To, class From>
158 struct types_are_compat<To, From*> :
159 std::is_pointer<To>
160 {};
161
162 template <class To, class From>
163 struct types_are_compat<To, const From*> :
164 std::conjunction<
165 std::is_pointer<To>,
166 std::is_const<
167 std::remove_pointer_t<To>>>
168 {};
169
170 template <class To, class From>
171 struct types_are_compat<To, volatile From*> :
172 std::conjunction<
173 std::is_pointer<To>,
174 std::is_volatile<
175 std::remove_pointer_t<To>>>
176 {};
177
178 template <class To, class From>
179 struct types_are_compat<To, const volatile From*> :
180 std::conjunction<
181 std::is_pointer<To>,
182 std::is_const<
183 std::remove_pointer_t<To>>,
184 std::is_volatile<
185 std::remove_pointer_t<To>>>
186 {};
187
188 template <class, class = void>
190 std::false_type
191 {};
192
193 template <class T>
195 T,
196 std::void_t<
197 decltype(remove_cvpr_t<T>::RTTI)>> :
198 std::true_type
199 {};
200
201 template <class To, class From>
203 std::conjunction<
204 types_are_compat<
205 To,
206 From>,
207 target_is_valid<
208 To>,
209 implements_rtti<To>,
210 implements_rtti<From>>
211 {};
212
213 template <class To, class From>
215 }
216}
217
218template <
219 class To,
220 class From,
221 std::enable_if_t<
223 To,
224 From*>,
225 int> = 0>
226To skyrim_cast(From* a_from)
227{
230
231 if (!from.get() || !to.get()) {
232 return nullptr;
233 }
234
235 return static_cast<To>(
237 const_cast<void*>(
238 static_cast<const volatile void*>(a_from)),
239 0,
240 from.get(),
241 to.get(),
242 false));
243}
#define RELOCATION_ID(a_se, a_ae)
Definition PCH.h:794
To skyrim_cast(From *a_from)
Definition RTTI.h:226
Definition RTTI.h:28
pointer get() const
Definition RTTI.h:40
std::uint32_t _rva
Definition RTTI.h:50
constexpr RVA() noexcept=default
constexpr bool is_good() const noexcept
Definition RTTI.h:47
std::uint32_t offset() const noexcept
Definition RTTI.h:41
value_type * pointer
Definition RTTI.h:31
reference operator*() const
Definition RTTI.h:42
T value_type
Definition RTTI.h:30
pointer operator->() const
Definition RTTI.h:43
value_type & reference
Definition RTTI.h:32
Definition Relocation.h:1401
Definition Relocation.h:1638
Definition PCH.h:223
msvc::type_info TypeDescriptor
Definition RTTI.h:54
std::remove_cv_t< std::remove_pointer_t< std::remove_reference_t< T > > > remove_cvpr_t
Definition RTTI.h:140
constexpr bool cast_is_valid_v
Definition RTTI.h:214
Definition AbsorbEffect.h:6
void * RTDynamicCast(void *a_inptr, std::int32_t a_vfDelta, void *a_srcType, void *a_targetType, std::int32_t a_isReference)
Definition RTTI.h:127
Definition ActorValueList.h:28
Definition RTTI.h:67
RVA< TypeDescriptor > typeDescriptor
Definition RTTI.h:82
std::uint32_t numContainedBases
Definition RTTI.h:83
Attribute
Definition RTTI.h:70
stl::enumeration< Attribute, std::uint32_t > attributes
Definition RTTI.h:85
PMD pmd
Definition RTTI.h:84
std::uint32_t numBaseClasses
Definition RTTI.h:103
RVA< BaseClassDescriptor > baseClassArray
Definition RTTI.h:104
stl::enumeration< Attribute, std::uint32_t > attributes
Definition RTTI.h:102
std::uint32_t signature
Definition RTTI.h:101
Definition RTTI.h:109
RVA< ClassHierarchyDescriptor > classDescriptor
Definition RTTI.h:122
std::uint32_t ctorDispOffset
Definition RTTI.h:120
std::uint32_t offset
Definition RTTI.h:119
stl::enumeration< Signature, std::uint32_t > signature
Definition RTTI.h:118
RVA< TypeDescriptor > typeDescriptor
Definition RTTI.h:121
Signature
Definition RTTI.h:112
Definition RTTI.h:57
std::int32_t pDisp
Definition RTTI.h:61
std::int32_t vDisp
Definition RTTI.h:62
std::int32_t mDisp
Definition RTTI.h:60
Definition RTTI.h:211
Definition RTTI.h:191
Definition RTTI.h:150
Definition RTTI.h:155