Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dnpatch/PatchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
Expand Down
12 changes: 10 additions & 2 deletions dnpatch/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions dnpatch/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down