Skip to content

Commit

Permalink
Lib: Support v31.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Jun 24, 2024
1 parent 6b49552 commit 3d1cea6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cpp2IL.Core/Model/Contexts/MethodAnalysisContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class MethodAnalysisContext : HasCustomAttributesAndName, IMethodInfoProv

public int ParameterCount => Parameters.Count;

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

public MethodAnalysisContext(Il2CppMethodDefinition? definition, TypeAnalysisContext parent) : base(definition?.token ?? 0, parent.AppContext)
Expand Down
29 changes: 17 additions & 12 deletions LibCpp2IL/Metadata/Il2CppMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,15 @@ public class Il2CppMetadata : ClassReadingBinaryReader
}

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

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

float actualVersion;
if (version == 27)
{
if (unityVersion.GreaterThanOrEquals(2021, 1))
actualVersion = 27.2f; //2021.1 and up is v27.2, which just changes Il2CppType to have one new bit
else if (unityVersion.GreaterThanOrEquals(2020, 2, 4))
actualVersion = 27.1f; //2020.2.4 and above is v27.1
else
actualVersion = version; //2020.2 and above is v27
}
else if (version == 24)
if (version == 24)
{
if (unityVersion.GreaterThanOrEquals(2020, 1, 11))
actualVersion = 24.4f; //2020.1.11-17 were released prior to 2019.4.21, so are still on 24.4
Expand All @@ -104,6 +95,15 @@ public class Il2CppMetadata : ClassReadingBinaryReader
else
actualVersion = version; //2017.1.0 was the first v24 version
}
else if (version == 27)
{
if (unityVersion.GreaterThanOrEquals(2021, 1))
actualVersion = 27.2f; //2021.1 and up is v27.2, which just changes Il2CppType to have one new bit
else if (unityVersion.GreaterThanOrEquals(2020, 2, 4))
actualVersion = 27.1f; //2020.2.4 and above is v27.1
else
actualVersion = version; //2020.2 and above is v27
}
else if (version == 29)
{
if (unityVersion.GreaterThanOrEquals(2023, 2, 0, UnityVersionType.Alpha, 22))
Expand All @@ -112,6 +112,11 @@ public class Il2CppMetadata : ClassReadingBinaryReader
actualVersion = 29.1f; //2022.1.0b7 introduces v29.1 which adds two new pointers to codereg
else
actualVersion = 29; //2021.3.0 introduces v29
} else if (version == 31)
{
//2022.3.33 introduces v31. Unity why would you bump this on a minor version.
//Adds one new field (return type token) to method def
actualVersion = 31;
}
else actualVersion = version;

Expand Down
5 changes: 5 additions & 0 deletions LibCpp2IL/Metadata/Il2CppMethodDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Il2CppMethodDefinition : ReadableClass
public int nameIndex;
public int declaringTypeIdx;
public int returnTypeIdx;
[Version(Min = 31)] public uint returnParameterToken;
public int parameterStart;
[Version(Max = 24)] public int customAttributeIndex;
public int genericContainerIndex;
Expand Down Expand Up @@ -155,6 +156,10 @@ public override void Read(ClassReadingBinaryReader reader)

declaringTypeIdx = reader.ReadInt32();
returnTypeIdx = reader.ReadInt32();

if(IsAtLeast(31))
returnParameterToken = reader.ReadUInt32();

parameterStart = reader.ReadInt32();

if (IsAtMost(24))
Expand Down

0 comments on commit 3d1cea6

Please sign in to comment.