From 0c998de8447a95982b6f2898ed8288827599bb32 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Thu, 13 Aug 2020 03:41:49 +0200 Subject: [PATCH] C++: Fix incorrect field alignment for 2/4/8-byte simple types --- Il2CppInspector.Common/Cpp/CppType.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Il2CppInspector.Common/Cpp/CppType.cs b/Il2CppInspector.Common/Cpp/CppType.cs index c6d2963..68f4027 100644 --- a/Il2CppInspector.Common/Cpp/CppType.cs +++ b/Il2CppInspector.Common/Cpp/CppType.cs @@ -250,6 +250,13 @@ namespace Il2CppInspector.Cpp if (field.BitfieldSize == 0 && field.Offset % 8 != 0) field.Offset = (field.Offset / 8) * 8 + 8; + // A struct or union must be aligned on a word boundary for the architecture bit width + //if (field.Type is CppComplexType && + + // A 2, 4 or 8-byte value etc. must be aligned on an equivalent boundary + if (!(field.Type is CppComplexType) && field.OffsetBytes % field.SizeBytes != 0) + field.Offset += (field.SizeBytes - field.OffsetBytes % field.SizeBytes) * 8; + // Respect alignment directives if (alignmentBytes > 0 && field.OffsetBytes % alignmentBytes != 0) field.Offset += (alignmentBytes - field.OffsetBytes % alignmentBytes) * 8;