smaller tweaks, hack around loops in cpp type layouting

This commit is contained in:
LukeFZ
2025-02-08 17:40:15 +01:00
parent e6bd289aa4
commit ffb1996252
6 changed files with 71 additions and 23 deletions

View File

@@ -228,6 +228,14 @@ namespace Il2CppInspector.Cpp
ns.ReserveName("_");
fieldType = types.Struct(name + "__Fields");
var baseFieldType = types[TypeNamer.GetName(ti.BaseType) + "__Fields"];
if (baseFieldType == null)
{
// if we end up here, there is a loop in the type generation.
// this is not currently supported, so we throw an exception.
throw new InvalidOperationException($"Failed to generate type for {ti}");
}
fieldType.AddField("_", baseFieldType);
GenerateFieldList(fieldType, ns, ti);
}
@@ -437,16 +445,30 @@ namespace Il2CppInspector.Cpp
/// <returns>A string containing C type declarations</returns>
public List<(TypeInfo ilType, CppComplexType valueType, CppComplexType referenceType, CppComplexType fieldsType,
CppComplexType vtableType, CppComplexType staticsType)> GenerateRemainingTypeDeclarations() {
var decl = GenerateVisitedFieldStructs().Select(s =>
(s.ilType, s.valueType, s.referenceType, s.fieldsType, (CppComplexType) null, (CppComplexType) null)).ToList();
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));
foreach (var ti in TodoTypeStructs)
{
var (cls, statics, vtable) = GenerateTypeStruct(ti);
decl.Add((ti, null, cls, null, vtable, statics));
}
return decl;
}
catch (Exception)
{
return null;
}
finally
{
TodoTypeStructs.Clear();
TodoFieldStructs.Clear();
}
TodoTypeStructs.Clear();
return decl;
}
#endregion