Skip to content

Commit

Permalink
style: moving ProcessInstruction above methods it uses
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 28, 2024
1 parent ffd6bf6 commit f183d42
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions Assets/Mirage/Weaver/Processors/PropertySiteProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,48 @@ private static bool WeavedMethods(MethodDefinition md) =>
md.Name != NetworkBehaviourProcessor.ProcessedFunctionName &&
!md.IsConstructor;

private Instruction ProcessInstruction(MethodDefinition md, Instruction instr, SequencePoint sequencePoint)
{
if (instr.OpCode == OpCodes.Stfld && instr.Operand is FieldReference opFieldst)
{
FieldReference resolved = opFieldst.Resolve();
if (resolved == null)
{
resolved = opFieldst.DeclaringType.Resolve().GetField(opFieldst.Name);
}

// this instruction sets the value of a field. cache the field reference.
ProcessInstructionSetterField(instr, resolved);
}

if (instr.OpCode == OpCodes.Ldfld && instr.Operand is FieldReference opFieldld)
{
FieldReference resolved = opFieldld.Resolve();
if (resolved == null)
{
resolved = opFieldld.DeclaringType.Resolve().GetField(opFieldld.Name);
}

// this instruction gets the value of a field. cache the field reference.
ProcessInstructionGetterField(instr, resolved);
}

if (instr.OpCode == OpCodes.Ldflda && instr.Operand is FieldReference opFieldlda)
{
FieldReference resolved = opFieldlda.Resolve();
if (resolved == null)
{
resolved = opFieldlda.DeclaringType.Resolve().GetField(opFieldlda.Name);
}

// loading a field by reference, watch out for initobj instruction
// see https://github.com/vis2k/Mirror/issues/696
return ProcessInstructionLoadAddress(md, instr, resolved);
}

return instr;
}

// replaces syncvar write access with the NetworkXYZ.get property calls
private void ProcessInstructionSetterField(Instruction i, FieldReference opField)
{
Expand Down Expand Up @@ -68,48 +110,6 @@ private void ProcessInstructionGetterField(Instruction i, FieldReference opField
}
}

private Instruction ProcessInstruction(MethodDefinition md, Instruction instr, SequencePoint sequencePoint)
{
if (instr.OpCode == OpCodes.Stfld && instr.Operand is FieldReference opFieldst)
{
FieldReference resolved = opFieldst.Resolve();
if (resolved == null)
{
resolved = opFieldst.DeclaringType.Resolve().GetField(opFieldst.Name);
}

// this instruction sets the value of a field. cache the field reference.
ProcessInstructionSetterField(instr, resolved);
}

if (instr.OpCode == OpCodes.Ldfld && instr.Operand is FieldReference opFieldld)
{
FieldReference resolved = opFieldld.Resolve();
if (resolved == null)
{
resolved = opFieldld.DeclaringType.Resolve().GetField(opFieldld.Name);
}

// this instruction gets the value of a field. cache the field reference.
ProcessInstructionGetterField(instr, resolved);
}

if (instr.OpCode == OpCodes.Ldflda && instr.Operand is FieldReference opFieldlda)
{
FieldReference resolved = opFieldlda.Resolve();
if (resolved == null)
{
resolved = opFieldlda.DeclaringType.Resolve().GetField(opFieldlda.Name);
}

// loading a field by reference, watch out for initobj instruction
// see https://github.com/vis2k/Mirror/issues/696
return ProcessInstructionLoadAddress(md, instr, resolved);
}

return instr;
}

private Instruction ProcessInstructionLoadAddress(MethodDefinition md, Instruction instr, FieldReference opField)
{
// does it set a field that we replaced?
Expand Down

0 comments on commit f183d42

Please sign in to comment.