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:
Robert Xiao
2020-04-11 13:21:46 -07:00
committed by Katy
parent 3cd5af09fc
commit a9f6e7b4e0
6 changed files with 65 additions and 32 deletions

View File

@@ -28,8 +28,8 @@ namespace Il2CppInspector.Reflection
public MethodInfo RaiseMethod { get; }
// Event handler delegate type
private int eventTypeReference;
public TypeInfo EventHandlerType => Assembly.Model.TypesByReferenceIndex[eventTypeReference];
private readonly TypeRef eventTypeReference;
public TypeInfo EventHandlerType => eventTypeReference.Value;
// True if the event has a special name
public bool IsSpecialName => (Attributes & EventAttributes.SpecialName) == EventAttributes.SpecialName;
@@ -42,8 +42,8 @@ namespace Il2CppInspector.Reflection
Index = eventIndex;
Name = pkg.Strings[Definition.nameIndex];
eventTypeReference = Definition.typeIndex;
var eventType = pkg.TypeReferences[eventTypeReference];
eventTypeReference = TypeRef.FromReferenceIndex(Assembly.Model, Definition.typeIndex);
var eventType = pkg.TypeReferences[Definition.typeIndex];
if ((eventType.attrs & Il2CppConstants.FIELD_ATTRIBUTE_SPECIAL_NAME) == Il2CppConstants.FIELD_ATTRIBUTE_SPECIAL_NAME)
Attributes |= EventAttributes.SpecialName;