diff --git a/Il2CppDumper/Il2CppCSharpDumper.cs b/Il2CppDumper/Il2CppCSharpDumper.cs index fd47179..f3c68e0 100644 --- a/Il2CppDumper/Il2CppCSharpDumper.cs +++ b/Il2CppDumper/Il2CppCSharpDumper.cs @@ -5,8 +5,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using Il2CppInspector.Reflection; +using MethodInfo = Il2CppInspector.Reflection.MethodInfo; +using TypeInfo = Il2CppInspector.Reflection.TypeInfo; namespace Il2CppInspector { @@ -205,10 +208,16 @@ namespace Il2CppInspector // Attributes writer.Write(prop.CustomAttributes.ToString(prefix + "\t")); - string modifiers = prop.GetMethod?.GetModifierString() ?? prop.SetMethod.GetModifierString(); + // The access mask enum values go from 1 (private) to 6 (public) in order from most to least restrictive + 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} {{ "); - writer.Write((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + "get; " : "") - + (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + "set; " : "") + "}"); + 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) + + (setAccess < getAccess? prop.SetMethod.GetAccessModifierString() : "") + "set; " : "") + "}"); if ((prop.CanRead && prop.GetMethod.VirtualAddress != 0) || (prop.CanWrite && prop.SetMethod.VirtualAddress != 0)) writer.Write(" // "); writer.Write((prop.CanRead && prop.GetMethod.VirtualAddress != 0 ? prop.GetMethod.VirtualAddress.ToAddressString() + " " : "") diff --git a/Il2CppInspector/Reflection/MethodBase.cs b/Il2CppInspector/Reflection/MethodBase.cs index 7f75321..34a4216 100644 --- a/Il2CppInspector/Reflection/MethodBase.cs +++ b/Il2CppInspector/Reflection/MethodBase.cs @@ -115,6 +115,18 @@ namespace Il2CppInspector.Reflection DeclaredParameters.Add(new ParameterInfo(pkg, p, this)); } + public string GetAccessModifierString() { + return this switch { + { IsPrivate: true } => "private ", + { IsPublic: true } => "public ", + { IsFamily: true } => "protected ", + { IsAssembly: true } => "internal ", + { IsFamilyOrAssembly: true } => "protected internal ", + { IsFamilyAndAssembly: true } => "private protected ", + _ => "" + }; + } + public string GetModifierString() { // Interface methods and properties have no visible modifiers (they are always declared 'public abstract') if (DeclaringType.IsInterface) @@ -122,18 +134,7 @@ namespace Il2CppInspector.Reflection StringBuilder modifiers = new StringBuilder(); - if (IsPrivate) - modifiers.Append("private "); - if (IsPublic) - modifiers.Append("public "); - if (IsFamily) - modifiers.Append("protected "); - if (IsAssembly) - modifiers.Append("internal "); - if (IsFamilyOrAssembly) - modifiers.Append("protected internal "); - if (IsFamilyAndAssembly) - modifiers.Append("private protected "); + modifiers.Append(GetAccessModifierString()); if (IsAbstract) modifiers.Append("abstract ");