/// <summary> /// Send a string to players or a player in the lobby /// </summary> /// <param name="objectToSend">string message to send. Can be JSON</param> /// <param name="peerId">The id of the peer you want the message to go to. Leave null if you want to send to all players</param> /// <param name="code">Coop code used to distinguish this message from others. Like a lock and key for reading messages</param> public static void SendMessage(this NKMultiGameInterface nkGI, Il2CppSystem.String objectToSend, byte?peerId = null, string code = "") { Message message = MessageUtils.CreateMessage(objectToSend, code); if (peerId.HasValue && peerId != null) { nkGI.SendToPeer(peerId.Value, message); } else { nkGI.relayConnection.Writer.Write(message); } }
/// <summary> /// Send a string to players or a player in the lobby /// </summary> /// <param name="objectToSend">string message to send. Can be JSON</param> /// <param name="peerId">The id of the peer you want the message to go to. Leave null if you want to send to all players</param> /// <param name="code">Coop code used to distinguish this message from others. Like a lock and key for reading messages</param> public static void SendMessage(this NKMultiGameInterface nkGI, Il2CppSystem.String objectToSend, byte?peerId = null, string code = "") { Message message = MessageUtils.CreateMessage(objectToSend, code); var str = Il2CppSystem.Text.Encoding.Default.GetString(message.bytes); MelonLoader.MelonLogger.Msg($"str: {str}"); if (peerId.HasValue && peerId != null) { nkGI.SendToPeer(peerId.Value, message); } else { nkGI.relayConnection.Writer.Write(message); } }