Skip to content

Commit

Permalink
feat: Add BSScript Types (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita authored Oct 21, 2023
1 parent 54c2797 commit f6e9011
Show file tree
Hide file tree
Showing 18 changed files with 1,522 additions and 0 deletions.
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);
}
}
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 @@ -54,6 +54,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 @@ -130,6 +155,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
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

0 comments on commit f6e9011

Please sign in to comment.