Output: Fix access modifiers on properties, add to getters and setters
This commit is contained in:
@@ -5,8 +5,11 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Il2CppInspector.Reflection;
|
using Il2CppInspector.Reflection;
|
||||||
|
using MethodInfo = Il2CppInspector.Reflection.MethodInfo;
|
||||||
|
using TypeInfo = Il2CppInspector.Reflection.TypeInfo;
|
||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
@@ -205,10 +208,16 @@ namespace Il2CppInspector
|
|||||||
// Attributes
|
// Attributes
|
||||||
writer.Write(prop.CustomAttributes.ToString(prefix + "\t"));
|
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($"{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; " : "")
|
writer.Write((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)
|
||||||
+ (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + "set; " : "") + "}");
|
+ (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))
|
if ((prop.CanRead && prop.GetMethod.VirtualAddress != 0) || (prop.CanWrite && prop.SetMethod.VirtualAddress != 0))
|
||||||
writer.Write(" // ");
|
writer.Write(" // ");
|
||||||
writer.Write((prop.CanRead && prop.GetMethod.VirtualAddress != 0 ? prop.GetMethod.VirtualAddress.ToAddressString() + " " : "")
|
writer.Write((prop.CanRead && prop.GetMethod.VirtualAddress != 0 ? prop.GetMethod.VirtualAddress.ToAddressString() + " " : "")
|
||||||
|
|||||||
@@ -115,6 +115,18 @@ namespace Il2CppInspector.Reflection
|
|||||||
DeclaredParameters.Add(new ParameterInfo(pkg, p, this));
|
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() {
|
public string GetModifierString() {
|
||||||
// Interface methods and properties have no visible modifiers (they are always declared 'public abstract')
|
// Interface methods and properties have no visible modifiers (they are always declared 'public abstract')
|
||||||
if (DeclaringType.IsInterface)
|
if (DeclaringType.IsInterface)
|
||||||
@@ -122,18 +134,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
StringBuilder modifiers = new StringBuilder();
|
StringBuilder modifiers = new StringBuilder();
|
||||||
|
|
||||||
if (IsPrivate)
|
modifiers.Append(GetAccessModifierString());
|
||||||
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 ");
|
|
||||||
|
|
||||||
if (IsAbstract)
|
if (IsAbstract)
|
||||||
modifiers.Append("abstract ");
|
modifiers.Append("abstract ");
|
||||||
|
|||||||
Reference in New Issue
Block a user