Skip to content

Commit

Permalink
Fix generated empty IL to be less dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Sep 6, 2020
1 parent 99f1aed commit 0857c37
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Cpp2IL/AssemblyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,24 @@ private static List<CppMethodData> ProcessTypeContents(Il2CppMetadata metadata,
if (methodDefinition.HasBody && ilTypeDefinition.BaseType?.FullName != "System.MulticastDelegate")
{
var ilprocessor = methodDefinition.Body.GetILProcessor();
ilprocessor.Append(ilprocessor.Create(OpCodes.Nop));
if (methodDefinition.ReturnType.FullName == "System.Void")
{
ilprocessor.Append(ilprocessor.Create(OpCodes.Ret));
}
else if (methodDefinition.ReturnType.IsValueType)
{
var variable = new VariableDefinition(methodDefinition.ReturnType);
methodDefinition.Body.Variables.Add(variable);
ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloca_S, variable));
ilprocessor.Append(ilprocessor.Create(OpCodes.Initobj, methodDefinition.ReturnType));
ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0));
ilprocessor.Append(ilprocessor.Create(OpCodes.Ret));
}
else
{
ilprocessor.Append(ilprocessor.Create(OpCodes.Ldnull));
ilprocessor.Append(ilprocessor.Create(OpCodes.Ret));
}
}

SharedState.MethodsByIndex.Add(methodId, methodDefinition);
Expand Down

0 comments on commit 0857c37

Please sign in to comment.