Skip to content

Commit be9f65d

Browse files
committed
修复错误的虚函数表
1 parent 25b5c22 commit be9f65d

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Il2CppDumper/Outputs/StructGenerator.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,21 @@ private void AddVTableMethod(StructInfo structInfo, Il2CppTypeDefinition typeDef
618618
{
619619
methodDef = metadata.methodDefs[index];
620620
}
621-
dic[methodDef.slot] = methodDef;
621+
if (methodDef.slot != ushort.MaxValue)
622+
{
623+
dic[methodDef.slot] = methodDef;
624+
}
622625
}
623-
foreach (var i in dic)
626+
if (typeDef.vtable_count > 0)
624627
{
625-
var methodInfo = new StructVTableMethodInfo();
626-
structInfo.VTableMethod.Add(methodInfo);
627-
var methodDef = i.Value;
628-
methodInfo.MethodName = $"_{methodDef.slot}_{FixName(metadata.GetStringFromIndex(methodDef.nameIndex))}";
628+
structInfo.VTableMethod = new StructVTableMethodInfo[dic.Last().Key + 1];
629+
foreach (var i in dic)
630+
{
631+
var methodInfo = new StructVTableMethodInfo();
632+
structInfo.VTableMethod[i.Key] = methodInfo;
633+
var methodDef = i.Value;
634+
methodInfo.MethodName = $"{FixName(metadata.GetStringFromIndex(methodDef.nameIndex))}";
635+
}
629636
}
630637
}
631638

@@ -842,9 +849,19 @@ private string RecursionStructInfo(StructInfo info)
842849
sb.Append("};\n");
843850

844851
sb.Append($"struct {info.TypeName}_VTable {{\n");
845-
foreach (var method in info.VTableMethod)
852+
for (int i = 0; i < info.VTableMethod.Length; i++)
846853
{
847-
sb.Append($"\tVirtualInvokeData {method.MethodName};\n");
854+
sb.Append($"\tVirtualInvokeData _{i}_");
855+
var method = info.VTableMethod[i];
856+
if (method != null)
857+
{
858+
sb.Append(method.MethodName);
859+
}
860+
else
861+
{
862+
sb.Append("unknown");
863+
}
864+
sb.Append(";\n");
848865
}
849866
sb.Append("};\n");
850867

Il2CppDumper/Outputs/StructInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace Il2CppDumper
45
{
@@ -9,7 +10,7 @@ public class StructInfo
910
public string Parent;
1011
public List<StructFieldInfo> Fields = new List<StructFieldInfo>();
1112
public List<StructFieldInfo> StaticFields = new List<StructFieldInfo>();
12-
public List<StructVTableMethodInfo> VTableMethod = new List<StructVTableMethodInfo>();
13+
public StructVTableMethodInfo[] VTableMethod = Array.Empty<StructVTableMethodInfo>();
1314
public List<StructRGCTXInfo> RGCTXs = new List<StructRGCTXInfo>();
1415
}
1516

0 commit comments

Comments
 (0)