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
This commit is contained in:
LukeFZ
2025-12-30 15:11:55 +01:00
parent 4b5a860381
commit 14821d023c
2 changed files with 19 additions and 1 deletions

View File

@@ -497,6 +497,7 @@ namespace Il2CppInspector.Cpp
// Allow auto-generation of forward declarations
// This will break type generation unless the ultimate wanted type is a pointer
// Note this can still be the case with indirectionCount == 0 if .AsPointer() is called afterwards
if (!Types.ContainsKey(baseName))
Struct(baseName);

View File

@@ -82,7 +82,24 @@ public class CppTypeDependencyGraph
// finally, process all instance fields.
// the reference type depends on the type of the field
foreach (var field in typeInfo.DeclaredFields.Where(f => f.IsInstanceField))
AddReference(typeNode, GetNode(field.FieldType), field.FieldType.IsPassedByReference);
{
// if the field type is a pointer and the element type an enum, we have to add a reference to the enum.
// this is a workaround for type emitting only being able to generate forward definitions for *struct* types, and not enum types
if (field.FieldType.IsPointer)
{
// support multiple pointer levels
var type = field.FieldType;
while (type.IsPointer)
type = type.ElementType;
if (type.IsEnum)
AddReference(typeNode, GetNode(type), false);
}
else
{
AddReference(typeNode, GetNode(field.FieldType), field.FieldType.IsPassedByReference);
}
}
}
public List<TypeInfo> DeriveDependencyOrderedTypes(TypeInfo typeInfo)