diff --git a/Cpp2IL.Core/AttributeRestorerPost29.cs b/Cpp2IL.Core/AttributeRestorerPost29.cs index bcc04922..4f346acf 100644 --- a/Cpp2IL.Core/AttributeRestorerPost29.cs +++ b/Cpp2IL.Core/AttributeRestorerPost29.cs @@ -127,7 +127,10 @@ private static CustomAttribute ReadAndCreateCustomAttribute(ModuleDefinition mod { bytesRead = 0; var managedConstructor = constructor.AsManaged(); + +#if !DEBUG try +#endif { var ret = new CustomAttribute(module.ImportReference(managedConstructor)); @@ -243,15 +246,13 @@ private static CustomAttribute ReadAndCreateCustomAttribute(ModuleDefinition mod return ret; } +#if !DEBUG catch (Exception e) { -#if DEBUG - throw; -#else Logger.WarnNewline($"Failed to parse custom attribute {constructor.DeclaringType!.FullName} due to an exception: {e.GetType()}: {e.Message}"); return MakeFallbackAttribute(module, managedConstructor) ?? throw new("Failed to resolve AttributeAttribute type"); -#endif } +#endif } private static object? WrapArrayValuesInCustomAttributeArguments(TypeReference typeReference, Array arr) @@ -271,12 +272,20 @@ private static CustomAttribute ReadAndCreateCustomAttribute(ModuleDefinition mod var objectTypeName = o?.GetType()?.FullName ?? throw new NullReferenceException($"Object {o} in array {arr} of variable type and length {arr.Length} is null, so cannot determine its type"); - var typeDef = MiscUtils.TryLookupTypeDefKnownNotGeneric(objectTypeName); + TypeDefinition typeDef; + if(o is TypeDefinition) + //Special case TypeDefinition => Type + typeDef = TypeDefinitions.Type; + else + typeDef = MiscUtils.TryLookupTypeDefKnownNotGeneric(objectTypeName); if (typeDef == null) throw new Exception($"Couldn't resolve type {objectTypeName}"); - list.Add(new CustomAttributeArgument(typeDef, o)); + var typedParam = new CustomAttributeArgument(typeDef, o); + + //Needs to be wrapped in an additional argument with type System.Object, because cecil + list.Add(new CustomAttributeArgument(TypeDefinitions.Object, typedParam)); } return list.ToArray(); @@ -541,6 +550,7 @@ private static Il2CppTypeEnum ReadBlobType(long pos, out int bytesRead, out Type Il2CppTypeEnum.IL2CPP_TYPE_STRING => TypeDefinitions.String.AsUnmanaged(), Il2CppTypeEnum.IL2CPP_TYPE_BYREF => TypeDefinitions.TypedReference.AsUnmanaged(), Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX => TypeDefinitions.Type.AsUnmanaged(), + Il2CppTypeEnum.IL2CPP_TYPE_OBJECT => TypeDefinitions.Object.AsUnmanaged(), _ => throw new ArgumentOutOfRangeException(nameof(typeEnum), typeEnum, null) }; }