Skip to content

Commit

Permalink
Merge pull request #17 from 18107/master
Browse files Browse the repository at this point in the history
Fixed operand check and debug output
  • Loading branch information
TomRichter authored Jan 13, 2019
2 parents cfeaefe + 2c0bf13 commit 8cd1519
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions PulsarPluginLoader/Patches/HarmonyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public static IEnumerable<CodeInstruction> PatchBySequence(IEnumerable<CodeInstr

for (int i = 0; i < newInstructions.Count; i++)
{
bool startsWithTargetInstruction = newInstructions[i].opcode.Equals(targetStart.opcode);
bool targetSequenceStillFits = i + targetSize <= newInstructions.Count;

if (startsWithTargetInstruction && targetSequenceStillFits)
if (targetSequenceStillFits)
{
bool foundTargetSequence = true;

for (int x = 1; x < targetSize && foundTargetSequence; x++)
for (int x = 0; x < targetSize && foundTargetSequence; x++)
{
foundTargetSequence = newInstructions[i + x].opcode.Equals(targetSequence.ElementAt(x).opcode)
&& (!checkOperands || (
Expand Down Expand Up @@ -56,23 +55,24 @@ public static IEnumerable<CodeInstruction> PatchBySequence(IEnumerable<CodeInstr

break;
}
else if (!targetSequenceStillFits)
{
StringBuilder sb = new StringBuilder();

sb.AppendLine($"Failed to patch by sequence: couldn't find target sequence. This might be okay in certain cases.");
}
else
{
StringBuilder sb = new StringBuilder();

// Cut down the stack trace because it's 20 lines of unhelpful reflection internals.
// Show enough to figure out which plugin + transpiler method is causing this:
sb.AppendLine($"Stack Trace:");
string[] stackTrace = new System.Diagnostics.StackTrace().ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
for (int lineNumber = 0; lineNumber < 2; lineNumber++)
{
sb.AppendLine(stackTrace[lineNumber]);
}
sb.AppendLine($"Failed to patch by sequence: couldn't find target sequence. This might be okay in certain cases.");

Logger.Info(sb.ToString());
// Cut down the stack trace because it's 20 lines of unhelpful reflection internals.
// Show enough to figure out which plugin + transpiler method is causing this:
sb.AppendLine($"Stack Trace:");
string[] stackTrace = new System.Diagnostics.StackTrace().ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
for (int lineNumber = 0; lineNumber < 2; lineNumber++)
{
sb.AppendLine(stackTrace[lineNumber]);
}

Logger.Info(sb.ToString());
break;
}
}

Expand Down

0 comments on commit 8cd1519

Please sign in to comment.