Skip to content

Commit 70164e0

Browse files
committed
Speculative v106.1 support
1 parent e881176 commit 70164e0

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

LibCpp2IL/BinarySearcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static bool ValidateCodeRegistration(Il2CppCodeRegistration codeReg, Dict
305305
public ulong FindMetadataRegistrationPre24_5()
306306
{
307307
//We're looking for TypeDefinitionsSizesCount, which is the 4th-to-last field
308-
var sizeOfMr = (ulong)Il2CppMetadataRegistration.GetStructSize(binary.is32Bit);
308+
var sizeOfMr = (ulong)Il2CppMetadataRegistration.GetStructSize(binary.is32Bit, metadata.MetadataVersion);
309309
var ptrSize = binary.is32Bit ? 4ul : 8ul;
310310

311311
var bytesToSubtract = sizeOfMr - ptrSize * 4;
@@ -335,7 +335,7 @@ public ulong FindMetadataRegistrationPre24_5()
335335
public ulong FindMetadataRegistrationPost24_5()
336336
{
337337
var ptrSize = binary.is32Bit ? 4ul : 8ul;
338-
var sizeOfMr = (uint)Il2CppMetadataRegistration.GetStructSize(binary.is32Bit);
338+
var sizeOfMr = (uint)Il2CppMetadataRegistration.GetStructSize(binary.is32Bit, metadata.MetadataVersion);
339339

340340
LibLogger.VerboseNewline($"\t\t\tLooking for the number of type definitions, 0x{typeDefinitionsCount:X}");
341341
var ptrsToNumberOfTypes = FindAllMappedWords((ulong)typeDefinitionsCount).ToList();

LibCpp2IL/BinaryStructures/Il2CppMetadataRegistration.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class Il2CppMetadataRegistration : ReadableClass
1515
* Regardless of how we do it, the fact of the matter is that the count fields are (as well as the pointers which of course are) in practice [pointer size] bytes before the next field, not always 4,
1616
* so when calculating the total size of this struct, we need to take that into account.
1717
*/
18-
public static int GetStructSize(bool isBinary32Bit)
19-
=> (NumIntFields + NumPointerFields) * (isBinary32Bit ? sizeof(int) : sizeof(long)); //On 32-bit platforms, all pointers (represented in fields by long/ulong) are 32-bit. If this struct is updated, update the number of fields above.
18+
public static int GetStructSize(bool isBinary32Bit, float metadataMetadataVersion)
19+
=> (NumIntFields + NumPointerFields + (metadataMetadataVersion >= 106.1f ? 2 : 0)) * (isBinary32Bit ? sizeof(int) : sizeof(long)); //On 32-bit platforms, all pointers (represented in fields by long/ulong) are 32-bit. If this struct is updated, update the number of fields above.
2020

2121
public long genericClassesCount;
2222
public ulong genericClasses;
@@ -36,6 +36,9 @@ public static int GetStructSize(bool isBinary32Bit)
3636
public ulong typeDefinitionsSizes;
3737
public ulong metadataUsagesCount; //this one, and only this one, is defined as size_t. The rest of the counts are int32_t.
3838
public ulong metadataUsages;
39+
[Version(Min = 106.1f)] public ulong alwaysInitMetadataUsagesCount;
40+
[Version(Min = 106.1f)] public ulong alwaysInitMetadataUsages;
41+
3942

4043
public override void Read(ClassReadingBinaryReader reader)
4144
{
@@ -58,5 +61,11 @@ public override void Read(ClassReadingBinaryReader reader)
5861
typeDefinitionsSizes = reader.ReadNUint();
5962
metadataUsagesCount = reader.ReadNUint();
6063
metadataUsages = reader.ReadNUint();
64+
65+
if(IsAtLeast(106.1f))
66+
{
67+
alwaysInitMetadataUsagesCount = reader.ReadNUint();
68+
alwaysInitMetadataUsages = reader.ReadNUint();
69+
}
6170
}
6271
}

LibCpp2IL/Metadata/Il2CppMetadata.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ public static Il2CppMetadata ReadFrom(byte[] bytes, UnityVersion unityVersion)
144144
//v31 WITHOUT changes in codereg
145145
actualVersion = 31;
146146
}
147+
else if (version == 106)
148+
{
149+
//6.5.0a6 => v106
150+
// - changes GenericParameterIndex, FieldIndex, DefaultValueDataIndex to variable size
151+
// - changes Il2CppGenericContainer type_argc int32 => uint16, is_method int32 => uint8
152+
//6.6.0a6 => 106.1
153+
// - adds 2 new fields to Il2CppMetadataRegistration
154+
// - removes the first value of MetadataUsageType
155+
if(unityVersion.GreaterThanOrEquals(6000, 6, 0, UnityVersionType.Alpha, 6))
156+
actualVersion = 106.1f;
157+
else
158+
actualVersion = 106;
159+
}
147160
else
148161
{
149162
//6000.3 and 6000.5 alphas made a bunch of quick-succession version changes:
@@ -165,9 +178,6 @@ public static Il2CppMetadata ReadFrom(byte[] bytes, UnityVersion unityVersion)
165178
//6.5.0a5 => v105
166179
// - changes MethodIndex to variable size.
167180
// - brings the Il2CppClass changes from v38 to v10x.
168-
//6.5.0a6 => v106
169-
// - changes GenericParameterIndex, FieldIndex, DefaultValueDataIndex to variable size
170-
// - changes Il2CppGenericContainer type_argc int32 => uint16, is_method int32 => uint8
171181
actualVersion = version;
172182
}
173183

LibCpp2IL/MetadataUsage.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using LibCpp2IL.BinaryStructures;
33
using LibCpp2IL.Metadata;
44
using LibCpp2IL.Reflection;
@@ -158,6 +158,9 @@ public override string ToString()
158158
{
159159
var encodedType = encoded & 0xE000_0000;
160160
var type = (MetadataUsageType)(encodedType >> 29);
161+
if (context.Metadata.MetadataVersion > 106.1f)
162+
type += 1; //TypeInfo removed in v106.1
163+
161164
if (type <= MetadataUsageType.MethodRef && type >= MetadataUsageType.TypeInfo)
162165
{
163166
var index = (uint)(encoded & 0x1FFF_FFFF);

LibCpp2IL/MetadataUsageType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public enum MetadataUsageType : uint
44
{
5-
TypeInfo = 1,
5+
TypeInfo = 1, //REMOVED in v106.1
66
Type = 2,
77
MethodDef = 3,
88
FieldInfo = 4,

0 commit comments

Comments
 (0)