Model: Cache type definitions by fully qualified name
This commit is contained in:
@@ -19,6 +19,9 @@ namespace Il2CppInspector.Reflection
|
|||||||
// List of all types ordered by their TypeDefinitionIndex
|
// List of all types ordered by their TypeDefinitionIndex
|
||||||
public TypeInfo[] TypesByDefinitionIndex { get; }
|
public TypeInfo[] TypesByDefinitionIndex { get; }
|
||||||
|
|
||||||
|
// List of all type definitions by fully qualified name
|
||||||
|
public Dictionary<string, TypeInfo> TypesByFullName { get; } = new Dictionary<string, TypeInfo>();
|
||||||
|
|
||||||
// List of all type usages ordered by their type usage index
|
// List of all type usages ordered by their type usage index
|
||||||
public TypeInfo[] TypesByUsageIndex { get; }
|
public TypeInfo[] TypesByUsageIndex { get; }
|
||||||
|
|
||||||
@@ -48,9 +51,6 @@ namespace Il2CppInspector.Reflection
|
|||||||
// Get an assembly by its name
|
// Get an assembly by its name
|
||||||
public Assembly GetAssembly(string name) => Assemblies.FirstOrDefault(a => a.FullName == name);
|
public Assembly GetAssembly(string name) => Assemblies.FirstOrDefault(a => a.FullName == name);
|
||||||
|
|
||||||
// Get a type by its full name
|
|
||||||
public TypeInfo GetType(string name) => Types.FirstOrDefault(t => t.FullName == name);
|
|
||||||
|
|
||||||
private TypeInfo getNewTypeUsage(Il2CppType usage, MemberTypes memberType) {
|
private TypeInfo getNewTypeUsage(Il2CppType usage, MemberTypes memberType) {
|
||||||
switch (usage.type) {
|
switch (usage.type) {
|
||||||
case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
|
case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
|
||||||
@@ -94,7 +94,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var fqn = Il2CppConstants.FullNameTypeString[(int) t];
|
var fqn = Il2CppConstants.FullNameTypeString[(int) t];
|
||||||
return TypesByDefinitionIndex.First(x => x.FullName == fqn);
|
return TypesByFullName[fqn];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type from a virtual address pointer
|
// Type from a virtual address pointer
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ namespace Il2CppInspector.Reflection {
|
|||||||
public TypeInfo BaseType => IsPointer? null :
|
public TypeInfo BaseType => IsPointer? null :
|
||||||
baseTypeUsage != -1?
|
baseTypeUsage != -1?
|
||||||
Assembly.Model.GetTypeFromUsage(baseTypeUsage, MemberTypes.TypeInfo)
|
Assembly.Model.GetTypeFromUsage(baseTypeUsage, MemberTypes.TypeInfo)
|
||||||
: IsArray? Assembly.Model.TypesByDefinitionIndex.First(t => t.FullName == "System.Array")
|
: IsArray? Assembly.Model.TypesByFullName["System.Array"]
|
||||||
: Namespace != "System" || BaseName != "Object" ? Assembly.Model.TypesByDefinitionIndex.First(t => t.FullName == "System.Object")
|
: Namespace != "System" || BaseName != "Object" ? Assembly.Model.TypesByFullName["System.Object"]
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// True if the type contains unresolved generic type parameters
|
// True if the type contains unresolved generic type parameters
|
||||||
@@ -252,6 +252,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
// Add to global type definition list
|
// Add to global type definition list
|
||||||
Assembly.Model.TypesByDefinitionIndex[Index] = this;
|
Assembly.Model.TypesByDefinitionIndex[Index] = this;
|
||||||
|
Assembly.Model.TypesByFullName[FullName] = this;
|
||||||
|
|
||||||
if ((Definition.flags & Il2CppConstants.TYPE_ATTRIBUTE_SERIALIZABLE) != 0)
|
if ((Definition.flags & Il2CppConstants.TYPE_ATTRIBUTE_SERIALIZABLE) != 0)
|
||||||
Attributes |= TypeAttributes.Serializable;
|
Attributes |= TypeAttributes.Serializable;
|
||||||
|
|||||||
Reference in New Issue
Block a user