Esempio n. 1
0
        public string Read(ReadOnlyBitStream bitStream)
        {
            StringWriter output           = new StringWriter();
            uint         socketIdentifier = bitStream.ReadUInt32();
            bool         isHandshake      = socketIdentifier == 0;

            output.WriteLine("Is Handshake: " + isHandshake);
            output.WriteLine("Socket ID: " + socketIdentifier);

            if (isHandshake)
            {
                string messageIdentifier = "";

                for (int i = 0; i < 4; i++)
                {
                    messageIdentifier += (char)bitStream.ReadByte();
                }

                output.WriteLine("Message ID: " + messageIdentifier);

                if (handshakeStructs.ContainsKey(messageIdentifier))
                {
                    handshakeStructs[messageIdentifier].ReadFromBitStream(bitStream);
                    handshakeStructs[messageIdentifier].WriteToTextWriter(output);
                }
            }
            else
            {
                byte        channel     = bitStream.ReadCrumb();
                byte        resendCount = bitStream.ReadCrumb();
                bool        isSplit     = bitStream.ReadBit();
                Util.UInt11 length      = new Util.UInt11();

                length.ReadFromBitStream(bitStream);

                output.WriteLine("Channel: " + channel);
                output.WriteLine("Resend Count: " + resendCount);
                output.WriteLine("Is Split: " + isSplit);
                output.WriteLine("Length: " + length);

                if (channel == 0)
                {
                    byte messageIdentifier = bitStream.ReadByte();

                    output.Write("Message ID: " + messageIdentifier);

                    if (channel0Structs.ContainsKey(messageIdentifier))
                    {
                        Structure srct = channel0Structs[messageIdentifier];

                        output.WriteLine(" (" + srct.GetType().Name + ")");

                        srct.ReadFromBitStream(bitStream);
                        srct.WriteToTextWriter(output);
                    }
                }
            }

            if (bitStream.GetBitsUnread() > 0)
            {
                output.WriteLine();

                if (bitStream.GetBitsUnread() % 8 == 0)
                {
                    output.WriteLine("Unread Bytes:");
                    byte[] bytes = bitStream.ReadBytes(bitStream.GetBitsUnread() / 8);

                    for (int i = 0; i < bytes.Length; i++)
                    {
                        output.WriteLine(bytes[i]);
                    }
                }
                else
                {
                    output.WriteLine("Unread Bits:");

                    for (int i = 0; i < bitStream.GetBitsUnread(); i++)
                    {
                        output.WriteLine(bitStream.ReadBit() ? 1 : 0);
                    }
                }
            }

            return(output.ToString());
        }
Esempio n. 2
0
 public void ReadFromBitStream(ReadOnlyBitStream bitStream)
 {
     b1  = bitStream.ReadBit();
     b2  = bitStream.ReadBit();
     b3  = bitStream.ReadBit();
     b4  = bitStream.ReadBit();
     b5  = bitStream.ReadBit();
     b6  = bitStream.ReadBit();
     b7  = bitStream.ReadBit();
     b8  = bitStream.ReadBit();
     b9  = bitStream.ReadBit();
     b10 = bitStream.ReadBit();
     b11 = bitStream.ReadBit();
 }
        public void FromBitStream(ReadOnlyBitStream packetStream)
        {
            float positionX = packetStream.ReadSingle();
            float positionY = packetStream.ReadSingle();
            float positionZ = packetStream.ReadSingle();

            Position = new JVector(positionX, positionY, positionZ);

            float rotationX = packetStream.ReadSingle();
            float rotationY = packetStream.ReadSingle();
            float rotationZ = packetStream.ReadSingle();
            float rotationW = packetStream.ReadSingle();

            Rotation = new JQuaternion(rotationX, rotationY, rotationZ, rotationW);

            IsSupported = packetStream.ReadBit();
            IsOnRail    = packetStream.ReadBit();

            bool flag = packetStream.ReadBit();

            if (flag)
            {
                float linearVelocityX = packetStream.ReadSingle();
                float linearVelocityY = packetStream.ReadSingle();
                float linearVelocityZ = packetStream.ReadSingle();

                LinearVelocity = new JVector(linearVelocityX, linearVelocityY, linearVelocityZ);
            }

            flag = packetStream.ReadBit();

            if (flag)
            {
                float angularVelocityX = packetStream.ReadSingle();
                float angularVelocityY = packetStream.ReadSingle();
                float angularVelocityZ = packetStream.ReadSingle();

                AngularVelocity = new JVector(angularVelocityX, angularVelocityY, angularVelocityZ);
            }

            flag = packetStream.ReadBit();

            if (flag)
            {
                LocalSpaceObjectId = packetStream.ReadInt64();

                float localPositionX = packetStream.ReadSingle();
                float localPositionY = packetStream.ReadSingle();
                float localPositionZ = packetStream.ReadSingle();

                LocalPosition = new JVector(localPositionX, localPositionY, localPositionZ);

                flag = packetStream.ReadBit();

                if (flag)
                {
                    float localLinearVelocityX = packetStream.ReadSingle();
                    float localLinearVelocityY = packetStream.ReadSingle();
                    float localLinearVelocityZ = packetStream.ReadSingle();

                    LocalLinearVelocity = new JVector(localLinearVelocityX, localLinearVelocityY, localLinearVelocityZ);
                }
            }
        }