-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Command and Rpc debugging information (#1551)
When replacing command and rpc methods, we now correctly move over the debugging information. Now you can put breakpoints in commands and Rpc Should fix #1550
- Loading branch information
Showing
5 changed files
with
74 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Mono.CecilX; | ||
using Mono.CecilX.Cil; | ||
|
||
namespace Mirror.Weaver | ||
{ | ||
public static class MethodProcessor | ||
{ | ||
|
||
// creates a method substitute | ||
// For example, if we have this: | ||
// public void CmdThrust(float thrusting, int spin) | ||
// { | ||
// xxxxx | ||
// } | ||
// | ||
// it will substitute the method and move the code to a new method with a provided name | ||
// for example: | ||
// | ||
// public void CmdTrust(float thrusting, int spin) | ||
// { | ||
// } | ||
// | ||
// public void <newName>(float thrusting, int spin) | ||
// { | ||
// xxxxx | ||
// } | ||
// | ||
// Note that all the calls to the method remain untouched | ||
// | ||
// the original method definition loses all code | ||
// this returns the newly created method with all the user provided code | ||
public static MethodDefinition SubstituteMethod(MethodDefinition md, string newName) | ||
{ | ||
MethodDefinition cmd = new MethodDefinition(newName,md.Attributes, md.ReturnType); | ||
|
||
// add parameters | ||
foreach (ParameterDefinition pd in md.Parameters) | ||
{ | ||
cmd.Parameters.Add(new ParameterDefinition(pd.Name, ParameterAttributes.None, pd.ParameterType)); | ||
} | ||
|
||
// swap bodies | ||
(cmd.Body, md.Body) = (md.Body, cmd.Body); | ||
|
||
// Move over all the debugging information | ||
foreach (SequencePoint sequencePoint in md.DebugInformation.SequencePoints) | ||
cmd.DebugInformation.SequencePoints.Add(sequencePoint); | ||
md.DebugInformation.SequencePoints.Clear(); | ||
|
||
foreach (CustomDebugInformation customInfo in md.CustomDebugInformations) | ||
cmd.CustomDebugInformations.Add(customInfo); | ||
md.CustomDebugInformations.Clear(); | ||
|
||
(md.DebugInformation.Scope, cmd.DebugInformation.Scope) = (cmd.DebugInformation.Scope, md.DebugInformation.Scope); | ||
|
||
return cmd; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirror/Editor/Weaver/Processors/MethodProcessor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters