diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index cfe1ede..773613e 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -694,7 +694,6 @@ namespace Il2CppInspector.Reflection { refs.UnionWith(DeclaredMethods.SelectMany(m => m.DeclaredParameters).Select(p => p.ParameterType)); // Method generic type parameters and constraints - // TODO: Needs to recurse through nested generic parameters refs.UnionWith(DeclaredMethods.SelectMany(m => m.GenericTypeParameters ?? new List())); refs.UnionWith(DeclaredMethods.SelectMany(m => m.GenericTypeParameters ?? new List()) .SelectMany(p => p.GetGenericParameterConstraints())); @@ -719,7 +718,6 @@ namespace Il2CppInspector.Reflection { refs.Add(GetEnumUnderlyingType()); // Generic type parameters and constraints - // TODO: Needs to recurse through nested generic parameters if (GenericTypeParameters != null) refs.UnionWith(GenericTypeParameters); if (GenericTypeArguments != null) @@ -729,14 +727,21 @@ namespace Il2CppInspector.Reflection { // Implemented interfaces refs.UnionWith(ImplementedInterfaces); - IEnumerable refList = refs.ToList(); - // Repeatedly replace arrays, pointers and references with their element types - while (refList.Any(r => r.HasElementType)) - refList = refList.Select(r => r.HasElementType ? r.ElementType : r); + while (refs.Any(r => r.HasElementType)) + refs = refs.Select(r => r.HasElementType ? r.ElementType : r).ToHashSet(); + + // Type arguments in generic types that may have been a field, method parameter etc. + IEnumerable genericArguments = refs.ToList(); + do { + genericArguments = genericArguments.Where(r => r.GenericTypeArguments != null).SelectMany(r => r.GenericTypeArguments); + refs.UnionWith(genericArguments); + } while (genericArguments.Any()); // Remove anonymous types - refList = refList.Where(r => !string.IsNullOrEmpty(r.FullName)); + refs.RemoveWhere(r => string.IsNullOrEmpty(r.FullName)); + + IEnumerable refList = refs; // Eliminated named duplicates (the HashSet removes instance duplicates) refList = refList.GroupBy(r => r.FullName).Select(p => p.First());