Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 0 additions & 144 deletions include/RED4ext/CString-inl.hpp

This file was deleted.

102 changes: 3 additions & 99 deletions include/RED4ext/CString.hpp
Original file line number Diff line number Diff line change
@@ -1,106 +1,10 @@
#pragma once

#include <RED4ext/Common.hpp>
#include <RED4ext/HashMap.hpp>
#include <cstdint>
#include <string>
#include <string_view>
#include <RED4ext/String.hpp>

namespace RED4ext
{
namespace Memory
{
struct IAllocator;
}

struct CString
{
CString(Memory::IAllocator* aAllocator = nullptr);
CString(const char* aText, Memory::IAllocator* aAllocator = nullptr);
CString(const char* aText, uint32_t aLength, Memory::IAllocator* aAllocator = nullptr);
CString(const std::string& aText, Memory::IAllocator* aAllocator = nullptr);
CString(const std::string_view& aText, Memory::IAllocator* aAllocator = nullptr);

CString(const CString& aOther);
CString(CString&& aOther) noexcept;

~CString();

CString& operator=(const CString& aRhs);
CString& operator=(CString&& aRhs) noexcept;

bool operator==(const char* aRhs) const noexcept;
bool operator==(const CString& aRhs) const noexcept;

inline bool operator!=(const char* aRhs) const noexcept
{
return !(*this == aRhs);
}

inline bool operator!=(const CString& aRhs) const noexcept
{
return !(*this == aRhs);
}

inline const char& operator[](size_t aIndex) const
{
return c_str()[aIndex];
}

[[nodiscard]] bool IsInline() const noexcept;

[[nodiscard]] const char* c_str() const noexcept;
[[nodiscard]] uint32_t Length() const noexcept;

[[nodiscard]] const char* begin() const
{
return c_str();
}

[[nodiscard]] const char* end() const
{
return c_str() + Length();
}

#pragma pack(push, 4)
union
{
char inline_str[0x14];
struct
{
char* ptr;
int8_t unk[8];
int32_t capacity;
} str;
} text; // 00
#pragma pack(pop)

uint32_t length; // 14
Memory::IAllocator* allocator; // 18
};
RED4EXT_ASSERT_SIZE(CString, 0x20);
RED4EXT_ASSERT_OFFSET(CString, text, 0x00);
RED4EXT_ASSERT_OFFSET(CString, length, 0x14);
RED4EXT_ASSERT_OFFSET(CString, allocator, 0x18);

template<typename T>
struct HashMapHash<T, std::enable_if_t<std::is_same_v<T, CString>>>
{
uint32_t operator()(const T& aKey) const noexcept
{
// I believe the game uses this implementation for StringView and String?
std::uint32_t hash{};

for (const auto i : aKey)
{
hash = static_cast<std::uint32_t>(i) + 31u * hash;
}

return hash;
}
};
} // namespace RED4ext
using CString [[deprecated("Use red::String")]] = red::String;

#ifdef RED4EXT_HEADER_ONLY
#include <RED4ext/CString-inl.hpp>
#endif
}
21 changes: 10 additions & 11 deletions include/RED4ext/Dump/Reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#include <unordered_set>

#include <RED4ext/CName.hpp>
#include <RED4ext/rtti/ClassType.hpp>

namespace RED4ext
{
struct CClass;
struct CBaseRTTIType;
struct CProperty;
struct CEnum;
struct CBitfield;
Expand All @@ -21,10 +20,10 @@ namespace RED4ext::GameReflection
{
using GetPrefix = std::function<std::string(const std::string&)>;
using NameSantizer = std::function<std::string(const std::string&, bool&)>;
using NameTransformer = std::function<std::string(const RED4ext::CBaseRTTIType*)>;
using DescriptorPath = std::function<std::string(const RED4ext::CBaseRTTIType*)>;
using NamespaceTransformer = std::function<std::vector<std::string>(const RED4ext::CBaseRTTIType*)>;
using TypeChecker = std::function<bool(const RED4ext::CBaseRTTIType*)>;
using NameTransformer = std::function<std::string(const RED4ext::rtti::IType*)>;
using DescriptorPath = std::function<std::string(const RED4ext::rtti::IType*)>;
using NamespaceTransformer = std::function<std::vector<std::string>(const RED4ext::rtti::IType*)>;
using TypeChecker = std::function<bool(const RED4ext::rtti::IType*)>;
using FixedTypeMapping = std::unordered_map<RED4ext::CName, std::string, RED4ext::CName>;

static constexpr const char* INVALID_CHARACTERS = R"(-|'|\(|\)|\]|\[|/|\.|\s|:)";
Expand Down Expand Up @@ -102,21 +101,21 @@ struct BitfieldFileDescriptor

struct ClassDependencyBuilder
{
const RED4ext::CClass* pType;
std::unordered_set<const RED4ext::CBaseRTTIType*> mDirect;
std::unordered_set<const RED4ext::CBaseRTTIType*> mIndirect;
const RED4ext::rtti::ClassType* pType;
std::unordered_set<const RED4ext::rtti::IType*> mDirect;
std::unordered_set<const RED4ext::rtti::IType*> mIndirect;
std::map<uint64_t, const RED4ext::CProperty*> mPropertyMap;
std::map<uint64_t, const RED4ext::CProperty*> mHolderPropertyMap;

void Accumulate(const RED4ext::CBaseRTTIType* type);
void Accumulate(const RED4ext::rtti::IType* type);

void ToFileDescriptor(ClassFileDescriptor& aFd, NameTransformer aNameTransformer,
NameTransformer aQualifiedTransformer, DescriptorPath aTypeToPath,
DescriptorPath aTypeToOverride, TypeChecker aHandleCompatChecker,
const FixedTypeMapping& aFixedMapping, bool aVerbose);
};

std::string TypeToString(const RED4ext::CBaseRTTIType* aType, NameTransformer aNameTransformer, bool aVerbose = false);
std::string TypeToString(const RED4ext::rtti::IType* aType, NameTransformer aNameTransformer, bool aVerbose = false);

void EmitBulkGenerated(std::filesystem::path aOutPath, const std::set<std::string>& aIncludes);

Expand Down
10 changes: 10 additions & 0 deletions include/RED4ext/DynArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Memory
struct IAllocator;
}

namespace red
{

template<typename T>
struct DynArray
{
Expand Down Expand Up @@ -351,7 +354,14 @@ struct DynArray
}
}
};

RED4EXT_ASSERT_SIZE(DynArray<void*>, 0x10);
RED4EXT_ASSERT_OFFSET(DynArray<void*>, capacity, 0x8);
RED4EXT_ASSERT_OFFSET(DynArray<void*>, size, 0xC);

} // namespace red

template <typename T>
using DynArray [[deprecated("Use red::DynArray")]] = red::DynArray<T>;

} // namespace RED4ext
28 changes: 28 additions & 0 deletions include/RED4ext/ERTTIType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <cstdint>

namespace RED4ext {

enum class ERTTIType : uint8_t
{
Name = 0,
Fundamental = 1,
Class = 2,
Array = 3,
Simple = 4,
Enum = 5,
StaticArray = 6,
NativeArray = 7,
Pointer = 8,
Handle = 9,
WeakHandle = 10,
ResourceReference = 11,
ResourceAsyncReference = 12,
BitField = 13,
LegacySingleChannelCurve = 14,
ScriptReference = 15,
FixedArray = 16
};

}
Loading
Loading