Skip to content

Commit

Permalink
Merge pull request #117 from psiberx/master
Browse files Browse the repository at this point in the history
Fix ISerializable and RawBuffer
  • Loading branch information
wopss authored Apr 24, 2024
2 parents 3b1697f + 1b841f5 commit 5ea7a1e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
1 change: 1 addition & 0 deletions include/RED4ext/Detail/AddressHashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ constexpr std::uint32_t ISerializable_sub_40 = 0x88B30FF9;
constexpr std::uint32_t ISerializable_sub_78 = 0xA1D93993;
constexpr std::uint32_t ISerializable_sub_A0 = 0xED221B32;
constexpr std::uint32_t ISerializable_sub_C0 = 0x80201C35;
constexpr std::uint32_t ISerializable_Counter = 2630817091;
#pragma endregion

#pragma region JobDispatcher
Expand Down
5 changes: 5 additions & 0 deletions include/RED4ext/ISerializable-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <RED4ext/RTTITypes.hpp>
#include <RED4ext/Relocation.hpp>

RED4EXT_INLINE RED4ext::ISerializable::ISerializable()
: unk28(InterlockedIncrement64(s_globalIDCounter.GetAddr()))
{
}

RED4EXT_INLINE RED4ext::CClass* RED4ext::ISerializable::GetType()
{
return GetNativeType();
Expand Down
6 changes: 5 additions & 1 deletion include/RED4ext/ISerializable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct CString;

struct ISerializable
{
ISerializable();

virtual CClass* GetNativeType() = 0; // 00
virtual CClass* GetType(); // 08
virtual Memory::IAllocator* GetAllocator(); // 10
Expand Down Expand Up @@ -51,7 +53,9 @@ struct ISerializable

WeakHandle<ISerializable> ref; // 00 - Initialized in Handle ctor
WeakHandle<ISerializable> unk18; // 18
uint64_t unk28; // 28 - Incremental ID set in ISerializable ctor, can be zero
uint64_t unk28; // 28 - Global incremental ID, used in serialization

inline static UniversalRelocPtr<volatile int64_t> s_globalIDCounter{Detail::AddressHashes::ISerializable_Counter};
};
RED4EXT_ASSERT_SIZE(ISerializable, 0x30);
} // namespace RED4ext
Expand Down
24 changes: 24 additions & 0 deletions include/RED4ext/NativeTypes-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ RED4EXT_INLINE bool RED4ext::Variant::CanBeInlined(const RED4ext::CBaseRTTIType*
return aType->GetSize() <= InlineSize && aType->GetAlignment() <= InlineAlignment;
}

RED4EXT_INLINE RED4ext::RawBuffer::RawBuffer()
: data(nullptr)
, size(0)
, alignment(8)
, allocator{0}
{
}

RED4EXT_INLINE RED4ext::RawBuffer::RawBuffer(void* aData, uint32_t aSize, uint32_t aAlignment)
: data(aData)
, size(aSize)
, alignment(aAlignment)
, allocator{0}
{
}

RED4EXT_INLINE RED4ext::RawBuffer::~RawBuffer()
{
if (data && allocator[0])
{
reinterpret_cast<RawBufferAllocator*>(&allocator)->Free(data);
}
}

RED4EXT_INLINE RED4ext::SharedPtr<RED4ext::DeferredDataBufferToken> RED4ext::DeferredDataBuffer::LoadAsync()
{
using LoadBufferAsync_t = JobHandle* (*)(DeferredDataBuffer*, JobHandle*, int64_t);
Expand Down
25 changes: 20 additions & 5 deletions include/RED4ext/NativeTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <RED4ext/InstanceType.hpp>
#include <RED4ext/NodeRef.hpp>
#include <RED4ext/ResourceReference.hpp>
#include <RED4ext/Unks.hpp>

namespace RED4ext
{
Expand Down Expand Up @@ -168,14 +167,30 @@ struct Variant
};
RED4EXT_ASSERT_SIZE(Variant, 0x18);

struct RawBufferAllocator
{
virtual void sub_00() = 0; // 08
virtual void Free(void* aData) = 0; // 08
virtual Memory::IAllocator GetAllocator() = 0; // 10

void* unk08;
};
RED4EXT_ASSERT_SIZE(RawBufferAllocator, 0x10);

struct RawBuffer
{
using AllocatorType = Memory::EngineAllocator;

void* data; // 00
uint32_t size; // 08
uint32_t alignment; // 0C
Unk530 unk10; // 10
RawBuffer();
RawBuffer(void* aData, uint32_t aSize, uint32_t aAlignment = 8);
RawBuffer(const RawBuffer&) = delete;
RawBuffer(RawBuffer&&) = default;
~RawBuffer();

void* data; // 00
uint32_t size; // 08
uint32_t alignment; // 0C
uint64_t allocator[2]; // 10
};
RED4EXT_ASSERT_SIZE(RawBuffer, 0x20);

Expand Down
8 changes: 1 addition & 7 deletions include/RED4ext/ResourcePath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ struct ResourcePath

constexpr ResourcePath& operator=(const char* aRhs) noexcept
{
*this = ResourcePath(aRhs);
return *this;
}

constexpr ResourcePath& operator=(const ResourcePath& aRhs) noexcept
{
hash = aRhs.hash;
hash = HashSanitized(aRhs);
return *this;
}

Expand Down
14 changes: 0 additions & 14 deletions include/RED4ext/Unks.hpp

This file was deleted.

0 comments on commit 5ea7a1e

Please sign in to comment.