Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add BSScript Types #177

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions CommonLibSF/include/RE/A/Array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#pragma once

#include "RE/B/BSContainer.h"
#include "RE/B/BSFixedString.h"
#include "RE/B/BSIntrusiveRefCounted.h"
#include "RE/B/BSLock.h"
#include "RE/B/BSTArray.h"
#include "RE/B/BSTEvent.h"
#include "RE/B/BSTSmartPointer.h"
#include "RE/M/MemoryManager.h"
#include "RE/T/TypeInfo.h"
#include "RE/V/Variable.h"

namespace RE
{
namespace BSScript
{
class TypeInfo;
class Variable;

class Array :
public BSIntrusiveRefCounted // 00
{
private:
Array* ctor(const TypeInfo* type_info, std::uint32_t initial_size = 0);
void dtor();

public:
using value_type = Variable;
using size_type = std::uint32_t;
using difference_type = std::int32_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = value_type*;
using const_iterator = const value_type*;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;

Array(const TypeInfo* type_info, std::uint32_t initial_size = 0);
~Array();

[[nodiscard]] reference operator[](size_type a_pos);
[[nodiscard]] const_reference operator[](size_type a_pos) const;

[[nodiscard]] reference front();
[[nodiscard]] const_reference front() const;

[[nodiscard]] reference back();
[[nodiscard]] const_reference back() const;

[[nodiscard]] pointer data() noexcept;
[[nodiscard]] const_pointer data() const noexcept;

[[nodiscard]] iterator begin() noexcept;
[[nodiscard]] const_iterator begin() const noexcept;
[[nodiscard]] const_iterator cbegin() const noexcept;

[[nodiscard]] iterator end() noexcept;
[[nodiscard]] const_iterator end() const noexcept;
[[nodiscard]] const_iterator cend() const noexcept;

[[nodiscard]] reverse_iterator rbegin() noexcept;
[[nodiscard]] const_reverse_iterator rbegin() const noexcept;
[[nodiscard]] const_reverse_iterator crbegin() const noexcept;

[[nodiscard]] reverse_iterator rend() noexcept;
[[nodiscard]] const_reverse_iterator rend() const noexcept;
[[nodiscard]] const_reverse_iterator crend() const noexcept;

[[nodiscard]] bool empty() const noexcept;

[[nodiscard]] size_type size() const noexcept;

[[nodiscard]] size_type max_size() const noexcept;

[[nodiscard]] TypeInfo& type_info();
[[nodiscard]] const TypeInfo& type_info() const;

[[nodiscard]] TypeInfo::RawType type() const;

// members
TypeInfo elementType; // 08
BSSpinLock elementsLock; // 10
BSTArray<Variable> elements; // 18
};
static_assert(sizeof(Array) == 0x28);
}
}
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/B/BGSObjectInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace RE
BGSObjectInstance* ctor(TESForm* a_object, TBO_InstanceData* a_instanceData)
{
using func_t = decltype(&BGSObjectInstance::ctor);
REL::Relocation<func_t> func{ Offset::BGSObjectInstance::ctor };
REL::Relocation<func_t> func{ ID::BGSObjectInstance::ctor };
return func(this, a_object, a_instanceData);
}
};
Expand Down
4 changes: 2 additions & 2 deletions CommonLibSF/include/RE/C/ConsoleLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace RE
// BSTSDM
[[nodiscard]] static ConsoleLog* GetSingleton()
{
static REL::Relocation<ConsoleLog**> singleton{ Offset::ConsoleLog::singleton };
static REL::Relocation<ConsoleLog**> singleton{ ID::ConsoleLog::singleton };
return *singleton;
}

void VPrint(const char* a_fmt, std::va_list a_args)
{
using func_t = decltype(&ConsoleLog::VPrint);
REL::Relocation<func_t> func{ Offset::ConsoleLog::VPrint };
REL::Relocation<func_t> func{ ID::ConsoleLog::VPrint };
func(this, a_fmt, a_args);
}

Expand Down
28 changes: 28 additions & 0 deletions CommonLibSF/include/RE/I/IComplexType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "RE/B/BSIntrusiveRefCounted.h"
#include "RE/T/TypeInfo.h"

namespace RE
{
namespace BSScript
{
class TypeInfo;

class __declspec(novtable) IComplexType :
public BSIntrusiveRefCounted // 08
{
public:
SF_RTTI_VTABLE(BSScript__IComplexType);

// TODO: Verify that setting this to default doesn't fuck everything up
virtual ~IComplexType() = default; // 00

// add
virtual TypeInfo::RawType GetRawType() const = 0; // 01

[[nodiscard]] bool IsObject() const { return GetRawType() == TypeInfo::RawType::kObject; }
};
static_assert(sizeof(IComplexType) == 0x10);
}
}
32 changes: 32 additions & 0 deletions CommonLibSF/include/RE/I/IVMObjectBindInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

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

namespace RE
{
namespace BSScript
{
class Object;

struct __declspec(novtable) IVMObjectBindInterface
{
public:
SF_RTTI_VTABLE(BSScript__IVMObjectBindInterface);
virtual ~IVMObjectBindInterface(); // 00

// add
[[nodiscard]] virtual std::uint64_t GetBoundHandle(const BSTSmartPointer<Object>& a_objPtr) const = 0; // 01
virtual void TypeCanBeBound(const BSFixedString& a_className, std::uint64_t a_handle) = 0; // 02
virtual void BindObject(BSTSmartPointer<Object>& a_objPtr, std::uint64_t a_handle, bool a_conditional) = 0; // 03
virtual void HandleLoadedBinding(BSTSmartPointer<Object>& a_objPtr, std::uint64_t a_handle, bool a_conditional) = 0; // 04
virtual void RemoveAllBoundObjects(std::uint64_t a_handle) = 0; // 05
virtual void RemoveAllDiskLoadedBoundObjects(std::uint64_t a_handle) = 0; // 06
virtual void HandleCObjectDeletion(std::uint64_t a_handle) = 0; // 07
virtual void UnbindObject(const BSTSmartPointer<Object>& a_objPtr) = 0; // 08
virtual bool CreateObjectWithProperties(const BSFixedString& a_className, std::uint32_t a_numProperties, BSTSmartPointer<Object>& a_objPtr) = 0; // 09
virtual bool InitObjectProperties(BSTSmartPointer<Object>& a_objPtr, void* a_property, bool a_arg3) = 0; // 0A
};
static_assert(sizeof(IVMObjectBindInterface) == 0x8);
}
}
30 changes: 30 additions & 0 deletions CommonLibSF/include/RE/IDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ namespace RE::ID

namespace BSScript
{
namespace Array
{
inline constexpr REL::ID ctor{ 196577 };
inline constexpr REL::ID dtor{ 196579 };
}

namespace Object
{
inline constexpr REL::ID ctor{ 196025 };
inline constexpr REL::ID dtor{ 196032 };
inline constexpr REL::ID GetHandle{ 196069 };
inline constexpr REL::ID SetHandle{ 196079 };
inline constexpr REL::ID IncRef{ 37879 };
inline constexpr REL::ID DecRef{ 196057 };
}

namespace ObjectTypeInfo
{
inline constexpr REL::ID ctor{ 197047 };
inline constexpr REL::ID dtor{ 196202 };
inline constexpr REL::ID Clear{ 196218 };
inline constexpr REL::ID CopyFromLinkedData{ 196219 };
inline constexpr REL::ID GetProperty{ 196241 };
}

namespace Internal
{
namespace NF_util
Expand Down Expand Up @@ -124,6 +149,11 @@ namespace RE::ID
inline constexpr REL::ID PlayMenuSound{ 167344 };
}

namespace ObjectBindPolicy
{
inline constexpr REL::ID BindObject{ 195981 };
}

namespace PlayerCamera
{
inline constexpr REL::ID singleton{ 878523 };
Expand Down
10 changes: 5 additions & 5 deletions CommonLibSF/include/RE/N/NativeFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace RE
virtual std::uint64_t* GetParam(std::uint32_t a_idx, BSFixedString* a_nameOut, std::uint64_t* a_typeOut)
{
using func_t = std::add_pointer_t<std::uint64_t*(ParameterInfo*, std::uint32_t, BSFixedString*, std::uint64_t*)>;
REL::Relocation<func_t> func{ Offset::BSScript::Internal::NF_util::NativeFunctionBase::GetParam };
REL::Relocation<func_t> func{ ID::BSScript::Internal::NF_util::NativeFunctionBase::GetParam };
return func(&_params, a_idx, a_nameOut, a_typeOut);
}
virtual std::uint64_t GetNumParams2(void) override { return _params.unk0A; }
Expand All @@ -73,13 +73,13 @@ namespace RE
virtual std::uint32_t Invoke(std::uint64_t a_unk0, std::uint64_t a_unk1, VMClassRegistry* a_registry, VMState* a_unk3) override
{
using func_t = decltype(&NativeFunctionBase::Invoke);
REL::Relocation<func_t> func{ Offset::BSScript::Internal::NF_util::NativeFunctionBase::Invoke };
REL::Relocation<func_t> func{ ID::BSScript::Internal::NF_util::NativeFunctionBase::Invoke };
return func(this, a_unk0, a_unk1, a_registry, a_unk3);
}
virtual BSFixedString* Unk_10(void) override
{
using func_t = decltype(&NativeFunctionBase::Unk_10);
REL::Relocation<func_t> func{ Offset::BSScript::Internal::NF_util::NativeFunctionBase::Unk_10 };
REL::Relocation<func_t> func{ ID::BSScript::Internal::NF_util::NativeFunctionBase::Unk_10 };
return func(this);
}
virtual bool Unk_11(std::uint32_t a_unk0, std::uint32_t* a_unk1) override
Expand All @@ -104,13 +104,13 @@ namespace RE
virtual bool GetParamInfo(std::uint32_t a_idx, void* a_out) override
{
using func_t = decltype(&NativeFunctionBase::GetParamInfo);
REL::Relocation<func_t> func{ Offset::BSScript::Internal::NF_util::NativeFunctionBase::GetParamInfo };
REL::Relocation<func_t> func{ ID::BSScript::Internal::NF_util::NativeFunctionBase::GetParamInfo };
return func(this, a_idx, a_out);
}
virtual void* Unk_15(std::uint64_t a_arg0, std::uint64_t a_arg1)
{
using func_t = decltype(&NativeFunctionBase::Unk_15);
REL::Relocation<func_t> func{ Offset::BSScript::Internal::NF_util::NativeFunctionBase::Unk_15 };
REL::Relocation<func_t> func{ ID::BSScript::Internal::NF_util::NativeFunctionBase::Unk_15 };
return func(this, a_arg0, a_arg1);
}
virtual bool GetUnk41(void) override { return _isCallableFromTasklet; }
Expand Down
97 changes: 97 additions & 0 deletions CommonLibSF/include/RE/O/Object.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once

#include "RE/B/BSContainer.h"
#include "RE/B/BSFixedString.h"
#include "RE/B/BSLock.h"
#include "RE/B/BSTArray.h"
#include "RE/B/BSTEvent.h"
#include "RE/B/BSTSmartPointer.h"
#include "RE/I/IObjectHandlePolicy.h"
#include "RE/M/MemoryManager.h"
#include "RE/O/ObjectTypeInfo.h"

namespace RE
{
namespace BSScript
{
class ObjectTypeInfo;
class Variable;

class Object
{
public:
void dtor()
{
using func_t = decltype(&Object::dtor);
REL::Relocation<func_t> func{ ID::BSScript::Object::dtor };
return func(this);
}

~Object()
{
dtor();
}

Object* ctor(const BSTSmartPointer<ObjectTypeInfo>& a_type, const IObjectHandlePolicy& a_handlePolicy, std::uint32_t a_numProperties)
{
using func_t = decltype(&Object::ctor);
REL::Relocation<func_t> func{ ID::BSScript::Object::ctor };
return func(this, a_type, a_handlePolicy, a_numProperties);
}

Object(const BSTSmartPointer<ObjectTypeInfo>& a_type, const IObjectHandlePolicy& a_handlePolicy, std::uint32_t a_numProperties)
{
ctor(a_type, a_handlePolicy, a_numProperties);
}

Object() = delete;

[[nodiscard]] constexpr bool IsConstructed() const noexcept { return static_cast<bool>(constructed); }
[[nodiscard]] constexpr bool IsInitialized() const noexcept { return static_cast<bool>(initialized); }
[[nodiscard]] constexpr bool IsValid() const noexcept { return static_cast<bool>(valid); }

[[nodiscard]] std::uint32_t DecRef() const
{
using func_t = decltype(&Object::DecRef);
REL::Relocation<func_t> func{ ID::BSScript::Object::DecRef };
return func(this);
}

[[nodiscard]] std::size_t GetHandle() const
{
using func_t = decltype(&Object::GetHandle);
REL::Relocation<func_t> func{ ID::BSScript::Object::GetHandle };
return func(this);
}

void IncRef() const
{
using func_t = decltype(&Object::IncRef);
REL::Relocation<func_t> func{ ID::BSScript::Object::IncRef };
return func(this);
}

SF_HEAP_REDEFINE_NEW();

// members
std::uint16_t unk00; // 00
std::uint16_t unk02; // 02
std::uint32_t unk04; // 04
std::uint64_t unk08; // 08
std::uint32_t constructed: 1; // 10:00
std::uint32_t initialized: 1; // 10:01
std::uint32_t valid: 1; // 10:02
std::uint32_t remainingPropsToInit: 29; // 10:03
std::uint32_t unk14; // 14
std::uint32_t unk18; // 18
std::uint32_t unk1C; // 1C
BSTSmartPointer<ObjectTypeInfo> type; // 20
BSFixedString currentState; // 28
void* lockStructure; // 30
IObjectHandlePolicy* handlePolicy; // 38
std::size_t handle; // 40
std::uint32_t refCountAndHandleLock; // 48
};
static_assert(sizeof(Object) == 0x50);
}
}
Loading
Loading