CommonLibVR
IVirtualMachine.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSFixedString.h"
5 #include "RE/B/BSTEvent.h"
6 #include "RE/B/BSTSmartPointer.h"
7 #include "RE/E/ErrorLogger.h"
9 #include "RE/T/TypeInfo.h"
10 #include "RE/V/Variable.h"
11 
12 namespace RE
13 {
14  namespace BSJobs
15  {
16  class JobList;
17  }
18 
19  class TESForm;
20 
21  namespace BSScript
22  {
23  class Array;
24  class ErrorLogger;
25  class IForEachScriptObjectFunctor;
26  class IFunction;
27  class IFunctionArguments;
28  class ISavePatcherInterface;
29  class ITypeLinkedCallback;
30  class Object;
31  class ObjectBindPolicy;
32  class ObjectTypeInfo;
33  class Variable;
34  struct IObjectHandlePolicy;
35  struct LogEvent;
36  struct StatsEvent;
37 
39  {
40  public:
41  inline static constexpr auto RTTI = RTTI_BSScript__IVirtualMachine;
42  inline static constexpr auto VTABLE = VTABLE_BSScript__IVirtualMachine;
43 
45  struct Awaitable
46  {
48  {
49  void operator()(Variable a_result) override;
50  void SetObject(const BSTSmartPointer<Object>&) override {}
51 
52  bool pending{ false };
54  std::coroutine_handle<> continuation;
55  };
56 
58  void SetPending(bool a_pending = true);
59  bool await_ready() const;
60  void await_suspend(std::coroutine_handle<> a_handle);
62 
64  };
65 
66  virtual ~IVirtualMachine(); // 00
67 
68  // add
69  virtual void SetLinkedCallback(ITypeLinkedCallback* a_callback) = 0; // 01
70  virtual void TraceStack(const char* a_str, VMStackID a_stackID, Severity a_severity = Severity::kError) = 0; // 02
71  virtual void FormatAndPostMessage(const char* a_message, Severity a_severity) = 0; // 03
72  virtual void Update(float a_budget) = 0; // 04
73  virtual void UpdateTasklets(float a_budget) = 0; // 05
74  virtual void SetOverstressed(bool a_set) = 0; // 06
75  virtual bool IsCompletelyFrozen() const = 0; // 07
76  virtual bool RegisterObjectType(VMTypeID a_typeID, const char* a_className) = 0; // 08
77  virtual bool GetScriptObjectType1(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) = 0; // 09
78  virtual bool GetScriptObjectType2(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) = 0; // 0A
79  virtual bool GetScriptObjectTypeNoLoad1(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) const = 0; // 0B
80  virtual bool GetScriptObjectTypeNoLoad2(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) const = 0; // 0C
81  virtual bool GetTypeIDForScriptObject(const BSFixedString& a_className, VMTypeID& a_typeID) const = 0; // 0D
82  virtual void GetScriptObjectsWithATypeID(BSScrapArray<BSFixedString>& a_classes) const = 0; // 0E
83  virtual bool GetParentNativeType(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) = 0; // 0F
84  virtual bool TypeIsValid(const BSFixedString& a_className) = 0; // 10
85  virtual bool ReloadType(const char* a_className) = 0; // 11
86  virtual void TasksToJobs(BSJobs::JobList& a_jobList) = 0; // 12
87  virtual void CalculateFullReloadList(void) const = 0; // 13
88  virtual bool CreateObject1(const BSFixedString& a_className, void* a_property, BSTSmartPointer<Object>& a_objPtr) = 0; // 14
89  virtual bool CreateObject2(const BSFixedString& a_className, BSTSmartPointer<Object>& a_result) = 0; // 15
90  virtual bool CreateArray1(const TypeInfo& a_typeInfo, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr) = 0; // 16
91  virtual bool CreateArray2(TypeInfo::RawType a_typeID, const BSFixedString& a_className, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr) = 0; // 17
92  virtual bool BindNativeMethod(IFunction* a_fn) = 0; // 18
93  virtual void SetCallableFromTasklets1(const char* a_className, const char* a_stateName, const char* a_fnName, bool a_callable) = 0; // 19
94  virtual void SetCallableFromTasklets2(const char* a_className, const char* a_fnName, bool a_callable) = 0; // 1A
95  virtual void ForEachBoundObject(VMHandle a_handle, IForEachScriptObjectFunctor* a_functor) = 0; // 1B
96 #ifdef SKYRIMVR
97  virtual void UnkVR_1C(void) = 0; // added in VR 1.4.15
98  virtual void UnkVR_1D(void) = 0; // added in VR 1.4.15
99 #endif
100  virtual bool FindBoundObject(VMHandle a_handle, const char* a_className, BSTSmartPointer<Object>& a_result) const = 0; // 1C
101  virtual void MoveBoundObjects(VMHandle a_from, VMHandle a_to) = 0; // 1D
102  virtual void ResetAllBoundObjects(VMHandle a_handle) = 0; // 1E
103  virtual bool CastObject(const BSTSmartPointer<Object>& a_fromObjPtr, const BSTSmartPointer<ObjectTypeInfo>& a_toTypeInfoPtr, BSTSmartPointer<Object>& a_toObjPtr) = 0; // 1F
104  virtual bool SetPropertyValue(BSTSmartPointer<Object>& a_obj, const char* a_propertyName, Variable& a_setVal) = 0; // 20
105  virtual bool GetPropertyValue(BSTSmartPointer<Object>& a_obj, const char* a_propertyName, Variable& a_getVal) = 0; // 21
106  virtual bool GetVariableValue1(const BSTSmartPointer<Object>& a_objPtr, std::uint32_t a_index, Variable& a_out) const = 0; // 22
107  virtual bool GetVariableValue2(VMHandle a_handle, const BSFixedString& a_className, std::int32_t a_variableIndex, Variable& a_out) const = 0; // 23
108  virtual void SendEvent(VMHandle a_handle, const BSFixedString& a_eventName, IFunctionArguments* a_args) = 0; // 24
109  virtual void SendEventAll(const BSFixedString& a_eventName, IFunctionArguments* a_args) = 0; // 25
110  virtual bool DispatchStaticCall(const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args, BSTSmartPointer<IStackCallbackFunctor>& a_result) = 0; // 26
112  virtual bool DispatchMethodCall2(VMHandle a_handle, const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args, BSTSmartPointer<IStackCallbackFunctor>& a_result) = 0; // 28
113  virtual bool DispatchUnboundMethodCall(void) = 0; // 29
114  virtual bool IsWaitingOnLatent(VMStackID a_stackID) const = 0; // 2A
115  virtual void ReturnFromLatent(VMStackID a_stackID, const Variable& a_val) = 0; // 2B
116  virtual ErrorLogger* GetErrorLogger() = 0; // 2C
118  virtual const IObjectHandlePolicy* GetObjectHandlePolicy2() const = 0; // 2E
120  virtual const ObjectBindPolicy* GetObjectBindPolicy2() const = 0; // 30
122  virtual void RegisterForLogEvent(BSTEventSink<LogEvent>* a_sink) = 0; // 32
123  virtual void UnregisterForLogEvent(BSTEventSink<LogEvent>* a_sink) = 0; // 33
124  virtual void RegisterForStatsEvent(BSTEventSink<StatsEvent>* a_sink) = 0; // 34
125  virtual void UnregisterForStatsEvent(BSTEventSink<StatsEvent>* a_sink) = 0; // 35
126 
127  bool CreateArray(const TypeInfo& a_typeInfo, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr);
128  bool CreateArray(TypeInfo::RawType a_typeID, const BSFixedString& a_className, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr);
129  bool CreateObject(const BSFixedString& a_className, void* a_property, BSTSmartPointer<Object>& a_objPtr);
130  bool CreateObject(const BSFixedString& a_className, BSTSmartPointer<Object>& a_result);
133  bool DispatchMethodCall(VMHandle a_handle, const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args, BSTSmartPointer<IStackCallbackFunctor>& a_result);
134  Awaitable DispatchMethodCall(VMHandle a_handle, const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args);
135  Awaitable DispatchStaticCall(const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args);
140  bool GetScriptObjectType(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr);
142  bool GetScriptObjectTypeNoLoad(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) const;
143  bool GetScriptObjectTypeNoLoad(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) const;
144  bool GetVariableValue(const BSTSmartPointer<Object>& a_objPtr, std::uint32_t a_index, Variable& a_out) const;
145  bool GetVariableValue(VMHandle a_handle, const BSFixedString& a_className, std::int32_t a_variableIndex, Variable& a_out) const;
146 
147  template <class F>
148  void RegisterFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets = false);
149 
150  template <class R, class F>
151  void RegisterLatentFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets = false);
152 
153  template <class V>
154  requires is_return_convertible_v<V>
155  void ReturnLatentResult(VMStackID a_stackID, V result);
156 
157  void SetCallableFromTasklets(const char* a_className, const char* a_stateName, const char* a_fnName, bool a_callable);
158  void SetCallableFromTasklets(const char* a_className, const char* a_fnName, bool a_callable);
159  void TraceForm(TESForm* a_form, const char* a_str, VMStackID a_stackID, Severity a_severity = Severity::kError);
160  void VTraceStack(VMStackID a_stackID, Severity a_severity, const char* a_fmt, ...);
161 
162  // members
163  std::uint32_t pad0C; // 0C
164  };
165  static_assert(sizeof(IVirtualMachine) == 0x10);
166  }
167 }
Definition: ErrorLogger.h:13
Severity
Definition: ErrorLogger.h:19
Definition: IFunctionArguments.h:12
Definition: IFunction.h:23
Definition: ISavePatcherInterface.h:11
Definition: IStackCallbackFunctor.h:14
Definition: IVirtualMachine.h:39
bool DispatchMethodCall(VMHandle a_handle, const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
virtual void UpdateTasklets(float a_budget)=0
Awaitable DispatchStaticCall(const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args)
virtual ISavePatcherInterface * GetSavePatcherInterface()=0
virtual bool FindBoundObject(VMHandle a_handle, const char *a_className, BSTSmartPointer< Object > &a_result) const =0
void SetCallableFromTasklets(const char *a_className, const char *a_stateName, const char *a_fnName, bool a_callable)
virtual void SetOverstressed(bool a_set)=0
virtual bool CreateObject1(const BSFixedString &a_className, void *a_property, BSTSmartPointer< Object > &a_objPtr)=0
Awaitable DispatchMethodCall(VMHandle a_handle, const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args)
virtual void RegisterForLogEvent(BSTEventSink< LogEvent > *a_sink)=0
virtual bool IsCompletelyFrozen() const =0
virtual void FormatAndPostMessage(const char *a_message, Severity a_severity)=0
virtual bool CreateArray1(const TypeInfo &a_typeInfo, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)=0
virtual bool CreateArray2(TypeInfo::RawType a_typeID, const BSFixedString &a_className, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)=0
virtual void ReturnFromLatent(VMStackID a_stackID, const Variable &a_val)=0
virtual bool GetScriptObjectType2(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr)=0
std::uint32_t pad0C
Definition: IVirtualMachine.h:163
virtual void SetLinkedCallback(ITypeLinkedCallback *a_callback)=0
virtual bool DispatchMethodCall2(VMHandle a_handle, const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)=0
virtual bool DispatchStaticCall(const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)=0
bool DispatchMethodCall(BSTSmartPointer< Object > &a_obj, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
virtual const IObjectHandlePolicy * GetObjectHandlePolicy2() const =0
static constexpr auto VTABLE
Definition: IVirtualMachine.h:42
virtual void GetScriptObjectsWithATypeID(BSScrapArray< BSFixedString > &a_classes) const =0
virtual bool GetTypeIDForScriptObject(const BSFixedString &a_className, VMTypeID &a_typeID) const =0
virtual void CalculateFullReloadList(void) const =0
virtual bool GetScriptObjectType1(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr)=0
virtual bool GetScriptObjectTypeNoLoad1(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_typeInfoPtr) const =0
virtual const ObjectBindPolicy * GetObjectBindPolicy2() const =0
virtual bool DispatchUnboundMethodCall(void)=0
virtual void ResetAllBoundObjects(VMHandle a_handle)=0
virtual void UnregisterForLogEvent(BSTEventSink< LogEvent > *a_sink)=0
void RegisterFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets=false)
Definition: NativeFunction.h:174
virtual bool SetPropertyValue(BSTSmartPointer< Object > &a_obj, const char *a_propertyName, Variable &a_setVal)=0
virtual void RegisterForStatsEvent(BSTEventSink< StatsEvent > *a_sink)=0
virtual bool CreateObject2(const BSFixedString &a_className, BSTSmartPointer< Object > &a_result)=0
virtual void Update(float a_budget)=0
bool GetVariableValue(const BSTSmartPointer< Object > &a_objPtr, std::uint32_t a_index, Variable &a_out) const
bool GetScriptObjectType(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr)
bool CreateObject(const BSFixedString &a_className, BSTSmartPointer< Object > &a_result)
virtual void MoveBoundObjects(VMHandle a_from, VMHandle a_to)=0
virtual bool RegisterObjectType(VMTypeID a_typeID, const char *a_className)=0
virtual void SetCallableFromTasklets1(const char *a_className, const char *a_stateName, const char *a_fnName, bool a_callable)=0
IObjectHandlePolicy * GetObjectHandlePolicy()
virtual bool IsWaitingOnLatent(VMStackID a_stackID) const =0
virtual void ForEachBoundObject(VMHandle a_handle, IForEachScriptObjectFunctor *a_functor)=0
virtual void UnregisterForStatsEvent(BSTEventSink< StatsEvent > *a_sink)=0
bool GetScriptObjectTypeNoLoad(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_typeInfoPtr) const
requires is_return_convertible_v< V > void ReturnLatentResult(VMStackID a_stackID, V result)
Returns a result to the stack if it is waiting for a latent function to return. This is a wrapper ove...
Definition: NativeLatentFunction.h:105
Awaitable DispatchMethodCall(BSTSmartPointer< Object > &a_obj, const BSFixedString &a_fnName, IFunctionArguments *a_args)
virtual bool TypeIsValid(const BSFixedString &a_className)=0
virtual bool GetScriptObjectTypeNoLoad2(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr) const =0
virtual bool ReloadType(const char *a_className)=0
virtual bool GetVariableValue1(const BSTSmartPointer< Object > &a_objPtr, std::uint32_t a_index, Variable &a_out) const =0
virtual bool CastObject(const BSTSmartPointer< Object > &a_fromObjPtr, const BSTSmartPointer< ObjectTypeInfo > &a_toTypeInfoPtr, BSTSmartPointer< Object > &a_toObjPtr)=0
virtual bool BindNativeMethod(IFunction *a_fn)=0
virtual bool GetParentNativeType(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_typeInfoPtr)=0
bool GetScriptObjectTypeNoLoad(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr) const
virtual void SendEvent(VMHandle a_handle, const BSFixedString &a_eventName, IFunctionArguments *a_args)=0
virtual void TraceStack(const char *a_str, VMStackID a_stackID, Severity a_severity=Severity::kError)=0
bool CreateArray(TypeInfo::RawType a_typeID, const BSFixedString &a_className, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)
virtual void SetCallableFromTasklets2(const char *a_className, const char *a_fnName, bool a_callable)=0
void TraceForm(TESForm *a_form, const char *a_str, VMStackID a_stackID, Severity a_severity=Severity::kError)
virtual ObjectBindPolicy * GetObjectBindPolicy1()=0
static constexpr auto RTTI
Definition: IVirtualMachine.h:41
void SetCallableFromTasklets(const char *a_className, const char *a_fnName, bool a_callable)
void VTraceStack(VMStackID a_stackID, Severity a_severity, const char *a_fmt,...)
virtual bool DispatchMethodCall1(BSTSmartPointer< Object > &a_obj, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)=0
bool GetScriptObjectType(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr)
const ObjectBindPolicy * GetObjectBindPolicy() const
bool CreateObject(const BSFixedString &a_className, void *a_property, BSTSmartPointer< Object > &a_objPtr)
bool GetVariableValue(VMHandle a_handle, const BSFixedString &a_className, std::int32_t a_variableIndex, Variable &a_out) const
virtual bool GetPropertyValue(BSTSmartPointer< Object > &a_obj, const char *a_propertyName, Variable &a_getVal)=0
void RegisterLatentFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets=false)
Registers a latent function. Unlike normal native functions, latent functions do not return a result ...
Definition: NativeLatentFunction.h:88
virtual void TasksToJobs(BSJobs::JobList &a_jobList)=0
const IObjectHandlePolicy * GetObjectHandlePolicy() const
virtual IObjectHandlePolicy * GetObjectHandlePolicy1()=0
virtual bool GetVariableValue2(VMHandle a_handle, const BSFixedString &a_className, std::int32_t a_variableIndex, Variable &a_out) const =0
bool CreateArray(const TypeInfo &a_typeInfo, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)
virtual void SendEventAll(const BSFixedString &a_eventName, IFunctionArguments *a_args)=0
ObjectBindPolicy * GetObjectBindPolicy()
virtual ErrorLogger * GetErrorLogger()=0
Definition: BSScriptObjectBindPolicy.h:16
Definition: TypeInfo.h:10
RawType
Definition: TypeInfo.h:13
Definition: Variable.h:15
Definition: BSTArray.h:378
Definition: BSTEvent.h:143
Definition: BSTSmartPointer.h:37
Definition: TESForm.h:40
Definition: AbsorbEffect.h:6
constexpr REL::ID RTTI_BSScript__IVirtualMachine(static_cast< std::uint64_t >(691836))
constexpr std::array< REL::ID, 1 > VTABLE_BSScript__IVirtualMachine
Definition: Offsets_VTABLE.h:9464
std::uint32_t VMTypeID
Definition: BSCoreTypes.h:9
std::uint32_t VMStackID
Definition: BSCoreTypes.h:8
std::uint64_t VMHandle
Definition: BSCoreTypes.h:7
requires(std::invocable< std::remove_reference_t< EF >>) class scope_exit
Definition: PCH.h:151
Definition: BSIntrusiveRefCounted.h:8
Definition: IObjectHandlePolicy.h:13
Variable result
Definition: IVirtualMachine.h:53
bool pending
Definition: IVirtualMachine.h:52
std::coroutine_handle continuation
Definition: IVirtualMachine.h:54
void SetObject(const BSTSmartPointer< Object > &) override
Definition: IVirtualMachine.h:50
Definition: IVirtualMachine.h:46
void await_suspend(std::coroutine_handle<> a_handle)
void SetPending(bool a_pending=true)
BSTSmartPointer< IStackCallbackFunctor > callback
Definition: IVirtualMachine.h:63