CommonLibSSE (powerof3)
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  inline static constexpr auto VTABLE = VTABLE_SkyrimVM;
143 
145  {
146  public:
147  enum class UpdateType : bool
148  {
149  kRepeat = 0, // RegisterForUpdate/RegisterForUpdateGameTime
150  kNoRepeat = 1, // RegisterForSingleUpdate/RegisterForSingleUpdateGameTime
151  };
152 
153  // members
155  std::uint16_t pad06; // 06
156  std::uint32_t timeToSendEvent; // 08 - updateTime + currentVMMenuMode/currentVMDaysPassed
157  std::uint32_t updateTime; // 0C
159  };
160  static_assert(sizeof(UpdateDataEvent) == 0x18);
161 
162  struct WaitCall
163  {
164  public:
165  // members
166  std::uint32_t timeToSendEvent; // 00 - Same as UpdateDataEvent, updateTime is discarded
167  VMStackID stackID; // 04 - used for vm->ReturnFromLatent()
169  };
170  static_assert(sizeof(WaitCall) == 0x10);
171 
173  {
174  public:
175  enum class LOSEventType
176  {
177  kGain = 0,
178  kLost,
179  kBoth,
180  };
181 
182  enum class PreviousLOS
183  {
184  kLOS = 1,
185  kNoLOS = 2
186  };
187 
188  // members
189  std::uint32_t pad04; // 04
194  PreviousLOS lastLOSCheckResult; // 1C - (2 - (akViewer::HasLOS(akTarget) != 0))
195  };
196  static_assert(sizeof(LOSDataEvent) == 0x20);
197 
199  {
200  // members
203  };
204  static_assert(sizeof(InventoryEventFilterLists) == 0x68);
205 
207  {
208  virtual bool matchesFilter(VMHandle handle) = 0;
209  };
210 
211  ~SkyrimVM() override; // 00
212 
214 
216  void RelayEvent(VMHandle handle, BSFixedString* event, BSScript::IFunctionArguments* args, ISendEventFilter* optionalFilter);
218 
219  // members
232  mutable BSSpinLock frozenLock; // 0678
233  std::uint32_t isFrozen; // 0680
234  mutable BSSpinLock currentVMTimeLock; // 0684
235  std::uint32_t currentVMTime; // 068C
236  std::uint32_t currentVMMenuModeTime; // 0690
237  std::uint32_t currentVMGameTime; // 0694
238  std::uint32_t currentVMDaysPassed; // 0698 - Calender.GetDaysPassed() * 1000
240  std::uint32_t pad06A4; // 06A4
241  BSTArray<WaitCall> queuedWaitCalls; // 06A8 - Utility.Wait() calls
242  BSTArray<WaitCall> queuedWaitMenuModeCalls; // 06C0 - Utility.WaitMenuMode() calls
243  BSTArray<WaitCall> queuedWaitGameCalls; // 06D8 - Utility.WaitGameTime() calls
246  std::uint32_t currentLOSEventCheckIndex; // 0710
248  std::uint32_t pad071C; // 071C
251  std::uint32_t unk0750; // 0750
253  std::uint32_t pad075C; // 075C
254  BSTSet<VMHandle> registeredSleepEvents; // 0760 - RegisterForSleep
256  BSTSet<VMHandle> registeredStatsEvents; // 0798 - RegisterForTrackedStats
271  mutable BSSpinLock userLogMapLock; // 88F8
274  std::uint32_t currentVMOverstressTime; // 8938
275  std::uint32_t lastVMStackDumpTime; // 893C
278  };
279  static_assert(sizeof(SkyrimVM) == 0x8978);
280 }
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:92
Definition: BSTArray.h:378
Definition: BSTMessageQueue.h:63
Definition: BSTEvent.h:143
Definition: BSTEvent.h:19
Definition: BSTHashMap.h:21
Definition: BSTSmartPointer.h:37
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:249
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > postRenderFunctorQueue2
Definition: SkyrimVM.h:264
bool QueuePostRenderCall(const BSTSmartPointer< SkyrimScript::DelayFunctor > &a_functor)
std::uint32_t currentVMGameTime
Definition: SkyrimVM.h:237
BSTSet< VMHandle > registeredSleepEvents
Definition: SkyrimVM.h:254
BSScript::CompiledScriptLoader scriptLoader
Definition: SkyrimVM.h:224
void RelayEvent(VMHandle handle, BSFixedString *event, BSScript::IFunctionArguments *args, ISendEventFilter *optionalFilter)
SkyrimScript::Logger logger
Definition: SkyrimVM.h:225
BSSpinLock frozenLock
Definition: SkyrimVM.h:232
std::uint32_t lastVMStackDumpTime
Definition: SkyrimVM.h:275
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > renderSafeFunctorQueue2
Definition: SkyrimVM.h:260
SkyrimScript::ObjectBindPolicy objectBindPolicy
Definition: SkyrimVM.h:227
~SkyrimVM() override
BSTHashMap< const char *, SkyrimScript::Logger * > userLogMap
Definition: SkyrimVM.h:272
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > postRenderFunctorPool2
Definition: SkyrimVM.h:263
std::uint32_t currentVMOverstressTime
Definition: SkyrimVM.h:274
BSSpinLock currentVMTimeLock
Definition: SkyrimVM.h:234
BSSpinLock InventoryEventFilterMapLock
Definition: SkyrimVM.h:276
BSTArray< WaitCall > queuedWaitGameCalls
Definition: SkyrimVM.h:243
BSScript::IVMDebugInterface * debugInterface
Definition: SkyrimVM.h:222
BSTArray< WaitCall > queuedWaitMenuModeCalls
Definition: SkyrimVM.h:242
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * postRenderQueueToReadFrom
Definition: SkyrimVM.h:269
SkyrimScript::FragmentSystem fragmentSystem
Definition: SkyrimVM.h:229
BSSpinLock renderSafeQueueLock
Definition: SkyrimVM.h:265
std::uint32_t isFrozen
Definition: SkyrimVM.h:233
SkyrimScript::HandlePolicy handlePolicy
Definition: SkyrimVM.h:226
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > renderSafeFunctorPool1
Definition: SkyrimVM.h:257
std::uint32_t currentVMMenuModeTime
Definition: SkyrimVM.h:236
BSTArray< WaitCall > queuedWaitCalls
Definition: SkyrimVM.h:241
std::uint32_t pad075C
Definition: SkyrimVM.h:253
BSScript::SimpleAllocMemoryPagePolicy memoryPagePolicy
Definition: SkyrimVM.h:223
BSTSmartPointer< SkyrimScript::Store > scriptStore
Definition: SkyrimVM.h:228
BSTArray< BSTSmartPointer< UpdateDataEvent > > queuedOnUpdateGameEvents
Definition: SkyrimVM.h:250
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * renderSafeQueueToWriteTo
Definition: SkyrimVM.h:267
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > renderSafeFunctorQueue1
Definition: SkyrimVM.h:258
static SkyrimVM * GetSingleton()
BSTSmartPointer< BSScript::IVirtualMachine > impl
Definition: SkyrimVM.h:220
std::uint32_t currentVMDaysPassed
Definition: SkyrimVM.h:238
static constexpr auto RTTI
Definition: SkyrimVM.h:141
BSSpinLock userLogMapLock
Definition: SkyrimVM.h:271
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > renderSafeFunctorPool2
Definition: SkyrimVM.h:259
std::uint32_t pad06A4
Definition: SkyrimVM.h:240
BSTHashMap< VMHandle, InventoryEventFilterLists * > InventoryEventFilterMap
Definition: SkyrimVM.h:277
BSTArray< BSTSmartPointer< LOSDataEvent > > queuedLOSEventChecks
Definition: SkyrimVM.h:245
BSSpinLock queuedWaitEventLock
Definition: SkyrimVM.h:239
BSSpinLock currentVMOverstressTimeLock
Definition: SkyrimVM.h:273
static constexpr auto VTABLE
Definition: SkyrimVM.h:142
BSSpinLock queuedLOSEventCheckLock
Definition: SkyrimVM.h:244
std::uint32_t unk0750
Definition: SkyrimVM.h:251
std::uint32_t currentLOSEventCheckIndex
Definition: SkyrimVM.h:246
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > postRenderFunctorQueue1
Definition: SkyrimVM.h:262
BSSpinLock queuedOnUpdateEventLock
Definition: SkyrimVM.h:247
BSTStaticFreeList< BSTSmartPointer< SkyrimScript::DelayFunctor >, 512 > postRenderFunctorPool1
Definition: SkyrimVM.h:261
BSTSet< VMHandle > registeredStatsEvents
Definition: SkyrimVM.h:256
BSSpinLock registeredSleepEventsLock
Definition: SkyrimVM.h:252
BSSpinLock postRenderQueueLock
Definition: SkyrimVM.h:268
std::uint32_t currentVMTime
Definition: SkyrimVM.h:235
SkyrimScript::Profiler profiler
Definition: SkyrimVM.h:230
void SendAndRelayEvent(VMHandle handle, BSFixedString *event, BSScript::IFunctionArguments *args, ISendEventFilter *optionalFilter)
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * postRenderQueueToWriteTo
Definition: SkyrimVM.h:270
std::uint32_t pad071C
Definition: SkyrimVM.h:248
BSTCommonLLMessageQueue< BSTSmartPointer< SkyrimScript::DelayFunctor > > * renderSafeQueueToReadFrom
Definition: SkyrimVM.h:266
BSSpinLock registeredStatsEventsLock
Definition: SkyrimVM.h:255
BSScript::IVMSaveLoadInterface * saveLoadInterface
Definition: SkyrimVM.h:221
SkyrimScript::SavePatcher savePatcher
Definition: SkyrimVM.h:231
Definition: AbsorbEffect.h:6
std::uint32_t FormID
Definition: BSCoreTypes.h:5
constexpr REL::ID RTTI_SkyrimVM(static_cast< std::uint64_t >(689129))
std::uint32_t VMStackID
Definition: BSCoreTypes.h:8
std::uint64_t VMHandle
Definition: BSCoreTypes.h:7
constexpr std::array< REL::ID, 52 > VTABLE_SkyrimVM
Definition: Offsets_VTABLE.h:12754
Definition: BSIntrusiveRefCounted.h:8
Definition: BSTSingleton.h:50
Definition: SkyrimVM.h:207
virtual bool matchesFilter(VMHandle handle)=0
Definition: SkyrimVM.h:199
BSTSet< FormID > itemListsForFiltering
Definition: SkyrimVM.h:202
BSTSet< FormID > itemsForFiltering
Definition: SkyrimVM.h:201
Definition: SkyrimVM.h:173
FormID akTargetFormID
Definition: SkyrimVM.h:192
LOSEventType losEventType
Definition: SkyrimVM.h:193
FormID akViewerFormID
Definition: SkyrimVM.h:191
PreviousLOS lastLOSCheckResult
Definition: SkyrimVM.h:194
VMHandle handle
Definition: SkyrimVM.h:190
std::uint32_t pad04
Definition: SkyrimVM.h:189
PreviousLOS
Definition: SkyrimVM.h:183
LOSEventType
Definition: SkyrimVM.h:176
Definition: SkyrimVM.h:145
std::uint32_t timeToSendEvent
Definition: SkyrimVM.h:156
UpdateType
Definition: SkyrimVM.h:148
VMHandle handle
Definition: SkyrimVM.h:158
std::uint32_t updateTime
Definition: SkyrimVM.h:157
UpdateType updateType
Definition: SkyrimVM.h:154
std::uint16_t pad06
Definition: SkyrimVM.h:155
Definition: SkyrimVM.h:163
VMStackID stackID
Definition: SkyrimVM.h:167
BSScript::IVirtualMachine * vm
Definition: SkyrimVM.h:168
std::uint32_t timeToSendEvent
Definition: SkyrimVM.h:166