Skip to content

Commit be52ffc

Browse files
slidedrumSlideDrum
andauthored
Added better support for nested classes in GetIl2CppTypeFullName method. (#233)
* Added better support for nested classes in GetIl2CppTypeFullName method. * Switched from a list to a stack. No more need to reverse the list. * Only add a . when namespacename exists. --------- Co-authored-by: SlideDrum <slidedrumofficial@gmail.com>
1 parent 769f080 commit be52ffc

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Il2CppInterop.Runtime/Injection/ClassInjector.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,24 +1115,22 @@ private static string GetIl2CppTypeFullName(Il2CppTypeStruct* typePointer)
11151115
{
11161116
var klass = UnityVersionHandler.Wrap((Il2CppClass*)IL2CPP.il2cpp_class_from_type((IntPtr)typePointer));
11171117
var assembly = UnityVersionHandler.Wrap(UnityVersionHandler.Wrap(klass.Image).Assembly);
1118-
11191118
var fullName = new StringBuilder();
1120-
1121-
var namespaceName = Marshal.PtrToStringUTF8(klass.Namespace);
1122-
if (!string.IsNullOrEmpty(namespaceName))
1123-
{
1124-
fullName.Append(namespaceName);
1125-
fullName.Append('.');
1126-
}
1127-
1119+
var names = new Stack<string>();
11281120
var declaringType = klass;
1129-
while ((declaringType = UnityVersionHandler.Wrap(declaringType.DeclaringType)) != default)
1121+
var outerType = klass;
1122+
do
11301123
{
1131-
fullName.Append(Marshal.PtrToStringUTF8(declaringType.Name));
1132-
fullName.Append('+');
1124+
names.Push(Marshal.PtrToStringUTF8(declaringType.Name) ?? "");
1125+
outerType = declaringType;
11331126
}
1127+
while ((declaringType = UnityVersionHandler.Wrap(declaringType.DeclaringType)) != default);
1128+
var namespaceName = outerType.Namespace != IntPtr.Zero ? Marshal.PtrToStringUTF8(outerType.Namespace) ?? "" : "";
11341129

1135-
fullName.Append(Marshal.PtrToStringUTF8(klass.Name));
1130+
fullName.Append(namespaceName);
1131+
if (namespaceName.Length > 0)
1132+
fullName.Append('.');
1133+
fullName.Append(string.Join("+", names));
11361134

11371135
var assemblyName = Marshal.PtrToStringUTF8(assembly.Name.Name);
11381136
if (assemblyName != "mscorlib")

0 commit comments

Comments
 (0)