Implement and output method modifiers correctly

This commit is contained in:
Katy Coe
2017-11-10 02:40:03 +01:00
parent f319ccb6b7
commit add2c54645
3 changed files with 52 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Il2CppInspector.Reflection; using Il2CppInspector.Reflection;
namespace Il2CppInspector namespace Il2CppInspector
@@ -22,7 +23,7 @@ namespace Il2CppInspector
} }
foreach (var type in model.Assemblies.SelectMany(x => x.DefinedTypes)) { foreach (var type in model.Assemblies.SelectMany(x => x.DefinedTypes)) {
writer.Write($"// Namespace: {type.Namespace}\n"); writer.Write($"\n// Namespace: {type.Namespace}\n");
if (type.IsSerializable) if (type.IsSerializable)
writer.Write("[Serializable]\n"); writer.Write("[Serializable]\n");
@@ -76,10 +77,27 @@ namespace Il2CppInspector
writer.Write("private "); writer.Write("private ");
if (method.IsPublic) if (method.IsPublic)
writer.Write("public "); writer.Write("public ");
if (method.IsVirtual) if (method.IsFamily)
writer.Write("virtual "); writer.Write("protected ");
if (method.IsAssembly)
writer.Write("internal ");
if (method.IsFamilyOrAssembly)
writer.Write("protected internal ");
if (method.IsFamilyAndAssembly)
writer.Write("[family and assembly] ");
if (method.IsAbstract)
writer.Write("abstract ");
// Methods that implement interfaces are IsVirtual && IsFinal with MethodAttributes.NewSlot (don't show 'virtual sealed' for these)
if (method.IsFinal && (method.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot)
writer.Write("sealed override ");
// All abstract, override and sealed methods are also virtual by nature
if (method.IsVirtual && !method.IsAbstract && !method.IsFinal)
writer.Write((method.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot? "virtual " : "override ");
if (method.IsStatic) if (method.IsStatic)
writer.Write("static "); writer.Write("static ");
if ((method.Attributes & MethodAttributes.PinvokeImpl) != 0)
writer.Write("extern ");
writer.Write($"{method.ReturnType.CSharpName} {method.Name}("); writer.Write($"{method.ReturnType.CSharpName} {method.Name}(");

View File

@@ -23,17 +23,18 @@ namespace Il2CppInspector.Reflection
public List<ParameterInfo> DeclaredParameters { get; } = new List<ParameterInfo>(); public List<ParameterInfo> DeclaredParameters { get; } = new List<ParameterInfo>();
public bool IsAbstract => (Attributes & MethodAttributes.Abstract) == MethodAttributes.Abstract; public bool IsAbstract => (Attributes & MethodAttributes.Abstract) == MethodAttributes.Abstract;
public bool IsAssembly => throw new NotImplementedException(); public bool IsAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
public bool IsConstructor => throw new NotImplementedException(); public bool IsConstructor => throw new NotImplementedException();
public bool IsFamily => throw new NotImplementedException(); public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
public bool IsFamilyAndAssembly => throw new NotImplementedException(); public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
public bool IsFamilyOrAssembly => throw new NotImplementedException(); public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
public bool IsFinal => throw new NotImplementedException(); public bool IsFinal => (Attributes & MethodAttributes.Final) == MethodAttributes.Final;
public bool IsGenericMethod => throw new NotImplementedException(); public bool IsGenericMethod => throw new NotImplementedException();
public bool IsGenericMethodDefinition => throw new NotImplementedException(); public bool IsGenericMethodDefinition => throw new NotImplementedException();
public bool IsHideBySig => throw new NotImplementedException(); public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) == MethodAttributes.HideBySig;
public bool IsPrivate => (Attributes & MethodAttributes.Private) == MethodAttributes.Private; public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
public bool IsPublic => (Attributes & MethodAttributes.Public) == MethodAttributes.Public; public bool IsPublic => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
public bool IsSpecialName => (Attributes & MethodAttributes.SpecialName) == MethodAttributes.SpecialName;
public bool IsStatic => (Attributes & MethodAttributes.Static) == MethodAttributes.Static; public bool IsStatic => (Attributes & MethodAttributes.Static) == MethodAttributes.Static;
public bool IsVirtual => (Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual; public bool IsVirtual => (Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual;

View File

@@ -43,10 +43,32 @@ namespace Il2CppInspector.Reflection
Attributes |= MethodAttributes.Private; Attributes |= MethodAttributes.Private;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PUBLIC) if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PUBLIC)
Attributes |= MethodAttributes.Public; Attributes |= MethodAttributes.Public;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_FAM_AND_ASSEM)
Attributes |= MethodAttributes.FamANDAssem;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_ASSEM)
Attributes |= MethodAttributes.Assembly;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_FAMILY)
Attributes |= MethodAttributes.Family;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_FAM_OR_ASSEM)
Attributes |= MethodAttributes.FamORAssem;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_VIRTUAL) != 0) if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_VIRTUAL) != 0)
Attributes |= MethodAttributes.Virtual; Attributes |= MethodAttributes.Virtual;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_ABSTRACT) != 0)
Attributes |= MethodAttributes.Abstract;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_STATIC) != 0) if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_STATIC) != 0)
Attributes |= MethodAttributes.Static; Attributes |= MethodAttributes.Static;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_FINAL) != 0)
Attributes |= MethodAttributes.Final;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_HIDE_BY_SIG) != 0)
Attributes |= MethodAttributes.HideBySig;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_VTABLE_LAYOUT_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_NEW_SLOT)
Attributes |= MethodAttributes.NewSlot;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_PINVOKE_IMPL) != 0)
Attributes |= MethodAttributes.PinvokeImpl;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_SPECIAL_NAME) != 0)
Attributes |= MethodAttributes.SpecialName;
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_UNMANAGED_EXPORT) != 0)
Attributes |= MethodAttributes.UnmanagedExport;
// Add return parameter // Add return parameter
returnType = pkg.TypeUsages[Definition.returnType]; returnType = pkg.TypeUsages[Definition.returnType];