This commit is contained in:
LukeFZ
2026-01-07 20:39:24 +01:00
3 changed files with 31 additions and 21 deletions

View File

@@ -435,30 +435,22 @@ public class CppDeclarationGenerator
/// <returns>A string containing C type declarations</returns>
public List<(TypeInfo ilType, CppComplexType valueType, CppComplexType referenceType, CppComplexType fieldsType,
CppComplexType vtableType, CppComplexType staticsType)> GenerateRemainingTypeDeclarations() {
try
{
var decl = GenerateVisitedFieldStructs().Select(s =>
(s.ilType, s.valueType, s.referenceType, s.fieldsType, (CppComplexType)null,
(CppComplexType)null))
.ToList();
foreach (var ti in _todoTypeStructs)
{
var (cls, statics, vtable) = GenerateTypeStruct(ti);
decl.Add((ti, null, cls, null, vtable, statics));
}
var decl = GenerateVisitedFieldStructs().Select(s =>
(s.ilType, s.valueType, s.referenceType, s.fieldsType, (CppComplexType)null,
(CppComplexType)null))
.ToList();
return decl;
}
catch (Exception)
foreach (var ti in _todoTypeStructs)
{
return null;
}
finally
{
_todoTypeStructs.Clear();
_todoFieldStructs.Clear();
var (cls, statics, vtable) = GenerateTypeStruct(ti);
decl.Add((ti, null, cls, null, vtable, statics));
}
_todoTypeStructs.Clear();
_todoFieldStructs.Clear();
return decl;
}
public List<CppType> GenerateRequiredForwardDefinitions()

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)