diff --git a/Il2CppInterop.Runtime/Injection/ClassInjector.cs b/Il2CppInterop.Runtime/Injection/ClassInjector.cs index 28610d08..bc39672b 100644 --- a/Il2CppInterop.Runtime/Injection/ClassInjector.cs +++ b/Il2CppInterop.Runtime/Injection/ClassInjector.cs @@ -1110,7 +1110,42 @@ private static Type RewriteType(Type type) return type; } - + [Flags] + public enum Il2CppTypeNameOptions + { + None = 0, + Namespace = 1 << 0, + Name = 1 << 1, + Assembly = 1 << 2, + All = Namespace | Name | Assembly + } + internal static string GetTypeName(Type type, Il2CppTypeNameOptions options = Il2CppTypeNameOptions.All) + { + var assembly = type.Assembly; + var fullName = new StringBuilder(); + var names = new Stack(); + var outerType = type; + while (outerType.DeclaringType != null) + outerType = outerType.DeclaringType; + var namespaceName = outerType.Namespace ?? ""; + if (options.HasFlag(Il2CppTypeNameOptions.Namespace) && namespaceName.Length > 0) + { + fullName.Append(namespaceName); + fullName.Append('.'); + } + if (options.HasFlag(Il2CppTypeNameOptions.Name) && names.Count > 0) + fullName.Append(string.Join("+", names)); + if (options.HasFlag(Il2CppTypeNameOptions.Assembly)) + { + var assemblyName = assembly.FullName; + if (assemblyName != "mscorlib") + { + fullName.Append(", "); + fullName.Append(assemblyName); + } + } + return fullName.ToString(); + } // Could add same options to GetIl2CppTypeFullName too. private static string GetIl2CppTypeFullName(Il2CppTypeStruct* typePointer) { var klass = UnityVersionHandler.Wrap((Il2CppClass*)IL2CPP.il2cpp_class_from_type((IntPtr)typePointer)); diff --git a/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs b/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs index 568e6300..dfd32fcc 100644 --- a/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs +++ b/Il2CppInterop.Runtime/Injection/InjectorHelpers.cs @@ -91,9 +91,9 @@ internal static long CreateClassToken(IntPtr classPointer) internal static void AddTypeToLookup(IntPtr typePointer) where T : class => AddTypeToLookup(typeof(T), typePointer); internal static void AddTypeToLookup(Type type, IntPtr typePointer) { - string klass = type.Name; - if (klass == null) return; - string namespaze = type.Namespace ?? string.Empty; + string klass = ClassInjector.GetTypeName(type, ClassInjector.Il2CppTypeNameOptions.Name); + if (klass.Length == 0) return; + string namespaze = ClassInjector.GetTypeName(type, ClassInjector.Il2CppTypeNameOptions.Namespace); var attribute = Attribute.GetCustomAttribute(type, typeof(Il2CppInterop.Runtime.Attributes.ClassInjectionAssemblyTargetAttribute)) as Il2CppInterop.Runtime.Attributes.ClassInjectionAssemblyTargetAttribute; foreach (IntPtr image in (attribute is null) ? IL2CPP.GetIl2CppImages() : attribute.GetImagePointers())