public static MinimumAvatarPacket BufferToPacket(byte[] buf)
        {
            if (buf == null || buf.Length != 31)
            {
                return(null);
            }
            var offset = sizeof(float);
            var userId = BitConverter.ToUInt64(buf, offset);
            var x      = BitConverter.ToInt16(buf, offset += sizeof(long));
            var y      = BitConverter.ToInt16(buf, offset += sizeof(short));
            var z      = BitConverter.ToInt16(buf, offset += sizeof(short));

            offset += sizeof(short);
            var radY = (sbyte)buf[offset];
            var qx   = (sbyte)buf[offset + 1];
            var qy   = (sbyte)buf[offset + 2];
            var qz   = (sbyte)buf[offset + 3];
            var qw   = (sbyte)buf[offset + 4];
            var time = BitConverter.ToDouble(buf, offset + 5);
            MinimumAvatarPacket packet =
                new MinimumAvatarPacket(userId, new Vector3(x, y, z), radY,
                                        new Vector4(qx, qy, qz, qw), time);

            if (packet.CheckRange())
            {
                return(packet);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
 public static List <MinimumAvatarPacket> BufferToPackets(byte[] buf)
 {
     if (buf != null && buf.Length > 0)
     {
         var numPackets      = BitConverter.ToInt32(buf, 0);
         var supposedBufSize = numPackets * 48 + 16;
         if (buf.Length == supposedBufSize)
         {
             List <MinimumAvatarPacket> packets = new List <MinimumAvatarPacket>();
             for (int i = 0; i < numPackets; ++i)
             {
                 var    beginOffset = i * 48;
                 var    idLen       = buf[16 + beginOffset];
                 byte[] bStr        = new byte[idLen];
                 Buffer.BlockCopy(buf, 16 + 1 + beginOffset, bStr, 0, idLen);
                 var userId = System.Text.Encoding.UTF8.GetString(bStr);
                 var x      = BitConverter.ToSingle(buf, 32 + beginOffset);
                 var y      = BitConverter.ToSingle(buf, 32 + sizeof(float) + beginOffset);
                 var z      = BitConverter.ToSingle(buf, 32 + sizeof(float) * 2 + beginOffset);
                 var radY   = BitConverter.ToSingle(buf, 32 + sizeof(float) * 3 + beginOffset);
                 var qx     = BitConverter.ToSingle(buf, 48 + beginOffset);
                 var qy     = BitConverter.ToSingle(buf, 48 + sizeof(float) + beginOffset);
                 var qz     = BitConverter.ToSingle(buf, 48 + sizeof(float) * 2 + beginOffset);
                 var qw     = BitConverter.ToSingle(buf, 48 + sizeof(float) * 3 + beginOffset);
                 MinimumAvatarPacket packet = new MinimumAvatarPacket(userId, new Vector3(x, y, z), radY, new Vector4(qx, qy, qz, qw));
                 packets.Add(packet);
             }
             return(packets);
         }
     }
     return(null);
 }
示例#3
0
        public static byte[] PacketToBuffer(MinimumAvatarPacket packet)
        {
            byte[] buff       = new byte[64];
            var    numPackets = BitConverter.GetBytes(1);

            Buffer.BlockCopy(numPackets, 0, buff, 0, sizeof(int));
            var beginOffset = 0;
            var id          = System.Text.Encoding.UTF8.GetBytes(packet.PaketId);
            var bx          = BitConverter.GetBytes(packet.Position.X);
            var by          = BitConverter.GetBytes(packet.Position.Y);
            var bz          = BitConverter.GetBytes(packet.Position.Z);
            var bRadY       = BitConverter.GetBytes(packet.RadY);
            var bQx         = BitConverter.GetBytes(packet.NeckRotation.X);
            var bQy         = BitConverter.GetBytes(packet.NeckRotation.Y);
            var bQz         = BitConverter.GetBytes(packet.NeckRotation.Z);
            var bQw         = BitConverter.GetBytes(packet.NeckRotation.W);

            buff[16] = (byte)id.Length;
            Buffer.BlockCopy(id, 0, buff, 16 + 1, id.Length);
            Buffer.BlockCopy(bx, 0, buff, 32, sizeof(float));
            Buffer.BlockCopy(by, 0, buff, 32 + sizeof(float), sizeof(float));
            Buffer.BlockCopy(bz, 0, buff, 32 + sizeof(float) * 2, sizeof(float));
            Buffer.BlockCopy(bRadY, 0, buff, 32 + sizeof(float) * 3, sizeof(float));
            Buffer.BlockCopy(bQx, 0, buff, 48, sizeof(float));
            Buffer.BlockCopy(bQy, 0, buff, 48 + sizeof(float), sizeof(float));
            Buffer.BlockCopy(bQz, 0, buff, 48 + sizeof(float) * 2, sizeof(float));
            Buffer.BlockCopy(bQw, 0, buff, 48 + sizeof(float) * 3, sizeof(float));
            return(buff);
        }
        public static List <MinimumAvatarPacket> BufferToPackets(byte[] buf)
        {
            if (buf != null && buf.Length > 0)
            {
                int begin           = sizeof(float);
                var numPackets      = BitConverter.ToInt32(buf, 0);
                var supposedBufSize = numPackets * 27 + begin;
                if (buf.Length == supposedBufSize)
                {
                    List <MinimumAvatarPacket> packets = new List <MinimumAvatarPacket>();
                    for (int i = 0; i < numPackets; ++i)
                    {
                        var offset = begin + i * 27;
                        var userId = BitConverter.ToUInt64(buf, offset);
                        var x      = BitConverter.ToInt16(buf, offset += sizeof(long));
                        var y      = BitConverter.ToInt16(buf, offset += sizeof(short));
                        var z      = BitConverter.ToInt16(buf, offset += sizeof(short));
                        offset += sizeof(short);
                        var radY = (sbyte)buf[offset];
                        var qx   = (sbyte)buf[offset + 1];
                        var qy   = (sbyte)buf[offset + 2];
                        var qz   = (sbyte)buf[offset + 3];
                        var qw   = (sbyte)buf[offset + 4];
                        var time = BitConverter.ToDouble(buf, offset + 5);
                        MinimumAvatarPacket packet = new MinimumAvatarPacket(userId, new Vector3(x, y, z),
                                                                             radY,
                                                                             new Vector4(qx, qy, qz, qw), time);
                        if (packet.CheckRange())
                        {
                            packets.Add(packet);
                        }
                    }

                    return(packets);
                }
            }


            return(null);
        }
示例#5
0
        public static MinimumAvatarPacket BufferToPacket(byte[] buf)
        {
            if (buf == null || buf.Length != 64)
            {
                return(null);
            }
            var idLen = buf[16];

            byte[] bStr = new byte[idLen];
            Buffer.BlockCopy(buf, 16 + 1, bStr, 0, idLen);
            var userId = System.Text.Encoding.UTF8.GetString(bStr);
            var x      = BitConverter.ToSingle(buf, 32);
            var y      = BitConverter.ToSingle(buf, 32 + sizeof(float));
            var z      = BitConverter.ToSingle(buf, 32 + sizeof(float) * 2);
            var radY   = BitConverter.ToSingle(buf, 32 + sizeof(float) * 3);
            var qx     = BitConverter.ToSingle(buf, 48);
            var qy     = BitConverter.ToSingle(buf, 48 + sizeof(float));
            var qz     = BitConverter.ToSingle(buf, 48 + sizeof(float) * 2);
            var qw     = BitConverter.ToSingle(buf, 48 + sizeof(float) * 3);
            MinimumAvatarPacket packet = new MinimumAvatarPacket(userId, new Vector3(x, y, z), radY, new Vector4(qx, qy, qz, qw));

            return(packet);
        }