Skip to content

Commit 3d1cea6

Browse files
committed
Lib: Support v31.
1 parent 6b49552 commit 3d1cea6

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

Cpp2IL.Core/Model/Contexts/MethodAnalysisContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class MethodAnalysisContext : HasCustomAttributesAndName, IMethodInfoProv
7474

7575
public int ParameterCount => Parameters.Count;
7676

77+
//TODO Support custom attributes on return types (v31 feature)
7778
public TypeAnalysisContext ReturnTypeContext => InjectedReturnType ?? DeclaringType!.DeclaringAssembly.ResolveIl2CppType(Definition!.RawReturnType!);
7879

7980
public MethodAnalysisContext(Il2CppMethodDefinition? definition, TypeAnalysisContext parent) : base(definition?.token ?? 0, parent.AppContext)

LibCpp2IL/Metadata/Il2CppMetadata.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,15 @@ public class Il2CppMetadata : ClassReadingBinaryReader
6666
}
6767

6868
var version = BitConverter.ToInt32(bytes, 4);
69-
if (version is < 23 or > 29)
69+
if (version is < 23 or > 31)
7070
{
71-
throw new FormatException("Unsupported metadata version found! We support 23-29, got " + version);
71+
throw new FormatException("Unsupported metadata version found! We support 23-31, got " + version);
7272
}
7373

7474
LibLogger.VerboseNewline($"\tIL2CPP Metadata Declares its version as {version}");
7575

7676
float actualVersion;
77-
if (version == 27)
78-
{
79-
if (unityVersion.GreaterThanOrEquals(2021, 1))
80-
actualVersion = 27.2f; //2021.1 and up is v27.2, which just changes Il2CppType to have one new bit
81-
else if (unityVersion.GreaterThanOrEquals(2020, 2, 4))
82-
actualVersion = 27.1f; //2020.2.4 and above is v27.1
83-
else
84-
actualVersion = version; //2020.2 and above is v27
85-
}
86-
else if (version == 24)
77+
if (version == 24)
8778
{
8879
if (unityVersion.GreaterThanOrEquals(2020, 1, 11))
8980
actualVersion = 24.4f; //2020.1.11-17 were released prior to 2019.4.21, so are still on 24.4
@@ -104,6 +95,15 @@ public class Il2CppMetadata : ClassReadingBinaryReader
10495
else
10596
actualVersion = version; //2017.1.0 was the first v24 version
10697
}
98+
else if (version == 27)
99+
{
100+
if (unityVersion.GreaterThanOrEquals(2021, 1))
101+
actualVersion = 27.2f; //2021.1 and up is v27.2, which just changes Il2CppType to have one new bit
102+
else if (unityVersion.GreaterThanOrEquals(2020, 2, 4))
103+
actualVersion = 27.1f; //2020.2.4 and above is v27.1
104+
else
105+
actualVersion = version; //2020.2 and above is v27
106+
}
107107
else if (version == 29)
108108
{
109109
if (unityVersion.GreaterThanOrEquals(2023, 2, 0, UnityVersionType.Alpha, 22))
@@ -112,6 +112,11 @@ public class Il2CppMetadata : ClassReadingBinaryReader
112112
actualVersion = 29.1f; //2022.1.0b7 introduces v29.1 which adds two new pointers to codereg
113113
else
114114
actualVersion = 29; //2021.3.0 introduces v29
115+
} else if (version == 31)
116+
{
117+
//2022.3.33 introduces v31. Unity why would you bump this on a minor version.
118+
//Adds one new field (return type token) to method def
119+
actualVersion = 31;
115120
}
116121
else actualVersion = version;
117122

LibCpp2IL/Metadata/Il2CppMethodDefinition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Il2CppMethodDefinition : ReadableClass
1313
public int nameIndex;
1414
public int declaringTypeIdx;
1515
public int returnTypeIdx;
16+
[Version(Min = 31)] public uint returnParameterToken;
1617
public int parameterStart;
1718
[Version(Max = 24)] public int customAttributeIndex;
1819
public int genericContainerIndex;
@@ -155,6 +156,10 @@ public override void Read(ClassReadingBinaryReader reader)
155156

156157
declaringTypeIdx = reader.ReadInt32();
157158
returnTypeIdx = reader.ReadInt32();
159+
160+
if(IsAtLeast(31))
161+
returnParameterToken = reader.ReadUInt32();
162+
158163
parameterStart = reader.ReadInt32();
159164

160165
if (IsAtMost(24))

0 commit comments

Comments
 (0)