Initial implementation and output of properties
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Il2CppInspector.Reflection
|
||||
{
|
||||
@@ -41,5 +42,37 @@ namespace Il2CppInspector.Reflection
|
||||
// TODO: GetMethodBody()
|
||||
|
||||
protected MethodBase(TypeInfo declaringType) : base(declaringType) { }
|
||||
|
||||
public string GetModifierString() {
|
||||
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("[family and assembly] ");
|
||||
|
||||
if (IsAbstract)
|
||||
modifiers.Append("abstract ");
|
||||
// Methods that implement interfaces are IsVirtual && IsFinal with MethodAttributes.NewSlot (don't show 'virtual sealed' for these)
|
||||
if (IsFinal && (Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot)
|
||||
modifiers.Append("sealed override ");
|
||||
// All abstract, override and sealed methods are also virtual by nature
|
||||
if (IsVirtual && !IsAbstract && !IsFinal)
|
||||
modifiers.Append((Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot ? "virtual " : "override ");
|
||||
if (IsStatic)
|
||||
modifiers.Append("static ");
|
||||
if ((Attributes & MethodAttributes.PinvokeImpl) != 0)
|
||||
modifiers.Append("extern ");
|
||||
|
||||
return modifiers.ToString().Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Il2CppInspector/Reflection/PropertyInfo.cs
Normal file
40
Il2CppInspector/Reflection/PropertyInfo.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||
|
||||
All rights reserved.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace Il2CppInspector.Reflection {
|
||||
public class PropertyInfo : MemberInfo
|
||||
{
|
||||
public bool CanRead => GetMethod != null;
|
||||
public bool CanWrite => SetMethod != null;
|
||||
|
||||
// TODO: CustomAttributes
|
||||
|
||||
public MethodInfo GetMethod { get; }
|
||||
public MethodInfo SetMethod { get; }
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[0].ParameterType;
|
||||
|
||||
public override MemberTypes MemberType => MemberTypes.Property;
|
||||
|
||||
public PropertyInfo(Il2CppInspector pkg, int propIndex, TypeInfo declaringType) :
|
||||
base(declaringType) {
|
||||
var prop = pkg.Metadata.Properties[propIndex];
|
||||
|
||||
Name = pkg.Strings[prop.nameIndex];
|
||||
|
||||
// NOTE: This relies on methods being added to TypeInfo.DeclaredMethods in the same order they are defined in the Il2Cpp metadata
|
||||
// prop.get and prop.set are method indices from the first method of the declaring type
|
||||
if (prop.get >= 0)
|
||||
GetMethod = declaringType.DeclaredMethods[prop.get];
|
||||
if (prop.set >= 0)
|
||||
SetMethod = declaringType.DeclaredMethods[prop.set];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,6 @@ namespace Il2CppInspector.Reflection
|
||||
base(declaringType) { }
|
||||
}
|
||||
|
||||
public class PropertyInfo : MemberInfo
|
||||
{
|
||||
// TODO
|
||||
public override MemberTypes MemberType => MemberTypes.Property | MemberTypes.Method;
|
||||
public PropertyInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) :
|
||||
base(declaringType) { }
|
||||
}
|
||||
|
||||
public class CustomAttributeData
|
||||
{
|
||||
// TODO
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Il2CppInspector.Reflection {
|
||||
public List<MemberInfo> DeclaredMembers => throw new NotImplementedException();
|
||||
public List<MethodInfo> DeclaredMethods { get; } = new List<MethodInfo>();
|
||||
public List<TypeInfo> DeclaredNestedTypes => throw new NotImplementedException();
|
||||
public List<PropertyInfo> DeclaredProperties => throw new NotImplementedException();
|
||||
public List<PropertyInfo> DeclaredProperties { get; } = new List<PropertyInfo>();
|
||||
|
||||
// Method that the type is declared in if this is a type parameter of a generic method
|
||||
public MethodBase DeclaringMethod => throw new NotImplementedException();
|
||||
@@ -180,6 +180,10 @@ namespace Il2CppInspector.Reflection {
|
||||
for (var m = Definition.methodStart; m < Definition.methodStart + Definition.method_count; m++)
|
||||
DeclaredMethods.Add(new MethodInfo(pkg, m, this));
|
||||
|
||||
// Add all properties
|
||||
for (var p = Definition.propertyStart; p < Definition.propertyStart + Definition.property_count; p++)
|
||||
DeclaredProperties.Add(new PropertyInfo(pkg, p, this));
|
||||
|
||||
MemberType = MemberTypes.TypeInfo;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user