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..a5ef51a06a 100644 --- a/include/RE/O/ObjectTypeInfo.h +++ b/include/RE/O/ObjectTypeInfo.h @@ -139,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; 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); - } } }