Skip to content

Commit 14821d0

Browse files
committed
add implicit reference to enum class if a struct has a enum pointer as an instance field
this is only needed due to the forward definition code only being capable of generating struct types. closes #38
1 parent 4b5a860 commit 14821d0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Il2CppInspector.Common/Cpp/CppTypeCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ public CppType GetType(string typeName, bool returnUnaliased = false) {
497497
// Allow auto-generation of forward declarations
498498
// This will break type generation unless the ultimate wanted type is a pointer
499499
// Note this can still be the case with indirectionCount == 0 if .AsPointer() is called afterwards
500+
500501
if (!Types.ContainsKey(baseName))
501502
Struct(baseName);
502503

Il2CppInspector.Common/Cpp/CppTypeDependencyGraph.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,24 @@ private void CollectReferences(CppTypeNode typeNode)
8282
// finally, process all instance fields.
8383
// the reference type depends on the type of the field
8484
foreach (var field in typeInfo.DeclaredFields.Where(f => f.IsInstanceField))
85-
AddReference(typeNode, GetNode(field.FieldType), field.FieldType.IsPassedByReference);
85+
{
86+
// if the field type is a pointer and the element type an enum, we have to add a reference to the enum.
87+
// this is a workaround for type emitting only being able to generate forward definitions for *struct* types, and not enum types
88+
if (field.FieldType.IsPointer)
89+
{
90+
// support multiple pointer levels
91+
var type = field.FieldType;
92+
while (type.IsPointer)
93+
type = type.ElementType;
94+
95+
if (type.IsEnum)
96+
AddReference(typeNode, GetNode(type), false);
97+
}
98+
else
99+
{
100+
AddReference(typeNode, GetNode(field.FieldType), field.FieldType.IsPassedByReference);
101+
}
102+
}
86103
}
87104

88105
public List<TypeInfo> DeriveDependencyOrderedTypes(TypeInfo typeInfo)

0 commit comments

Comments
 (0)