Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type resolution for unstripping #158

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading