Skip to content

Commit d314004

Browse files
committed
2 parents 776c507 + 14821d0 commit d314004

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

Il2CppInspector.Common/Cpp/CppDeclarationGenerator.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -435,30 +435,22 @@ should display the correct method name (with a computed
435435
/// <returns>A string containing C type declarations</returns>
436436
public List<(TypeInfo ilType, CppComplexType valueType, CppComplexType referenceType, CppComplexType fieldsType,
437437
CppComplexType vtableType, CppComplexType staticsType)> GenerateRemainingTypeDeclarations() {
438-
try
439-
{
440-
var decl = GenerateVisitedFieldStructs().Select(s =>
441-
(s.ilType, s.valueType, s.referenceType, s.fieldsType, (CppComplexType)null,
442-
(CppComplexType)null))
443-
.ToList();
444438

445-
foreach (var ti in _todoTypeStructs)
446-
{
447-
var (cls, statics, vtable) = GenerateTypeStruct(ti);
448-
decl.Add((ti, null, cls, null, vtable, statics));
449-
}
439+
var decl = GenerateVisitedFieldStructs().Select(s =>
440+
(s.ilType, s.valueType, s.referenceType, s.fieldsType, (CppComplexType)null,
441+
(CppComplexType)null))
442+
.ToList();
450443

451-
return decl;
452-
}
453-
catch (Exception)
454-
{
455-
return null;
456-
}
457-
finally
444+
foreach (var ti in _todoTypeStructs)
458445
{
459-
_todoTypeStructs.Clear();
460-
_todoFieldStructs.Clear();
446+
var (cls, statics, vtable) = GenerateTypeStruct(ti);
447+
decl.Add((ti, null, cls, null, vtable, statics));
461448
}
449+
450+
_todoTypeStructs.Clear();
451+
_todoFieldStructs.Clear();
452+
453+
return decl;
462454
}
463455

464456
public List<CppType> GenerateRequiredForwardDefinitions()

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)