Fix short form jump issue, minor fix
This commit is contained in:
parent
d80028e8a8
commit
675b9886d5
|
@ -23,15 +23,51 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
|
||||||
public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
|
public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction)
|
||||||
{
|
{
|
||||||
// get method ref
|
// get method ref
|
||||||
|
bool rewritten = false;
|
||||||
|
// dynamic inserted instruction
|
||||||
|
if (instruction.Offset == 0 && instruction.Previous != null)
|
||||||
|
return false;
|
||||||
|
// rewrite does not insert instruction
|
||||||
|
if (!(instruction.Previous != null && instruction.Previous.Offset == 0
|
||||||
|
|| instruction.Next != null && instruction.Next.Offset == 0))
|
||||||
|
return false;
|
||||||
foreach (var ins in cil.Body.Instructions)
|
foreach (var ins in cil.Body.Instructions)
|
||||||
{
|
{
|
||||||
|
// dynamic inserted instruction
|
||||||
|
if(ins.Offset == 0)
|
||||||
|
continue;
|
||||||
OpCode targetOp = this.RewriteTarget(ins);
|
OpCode targetOp = this.RewriteTarget(ins);
|
||||||
|
// not a jump instruction
|
||||||
if (targetOp == OpCodes.Nop)
|
if (targetOp == OpCodes.Nop)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
Instruction insJumpTo = (Instruction) ins.Operand;
|
||||||
|
// jump forward
|
||||||
|
if (insJumpTo.Offset > ins.Offset)
|
||||||
|
{
|
||||||
|
// jump across the rewrite point
|
||||||
|
if(instruction.Offset > ins.Offset && instruction.Offset < insJumpTo.Offset)
|
||||||
|
{
|
||||||
// rewrite
|
// rewrite
|
||||||
ins.OpCode = targetOp;
|
ins.OpCode = targetOp;
|
||||||
|
rewritten = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// jump backward
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// jump across the rewrite point
|
||||||
|
if(instruction.Offset > insJumpTo.Offset && instruction.Offset < ins.Offset)
|
||||||
|
{
|
||||||
|
// rewrite
|
||||||
|
ins.OpCode = targetOp;
|
||||||
|
rewritten = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(rewritten)
|
||||||
return this.MarkRewritten();
|
return this.MarkRewritten();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue