diff --git a/Il2CppInspector.Common/IL2CPP/CustomAttributeDataReader.cs b/Il2CppInspector.Common/IL2CPP/CustomAttributeDataReader.cs index 5b8897a..8901ba8 100644 --- a/Il2CppInspector.Common/IL2CPP/CustomAttributeDataReader.cs +++ b/Il2CppInspector.Common/IL2CPP/CustomAttributeDataReader.cs @@ -103,15 +103,17 @@ namespace Il2CppInspector var type = BlobReader.ReadEncodedTypeEnum(_inspector, _data, out var typeDef); var value = BlobReader.GetConstantValueFromBlob(_inspector, type, _data); - if (value is BlobReader.ConstantBlobArray blobArray) + value = ConvertAttributeValue(value); + + if (value is CustomAttributeArgument valueAttr) { - arg.Type = ConvertTypeDef(blobArray.ArrayTypeDef, blobArray.ArrayTypeEnum); - arg.Value = blobArray.Elements.Select(ConvertAttributeValue).ToArray(); + arg.Type = valueAttr.Type; + arg.Value = valueAttr.Value; } else { arg.Type = ConvertTypeDef(typeDef, type); - arg.Value = ConvertAttributeValue(value); + arg.Value = value; } } @@ -126,21 +128,15 @@ namespace Il2CppInspector var arrValue = new CustomAttributeArgument { Type = ConvertTypeDef(blobArray.ArrayTypeDef, blobArray.ArrayTypeEnum), - Value = blobArray.Elements.Select(ConvertAttributeValue).ToArray() + Value = blobArray.Elements.Select(blobElem => new CustomAttributeArgument + { + Type = ConvertTypeDef(blobElem.TypeDef, blobElem.TypeEnum), + Value = ConvertAttributeValue(blobElem.Value) + }).ToArray() }; return arrValue; } - case BlobReader.ConstantBlobArrayElement blobElem: - { - var subArgument = new CustomAttributeArgument - { - Type = ConvertTypeDef(blobElem.TypeDef, blobElem.TypeEnum), - Value = blobElem.Value - }; - - return subArgument; - } default: return value; } diff --git a/Il2CppInspector.Common/Outputs/AssemblyShims.cs b/Il2CppInspector.Common/Outputs/AssemblyShims.cs index 192acc7..bb6e5fb 100644 --- a/Il2CppInspector.Common/Outputs/AssemblyShims.cs +++ b/Il2CppInspector.Common/Outputs/AssemblyShims.cs @@ -479,13 +479,6 @@ namespace Il2CppInspector.Outputs case CustomAttributeArgument[] argumentArray: return new CAArgument(new SZArraySig(typeSig), argumentArray.Select(GetArgument).ToList()); - case object[] caArray: - return new CAArgument(new SZArraySig(typeSig), - caArray.Select(x => new CustomAttributeArgument - { - Type = argument.Type, - Value = x - }).Select(GetArgument).ToList()); default: return new CAArgument(typeSig, argument.Value); } diff --git a/Il2CppInspector.Common/Reflection/CustomAttributeData.cs b/Il2CppInspector.Common/Reflection/CustomAttributeData.cs index 42f0d49..4a96a92 100644 --- a/Il2CppInspector.Common/Reflection/CustomAttributeData.cs +++ b/Il2CppInspector.Common/Reflection/CustomAttributeData.cs @@ -75,10 +75,6 @@ namespace Il2CppInspector.Reflection foreach (var info in GetTypeReferences(array)) yield return info; break; - case TypeInfo[] infos: - foreach (var info in infos) - yield return info; - break; } } } diff --git a/Il2CppInspector.Common/Reflection/Extensions.cs b/Il2CppInspector.Common/Reflection/Extensions.cs index 0590eb6..e93ee78 100644 --- a/Il2CppInspector.Common/Reflection/Extensions.cs +++ b/Il2CppInspector.Common/Reflection/Extensions.cs @@ -209,7 +209,7 @@ namespace Il2CppInspector.Reflection } case TypeInfo typeInfo: return $"typeof({typeInfo.GetScopedCSharpName(usingScope)})"; - case object[] array: + case CustomAttributeArgument[] array: var arraySb = new StringBuilder(); arraySb.Append("new "); arraySb.Append(type.GetScopedCSharpName(usingScope)); @@ -222,8 +222,7 @@ namespace Il2CppInspector.Reflection arraySb.Append(" {"); for (int i = 0; i < array.Length; i++) { - if (array[i] is CustomAttributeArgument arrayArgument) // Used for array with different entries, see BlobReader for more info - arraySb.Append(arrayArgument.Value.ToCSharpValue(arrayArgument.Type, usingScope)); + arraySb.Append(array[i].Value.ToCSharpValue(array[i].Type, usingScope)); if (i + 1 != array.Length) arraySb.Append(", "); diff --git a/Il2CppInspector.Common/Utils/BlobReader.cs b/Il2CppInspector.Common/Utils/BlobReader.cs index 4afd850..ba99452 100644 --- a/Il2CppInspector.Common/Utils/BlobReader.cs +++ b/Il2CppInspector.Common/Utils/BlobReader.cs @@ -78,28 +78,25 @@ public static class BlobReader var arrayElementType = ReadEncodedTypeEnum(inspector, blob, out var arrayElementDef); var arrayElementsAreDifferent = blob.ReadByte(); + var array = new ConstantBlobArrayElement[length]; if (arrayElementsAreDifferent == kArrayTypeWithDifferentElements) { - var array = new ConstantBlobArrayElement[length]; for (int i = 0; i < length; i++) { var elementType = ReadEncodedTypeEnum(inspector, blob, out var elementTypeDef); array[i] = new ConstantBlobArrayElement(elementTypeDef, GetConstantValueFromBlob(inspector, elementType, blob), elementType); } - - value = new ConstantBlobArray(arrayElementDef, array, true, arrayElementType); } else { - var array = new object[length]; for (int i = 0; i < length; i++) { - array[i] = GetConstantValueFromBlob(inspector, arrayElementType, blob); + array[i] = new ConstantBlobArrayElement(arrayElementDef, GetConstantValueFromBlob(inspector, arrayElementType, blob), arrayElementType); } - - value = new ConstantBlobArray(arrayElementDef, array, false, arrayElementType); } + value = new ConstantBlobArray(arrayElementDef, array, arrayElementType); + break; case Il2CppTypeEnum.IL2CPP_TYPE_CLASS: @@ -133,9 +130,9 @@ public static class BlobReader var typeIndex = blob.ReadCompressedInt32(); var typeHandle = (uint)inspector.TypeReferences[typeIndex].datapoint; enumType = inspector.TypeDefinitions[typeHandle]; + var elementTypeHandle = inspector.TypeReferences[enumType.elementTypeIndex].datapoint; var elementType = inspector.TypeDefinitions[elementTypeHandle]; - typeEnum = inspector.TypeReferences[elementType.byvalTypeIndex].type; } // This technically also handles SZARRAY (System.Array) and all others by just returning their system type @@ -143,7 +140,7 @@ public static class BlobReader return typeEnum; } - public record ConstantBlobArray(Il2CppTypeDefinition ArrayTypeDef, object[] Elements, bool DifferentElements, Il2CppTypeEnum ArrayTypeEnum); + public record ConstantBlobArray(Il2CppTypeDefinition ArrayTypeDef, ConstantBlobArrayElement[] Elements, Il2CppTypeEnum ArrayTypeEnum); public record ConstantBlobArrayElement(Il2CppTypeDefinition TypeDef, object Value, Il2CppTypeEnum TypeEnum); } \ No newline at end of file