diff --git a/dnpatch/PatchHelper.cs b/dnpatch/PatchHelper.cs index 601dec1..f94e557 100644 --- a/dnpatch/PatchHelper.cs +++ b/dnpatch/PatchHelper.cs @@ -77,6 +77,32 @@ public void PatchAndClear(Target target) } } + public void PatchAndInsert(Target target) + { + string[] nestedClasses = { }; + if (target.NestedClasses != null) + { + nestedClasses = target.NestedClasses; + } + else if (target.NestedClass != null) + { + nestedClasses = new[] { target.NestedClass }; + } + var type = FindType(target.Namespace + "." + target.Class, nestedClasses); + var method = FindMethod(type, target.Method, target.Parameters, target.ReturnType); + var instructions = method.Body.Instructions; + + if (target.Instructions != null && target.Indices != null) + { + for (int i = 0; i < target.Instructions.Length; i++) + { + instructions.Insert(target.Indices[i], target.Instructions[i]); + + } + } + + } + public void PatchOffsets(Target target) { string[] nestedClasses = { }; diff --git a/dnpatch/Patcher.cs b/dnpatch/Patcher.cs index ff0c0db..ecd0347 100644 --- a/dnpatch/Patcher.cs +++ b/dnpatch/Patcher.cs @@ -49,7 +49,11 @@ public void Patch(Target target) if ((target.Indices != null || target.Index != -1) && (target.Instruction != null || target.Instructions != null)) { - _patcher.PatchOffsets(target); + if (target.InsertInstructions) + _patcher.PatchAndInsert(target); + + else + _patcher.PatchOffsets(target); } else if ((target.Index == -1 && target.Indices == null) && (target.Instruction != null || target.Instructions != null)) @@ -69,7 +73,11 @@ public void Patch(Target[] targets) if ((target.Indices != null || target.Index != -1) && (target.Instruction != null || target.Instructions != null)) { - _patcher.PatchOffsets(target); + if (target.InsertInstructions) + _patcher.PatchAndInsert(target); + + else + _patcher.PatchOffsets(target); } else if ((target.Index == -1 && target.Indices == null) && (target.Instruction != null || target.Instructions != null)) diff --git a/dnpatch/Target.cs b/dnpatch/Target.cs index b62d079..48f0540 100644 --- a/dnpatch/Target.cs +++ b/dnpatch/Target.cs @@ -48,6 +48,11 @@ public partial class Target public Instruction Instruction { get; set; } } + public partial class Target + { + public bool InsertInstructions { get; set; } = false; + } + public partial class Target { public string[] NestedClasses { get; set; }