Generify reference indices to prepare for generic instances
We use indices into the TypesByReferenceIndex table to defer type lookup during model construction. However, this won't support fully generic instances (which might not be in the type table at all). This patch introduces a new TypeRef abstraction which can either represent a fixed index or an instantiated generic type.
This commit is contained in:
@@ -17,8 +17,8 @@ namespace Il2CppInspector.Reflection
|
||||
public ParameterInfo ReturnParameter { get; }
|
||||
|
||||
// Return type of the method
|
||||
private readonly int returnTypeReference;
|
||||
public TypeInfo ReturnType => Assembly.Model.TypesByReferenceIndex[returnTypeReference];
|
||||
private readonly TypeRef returnTypeReference;
|
||||
public TypeInfo ReturnType => returnTypeReference.Value;
|
||||
|
||||
public override bool RequiresUnsafeContext => base.RequiresUnsafeContext || ReturnType.RequiresUnsafeContext;
|
||||
|
||||
@@ -26,15 +26,14 @@ namespace Il2CppInspector.Reflection
|
||||
|
||||
public MethodInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) {
|
||||
// Add return parameter
|
||||
returnTypeReference = Definition.returnType;
|
||||
returnTypeReference = TypeRef.FromReferenceIndex(Assembly.Model, Definition.returnType);
|
||||
ReturnParameter = new ParameterInfo(pkg, -1, this);
|
||||
}
|
||||
|
||||
public MethodInfo(Il2CppModel model, Il2CppMethodSpec spec, TypeInfo declaringType) : base(model, spec, declaringType) {
|
||||
var methodDef = model.MethodsByDefinitionIndex[spec.methodDefinitionIndex];
|
||||
|
||||
// Add return parameter
|
||||
returnTypeReference = methodDef.Definition.returnType;
|
||||
// Add return parameter (TODO substitute type)
|
||||
returnTypeReference = TypeRef.FromReferenceIndex(Assembly.Model, methodDef.Definition.returnType);
|
||||
ReturnParameter = ((MethodInfo) methodDef).ReturnParameter;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user