CommonLibSSE NG
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"
8 #include "RE/T/TypeInfo.h"
9 #include "RE/T/TypeTraits.h"
10 
11 namespace RE
12 {
13  namespace BSJobs
14  {
15  class JobList;
16  }
17 
18  class TESForm;
19 
20  namespace BSScript
21  {
22  class Array;
23  class ErrorLogger;
24  class IForEachScriptObjectFunctor;
25  class IFunction;
26  class IFunctionArguments;
27  class ISavePatcherInterface;
28  class IStackCallbackFunctor;
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 
44 
45  virtual ~IVirtualMachine(); // 00
46 
47  // add
48  virtual void SetLinkedCallback(ITypeLinkedCallback* a_callback) = 0; // 01
49  virtual void TraceStack(const char* a_str, VMStackID a_stackID, Severity a_severity = Severity::kError) = 0; // 02
50  virtual void FormatAndPostMessage(const char* a_message, Severity a_severity) = 0; // 03
51  virtual void Update(float a_budget) = 0; // 04
52  virtual void UpdateTasklets(float a_budget) = 0; // 05
53  virtual void SetOverstressed(bool a_set) = 0; // 06
54  virtual bool IsCompletelyFrozen() const = 0; // 07
55  virtual bool RegisterObjectType(VMTypeID a_typeID, const char* a_className) = 0; // 08
56  virtual bool GetScriptObjectType1(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) = 0; // 09
57  virtual bool GetScriptObjectType2(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) = 0; // 0A
58  virtual bool GetScriptObjectTypeNoLoad1(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) const = 0; // 0B
59  virtual bool GetScriptObjectTypeNoLoad2(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) const = 0; // 0C
60  virtual bool GetTypeIDForScriptObject(const BSFixedString& a_className, VMTypeID& a_typeID) const = 0; // 0D
61  virtual void GetScriptObjectsWithATypeID(BSScrapArray<BSFixedString>& a_classes) const = 0; // 0E
62  virtual bool GetParentNativeType(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) = 0; // 0F
63  virtual bool TypeIsValid(const BSFixedString& a_className) = 0; // 10
64  virtual bool ReloadType(const char* a_className) = 0; // 11
65  virtual void TasksToJobs(BSJobs::JobList& a_jobList) = 0; // 12
66  virtual void CalculateFullReloadList(void) const = 0; // 13
67  virtual bool CreateObject1(const BSFixedString& a_className, void* a_property, BSTSmartPointer<Object>& a_objPtr) = 0; // 14
68  virtual bool CreateObject2(const BSFixedString& a_className, BSTSmartPointer<Object>& a_result) = 0; // 15
69  virtual bool CreateArray1(const TypeInfo& a_typeInfo, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr) = 0; // 16
70  virtual bool CreateArray2(TypeInfo::RawType a_typeID, const BSFixedString& a_className, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr) = 0; // 17
71  virtual bool BindNativeMethod(IFunction* a_fn) = 0; // 18
72  virtual void SetCallableFromTasklets1(const char* a_className, const char* a_stateName, const char* a_fnName, bool a_callable) = 0; // 19
73  virtual void SetCallableFromTasklets2(const char* a_className, const char* a_fnName, bool a_callable) = 0; // 1A
74 #if !defined(ENABLE_SKYRIM_AE) && !defined(ENABLE_SKYRIM_SE)
75  virtual void New_1B(void) = 0;
76 #endif
77  SKYRIM_REL_VR_VIRTUAL void ForEachBoundObject(VMHandle a_handle, IForEachScriptObjectFunctor* a_functor); // 1B, 1C
78 #if !defined(ENABLE_SKYRIM_AE) && !defined(ENABLE_SKYRIM_SE)
79  virtual void New_1D(void) = 0;
80 #endif
81  SKYRIM_REL_VR_VIRTUAL bool FindBoundObject(VMHandle a_handle, const char* a_className, BSTSmartPointer<Object>& a_result) const; // 1C
84  SKYRIM_REL_VR_VIRTUAL bool CastObject(const BSTSmartPointer<Object>& a_fromObjPtr, const BSTSmartPointer<ObjectTypeInfo>& a_toTypeInfoPtr, BSTSmartPointer<Object>& a_toObjPtr); // 1F
85  SKYRIM_REL_VR_VIRTUAL bool SetPropertyValue(BSTSmartPointer<Object>& a_obj, const char* a_propertyName, Variable& a_setVal); // 20
86  SKYRIM_REL_VR_VIRTUAL bool GetPropertyValue(BSTSmartPointer<Object>& a_obj, const char* a_propertyName, Variable& a_getVal); // 21
87  SKYRIM_REL_VR_VIRTUAL bool GetVariableValue1(const BSTSmartPointer<Object>& a_objPtr, std::uint32_t a_index, Variable& a_out) const; // 22
88  SKYRIM_REL_VR_VIRTUAL bool GetVariableValue2(VMHandle a_handle, const BSFixedString& a_className, std::int32_t a_variableIndex, Variable& a_out) const; // 23
89  SKYRIM_REL_VR_VIRTUAL void SendEvent(VMHandle a_handle, const BSFixedString& a_eventName, IFunctionArguments* a_args); // 24
90  SKYRIM_REL_VR_VIRTUAL void SendEventAll(const BSFixedString& a_eventName, IFunctionArguments* a_args); // 25
95  SKYRIM_REL_VR_VIRTUAL bool IsWaitingOnLatent(VMStackID a_stackID) const; // 2A
96  SKYRIM_REL_VR_VIRTUAL void ReturnFromLatent(VMStackID a_stackID, const Variable& a_val); // 2B
107 
108  bool CreateArray(const TypeInfo& a_typeInfo, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr);
109  bool CreateArray(TypeInfo::RawType a_typeID, const BSFixedString& a_className, std::uint32_t a_size, BSTSmartPointer<Array>& a_arrayPtr);
110  bool CreateObject(const BSFixedString& a_className, void* a_property, BSTSmartPointer<Object>& a_objPtr);
111  bool CreateObject(const BSFixedString& a_className, BSTSmartPointer<Object>& a_result);
113  bool DispatchMethodCall(VMHandle a_handle, const BSFixedString& a_className, const BSFixedString& a_fnName, IFunctionArguments* a_args, BSTSmartPointer<IStackCallbackFunctor>& a_result);
118  bool GetScriptObjectType(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr);
120  bool GetScriptObjectTypeNoLoad(const BSFixedString& a_className, BSTSmartPointer<ObjectTypeInfo>& a_typeInfoPtr) const;
121  bool GetScriptObjectTypeNoLoad(VMTypeID a_typeID, BSTSmartPointer<ObjectTypeInfo>& a_outTypeInfoPtr) const;
122  bool GetVariableValue(const BSTSmartPointer<Object>& a_objPtr, std::uint32_t a_index, Variable& a_out) const;
123  bool GetVariableValue(VMHandle a_handle, const BSFixedString& a_className, std::int32_t a_variableIndex, Variable& a_out) const;
124 
125  template <class F>
126  void RegisterFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets = false);
127 
128  template <class R, class F>
129  void RegisterLatentFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets = false);
130 
131  template <class V>
132  requires is_return_convertible_v<V>
133  void ReturnLatentResult(VMStackID a_stackID, V result);
134 
135  void SetCallableFromTasklets(const char* a_className, const char* a_stateName, const char* a_fnName, bool a_callable);
136  void SetCallableFromTasklets(const char* a_className, const char* a_fnName, bool a_callable);
137  void TraceForm(TESForm* a_form, const char* a_str, VMStackID a_stackID, Severity a_severity = Severity::kError);
138  void VTraceStack(VMStackID a_stackID, Severity a_severity, const char* a_fmt, ...);
139 
140  // members
141  std::uint32_t pad0C; // 0C
142  };
143  static_assert(sizeof(IVirtualMachine) == 0x10);
144  }
145 }
#define SKYRIM_REL_VR_VIRTUAL
Definition: Common.h:94
Definition: ErrorLogger.h:13
Severity
Definition: ErrorLogger.h:18
Definition: IFunctionArguments.h:12
Definition: IFunction.h:23
Definition: ISavePatcherInterface.h:11
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
SKYRIM_REL_VR_VIRTUAL void MoveBoundObjects(VMHandle a_from, VMHandle a_to)
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
SKYRIM_REL_VR_VIRTUAL const IObjectHandlePolicy * GetObjectHandlePolicy2() const
SKYRIM_REL_VR_VIRTUAL void RegisterForLogEvent(BSTEventSink< LogEvent > *a_sink)
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
SKYRIM_REL_VR_VIRTUAL bool GetPropertyValue(BSTSmartPointer< Object > &a_obj, const char *a_propertyName, Variable &a_getVal)
virtual bool CreateArray2(TypeInfo::RawType a_typeID, const BSFixedString &a_className, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)=0
virtual bool GetScriptObjectType2(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr)=0
SKYRIM_REL_VR_VIRTUAL void UnregisterForStatsEvent(BSTEventSink< StatsEvent > *a_sink)
std::uint32_t pad0C
Definition: IVirtualMachine.h:141
virtual void SetLinkedCallback(ITypeLinkedCallback *a_callback)=0
SKYRIM_REL_VR_VIRTUAL bool DispatchUnboundMethodCall(void)
bool DispatchMethodCall(BSTSmartPointer< Object > &a_obj, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
SKYRIM_REL_VR_VIRTUAL bool DispatchMethodCall1(BSTSmartPointer< Object > &a_obj, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
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
SKYRIM_REL_VR_VIRTUAL bool GetVariableValue1(const BSTSmartPointer< Object > &a_objPtr, std::uint32_t a_index, Variable &a_out) const
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 void New_1B(void)=0
void RegisterFunction(std::string_view a_fnName, std::string_view a_className, F a_callback, bool a_callableFromTasklets=false)
Definition: NativeFunction.h:174
SKYRIM_REL_VR_VIRTUAL bool FindBoundObject(VMHandle a_handle, const char *a_className, BSTSmartPointer< Object > &a_result) const
virtual bool CreateObject2(const BSFixedString &a_className, BSTSmartPointer< Object > &a_result)=0
SKYRIM_REL_VR_VIRTUAL const ObjectBindPolicy * GetObjectBindPolicy2() const
SKYRIM_REL_VR_VIRTUAL bool SetPropertyValue(BSTSmartPointer< Object > &a_obj, const char *a_propertyName, Variable &a_setVal)
virtual void Update(float a_budget)=0
virtual void New_1D(void)=0
SKYRIM_REL_VR_VIRTUAL void RegisterForStatsEvent(BSTEventSink< StatsEvent > *a_sink)
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)
SKYRIM_REL_VR_VIRTUAL void UnregisterForLogEvent(BSTEventSink< LogEvent > *a_sink)
virtual bool RegisterObjectType(VMTypeID a_typeID, const char *a_className)=0
SKYRIM_REL_VR_VIRTUAL void SendEvent(VMHandle a_handle, const BSFixedString &a_eventName, IFunctionArguments *a_args)
SKYRIM_REL_VR_VIRTUAL void ResetAllBoundObjects(VMHandle a_handle)
virtual void SetCallableFromTasklets1(const char *a_className, const char *a_stateName, const char *a_fnName, bool a_callable)=0
SKYRIM_REL_VR_VIRTUAL IObjectHandlePolicy * GetObjectHandlePolicy1()
SKYRIM_REL_VR_VIRTUAL void SendEventAll(const BSFixedString &a_eventName, IFunctionArguments *a_args)
IObjectHandlePolicy * GetObjectHandlePolicy()
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
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 BindNativeMethod(IFunction *a_fn)=0
virtual bool GetParentNativeType(const BSFixedString &a_className, BSTSmartPointer< ObjectTypeInfo > &a_typeInfoPtr)=0
SKYRIM_REL_VR_VIRTUAL ISavePatcherInterface * GetSavePatcherInterface()
bool GetScriptObjectTypeNoLoad(VMTypeID a_typeID, BSTSmartPointer< ObjectTypeInfo > &a_outTypeInfoPtr) const
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)
static constexpr auto RTTI
Definition: IVirtualMachine.h:41
SKYRIM_REL_VR_VIRTUAL bool DispatchStaticCall(const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
SKYRIM_REL_VR_VIRTUAL bool DispatchMethodCall2(VMHandle a_handle, const BSFixedString &a_className, const BSFixedString &a_fnName, IFunctionArguments *a_args, BSTSmartPointer< IStackCallbackFunctor > &a_result)
void SetCallableFromTasklets(const char *a_className, const char *a_fnName, bool a_callable)
SKYRIM_REL_VR_VIRTUAL bool CastObject(const BSTSmartPointer< Object > &a_fromObjPtr, const BSTSmartPointer< ObjectTypeInfo > &a_toTypeInfoPtr, BSTSmartPointer< Object > &a_toObjPtr)
SKYRIM_REL_VR_VIRTUAL void ForEachBoundObject(VMHandle a_handle, IForEachScriptObjectFunctor *a_functor)
void VTraceStack(VMStackID a_stackID, Severity a_severity, const char *a_fmt,...)
SKYRIM_REL_VR_VIRTUAL ErrorLogger * GetErrorLogger()
SKYRIM_REL_VR_VIRTUAL void ReturnFromLatent(VMStackID a_stackID, const Variable &a_val)
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
SKYRIM_REL_VR_VIRTUAL ObjectBindPolicy * GetObjectBindPolicy1()
SKYRIM_REL_VR_VIRTUAL bool IsWaitingOnLatent(VMStackID a_stackID) const
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
bool CreateArray(const TypeInfo &a_typeInfo, std::uint32_t a_size, BSTSmartPointer< Array > &a_arrayPtr)
SKYRIM_REL_VR_VIRTUAL bool GetVariableValue2(VMHandle a_handle, const BSFixedString &a_className, std::int32_t a_variableIndex, Variable &a_out) const
ObjectBindPolicy * GetObjectBindPolicy()
Definition: BSScriptObjectBindPolicy.h:16
Definition: TypeInfo.h:10
RawType
Definition: TypeInfo.h:13
Definition: Variable.h:15
Definition: BSTArray.h:377
Definition: BSTEvent.h:143
Definition: BSTSmartPointer.h:36
Definition: TESForm.h:36
requires(is_builtin_convertible_v< T >) struct GetRawType< T >
Definition: PackUnpack.h:30
Definition: AbsorbEffect.h:6
std::uint32_t VMTypeID
Definition: BSCoreTypes.h:9
constexpr REL::VariantID RTTI_BSScript__IVirtualMachine(691836, 399880, 0x1f7ccc0)
std::uint32_t VMStackID
Definition: BSCoreTypes.h:8
std::uint64_t VMHandle
Definition: BSCoreTypes.h:7
Definition: BSIntrusiveRefCounted.h:8
Definition: IObjectHandlePolicy.h:13