-
-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathCustomAttributeEnumParameter.cs
More file actions
38 lines (30 loc) · 1.65 KB
/
Copy pathCustomAttributeEnumParameter.cs
File metadata and controls
38 lines (30 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.IO;
using System.Linq;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using LibCpp2IL.BinaryStructures;
namespace Cpp2IL.Core.Model.CustomAttributes;
public class CustomAttributeEnumParameter : BaseCustomAttributeParameter
{
public readonly Il2CppType EnumType;
public readonly Il2CppType UnderlyingPrimitiveType;
public readonly CustomAttributePrimitiveParameter UnderlyingPrimitiveParameter;
public TypeAnalysisContext EnumTypeContext => Owner.Constructor.AppContext.ResolveIl2CppType(EnumType);
public CustomAttributeEnumParameter(Il2CppType enumType, ApplicationAnalysisContext context, AnalyzedCustomAttribute owner, CustomAttributeParameterKind kind, int index) : base(owner, kind, index)
{
EnumType = enumType;
var enumTypeDef = EnumType.AsClass();
UnderlyingPrimitiveType = enumTypeDef.EnumUnderlyingType;
UnderlyingPrimitiveParameter = new(UnderlyingPrimitiveType.Type, owner, kind, index);
}
public Il2CppTypeEnum GetTypeByte() => UnderlyingPrimitiveType.Type;
public override void ReadFromV29Blob(BinaryReader reader, ApplicationAnalysisContext context) => UnderlyingPrimitiveParameter.ReadFromV29Blob(reader, context);
public override string ToString()
{
var enumTypeDef = EnumType.AsClass();
var matchingField = enumTypeDef.Fields?.FirstOrDefault(f => Equals(f.DefaultValue?.Value?.Value, UnderlyingPrimitiveParameter.PrimitiveValue));
if (matchingField != null)
return $"{enumTypeDef.Name}::{matchingField.Name} ({UnderlyingPrimitiveParameter.PrimitiveValue})";
return UnderlyingPrimitiveParameter.ToString();
}
}