diff --git a/include/RED4ext/Callback.hpp b/include/RED4ext/Callback.hpp index ae0e8ba2b..35f144d5f 100644 --- a/include/RED4ext/Callback.hpp +++ b/include/RED4ext/Callback.hpp @@ -221,7 +221,7 @@ class FlexCallback static_assert(InlineSize >= sizeof(void*), "Buffer size can't be less than pointer size"); FlexCallback(R (*aFunc)(Args...)) - : allocator(nullptr) + : allocator(0) , extendedSize(0) { using TargetType = Detail::UnboundFunctionTarget; @@ -233,7 +233,7 @@ class FlexCallback template FlexCallback(C* aContext, R (C::*aFunc)(Args...)) - : allocator(nullptr) + : allocator(0) , extendedSize(0) { using TargetType = Detail::MemberFunctionTarget; @@ -246,7 +246,7 @@ class FlexCallback template requires Detail::IsClosure FlexCallback(L&& aClosure) - : allocator(nullptr) + : allocator(0) , extendedSize(0) { using TargetType = Detail::ClosureTarget; @@ -311,7 +311,7 @@ class FlexCallback uint8_t buffer[InlineSize]; HandlerPtr handler; - Memory::IAllocator* allocator; + uint64_t allocator; // This is not a pointer to allocator, this is allocator instance that takes 8 bytes uint32_t extendedSize; protected: @@ -344,17 +344,22 @@ class FlexCallback handler = nullptr; } + inline Memory::IAllocator* GetAllocator() + { + return reinterpret_cast(&allocator); + } + void InitializeBuffer(uint32_t aSize) { if (aSize > InlineSize) { if (!allocator) { - allocator = AllocatorType::Get(); + std::memcpy(&allocator, AllocatorType::Get(), sizeof(uint64_t)); } auto bufferPtr = reinterpret_cast(buffer); - *bufferPtr = allocator->Alloc(aSize).memory; + *bufferPtr = reinterpret_cast(&allocator)->Alloc(aSize).memory; extendedSize = aSize; extendedSize |= ExtendedFlag; @@ -365,7 +370,7 @@ class FlexCallback } } - void InitializeBuffer(uint32_t aSize, Memory::IAllocator* aAllocator) + void InitializeBuffer(uint32_t aSize, uint64_t aAllocator) { allocator = aAllocator; @@ -406,7 +411,7 @@ class FlexCallback { if (IsExtendedMode()) { - allocator->Free(GetBuffer()); + reinterpret_cast(&allocator)->Free(GetBuffer()); extendedSize = 0; } } diff --git a/include/RED4ext/ResourceReference.hpp b/include/RED4ext/ResourceReference.hpp index 8d57ed3e9..8bdd9ef62 100644 --- a/include/RED4ext/ResourceReference.hpp +++ b/include/RED4ext/ResourceReference.hpp @@ -166,6 +166,16 @@ struct ResourceAsyncReference return *this; } + bool operator==(const ResourceAsyncReference& aRhs) const noexcept + { + return path == aRhs.path; + } + + bool operator!=(const ResourceAsyncReference& aRhs) const noexcept + { + return !(*this == aRhs); + } + [[nodiscard]] ResourceReference Resolve() const noexcept { return {path};