From 53f0f4362f691ba95c0e686e0beed02eddda74ef Mon Sep 17 00:00:00 2001 From: shad0wshayd3 <2724172+shad0wshayd3@users.noreply.github.com> Date: Thu, 17 Sep 2026 19:54:47 -0600 Subject: [PATCH 1/2] feat: `BSScript::Object::~Object` impl --- include/RE/O/Object.h | 3 --- include/RE/O/ObjectTypeInfo.h | 11 +++++++++++ src/RE/O/Object.cpp | 23 +++++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/RE/O/Object.h b/include/RE/O/Object.h index 0228ef4af0..a2fa9acce8 100644 --- a/include/RE/O/Object.h +++ b/include/RE/O/Object.h @@ -47,9 +47,6 @@ namespace RE volatile std::int32_t refCountAndHandleLock; // 28 std::uint32_t pad2C; // 2C Variable variables[0]; // 30 - size == classPtr->GetTotalNumVariables() + 3 - - private: - void Dtor(); }; static_assert(sizeof(Object) == 0x30); } diff --git a/include/RE/O/ObjectTypeInfo.h b/include/RE/O/ObjectTypeInfo.h index 6420c92b95..6588c73409 100644 --- a/include/RE/O/ObjectTypeInfo.h +++ b/include/RE/O/ObjectTypeInfo.h @@ -24,6 +24,17 @@ namespace RE kLinkedValid }; + [[nodiscard]] std::uint32_t GetVariableCount() const noexcept + { + std::uint32_t count = 0; + for (BSTSmartPointer iter{ this }; iter && iter->Valid(); iter = iter->parentTypeInfo) { + count += iter->variableCount; + } + return count; + } + + [[nodiscard]] bool Valid() const noexcept { return linkedValid == LinkValidState::kLinkedValid; } + struct UnlinkedNativeFunction { public: diff --git a/src/RE/O/Object.cpp b/src/RE/O/Object.cpp index 16543768c2..cfdb910087 100644 --- a/src/RE/O/Object.cpp +++ b/src/RE/O/Object.cpp @@ -10,7 +10,21 @@ namespace RE { Object::~Object() { - Dtor(); + if (IsConstructed()) { + const std::uint32_t size = type ? type->GetVariableCount() : 0; + for (std::uint32_t i = 0; i < size; ++i) { + variables[i].SetNone(); + } + + constructed = false; + initialized = false; + } + + auto lock = reinterpret_cast(lockStructure) & ~static_cast(1); + if (lock) { + REX::TAtomicRef l{ lock }; + --l; + } } VMHandle Object::GetHandle() const @@ -109,12 +123,5 @@ namespace RE return std::addressof(variables[offset + idx]); } - - void Object::Dtor() - { - using func_t = decltype(&Object::Dtor); - static REL::Relocation func{ RELOCATION_ID(97462, 104246) }; - return func(this); - } } } From 0bf6621dcd6c880f0c55bd9ba1075877178dc552 Mon Sep 17 00:00:00 2001 From: shad0wshayd3 <2724172+shad0wshayd3@users.noreply.github.com> Date: Thu, 17 Sep 2026 22:22:08 -0600 Subject: [PATCH 2/2] refactor: move `ObjectTypeInfo` additions --- include/RE/O/ObjectTypeInfo.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/include/RE/O/ObjectTypeInfo.h b/include/RE/O/ObjectTypeInfo.h index 6588c73409..a5ef51a06a 100644 --- a/include/RE/O/ObjectTypeInfo.h +++ b/include/RE/O/ObjectTypeInfo.h @@ -24,17 +24,6 @@ namespace RE kLinkedValid }; - [[nodiscard]] std::uint32_t GetVariableCount() const noexcept - { - std::uint32_t count = 0; - for (BSTSmartPointer iter{ this }; iter && iter->Valid(); iter = iter->parentTypeInfo) { - count += iter->variableCount; - } - return count; - } - - [[nodiscard]] bool Valid() const noexcept { return linkedValid == LinkValidState::kLinkedValid; } - struct UnlinkedNativeFunction { public: @@ -150,6 +139,20 @@ namespace RE } } + [[nodiscard]] constexpr bool IsLinkedValid() const noexcept + { + return linkedValid == LinkValidState::kLinkedValid; + } + + [[nodiscard]] std::uint32_t GetVariableCount() const noexcept + { + std::uint32_t count = 0; + for (BSTSmartPointer iter{ this }; iter && iter->IsLinkedValid(); iter = iter->parentTypeInfo) { + count += iter->variableCount; + } + return count; + } + UnlinkedNativeFunction* GetUnlinkedFunctionIter(); const UnlinkedNativeFunction* GetUnlinkedFunctionIter() const;