Skip to content

Commit

Permalink
Big fix - Variables were not copied corectly
Browse files Browse the repository at this point in the history
  • Loading branch information
reflection-emit committed Mar 30, 2017
1 parent a1fb4a0 commit 8206509
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Interception/Cauldron.Interception.Cecilator/InstructionsSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Method Copy(Modifiers modifiers, string newName)
method.GenericParameters.Add(item);

foreach (var item in this.method.methodDefinition.Body.Variables)
method.Body.Variables.Add(item);
method.Body.Variables.Add(new VariableDefinition(item.Name, item.VariableType));

method.Body.InitLocals = this.method.methodDefinition.Body.InitLocals;

Expand All @@ -146,8 +146,6 @@ public Method Copy(Modifiers modifiers, string newName)
var index = this.method.methodDefinition.Body.Instructions.IndexOf(operand?.Offset ?? item.Offset);
jumps.Add(new Tuple<int, int>(i, index));
this.LogInfo($"IL_{item.Offset.ToString("X4")}: {i} {index}");
var instruction = methodProcessor.Create(OpCodes.Nop);
instruction.OpCode = item.OpCode;
return instruction;
Expand Down Expand Up @@ -180,6 +178,11 @@ public Method Copy(Modifiers modifiers, string newName)
instruction.OpCode = item.OpCode;
instruction.Operand = item.Operand;
methodProcessor.Append(instruction);

// Set the correct variable def if required
var variable = instruction.Operand as VariableDefinition;
if (variable != null)
instruction.Operand = method.Body.Variables[variable.Index];
}
}

Expand All @@ -203,7 +206,7 @@ public Method Copy(Modifiers modifiers, string newName)
if (x == null)
return null;
var index = this.method.methodDefinition.Body.Instructions.IndexOf(x);
var index = this.method.methodDefinition.Body.Instructions.IndexOf(x.Offset);
return method.Body.Instructions[index];
});

Expand Down

0 comments on commit 8206509

Please sign in to comment.