From 7f683fc629e92979b79dc8e398d7121e16b0d1b2 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 9 Nov 2019 23:46:07 +0100 Subject: [PATCH] Output: Handle indexers correctly --- Il2CppDumper/Il2CppCSharpDumper.cs | 12 ++++++++++-- Il2CppInspector/Reflection/PropertyInfo.cs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Il2CppDumper/Il2CppCSharpDumper.cs b/Il2CppDumper/Il2CppCSharpDumper.cs index ac9ec04..019d6e8 100644 --- a/Il2CppDumper/Il2CppCSharpDumper.cs +++ b/Il2CppDumper/Il2CppCSharpDumper.cs @@ -212,8 +212,16 @@ namespace Il2CppInspector var getAccess = (prop.GetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask; var setAccess = (prop.SetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask; - string modifiers = getAccess > setAccess? prop.GetMethod.GetModifierString() : prop.SetMethod.GetModifierString(); - writer.Write($"{prefix}\t{modifiers}{prop.PropertyType.CSharpName} {prop.Name} {{ "); + var primary = getAccess >= setAccess ? prop.GetMethod : prop.SetMethod; + writer.Write($"{prefix}\t{primary.GetModifierString()}{prop.PropertyType.CSharpName} "); + + // Non-indexer + if ((!prop.CanRead || !prop.GetMethod.DeclaredParameters.Any()) && (!prop.CanWrite || prop.SetMethod.DeclaredParameters.Count == 1)) + writer.Write($"{prop.Name} {{ "); + // Indexer + else + writer.Write("this[" + string.Join(", ", primary.DeclaredParameters.SkipLast(getAccess > setAccess? 0 : 1).Select(p => p.GetParameterString())) + "] { "); + writer.Write((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + (getAccess < setAccess? prop.GetMethod.GetAccessModifierString() : "") + "get; " : "") + (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) diff --git a/Il2CppInspector/Reflection/PropertyInfo.cs b/Il2CppInspector/Reflection/PropertyInfo.cs index ffdb346..70c440c 100644 --- a/Il2CppInspector/Reflection/PropertyInfo.cs +++ b/Il2CppInspector/Reflection/PropertyInfo.cs @@ -26,7 +26,7 @@ namespace Il2CppInspector.Reflection { public override string Name { get; protected set; } - public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[0].ParameterType; + public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[^1].ParameterType; public override MemberTypes MemberType => MemberTypes.Property;