Skip to content

Commit 540425f

Browse files
committed
Add support for v39
1 parent 76b22e7 commit 540425f

5 files changed

Lines changed: 65 additions & 9 deletions

File tree

Il2CppDumper/IO/BinaryStream.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,40 @@ public GenericContainerIndex ReadGenericContainerIndex()
215215
}
216216
}
217217
}
218+
public ParameterIndex ReadParameterIndex()
219+
{
220+
if (Version < 39)
221+
{
222+
// Before Version 39, these were always Int32
223+
int value = ReadInt32();
224+
return new ParameterIndex(value);
225+
}
226+
else
227+
{
228+
switch (Metadata.parameterIndexSize)
229+
{
230+
case 1:
231+
{
232+
uint value = ReadByte();
233+
if (value == Byte.MaxValue) return new ParameterIndex(-1);
234+
return new ParameterIndex((int)value);
235+
}
236+
case 2:
237+
{
238+
uint value = ReadUInt16();
239+
if (value == UInt16.MaxValue) return new ParameterIndex(-1);
240+
return new ParameterIndex((int)value);
241+
}
242+
case 4:
243+
default:
244+
{
245+
uint value = ReadUInt32();
246+
if (value == UInt32.MaxValue) return new ParameterIndex(-1);
247+
return new ParameterIndex((int)value);
248+
}
249+
}
250+
}
251+
}
218252

219253
public T ReadClass<T>() where T : new()
220254
{
@@ -284,6 +318,10 @@ public GenericContainerIndex ReadGenericContainerIndex()
284318
{
285319
i.SetValue(t, ReadGenericContainerIndex());
286320
}
321+
else if (fieldType == typeof(ParameterIndex))
322+
{
323+
i.SetValue(t, ReadParameterIndex());
324+
}
287325
else if (fieldType == typeof(Il2CppSectionMetadata))
288326
{
289327
i.SetValue(t, ReadClass<Il2CppSectionMetadata>());

Il2CppDumper/Il2Cpp/Metadata.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class Metadata : BinaryStream
1818
public Il2CppParameterDefinition[] parameterDefs;
1919
public Il2CppFieldDefinition[] fieldDefs;
2020
private readonly Dictionary<int, Il2CppFieldDefaultValue> fieldDefaultValuesDic;
21-
private readonly Dictionary<int, Il2CppParameterDefaultValue> parameterDefaultValuesDic;
21+
private readonly Dictionary<ParameterIndex, Il2CppParameterDefaultValue> parameterDefaultValuesDic;
2222
public Il2CppPropertyDefinition[] propertyDefs;
2323
public Il2CppCustomAttributeTypeRange[] attributeTypeRanges;
2424
public Il2CppCustomAttributeDataRange[] attributeDataRanges;
@@ -46,6 +46,7 @@ public sealed class Metadata : BinaryStream
4646
public static int typeIndexSize;
4747
public static int typeDefinitionIndexSize;
4848
public static int genericContainerIndexSize;
49+
public static int parameterIndexSize;
4950

5051
public Metadata(Stream stream) : base(stream)
5152
{
@@ -59,7 +60,7 @@ public Metadata(Stream stream) : base(stream)
5960
{
6061
throw new InvalidDataException("ERROR: Metadata file supplied is not valid metadata file.");
6162
}
62-
if (version < 16 || version > 38)
63+
if (version < 16 || version > 39)
6364
{
6465
throw new NotSupportedException($"ERROR: Metadata file supplied is not a supported version[{version}].");
6566
}
@@ -102,13 +103,15 @@ public Metadata(Stream stream) : base(stream)
102103
typeIndexSize = sizeOfIl2CppParameterDefinition - 8;
103104
typeDefinitionIndexSize = GetIndexSize((int)header.typeDefinitions.count);
104105
genericContainerIndexSize = GetIndexSize((int)header.genericContainers.count);
106+
parameterIndexSize = GetIndexSize((int)header.parameters.count);
105107
}
106108
else
107109
{
108110
// Before version 38, these were always ints
109111
typeIndexSize = 4;
110112
typeDefinitionIndexSize = 4;
111113
genericContainerIndexSize = 4;
114+
parameterIndexSize = 4;
112115
}
113116

114117
imageDefs = Version < 38
@@ -251,7 +254,7 @@ public bool GetFieldDefaultValueFromIndex(int index, out Il2CppFieldDefaultValue
251254

252255
public bool GetParameterDefaultValueFromIndex(int index, out Il2CppParameterDefaultValue value)
253256
{
254-
return parameterDefaultValuesDic.TryGetValue(index, out value);
257+
return parameterDefaultValuesDic.TryGetValue(new ParameterIndex(index), out value);
255258
}
256259

257260
public uint GetDefaultValueFromIndex(int index)
@@ -385,6 +388,10 @@ public int SizeOf(Type type)
385388
{
386389
size += genericContainerIndexSize;
387390
}
391+
else if (fieldType == typeof(ParameterIndex))
392+
{
393+
size += parameterIndexSize;
394+
}
388395
else
389396
{
390397
size += SizeOf(fieldType);

Il2CppDumper/Il2Cpp/MetadataClass.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public class Il2CppMethodDefinition
385385
public TypeIndex returnType;
386386
[Version(Min = 31)]
387387
public int returnParameterToken;
388-
public int parameterStart;
388+
public ParameterIndex parameterStart;
389389
[Version(Max = 24)]
390390
public int customAttributeIndex;
391391
public GenericContainerIndex genericContainerIndex;
@@ -480,7 +480,7 @@ public class Il2CppStringLiteral
480480

481481
public class Il2CppParameterDefaultValue
482482
{
483-
public int parameterIndex;
483+
public ParameterIndex parameterIndex;
484484
public TypeIndex typeIndex;
485485
public int dataIndex;
486486
}
@@ -618,7 +618,16 @@ public static implicit operator int(GenericContainerIndex genericContainer)
618618
return genericContainer.value;
619619
}
620620
}
621-
622-
623-
621+
public class ParameterIndex : ICustomType
622+
{
623+
public int value;
624+
public ParameterIndex(int value)
625+
{
626+
this.value = value;
627+
}
628+
public static implicit operator int(ParameterIndex parameter)
629+
{
630+
return parameter.value;
631+
}
632+
}
624633
}

Il2CppDumper/Outputs/Il2CppDecompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ public void Decompile(Config config, string outputDir)
281281
}
282282
writer.Write($"{executor.GetTypeName(methodReturnType, false, false)} {methodName}(");
283283
var parameterStrs = new List<string>();
284-
for (var j = 0; j < methodDef.parameterCount; ++j)
284+
for (int j = 0; j < methodDef.parameterCount; ++j)
285285
{
286286
var parameterStr = "";
287+
287288
var parameterDef = metadata.parameterDefs[methodDef.parameterStart + j];
288289
var parameterName = metadata.GetStringFromIndex(parameterDef.nameIndex);
289290
var parameterType = il2Cpp.types[parameterDef.typeIndex];

Il2CppDumper/Outputs/StructGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ public void WriteScript(string outputDir)
421421
case 31:
422422
case 35:
423423
case 38:
424+
case 39:
424425
sb.Append(HeaderConstants.HeaderV29);
425426
break;
426427
default:

0 commit comments

Comments
 (0)