NetOutboundPacket[] SplitPacketIntoPartials(NetOutboundPacket packet) { packet.position = 0; // Calculate the number of packets to split it into, // and each of their sizes int numPackets = (int)Math.Ceiling((double)(packet.Length) / (MTU - 12)); int newPacketSize = MTU - 12; int packetChunkIndex = 0; ushort id = nextPartialId++; NetOutboundPacket[] partialPackets = new NetOutboundPacket[numPackets]; for (byte i = 0; i < numPackets; i++) { int packetSize = Math.Min(newPacketSize, packet.Length - packetChunkIndex); // Create the new partial NetOutboundPacket partial = packet.Clone(true); partial.isPartial = true; partial.Encrypt = false; partial.Compression = NetPacketCompression.None; partial.Clear(6 + packetSize); // Write the partial header partial.Write(id); partial.Write(i); partial.Write((byte)numPackets); partial.Write((ushort)packetSize); // Write the data allocated to this partial partial.WriteBytes(packet.ReadBytes(packetChunkIndex, packetSize)); // Add it to the list of partials partialPackets[i] = partial; packetChunkIndex += packetSize; } if (NetLogger.LogPartials) { NetLogger.LogVerbose("[Partial] Split Packet into {0} parts; Size: {1}b, Original Size: {2}b", numPackets, newPacketSize, packet.Length); } return(partialPackets); }