private void Prop_ValueChanged(SendProp prop) { Debug.Assert(ReferenceEquals(prop.Entity, Entity)); Debug.Assert((!Entity.InPVS && Property == null) || prop == Property); Value = Decoder(prop.Value); m_ValueChanged = true; }
public void AddProperty(SendProp newProp) { Debug.Assert(!m_Properties.Any(p => ReferenceEquals(p.Definition, newProp.Definition))); Debug.Assert(ReferenceEquals(newProp.Entity, this)); m_Properties.Add(newProp); PropertyAdded.Invoke(newProp); }
public IEnumerable <SendProp> Parse(IBitStream bitstream) { var sendprops = new List <SendProp>(); while (!bitstream.ChunkFinished) { var desc = bitstream.ReadProtobufVarInt(); var wireType = desc & 7; var fieldnum = desc >> 3; if (wireType == 2) { if (fieldnum == 2) { NetTableName = bitstream.ReadProtobufString(); } else if (fieldnum == 4) { // Props are special. // We'll simply hope that gaben is nice and sends // props last, just like he should. var len = bitstream.ReadProtobufVarInt(); bitstream.BeginChunk(len * 8); var sendprop = new SendProp(); sendprop.Parse(bitstream); sendprops.Add(sendprop); bitstream.EndChunk(); } else { throw new InvalidDataException("yes I know we should drop this" + "but we probably want to know that they added a new big field"); } } else if (wireType == 0) { var val = bitstream.ReadProtobufVarInt(); switch (fieldnum) { case 1: _IsEnd = val; break; case 3: _NeedsDecoder = val; break; } } else { throw new InvalidDataException(); } } return(sendprops); }
private void Entity_PropertyAdded(SendProp prop) { if (prop.Definition.FullName == PropertyName) { Property = prop; if (prop.ValueChanged.Add(Prop_ValueChanged)) { // First add only if (prop.Value != null) { Prop_ValueChanged(prop); } } } }
public static void ApplyEntityUpdate(IEntity e, BitStream stream) { var testGuessProps = e.NetworkTable.FlattenedProps; bool atLeastOne = false; int index = -1; while ((index = ReadFieldIndex(stream, index)) != -1) { Debug.Assert(index < testGuessProps.Length); Debug.Assert(index < SourceConstants.MAX_DATATABLE_PROPS); var prop = testGuessProps[index]; SendProp s = e.GetProperty(prop); bool wasNull = false; if (s == null) { s = new SendProp(e, prop); wasNull = true; } object newValue = prop.Decode(stream); s.Value = newValue; atLeastOne = true; if (wasNull) { e.AddProperty(s); } } if (atLeastOne) { e.PropertiesUpdated.Invoke(e); } }
public IEnumerable<SendProp> Parse(IBitStream bitstream) { var sendprops = new List<SendProp>(); while (!bitstream.ChunkFinished) { var desc = bitstream.ReadProtobufVarInt(); var wireType = desc & 7; var fieldnum = desc >> 3; if (wireType == 2) { if (fieldnum == 2) { NetTableName = bitstream.ReadProtobufString(); } else if (fieldnum == 4) { // Props are special. // We'll simply hope that gaben is nice and sends // props last, just like he should. var len = bitstream.ReadProtobufVarInt(); bitstream.BeginChunk(len * 8); var sendprop = new SendProp(); sendprop.Parse(bitstream); sendprops.Add(sendprop); bitstream.EndChunk(); } else throw new InvalidDataException("yes I know we should drop this" + "but we probably want to know that they added a new big field"); } else if (wireType == 0) { var val = bitstream.ReadProtobufVarInt(); switch (fieldnum) { case 1: _IsEnd = val; break; case 3: _NeedsDecoder = val; break; default: // silently drop break; } } else throw new InvalidDataException(); } return sendprops; }
public static Task Read(this SourceDemo demo, DataTables frame) { var buf = frame.Buffer; while (buf.ReadBoolean()) { bool needsdecoder = buf.ReadBoolean(); var table = new SendTable() { NetTableName = buf.ReadString(), NeedsDecoder = needsdecoder }; var props = buf.ReadUBits(DataTable.PROPINFOBITS_NUMPROPS); for (int j = 0; j < props; j++) { int fbits = (demo.Protocol == 2) ? 11 : DataTable.PROPINFOBITS_FLAGS; var prop = new SendProp { Type = (SendPropType)buf.ReadUBits(DataTable.PROPINFOBITS_TYPE), VarName = buf.ReadString(), Flags = (SendPropFlags)buf.ReadUBits(fbits) }; if ((prop.Type == SendPropType.DataTable) || (prop.IsExcludeProp())) { prop.ExcludeDtName = buf.ReadString(); //if ((prop.Flags & SendPropFlags.Collapsible) != 0) //{ //} } else if (prop.Type == SendPropType.Array) { prop.Elements = (int)buf.ReadUBits(DataTable.PROPINFOBITS_NUMELEMENTS); } else { prop.LowValue = buf.ReadSingle(); prop.HighValue = buf.ReadSingle(); prop.Bits = (int)buf.ReadUBits(DataTable.PROPINFOBITS_NUMBITS + 1); } table.Props.Add(prop); } frame.Tables.Add(table); } var classes = buf.ReadInt16(); for (var i = 0; i < classes; i++) { frame.Classes.Add(new ServerClassInfo { ClassId = buf.ReadInt16(), ClassName = buf.ReadString(), DataTableName = buf.ReadString() }); } return(Task.CompletedTask); }