Skip to content

Commit

Permalink
fix: adding sequence point to hookException
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed May 25, 2022
1 parent d485a25 commit 47ec337
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Assets/Mirage/Weaver/MethodExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Mono.Cecil;
using Mono.Cecil.Cil;
Expand Down Expand Up @@ -66,5 +67,12 @@ public static SequencePoint GetSequencePoint(this MethodDefinition method, Instr
SequencePoint sequencePoint = method.DebugInformation.GetSequencePoint(instruction);
return sequencePoint;
}

public static SequencePoint GetFirstSequencePoint(this MethodDefinition method)
{
Instruction firstInstruction = method.Body.Instructions.First();
SequencePoint sequencePoint = method.DebugInformation.GetSequencePoint(firstInstruction);
return sequencePoint;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static SyncVarHook ValidateMethod(FieldDefinition syncVar, string hookFu
}

// else throw saying args were wrong
throw new HookMethodException($"Wrong type for Parameter in hook for '{syncVar.Name}', hook name '{hookFunctionName}'.", syncVar);
throw new HookMethodException($"Wrong type for Parameter in hook for '{syncVar.Name}', hook name '{hookFunctionName}'.", syncVar, methods.First());
}

private static SyncVarHook FindEvent1Arg(FieldDefinition syncVar, string hookFunctionName, TypeReference originalType)
Expand Down
2 changes: 2 additions & 0 deletions Assets/Mirage/Weaver/WeaverExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal class NetworkBehaviourException : WeaverException
internal class SyncVarException : WeaverException
{
public SyncVarException(string message, MemberReference memberReference) : base(message, memberReference, null) { }
public SyncVarException(string message, MemberReference memberReference, SequencePoint sequencePoint) : base(message, memberReference, sequencePoint) { }
}

internal class RpcException : WeaverException
Expand All @@ -66,6 +67,7 @@ namespace Mirage.Weaver.SyncVars
internal class HookMethodException : SyncVarException
{
public HookMethodException(string message, MemberReference memberReference) : base(message, memberReference) { }
public HookMethodException(string message, MemberReference memberReference, MethodDefinition method) : base(message, memberReference, method.GetFirstSequencePoint()) { }
}
}

Expand Down

0 comments on commit 47ec337

Please sign in to comment.