Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ public static void PopulateCustomAttributes(AssemblyAnalysisContext asmContext)
CopyCustomAttributes(field, field.GetExtraData<FieldDefinition>("AsmResolverField")!.CustomAttributes);

foreach (var property in type.Properties)
CopyCustomAttributes(property, property.GetExtraData<PropertyDefinition>("AsmResolverProperty")!.CustomAttributes);
{
// Property may have been skipped in CopyPropertiesInType (e.g. badly stripped metadata can lead to
// properties with no accessors). Skip custom attribute copy too.
Comment thread
Dredsen marked this conversation as resolved.
Outdated
var propertyDef = property.GetExtraData<PropertyDefinition>("AsmResolverProperty");
if (propertyDef == null) continue;
CopyCustomAttributes(property, propertyDef.CustomAttributes);
}

foreach (var eventDefinition in type.Events)
CopyCustomAttributes(eventDefinition, eventDefinition.GetExtraData<EventDefinition>("AsmResolverEvent")!.CustomAttributes);
Expand Down Expand Up @@ -443,6 +449,10 @@ private static void CopyPropertiesInType(ReferenceImporter importer, TypeAnalysi
{
foreach (var propertyCtx in typeContext.Properties)
{
// Skip bad properties with neither getter nor setter — their type can't be resolved.
Comment thread
Dredsen marked this conversation as resolved.
Outdated
if (propertyCtx.Getter == null && propertyCtx.Setter == null)
continue;

var propertyTypeSig = propertyCtx.ToTypeSignature(importer.TargetModule);
var propertySignature = propertyCtx.IsStatic
? PropertySignature.CreateStatic(propertyTypeSig)
Expand Down
24 changes: 21 additions & 3 deletions LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,29 @@ public Il2CppTypeDefinition? DeclaringType

public Il2CppMethodDefinition? Setter => LibCpp2IlMain.TheMetadata == null || set.IsNull || DeclaringType == null ? null : LibCpp2IlMain.TheMetadata.GetMethodDefinitionFromIndex(DeclaringType.FirstMethodIdx + set);

public Il2CppTypeReflectionData? PropertyType => LibCpp2IlMain.TheMetadata == null ? null : Getter == null ? Setter!.Parameters![0].Type : Getter!.ReturnType;
public Il2CppTypeReflectionData? PropertyType
{
get
{
if (LibCpp2IlMain.TheMetadata == null) return null;
if (Getter != null) return Getter.ReturnType;
if (Setter != null && Setter.Parameters is { Length: > 0 }) return Setter.Parameters[0].Type;
Comment thread
Dredsen marked this conversation as resolved.
Outdated
return null;
}
}

public Il2CppType? RawPropertyType => LibCpp2IlMain.TheMetadata == null ? null : Getter == null ? Setter!.Parameters![0].RawType : Getter!.RawReturnType;
public Il2CppType? RawPropertyType
{
get
{
if (LibCpp2IlMain.TheMetadata == null) return null;
if (Getter != null) return Getter.RawReturnType;
if (Setter != null && Setter.Parameters is { Length: > 0 }) return Setter.Parameters[0].RawType;
Comment thread
Dredsen marked this conversation as resolved.
Outdated
return null;
}
}

public bool IsStatic => Getter == null ? Setter!.IsStatic : Getter!.IsStatic;
public bool IsStatic => Getter?.IsStatic ?? Setter?.IsStatic ?? false;
public uint Token => token;

public override void Read(ClassReadingBinaryReader reader)
Expand Down