Skip to content

Commit

Permalink
fix: pack works if message is boxed
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Sep 26, 2019
1 parent 6dcea5f commit 55c9bb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Assets/Mirror/Runtime/MessagePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static class MessagePacker
return typeof(T).FullName.GetStableHashCode() & 0xFFFF;
}

public static int GetId(Type type)
{
return type.FullName.GetStableHashCode() & 0xFFFF;
}

// pack message before sending
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Use Pack<T> instead")]
public static byte[] PackMessage(int msgType, MessageBase msg)
Expand Down Expand Up @@ -54,7 +59,7 @@ public static byte[] PackMessage(int msgType, MessageBase msg)
try
{
// write message type
int msgType = GetId<T>();
int msgType = GetId(message.GetType());
writer.WriteUInt16((ushort)msgType);

// serialize message into writer
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader)
/// <returns></returns>
public bool InvokeHandler<T>(T msg) where T : IMessageBase
{
int msgType = MessagePacker.GetId<T>();
int msgType = MessagePacker.GetId(msg.GetType());
byte[] data = MessagePacker.Pack(msg);
return InvokeHandler(msgType, new NetworkReader(data));
}
Expand Down

0 comments on commit 55c9bb6

Please sign in to comment.