Example #1
0
 /// <summary>
 ///     *
 /// </summary>
 public override void read_scalefactor(Bitstream stream, Header header)
 {
     if (allocation != 0)
         scalefactor = ScaleFactors[stream.GetBitsFromBuffer(6)];
     if (channel2_allocation != 0)
         channel2_scalefactor = ScaleFactors[stream.GetBitsFromBuffer(6)];
 }
        /// <summary>
        ///     *
        /// </summary>
        public override void ReadScaleFactor(Bitstream stream, Header header)
        {
            base.ReadScaleFactor(stream, header);
            if (channel2_allocation != 0)
            {
                switch (channel2_scfsi)
                {
                    case 0:
                        channel2_scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 1:
                        channel2_scalefactor1 = channel2_scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 2:
                        channel2_scalefactor1 =
                            channel2_scalefactor2 = channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 3:
                        channel2_scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor2 = channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;
                }
                prepare_sample_reading(header, channel2_allocation, 1, channel2_factor, channel2_codelength,
                    channel2_c, channel2_d);
            }
        }
Example #3
0
        private float UnpackFloatCoord(Bitstream stream) {
            bool hasInteger = stream.ReadBool();
            bool hasFraction = stream.ReadBool();

            if (hasInteger || hasFraction) {
                bool sign = stream.ReadBool();

                uint integer = 0;
                if (hasInteger) {
                    integer = stream.ReadBits(COORD_INTEGER_BITS) + 1;
                }

                uint fraction = 0;
                if (hasFraction) {
                    fraction = stream.ReadBits(COORD_FRACTIONAL_BITS);
                }

                float f = (float) (integer + fraction * COORD_RESOLUTION);

                if (sign) {
                    f *= -1;
                }

                return f;
            } else {
                return 0;
            }
        }
Example #4
0
        private UpdateFlag ReadHeader(ref uint id, Bitstream stream) {
            uint value = stream.ReadBits(6);

            if ((value & 0x30) > 0) {
                uint a = (value >> 4) & 3;
                uint b = (uint) ((a == 3) ? 16 : 0);

                value = (stream.ReadBits((byte) (4 * a + b)) << 4) | (value & 0xF);
            }

            id = unchecked(id + value + 1);

            var flags = UpdateFlag.None;

            if (!stream.ReadBool()) {
                if (stream.ReadBool()) {
                    flags |= UpdateFlag.EnterPvs;
                }
            } else {
                flags |= UpdateFlag.LeavePvs;

                if (stream.ReadBool()) {
                    flags |= UpdateFlag.Delete;
                }
            }

            return flags;
        }
        /// <summary>
        ///     *
        /// </summary>
        public override void ReadScaleFactor(Bitstream stream, Header header)
        {
            if (allocation != 0)
            {
                base.ReadScaleFactor(stream, header);
                switch (channel2_scfsi)
                {
                    case 0:
                        channel2_scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 1:
                        channel2_scalefactor1 = channel2_scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 2:
                        channel2_scalefactor1 =
                            channel2_scalefactor2 = channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 3:
                        channel2_scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        channel2_scalefactor2 = channel2_scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;
                }
            }
        }
Example #6
0
        public void Update(Bitstream stream, uint baseline, bool updateBaseline, uint updated, bool isDelta) {
            uint id = UInt32.MaxValue;
            uint found = 0;

            while (found < updated) {
                var flags = ReadHeader(ref id, stream);

                if (flags.HasFlag(UpdateFlag.EnterPvs)) {
                    ReadEnterPvs(id, baseline, updateBaseline, stream);
                } else if (flags.HasFlag(UpdateFlag.LeavePvs)) {
                    if (flags.HasFlag(UpdateFlag.Delete)) {
                        Delete(id);
                    }
                } else {
                    ReadUpdate(id, stream);
                }

                ++found;
            }

            if (isDelta) {
                while (stream.ReadBool()) {
                    id = stream.ReadBits(11);
                    Delete(id);
                }
            }
        }
Example #7
0
        private string ReadKeyIfIncluded(Bitstream stream, List<string> keyHistory) {
            bool has_key = stream.ReadBool();

            if (!has_key) {
                return null;
            } 

            bool is_substring = stream.ReadBool();

            string key;

            if (!is_substring) {
                key = stream.ReadString();
            } else {
                int fromIndex = (int) stream.ReadBits(5);
                int fromLength = (int) stream.ReadBits(5);
                key = keyHistory[fromIndex].Substring(0, fromLength);

                key += stream.ReadString();
            }

            Preconditions.CheckArgument(key.Length <= MAX_KEY_SIZE);

            if (keyHistory.Count == KEY_HISTORY_SIZE) {
                keyHistory.RemoveAt(0);
            }

            keyHistory.Add(key);

            return key;
        }
Example #8
0
        public float UnpackFloat(PropertyInfo info, Bitstream stream) {
            var flags = info.Flags;

            if (flags.HasFlag(PropertyInfo.MultiFlag.Coord)) {
                return UnpackFloatCoord(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMp)) {
                return UnpackFloatCoordMp(stream, FloatType.None);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMpLowPrecision)) {
                return UnpackFloatCoordMp(stream, FloatType.LowPrecision);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMpIntegral)) {
                return UnpackFloatCoordMp(stream, FloatType.Integral);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.NoScale)) {
                return UnpackFloatNoScale(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.Normal)) {
                return UnpackFloatNormal(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoord)) {
                return UnpackFloatCellCoord(info, stream, FloatType.None);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoordLowPrecision)) {
                return UnpackFloatCellCoord(info, stream, FloatType.LowPrecision);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoordIntegral)) {
                return UnpackFloatCellCoord(info, stream, FloatType.Integral);
            } else {
                uint dividend = stream.ReadBits(info.NumBits);
                uint divisor = (uint) (1 << info.NumBits) - 1;

                float f = ((float) dividend) / divisor;
                float range = info.HighValue - info.LowValue;

                return f * range + info.LowValue;
            }
        }
Example #9
0
        public override void Deserialize(Bitstream msg)
        {
            var count = msg.ReadUInt16();
            count = (ushort)Math.Max((int)count, 0);
            count = (ushort)Math.Min((int)count, 100);
            State = new List<PlayerStateData>(count);

            if (count > 0)
            {
                ushort objType = msg.ReadByte();
                PlayerId = msg.ReadVariableUInt32();
                if (_ownerType == null)
                {
                    _ownerType = ObjectMapper.LookupType(objType);
                    _lookupItem = DataLookupTable.Get(_ownerType.GetTypeInfo());

                }
            }

            NetworkObject pState = PlayerId > 0 ? ObjectMapper.GetCurrentPlayerState(PlayerId) : null;
            for (int i = 0; i < count; ++i)
            {
                NetworkObject data = Activator.CreateInstance(_ownerType) as NetworkObject;
                DataObjectPacket.ReadNetObject(_lookupItem, msg, data, pState);
                pState = data;
                State.Add(data as PlayerStateData);
            }

            if (State.Count > 0 && PlayerId > 0)
                ObjectMapper.SetCurrentPlayerState(PlayerId, State.Last());
        }
Example #10
0
 /// <summary>
 ///     *
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     bool returnvalue = base.read_sampledata(stream);
     if (channel2_allocation != 0)
     {
         channel2_sample = stream.GetBitsFromBuffer(channel2_samplelength);
     }
     return (returnvalue);
 }
Example #11
0
 public override void Serialize(Bitstream msg)
 {
     msg.Write(Name);
     msg.WriteVariableUInt32(EntityId);
     msg.Write(Parameters.Count);
     foreach (var p in Parameters)
     {
         WriteParam(p, msg);
     }
 }
Example #12
0
 public virtual void Create(Bitstream stream0, Header header0, SynthesisFilter filtera, SynthesisFilter filterb,
     ABuffer buffer0, int whichCh0)
 {
     stream = stream0;
     header = header0;
     filter1 = filtera;
     filter2 = filterb;
     buffer = buffer0;
     which_channels = whichCh0;
 }
Example #13
0
        public static uint Compute32(Bitstream stream)
        {
            uint crc = 0xFFFFFFFF;

            while (!stream.Eof)
            {
                byte index = (byte)(((crc) & 0xFF) ^ stream.ReadByte(true));
                crc = (uint)((crc >> 8) ^ table[index]);
            }
            return ~crc;
        }
Example #14
0
 /// <summary>
 ///     *
 /// </summary>
 public override void ReadBitAllocation(Bitstream stream, Header header, Crc16 crc)
 {
     int length = get_allocationlength(header);
     allocation = stream.GetBitsFromBuffer(length);
     channel2_allocation = stream.GetBitsFromBuffer(length);
     if (crc != null)
     {
         crc.add_bits(allocation, length);
         crc.add_bits(channel2_allocation, length);
     }
 }
 /// <summary>
 ///     *
 /// </summary>
 public override void read_scalefactor_selection(Bitstream stream, Crc16 crc)
 {
     if (allocation != 0)
     {
         scfsi = stream.GetBitsFromBuffer(2);
         channel2_scfsi = stream.GetBitsFromBuffer(2);
         if (crc != null)
         {
             crc.add_bits(scfsi, 2);
             crc.add_bits(channel2_scfsi, 2);
         }
     }
 }
Example #16
0
        public Nullable<Message> Receive(Bitstream stream) {
            bool hasData = stream.ReadBool();

            if (!hasData) {
                return null;
            }

            if (stream.ReadBool()) {
                return ReadChunk(stream);
            } else {
                return ReadSingle(stream);
            }
        }
Example #17
0
        public override void Deserialize(Bitstream msg)
        {
            Name = msg.ReadString();
            EntityId = msg.ReadVariableUInt32();
            int count = msg.ReadInt32();
            Parameters = new List<object>(count);
            for(int i=0; i < count; ++i)
            {
                var p = ReadParam(msg);
                Parameters.Add(p);
            }

            RPCManager._Call(Name, EntityId, Parameters);
        }
Example #18
0
        public override void Deserialize(Bitstream msg)
        {
            SnapId = msg.ReadUInt32();
            BaselineId = msg.ReadUInt32();

            ushort count = msg.ReadByte();
            Dictionary<int, NetworkObject> state = new Dictionary<int, NetworkObject>();
            int addDeltaCount = 0;
            for (int i=0; i < count; ++i)
            {
                ushort objTypeId = msg.ReadByte();
                var entId = msg.ReadVariableUInt32();

                NetworkObject obj = ObjectMapper.Lookup(entId, objTypeId, true);
                if (obj == null)
                {
                    obj = ObjectMapper.Create(entId, objTypeId);
                }

                NetworkObject realObj = ObjectMapper.Lookup(entId, objTypeId, false);
                var realHash = 0;
                if (realObj != null)
                    realHash = realObj.GetHashCode();

                NetworkObject baseline = null;
                var usebaseLine = msg.ReadBool();
                uint bOffset = 0;
                if (usebaseLine)
                {
                    byte offset = msg.ReadByte();
                    var objBaselineId = BaselineId - (uint)offset;
                    bOffset = objBaselineId;

                    baseline = ObjectMapper.GetBaseline(objBaselineId, realHash);
                }

                var ownerType = obj.GetType().GetTypeInfo();
                var dItem = DataLookupTable.Get(ownerType);
                ReadNetObject(dItem, msg, obj, baseline);
                ObjectMapper.AddDeltaState(realHash, SnapId, obj);

                if (BaselineId != 0 && realHash != 0)
                    addDeltaCount++;
            }

            if (addDeltaCount == count)
                ObjectMapper.LastSimId = BaselineId;
        }
Example #19
0
 /// <summary>
 ///     *
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     if ((allocation = stream.GetBitsFromBuffer(4)) == 15)
     {
     }
     //	 cerr << "WARNING: stream contains an illegal allocation!\n";
     // MPEG-stream is corrupted!
     if (crc != null)
         crc.add_bits(allocation, 4);
     if (allocation != 0)
     {
         samplelength = allocation + 1;
         factor = TableFactor[allocation];
         offset = TableOffset[allocation];
     }
 }
Example #20
0
        private Nullable<Message> ReadChunk(Bitstream stream) {
            uint offset = stream.ReadBits(18);
            uint count = stream.ReadBits(3);

            log.DebugFormat("chunk start = {0} end = {1}", offset, count);

            if (offset == 0) {
                Preconditions.CheckArgument(!Receiving);
                ReadChunkHeader(stream);
            } else {
                Preconditions.CheckArgument(Receiving);
            }

            uint byteOffset = offset * Connection.BYTES_PER_CHUNK;

            uint byteCount;
            if (offset + count < header.ChunkCount) {
                byteCount = count * Connection.BYTES_PER_CHUNK;
            } else {
                byteCount = header.ByteLength - byteOffset;
            }

            stream.Read(dataIn, (int)byteOffset, (int)byteCount);

            for (uint i = offset;
                    i < offset + count;
                    ++i) {
                if (!dataReceived[i]) {
                    dataReceived[i] = true;
                    ++countReceived;
                }
            }

            if (countReceived == header.ChunkCount) {
                log.Debug("chunk complete");
                Receiving = false;
                return new Message {
                    IsCompressed = header.IsCompressed,
                    DecompressedLength = header.DecompressedLength,

                    Data = dataIn,
                };
            } else {
                log.DebugFormat("chunk has {0}/{1}", countReceived, header.ChunkCount);
                return null;
            }
        }
Example #21
0
        private static void WriteParam(object o, Bitstream msg)
        {
            var t = o.GetType();
            var dsitem = new DataSerializationProperty(null, t);

            msg.Write(t.FullName);
            switch (dsitem.Type)
            {
                case DataTypes.BOOL:
                    msg.Write((bool)o);
                    break;
                case DataTypes.UBYTE:
                    msg.Write((byte)o);
                    break;
                case DataTypes.UINT:
                    msg.WriteVariableUInt32((uint)o);
                    break;
                case DataTypes.BYTE:
                    msg.Write((sbyte)o);
                    break;
                case DataTypes.INT:
                    msg.WriteVariableInt32((int)o);
                    break;
                case DataTypes.ULONG:
                    msg.Write((ulong)o);
                    break;
                case DataTypes.LONG:
                    msg.Write((long)o);
                    break;
                case DataTypes.FLOAT:
                    msg.Write((float)o);
                    break;
                case DataTypes.DOUBLE:
                    msg.Write((double)o);
                    break;
                case DataTypes.STRING:
                    msg.Write((string)o);
                    break;
                case DataTypes.VECTOR2:
                    msg.Write((Vector2)o);
                    break;
                default:
                    throw new ArgumentException("Invalid RPC paramter type.");
            }
        }
Example #22
0
        public uint UnpackInt(PropertyInfo info, Bitstream stream) {
            var flags = info.Flags;

            if (flags.HasFlag(PropertyInfo.MultiFlag.EncodedAgainstTickcount)) {
                if (flags.HasFlag(PropertyInfo.MultiFlag.Unsigned)) {
                    return stream.ReadVarUInt();
                } else {
                    uint value = stream.ReadVarUInt();
                    return unchecked((uint) ((-(value & 1)) ^ (value >> 1)));
                }
            } else {
                byte numBits = info.NumBits;

                uint isUnsigned = Convert.ToUInt32(flags.HasFlag(PropertyInfo.MultiFlag.Unsigned));
                uint signer = (0x80000000 >> (32 - numBits)) & unchecked((uint) (isUnsigned - 1));

                uint value = stream.ReadBits(numBits) ^ signer;
                return value - signer;
            }
        }
Example #23
0
 /// <summary>
 ///     *
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     allocation = stream.GetBitsFromBuffer(4);
     channel2_allocation = stream.GetBitsFromBuffer(4);
     if (crc != null)
     {
         crc.add_bits(allocation, 4);
         crc.add_bits(channel2_allocation, 4);
     }
     if (allocation != 0)
     {
         samplelength = allocation + 1;
         factor = TableFactor[allocation];
         offset = TableOffset[allocation];
     }
     if (channel2_allocation != 0)
     {
         channel2_samplelength = channel2_allocation + 1;
         channel2_factor = TableFactor[channel2_allocation];
         channel2_offset = TableOffset[channel2_allocation];
     }
 }
Example #24
0
        public override void Serialize(Bitstream msg)
        {
            var count = State.Count;
            msg.Write((ushort)State.Count);
            if (count > 0 && _ownerType == null)
            {
                _ownerType = State[0].GetType();
                _lookupItem = DataLookupTable.Get(_ownerType.GetTypeInfo());
            }
            if (count > 0)
            {
                ushort objTypeId = ObjectMapper.LookupType(_ownerType);
                msg.Write((byte)objTypeId);
                msg.WriteVariableUInt32(PlayerId);
            }

            PlayerStateData pState = PreviousState;
            foreach (var o in State)
            {
                DataObjectPacket.WriteNetObject(_lookupItem, msg, o, pState);
                pState = o;
            }
        }
Example #25
0
        private void ReadChunkHeader(Bitstream stream) {
            header = new ChunkedHeader();

            header.IsFile = stream.ReadBool();
            if (header.IsFile) {
                uint filenameLength = stream.ReadUInt32();
                byte[] filename = new byte[filenameLength + 1]; // semantically wrong. should be
                                                                // 0x104
                stream.Read(filename, 0, (int)filenameLength); // and then read to end of string
                filename[filenameLength] = 0; // whatever 
                header.Filename = Encoding.UTF8.GetString(filename);
                log.ErrorFormat("read filename: \"{0}\" ({1})", filenameLength, header.Filename);
                throw new NotImplementedException();
            }

            header.IsCompressed = stream.ReadBool();
            if (header.IsCompressed) {
                header.DecompressedLength = stream.ReadBits(26);
                log.DebugFormat(
                    "chunkheader compressed: decompressed len {0}", 
                    header.DecompressedLength);
            }

            header.ByteLength = stream.ReadBits(26);
            header.ChunkCount = 
                (header.ByteLength + Connection.BYTES_PER_CHUNK - 1) /
                Connection.BYTES_PER_CHUNK;
            log.DebugFormat(
                "chunkheader len {0} expecting {1} chunks", 
                header.ByteLength, header.ChunkCount);

            Receiving = true;
            dataIn = new byte[header.ByteLength];
            dataReceived = new bool[header.ChunkCount];
            countReceived = 0;
        }
Example #26
0
        /// <summary>
        ///     *
        /// </summary>
        public override bool ReadSampleData(Bitstream stream)
        {
            if (allocation != 0)
                if (groupingtable[0] != null)
                {
                    int samplecode = stream.GetBitsFromBuffer(codelength[0]);
                    // create requantized samples:
                    samplecode += samplecode << 1;
                    float[] target = samples;
                    float[] source = groupingtable[0];
                    /*
                    int tmp = 0;
                    int temp = 0;
                    target[tmp++] = source[samplecode + temp];
                    temp++;
                    target[tmp++] = source[samplecode + temp];
                    temp++;
                    target[tmp] = source[samplecode + temp];
                    */
                    //Bugfix:
                    int tmp = 0;
                    int temp = samplecode;

                    if (temp > source.Length - 3)
                        temp = source.Length - 3;

                    target[tmp] = source[temp];
                    temp++;
                    tmp++;
                    target[tmp] = source[temp];
                    temp++;
                    tmp++;
                    target[tmp] = source[temp];

                    // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
                }
                else
                {
                    samples[0] = (float)((stream.GetBitsFromBuffer(codelength[0])) * factor[0] - 1.0);
                    samples[1] = (float)((stream.GetBitsFromBuffer(codelength[0])) * factor[0] - 1.0);
                    samples[2] = (float)((stream.GetBitsFromBuffer(codelength[0])) * factor[0] - 1.0);
                }

            samplenumber = 0;
            if (++groupnumber == 12)
                return true;
            return false;
        }
Example #27
0
        /// <summary>
        ///     *
        /// </summary>
        public override void ReadScaleFactor(Bitstream stream, Header header)
        {
            if (allocation != 0)
            {
                switch (scfsi)
                {
                    case 0:
                        scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 1:
                        scalefactor1 = scalefactor2 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 2:
                        scalefactor1 = scalefactor2 = scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;

                    case 3:
                        scalefactor1 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        scalefactor2 = scalefactor3 = ScaleFactors[stream.GetBitsFromBuffer(6)];
                        break;
                }
                prepare_sample_reading(header, allocation, 0, factor, codelength, c, d);
            }
        }
Example #28
0
 /// <summary>
 ///     *
 /// </summary>
 public virtual void read_scalefactor_selection(Bitstream stream, Crc16 crc)
 {
     if (allocation != 0)
     {
         scfsi = stream.GetBitsFromBuffer(2);
         if (crc != null)
             crc.add_bits(scfsi, 2);
     }
 }
 /// <summary>
 ///     *
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     return base.read_sampledata(stream);
 }
 /// <summary>
 ///     *
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     base.read_allocation(stream, header, crc);
 }