private void MessagePacketEntities()
        {
            if (!demo.ConvertNetworkProtocol())
            {
                parser.MessagePacketEntities();
                return;
            }

            Int32 messageStartOffset = parser.BitBuffer.CurrentByte;
            BitWriter bitWriter = new BitWriter();

            // read message into new message
            bitWriter.WriteUInt16(parser.BitBuffer.ReadUInt16()); // nEntities/maxEntities

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

            UInt32 entityNumber = 0;

            while (true)
            {
                UInt16 footer = parser.BitBuffer.ReadUInt16();

                if (footer == 0)
                {
                    bitWriter.WriteUInt16(footer);
                    break;
                }
                else
                {
                    parser.BitBuffer.SeekBits(-16);
                }

                if (!parser.BitBuffer.ReadBoolean()) // entity number isn't last entity number + 1, need to read it in
                {
                    bitWriter.WriteBoolean(false);

                    // is the following entity number absolute, or relative from the last one?
                    if (parser.BitBuffer.ReadBoolean())
                    {
                        bitWriter.WriteBoolean(true);
                        entityNumber = parser.BitBuffer.ReadUnsignedBits(11);
                        bitWriter.WriteUnsignedBits(entityNumber, 11);
                    }
                    else
                    {
                        bitWriter.WriteBoolean(false);
                        UInt32 entityNumberDelta = parser.BitBuffer.ReadUnsignedBits(6);
                        bitWriter.WriteUnsignedBits(entityNumberDelta, 6);
                        entityNumber += entityNumberDelta;
                    }
                }
                else
                {
                    bitWriter.WriteBoolean(true);
                    entityNumber++;
                }

                Boolean custom = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(custom);
                Boolean baseline = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(baseline);

                if (baseline)
                {
                    bitWriter.WriteUnsignedBits(parser.BitBuffer.ReadUnsignedBits(6), 6); // baseline index
                }

                String entityType = "entity_state_t";

                if (entityNumber > 0 && entityNumber <= demo.MaxClients)
                {
                    entityType = "entity_state_player_t";
                }
                else if (custom)
                {
                    entityType = "custom_entity_state_t";
                }

                HalfLifeDeltaStructure entityStateStructure = parser.GetDeltaStructure(entityType);
                HalfLifeDelta delta = entityStateStructure.CreateDelta();
                Byte[] bitmaskBytes;
                entityStateStructure.ReadDelta(parser.BitBuffer, delta, out bitmaskBytes);

                if (demo.Game != null)
                {
                    demo.Game.ConvertPacketEntititiesCallback(delta, entityType, demo.GameVersion);
                }

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

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

            // insert new message
            ReWriteMessage(messageStartOffset, bitWriter.Data);
        }
Ejemplo n.º 2
0
        private void MessageDeltaPacketEntities()
        {
            if (!demo.ConvertNetworkProtocol() || demo.IsBetaSteam())
            {
                parser.MessageDeltaPacketEntities();
                return;
            }

            Int32     messageStartOffset = parser.BitBuffer.CurrentByte;
            BitWriter bitWriter          = new BitWriter();

            // read message
            bitWriter.WriteUInt16(parser.BitBuffer.ReadUInt16()); // nEntities/maxEntities

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

            bitWriter.WriteByte(parser.BitBuffer.ReadByte()); // delta sequence number

            UInt32 entityNumber = 0;

            while (true)
            {
                // check for footer
                UInt16 footer = parser.BitBuffer.ReadUInt16();

                if (footer == 0)
                {
                    bitWriter.WriteUInt16(footer);
                    break;
                }

                parser.BitBuffer.SeekBits(-16);

                // option bits
                Boolean removeEntity = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(removeEntity);
                Boolean absoluteEntityNumber = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(absoluteEntityNumber);

                // entity number
                if (absoluteEntityNumber)
                {
                    entityNumber = parser.BitBuffer.ReadUnsignedBits(11);
                    bitWriter.WriteUnsignedBits(entityNumber, 11);
                }
                else
                {
                    UInt32 deltaEntityNumber = parser.BitBuffer.ReadUnsignedBits(6);
                    bitWriter.WriteUnsignedBits(deltaEntityNumber, 6);
                    entityNumber += deltaEntityNumber;
                }

                if (!removeEntity)
                {
                    // entity type
                    Boolean custom = parser.BitBuffer.ReadBoolean();
                    bitWriter.WriteBoolean(custom);

                    if (demo.NetworkProtocol <= 43)
                    {
                        parser.BitBuffer.SeekBits(1); // unknown, always 0
                    }

                    String entityType = "entity_state_t";

                    if (entityNumber > 0 && entityNumber <= demo.MaxClients)
                    {
                        entityType = "entity_state_player_t";
                    }
                    else if (custom)
                    {
                        entityType = "custom_entity_state_t";
                    }

                    // delta compressed data
                    Byte[] bitmaskBytes;
                    HalfLifeDeltaStructure deltaDecoder = parser.GetDeltaStructure(entityType);
                    HalfLifeDelta          deltaEntity  = deltaDecoder.CreateDelta();
                    deltaDecoder.ReadDelta(parser.BitBuffer, deltaEntity, out bitmaskBytes);

                    if (demo.Game != null)
                    {
                        demo.Game.ConvertPacketEntititiesCallback(deltaEntity, entityType, demo.GameVersion);
                    }

                    deltaDecoder.WriteDelta(bitWriter, deltaEntity, bitmaskBytes);
                }
            }

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

            // insert new message
            ReWriteMessage(messageStartOffset, bitWriter.Data);
        }
        private void MessageDeltaPacketEntities()
        {
            if (!demo.ConvertNetworkProtocol() || demo.IsBetaSteam())
            {
                parser.MessageDeltaPacketEntities();
                return;
            }

            Int32 messageStartOffset = parser.BitBuffer.CurrentByte;
            BitWriter bitWriter = new BitWriter();

            // read message
            bitWriter.WriteUInt16(parser.BitBuffer.ReadUInt16()); // nEntities/maxEntities

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

            bitWriter.WriteByte(parser.BitBuffer.ReadByte()); // delta sequence number

            UInt32 entityNumber = 0;

            while (true)
            {
                // check for footer
                UInt16 footer = parser.BitBuffer.ReadUInt16();

                if (footer == 0)
                {
                    bitWriter.WriteUInt16(footer);
                    break;
                }

                parser.BitBuffer.SeekBits(-16);

                // option bits
                Boolean removeEntity = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(removeEntity);
                Boolean absoluteEntityNumber = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(absoluteEntityNumber);

                // entity number
                if (absoluteEntityNumber)
                {
                    entityNumber = parser.BitBuffer.ReadUnsignedBits(11);
                    bitWriter.WriteUnsignedBits(entityNumber, 11);
                }
                else
                {
                    UInt32 deltaEntityNumber = parser.BitBuffer.ReadUnsignedBits(6);
                    bitWriter.WriteUnsignedBits(deltaEntityNumber, 6);
                    entityNumber += deltaEntityNumber;
                }

                if (!removeEntity)
                {
                    // entity type
                    Boolean custom = parser.BitBuffer.ReadBoolean();
                    bitWriter.WriteBoolean(custom);

                    if (demo.NetworkProtocol <= 43)
                    {
                        parser.BitBuffer.SeekBits(1); // unknown, always 0
                    }

                    String entityType = "entity_state_t";

                    if (entityNumber > 0 && entityNumber <= demo.MaxClients)
                    {
                        entityType = "entity_state_player_t";
                    }
                    else if (custom)
                    {
                        entityType = "custom_entity_state_t";
                    }

                    // delta compressed data
                    Byte[] bitmaskBytes;
                    HalfLifeDeltaStructure deltaDecoder = parser.GetDeltaStructure(entityType);
                    HalfLifeDelta deltaEntity = deltaDecoder.CreateDelta();
                    deltaDecoder.ReadDelta(parser.BitBuffer, deltaEntity, out bitmaskBytes);

                    if (demo.Game != null)
                    {
                        demo.Game.ConvertPacketEntititiesCallback(deltaEntity, entityType, demo.GameVersion);
                    }

                    deltaDecoder.WriteDelta(bitWriter, deltaEntity, bitmaskBytes);
                }
            }

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

            // insert new message
            ReWriteMessage(messageStartOffset, bitWriter.Data);
        }
Ejemplo n.º 4
0
        private void MessagePacketEntities()
        {
            if (!demo.ConvertNetworkProtocol())
            {
                parser.MessagePacketEntities();
                return;
            }

            Int32     messageStartOffset = parser.BitBuffer.CurrentByte;
            BitWriter bitWriter          = new BitWriter();

            // read message into new message
            bitWriter.WriteUInt16(parser.BitBuffer.ReadUInt16()); // nEntities/maxEntities

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

            UInt32 entityNumber = 0;

            while (true)
            {
                UInt16 footer = parser.BitBuffer.ReadUInt16();

                if (footer == 0)
                {
                    bitWriter.WriteUInt16(footer);
                    break;
                }
                else
                {
                    parser.BitBuffer.SeekBits(-16);
                }

                if (!parser.BitBuffer.ReadBoolean()) // entity number isn't last entity number + 1, need to read it in
                {
                    bitWriter.WriteBoolean(false);

                    // is the following entity number absolute, or relative from the last one?
                    if (parser.BitBuffer.ReadBoolean())
                    {
                        bitWriter.WriteBoolean(true);
                        entityNumber = parser.BitBuffer.ReadUnsignedBits(11);
                        bitWriter.WriteUnsignedBits(entityNumber, 11);
                    }
                    else
                    {
                        bitWriter.WriteBoolean(false);
                        UInt32 entityNumberDelta = parser.BitBuffer.ReadUnsignedBits(6);
                        bitWriter.WriteUnsignedBits(entityNumberDelta, 6);
                        entityNumber += entityNumberDelta;
                    }
                }
                else
                {
                    bitWriter.WriteBoolean(true);
                    entityNumber++;
                }

                Boolean custom = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(custom);
                Boolean baseline = parser.BitBuffer.ReadBoolean();
                bitWriter.WriteBoolean(baseline);

                if (baseline)
                {
                    bitWriter.WriteUnsignedBits(parser.BitBuffer.ReadUnsignedBits(6), 6); // baseline index
                }

                String entityType = "entity_state_t";

                if (entityNumber > 0 && entityNumber <= demo.MaxClients)
                {
                    entityType = "entity_state_player_t";
                }
                else if (custom)
                {
                    entityType = "custom_entity_state_t";
                }

                HalfLifeDeltaStructure entityStateStructure = parser.GetDeltaStructure(entityType);
                HalfLifeDelta          delta = entityStateStructure.CreateDelta();
                Byte[] bitmaskBytes;
                entityStateStructure.ReadDelta(parser.BitBuffer, delta, out bitmaskBytes);

                if (demo.Game != null)
                {
                    demo.Game.ConvertPacketEntititiesCallback(delta, entityType, demo.GameVersion);
                }

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

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

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