CommonLibSSE NG
SkyrimVM.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSAtomic.h"
4 #include "RE/B/BSTEvent.h"
5 #include "RE/B/BSTFreeList.h"
6 #include "RE/B/BSTHashMap.h"
7 #include "RE/B/BSTMessageQueue.h"
8 #include "RE/B/BSTSingleton.h"
9 #include "RE/B/BSTSmartPointer.h"
11 #include "RE/D/DelayFunctor.h"
12 #include "RE/F/FragmentSystem.h"
13 #include "RE/H/HandlePolicy.h"
14 #include "RE/I/IFreezeQuery.h"
16 #include "RE/L/Logger.h"
17 #include "RE/P/Profiler.h"
18 #include "RE/S/SavePatcher.h"
21 #include "RE/S/SkyrimScriptStore.h"
22 
23 namespace RE
24 {
25  namespace BSScript
26  {
27  class IFunctionArguments;
28  class IVirtualMachine;
29  class IVMDebugInterface;
30  class IVMSaveLoadInterface;
31  struct StatsEvent;
32  }
33 
34  struct PositionPlayerEvent;
35  struct TESActivateEvent;
36  struct TESActiveEffectApplyRemoveEvent;
37  struct TESActorLocationChangeEvent;
38  struct TESBookReadEvent;
39  struct TESCellAttachDetachEvent;
40  struct TESCellFullyLoadedEvent;
41  struct TESCombatEvent;
42  struct TESContainerChangedEvent;
43  struct TESDeathEvent;
44  struct TESDestructionStageChangedEvent;
45  struct TESEnterBleedoutEvent;
46  struct TESEquipEvent;
47  struct TESFastTravelEndEvent;
48  struct TESFormDeleteEvent;
49  struct TESFurnitureEvent;
50  struct TESGrabReleaseEvent;
51  struct TESHitEvent;
52  struct TESInitScriptEvent;
53  struct TESLoadGameEvent;
54  struct TESLockChangedEvent;
55  struct TESMagicEffectApplyEvent;
56  struct TESMagicWardHitEvent;
57  struct TESMoveAttachDetachEvent;
58  struct TESObjectLoadedEvent;
59  struct TESObjectREFRTranslationEvent;
60  struct TESOpenCloseEvent;
61  struct TESPackageEvent;
62  struct TESPerkEntryRunEvent;
63  struct TESPlayerBowShotEvent;
64  struct TESQuestInitEvent;
65  struct TESQuestStageEvent;
66  struct TESResetEvent;
67  struct TESResolveNPCTemplatesEvent;
68  struct TESSceneActionEvent;
69  struct TESSceneEvent;
70  struct TESScenePhaseEvent;
71  struct TESSellEvent;
72  struct TESSleepStartEvent;
73  struct TESSleepStopEvent;
74  struct TESSpellCastEvent;
75  struct TESSwitchRaceCompleteEvent;
76  struct TESTopicInfoEvent;
77  struct TESTrackedStatsEvent;
78  struct TESTrapHitEvent;
79  struct TESTriggerEnterEvent;
80  struct TESTriggerEvent;
81  struct TESTriggerLeaveEvent;
82  struct TESUniqueIDChangeEvent;
83 
84  class SkyrimVM :
85  public BSTSingletonSDM<SkyrimVM>, // 01A0
86  public BSScript::IFreezeQuery, // 0000
88  public BSTEventSink<TESActivateEvent>, // 0010
89  public BSTEventSink<TESActiveEffectApplyRemoveEvent>, // 0018
90  public BSTEventSink<TESActorLocationChangeEvent>, // 0020
91  public BSTEventSink<TESBookReadEvent>, // 0028
92  public BSTEventSink<TESCellAttachDetachEvent>, // 0030
93  public BSTEventSink<TESCellFullyLoadedEvent>, // 0038
94  public BSTEventSink<TESCombatEvent>, // 0040
95  public BSTEventSink<TESContainerChangedEvent>, // 0048
96  public BSTEventSink<TESDeathEvent>, // 0050
97  public BSTEventSink<TESDestructionStageChangedEvent>, // 0058
98  public BSTEventSink<TESEnterBleedoutEvent>, // 0060
99  public BSTEventSink<TESEquipEvent>, // 0068
100  public BSTEventSink<TESFormDeleteEvent>, // 0070
101  public BSTEventSink<TESFurnitureEvent>, // 0078
102  public BSTEventSink<TESGrabReleaseEvent>, // 0080
103  public BSTEventSink<TESHitEvent>, // 0088
104  public BSTEventSink<TESInitScriptEvent>, // 0090
105  public BSTEventSink<TESLoadGameEvent>, // 0098
106  public BSTEventSink<TESLockChangedEvent>, // 00A0
107  public BSTEventSink<TESMagicEffectApplyEvent>, // 00A8
108  public BSTEventSink<TESMagicWardHitEvent>, // 00B0
109  public BSTEventSink<TESMoveAttachDetachEvent>, // 00B8
110  public BSTEventSink<TESObjectLoadedEvent>, // 00C0
111  public BSTEventSink<TESObjectREFRTranslationEvent>, // 00C8
112  public BSTEventSink<TESOpenCloseEvent>, // 00D0
113  public BSTEventSink<TESPackageEvent>, // 00D8
114  public BSTEventSink<TESPerkEntryRunEvent>, // 00E0
115  public BSTEventSink<TESQuestInitEvent>, // 00E8
116  public BSTEventSink<TESQuestStageEvent>, // 00F0
117  public BSTEventSink<TESResetEvent>, // 00F8
118  public BSTEventSink<TESResolveNPCTemplatesEvent>, // 0100
119  public BSTEventSink<TESSceneEvent>, // 0108
120  public BSTEventSink<TESSceneActionEvent>, // 0110
121  public BSTEventSink<TESScenePhaseEvent>, // 0118
122  public BSTEventSink<TESSellEvent>, // 0120
123  public BSTEventSink<TESSleepStartEvent>, // 0128
124  public BSTEventSink<TESSleepStopEvent>, // 0130
125  public BSTEventSink<TESSpellCastEvent>, // 0138
126  public BSTEventSink<TESTopicInfoEvent>, // 0140
127  public BSTEventSink<TESTrackedStatsEvent>, // 0148
128  public BSTEventSink<TESTrapHitEvent>, // 0150
129  public BSTEventSink<TESTriggerEvent>, // 0158
130  public BSTEventSink<TESTriggerEnterEvent>, // 0160
131  public BSTEventSink<TESTriggerLeaveEvent>, // 0168
132  public BSTEventSink<TESUniqueIDChangeEvent>, // 0170
133  public BSTEventSink<TESSwitchRaceCompleteEvent>, // 0178
134  public BSTEventSink<TESPlayerBowShotEvent>, // 0180
135  public BSTEventSink<TESFastTravelEndEvent>, // 0188
136  public BSTEventSink<PositionPlayerEvent>, // 0190
137  public BSTEventSink<BSScript::StatsEvent>, // 0198
138  public BSTEventSource<BSScript::StatsEvent> // 01A8
139  {
140  public:
141  inline static constexpr auto RTTI = RTTI_SkyrimVM;
142 
144  {
145  public:
146  enum class UpdateType : bool
147  {
148  kRepeat = 0, // RegisterForUpdate/RegisterForUpdateGameTime
149  kNoRepeat = 1, // RegisterForSingleUpdate/RegisterForSingleUpdateGameTime
150  };
151 
152  // members
154  std::uint16_t pad06; // 06
155  std::uint32_t timeToSendEvent; // 08 - updateTime + currentVMMenuMode/currentVMDaysPassed
156  std::uint32_t updateTime; // 0C
158  };
159  static_assert(sizeof(UpdateDataEvent) == 0x18);
160 
161  struct WaitCall
162  {
163  public:
164  // members
165  std::uint32_t timeToSendEvent; // 00 - Same as UpdateDataEvent, updateTime is discarded
166  VMStackID stackID; // 04 - used for vm->ReturnFromLatent()
168  };
169  static_assert(sizeof(WaitCall) == 0x10);
170 
172  {
173  public:
174  enum class LOSEventType
175  {
176  kGain = 0,
177  kLost,
178  kBoth,
179  };
180 
181  enum class PreviousLOS
182  {
183  kLOS = 1,
184  kNoLOS = 2
185  };
186 
187  // members
188  std::uint32_t pad04; // 04
193  PreviousLOS lastLOSCheckResult; // 1C - (2 - (akViewer::HasLOS(akTarget) != 0))
194  };
195  static_assert(sizeof(LOSDataEvent) == 0x20);
196 
198  {
199  // members
202  };
203  static_assert(sizeof(InventoryEventFilterLists) == 0x68);
204 
206  {
207  virtual bool matchesFilter(VMHandle handle) = 0;
208  };
209 
210  ~SkyrimVM() override; // 00
211 
213 
215  void RelayEvent(VMHandle handle, BSFixedString* event, BSScript::IFunctionArguments* args, ISendEventFilter* optionalFilter);
217 
218  // members
231  mutable BSSpinLock frozenLock; // 0678
232  std::uint32_t isFrozen; // 0680
233  mutable BSSpinLock currentVMTimeLock; // 0684
234  std::uint32_t currentVMTime; // 068C
235  std::uint32_t currentVMMenuModeTime; // 0690
236  std::uint32_t currentVMGameTime; // 0694
237  std::uint32_t currentVMDaysPassed; // 0698 - Calender.GetDaysPassed() * 1000
239  std::uint32_t pad06A4; // 06A4
240  BSTArray<WaitCall> queuedWaitCalls; // 06A8 - Utility.Wait() calls
241  BSTArray<WaitCall> queuedWaitMenuModeCalls; // 06C0 - Utility.WaitMenuMode() calls
242  BSTArray<WaitCall> queuedWaitGameCalls; // 06D8 - Utility.WaitGameTime() calls
245  std::uint32_t currentLOSEventCheckIndex; // 0710
247  std::uint32_t pad071C; // 071C
250  std::uint32_t unk0750; // 0750
252  std::uint32_t pad075C; // 075C
253  BSTSet<VMHandle> registeredSleepEvents; // 0760 - RegisterForSleep
255  BSTSet<VMHandle> registeredStatsEvents; // 0798 - RegisterForTrackedStats
270  mutable BSSpinLock userLogMapLock; // 88F8
273  std::uint32_t currentVMOverstressTime; // 8938
274  std::uint32_t lastVMStackDumpTime; // 893C
277  };
278  static_assert(sizeof(SkyrimVM) == 0x8978);
279 }
Definition: CompiledScriptLoader.h:15
Definition: IFreezeQuery.h:8
Definition: IFunctionArguments.h:12
Definition: IStackCallbackSaveInterface.h:8
Definition: IVMDebugInterface.h:8
Definition: IVMSaveLoadInterface.h:47
Definition: IVirtualMachine.h:39
Definition: SimpleAllocMemoryPagePolicy.h:11
Definition: BSAtomic.h:51
Definition: BSTArray.h:377
Definition: BSTMessageQueue.h:63
Definition: BSTEvent.h:143
Definition: BSTEvent.h:19
Definition: BSTHashMap.h:21
Definition: BSTSmartPointer.h:36
Definition: BSTFreeList.h:28
Definition: FragmentSystem.h:11
Definition: HandlePolicy.h:11
Definition: Logger.h:11
Definition: SkyrimScriptObjectBindPolicy.h:11
Definition: Profiler.h:12
Definition: SavePatcher.h:10
Definition: SkyrimVM.h:139
BSTArray< BSTSmartPointer< UpdateDataEvent > > queuedOnUpdateEvents
Definition: SkyrimVM.h:248
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > postRenderFunctorQueue2
Definition: SkyrimVM.h:263
bool QueuePostRenderCall(const BSTSmartPointer< SkyrimScript::DelayFunctor > &a_functor)
std::uint32_t currentVMGameTime
Definition: SkyrimVM.h:236
BSTSet< VMHandle > registeredSleepEvents
Definition: SkyrimVM.h:253
BSScript::CompiledScriptLoader scriptLoader
Definition: SkyrimVM.h:223
void RelayEvent(VMHandle handle, BSFixedString *event, BSScript::IFunctionArguments *args, ISendEventFilter *optionalFilter)
SkyrimScript::Logger logger
Definition: SkyrimVM.h:224
BSSpinLock frozenLock
Definition: SkyrimVM.h:231
std::uint32_t lastVMStackDumpTime
Definition: SkyrimVM.h:274
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > renderSafeFunctorQueue2
Definition: SkyrimVM.h:259
SkyrimScript::ObjectBindPolicy objectBindPolicy
Definition: SkyrimVM.h:226
~SkyrimVM() override
BSTHashMap< const char *, SkyrimScript::Logger * > userLogMap
Definition: SkyrimVM.h:271
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > postRenderFunctorPool2
Definition: SkyrimVM.h:262
std::uint32_t currentVMOverstressTime
Definition: SkyrimVM.h:273
BSSpinLock currentVMTimeLock
Definition: SkyrimVM.h:233
BSSpinLock InventoryEventFilterMapLock
Definition: SkyrimVM.h:275
BSTArray< WaitCall > queuedWaitGameCalls
Definition: SkyrimVM.h:242
BSScript::IVMDebugInterface * debugInterface
Definition: SkyrimVM.h:221
BSTArray< WaitCall > queuedWaitMenuModeCalls
Definition: SkyrimVM.h:241
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * postRenderQueueToReadFrom
Definition: SkyrimVM.h:268
SkyrimScript::FragmentSystem fragmentSystem
Definition: SkyrimVM.h:228
BSSpinLock renderSafeQueueLock
Definition: SkyrimVM.h:264
std::uint32_t isFrozen
Definition: SkyrimVM.h:232
SkyrimScript::HandlePolicy handlePolicy
Definition: SkyrimVM.h:225
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > renderSafeFunctorPool1
Definition: SkyrimVM.h:256
std::uint32_t currentVMMenuModeTime
Definition: SkyrimVM.h:235
BSTArray< WaitCall > queuedWaitCalls
Definition: SkyrimVM.h:240
std::uint32_t pad075C
Definition: SkyrimVM.h:252
BSScript::SimpleAllocMemoryPagePolicy memoryPagePolicy
Definition: SkyrimVM.h:222
BSTSmartPointer< SkyrimScript::Store > scriptStore
Definition: SkyrimVM.h:227
BSTArray< BSTSmartPointer< UpdateDataEvent > > queuedOnUpdateGameEvents
Definition: SkyrimVM.h:249
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * renderSafeQueueToWriteTo
Definition: SkyrimVM.h:266
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > renderSafeFunctorQueue1
Definition: SkyrimVM.h:257
static SkyrimVM * GetSingleton()
BSTSmartPointer< BSScript::IVirtualMachine > impl
Definition: SkyrimVM.h:219
std::uint32_t currentVMDaysPassed
Definition: SkyrimVM.h:237
static constexpr auto RTTI
Definition: SkyrimVM.h:141
BSSpinLock userLogMapLock
Definition: SkyrimVM.h:270
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > renderSafeFunctorPool2
Definition: SkyrimVM.h:258
std::uint32_t pad06A4
Definition: SkyrimVM.h:239
BSTHashMap< VMHandle, InventoryEventFilterLists * > InventoryEventFilterMap
Definition: SkyrimVM.h:276
BSTArray< BSTSmartPointer< LOSDataEvent > > queuedLOSEventChecks
Definition: SkyrimVM.h:244
BSSpinLock queuedWaitEventLock
Definition: SkyrimVM.h:238
BSSpinLock currentVMOverstressTimeLock
Definition: SkyrimVM.h:272
BSSpinLock queuedLOSEventCheckLock
Definition: SkyrimVM.h:243
std::uint32_t unk0750
Definition: SkyrimVM.h:250
std::uint32_t currentLOSEventCheckIndex
Definition: SkyrimVM.h:245
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > postRenderFunctorQueue1
Definition: SkyrimVM.h:261
BSSpinLock queuedOnUpdateEventLock
Definition: SkyrimVM.h:246
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > postRenderFunctorPool1
Definition: SkyrimVM.h:260
BSTSet< VMHandle > registeredStatsEvents
Definition: SkyrimVM.h:255
BSSpinLock registeredSleepEventsLock
Definition: SkyrimVM.h:251
BSSpinLock postRenderQueueLock
Definition: SkyrimVM.h:267
std::uint32_t currentVMTime
Definition: SkyrimVM.h:234
SkyrimScript::Profiler profiler
Definition: SkyrimVM.h:229
void SendAndRelayEvent(VMHandle handle, BSFixedString *event, BSScript::IFunctionArguments *args, ISendEventFilter *optionalFilter)
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * postRenderQueueToWriteTo
Definition: SkyrimVM.h:269
std::uint32_t pad071C
Definition: SkyrimVM.h:247
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * renderSafeQueueToReadFrom
Definition: SkyrimVM.h:265
BSSpinLock registeredStatsEventsLock
Definition: SkyrimVM.h:254
BSScript::IVMSaveLoadInterface * saveLoadInterface
Definition: SkyrimVM.h:220
SkyrimScript::SavePatcher savePatcher
Definition: SkyrimVM.h:230
Definition: AbsorbEffect.h:6
std::uint32_t FormID
Definition: BSCoreTypes.h:5
std::uint32_t VMStackID
Definition: BSCoreTypes.h:8
std::uint64_t VMHandle
Definition: BSCoreTypes.h:7
constexpr REL::VariantID RTTI_SkyrimVM(689129, 396984, 0x1f4c540)
Definition: BSIntrusiveRefCounted.h:8
Definition: BSTSingleton.h:50
Definition: SkyrimVM.h:206
virtual bool matchesFilter(VMHandle handle)=0
Definition: SkyrimVM.h:198
BSTSet< FormID > itemListsForFiltering
Definition: SkyrimVM.h:201
BSTSet< FormID > itemsForFiltering
Definition: SkyrimVM.h:200
Definition: SkyrimVM.h:172
FormID akTargetFormID
Definition: SkyrimVM.h:191
LOSEventType losEventType
Definition: SkyrimVM.h:192
FormID akViewerFormID
Definition: SkyrimVM.h:190
PreviousLOS lastLOSCheckResult
Definition: SkyrimVM.h:193
VMHandle handle
Definition: SkyrimVM.h:189
std::uint32_t pad04
Definition: SkyrimVM.h:188
PreviousLOS
Definition: SkyrimVM.h:182
LOSEventType
Definition: SkyrimVM.h:175
Definition: SkyrimVM.h:144
std::uint32_t timeToSendEvent
Definition: SkyrimVM.h:155
UpdateType
Definition: SkyrimVM.h:147
VMHandle handle
Definition: SkyrimVM.h:157
std::uint32_t updateTime
Definition: SkyrimVM.h:156
UpdateType updateType
Definition: SkyrimVM.h:153
std::uint16_t pad06
Definition: SkyrimVM.h:154
Definition: SkyrimVM.h:162
VMStackID stackID
Definition: SkyrimVM.h:166
BSScript::IVirtualMachine * vm
Definition: SkyrimVM.h:167
std::uint32_t timeToSendEvent
Definition: SkyrimVM.h:165