Implement ParameterInfo and return parameters
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
// TODO: Custom attribute stuff
|
// TODO: Custom attribute stuff
|
||||||
|
|
||||||
public List<ParameterInfo> DeclaredParameters => throw new NotImplementedException();
|
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 => throw new NotImplementedException();
|
||||||
@@ -38,7 +38,6 @@ namespace Il2CppInspector.Reflection
|
|||||||
public bool IsVirtual => (Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual;
|
public bool IsVirtual => (Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual;
|
||||||
|
|
||||||
// TODO: GetMethodBody()
|
// TODO: GetMethodBody()
|
||||||
// TODO: GetParameters()
|
|
||||||
|
|
||||||
protected MethodBase(TypeInfo declaringType) : base(declaringType) { }
|
protected MethodBase(TypeInfo declaringType) : base(declaringType) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Il2CppInspector.Reflection
|
namespace Il2CppInspector.Reflection
|
||||||
@@ -24,7 +25,6 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
// Return type of the method
|
// Return type of the method
|
||||||
private readonly Il2CppType returnType;
|
private readonly Il2CppType returnType;
|
||||||
|
|
||||||
public TypeInfo ReturnType => Assembly.Model.GetType(returnType, MemberTypes.TypeInfo);
|
public TypeInfo ReturnType => Assembly.Model.GetType(returnType, MemberTypes.TypeInfo);
|
||||||
|
|
||||||
// TODO: ReturnTypeCustomAttributes
|
// TODO: ReturnTypeCustomAttributes
|
||||||
@@ -39,8 +39,6 @@ namespace Il2CppInspector.Reflection
|
|||||||
}
|
}
|
||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
returnType = pkg.TypeUsages[Definition.returnType];
|
|
||||||
|
|
||||||
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == DefineConstants.METHOD_ATTRIBUTE_PRIVATE)
|
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == DefineConstants.METHOD_ATTRIBUTE_PRIVATE)
|
||||||
Attributes |= MethodAttributes.Private;
|
Attributes |= MethodAttributes.Private;
|
||||||
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == DefineConstants.METHOD_ATTRIBUTE_PUBLIC)
|
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == DefineConstants.METHOD_ATTRIBUTE_PUBLIC)
|
||||||
@@ -49,6 +47,16 @@ namespace Il2CppInspector.Reflection
|
|||||||
Attributes |= MethodAttributes.Virtual;
|
Attributes |= MethodAttributes.Virtual;
|
||||||
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_STATIC) != 0)
|
if ((Definition.flags & DefineConstants.METHOD_ATTRIBUTE_STATIC) != 0)
|
||||||
Attributes |= MethodAttributes.Static;
|
Attributes |= MethodAttributes.Static;
|
||||||
|
|
||||||
|
// Add return parameter
|
||||||
|
returnType = pkg.TypeUsages[Definition.returnType];
|
||||||
|
ReturnParameter = new ParameterInfo(pkg, -1, this);
|
||||||
|
|
||||||
|
// Add arguments
|
||||||
|
for (var p = Definition.parameterStart; p < Definition.parameterStart + Definition.parameterCount; p++)
|
||||||
|
DeclaredParameters.Add(new ParameterInfo(pkg, p, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString() => ReturnType.Name + " " + Name + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,14 +17,15 @@ namespace Il2CppInspector.Reflection
|
|||||||
// TODO: CustomAttributes
|
// TODO: CustomAttributes
|
||||||
|
|
||||||
// True if the parameter has a default value
|
// True if the parameter has a default value
|
||||||
public bool HasDefaultValue { get; }
|
public bool HasDefaultValue => (Attributes & ParameterAttributes.HasDefault) != 0;
|
||||||
|
|
||||||
// Default value for the parameter
|
// Default value for the parameter
|
||||||
public object DefaultValue { get; }
|
public object DefaultValue => throw new NotImplementedException();
|
||||||
|
|
||||||
public bool IsIn { get; }
|
public bool IsIn => (Attributes & ParameterAttributes.In) != 0;
|
||||||
public bool IsOptional { get; }
|
public bool IsOptional => (Attributes & ParameterAttributes.Optional) != 0;
|
||||||
public bool IsOut { get; }
|
public bool IsOut => (Attributes & ParameterAttributes.Out) != 0;
|
||||||
|
public bool IsRetval => (Attributes & ParameterAttributes.Retval) != 0;
|
||||||
|
|
||||||
// The member in which the parameter is defined
|
// The member in which the parameter is defined
|
||||||
public MemberInfo Member { get; }
|
public MemberInfo Member { get; }
|
||||||
@@ -33,9 +34,39 @@ namespace Il2CppInspector.Reflection
|
|||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
// Type of this parameter
|
// Type of this parameter
|
||||||
public TypeInfo ParameterType { get; }
|
private readonly Il2CppType paramType;
|
||||||
|
public TypeInfo ParameterType => Member.Assembly.Model.GetType(paramType, MemberTypes.TypeInfo);
|
||||||
|
|
||||||
// Zero-indexed position of the parameter in parameter list
|
// Zero-indexed position of the parameter in parameter list
|
||||||
public int Position { get; }
|
public int Position { get; private set; }
|
||||||
|
|
||||||
|
// Create a parameter. Specify paramIndex == -1 for a return type parameter
|
||||||
|
public ParameterInfo(Il2CppInspector pkg, int paramIndex, MethodInfo declaringMethod) {
|
||||||
|
Member = declaringMethod;
|
||||||
|
|
||||||
|
if (paramIndex == -1) {
|
||||||
|
Position = -1;
|
||||||
|
paramType = pkg.TypeUsages[declaringMethod.Definition.returnType];
|
||||||
|
Attributes |= ParameterAttributes.Retval;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var param = pkg.Metadata.Params[paramIndex];
|
||||||
|
Name = pkg.Metadata.Strings[param.nameIndex];
|
||||||
|
Position = paramIndex - declaringMethod.Definition.parameterStart;
|
||||||
|
paramType = pkg.TypeUsages[param.typeIndex];
|
||||||
|
|
||||||
|
if ((paramType.attrs & DefineConstants.PARAM_ATTRIBUTE_OPTIONAL) != 0)
|
||||||
|
Attributes |= ParameterAttributes.Optional;
|
||||||
|
if ((paramType.attrs & DefineConstants.PARAM_ATTRIBUTE_OUT) != 0)
|
||||||
|
Attributes |= ParameterAttributes.Out;
|
||||||
|
|
||||||
|
if (Position == -1)
|
||||||
|
Attributes |= ParameterAttributes.Retval;
|
||||||
|
else if (!IsOut)
|
||||||
|
Attributes |= ParameterAttributes.In;
|
||||||
|
|
||||||
|
// TODO: DefaultValue/HasDefaultValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user