Esempio n. 1
0
        public DemoPacketCommand(Stream input) : base(input)
        {
            Type = DemoCommandType.dem_packet;

            using (BinaryReader r = new BinaryReader(input, Encoding.ASCII, true))
            {
                Viewpoint = new DemoViewpoint();

                Viewpoint.ViewpointFlags = (DemoViewpoint.Flags)r.ReadInt32();

                Viewpoint.ViewOrigin1      = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                Viewpoint.ViewAngles1      = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                Viewpoint.LocalViewAngles1 = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());

                Viewpoint.ViewOrigin2      = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                Viewpoint.ViewAngles2      = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                Viewpoint.LocalViewAngles2 = new Vector(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());

                SequenceIn  = r.ReadInt32();
                SequenceOut = r.ReadInt32();

                BitStream data = new BitStream(r.ReadBytes((int)r.ReadUInt32()));
                Messages = NetMessageCoder.Decode(data).ToArray();
            }
        }
        public void ReadMsg(BitStream stream)
        {
            if (_messageCount + 1 > _maxMessageCount)
            {
                Debug.WriteLine("hit MaxMessageCOunt abourting");

                throw new ApplicationException();
            }

            _messageCount++;
            while (stream.Length - stream.Cursor > 2)
            {
                _bs.Add(stream.ReadBool());

                //removing DebugListeners to ignore Debug.Assert's while trying to parse with current length
                TraceListener[] listeners = new TraceListener[Debug.Listeners.Count];
                Debug.Listeners.CopyTo(listeners, 0);
                Debug.Listeners.Clear();

                try
                {
                    List <INetMessage> netMessages = NetMessageCoder.Decode(stream.Clone());
                    AddCandidates(netMessages);
                }
                catch (StackOverflowException)
                {
                    Debug.WriteLine("hit StackOverflowException aborting");
                    break;
                }
                catch (OverflowException exception)
                {
                    Debug.WriteLine("hit OverflowException aborting");
                    break;
                }
                catch (Exception exception)
                {
                }
                finally
                {
                    Debug.Listeners.AddRange(listeners);
                }
            }

            _bestCandidate = _candidates
                             .Where(c => c.Messages.Count > 0)
                             .Where(c => c.ChildDebugMessageLength != int.MaxValue)
                             .OrderByDescending(c => c.Messages.Count)
                             .ThenBy(c => c.ChildDebugMessageLength)
                             .FirstOrDefault();

            if (_bestCandidate == null)
            {
                Debug.WriteLine("Unknown message: no candidate");
            }
            else
            {
                Debug.WriteLine("Unknown message: {0} bits long with best candidate having {1} unknown bits ", _bestCandidate.FieldLength, _bestCandidate.ChildDebugMessageLength);
            }

            _messageCount--;
        }