CommonLibVR
Interfaces.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "SKSE/Impl/Stubs.h"
4 #include "SKSE/Version.h"
5 
6 namespace RE
7 {
8  class GFxMovieView;
9  class GFxValue;
10  class InventoryEntryData;
11 
12  namespace BSScript
13  {
14  namespace Internal
15  {
16  class VirtualMachine;
17  }
18 
19  class IVirtualMachine;
20  }
21 }
22 
23 namespace SKSE
24 {
25  struct PluginInfo;
26 
28  {
29  public:
30  [[nodiscard]] std::uint32_t EditorVersion() const;
31  [[nodiscard]] bool IsEditor() const;
32  [[nodiscard]] REL::Version RuntimeVersion() const;
33  [[nodiscard]] std::uint32_t SKSEVersion() const;
34 
35  protected:
36  [[nodiscard]] const detail::SKSEInterface* GetProxy() const;
37  };
38 
40  {
41  public:
42  enum : std::uint32_t
43  {
44  kInvalid = 0,
52  kTotal
53  };
54 
55  [[nodiscard]] PluginHandle GetPluginHandle() const;
56  const PluginInfo* GetPluginInfo(const char* a_name) const;
57  [[nodiscard]] std::uint32_t GetReleaseIndex() const;
58  [[nodiscard]] void* QueryInterface(std::uint32_t a_id) const;
59  };
60 
62  {
63  public:
64  using RegCallback = bool(RE::GFxMovieView* a_view, RE::GFxValue* a_root);
65  using RegInvCallback = void(RE::GFxMovieView* a_view, RE::GFxValue* a_object, RE::InventoryEntryData* a_item);
66 
67  enum
68  {
69  kVersion = 2
70  };
71 
72  [[nodiscard]] std::uint32_t Version() const;
73 
74  bool Register(RegCallback* a_callback, const char* a_name) const;
75  void Register(RegInvCallback* a_callback) const;
76 
77  protected:
78  [[nodiscard]] const detail::SKSEScaleformInterface* GetProxy() const;
79  };
80 
82  {
83  public:
84  using EventCallback = void(SerializationInterface* a_intfc);
85  using FormDeleteCallback = void(RE::VMHandle a_handle);
86 
87  enum
88  {
89  kVersion = 4
90  };
91 
92  [[nodiscard]] std::uint32_t Version() const;
93 
94  void SetUniqueID(std::uint32_t a_uid) const;
95 
96  void SetFormDeleteCallback(FormDeleteCallback* a_callback) const;
97  void SetLoadCallback(EventCallback* a_callback) const;
98  void SetRevertCallback(EventCallback* a_callback) const;
99  void SetSaveCallback(EventCallback* a_callback) const;
100 
101  bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const void* a_buf, std::uint32_t a_length) const;
102 
103  template <
104  class T,
105  std::enable_if_t<
106  std::negation_v<
107  std::is_pointer<T>>,
108  int> = 0>
109  inline bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T& a_buf) const
110  {
111  return WriteRecord(a_type, a_version, std::addressof(a_buf), sizeof(T));
112  }
113 
114  template <
115  class T,
116  std::size_t N,
117  std::enable_if_t<
118  std::is_array_v<T>,
119  int> = 0>
120  inline bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T (&a_buf)[N]) const
121  {
122  return WriteRecord(a_type, a_version, std::addressof(a_buf), sizeof(T) * N);
123  }
124 
125  [[nodiscard]] bool OpenRecord(std::uint32_t a_type, std::uint32_t a_version) const;
126 
127  bool WriteRecordData(const void* a_buf, std::uint32_t a_length) const;
128 
129  template <
130  class T,
131  std::enable_if_t<
132  std::negation_v<
133  std::is_pointer<T>>,
134  int> = 0>
135  inline bool WriteRecordData(const T& a_buf) const
136  {
137  return WriteRecordData(std::addressof(a_buf), sizeof(T));
138  }
139 
140  template <
141  class T,
142  std::size_t N,
143  std::enable_if_t<
144  std::is_array_v<T>,
145  int> = 0>
146  inline bool WriteRecordData(const T (&a_buf)[N]) const
147  {
148  return WriteRecordData(std::addressof(a_buf), sizeof(T) * N);
149  }
150 
151  bool GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const;
152 
153  std::uint32_t ReadRecordData(void* a_buf, std::uint32_t a_length) const;
154 
155  template <
156  class T,
157  std::enable_if_t<
158  std::negation_v<
159  std::is_pointer<T>>,
160  int> = 0>
161  inline std::uint32_t ReadRecordData(T& a_buf) const
162  {
163  return ReadRecordData(std::addressof(a_buf), sizeof(T));
164  }
165 
166  template <
167  class T,
168  std::size_t N,
169  std::enable_if_t<
170  std::is_array_v<T>,
171  int> = 0>
172  inline std::uint32_t ReadRecordData(T (&a_buf)[N]) const
173  {
174  return ReadRecordData(std::addressof(a_buf), sizeof(T) * N);
175  }
176 
177  bool ResolveFormID(RE::FormID a_oldFormID, RE::FormID& a_newFormID) const;
178  bool ResolveHandle(RE::VMHandle a_oldHandle, RE::VMHandle& a_newHandle) const;
179 
180  protected:
181  [[nodiscard]] const detail::SKSESerializationInterface* GetProxy() const;
182  };
183 
185  {
186  public:
187  using TaskFn = std::function<void()>;
188 
189  enum
190  {
191  kVersion = 2
192  };
193 
194  [[nodiscard]] std::uint32_t Version() const;
195 
196  void AddTask(TaskFn a_task) const;
197  void AddTask(TaskDelegate* a_task) const;
198  void AddUITask(TaskFn a_task) const;
199  void AddUITask(UIDelegate_v1* a_task) const;
200 
201  protected:
202  class Task : public detail::TaskDelegate
203  {
204  public:
205  Task(TaskFn&& a_fn);
206 
207  void Run() override;
208  void Dispose() override;
209 
210  private:
211  TaskFn _fn;
212  };
213 
215  {
216  public:
217  UITask(TaskFn&& a_fn);
218 
219  void Run() override;
220  void Dispose() override;
221 
222  private:
223  TaskFn _fn;
224  };
225 
226  [[nodiscard]] const detail::SKSETaskInterface* GetProxy() const;
227  };
228 
230  {
231  public:
234 
235  enum
236  {
237  kVersion = 1
238  };
239 
240  [[nodiscard]] std::uint32_t Version() const;
241 
242  template <class Last>
243  bool Register(Last a_last) const
244  {
245  return Register_Impl(a_last);
246  }
247 
248  template <class First, class... Rest>
249  bool Register(First a_first, Rest... a_rest) const
250  {
251  return Register_Impl(a_first) && Register(a_rest...);
252  }
253 
254  protected:
255  [[nodiscard]] const detail::SKSEPapyrusInterface* GetProxy() const;
256 
257  private:
258  bool Register_Impl(RegFunction1* a_fn) const;
259  bool Register_Impl(RegFunction2* a_fn) const;
260  };
261 
263  {
264  public:
265  struct Message
266  {
267  const char* sender;
268  std::uint32_t type;
269  std::uint32_t dataLen;
270  void* data;
271  };
272 
273  using EventCallback = void(Message* a_msg);
274 
275  enum
276  {
277  kVersion = 2
278  };
279 
280  enum : std::uint32_t
281  {
291 
292  kTotal
293  };
294 
295  enum class Dispatcher : std::uint32_t
296  {
297  kModEvent = 0,
298  kCameraEvent,
300  kActionEvent,
302 
303  kTotal
304  };
305 
306  [[nodiscard]] std::uint32_t Version() const;
307 
308  bool Dispatch(std::uint32_t a_messageType, void* a_data, std::uint32_t a_dataLen, const char* a_receiver) const;
309  [[nodiscard]] void* GetEventDispatcher(Dispatcher a_dispatcherID) const;
310  bool RegisterListener(EventCallback* a_callback) const;
311  bool RegisterListener(const char* a_sender, EventCallback* a_callback) const;
312 
313  protected:
314  [[nodiscard]] const detail::SKSEMessagingInterface* GetProxy() const;
315  };
316 
318  {
319  public:
320  enum
321  {
322  kVersion = 1
323  };
324 
325  [[nodiscard]] std::uint32_t Version() const;
326 
327  [[nodiscard]] SKSEDelayFunctorManager& GetDelayFunctorManager() const;
328  [[nodiscard]] SKSEObjectRegistry& GetObjectRegistry() const;
329  [[nodiscard]] SKSEPersistentObjectStorage& GetPersistentObjectStorage() const;
330 
331  private:
332  [[nodiscard]] const detail::SKSEObjectInterface* GetProxy() const;
333  };
334 
336  {
337  public:
338  enum
339  {
340  kVersion = 1
341  };
342 
343  [[nodiscard]] std::uint32_t Version() const;
344 
345  [[nodiscard]] void* AllocateFromBranchPool(std::size_t a_size) const;
346  [[nodiscard]] void* AllocateFromLocalPool(std::size_t a_size) const;
347 
348  private:
349  [[nodiscard]] const detail::SKSETrampolineInterface* GetProxy() const;
350  };
351 
352  struct PluginInfo
353  {
354  enum
355  {
356  kVersion = 1
357  };
358 
359  std::uint32_t infoVersion;
360  const char* name;
361  std::uint32_t version;
362  };
363 
364 #ifdef SKYRIM_SUPPORT_AE
365  struct PluginVersionData
366  {
367  public:
368  enum
369  {
370  kVersion = 1,
371  };
372 
373  enum
374  {
375  kVersionIndependent_AddressLibraryPostAE = 1 << 0,
376  kVersionIndependent_Signatures = 1 << 1,
377  kVersionIndependent_StructsPost629 = 1 << 2,
378  };
379 
380  enum
381  {
382  kVersionIndependentEx_NoStructUse = 1 << 0,
383  };
384 
385  constexpr void PluginVersion(REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }
386 
387  [[nodiscard]] constexpr REL::Version GetPluginVersion() const noexcept { return REL::Version::unpack(pluginVersion); }
388 
389  constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); }
390 
391  [[nodiscard]] constexpr std::string_view GetPluginName() const noexcept { return std::string_view{ pluginName }; }
392 
393  constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); }
394 
395  [[nodiscard]] constexpr std::string_view GetAuthorName() const noexcept { return std::string_view{ author }; }
396 
397  constexpr void AuthorEmail(std::string_view a_email) noexcept { SetCharBuffer(a_email, std::span{ supportEmail }); }
398 
399  [[nodiscard]] constexpr std::string_view GetAuthorEmail() const noexcept { return std::string_view{ supportEmail }; }
400 
401  constexpr void UsesAddressLibrary() noexcept { versionIndependence |= kVersionIndependent_AddressLibraryPostAE; }
402  constexpr void UsesSigScanning() noexcept { versionIndependence |= kVersionIndependent_Signatures; }
403  constexpr void UsesUpdatedStructs() noexcept { versionIndependence |= kVersionIndependent_StructsPost629; }
404 
405  constexpr void UsesNoStructs() noexcept { versionIndependenceEx |= kVersionIndependentEx_NoStructUse; }
406 
407  constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }
408 
409  constexpr void CompatibleVersions(std::initializer_list<REL::Version> a_versions) noexcept
410  {
411  assert(a_versions.size() < std::size(compatibleVersions) - 1);
412  std::transform(
413  a_versions.begin(),
414  a_versions.end(),
415  std::begin(compatibleVersions),
416  [](const REL::Version& a_version) noexcept { return a_version.pack(); });
417  }
418 
419  [[nodiscard]] static const PluginVersionData* GetSingleton() noexcept;
420 
421  const std::uint32_t dataVersion{ kVersion };
422  std::uint32_t pluginVersion = 0;
423  char pluginName[256] = {};
424  char author[256] = {};
425  char supportEmail[252] = {};
426  std::uint32_t versionIndependenceEx = 0;
427  std::uint32_t versionIndependence = 0;
428  std::uint32_t compatibleVersions[16] = {};
429  std::uint32_t xseMinimum = 0;
430 
431  private:
432  static constexpr void SetCharBuffer(
433  std::string_view a_src,
434  std::span<char> a_dst) noexcept
435  {
436  assert(a_src.size() < a_dst.size());
437  std::fill(a_dst.begin(), a_dst.end(), '\0');
438  std::copy(a_src.begin(), a_src.end(), a_dst.begin());
439  }
440  };
441  static_assert(offsetof(PluginVersionData, dataVersion) == 0x000);
442  static_assert(offsetof(PluginVersionData, pluginVersion) == 0x004);
443  static_assert(offsetof(PluginVersionData, pluginName) == 0x008);
444  static_assert(offsetof(PluginVersionData, author) == 0x108);
445  static_assert(offsetof(PluginVersionData, supportEmail) == 0x208);
446  static_assert(offsetof(PluginVersionData, versionIndependenceEx) == 0x304);
447  static_assert(offsetof(PluginVersionData, versionIndependence) == 0x308);
448  static_assert(offsetof(PluginVersionData, compatibleVersions) == 0x30C);
449  static_assert(offsetof(PluginVersionData, xseMinimum) == 0x34C);
450  static_assert(sizeof(PluginVersionData) == 0x350);
451 #endif
452 }
453 
454 #define SKSEPluginLoad(...) extern "C" [[maybe_unused]] __declspec(dllexport) bool SKSEPlugin_Load(__VA_ARGS__)
455 #define SKSEPluginVersion extern "C" [[maybe_unused]] __declspec(dllexport) constinit SKSE::PluginVersionData SKSEPlugin_Version
Definition: Version.h:6
static constexpr Version unpack(std::uint32_t a_packedVersion) noexcept
Definition: Version.h:97
Definition: IVirtualMachine.h:39
Definition: VirtualMachine.h:46
Definition: GFxMovieView.h:24
Definition: GFxValue.h:92
Definition: InventoryEntryData.h:15
Definition: Interfaces.h:40
void * QueryInterface(std::uint32_t a_id) const
@ kTrampoline
Definition: Interfaces.h:51
@ kMessaging
Definition: Interfaces.h:49
@ kPapyrus
Definition: Interfaces.h:46
@ kSerialization
Definition: Interfaces.h:47
@ kObject
Definition: Interfaces.h:50
@ kTask
Definition: Interfaces.h:48
@ kInvalid
Definition: Interfaces.h:44
@ kScaleform
Definition: Interfaces.h:45
@ kTotal
Definition: Interfaces.h:52
const PluginInfo * GetPluginInfo(const char *a_name) const
PluginHandle GetPluginHandle() const
std::uint32_t GetReleaseIndex() const
Definition: Interfaces.h:263
Dispatcher
Definition: Interfaces.h:296
@ kTotal
Definition: Interfaces.h:292
@ kPostPostLoad
Definition: Interfaces.h:283
@ kPostLoad
Definition: Interfaces.h:282
@ kPreLoadGame
Definition: Interfaces.h:284
@ kSaveGame
Definition: Interfaces.h:286
@ kNewGame
Definition: Interfaces.h:289
@ kDataLoaded
Definition: Interfaces.h:290
@ kInputLoaded
Definition: Interfaces.h:288
@ kDeleteGame
Definition: Interfaces.h:287
@ kPostLoadGame
Definition: Interfaces.h:285
std::uint32_t Version() const
void * GetEventDispatcher(Dispatcher a_dispatcherID) const
bool Dispatch(std::uint32_t a_messageType, void *a_data, std::uint32_t a_dataLen, const char *a_receiver) const
bool RegisterListener(const char *a_sender, EventCallback *a_callback) const
@ kVersion
Definition: Interfaces.h:277
const detail::SKSEMessagingInterface * GetProxy() const
bool RegisterListener(EventCallback *a_callback) const
void(Message *a_msg) EventCallback
Definition: Interfaces.h:273
Definition: Interfaces.h:318
SKSEDelayFunctorManager & GetDelayFunctorManager() const
SKSEPersistentObjectStorage & GetPersistentObjectStorage() const
std::uint32_t Version() const
SKSEObjectRegistry & GetObjectRegistry() const
@ kVersion
Definition: Interfaces.h:322
Definition: Interfaces.h:230
bool Register(First a_first, Rest... a_rest) const
Definition: Interfaces.h:249
std::uint32_t Version() const
const detail::SKSEPapyrusInterface * GetProxy() const
bool(RE::BSScript::Internal::VirtualMachine *a_vm) RegFunction1
Definition: Interfaces.h:232
bool(RE::BSScript::IVirtualMachine *a_vm) RegFunction2
Definition: Interfaces.h:233
bool Register(Last a_last) const
Definition: Interfaces.h:243
@ kVersion
Definition: Interfaces.h:237
Definition: Interfaces.h:28
std::uint32_t EditorVersion() const
REL::Version RuntimeVersion() const
const detail::SKSEInterface * GetProxy() const
std::uint32_t SKSEVersion() const
bool IsEditor() const
Definition: Interfaces.h:62
void(RE::GFxMovieView *a_view, RE::GFxValue *a_object, RE::InventoryEntryData *a_item) RegInvCallback
Definition: Interfaces.h:65
@ kVersion
Definition: Interfaces.h:69
void Register(RegInvCallback *a_callback) const
bool Register(RegCallback *a_callback, const char *a_name) const
const detail::SKSEScaleformInterface * GetProxy() const
std::uint32_t Version() const
bool(RE::GFxMovieView *a_view, RE::GFxValue *a_root) RegCallback
Definition: Interfaces.h:64
Definition: Interfaces.h:82
bool ResolveHandle(RE::VMHandle a_oldHandle, RE::VMHandle &a_newHandle) const
void SetLoadCallback(EventCallback *a_callback) const
void SetFormDeleteCallback(FormDeleteCallback *a_callback) const
std::uint32_t ReadRecordData(T &a_buf) const
Definition: Interfaces.h:161
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T(&a_buf)[N]) const
Definition: Interfaces.h:120
void(SerializationInterface *a_intfc) EventCallback
Definition: Interfaces.h:84
bool WriteRecordData(const T &a_buf) const
Definition: Interfaces.h:135
void(RE::VMHandle a_handle) FormDeleteCallback
Definition: Interfaces.h:85
std::uint32_t ReadRecordData(void *a_buf, std::uint32_t a_length) const
void SetRevertCallback(EventCallback *a_callback) const
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T &a_buf) const
Definition: Interfaces.h:109
void SetUniqueID(std::uint32_t a_uid) const
bool WriteRecordData(const void *a_buf, std::uint32_t a_length) const
bool GetNextRecordInfo(std::uint32_t &a_type, std::uint32_t &a_version, std::uint32_t &a_length) const
void SetSaveCallback(EventCallback *a_callback) const
std::uint32_t ReadRecordData(T(&a_buf)[N]) const
Definition: Interfaces.h:172
const detail::SKSESerializationInterface * GetProxy() const
bool ResolveFormID(RE::FormID a_oldFormID, RE::FormID &a_newFormID) const
@ kVersion
Definition: Interfaces.h:89
bool WriteRecordData(const T(&a_buf)[N]) const
Definition: Interfaces.h:146
std::uint32_t Version() const
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const void *a_buf, std::uint32_t a_length) const
bool OpenRecord(std::uint32_t a_type, std::uint32_t a_version) const
Definition: Interfaces.h:203
void Dispose() override
Definition: Interfaces.h:215
Definition: Interfaces.h:185
void AddUITask(UIDelegate_v1 *a_task) const
std::function< void()> TaskFn
Definition: Interfaces.h:187
@ kVersion
Definition: Interfaces.h:191
void AddTask(TaskFn a_task) const
void AddUITask(TaskFn a_task) const
void AddTask(TaskDelegate *a_task) const
const detail::SKSETaskInterface * GetProxy() const
std::uint32_t Version() const
Definition: Interfaces.h:336
std::uint32_t Version() const
void * AllocateFromLocalPool(std::size_t a_size) const
void * AllocateFromBranchPool(std::size_t a_size) const
@ kVersion
Definition: Interfaces.h:340
Definition: Stubs.h:99
Definition: Stubs.h:106
constexpr REL::ID GetSingleton(static_cast< std::uint64_t >(10878))
Definition: AbsorbEffect.h:6
std::uint32_t FormID
Definition: BSCoreTypes.h:5
std::uint64_t VMHandle
Definition: BSCoreTypes.h:7
Definition: API.h:14
std::uint32_t PluginHandle
Definition: Stubs.h:11
Definition: EffectArchetypes.h:65
Definition: Interfaces.h:266
std::uint32_t dataLen
Definition: Interfaces.h:269
const char * sender
Definition: Interfaces.h:267
std::uint32_t type
Definition: Interfaces.h:268
void * data
Definition: Interfaces.h:270
Definition: Interfaces.h:353
@ kVersion
Definition: Interfaces.h:356
std::uint32_t version
Definition: Interfaces.h:361
const char * name
Definition: Interfaces.h:360
std::uint32_t infoVersion
Definition: Interfaces.h:359
Definition: Stubs.h:27
Definition: Stubs.h:47
Definition: Stubs.h:85