Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void WriteUIntsIfExists()
        {
            var                         random = new Random(0);
            BitStreamWriter             bsw    = new BitStreamWriter();
            List <(uint?val, int size)> bits   = new List <(uint?val, int size)>();

            for (int _ = 0; _ < Iterations; _++)
            {
                bool rBool = random.NextDouble() >= 0.5;
                (uint?val, int size)r = (rBool ? (uint?)null : (uint)random.Next(), random.Next(1, 33));
                r.val &= uint.MaxValue >> (32 - r.size);
                bits.Add(r);
                bsw.WriteBitsFromUIntIfExists(r.val, r.size);
            }
            BitStreamReader bsr = new BitStreamReader(bsw);

            for (int i = 0; i < Iterations; i++)
            {
                Assert.AreEqual(bits[i].val, bsr.ReadUIntIfExists(bits[i].size), $"index: {i}");
            }
        }
Ejemplo n.º 3
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();
            }
        }