Move index decoding to MetadataUsage
This reduces code duplication between metadata usage index decoding and vtable method index decoding.
This commit is contained in:
@@ -21,13 +21,28 @@ namespace Il2CppInspector
|
||||
{
|
||||
public MetadataUsageType Type { get; }
|
||||
public int SourceIndex { get; }
|
||||
public int DestinationIndex { get; }
|
||||
public ulong VirtualAddress { get; private set; }
|
||||
|
||||
public MetadataUsage(MetadataUsageType type, int sourceIndex, int destinationIndex) {
|
||||
public MetadataUsage(MetadataUsageType type, int sourceIndex) {
|
||||
Type = type;
|
||||
SourceIndex = sourceIndex;
|
||||
DestinationIndex = destinationIndex;
|
||||
}
|
||||
|
||||
public static MetadataUsage FromEncodedIndex(Il2CppInspector package, uint encodedIndex) {
|
||||
uint index;
|
||||
MetadataUsageType usageType;
|
||||
if (package.Version < 19) {
|
||||
/* These encoded indices appear only in vtables, and are decoded by IsGenericMethodIndex/GetDecodedMethodIndex */
|
||||
var isGeneric = encodedIndex & 0x80000000;
|
||||
index = package.Binary.VTableMethodReferences[encodedIndex & 0x7FFFFFFF];
|
||||
usageType = (isGeneric != 0) ? MetadataUsageType.MethodRef : MetadataUsageType.MethodDef;
|
||||
} else {
|
||||
/* These encoded indices appear in metadata usages, and are decoded by GetEncodedIndexType/GetDecodedMethodIndex */
|
||||
var encodedType = encodedIndex & 0xE0000000;
|
||||
usageType = (MetadataUsageType)(encodedType >> 29);
|
||||
index = encodedIndex & 0x1FFFFFFF;
|
||||
}
|
||||
return new MetadataUsage(usageType, (int)index);
|
||||
}
|
||||
|
||||
public void SetAddress(ulong virtualAddress) => VirtualAddress = virtualAddress;
|
||||
|
||||
Reference in New Issue
Block a user