Skip to content

Commit

Permalink
Improve type resolution for unstripping (#158)
Browse files Browse the repository at this point in the history
* Support PinnedTypeSignature
* Support CustomModifierTypeSignature
* Resolve nested types with the correct priority
* Handle BoxedTypeSignature and FunctionPointerTypeSignature

SentinelTypeSignature

Function pointers and boxed types
  • Loading branch information
ds5678 authored Sep 14, 2024
1 parent 4f47526 commit 89b8d31
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 89b8d31

Please sign in to comment.