Beispiel #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;
        }