Esempio n. 1
0
        private bool ProcessTick()
        {
            DemoCommand demoCommand = (DemoCommand)m_BitStream.ReadByte();

            int tickNumber = m_BitStream.ReadInt32();
            int playerSlot = m_BitStream.ReadByte();

            switch (demoCommand)
            {
                case DemoCommand.DataTables:
                    {
                        int length = m_BitStream.ReadInt32();
                        byte[] data = m_BitStream.ReadBytes(length);

                        BitStream bitStream = new BitStream(data);

                        while (true)
                        {
                            int dataTableType = bitStream.ReadVarint32();
                            int dataTablelength = bitStream.ReadVarint32();
                            byte[] dataTableData = bitStream.ReadBytes(dataTablelength);

                            DataTable dataTable = new DataTable(this.DataTables.Count, dataTableData);

                            if (dataTable.IsEnd)
                            {
                                break;
                            }
                            else
                            {
                                this.DataTables.Add(dataTable);
                            }
                        }

                        int count = bitStream.ReadShort();

                        for (int i = 0; i < count; i++)
                        {
                            int serverClassID = bitStream.ReadShort();
                            string serverClassName = bitStream.ReadString();
                            string dataTableName = bitStream.ReadString();

                            DataTable dataTable = this.DataTables.GetDataTable(dataTableName);

                            ServerClass serverClass = new ServerClass(serverClassID, serverClassName, dataTable.ID, dataTable.Name);

                            this.ServerClasses.Add(serverClass);
                        }

                        this.ServerClasses.ProcessAllServerClasses();

                        break;
                    }
                case DemoCommand.Packet:
                case DemoCommand.SignOn:
                    {
                        m_BitStream.SeekBytes(160, SeekOrigin.Current);

                        int length = m_BitStream.ReadInt32();
                        byte[] data = m_BitStream.ReadBytes(length);

                        BitStream packetReader = new BitStream(data);

                        while (packetReader.PositionInBytes < packetReader.LengthInBytes)
                        {
                            int packetID = packetReader.ReadVarint32();
                            int packetLength = packetReader.ReadVarint32();
                            byte[] packetData = packetReader.ReadBytes(packetLength);

                            PacketType packetType;

                            if (!Enum.TryParse<PacketType>(packetID.ToString(), out packetType))
                            {
                                Console.WriteLine("Unknown Packet Type: {0}", packetID);

                                break;
                            }

                            this.PacketHandlers.OnPacketReceived(packetType, packetData);
                        }

                        break;
                    }
                case DemoCommand.Stop:
                    {
                        return true;
                    }
                case DemoCommand.StringTables:
                    {
                        int length = m_BitStream.ReadInt32();
                        byte[] data = m_BitStream.ReadBytes(length);

                        BitStream bitStream = new BitStream(data);

                        int stringTableCount = bitStream.ReadByte();

                        for (int i = 0; i < stringTableCount; i++)
                        {
                            string stringTableName = bitStream.ReadString();

                            int entryCount = bitStream.ReadUShort();

                            for (int j = 0; j < entryCount; j++)
                            {
                                string entryName = bitStream.ReadString();
                                bool entryHasData = bitStream.ReadBit();

                                byte[] entryData = null;

                                if (entryHasData)
                                {
                                    int entryDataLength = bitStream.ReadShort();

                                    entryData = bitStream.ReadBytes(entryDataLength);
                                }

                                StringTableEntry stringTableEntry = new StringTableEntry(entryName, entryData);

                                this.StringTables.Add(stringTableName, stringTableEntry);
                            }

                            bool hasExtraTableData = bitStream.ReadBit();

                            if (hasExtraTableData)
                            {
                                int extraTableDataLength = bitStream.ReadShort();
                                byte[] extraTableData = bitStream.ReadBytes(extraTableDataLength);
                            }
                        }

                        break;
                    }
                case DemoCommand.SyncTick:
                    {
                        break;
                    }

                default:
                    {
                        Console.WriteLine("Unknown Demo Command: {0}", demoCommand);

                        break;
                    }
            }

            return false;
        }
Esempio n. 2
0
 private int ReadInt32(BitStream bitStream, DataTableProperty dataTableProperty)
 {
     if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.Varint))
     {
         if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.Unsigned))
         {
             return (int)bitStream.ReadVarint32();
         }
         else
         {
             return (int)bitStream.ReadVarint32();
         }
     }
     else
     {
         if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.Unsigned))
         {
             return (int)bitStream.ReadBits(dataTableProperty.NumberOfBits);
         }
         else
         {
             return (int)bitStream.ReadBits(dataTableProperty.NumberOfBits);
         }
     }
 }
Esempio n. 3
0
        public ProtoMessage(byte[] protoMessageData)
        {
            this.Values = new Dictionary<String, List<Object>>();

            BitStream bitStream = new BitStream(protoMessageData);

            while ((bitStream.PositionInBytes) < bitStream.LengthInBytes)
            {
                int key = bitStream.ReadVarint32();

                int fieldNumber = key >> 3;
                int wireType = key & 7;

                object value = null;

                switch (wireType)
                {
                    case 0:
                        {
                            value = bitStream.ReadVarint32();

                            break;
                        }
                    case 1:
                        {
                            Console.WriteLine("ProtoMessage WireType 1");

                            bitStream.SeekBytes(0, SeekOrigin.End);

                            break;
                        }
                    case 2:
                        {
                            int length = bitStream.ReadVarint32();

                            byte[] buffer = bitStream.ReadBytes(length);

                            value = buffer;

                            break;
                        }
                    case 5:
                        {
                            value = bitStream.ReadFloat();

                            break;
                        }

                    default:
                        {
                            Console.WriteLine("Unknown ProtoMessage WireType: {0}", wireType);

                            bitStream.SeekBytes(0, SeekOrigin.End);

                            return;
                        }
                }

                if (value != null)
                {
                    List<Object> fieldValues;

                    if (this.Values.TryGetValue(fieldNumber.ToString(), out fieldValues))
                    {
                        fieldValues.Add(value);
                    }
                    else
                    {
                        fieldValues = new List<Object>();

                        fieldValues.Add(value);

                        this.Values.Add(fieldNumber.ToString(), fieldValues);
                    }
                }
            }
        }