CommonLibSSE (Parapets fork)
TESForm.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSAtomic.h"
4 #include "RE/B/BSFixedString.h"
5 #include "RE/B/BSTArray.h"
6 #include "RE/B/BSTHashMap.h"
8 #include "RE/F/FormTypes.h"
9 
10 namespace RE
11 {
12  class BGSLoadFormBuffer;
13  class BGSSaveFormBuffer;
14  class TESBoundObject;
15  class TESFile;
16  struct FORM;
17  struct FORM_GROUP;
18 
19  class TESFileArray : public BSStaticArray<TESFile*>
20  {
21  public:
22  };
23  static_assert(sizeof(TESFileArray) == 0x10);
24 
26  {
27  public:
28  // members
30  };
31  static_assert(sizeof(TESFileContainer) == 0x8);
32 
33  class TESForm : public BaseFormComponent
34  {
35  public:
36  inline static constexpr auto RTTI = RTTI_TESForm;
37  inline static constexpr auto FORMTYPE = FormType::None;
38 
39  struct ChangeFlags
40  {
41  enum ChangeFlag : std::uint32_t
42  {
43  kCreated = 0,
44  kFlags = 1 << 0
45  };
46  };
47 
48  struct RecordFlags
49  {
50  enum RecordFlag : std::uint32_t
51  {
52  kDestructible = 1 << 0,
53  kMaster = 1 << 0,
54  kUnlocked = 1 << 0,
55 
56  kAltered = 1 << 1,
57  kPlayable = 1 << 2,
58  kInitialized = 1 << 3,
59  kNonOccluder = 1 << 4,
60  kDeleted = 1 << 5,
61 
62  kBorderRegion = 1 << 6,
63  kGlobalConstant = 1 << 6,
64  kHasSpokenFlag = 1 << 6,
65  kKnown = 1 << 6,
67 
68  kFireOff = 1 << 7,
69  kMustUpdate = 1 << 8,
70  kOnLocalMap = 1 << 9,
71  kPersistent = 1 << 10,
72 
73  kDisabled = 1 << 11,
75 
76  kIgnored = 1 << 12,
77 
78  kEmpty = 1 << 13,
79  kResetDestruction = 1 << 13,
80 
81  kTemporary = 1 << 14,
83  kRandomAnim = 1 << 16,
84  kDangerous = 1 << 17,
85  kHasCurrents = 1 << 19,
87  kStillLoading = 1 << 21,
88  kFormRetainsID = 1 << 22,
89  kDestroyed = 1 << 23,
90 
91  kNoAIAcquire = 1 << 25,
92  kObstacle = 1 << 25,
93 
95  kDisableFade = 1 << 27,
96 
98  kShowOnWorldMap = 1 << 28,
99 
100  kChildCanUse = 1 << 29
101  };
102  };
103 
104  enum class InGameFormFlag
105  {
106  kNone = 0,
107  kWantsDelete = 1 << 0,
108  kForcedPersistent = 1 << 1,
109  kNoFavorAllowed = 1 << 4,
110  kIsSkyObject = 1 << 5,
111  kRefOriginalPersistent = 1 << 6,
112  kRefPermanentlyDeleted = 1 << 7
113  };
114 
115  ~TESForm() override; // 00
116 
117  // override (BaseFormComponent)
118  void InitializeDataComponent() override; // 01 - { return; }
119  void ClearDataComponent() override; // 02 - { SetEditorID(""); }
120  void CopyComponent(BaseFormComponent* a_rhs) override; // 03
121 
122  // add
123  virtual void InitializeData(); // 04 - { return; }
124  virtual void ClearData(); // 05 - { return; }
125  virtual bool Load(TESFile* a_mod); // 06 - { return true; }
126  virtual bool LoadPartial(TESFile* a_mod); // 07 - { return true; }
127  virtual bool LoadEdit(TESFile* a_mod); // 08 - { return Load(a_mod); }
128  virtual TESForm* CreateDuplicateForm(bool a_createEditorID, void* a_arg2); // 09
129  virtual bool AddChange(std::uint32_t a_changeFlags); // 0A
130  virtual void RemoveChange(std::uint32_t a_changeFlags); // 0B
131  virtual bool FindInFileFast(TESFile* a_mod); // 0C - { return false; }
132  virtual bool CheckSaveGame(BGSSaveFormBuffer* a_buf); // 0D - { return true; }
133  virtual void SaveGame(BGSSaveFormBuffer* a_buf); // 0E
134  virtual void LoadGame(BGSLoadFormBuffer* a_buf); // 0F
135  virtual void InitLoadGame(BGSLoadFormBuffer* a_buf); // 10 - { return; }
136  virtual void FinishLoadGame(BGSLoadFormBuffer* a_buf); // 11 - { return; }
137  virtual void Revert(BGSLoadFormBuffer* a_buf); // 12 - { return; }
138  virtual void InitItemImpl(); // 13 - { return; }
139  [[nodiscard]] virtual TESFile* GetDescriptionOwnerFile() const; // 14 - returns the file that last modified this form
140  [[nodiscard]] virtual FormType GetSavedFormType() const; // 15 - { return formType; }
141  virtual void GetFormDetailedString(char* a_buf, std::uint32_t a_bufLen); // 16 - { return std::sprintf_s(a_buf, a_bufLen, "%s Form '%s' (%08X)", g_formStrings[3 * formID], "", formID); }
142  [[nodiscard]] virtual bool GetKnown() const; // 17 - { return (flags >> 6 ) & 1; }
143  [[nodiscard]] virtual bool GetRandomAnim() const; // 18 - { return (flags >> 16) & 1; }
144  [[nodiscard]] virtual bool GetPlayable() const; // 19 - { return (flags >> 2) & 1; }
145  [[nodiscard]] virtual bool IsHeadingMarker() const; // 1A - { return false; }
146  [[nodiscard]] virtual bool GetDangerous() const; // 1B - { return (flags >> 17) & 1; }
147  [[nodiscard]] virtual bool QHasCurrents() const; // 1C - { return (flags >> 19) & 1; }
148  [[nodiscard]] virtual bool GetObstacle() const; // 1D - { return (flags >> 25) & 1; }
149  [[nodiscard]] virtual bool QIsLODLandObject() const; // 1E - { return false; }
150  [[nodiscard]] virtual bool GetOnLocalMap() const; // 1F - { return (flags >> 9) & 1; }
151  [[nodiscard]] virtual bool GetMustUpdate() const; // 20 - { return (flags >> 8) & 1; }
152  virtual void SetOnLocalMap(bool a_set); // 21 - { if (a_set) flags &= 0xFFFFFDFF; else flags |= 0x200; }
153  [[nodiscard]] virtual bool GetIgnoredBySandbox() const; // 22 - { return false; }
154  virtual void SetDelete(bool a_set); // 23 - { bool result = (flags >> 5) & 1; if (result != a_set) { if (a_set) flags |= 0x20; else flags &= 0xFFFFFFDF; AddChange(1); return result; }
155  virtual void SetAltered(bool a_set); // 24
156  virtual void SaveObjectBound(); // 25 - { return; }
157  virtual void LoadObjectBound(TESFile* a_mod); // 26 - { return; }
158  [[nodiscard]] virtual bool IsBoundObject() const; // 27 - { return false; }
159  [[nodiscard]] virtual bool IsObject() const; // 28 - { return false; }
160  [[nodiscard]] virtual bool IsMagicItem() const; // 29 - { return false; }
161  [[nodiscard]] virtual bool IsWater() const; // 2A - { return false; }
162  virtual TESObjectREFR* AsReference1(); // 2B - { return 0; }
163  [[nodiscard]] virtual const TESObjectREFR* AsReference2() const; // 2C - { return 0; }
164  [[nodiscard]] virtual std::uint32_t GetRefCount() const; // 2D - { return 0; }
165  [[nodiscard]] virtual const char* GetTextForParsedSubTag(const BSFixedString& a_tag) const; // 2E
166  virtual void Copy(TESForm* a_srcForm); // 2F - { return; }
167  virtual bool BelongsInGroup(FORM* a_form, bool a_allowParentGroups, bool a_currentOnly); // 30
168  virtual void CreateGroupData(FORM* a_form, FORM_GROUP* a_group); // 31
169  [[nodiscard]] virtual const char* GetFormEditorID() const; // 32 - { return ""; }
170  virtual bool SetFormEditorID(const char* a_str); // 33 - { return true; }
171  virtual bool IsParentForm(); // 34 - { return false; }
172  virtual bool IsParentFormTree(); // 35 - { return false; }
173  virtual bool IsFormTypeChild(FormType a_type); // 36 - { return false; }
174  virtual bool Activate(TESObjectREFR* a_targetRef, TESObjectREFR* a_activatorRef, std::uint8_t a_arg3, TESBoundObject* a_object, std::int32_t a_targetCount); // 37 - { return false; }
175  virtual void SetFormID(FormID a_id, bool a_updateFile); // 38
176  [[nodiscard]] virtual const char* GetObjectTypeName() const; // 39 - { return ""; }
177  [[nodiscard]] virtual bool QAvailableInGame() const; // 3A - { return true; }
178 
179  static void AddCompileIndex(FormID& a_id, TESFile* a_file);
180 
181  [[nodiscard]] static auto GetAllForms()
182  -> std::pair<
184  std::reference_wrapper<BSReadWriteLock>>;
185 
186  [[nodiscard]] static auto GetAllFormsByEditorID()
187  -> std::pair<
189  std::reference_wrapper<BSReadWriteLock>>;
190 
191  [[nodiscard]] static TESForm* LookupByID(FormID a_formID);
192 
193  template <class T>
194  [[nodiscard]] static T* LookupByID(FormID a_formID)
195  {
196  const auto form = LookupByID(a_formID);
197  return form ? form->As<T>() : nullptr;
198  }
199 
200  [[nodiscard]] static TESForm* LookupByEditorID(const std::string_view& a_editorID);
201 
202  template <class T>
203  [[nodiscard]] static T* LookupByEditorID(const std::string_view& a_editorID)
204  {
205  const auto form = LookupByEditorID(a_editorID);
206  return form ? form->As<T>() : nullptr;
207  }
208 
209  template <class T>
210  requires(std::is_class_v<T>)
211  [[nodiscard]] T* As() noexcept
212  {
213  return const_cast<T*>(
214  static_cast<const TESForm*>(this)->As<T>());
215  }
216 
217  template <class T>
218  requires(requires { T::FORMTYPE; })
219  [[nodiscard]] const T* As() const noexcept
220  {
221  if (GetFormType() == T::FORMTYPE) {
222  return static_cast<const T*>(this);
223  } else {
224  return nullptr;
225  }
226  }
227 
228  template <class T>
229  requires(!requires { T::FORMTYPE; })
230  [[nodiscard]] const T* As() const noexcept;
231 
232  [[nodiscard]] TESObjectREFR* AsReference() { return AsReference1(); }
233  [[nodiscard]] const TESObjectREFR* AsReference() const { return AsReference2(); }
234 
235  [[nodiscard]] TESFile* GetFile(std::int32_t a_idx = -1) const
236  {
237  const auto array = sourceFiles.array;
238  if (!array || array->empty()) {
239  return nullptr;
240  }
241 
242  if (a_idx < 0 || static_cast<std::uint32_t>(a_idx) >= array->size()) {
243  return array->back();
244  } else {
245  return (*array)[a_idx];
246  }
247  }
248 
249  [[nodiscard]] std::uint32_t GetFormFlags() const noexcept { return formFlags; }
250  [[nodiscard]] FormID GetFormID() const noexcept { return formID; }
251  [[nodiscard]] FormType GetFormType() const noexcept { return *formType; }
252  [[nodiscard]] std::int32_t GetGoldValue() const;
253  [[nodiscard]] const char* GetName() const;
254  [[nodiscard]] float GetWeight() const;
255  [[nodiscard]] bool HasVMAD() const;
256  [[nodiscard]] bool HasWorldModel() const noexcept;
257  void InitItem() { InitItemImpl(); }
258 
259  [[nodiscard]] bool Is(FormType a_type) const noexcept { return GetFormType() == a_type; }
260 
261  template <class... Args>
262  [[nodiscard]] bool Is(Args... a_args) const noexcept //
263  requires(std::same_as<Args, FormType>&&...)
264  {
265  return (Is(a_args) || ...);
266  }
267 
268  [[nodiscard]] bool IsAmmo() const noexcept { return Is(FormType::Ammo); }
269  [[nodiscard]] bool IsArmor() const noexcept { return Is(FormType::Armor); }
270  [[nodiscard]] bool IsBook() const noexcept { return Is(FormType::Book); }
271  [[nodiscard]] bool IsDeleted() const noexcept { return (GetFormFlags() & RecordFlags::kDeleted) != 0; }
272  [[nodiscard]] bool IsDynamicForm() const noexcept { return GetFormID() >= 0xFF000000; }
273  [[nodiscard]] bool IsGold() const noexcept { return GetFormID() == 0x0000000F; }
274  [[nodiscard]] bool IsIgnored() const noexcept { return (GetFormFlags() & RecordFlags::kIgnored) != 0; }
275  [[nodiscard]] bool IsInitialized() const noexcept { return (GetFormFlags() & RecordFlags::kInitialized) != 0; }
276  [[nodiscard]] bool IsKey() const noexcept { return Is(FormType::KeyMaster); }
277  [[nodiscard]] bool IsLockpick() const noexcept { return GetFormID() == 0x0000000A; }
278 
279  [[nodiscard]] bool IsNot(FormType a_type) const noexcept { return !Is(a_type); }
280 
281  template <class... Args>
282  [[nodiscard]] bool IsNot(Args... a_args) const noexcept //
283  requires(std::same_as<Args, FormType>&&...)
284  {
285  return (IsNot(a_args) && ...);
286  }
287 
288  [[nodiscard]] bool IsNote() const noexcept { return Is(FormType::Note); }
289  [[nodiscard]] bool IsPlayer() const noexcept { return GetFormID() == 0x00000007; }
290  [[nodiscard]] bool IsPlayerRef() const noexcept { return GetFormID() == 0x00000014; }
291  [[nodiscard]] bool IsSoulGem() const noexcept { return Is(FormType::SoulGem); }
292  [[nodiscard]] bool IsWeapon() const noexcept { return Is(FormType::Weapon); }
293 
294  // members
296  std::uint32_t formFlags; // 10
297  FormID formID; // 14
300  std::uint8_t pad1B; // 1B
301  std::uint32_t pad1C; // 1C
302  };
303  static_assert(sizeof(TESForm) == 0x20);
304 }
Definition: BSTArray.h:707
constexpr reference back() noexcept
Definition: BSTArray.h:733
Definition: BSTHashMap.h:21
Definition: BaseFormComponent.h:8
Definition: TESBoundObject.h:24
Definition: TESForm.h:20
Definition: TESForm.h:26
TESFileArray * array
Definition: TESForm.h:29
Definition: TESFile.h:14
Definition: TESForm.h:34
bool IsLockpick() const noexcept
Definition: TESForm.h:277
virtual void InitItemImpl()
virtual void SaveGame(BGSSaveFormBuffer *a_buf)
virtual bool LoadEdit(TESFile *a_mod)
virtual bool IsFormTypeChild(FormType a_type)
virtual void LoadGame(BGSLoadFormBuffer *a_buf)
virtual bool IsBoundObject() const
virtual void SetAltered(bool a_set)
virtual bool QAvailableInGame() const
bool IsNot(Args... a_args) const noexcept requires(std
Definition: TESForm.h:282
virtual void SetFormID(FormID a_id, bool a_updateFile)
virtual const TESObjectREFR * AsReference2() const
static void AddCompileIndex(FormID &a_id, TESFile *a_file)
virtual const char * GetTextForParsedSubTag(const BSFixedString &a_tag) const
void CopyComponent(BaseFormComponent *a_rhs) override
virtual bool QHasCurrents() const
virtual void InitializeData()
requires(!requires { T::FORMTYPE;}) const T *As() const noexcept
virtual bool GetIgnoredBySandbox() const
virtual bool GetMustUpdate() const
virtual bool GetDangerous() const
static auto GetAllFormsByEditorID() -> std::pair< BSTHashMap< BSFixedString, TESForm * > *, std::reference_wrapper< BSReadWriteLock >>
virtual bool SetFormEditorID(const char *a_str)
bool IsDeleted() const noexcept
Definition: TESForm.h:271
InGameFormFlag
Definition: TESForm.h:105
std::uint8_t pad1B
Definition: TESForm.h:300
bool IsWeapon() const noexcept
Definition: TESForm.h:292
static auto GetAllForms() -> std::pair< BSTHashMap< FormID, TESForm * > *, std::reference_wrapper< BSReadWriteLock >>
virtual bool GetPlayable() const
virtual void SetOnLocalMap(bool a_set)
virtual bool AddChange(std::uint32_t a_changeFlags)
bool HasWorldModel() const noexcept
stl::enumeration< FormType, std::uint8_t > formType
Definition: TESForm.h:299
requires(requires { T::FORMTYPE;}) const T *As() const noexcept
Definition: TESForm.h:218
const TESObjectREFR * AsReference() const
Definition: TESForm.h:233
virtual void Copy(TESForm *a_srcForm)
virtual void RemoveChange(std::uint32_t a_changeFlags)
virtual bool IsParentFormTree()
static T * LookupByEditorID(const std::string_view &a_editorID)
Definition: TESForm.h:203
bool IsInitialized() const noexcept
Definition: TESForm.h:275
virtual void CreateGroupData(FORM *a_form, FORM_GROUP *a_group)
bool IsArmor() const noexcept
Definition: TESForm.h:269
TESObjectREFR * AsReference()
Definition: TESForm.h:232
virtual void InitLoadGame(BGSLoadFormBuffer *a_buf)
FormType GetFormType() const noexcept
Definition: TESForm.h:251
virtual bool IsHeadingMarker() const
virtual bool IsObject() const
virtual void Revert(BGSLoadFormBuffer *a_buf)
virtual void LoadObjectBound(TESFile *a_mod)
static TESForm * LookupByEditorID(const std::string_view &a_editorID)
static TESForm * LookupByID(FormID a_formID)
virtual bool IsWater() const
static constexpr auto RTTI
Definition: TESForm.h:36
bool IsAmmo() const noexcept
Definition: TESForm.h:268
virtual void FinishLoadGame(BGSLoadFormBuffer *a_buf)
virtual bool GetRandomAnim() const
virtual bool Activate(TESObjectREFR *a_targetRef, TESObjectREFR *a_activatorRef, std::uint8_t a_arg3, TESBoundObject *a_object, std::int32_t a_targetCount)
const char * GetName() const
virtual const char * GetFormEditorID() const
virtual bool BelongsInGroup(FORM *a_form, bool a_allowParentGroups, bool a_currentOnly)
virtual TESForm * CreateDuplicateForm(bool a_createEditorID, void *a_arg2)
stl::enumeration< InGameFormFlag, std::uint16_t > inGameFormFlags
Definition: TESForm.h:298
virtual void GetFormDetailedString(char *a_buf, std::uint32_t a_bufLen)
virtual bool IsParentForm()
void ClearDataComponent() override
virtual void SetDelete(bool a_set)
virtual bool CheckSaveGame(BGSSaveFormBuffer *a_buf)
bool IsIgnored() const noexcept
Definition: TESForm.h:274
FormID formID
Definition: TESForm.h:297
requires(std::is_class_v< T >) T *As() noexcept
Definition: TESForm.h:210
virtual std::uint32_t GetRefCount() const
bool IsNot(FormType a_type) const noexcept
Definition: TESForm.h:279
virtual TESFile * GetDescriptionOwnerFile() const
static T * LookupByID(FormID a_formID)
Definition: TESForm.h:194
virtual void ClearData()
FormID GetFormID() const noexcept
Definition: TESForm.h:250
std::uint32_t pad1C
Definition: TESForm.h:301
bool Is(FormType a_type) const noexcept
Definition: TESForm.h:259
std::int32_t GetGoldValue() const
bool IsPlayerRef() const noexcept
Definition: TESForm.h:290
virtual bool FindInFileFast(TESFile *a_mod)
float GetWeight() const
virtual const char * GetObjectTypeName() const
virtual bool GetKnown() const
virtual void SaveObjectBound()
bool HasVMAD() const
virtual bool GetObstacle() const
virtual bool IsMagicItem() const
virtual bool Load(TESFile *a_mod)
virtual bool QIsLODLandObject() const
virtual TESObjectREFR * AsReference1()
bool IsDynamicForm() const noexcept
Definition: TESForm.h:272
TESFileContainer sourceFiles
Definition: TESForm.h:295
TESFile * GetFile(std::int32_t a_idx=-1) const
Definition: TESForm.h:235
std::uint32_t GetFormFlags() const noexcept
Definition: TESForm.h:249
void InitItem()
Definition: TESForm.h:257
std::uint32_t formFlags
Definition: TESForm.h:296
static constexpr auto FORMTYPE
Definition: TESForm.h:37
bool IsGold() const noexcept
Definition: TESForm.h:273
virtual FormType GetSavedFormType() const
void InitializeDataComponent() override
bool Is(Args... a_args) const noexcept requires(std
Definition: TESForm.h:262
bool IsSoulGem() const noexcept
Definition: TESForm.h:291
bool IsNote() const noexcept
Definition: TESForm.h:288
bool IsPlayer() const noexcept
Definition: TESForm.h:289
bool IsBook() const noexcept
Definition: TESForm.h:270
~TESForm() override
virtual bool LoadPartial(TESFile *a_mod)
virtual bool GetOnLocalMap() const
bool IsKey() const noexcept
Definition: TESForm.h:276
Definition: TESObjectREFR.h:105
Definition: AbsorbEffect.h:6
FormType
Definition: FormTypes.h:139
std::uint32_t FormID
Definition: BSCoreTypes.h:5
constexpr REL::ID RTTI_TESForm
Definition: Offsets_RTTI.h:5995
Definition: FORM.h:20
Definition: FORM.h:6
Definition: TESForm.h:40
ChangeFlag
Definition: TESForm.h:42
@ kCreated
Definition: TESForm.h:43
@ kFlags
Definition: TESForm.h:44
Definition: TESForm.h:49
RecordFlag
Definition: TESForm.h:51
@ kTemporary
Definition: TESForm.h:81
@ kStillLoading
Definition: TESForm.h:87
@ kOnLocalMap
Definition: TESForm.h:70
@ kMaster
Definition: TESForm.h:53
@ kRandomAnim
Definition: TESForm.h:83
@ kResetDestruction
Definition: TESForm.h:79
@ kUsedAsMovingPlatform
Definition: TESForm.h:74
@ kFireOff
Definition: TESForm.h:68
@ kDeleted
Definition: TESForm.h:60
@ kUnlocked
Definition: TESForm.h:54
@ kMustBeVisibleDistant
Definition: TESForm.h:82
@ kReflectedByAutoWater
Definition: TESForm.h:97
@ kInPlaceableWater
Definition: TESForm.h:66
@ kVATSTargetOverride
Definition: TESForm.h:94
@ kDisabled
Definition: TESForm.h:73
@ kNoAIAcquire
Definition: TESForm.h:91
@ kAltered
Definition: TESForm.h:56
@ kIgnoreFriendlyHits
Definition: TESForm.h:86
@ kDisableFade
Definition: TESForm.h:95
@ kFormRetainsID
Definition: TESForm.h:88
@ kShowOnWorldMap
Definition: TESForm.h:98
@ kInitialized
Definition: TESForm.h:58
@ kDangerous
Definition: TESForm.h:84
@ kEmpty
Definition: TESForm.h:78
@ kMustUpdate
Definition: TESForm.h:69
@ kDestructible
Definition: TESForm.h:52
@ kIgnored
Definition: TESForm.h:76
@ kObstacle
Definition: TESForm.h:92
@ kChildCanUse
Definition: TESForm.h:100
@ kHasCurrents
Definition: TESForm.h:85
@ kBorderRegion
Definition: TESForm.h:62
@ kGlobalConstant
Definition: TESForm.h:63
@ kPlayable
Definition: TESForm.h:57
@ kKnown
Definition: TESForm.h:65
@ kPersistent
Definition: TESForm.h:71
@ kDestroyed
Definition: TESForm.h:89
@ kNonOccluder
Definition: TESForm.h:59
@ kHasSpokenFlag
Definition: TESForm.h:64