Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
18 changes: 9 additions & 9 deletions include/RED4ext/Dump/Reflection-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
// First pass gather all properties and descriptors
rttiSystem->types.for_each(
[&descriptorMap, GetPrefix, &prefixHierarchy, aPropertyHolders](RED4ext::CName aName,
RED4ext::CBaseRTTIType*& aType)
RED4ext::rtti::IType*& aType)
{
if (aType->GetType() == RED4ext::ERTTIType::Class)
{
Expand Down Expand Up @@ -196,7 +196,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
}

auto GetGeneratedPath = [aExtendedPath, redEvent, scriptable, serializable, GetPrefix,
&prefixHierarchy](const RED4ext::CBaseRTTIType* aType) -> std::string
&prefixHierarchy](const RED4ext::rtti::IType* aType) -> std::string
{
auto name = aType->GetName();

Expand Down Expand Up @@ -250,7 +250,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
return "Scripting/Natives/Generated/" + pathPrefix;
};

auto GetOverridePath = [&aIncludePath](const RED4ext::CBaseRTTIType* aType) -> std::string
auto GetOverridePath = [&aIncludePath](const RED4ext::rtti::IType* aType) -> std::string
{
std::string name = aType->GetName().ToString();
std::string path = "Scripting/Natives/" + name + ".hpp";
Expand All @@ -264,7 +264,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
};

// Remove the prefix from the class
auto SanitizeType = [GetPrefix](const RED4ext::CBaseRTTIType* aType) -> std::string
auto SanitizeType = [GetPrefix](const RED4ext::rtti::IType* aType) -> std::string
{
auto name = aType->GetName();
std::string fullName = name.ToString();
Expand All @@ -291,7 +291,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
};

// Combine the namespace and sanitized name
auto QualifiedType = [GetNamespace, GetPrefix](const RED4ext::CBaseRTTIType* aType) -> std::string
auto QualifiedType = [GetNamespace, GetPrefix](const RED4ext::rtti::IType* aType) -> std::string
{
auto name = aType->GetName();

Expand All @@ -303,7 +303,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
return ns.empty() ? stripped : ns + "::" + stripped;
};

auto IsHandleCompatible = [serializable](const RED4ext::CBaseRTTIType* aType) -> bool
auto IsHandleCompatible = [serializable](const RED4ext::rtti::IType* aType) -> bool
{
if (aType->GetType() == RED4ext::ERTTIType::Class)
{
Expand Down Expand Up @@ -383,7 +383,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a

rttiSystem->types.for_each(
[&aOutPath, SanitizeType, &QualifiedType, GetGeneratedPath, nameSanitizer](RED4ext::CName aName,
RED4ext::CBaseRTTIType*& aType)
RED4ext::rtti::IType*& aType)
{
RED4EXT_UNUSED_PARAMETER(aName);

Expand Down Expand Up @@ -415,7 +415,7 @@ RED4EXT_INLINE void Dump(std::filesystem::path aOutPath, std::filesystem::path a
EmitBulkGenerated(aOutPath, includeCollector);
}

RED4EXT_INLINE void ClassDependencyBuilder::Accumulate(const RED4ext::CBaseRTTIType* aType)
RED4EXT_INLINE void ClassDependencyBuilder::Accumulate(const RED4ext::rtti::IType* aType)
{
switch (aType->GetType())
{
Expand Down Expand Up @@ -883,7 +883,7 @@ RED4EXT_INLINE void ClassDependencyBuilder::ToFileDescriptor(ClassFileDescriptor
}
}

RED4EXT_INLINE std::string TypeToString(const RED4ext::CBaseRTTIType* aType, NameTransformer aNameTransformer,
RED4EXT_INLINE std::string TypeToString(const RED4ext::rtti::IType* aType, NameTransformer aNameTransformer,
bool aVerbose)
{
// Handle some simple type conversions and fundamentals
Expand Down
21 changes: 12 additions & 9 deletions include/RED4ext/Dump/Reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

namespace RED4ext
{
namespace rtti
{
struct IType;
}
struct CClass;
struct CBaseRTTIType;
struct CProperty;
struct CEnum;
struct CBitfield;
Expand All @@ -21,10 +24,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 @@ -103,20 +106,20 @@ struct BitfieldFileDescriptor
struct ClassDependencyBuilder
{
const RED4ext::CClass* pType;
std::unordered_set<const RED4ext::CBaseRTTIType*> mDirect;
std::unordered_set<const RED4ext::CBaseRTTIType*> mIndirect;
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
47 changes: 25 additions & 22 deletions include/RED4ext/GameEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

namespace RED4ext
{
struct CBaseRTTIType;
namespace rtti
{
struct IType;
}
struct IScriptable;
struct CGameOptions;

Expand All @@ -31,25 +34,25 @@ enum class EEngineState : int32_t

struct GameInstance
{
virtual ~GameInstance() = 0; // 00
virtual IScriptable* GetSystem(const CBaseRTTIType* aType) = 0; // 08
virtual void Unk_10() = 0; // 10
virtual void Unk_18() = 0; // 18
virtual void Unk_20() = 0; // 20
virtual void Unk_28() = 0; // 28
virtual void Unk_30() = 0; // 30
virtual void Unk_38() = 0; // 38
virtual void Unk_40() = 0; // 40
virtual void Unk_48() = 0; // 48
virtual void Unk_50() = 0; // 50
virtual void Unk_58() = 0; // 58
virtual void Unk_60() = 0; // 60
virtual void Unk_68() = 0; // 68

HashMap<CBaseRTTIType*, Handle<IScriptable>> systemMap; // 08 - Maps implementation type to instance
DynArray<Handle<IScriptable>> systemInstances; // 38
HashMap<CBaseRTTIType*, CBaseRTTIType*> systemImplementations; // 48 - Maps interface type to implementation type
uintptr_t unk78[(0x138 - 0x78) >> 3]; // 78
virtual ~GameInstance() = 0; // 00
virtual IScriptable* GetSystem(const rtti::IType* aType) = 0; // 08
virtual void Unk_10() = 0; // 10
virtual void Unk_18() = 0; // 18
virtual void Unk_20() = 0; // 20
virtual void Unk_28() = 0; // 28
virtual void Unk_30() = 0; // 30
virtual void Unk_38() = 0; // 38
virtual void Unk_40() = 0; // 40
virtual void Unk_48() = 0; // 48
virtual void Unk_50() = 0; // 50
virtual void Unk_58() = 0; // 58
virtual void Unk_60() = 0; // 60
virtual void Unk_68() = 0; // 68

HashMap<rtti::IType*, Handle<IScriptable>> systemMap; // 08 - Maps implementation type to instance
DynArray<Handle<IScriptable>> systemInstances; // 38
HashMap<rtti::IType*, rtti::IType*> systemImplementations; // 48 - Maps interface type to implementation type
uintptr_t unk78[(0x138 - 0x78) >> 3]; // 78
};
RED4EXT_ASSERT_SIZE(GameInstance, 0x138);

Expand Down Expand Up @@ -91,8 +94,8 @@ struct CBaseEngine
};
RED4EXT_ASSERT_SIZE(Unk110, 0x10);

virtual CBaseRTTIType* GetNativeType() = 0; // 00
virtual CBaseRTTIType* GetParentType() = 0; // 08
virtual rtti::IType* GetNativeType() = 0; // 00
virtual rtti::IType* GetParentType() = 0; // 08
virtual Memory::IAllocator* GetAllocator() = 0; // 10
virtual ~CBaseEngine() = 0; // 18
virtual void sub_18() = 0; // 20
Expand Down
18 changes: 9 additions & 9 deletions include/RED4ext/NativeTypes-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ RED4EXT_INLINE RED4ext::gamedataLocKeyWrapper::gamedataLocKeyWrapper(const char*
{
}

RED4EXT_INLINE RED4ext::Variant::Variant(const RED4ext::CBaseRTTIType* aType)
RED4EXT_INLINE RED4ext::Variant::Variant(const RED4ext::rtti::IType* aType)
: Variant()
{
if (aType)
Expand All @@ -124,7 +124,7 @@ RED4EXT_INLINE RED4ext::Variant::Variant(const RED4ext::CBaseRTTIType* aType)
}
}

RED4EXT_INLINE RED4ext::Variant::Variant(const RED4ext::CBaseRTTIType* aType, const RED4ext::ScriptInstance aData)
RED4EXT_INLINE RED4ext::Variant::Variant(const RED4ext::rtti::IType* aType, const RED4ext::ScriptInstance aData)
: Variant()
{
if (aType)
Expand Down Expand Up @@ -188,25 +188,25 @@ RED4EXT_INLINE bool RED4ext::Variant::IsInlined() const noexcept
return reinterpret_cast<uintptr_t>(type) & InlineFlag;
}

RED4EXT_INLINE RED4ext::CBaseRTTIType* RED4ext::Variant::GetType() const noexcept
RED4EXT_INLINE RED4ext::rtti::IType* RED4ext::Variant::GetType() const noexcept
{
return reinterpret_cast<RED4ext::CBaseRTTIType*>(reinterpret_cast<uintptr_t>(type) & TypeMask);
return reinterpret_cast<RED4ext::rtti::IType*>(reinterpret_cast<uintptr_t>(type) & TypeMask);
}

RED4EXT_INLINE RED4ext::ScriptInstance RED4ext::Variant::GetDataPtr() const noexcept
{
return IsInlined() ? const_cast<uint8_t*>(inlined) : instance;
}

RED4EXT_INLINE bool RED4ext::Variant::Init(const RED4ext::CBaseRTTIType* aType)
RED4EXT_INLINE bool RED4ext::Variant::Init(const RED4ext::rtti::IType* aType)
{
if (!aType)
{
Free();
return false;
}

RED4ext::CBaseRTTIType* ownType = GetType();
RED4ext::rtti::IType* ownType = GetType();
RED4ext::ScriptInstance ownData = GetDataPtr();

if (ownType)
Expand Down Expand Up @@ -241,7 +241,7 @@ RED4EXT_INLINE bool RED4ext::Variant::Init(const RED4ext::CBaseRTTIType* aType)
return true;
}

RED4EXT_INLINE bool RED4ext::Variant::Fill(const RED4ext::CBaseRTTIType* aType, const RED4ext::ScriptInstance aData)
RED4EXT_INLINE bool RED4ext::Variant::Fill(const RED4ext::rtti::IType* aType, const RED4ext::ScriptInstance aData)
{
if (!Init(aType))
return false;
Expand Down Expand Up @@ -269,7 +269,7 @@ RED4EXT_INLINE void RED4ext::Variant::Free()
if (IsEmpty())
return;

RED4ext::CBaseRTTIType* ownType = GetType();
RED4ext::rtti::IType* ownType = GetType();
RED4ext::ScriptInstance ownData = GetDataPtr();

if (ownData)
Expand All @@ -284,7 +284,7 @@ RED4EXT_INLINE void RED4ext::Variant::Free()
type = nullptr;
}

RED4EXT_INLINE bool RED4ext::Variant::CanBeInlined(const RED4ext::CBaseRTTIType* aType) noexcept
RED4EXT_INLINE bool RED4ext::Variant::CanBeInlined(const RED4ext::rtti::IType* aType) noexcept
{
return aType->GetSize() <= InlineSize && aType->GetAlignment() <= InlineAlignment;
}
Expand Down
29 changes: 16 additions & 13 deletions include/RED4ext/NativeTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

namespace RED4ext
{
struct CBaseRTTIType;
namespace rtti
{
struct IType;
}

struct CDateTime
{
Expand Down Expand Up @@ -147,8 +150,8 @@ struct Variant
static constexpr uintptr_t TypeMask = ~InlineFlag;

Variant() noexcept = default;
Variant(const CBaseRTTIType* aType);
Variant(const CBaseRTTIType* aType, const ScriptInstance aData);
Variant(const rtti::IType* aType);
Variant(const rtti::IType* aType, const ScriptInstance aData);
Variant(CName aTypeName);
Variant(CName aTypeName, const ScriptInstance aData);
Variant(const Variant& aOther);
Expand All @@ -161,17 +164,17 @@ struct Variant
bool IsEmpty() const noexcept;
bool IsInlined() const noexcept;

CBaseRTTIType* GetType() const noexcept;
rtti::IType* GetType() const noexcept;
ScriptInstance GetDataPtr() const noexcept;

bool Init(const CBaseRTTIType* aType);
bool Fill(const CBaseRTTIType* aType, const ScriptInstance aData);
bool Init(const rtti::IType* aType);
bool Fill(const rtti::IType* aType, const ScriptInstance aData);
bool Extract(ScriptInstance aBuffer);
void Free();

static bool CanBeInlined(const CBaseRTTIType* aType) noexcept;
static bool CanBeInlined(const rtti::IType* aType) noexcept;

const CBaseRTTIType* type{nullptr};
const rtti::IType* type{nullptr};
union
{
uint8_t inlined[InlineSize]{0};
Expand Down Expand Up @@ -262,7 +265,7 @@ struct CurveData

CName name; // 00
RawBuffer buffer; // 08
CBaseRTTIType* valueType; // 40
rtti::IType* valueType; // 40
curve::EInterpolationType interpolationType; // 48
curve::ESegmentsLinkType linkType; // 49
};
Expand All @@ -276,10 +279,10 @@ RED4EXT_ASSERT_OFFSET(CurveData<float>, linkType, 0x31);
template<typename T>
struct ScriptRef
{
uint8_t unk00[0x10]; // 00
CBaseRTTIType* innerType; // 10
T* ref; // 18
CName hash; // 20
uint8_t unk00[0x10]; // 00
rtti::IType* innerType; // 10
T* ref; // 18
CName hash; // 20
};
RED4EXT_ASSERT_SIZE(ScriptRef<void>, 0x28);

Expand Down
Loading