Skip to content

Commit 7f8e63d

Browse files
committed
BSPointerHandle RE
1 parent 7246289 commit 7f8e63d

2 files changed

Lines changed: 41 additions & 22 deletions

File tree

include/RE/B/BSPointerHandle.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace RE
6363
}
6464

6565
[[nodiscard]] explicit operator bool() const noexcept { return has_value(); }
66-
[[nodiscard]] bool has_value() const noexcept { return _handle != 0; }
66+
[[nodiscard]] bool has_value() const noexcept { return _handle != 0; }
6767

6868
[[nodiscard]] value_type value() const noexcept { return _handle; }
6969

@@ -152,17 +152,17 @@ namespace RE
152152

153153
void reset() noexcept { _handle.reset(); }
154154

155-
[[nodiscard]] NiPointer<T> get() const
155+
[[nodiscard]] NiPointer<T> get()
156156
{
157157
NiPointer<T> ptr;
158158
get_smartptr(ptr);
159159
return ptr;
160160
}
161161

162-
[[nodiscard]] NiPointer<T> getsafe() const
162+
[[nodiscard]] NiPointer<T> get() const
163163
{
164164
NiPointer<T> ptr;
165-
get_validated_smartptr(ptr);
165+
get_smartptr(ptr);
166166
return ptr;
167167
}
168168

@@ -185,8 +185,8 @@ namespace RE
185185
friend class BSPointerHandle;
186186

187187
void get_handle(T* a_ptr);
188+
bool get_smartptr(NiPointer<T>& a_smartPointerOut);
188189
bool get_smartptr(NiPointer<T>& a_smartPointerOut) const;
189-
bool get_validated_smartptr(NiPointer<T>& a_smartPointerOut) const;
190190

191191
Handle _handle;
192192
};
@@ -222,17 +222,17 @@ namespace RE
222222
return func(a_ptr);
223223
}
224224

225-
static bool GetSmartPointer(const BSPointerHandle<T>& a_handle, NiPointer<T>& a_smartPointerOut)
225+
static bool GetSmartPointer(BSPointerHandle<T>& a_handle, NiPointer<T>& a_smartPointerOut) // clears the handle
226226
{
227-
using func_t = decltype(&BSPointerHandleManagerInterface<T, Manager>::GetSmartPointer);
228-
static REL::Relocation<func_t> func{ RELOCATION_ID(12204, 12332) };
227+
using func_t = bool (*)(BSPointerHandle<T>&, NiPointer<T>&);
228+
static REL::Relocation<func_t> func{ RELOCATION_ID(12785, 12922) };
229229
return func(a_handle, a_smartPointerOut);
230230
}
231231

232-
static bool GetHandleValidatedSmartPointer(const BSPointerHandle<T>& a_handle, NiPointer<T>& a_smartPointerOut)
232+
static bool GetSmartPointer(const BSPointerHandle<T>& a_handle, NiPointer<T>& a_smartPointerOut)
233233
{
234-
using func_t = decltype(&BSPointerHandleManagerInterface<T, Manager>::GetHandleValidatedSmartPointer);
235-
static REL::Relocation<func_t> func{ RELOCATION_ID(12785, 12922) };
234+
using func_t = bool (*)(const BSPointerHandle<T>&, NiPointer<T>&);
235+
static REL::Relocation<func_t> func{ RELOCATION_ID(12204, 12332) };
236236
return func(a_handle, a_smartPointerOut);
237237
}
238238
};
@@ -248,14 +248,14 @@ namespace RE
248248
}
249249

250250
template <class T, class Handle>
251-
bool BSPointerHandle<T, Handle>::get_smartptr(NiPointer<T>& a_smartPointerOut) const
251+
bool BSPointerHandle<T, Handle>::get_smartptr(NiPointer<T>& a_smartPointerOut)
252252
{
253253
return BSPointerHandleManagerInterface<T>::GetSmartPointer(*this, a_smartPointerOut);
254254
}
255255

256256
template <class T, class Handle>
257-
bool BSPointerHandle<T, Handle>::get_validated_smartptr(NiPointer<T>& a_smartPointerOut) const
257+
bool BSPointerHandle<T, Handle>::get_smartptr(NiPointer<T>& a_smartPointerOut) const
258258
{
259-
return BSPointerHandleManagerInterface<T>::GetHandleValidatedSmartPointer(*this, a_smartPointerOut);
259+
return BSPointerHandleManagerInterface<T>::GetSmartPointer(*this, a_smartPointerOut);
260260
}
261261
}
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "RE/B/BSHandleRefObject.h"
3+
#include "RE/B/BSPointerHandle.h"
44
#include "RE/N/NiSmartPointer.h"
55

66
namespace RE
@@ -12,23 +12,42 @@ namespace RE
1212
struct Entry
1313
{
1414
public:
15-
enum EntryBitfieldConstants : std::uint32_t
15+
enum class EntryBitfieldConstants
1616
{
17-
//kAgeInc = (1 << T::kFreeListBits), // 0x100000
18-
//kFreeListMask = kAgeInc - 1, // 0xFFFFF
19-
//kInUseBit = kAgeInc << kAgeShift // 0x4000000
17+
kAgeInc = 1 << 20, // (1 << T::kFreeListBits)
18+
kFreeListMask = kAgeInc - 1, // 0xFFFFF
19+
kInUseBit = 1 << 26 // kAgeInc << T::kAgeShift
2020
};
2121

22+
[[nodiscard]] bool IsInUse() const
23+
{
24+
return handleEntryBits.any(EntryBitfieldConstants::kInUseBit);
25+
}
26+
2227
// members
23-
std::uint32_t handleEntryBits; // 00
24-
std::uint32_t pad04; // 04
25-
NiPointer<BSHandleRefObject> pointer; // 08
28+
REX::EnumSet<EntryBitfieldConstants, std::uint32_t> handleEntryBits; // 00
29+
std::uint32_t pad04; // 04
30+
NiPointer<BSHandleRefObject> pointer; // 08
2631
};
32+
static_assert(sizeof(Entry) == 0x10);
33+
34+
[[nodiscard]] static bool IsValid(const ObjectRefHandle& a_handle)
35+
{
36+
using func_t = decltype(&BSPointerHandleManager<TESObjectREFR>::IsValid);
37+
static REL::Relocation<func_t> func{ RELOCATION_ID(75454, 77239) };
38+
return func(a_handle);
39+
}
2740

2841
[[nodiscard]] static auto GetHandleEntries()
2942
{
3043
static REL::Relocation<Entry(*)[0x100000]> entries{ RELOCATION_ID(514478, 400622) };
3144
return std::span<Entry, 0x100000>{ *entries };
3245
}
46+
47+
[[nodiscard]] static BSReadWriteLock& GetHandleManagerLock()
48+
{
49+
static REL::Relocation<BSReadWriteLock*> handleManagerLock{ RELOCATION_ID(514477, 400621) };
50+
return *handleManagerLock;
51+
}
3352
};
3453
}

0 commit comments

Comments
 (0)