Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions include/RE/IDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ namespace RE::ID
{
inline constexpr REL::ID ctor{ 137778 }; // 196025
inline constexpr REL::ID dtor{ 0 }; // 196032 - inlined
inline constexpr REL::ID dtorUnkSub{ 137823 };
inline constexpr REL::ID GetHandle{ 0 }; // 196069 - inlined
inline constexpr REL::ID SetHandle{ 0 }; // 196079
inline constexpr REL::ID IncRef{ 0 }; // 37879
Expand All @@ -289,8 +290,8 @@ namespace RE::ID

namespace ObjectTypeInfo
{
inline constexpr REL::ID ctor{ 0 }; // 197047
inline constexpr REL::ID dtor{ 0 }; // 196202
inline constexpr REL::ID ctor{ 138400 }; // 197047
inline constexpr REL::ID dtor{ 137885 }; // 196202
inline constexpr REL::ID Clear{ 0 }; // 196218
inline constexpr REL::ID CopyFromLinkedData{ 0 }; // 196219
inline constexpr REL::ID GetProperty{ 0 }; // 196241
Expand Down
11 changes: 2 additions & 9 deletions include/RE/O/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ namespace RE::BSScript
class Object
{
public:
void dtor()
{
using func_t = decltype(&Object::dtor);
static REL::Relocation<func_t> func{ ID::BSScript::Object::dtor };
return func(this);
}
void dtor();

~Object()
{
// TODO: The destructor was inlined in version Starfield 1.15 and still needs to be
// pieced together or reimplemented
dtor();
}

Expand Down Expand Up @@ -66,7 +59,7 @@ namespace RE::BSScript
std::uint32_t unk1C; // 1C
BSTSmartPointer<ObjectTypeInfo> type; // 20
BSFixedString currentState; // 28
void* lockStructure; // 30
volatile void* lockStructure; // 30
IObjectHandlePolicy* handlePolicy; // 38
std::size_t handle; // 40
volatile std::uint32_t refCountAndHandleLock; // 48
Expand Down
25 changes: 25 additions & 0 deletions src/RE/O/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

namespace RE::BSScript
{
void Object::dtor()
{
static REL::Relocation<void (*)(Object*)> UnkObjectDtorSubroutine{ ID::BSScript::Object::dtorUnkSub };
typedef ObjectTypeInfo* (*ObjectTypeInfoDeallocator)(ObjectTypeInfo*, std::uint32_t);
static REL::Relocation<ObjectTypeInfoDeallocator> ObjectTypeInfoDealloc{ ID::BSScript::ObjectTypeInfo::dtor };

this->lockStructure =
reinterpret_cast<void*>(reinterpret_cast<volatile std::uint64_t>(this->lockStructure) & 0xfffffffffffffffe);

if (this->lockStructure != 0) {
_InterlockedExchangeAdd(reinterpret_cast<volatile long*>(this->lockStructure), -1);
}

ObjectTypeInfo* pType = this->type.get();

//BSTSmartPointer will decrement type's refcount automatically at end of scope
if (pType->QRefCount() == 1) {
//This deallocates this->type and also sets its refcount to -1, which will prevent the smart pointer
//from trying to double free it afterward
ObjectTypeInfoDealloc(pType, 1);
}

UnkObjectDtorSubroutine(this);
}

[[nodiscard]] std::uint32_t Object::DecRef()
{
std::int32_t iVar1;
Expand Down
Loading