Exemplo n.º 1
0
        protected override void Parse(ref BitStreamReader bsr)
        {
            Cmd = bsr.ReadUInt();
            uint byteSize        = bsr.ReadUInt();
            int  indexBeforeData = bsr.CurrentBitIndex;

            CommandNumber    = bsr.ReadUIntIfExists();
            TickCount        = bsr.ReadUIntIfExists();
            ViewAngleX       = bsr.ReadFloatIfExists();
            ViewAngleY       = bsr.ReadFloatIfExists();
            ViewAngleZ       = bsr.ReadFloatIfExists();
            SidewaysMovement = bsr.ReadFloatIfExists();
            ForwardMovement  = bsr.ReadFloatIfExists();
            VerticalMovement = bsr.ReadFloatIfExists();
            Buttons          = (Buttons?)bsr.ReadUIntIfExists();
            Impulse          = bsr.ReadByteIfExists();
            if (bsr.ReadBool())
            {
                WeaponSelect  = bsr.ReadUInt(11);
                WeaponSubtype = bsr.ReadUIntIfExists(6);
            }
            MouseDx             = (short?)bsr.ReadUShortIfExists();
            MouseDy             = (short?)bsr.ReadUShortIfExists();
            bsr.CurrentBitIndex = indexBeforeData + (int)(byteSize << 3);
        }
Exemplo n.º 2
0
        protected override void Parse(ref BitStreamReader bsr)
        {
            EntityIndex = bsr.ReadBool() ? bsr.ReadUInt(bsr.ReadBool() ? 5 : DemoInfo.MaxEdictBits) : _deltaTmp.EntityIndex;

#pragma warning disable 8629
            if (DemoInfo.NewDemoProtocol)
            {
                Flags = (SoundFlags?)bsr.ReadUIntIfExists(DemoInfo.SoundFlagBitsEncode) ?? _deltaTmp.Flags;
                if ((Flags & SoundFlags.IsScriptHandle) != 0)
                {
                    ScriptHash = bsr.ReadUInt();
                }
                else
                {
                    SoundNum = (int?)bsr.ReadUIntIfExists(DemoInfo.MaxSndIndexBits) ?? _deltaTmp.SoundNum;
                }
            }
            else
            {
                SoundNum = (int?)bsr.ReadUIntIfExists(DemoInfo.MaxSndIndexBits) ?? _deltaTmp.SoundNum;
                Flags    = (SoundFlags?)bsr.ReadUIntIfExists(DemoInfo.SoundFlagBitsEncode) ?? _deltaTmp.Flags;
            }
            Chan = (Channel?)bsr.ReadUIntIfExists(3) ?? _deltaTmp.Chan;
#pragma warning restore 8629

            #region get sound name

            if (SoundNum.HasValue)
            {
                var mgr = DemoRef.StringTablesManager;

                if (mgr.TableReadable.GetValueOrDefault(TableNames.SoundPreCache))
                {
                    _soundTableReadable = true;
                    if (SoundNum >= mgr.Tables[TableNames.SoundPreCache].Entries.Count)
                    {
                        DemoRef.LogError($"{GetType().Name} - sound index out of range: {SoundNum}");
                    }
                    else if (SoundNum != 0)
                    {
                        SoundName = mgr.Tables[TableNames.SoundPreCache].Entries[SoundNum.Value].EntryName;
                    }
                }
            }

            #endregion

            IsAmbient  = bsr.ReadBool();
            IsSentence = bsr.ReadBool();

            if (Flags != SoundFlags.Stop)
            {
                if (bsr.ReadBool())
                {
                    SequenceNumber = _deltaTmp.SequenceNumber;
                }
                else if (bsr.ReadBool())
                {
                    SequenceNumber = _deltaTmp.SequenceNumber + 1;
                }
                else
                {
                    SequenceNumber = bsr.ReadUInt(SndSeqNumberBits);
                }

                Volume     = bsr.ReadUIntIfExists(7) / 127.0f ?? _deltaTmp.Volume;
                SoundLevel = bsr.ReadUIntIfExists(MaxSndLvlBits) ?? _deltaTmp.SoundLevel;
                Pitch      = bsr.ReadUIntIfExists(8) ?? _deltaTmp.Pitch;
                if (!DemoInfo.NewDemoProtocol && DemoRef.Header.NetworkProtocol > 21)
                {
                    SpecialDspCount = bsr.ReadByteIfExists() ?? _deltaTmp.SpecialDspCount;
                }

                if (DemoInfo.NewDemoProtocol)
                {
                    RandomSeed = bsr.ReadSIntIfExists(6) ?? _deltaTmp.RandomSeed;                     // 6, 18, or 29
                    Delay      = bsr.ReadFloatIfExists() ?? _deltaTmp.Delay;
                }
                else
                {
                    if (bsr.ReadBool())
                    {
                        Delay = bsr.ReadSInt(MaxSndDelayMSecEncodeBits) / 1000.0f;
                        if (Delay < 0)
                        {
                            Delay *= 10.0f;
                        }
                        Delay -= SndDelayOffset;
                    }
                    else
                    {
                        Delay = _deltaTmp.Delay;
                    }
                }

                Origin = new Vector3 {
                    X = bsr.ReadSIntIfExists(PropDecodeConsts.CoordIntBits - 2) * 8 ?? _deltaTmp.Origin.X,
                    Y = bsr.ReadSIntIfExists(PropDecodeConsts.CoordIntBits - 2) * 8 ?? _deltaTmp.Origin.Y,
                    Z = bsr.ReadSIntIfExists(PropDecodeConsts.CoordIntBits - 2) * 8 ?? _deltaTmp.Origin.Z
                };
                SpeakerEntity = bsr.ReadSIntIfExists(DemoInfo.MaxEdictBits + 1) ?? _deltaTmp.SpeakerEntity;
            }
            else
            {
                ClearStopFields();
            }
        }