CommonLibVR
Loading...
Searching...
No Matches
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
6namespace 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
23namespace 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 {
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
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 <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
104 inline bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T& a_buf) const
105 {
106 return WriteRecord(a_type, a_version, std::addressof(a_buf), sizeof(T));
107 }
108
109 template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
110 inline bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T (&a_buf)[N]) const
111 {
112 return WriteRecord(a_type, a_version, std::addressof(a_buf), sizeof(T) * N);
113 }
114
115 [[nodiscard]] bool OpenRecord(std::uint32_t a_type, std::uint32_t a_version) const;
116
117 bool WriteRecordData(const void* a_buf, std::uint32_t a_length) const;
118 bool WriteRecordDataEx(std::uint32_t& a_diff, const void* a_buf, std::uint32_t a_length) const;
119
120 template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
121 bool WriteRecordData(const T& a_buf) const
122 {
123 return WriteRecordData(std::addressof(a_buf), sizeof(T));
124 }
125
126 template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
127 bool WriteRecordDataEx(std::uint32_t& a_diff, const T& a_buf) const
128 {
129 return WriteRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T));
130 }
131
132 template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
133 bool WriteRecordData(const T (&a_buf)[N]) const
134 {
135 return WriteRecordData(std::addressof(a_buf), sizeof(T) * N);
136 }
137
138 template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
139 bool WriteRecordDataEx(std::uint32_t& a_diff, const T (&a_buf)[N]) const
140 {
141 return WriteRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T) * N);
142 }
143
144 bool GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const;
145
146 std::uint32_t ReadRecordData(void* a_buf, std::uint32_t a_length) const;
147 std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, void* a_buf, std::uint32_t a_length) const;
148
149 template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
150 std::uint32_t ReadRecordData(T& a_buf) const
151 {
152 return ReadRecordData(std::addressof(a_buf), sizeof(T));
153 }
154
155 template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
156 std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, T& a_buf) const
157 {
158 return ReadRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T));
159 }
160
161 template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
162 std::uint32_t ReadRecordData(T (&a_buf)[N]) const
163 {
164 return ReadRecordData(std::addressof(a_buf), sizeof(T) * N);
165 }
166
167 template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
168 std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, T (&a_buf)[N]) const
169 {
170 return ReadRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T) * N);
171 }
172
173 bool ResolveFormID(RE::FormID a_oldFormID, RE::FormID& a_newFormID) const;
174 bool ResolveHandle(RE::VMHandle a_oldHandle, RE::VMHandle& a_newHandle) const;
175
176 protected:
177 [[nodiscard]] const detail::SKSESerializationInterface* GetProxy() const;
178 };
179
181 {
182 public:
183 using TaskFn = std::function<void()>;
184
185 enum
186 {
187 kVersion = 2
188 };
189
190 [[nodiscard]] std::uint32_t Version() const;
191
192 void AddTask(TaskFn a_task) const;
193 void AddTask(TaskDelegate* a_task) const;
194 void AddUITask(TaskFn a_task) const;
195 void AddUITask(UIDelegate_v1* a_task) const;
196
197 protected:
199 {
200 public:
201 Task(TaskFn&& a_fn);
202
203 void Run() override;
204 void Dispose() override;
205
206 private:
207 TaskFn _fn;
208 };
209
211 {
212 public:
213 UITask(TaskFn&& a_fn);
214
215 void Run() override;
216 void Dispose() override;
217
218 private:
219 TaskFn _fn;
220 };
221
222 [[nodiscard]] const detail::SKSETaskInterface* GetProxy() const;
223 };
224
226 {
227 public:
230
231 enum
232 {
233 kVersion = 1
234 };
235
236 [[nodiscard]] std::uint32_t Version() const;
237
238 template <class Last>
239 bool Register(Last a_last) const
240 {
241 return Register_Impl(a_last);
242 }
243
244 template <class First, class... Rest>
245 bool Register(First a_first, Rest... a_rest) const
246 {
247 return Register_Impl(a_first) && Register(a_rest...);
248 }
249
250 protected:
251 [[nodiscard]] const detail::SKSEPapyrusInterface* GetProxy() const;
252
253 private:
254 bool Register_Impl(RegFunction1* a_fn) const;
255 bool Register_Impl(RegFunction2* a_fn) const;
256 };
257
259 {
260 public:
261 struct Message
262 {
263 const char* sender;
264 std::uint32_t type;
265 std::uint32_t dataLen;
266 void* data;
267 };
268
269 using EventCallback = void(Message* a_msg);
270
271 enum
272 {
273 kVersion = 2
274 };
275
276 enum : std::uint32_t
277 {
287
288 kTotal
289 };
290
291 enum class Dispatcher : std::uint32_t
292 {
293 kModEvent = 0,
298
299 kTotal
300 };
301
302 [[nodiscard]] std::uint32_t Version() const;
303
304 bool Dispatch(std::uint32_t a_messageType, void* a_data, std::uint32_t a_dataLen, const char* a_receiver) const;
305 [[nodiscard]] void* GetEventDispatcher(Dispatcher a_dispatcherID) const;
306 bool RegisterListener(EventCallback* a_callback) const;
307 bool RegisterListener(const char* a_sender, EventCallback* a_callback) const;
308
309 protected:
310 [[nodiscard]] const detail::SKSEMessagingInterface* GetProxy() const;
311 };
312
314 {
315 public:
316 enum
317 {
318 kVersion = 1
319 };
320
321 [[nodiscard]] std::uint32_t Version() const;
322
323 [[nodiscard]] SKSEDelayFunctorManager& GetDelayFunctorManager() const;
324 [[nodiscard]] SKSEObjectRegistry& GetObjectRegistry() const;
325 [[nodiscard]] SKSEPersistentObjectStorage& GetPersistentObjectStorage() const;
326
327 private:
328 [[nodiscard]] const detail::SKSEObjectInterface* GetProxy() const;
329 };
330
332 {
333 public:
334 enum
335 {
336 kVersion = 1
337 };
338
339 [[nodiscard]] std::uint32_t Version() const;
340
341 [[nodiscard]] void* AllocateFromBranchPool(std::size_t a_size) const;
342 [[nodiscard]] void* AllocateFromLocalPool(std::size_t a_size) const;
343
344 private:
345 [[nodiscard]] const detail::SKSETrampolineInterface* GetProxy() const;
346 };
347
349 {
350 enum
351 {
352 kVersion = 1
353 };
354
355 std::uint32_t infoVersion;
356 const char* name;
357 std::uint32_t version;
358 };
359
360#ifdef SKYRIM_SUPPORT_AE
361 struct PluginVersionData
362 {
363 public:
364 enum
365 {
366 kVersion = 1,
367 };
368
369 enum
370 {
371 kVersionIndependent_AddressLibraryPostAE = 1 << 0,
372 kVersionIndependent_Signatures = 1 << 1,
373 kVersionIndependent_StructsPost629 = 1 << 2,
374 };
375
376 enum
377 {
378 kVersionIndependentEx_NoStructUse = 1 << 0,
379 };
380
381 constexpr void PluginVersion(REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }
382
383 [[nodiscard]] constexpr REL::Version GetPluginVersion() const noexcept { return REL::Version::unpack(pluginVersion); }
384
385 constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); }
386
387 [[nodiscard]] constexpr std::string_view GetPluginName() const noexcept { return std::string_view{ pluginName }; }
388
389 constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); }
390
391 [[nodiscard]] constexpr std::string_view GetAuthorName() const noexcept { return std::string_view{ author }; }
392
393 constexpr void AuthorEmail(std::string_view a_email) noexcept { SetCharBuffer(a_email, std::span{ supportEmail }); }
394
395 [[nodiscard]] constexpr std::string_view GetAuthorEmail() const noexcept { return std::string_view{ supportEmail }; }
396
397 constexpr void UsesAddressLibrary() noexcept { versionIndependence |= kVersionIndependent_AddressLibraryPostAE; }
398 constexpr void UsesSigScanning() noexcept { versionIndependence |= kVersionIndependent_Signatures; }
399 constexpr void UsesUpdatedStructs() noexcept { versionIndependence |= kVersionIndependent_StructsPost629; }
400
401 constexpr void UsesNoStructs() noexcept { versionIndependenceEx |= kVersionIndependentEx_NoStructUse; }
402
403 constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }
404
405 constexpr void CompatibleVersions(std::initializer_list<REL::Version> a_versions) noexcept
406 {
407 assert(a_versions.size() < std::size(compatibleVersions) - 1);
408 std::transform(
409 a_versions.begin(),
410 a_versions.end(),
411 std::begin(compatibleVersions),
412 [](const REL::Version& a_version) noexcept { return a_version.pack(); });
413 }
414
415 [[nodiscard]] static const PluginVersionData* GetSingleton() noexcept;
416
417 const std::uint32_t dataVersion{ kVersion };
418 std::uint32_t pluginVersion = 0;
419 char pluginName[256] = {};
420 char author[256] = {};
421 char supportEmail[252] = {};
422 std::uint32_t versionIndependenceEx = 0;
423 std::uint32_t versionIndependence = 0;
424 std::uint32_t compatibleVersions[16] = {};
425 std::uint32_t xseMinimum = 0;
426
427 private:
428 static constexpr void SetCharBuffer(
429 std::string_view a_src,
430 std::span<char> a_dst) noexcept
431 {
432 assert(a_src.size() < a_dst.size());
433 std::fill(a_dst.begin(), a_dst.end(), '\0');
434 std::copy(a_src.begin(), a_src.end(), a_dst.begin());
435 }
436 };
437 static_assert(offsetof(PluginVersionData, dataVersion) == 0x000);
438 static_assert(offsetof(PluginVersionData, pluginVersion) == 0x004);
439 static_assert(offsetof(PluginVersionData, pluginName) == 0x008);
440 static_assert(offsetof(PluginVersionData, author) == 0x108);
441 static_assert(offsetof(PluginVersionData, supportEmail) == 0x208);
442 static_assert(offsetof(PluginVersionData, versionIndependenceEx) == 0x304);
443 static_assert(offsetof(PluginVersionData, versionIndependence) == 0x308);
444 static_assert(offsetof(PluginVersionData, compatibleVersions) == 0x30C);
445 static_assert(offsetof(PluginVersionData, xseMinimum) == 0x34C);
446 static_assert(sizeof(PluginVersionData) == 0x350);
447#endif
448}
449
450#define SKSEPluginLoad(...) extern "C" [[maybe_unused]] __declspec(dllexport) bool SKSEPlugin_Load(__VA_ARGS__)
451#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:40
Definition VirtualMachine.h:46
Definition GFxMovieView.h:24
Definition GFxValue.h:92
Definition InventoryEntryData.h:15
Definition Interfaces.h:40
@ 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
void * QueryInterface(std::uint32_t a_id) const
PluginHandle GetPluginHandle() const
std::uint32_t GetReleaseIndex() const
const PluginInfo * GetPluginInfo(const char *a_name) const
Definition Interfaces.h:259
Dispatcher
Definition Interfaces.h:292
void * GetEventDispatcher(Dispatcher a_dispatcherID) const
std::uint32_t Version() const
@ kTotal
Definition Interfaces.h:288
@ kPostPostLoad
Definition Interfaces.h:279
@ kPostLoad
Definition Interfaces.h:278
@ kPreLoadGame
Definition Interfaces.h:280
@ kSaveGame
Definition Interfaces.h:282
@ kNewGame
Definition Interfaces.h:285
@ kDataLoaded
Definition Interfaces.h:286
@ kInputLoaded
Definition Interfaces.h:284
@ kDeleteGame
Definition Interfaces.h:283
@ kPostLoadGame
Definition Interfaces.h:281
const detail::SKSEMessagingInterface * GetProxy() 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:273
bool RegisterListener(EventCallback *a_callback) const
void(Message *a_msg) EventCallback
Definition Interfaces.h:269
Definition Interfaces.h:314
@ kVersion
Definition Interfaces.h:318
SKSEObjectRegistry & GetObjectRegistry() const
SKSEPersistentObjectStorage & GetPersistentObjectStorage() const
std::uint32_t Version() const
SKSEDelayFunctorManager & GetDelayFunctorManager() const
Definition Interfaces.h:226
bool Register(First a_first, Rest... a_rest) const
Definition Interfaces.h:245
const detail::SKSEPapyrusInterface * GetProxy() const
@ kVersion
Definition Interfaces.h:233
std::uint32_t Version() const
bool(RE::BSScript::Internal::VirtualMachine *a_vm) RegFunction1
Definition Interfaces.h:228
bool(RE::BSScript::IVirtualMachine *a_vm) RegFunction2
Definition Interfaces.h:229
bool Register(Last a_last) const
Definition Interfaces.h:239
Definition Interfaces.h:28
const detail::SKSEInterface * GetProxy() const
std::uint32_t EditorVersion() const
REL::Version RuntimeVersion() const
std::uint32_t SKSEVersion() const
bool IsEditor() const
Definition Interfaces.h:62
const detail::SKSEScaleformInterface * GetProxy() const
void(RE::GFxMovieView *a_view, RE::GFxValue *a_object, RE::InventoryEntryData *a_item) RegInvCallback
Definition Interfaces.h:65
void Register(RegInvCallback *a_callback) const
bool Register(RegCallback *a_callback, const char *a_name) const
@ kVersion
Definition Interfaces.h:69
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
std::uint32_t ReadRecordDataEx(std::uint32_t &a_diff, T &a_buf) const
Definition Interfaces.h:156
void SetFormDeleteCallback(FormDeleteCallback *a_callback) const
std::uint32_t ReadRecordData(T &a_buf) const
Definition Interfaces.h:150
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T(&a_buf)[N]) const
Definition Interfaces.h:110
bool WriteRecordDataEx(std::uint32_t &a_diff, const T(&a_buf)[N]) const
Definition Interfaces.h:139
void(SerializationInterface *a_intfc) EventCallback
Definition Interfaces.h:84
bool WriteRecordData(const T &a_buf) const
Definition Interfaces.h:121
void(RE::VMHandle a_handle) FormDeleteCallback
Definition Interfaces.h:85
std::uint32_t ReadRecordDataEx(std::uint32_t &a_diff, T(&a_buf)[N]) const
Definition Interfaces.h:168
std::uint32_t ReadRecordData(void *a_buf, std::uint32_t a_length) const
void SetRevertCallback(EventCallback *a_callback) const
const detail::SKSESerializationInterface * GetProxy() const
bool WriteRecordDataEx(std::uint32_t &a_diff, const void *a_buf, std::uint32_t a_length) const
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const T &a_buf) const
Definition Interfaces.h:104
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:162
bool ResolveFormID(RE::FormID a_oldFormID, RE::FormID &a_newFormID) const
std::uint32_t ReadRecordDataEx(std::uint32_t &a_diff, void *a_buf, std::uint32_t a_length) const
@ kVersion
Definition Interfaces.h:89
bool WriteRecordData(const T(&a_buf)[N]) const
Definition Interfaces.h:133
bool WriteRecordDataEx(std::uint32_t &a_diff, const T &a_buf) const
Definition Interfaces.h:127
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:199
void Dispose() override
Definition Interfaces.h:211
Definition Interfaces.h:181
void AddUITask(UIDelegate_v1 *a_task) const
std::function< void()> TaskFn
Definition Interfaces.h:183
const detail::SKSETaskInterface * GetProxy() const
void AddTask(TaskFn a_task) const
@ kVersion
Definition Interfaces.h:187
void AddUITask(TaskFn a_task) const
void AddTask(TaskDelegate *a_task) const
std::uint32_t Version() const
Definition Interfaces.h:332
void * AllocateFromBranchPool(std::size_t a_size) const
std::uint32_t Version() const
@ kVersion
Definition Interfaces.h:336
void * AllocateFromLocalPool(std::size_t a_size) const
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:262
std::uint32_t dataLen
Definition Interfaces.h:265
const char * sender
Definition Interfaces.h:263
std::uint32_t type
Definition Interfaces.h:264
void * data
Definition Interfaces.h:266
Definition Interfaces.h:349
std::uint32_t version
Definition Interfaces.h:357
const char * name
Definition Interfaces.h:356
std::uint32_t infoVersion
Definition Interfaces.h:355
@ kVersion
Definition Interfaces.h:352
Definition Stubs.h:27
Definition Stubs.h:85