예제 #1
0
        private void MessageEvent()
        {
            if (!demo.ConvertNetworkProtocol())
            {
                parser.MessageEvent();
                return;
            }

            Int32 messageStartOffset = parser.BitBuffer.CurrentByte;

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

            BitWriter bitWriter = new BitWriter();
            HalfLifeDeltaStructure eventStructure = parser.GetDeltaStructure("event_t");

            UInt32 nEvents = parser.BitBuffer.ReadUnsignedBits(5);

            bitWriter.WriteUnsignedBits(nEvents, 5);

            for (Int32 i = 0; i < nEvents; i++)
            {
                UInt32 eventIndex = parser.BitBuffer.ReadUnsignedBits(10);
                bitWriter.WriteUnsignedBits(eventIndex, 10); // event index

                Boolean packetIndexBit = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(packetIndexBit);

                if (packetIndexBit)
                {
                    bitWriter.WriteUnsignedBits(parser.BitBuffer.ReadUnsignedBits(11), 11); // packet index

                    Boolean deltaBit = parser.BitBuffer.ReadBoolean();
                    bitWriter.WriteBoolean(deltaBit);

                    if (deltaBit)
                    {
                        HalfLifeDelta delta = eventStructure.CreateDelta();
                        Byte[]        bitmaskBytes;
                        eventStructure.ReadDelta(parser.BitBuffer, delta, out bitmaskBytes);

                        if (demo.Game != null)
                        {
                            demo.Game.ConvertEventCallback(demo, delta, eventIndex);
                        }

                        eventStructure.WriteDelta(bitWriter, delta, bitmaskBytes);
                    }
                }

                Boolean fireTimeBit = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(fireTimeBit);

                if (fireTimeBit)
                {
                    bitWriter.WriteUnsignedBits(parser.BitBuffer.ReadUnsignedBits(16), 16); // fire time
                }
            }

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

            // insert new message
            ReWriteMessage(messageStartOffset, bitWriter.Data);
        }