public void Broadcast(IPCMessage msg) { using (MemoryStream stream = new MemoryStream()) { ISerializer serializer = _serializerResolver.GetSerializer(msg.GetType()); if (serializer == null) { return; } SerializationContext serializationContext = new SerializationContext(_serializerResolver); StreamWriter writer = new StreamWriter(stream) { Position = 0 }; writer.WriteUInt16(PacketPrefix); writer.WriteInt16(0); writer.WriteByte(_channelId); writer.WriteInt32(DynelManager.LocalPlayer.Identity.Instance); writer.WriteInt16(msg.Opcode); serializer.Serialize(writer, serializationContext, msg); long length = writer.Position; writer.Position = 2; writer.WriteInt16((short)length); writer.Dispose(); byte[] serialized = stream.ToArray(); _udpClient.Send(serialized, serialized.Length, _remoteEndPoint); } }
private void ProcessIPCMessage(byte[] msgBytes) { try { using (MemoryStream stream = new MemoryStream(msgBytes)) { StreamReader reader = new StreamReader(stream) { Position = 0 }; if (reader.ReadUInt16() != 0xFFFF) { return; } ushort len = reader.ReadUInt16(); if (len != msgBytes.Length) { return; } byte channelId = reader.ReadByte(); if (channelId != _channelId) { return; } int charId = reader.ReadInt32(); if (charId == Game.ClientInst) { return; } reader.Position = 2; TypeInfo subTypeInfo = _packetInspector.FindSubType(reader, out int opCode); if (subTypeInfo == null) { return; } var serializer = _serializerResolver.GetSerializer(subTypeInfo.Type); if (serializer == null) { return; } reader.Position = 11; SerializationContext serializationContext = new SerializationContext(_serializerResolver); IPCMessage message = (IPCMessage)serializer.Deserialize(reader, serializationContext); if (_callbacks.ContainsKey(opCode)) { _callbacks[opCode]?.Invoke(charId, message); } } } catch (Exception e) { //If you get this message and it concerns you please create an issue or contact me on Discord! Chat.WriteLine($"Failed to process IPC message {e.Message}"); } }