Skip to content

Commit

Permalink
feat: names for mirror rpcs (#5)
Browse files Browse the repository at this point in the history

* Added full name, asome low tech method fix
  • Loading branch information
GoToNightmare authored Sep 8, 2022
1 parent e5b09b8 commit 6bd5fa5
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions Assets/Mirage.Profiler/Runtime/NetworkInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Text.RegularExpressions;
using Mirror;
using Mirror.RemoteCalls;
using UnityEngine;
using UnityEngine.Assertions;

namespace Mirage.NetworkProfiler
{
Expand Down Expand Up @@ -61,18 +65,37 @@ public string GetRpcName(NetworkDiagnostics.MessageInfo info)
}
}

private string GetRpcName(uint netId, int componentIndex, int functionIndex)
private string GetRpcName(uint netId, int componentIndex, ushort functionIndex)
{
// todo find out if there is way to get this in mirror
ushort hash = functionIndex;
var remoteCallDelegate = RemoteProcedureCalls.GetDelegate(hash);
if (remoteCallDelegate != null)
{
string fixedMethodName = MirrorMethodNameTrimmer.FixMethodName(remoteCallDelegate.Method.Name);
string methodFullName = $"{remoteCallDelegate.Method.DeclaringType?.FullName}.{fixedMethodName}";
return methodFullName;
}

// todo some error maybe
return string.Empty;
}


/// <summary>
/// Some stuff from Mirror.Weaver
/// </summary>
private static class MirrorMethodNameTrimmer
{
private static readonly Regex regex1 = new Regex($"^InvokeUserCode_", RegexOptions.Compiled);
private static readonly Regex regex2 = new Regex("__[A-Z][\\w`]*$", RegexOptions.Compiled);

//var identity = GetNetworkIdentity(netId);
//if (identity == null)
// return string.Empty;
public static string FixMethodName(string methodName)
{
methodName = regex1.Replace(methodName, "");
methodName = regex2.Replace(methodName, "");

//var behaviour = identity.NetworkBehaviours[componentIndex];
//var rpc = behaviour.RemoteCallCollection.Get(functionIndex);
//return rpc.name;
return methodName;
}
}
}
}

0 comments on commit 6bd5fa5

Please sign in to comment.