diff --git a/include/RED4ext/NativeTypes.hpp b/include/RED4ext/NativeTypes.hpp index 325f31ba3..076a737ac 100644 --- a/include/RED4ext/NativeTypes.hpp +++ b/include/RED4ext/NativeTypes.hpp @@ -162,8 +162,8 @@ struct Variant Variant(CName aTypeName); Variant(CName aTypeName, const void* aData); template - requires !std::derived_from>, rtti::IType> - Variant(const T& acValue) + requires(!std::derived_from>, rtti::IType>) + Variant(const T& acValue) : Variant(GetTypeName(), std::addressof(acValue)) { } @@ -290,7 +290,7 @@ struct Variant { // TODO: support all game types and user types using RedLib solution: // https://github.com/psiberx/cp2077-red-lib/blob/master/include/Red/TypeInfo/Resolving.hpp - static_assert(false, "Type is currently unsupported."); + static_assert(!std::is_same_v, "Type is currently unsupported."); return ""; } } diff --git a/include/RED4ext/TweakDB-inl.hpp b/include/RED4ext/TweakDB-inl.hpp index 1518dceef..f25e3519c 100644 --- a/include/RED4ext/TweakDB-inl.hpp +++ b/include/RED4ext/TweakDB-inl.hpp @@ -324,17 +324,20 @@ RED4EXT_INLINE int32_t RED4ext::TweakDB::CreateFlatValue(const CStackType& aStac UpsizeFlatDataBuffer(MaxFlatDataBufferSize); - uintptr_t flatAlignment = (std::max)(aStackType.type->GetAlignment(), 8u); - uintptr_t flatValueSize = RED4ext::AlignUp(8ull /* vftable */ + aStackType.type->GetSize(), flatAlignment); - uintptr_t flatDataBufferEnd_Aligned = RED4ext::AlignUp(flatDataBufferEnd, flatAlignment); + const uintptr_t flatAlignment = (std::max)(aStackType.type->GetAlignment(), 8u); + const uintptr_t flatValueSize = RED4ext::AlignUp(8ull /* vftable */ + aStackType.type->GetSize(), flatAlignment); + const uintptr_t flatAddressAligned = RED4ext::AlignUp(flatDataBufferEnd, flatAlignment); + const uintptr_t newFlatDataBufferEnd = flatAddressAligned + flatValueSize; - if (AllocateFlatValue(reinterpret_cast(flatDataBufferEnd_Aligned), aStackType)) + if (newFlatDataBufferEnd > (flatDataBuffer + flatDataBufferCapacity) || + !AllocateFlatValue(reinterpret_cast(flatAddressAligned), aStackType)) { - flatDataBufferEnd = flatDataBufferEnd_Aligned + flatValueSize; - return reinterpret_cast(flatDataBufferEnd_Aligned)->ToTDBOffset(); + return -1; } - return -1; + flatDataBufferEnd = newFlatDataBufferEnd; + + return reinterpret_cast(flatAddressAligned)->ToTDBOffset(); } RED4EXT_INLINE bool RED4ext::TweakDB::AllocateFlatValue(void* aBuffer, const CStackType& aStackType)