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 property resolution during unstripping #169

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Il2CppInterop.Generator/Contexts/RewriteGlobalContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public AssemblyRewriteContext GetAssemblyByName(string name)
return null;
}

public TypeRewriteContext GetContextForNewType(TypeDefinition type)
{
return GetAssemblyByName(type.Module!.Assembly!.Name!).GetContextForNewType(type);
}

public MethodDefinition? CreateParamsMethod(MethodDefinition originalMethod, MethodDefinition newMethod,
RuntimeAssemblyReferences imports, Func<TypeSignature, TypeSignature?> resolve)
{
Expand Down
17 changes: 13 additions & 4 deletions Il2CppInterop.Generator/Utils/UnstripTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,27 @@ public static bool TranslateMethod(MethodDefinition original, MethodDefinition t
var fieldDeclarerDefinition = fieldDeclarer.Resolve();
if (fieldDeclarerDefinition == null)
return false;
var newField = fieldDeclarerDefinition.Fields.SingleOrDefault(it => it.Name == fieldArg.Name);

var fieldDeclarerContext = globalContext.GetContextForNewType(fieldDeclarerDefinition);
var propertyName = fieldDeclarerContext.Fields.SingleOrDefault(it => it.OriginalField.Name == fieldArg.Name)?.UnmangledName;

var newField = fieldDeclarerDefinition.Fields.SingleOrDefault(it => it.Name == fieldArg.Name)
?? fieldDeclarerDefinition.Fields.SingleOrDefault(it => it.Name == propertyName);
if (newField != null)
{
var newInstruction = targetBuilder.Add(bodyInstruction.OpCode, imports.Module.DefaultImporter.ImportField(newField));
instructionMap.Add(bodyInstruction, newInstruction);
}
else
{
if (bodyInstruction.OpCode == OpCodes.Ldfld || bodyInstruction.OpCode == OpCodes.Ldsfld)
if (propertyName == null)
{
return false;
}
else if (bodyInstruction.OpCode == OpCodes.Ldfld || bodyInstruction.OpCode == OpCodes.Ldsfld)
{
var getterMethod = fieldDeclarerDefinition.Properties
.SingleOrDefault(it => it.Name == fieldArg.Name)?.GetMethod;
.SingleOrDefault(it => it.Name == propertyName)?.GetMethod;
if (getterMethod == null)
return false;

Expand All @@ -126,7 +135,7 @@ public static bool TranslateMethod(MethodDefinition original, MethodDefinition t
else if (bodyInstruction.OpCode == OpCodes.Stfld || bodyInstruction.OpCode == OpCodes.Stsfld)
{
var setterMethod = fieldDeclarerDefinition.Properties
.SingleOrDefault(it => it.Name == fieldArg.Name)?.SetMethod;
.SingleOrDefault(it => it.Name == propertyName)?.SetMethod;
if (setterMethod == null)
return false;

Expand Down
Loading