From 2c28edee3f55193de7411a6e86d1ba8c7ddac6be Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:13:21 -0700 Subject: [PATCH] Improve type resolution for unstripping * Support PinnedTypeSignature * Support CustomModifierTypeSignature * Resolve nested types with the correct priority * Handle BoxedTypeSignature and FunctionPointerTypeSignature SentinelTypeSignature Function pointers and boxed types --- .../Passes/Pass80UnstripMethods.cs | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs b/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs index 76ecd6e0..3fce73fb 100644 --- a/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs +++ b/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs @@ -187,7 +187,7 @@ private static PropertyDefinition GetOrCreateProperty(MethodDefinition unityMeth if (unityType is ByReferenceTypeSignature) { var resolvedElementType = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); - return resolvedElementType == null ? null : new ByReferenceTypeSignature(resolvedElementType); + return resolvedElementType?.MakeByReferenceType(); } if (unityType is ArrayBaseTypeSignature arrayType) @@ -203,20 +203,25 @@ private static PropertyDefinition GetOrCreateProperty(MethodDefinition unityMeth return new GenericInstanceTypeSignature(genericBase.ToTypeDefOrRef(), false, resolvedElementType); } - if (unityType.DeclaringType != null) + if (unityType is PointerTypeSignature) { - var enclosingResolvedType = ResolveTypeInNewAssembliesRaw(context, unityType.DeclaringType.ToTypeSignature(), imports); - if (enclosingResolvedType == null) return null; - var resolvedNestedType = enclosingResolvedType.Resolve()!.NestedTypes - .FirstOrDefault(it => it.Name == unityType.Name); - - return resolvedNestedType?.ToTypeSignature(); + var resolvedElementType = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); + return resolvedElementType?.MakePointerType(); } - if (unityType is PointerTypeSignature) + if (unityType is PinnedTypeSignature) { var resolvedElementType = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); - return resolvedElementType?.MakePointerType(); + return resolvedElementType?.MakePinnedType(); + } + + if (unityType is CustomModifierTypeSignature customModifier) + { + var resolvedElementType = ResolveTypeInNewAssemblies(context, customModifier.BaseType, imports); + var resolvedModifierType = ResolveTypeInNewAssemblies(context, customModifier.ModifierType.ToTypeSignature(), imports); + return resolvedElementType is not null && resolvedModifierType is not null + ? new CustomModifierTypeSignature(resolvedModifierType.ToTypeDefOrRef(), customModifier.IsRequired, resolvedElementType) + : null; } if (unityType is GenericInstanceTypeSignature genericInstance) @@ -234,6 +239,25 @@ private static PropertyDefinition GetOrCreateProperty(MethodDefinition unityMeth return newInstance; } + if (unityType is BoxedTypeSignature) + return null; // Boxed types are not yet supported + + if (unityType is FunctionPointerTypeSignature) + return null; // Function pointers are not yet supported + + if (unityType is SentinelTypeSignature) + return unityType; // SentinelTypeSignature has no state and be reused. + + if (unityType.DeclaringType != null) + { + var enclosingResolvedType = ResolveTypeInNewAssembliesRaw(context, unityType.DeclaringType.ToTypeSignature(), imports); + if (enclosingResolvedType == null) return null; + var resolvedNestedType = enclosingResolvedType.Resolve()!.NestedTypes + .FirstOrDefault(it => it.Name == unityType.Name); + + return resolvedNestedType?.ToTypeSignature(); + } + var targetAssemblyName = unityType.Scope!.Name!; if (targetAssemblyName.EndsWith(".dll")) targetAssemblyName = targetAssemblyName.Substring(0, targetAssemblyName.Length - 4);