unify logic for getting element type index

This commit is contained in:
LukeFZ
2025-07-21 17:06:16 +02:00
parent 8055ed1cdb
commit 893d2c1300
4 changed files with 9 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
using System.Reflection;
using VersionedSerialization;
using VersionedSerialization.Attributes;
namespace Il2CppInspector.Next.Metadata;
@@ -82,4 +83,9 @@ public partial record struct Il2CppTypeDefinition
public uint Token { get; private set; }
public readonly bool IsValid => NameIndex != 0;
public int GetEnumElementTypeIndex(StructVersion version)
=> version >= MetadataVersions.V350
? ParentIndex
: ElementTypeIndex;
}

View File

@@ -786,10 +786,7 @@ namespace Il2CppInspector.Reflection
if (Definition.Bitfield.EnumType) {
IsEnum = true;
var enumUnderlyingTypeIndex = Assembly.Model.Package.Version >= MetadataVersions.V350
? Definition.ParentIndex
: Definition.ElementTypeIndex;
var enumUnderlyingTypeIndex = Definition.GetEnumElementTypeIndex(Assembly.Model.Package.Version);
enumUnderlyingTypeReference = TypeRef.FromReferenceIndex(Assembly.Model, enumUnderlyingTypeIndex);
}

View File

@@ -163,9 +163,7 @@ public static class BlobReader
var typeHandle = inspector.TypeReferences[typeIndex].Data.KlassIndex;
enumType = inspector.TypeDefinitions[typeHandle];
var elementTypeIndex = inspector.Version >= MetadataVersions.V350
? enumType.ParentIndex
: enumType.ElementTypeIndex;
var elementTypeIndex = enumType.GetEnumElementTypeIndex(inspector.Version);
var elementTypeHandle = inspector.TypeReferences[elementTypeIndex].Data.KlassIndex;
var elementType = inspector.TypeDefinitions[elementTypeHandle];

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<AnalyzerRoslynVersion>4.10</AnalyzerRoslynVersion>
<RoslynApiVersion>4.10.0</RoslynApiVersion>