Пример #1
0
        private void MessageResourceList()
        {
            Int32 startByteIndex = parser.BitBuffer.CurrentByte;

            // read message
            if (demo.NetworkProtocol <= 43)
            {
                parser.BitBuffer.Endian = BitBuffer.EndianType.Big;
            }

            UInt32          nEntries     = parser.BitBuffer.ReadUnsignedBits(12);
            List <Resource> resourceList = new List <Resource>((Int32)nEntries);

            for (Int32 i = 0; i < nEntries; i++)
            {
                Resource r = new Resource();

                r.type     = parser.BitBuffer.ReadUnsignedBits(4);
                r.name     = parser.BitBuffer.ReadString();
                r.index    = parser.BitBuffer.ReadUnsignedBits(12);
                r.fileSize = parser.BitBuffer.ReadBits(24); // signed?
                r.flags    = parser.BitBuffer.ReadUnsignedBits(3);

                if ((r.flags & 4) != 0) // md5 hash (RES_CUSTOM?)
                {
                    r.md5Hash = parser.BitBuffer.ReadBytes(16);
                }

                r.hasReservedData = parser.BitBuffer.ReadBoolean();

                if (r.hasReservedData)
                {
                    r.reservedData = parser.BitBuffer.ReadBytes(32);
                }

                if (demo.Game == null || demo.Game.ConvertResourceListCallback(demo, r.type, r.index, ref r.name))
                {
                    resourceList.Add(r);
                }
            }

            // consistency list
            // indices of resources to force consistency upon?
            if (parser.BitBuffer.ReadBoolean())
            {
                while (parser.BitBuffer.ReadBoolean())
                {
                    Int32 nBits = (parser.BitBuffer.ReadBoolean() ? 5 : 10);
                    parser.BitBuffer.SeekBits(nBits);
                }
            }

            parser.BitBuffer.SkipRemainingBits();
            parser.BitBuffer.Endian = BitBuffer.EndianType.Little;

            // stop now if we're not converting network protocols
            if (!demo.ConvertNetworkProtocol())
            {
                return;
            }

            // create new message
            BitWriter bitWriter = new BitWriter();

            bitWriter.WriteUnsignedBits((UInt32)resourceList.Count, 12);

            foreach (Resource r in resourceList)
            {
                bitWriter.WriteUnsignedBits(r.type, 4);
                bitWriter.WriteString(r.name);
                bitWriter.WriteUnsignedBits(r.index, 12);
                bitWriter.WriteBits(r.fileSize, 24);
                bitWriter.WriteUnsignedBits(r.flags, 3);

                if ((r.flags & 4) != 0) // md5 hash
                {
                    bitWriter.WriteBytes(r.md5Hash);
                }

                bitWriter.WriteBoolean(r.hasReservedData);

                if (r.hasReservedData)
                {
                    bitWriter.WriteBytes(r.reservedData);
                }
            }

            bitWriter.WriteBoolean(false); // consistency list

            // remove old message
            Int32 endByteIndex = parser.BitBuffer.CurrentByte;

            parser.Seek(startByteIndex, SeekOrigin.Begin);
            parser.BitBuffer.RemoveBytes(endByteIndex - startByteIndex);

            // insert new message into bitbuffer
            parser.BitBuffer.InsertBytes(bitWriter.Data);
        }