diff --git a/LibCpp2IL/Metadata/Il2CppMetadata.cs b/LibCpp2IL/Metadata/Il2CppMetadata.cs index 1ae4b9b3..a4c9a5c3 100644 --- a/LibCpp2IL/Metadata/Il2CppMetadata.cs +++ b/LibCpp2IL/Metadata/Il2CppMetadata.cs @@ -28,7 +28,7 @@ public class Il2CppMetadata : ClassReadingBinaryReader private Il2CppParameterDefaultValue[] parameterDefaultValues; public Il2CppPropertyDefinition[] propertyDefs; public List attributeTypeRanges; - private Il2CppStringLiteral[] stringLiterals; + public Il2CppStringLiteral[] stringLiterals; public Il2CppMetadataUsageList[] metadataUsageLists; private Il2CppMetadataUsagePair[] metadataUsagePairs; public Il2CppRGCTXDefinition[] RgctxDefinitions; //Moved to binary in v24.2 diff --git a/LibCpp2IL/MetadataUsage.cs b/LibCpp2IL/MetadataUsage.cs index 3f8a32b7..6d170793 100644 --- a/LibCpp2IL/MetadataUsage.cs +++ b/LibCpp2IL/MetadataUsage.cs @@ -25,28 +25,27 @@ public class MetadataUsage(MetadataUsageType type, ulong offset, uint value) public uint RawValue => value; - public object Value - { - get + public object Value => + Type switch { - switch (Type) - { - case MetadataUsageType.Type: - case MetadataUsageType.TypeInfo: - return AsType(); - case MetadataUsageType.MethodDef: - return AsMethod(); - case MetadataUsageType.FieldInfo: - return AsField(); - case MetadataUsageType.StringLiteral: - return AsLiteral(); - case MetadataUsageType.MethodRef: - return AsGenericMethodRef(); - default: - throw new ArgumentOutOfRangeException(); - } - } - } + MetadataUsageType.Type or MetadataUsageType.TypeInfo => AsType(), + MetadataUsageType.MethodDef => AsMethod(), + MetadataUsageType.FieldInfo => AsField(), + MetadataUsageType.StringLiteral => AsLiteral(), + MetadataUsageType.MethodRef => AsGenericMethodRef(), + _ => throw new ArgumentOutOfRangeException() + }; + + public bool IsValid => + Type switch + { + MetadataUsageType.Type or MetadataUsageType.TypeInfo => value < LibCpp2IlMain.Binary!.NumTypes, + MetadataUsageType.MethodDef => value < LibCpp2IlMain.TheMetadata!.methodDefs.Length, + MetadataUsageType.FieldInfo => value < LibCpp2IlMain.TheMetadata!.fieldRefs.Length, + MetadataUsageType.StringLiteral => value < LibCpp2IlMain.TheMetadata!.stringLiterals.Length, + MetadataUsageType.MethodRef => value < LibCpp2IlMain.Binary!.AllGenericMethodSpecs.Length, + _ => false + }; public Il2CppTypeReflectionData AsType() { @@ -155,22 +154,6 @@ public override string ToString() return $"Metadata Usage {{type={Type}, Value={Value}}}"; } - public bool IsValid - { - get - { - try - { - var _ = Value; - return true; - } - catch (Exception) - { - return false; - } - } - } - public static MetadataUsage? DecodeMetadataUsage(ulong encoded, ulong address) {