CommonLibSSE NG
TESDataHandler.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSPointerHandle.h"
4 #include "RE/B/BSTArray.h"
5 #include "RE/B/BSTList.h"
6 #include "RE/B/BSTSingleton.h"
7 #include "RE/F/FormTypes.h"
8 #include "RE/N/NiTArray.h"
9 #include "RE/N/NiTList.h"
10 #include "RE/T/TESForm.h"
11 
12 namespace RE
13 {
14  class BGSPrimitive;
15  class InventoryChanges;
16  class NiPoint3;
17  class TESFile;
18  class TESRegionDataManager;
19  class TESRegionList;
20 
22  {
23  public:
24  // members
25  std::uint8_t pad0; // 0
26  };
27  static_assert(sizeof(TESObjectList) == 0x1);
28 
30  {
31  public:
32  // members
35  };
36  static_assert(sizeof(TESFileCollection) == 0x30);
37 
38  class TESDataHandler : public BSTSingletonSDM<TESDataHandler>
39  {
40  public:
42 
44 
45  std::uint32_t LoadScripts();
46  TESForm* LookupForm(FormID a_localFormID, std::string_view a_modName);
47  TESForm* LookupFormRaw(FormID a_rawFormID, std::string_view a_modName);
48  template <class T>
49  T* LookupForm(FormID a_localFormID, std::string_view a_modName);
50  template <class T>
51  T* LookupFormRaw(FormID a_rawFormID, std::string_view a_modName);
52  FormID LookupFormID(FormID a_localFormID, std::string_view a_modName);
53  FormID LookupFormIDRaw(FormID a_rawFormID, std::string_view a_modName);
54 
55  const TESFile* LookupModByName(std::string_view a_modName);
56  std::optional<std::uint8_t> GetModIndex(std::string_view a_modName);
57 
58  const TESFile* LookupLoadedModByName(std::string_view a_modName);
59  const TESFile* LookupLoadedModByIndex(std::uint8_t a_index);
60  std::optional<std::uint8_t> GetLoadedModIndex(std::string_view a_modName);
61 
62  const TESFile* LookupLoadedLightModByName(std::string_view a_modName);
63  const TESFile* LookupLoadedLightModByIndex(std::uint16_t a_index);
64  std::optional<std::uint16_t> GetLoadedLightModIndex(std::string_view a_modName);
65 
66  bool IsGeneratedID(FormID a_formID);
67 
69  template <class T>
71 
72  ObjectRefHandle CreateReferenceAtLocation(TESBoundObject* a_base, const NiPoint3& a_location, const NiPoint3& a_rotation, TESObjectCELL* a_targetCell, TESWorldSpace* a_selfWorldSpace, TESObjectREFR* a_alreadyCreatedRef, BGSPrimitive* a_primitive, const ObjectRefHandle& a_linkedRoomRefHandle, bool a_forcePersist, bool a_arg11);
73 
74  struct RUNTIME_DATA
75  {
76 #define RUNTIME_DATA_CONTENT \
77  bool masterSave; \
78  bool blockSave; \
79  bool saveLoadGame; \
80  bool autoSaving; \
81  bool exportingPlugin; \
82  bool clearingData; \
83  bool hasDesiredFiles; \
84  bool checkingModels; \
85  bool loadingFiles; \
86  bool dontRemoveIDs;
87 
89  };
90 
91  [[nodiscard]] inline RUNTIME_DATA& GetGeometryRuntimeData() noexcept
92  {
93  return REL::RelocateMember<RUNTIME_DATA>(this, 0xDA0, 0x1570);
94  }
95 
96  [[nodiscard]] inline const RUNTIME_DATA& GetGeometryRuntimeData() const noexcept
97  {
98  return REL::RelocateMember<RUNTIME_DATA>(this, 0xDA0, 0x1570);
99  }
100 
101  [[nodiscard]] inline TESFile** GetLoadedMods() noexcept {
103  return &REL::RelocateMember<TESFile*>(this, 0x0, 0xD78);
104  } else {
105  return REL::RelocateMember<TESFileCollection>(this, 0xD70, 0).files.data();
106  }
107  }
108 
109  [[nodiscard]] inline const TESFile* const * GetLoadedMods() const noexcept {
111  return &REL::RelocateMember<const TESFile*>(this, 0x0, 0xD78);
112  } else {
113  return REL::RelocateMember<const TESFileCollection>(this, 0xD70, 0).files.data();
114  }
115  }
116 
117  [[nodiscard]] inline std::uint8_t GetLoadedModCount() const noexcept {
119  return static_cast<std::uint8_t>(REL::RelocateMember<std::uint32_t>(this, 0x0, 0xD70));
120  } else {
121  return static_cast<std::uint8_t>(REL::RelocateMember<const TESFileCollection>(this, 0xD70, 0).files.size());
122  }
123  }
124 
125  [[nodiscard]] inline TESFile** GetLoadedLightMods() noexcept {
127  return nullptr;
128  } else {
129  return REL::RelocateMember<TESFileCollection>(this, 0xD70, 0).smallFiles.data();
130  }
131  }
132 
133  [[nodiscard]] inline const TESFile* const * GetLoadedLightMods() const noexcept {
135  return nullptr;
136  } else {
137  return REL::RelocateMember<const TESFileCollection>(this, 0xD70, 0).smallFiles.data();
138  }
139  }
140 
141  [[nodiscard]] inline std::uint16_t GetLoadedLightModCount() const noexcept {
143  return 0;
144  } else {
145  return static_cast<std::uint16_t>(REL::RelocateMember<const TESFileCollection>(this, 0xD70, 0).smallFiles.size());
146  }
147  }
148 
149  [[nodiscard]] inline TESRegionDataManager* GetRegionDataManager() noexcept {
150  return REL::RelocateMember<TESRegionDataManager*>(this, 0xDB0, 0x1580);
151  }
152 
153  [[nodiscard]] inline const TESRegionDataManager* GetRegionDataManager() const noexcept {
154  return REL::RelocateMember<TESRegionDataManager*>(this, 0xDB0, 0x1580);
155  }
156 
157  [[nodiscard]] inline InventoryChanges* GetMerchantInventory() noexcept {
158  return REL::RelocateMember<InventoryChanges*>(this, 0xDB8, 0x1588);
159  }
160 
161  [[nodiscard]] inline const InventoryChanges* GetMerchantInventory() const noexcept {
162  return REL::RelocateMember<InventoryChanges*>(this, 0xDB8, 0x1588);
163  }
164 
165  // members
166  std::uint8_t pad001; // 001
167  std::uint16_t pad002; // 002
168  std::uint32_t pad004; // 004
170  BSTArray<TESForm*> formArrays[std::to_underlying(FormType::Max)]; // 010
175  FormID nextID; // D50
176  std::uint32_t padD54; // D54
179 #ifndef ENABLE_SKYRIM_VR
182  std::uint8_t unkDAA; // DAA
183  std::uint8_t padDAB; // DAB
184  std::uint32_t padDAC; // DAC
187 #elif !defined(ENABLE_SKYRIM_AE) && !defined(ENABLE_SKYRIM_SE)
188  std::uint32_t loadedModCount; // D70
189  std::uint32_t pad14; // D74
190  TESFile* loadedMods[0xFF]; // D78
192  std::uint8_t pad157B[5]; // 157B
195 #endif
196  };
197 #undef RUNTIME_DATA_CONTENT
198 
199  template <class T>
200  T* TESDataHandler::LookupForm(FormID a_localFormID, std::string_view a_modName)
201  {
202  auto form = LookupForm(a_localFormID, a_modName);
203  if (!form) {
204  return 0;
205  }
206 
207  return form->Is(T::FORMTYPE) ? static_cast<T*>(form) : 0;
208  }
209 
210  template <class T>
211  T* TESDataHandler::LookupFormRaw(FormID a_rawFormID, std::string_view a_modName)
212  {
213  auto form = LookupFormRaw(a_rawFormID, a_modName);
214  if (!form) {
215  return 0;
216  }
217 
218  return form->Is(T::FORMTYPE) ? static_cast<T*>(form) : 0;
219  }
220 
221  template <class T>
223  {
224  return reinterpret_cast<BSTArray<T*>&>(GetFormArray(T::FORMTYPE));
225  }
226 }
#define SKYRIM_REL_CONSTEXPR
Definition: Common.h:47
#define RUNTIME_DATA_CONTENT
Definition: TESDataHandler.h:76
static SKYRIM_REL_VR bool IsVR() noexcept
Definition: Module.h:254
Definition: BSTList.h:10
Definition: BSTArray.h:377
Definition: InventoryChanges.h:16
Definition: NiPoint3.h:6
Definition: NiTList.h:10
Definition: NiTArray.h:136
Definition: TESBoundObject.h:24
Definition: TESDataHandler.h:39
TESForm * LookupFormRaw(FormID a_rawFormID, std::string_view a_modName)
const TESRegionDataManager * GetRegionDataManager() const noexcept
Definition: TESDataHandler.h:153
std::uint32_t padD54
Definition: TESDataHandler.h:176
TESRegionDataManager * regionDataManager
Definition: TESDataHandler.h:185
FormID LookupFormIDRaw(FormID a_rawFormID, std::string_view a_modName)
BSTArray< TESForm * > formArrays[std::to_underlying(FormType::Max)]
Definition: TESDataHandler.h:170
TESFile ** GetLoadedMods() noexcept
Definition: TESDataHandler.h:101
std::uint32_t pad004
Definition: TESDataHandler.h:168
TESFile ** GetLoadedLightMods() noexcept
Definition: TESDataHandler.h:125
InventoryChanges * GetMerchantInventory() noexcept
Definition: TESDataHandler.h:157
std::uint16_t GetLoadedLightModCount() const noexcept
Definition: TESDataHandler.h:141
FormID nextID
Definition: TESDataHandler.h:175
const InventoryChanges * GetMerchantInventory() const noexcept
Definition: TESDataHandler.h:161
BSSimpleList< TESFile * > files
Definition: TESDataHandler.h:178
const TESFile * LookupLoadedModByIndex(std::uint8_t a_index)
BSTArray< TESForm * > & GetFormArray(FormType a_formType)
bool AddFormToDataHandler(TESForm *a_form)
TESRegionDataManager * GetRegionDataManager() noexcept
Definition: TESDataHandler.h:149
const TESFile * LookupLoadedLightModByName(std::string_view a_modName)
InventoryChanges * merchantInventory
Definition: TESDataHandler.h:186
const TESFile * LookupModByName(std::string_view a_modName)
std::uint8_t GetLoadedModCount() const noexcept
Definition: TESDataHandler.h:117
NiTList< TESForm * > badForms
Definition: TESDataHandler.h:174
TESObjectList * objectList
Definition: TESDataHandler.h:169
const TESFile * LookupLoadedLightModByIndex(std::uint16_t a_index)
std::optional< std::uint8_t > GetLoadedModIndex(std::string_view a_modName)
const TESFile * LookupLoadedModByName(std::string_view a_modName)
BSTArray< T * > & GetFormArray()
Definition: TESDataHandler.h:222
std::uint8_t pad001
Definition: TESDataHandler.h:166
const TESFile *const * GetLoadedMods() const noexcept
Definition: TESDataHandler.h:109
TESForm * LookupForm(FormID a_localFormID, std::string_view a_modName)
std::uint32_t LoadScripts()
NiTPrimitiveArray< TESObjectCELL * > interiorCells
Definition: TESDataHandler.h:172
TESRegionList * regionList
Definition: TESDataHandler.h:171
NiTPrimitiveArray< BGSAddonNode * > addonNodes
Definition: TESDataHandler.h:173
TESFile * activeFile
Definition: TESDataHandler.h:177
RUNTIME_DATA_CONTENT std::uint8_t unkDAA
Definition: TESDataHandler.h:182
std::optional< std::uint8_t > GetModIndex(std::string_view a_modName)
std::uint32_t padDAC
Definition: TESDataHandler.h:184
const RUNTIME_DATA & GetGeometryRuntimeData() const noexcept
Definition: TESDataHandler.h:96
std::optional< std::uint16_t > GetLoadedLightModIndex(std::string_view a_modName)
const TESFile *const * GetLoadedLightMods() const noexcept
Definition: TESDataHandler.h:133
TESFileCollection compiledFileCollection
Definition: TESDataHandler.h:180
static TESDataHandler * GetSingleton()
FormID LookupFormID(FormID a_localFormID, std::string_view a_modName)
ObjectRefHandle CreateReferenceAtLocation(TESBoundObject *a_base, const NiPoint3 &a_location, const NiPoint3 &a_rotation, TESObjectCELL *a_targetCell, TESWorldSpace *a_selfWorldSpace, TESObjectREFR *a_alreadyCreatedRef, BGSPrimitive *a_primitive, const ObjectRefHandle &a_linkedRoomRefHandle, bool a_forcePersist, bool a_arg11)
RUNTIME_DATA & GetGeometryRuntimeData() noexcept
Definition: TESDataHandler.h:91
std::uint16_t pad002
Definition: TESDataHandler.h:167
bool IsGeneratedID(FormID a_formID)
std::uint8_t padDAB
Definition: TESDataHandler.h:183
Definition: TESFile.h:17
Definition: TESForm.h:36
Definition: TESObjectCELL.h:116
Definition: TESObjectREFR.h:113
Definition: TESRegionDataManager.h:18
Definition: TESRegionList.h:10
Definition: TESWorldSpace.h:118
Definition: AbsorbEffect.h:6
FormType
Definition: FormTypes.h:139
std::uint32_t FormID
Definition: BSCoreTypes.h:5
Definition: BSTSingleton.h:50
Definition: TESDataHandler.h:75
Definition: TESDataHandler.h:30
BSTArray< TESFile * > smallFiles
Definition: TESDataHandler.h:34
BSTArray< TESFile * > files
Definition: TESDataHandler.h:33
Definition: TESDataHandler.h:22
std::uint8_t pad0
Definition: TESDataHandler.h:25