Skip to content

Commit

Permalink
fix(Weaver): avoiding short instructions for methods with unknown length
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Feb 7, 2022
1 parent eb74c4c commit f605c46
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirage/Weaver/Processors/AttributeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void InjectGuardParameters(MethodDefinition md, ILProcessor worker, Instr
VariableDefinition elementLocal = md.AddLocal(elementType);

worker.InsertBefore(top, worker.Create(OpCodes.Ldarg, index + offset));
worker.InsertBefore(top, worker.Create(OpCodes.Ldloca_S, elementLocal));
worker.InsertBefore(top, worker.Create(OpCodes.Ldloca, elementLocal));
worker.InsertBefore(top, worker.Create(OpCodes.Initobj, elementType));
worker.InsertBefore(top, worker.Create(OpCodes.Ldloc, elementLocal));
worker.InsertBefore(top, worker.Create(OpCodes.Stobj, elementType));
Expand All @@ -190,7 +190,7 @@ static void InjectGuardReturnValue(MethodDefinition md, ILProcessor worker, Inst
if (!md.ReturnType.Is(typeof(void)))
{
VariableDefinition returnLocal = md.AddLocal(md.ReturnType);
worker.InsertBefore(top, worker.Create(OpCodes.Ldloca_S, returnLocal));
worker.InsertBefore(top, worker.Create(OpCodes.Ldloca, returnLocal));
worker.InsertBefore(top, worker.Create(OpCodes.Initobj, md.ReturnType));
worker.InsertBefore(top, worker.Create(OpCodes.Ldloc, returnLocal));
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Weaver/Processors/SyncVarProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void WriteCallHookEvent(ILProcessor worker, EventDefinition @event, VariableDefi
worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Ldfld, eventField));
// jump to nop if null
worker.Append(worker.Create(OpCodes.Brfalse_S, nop));
worker.Append(worker.Create(OpCodes.Brfalse, nop));

worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Ldfld, eventField));
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Weaver/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static TypeReference ConvertToGenericIfNeeded(this TypeDefinition type)
}
}

public static FieldReference GetField(this TypeDefinition type, string fieldName)
public static FieldDefinition GetField(this TypeDefinition type, string fieldName)
{
if (type.HasFields)
{
Expand Down

0 comments on commit f605c46

Please sign in to comment.