Implement and output method modifiers correctly
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Il2CppInspector.Reflection;
|
||||
|
||||
namespace Il2CppInspector
|
||||
@@ -22,7 +23,7 @@ namespace Il2CppInspector
|
||||
}
|
||||
|
||||
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)
|
||||
writer.Write("[Serializable]\n");
|
||||
@@ -76,10 +77,27 @@ namespace Il2CppInspector
|
||||
writer.Write("private ");
|
||||
if (method.IsPublic)
|
||||
writer.Write("public ");
|
||||
if (method.IsVirtual)
|
||||
writer.Write("virtual ");
|
||||
if (method.IsFamily)
|
||||
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)
|
||||
writer.Write("static ");
|
||||
if ((method.Attributes & MethodAttributes.PinvokeImpl) != 0)
|
||||
writer.Write("extern ");
|
||||
|
||||
writer.Write($"{method.ReturnType.CSharpName} {method.Name}(");
|
||||
|
||||
|
||||
@@ -23,17 +23,18 @@ namespace Il2CppInspector.Reflection
|
||||
public List<ParameterInfo> DeclaredParameters { get; } = new List<ParameterInfo>();
|
||||
|
||||
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 IsFamily => throw new NotImplementedException();
|
||||
public bool IsFamilyAndAssembly => throw new NotImplementedException();
|
||||
public bool IsFamilyOrAssembly => throw new NotImplementedException();
|
||||
public bool IsFinal => throw new NotImplementedException();
|
||||
public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
|
||||
public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
|
||||
public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
|
||||
public bool IsFinal => (Attributes & MethodAttributes.Final) == MethodAttributes.Final;
|
||||
public bool IsGenericMethod => throw new NotImplementedException();
|
||||
public bool IsGenericMethodDefinition => throw new NotImplementedException();
|
||||
public bool IsHideBySig => throw new NotImplementedException();
|
||||
public bool IsPrivate => (Attributes & MethodAttributes.Private) == MethodAttributes.Private;
|
||||
public bool IsPublic => (Attributes & MethodAttributes.Public) == MethodAttributes.Public;
|
||||
public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) == MethodAttributes.HideBySig;
|
||||
public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
|
||||
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 IsVirtual => (Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual;
|
||||
|
||||
|
||||
@@ -43,10 +43,32 @@ namespace Il2CppInspector.Reflection
|
||||
Attributes |= MethodAttributes.Private;
|
||||
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_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)
|
||||
Attributes |= MethodAttributes.Virtual;
|
||||
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_ABSTRACT) != 0)
|
||||
Attributes |= MethodAttributes.Abstract;
|
||||
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_STATIC) != 0)
|
||||
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
|
||||
returnType = pkg.TypeUsages[Definition.returnType];
|
||||
|
||||
Reference in New Issue
Block a user