IL2CPP: Fix field offsets for value types (#25)
This commit is contained in:
@@ -15,7 +15,14 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// IL2CPP-specific data
|
// IL2CPP-specific data
|
||||||
public Il2CppFieldDefinition Definition { get; }
|
public Il2CppFieldDefinition Definition { get; }
|
||||||
public int Index { get; }
|
public int Index { get; }
|
||||||
public long Offset { get; }
|
|
||||||
|
// Offsets for reference types start at 0x8 or 0x10 due to Il2CppObject "header" containing 2 pointers
|
||||||
|
// Value types don't have this header but the offsets are still stored as starting at 0x8 or 0x10, so we have to subtract this
|
||||||
|
// Open generic types have offsets that aren't known until runtime
|
||||||
|
private readonly long rawOffset;
|
||||||
|
public long Offset => DeclaringType.ContainsGenericParameters? 0 :
|
||||||
|
rawOffset - (DeclaringType.IsValueType && !IsStatic? (Assembly.Model.Package.BinaryImage.Bits / 8) * 2 : 0);
|
||||||
|
|
||||||
public ulong DefaultValueMetadataAddress { get; }
|
public ulong DefaultValueMetadataAddress { get; }
|
||||||
|
|
||||||
// Custom attributes for this member
|
// Custom attributes for this member
|
||||||
@@ -78,9 +85,10 @@ namespace Il2CppInspector.Reflection {
|
|||||||
base(declaringType) {
|
base(declaringType) {
|
||||||
Definition = pkg.Fields[fieldIndex];
|
Definition = pkg.Fields[fieldIndex];
|
||||||
Index = fieldIndex;
|
Index = fieldIndex;
|
||||||
Offset = pkg.FieldOffsets[fieldIndex];
|
|
||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
|
rawOffset = pkg.FieldOffsets[fieldIndex];
|
||||||
|
|
||||||
fieldTypeReference = Definition.typeIndex;
|
fieldTypeReference = Definition.typeIndex;
|
||||||
var fieldType = pkg.TypeReferences[fieldTypeReference];
|
var fieldType = pkg.TypeReferences[fieldTypeReference];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user