Skip to content

Commit

Permalink
feat: Implement IFuncCallQuery, RawFuncCallQuery, CodeTasklet (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita authored Oct 24, 2023
1 parent 0cd9f3d commit 32dfc33
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 0 deletions.
113 changes: 113 additions & 0 deletions CommonLibSF/include/RE/C/CodeTasklet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "RE/I/IFuncCallQuery.h"

namespace RE
{
namespace BSScript
{
class ErrorLogger;
class Stack; // stub
class StackFrame; // stub

namespace Internal
{
class VirtualMachine;

class CodeTasklet :
public IFuncCallQuery // 00
{
public:
SF_RTTI_VTABLE(BSScript__Internal__CodeTasklet);

enum class OpCode : std::uint32_t
{
kNOP,
kIADD,
kFADD,
kISUB,
kFSUB,
kIMUL,
kFMUL,
kIDIV,
kFDIV,
kIMOD,
kNOT,
kINEG,
kFNEG,
kASSIGN,
kCAST,
kCMP_EQ,
kCMP_LT,
kCMP_LTE,
kCMP_GT,
kCMP_GTE,
kJMP,
kJMPT,
kJMPF,
kCALLMETHOD,
kCALLPARENT,
kCALLSTATIC,
kRETURN,
kSTRCAT,
kPROPGET,
kPROPSET,
kARRAY_CREATE,
kARRAY_LENGTH,
kARRAY_GETELEMENT,
kARRAY_SETELEMENT,
kARRAY_FINDELEMENT,
kARRAY_RFINDELEMENT,
kIS,
kSTRUCT_CREATE,
kSTRUCT_GET,
kSTRUCT_SET,
kARRAY_FINDSTRUCT,
kARRAY_RFINDSTRUCT,
kARRAY_ADD,
kARRAY_INSERT,
kARRAY_REMOVELAST,
kARRAY_REMOVE,
kARRAY_CLEAR
};

enum class ResumeReason
{
kNotResuming = 0,
kNotResumingNoIncrement = 1,
kInitialStart = 2,
kFunctionReturn = 3,
kRetryInstruction = 4,
kFunctionCall = 5
};

virtual ~CodeTasklet(); // 00

// override (IFuncCallQuery)
virtual bool GetFunctionCallInfo(
CallType& a_callType,
BSTSmartPointer<ObjectTypeInfo>& a_objectTypeInfo,
BSFixedString& a_name,
Variable& a_self,
void* /* BSScrapArray<Variable>& */ a_args) const override; // 01

virtual BSTSmartPointer<Object> GetSelfAsObject() const override; // 02

// members
Stack* stack; // 10
VirtualMachine* vm; // 18
ErrorLogger* errorLogger; // 20
stl::enumeration<ResumeReason, std::uint32_t> resumeReason; // 28
std::uint32_t pad2C; // 2C
const void* instructionDataStart; // 30
StackFrame* topFrame; // 38
std::uint32_t frameMemoryPage; // 40
std::uint32_t instructionDataBitCount; // 44
std::int8_t jumpBitCount; // 48
std::int8_t localVarBitCount; // 49
std::int8_t memberVarBitCount; // 4A
std::int8_t unk4B; // 4B
std::uint32_t pad4C; // 4C
};
static_assert(sizeof(CodeTasklet) == 0x50);
}
}
}
43 changes: 43 additions & 0 deletions CommonLibSF/include/RE/I/IFuncCallQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "RE/B/BSFixedString.h"
#include "RE/B/BSIntrusiveRefCounted.h"
#include "RE/B/BSTSmartPointer.h"

namespace RE
{
namespace BSScript
{

class StackFrame;
class Variable;
class ObjectTypeInfo;
class Object;

class IFuncCallQuery : public BSIntrusiveRefCounted
{
public:
SF_RTTI_VTABLE(BSScript__Internal__IFuncCallQuery);

enum class CallType
{
kMember,
kStatic,
kGetter,
kSetter
};
virtual ~IFuncCallQuery(); // 00

// add
virtual bool GetFunctionCallInfo(
CallType& a_callType,
BSTSmartPointer<ObjectTypeInfo>& a_objectTypeInfo,
BSFixedString& a_name,
Variable& a_self,
void* /* BSScrapArray<Variable>& */ a_args) const = 0; // 01
virtual BSTSmartPointer<Object> GetSelfAsObject() const = 0; // 02
};
static_assert(sizeof(IFuncCallQuery) == 0x10);

};
}
50 changes: 50 additions & 0 deletions CommonLibSF/include/RE/R/RawFuncCallQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "RE/B/BSFixedString.h"
#include "RE/B/BSTSmartPointer.h"

#include "RE/B/BSTArray.h"
#include "RE/I/IFuncCallQuery.h"
#include "RE/V/Variable.h"
namespace RE
{
namespace BSScript
{

class StackFrame;
class Variable;
class ObjectTypeInfo;

namespace Internal
{
class RawFuncCallQuery :
public IFuncCallQuery // 00
{
public:
SF_RTTI_VTABLE(BSScript__Internal__RawFuncCallQuery);

virtual ~RawFuncCallQuery(); // 00

// override (IFuncCallQuery)
virtual bool GetFunctionCallInfo(
CallType& a_callType,
BSTSmartPointer<ObjectTypeInfo>& a_objectTypeInfo,
BSFixedString& a_name,
Variable& a_self,
void* /* BSScrapArray<Variable>& */ a_args) const override; // 01

virtual BSTSmartPointer<Object> GetSelfAsObject() const override; // 02 -- just calls get<BSTSmartPointer<Object>>()

// members
CallType callType; // 10
std::uint32_t pad14; // 14
BSTSmartPointer<ObjectTypeInfo> objType; // 18
BSFixedString name; // 20
Variable self; // 28
BSTArray<Variable> args; // 38
};
static_assert(sizeof(RawFuncCallQuery) == 0x48);
}

};
}
3 changes: 3 additions & 0 deletions CommonLibSF/include/RE/Starfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "RE/B/BSTTuple.h"
#include "RE/B/BSTTuple3.h"
#include "RE/B/BaseFormComponent.h"
#include "RE/C/CodeTasklet.h"
#include "RE/C/Color.h"
#include "RE/C/CombatGroup.h"
#include "RE/C/Console.h"
Expand All @@ -88,6 +89,7 @@
#include "RE/H/HandlePolicy.h"
#include "RE/I/IAnimationGraphManagerHolder.h"
#include "RE/I/IComplexType.h"
#include "RE/I/IFuncCallQuery.h"
#include "RE/I/IFunction.h"
#include "RE/I/IKeywordFormBase.h"
#include "RE/I/IMenu.h"
Expand Down Expand Up @@ -122,6 +124,7 @@
#include "RE/P/PlayerCharacter.h"
#include "RE/P/PropertyGroupInfo.h"
#include "RE/P/PropertyTypeInfo.h"
#include "RE/R/RawFuncCallQuery.h"
#include "RE/R/RegSettingCollection.h"
#include "RE/RTTI.h"
#include "RE/S/SWFToCodeFunctionHandler.h"
Expand Down

0 comments on commit 32dfc33

Please sign in to comment.