Skip to content

Commit

Permalink
Core: Workaround for issues with outputting diffablecs CAs
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Dec 29, 2023
1 parent ef427a9 commit 4e1fecd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
16 changes: 13 additions & 3 deletions Cpp2IL.Core/Utils/CsFileUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Reflection;
using System;
using System.Reflection;
using System.Text;
using Cpp2IL.Core.Logging;
using Cpp2IL.Core.Model.Contexts;
using LibCpp2IL;

Expand Down Expand Up @@ -250,7 +252,15 @@ public static string GetCustomAttributeStrings(HasCustomAttributes context, int
if (indentCount > 0)
sb.Append('\t', indentCount);

sb.AppendLine(analyzedCustomAttribute.ToString());
try
{
sb.AppendLine(analyzedCustomAttribute.ToString());
}
catch (Exception e)
{
Logger.WarnNewline("Exception printing/formatting custom attribute: " + e, "C# Generator");
sb.Append("/*Cpp2IL: Exception outputting custom attribute of type ").Append(analyzedCustomAttribute.Constructor.DeclaringType?.Name ?? "<unknown type?>").AppendLine("*/");
}
}

return sb.ToString();
Expand Down Expand Up @@ -320,4 +330,4 @@ public static void AppendInheritanceInfo(TypeAnalysisContext type, StringBuilder
sb.Append(GetTypeName(iface.Name));
}
}
}
}
24 changes: 19 additions & 5 deletions LibCpp2IL/BinaryStructures/Il2CppTypeEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ public enum Il2CppTypeEnum

public static class Il2CppTypeEnumExtensions
{
public static bool IsIl2CppPrimitive(this Il2CppTypeEnum e)
{
return e is >= Il2CppTypeEnum.IL2CPP_TYPE_VOID and <= Il2CppTypeEnum.IL2CPP_TYPE_STRING or Il2CppTypeEnum.IL2CPP_TYPE_I or Il2CppTypeEnum.IL2CPP_TYPE_U or Il2CppTypeEnum.IL2CPP_TYPE_OBJECT or Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF or Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX;
}
public static bool IsIl2CppPrimitive(this Il2CppTypeEnum e) =>
e switch
{
//VOID-STRING is all primitive - this covers void, bool, char, all integer and float types, and string
>= Il2CppTypeEnum.IL2CPP_TYPE_VOID and <= Il2CppTypeEnum.IL2CPP_TYPE_STRING => true,

//IntPtr and UIntPtr are also primitive
Il2CppTypeEnum.IL2CPP_TYPE_I => true,
Il2CppTypeEnum.IL2CPP_TYPE_U => true,

//Object is considered primitive in il2cpp metadata
Il2CppTypeEnum.IL2CPP_TYPE_OBJECT => true,

//TypedByRef is also primitive
Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF => true,
Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX => true,
_ => false
};
}
}
}

0 comments on commit 4e1fecd

Please sign in to comment.