Esempio n. 1
0
        public static void Serialize(Stream stream, Magazine instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(8);
            ProtocolParser.WriteUInt64(stream, (ulong)instance.capacity);
            stream.WriteByte(16);
            ProtocolParser.WriteUInt64(stream, (ulong)instance.contents);
            stream.WriteByte(24);
            ProtocolParser.WriteUInt64(stream, (ulong)instance.ammoType);
            Pool.FreeMemoryStream(ref memoryStream);
        }
        public static void SerializeDelta(Stream stream, BaseProjectile instance, BaseProjectile previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.primaryMagazine != null)
            {
                stream.WriteByte(10);
                memoryStream.SetLength((long)0);
                Magazine.SerializeDelta(memoryStream, instance.primaryMagazine, previous.primaryMagazine);
                uint length = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Esempio n. 3
0
 public ProtoBuf.Magazine Save()
 {
     ProtoBuf.Magazine magazine = Facepunch.Pool.Get <ProtoBuf.Magazine>();
     if (ammoType == null)
     {
         magazine.capacity = capacity;
         magazine.contents = 0;
         magazine.ammoType = 0;
     }
     else
     {
         magazine.capacity = capacity;
         magazine.contents = contents;
         magazine.ammoType = ammoType.itemid;
     }
     return(magazine);
 }
Esempio n. 4
0
        public static void SerializeDelta(Stream stream, Magazine instance, Magazine previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.capacity != previous.capacity)
            {
                stream.WriteByte(8);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.capacity);
            }
            if (instance.contents != previous.contents)
            {
                stream.WriteByte(16);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.contents);
            }
            if (instance.ammoType != previous.ammoType)
            {
                stream.WriteByte(24);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.ammoType);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Esempio n. 5
0
        public static Magazine DeserializeLengthDelimited(Stream stream, Magazine instance, bool isDelta)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num == 8)
                {
                    instance.capacity = (int)ProtocolParser.ReadUInt64(stream);
                }
                else if (num == 16)
                {
                    instance.contents = (int)ProtocolParser.ReadUInt64(stream);
                }
                else if (num == 24)
                {
                    instance.ammoType = (int)ProtocolParser.ReadUInt64(stream);
                }
                else
                {
                    Key key = ProtocolParser.ReadKey((byte)num, stream);
                    if (key.Field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    ProtocolParser.SkipKey(stream, key);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
        public static BaseProjectile DeserializeLengthDelimited(Stream stream, BaseProjectile instance, bool isDelta)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num != 10)
                {
                    Key key = ProtocolParser.ReadKey((byte)num, stream);
                    if (key.Field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    ProtocolParser.SkipKey(stream, key);
                }
                else if (instance.primaryMagazine != null)
                {
                    Magazine.DeserializeLengthDelimited(stream, instance.primaryMagazine, isDelta);
                }
                else
                {
                    instance.primaryMagazine = Magazine.DeserializeLengthDelimited(stream);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Esempio n. 7
0
 public void CopyTo(Magazine instance)
 {
     instance.capacity = this.capacity;
     instance.contents = this.contents;
     instance.ammoType = this.ammoType;
 }
Esempio n. 8
0
 public virtual void WriteToStream(Stream stream)
 {
     Magazine.Serialize(stream, this);
 }
Esempio n. 9
0
 public byte[] ToProtoBytes()
 {
     return(Magazine.SerializeToBytes(this));
 }
Esempio n. 10
0
 public void ToProto(Stream stream)
 {
     Magazine.Serialize(stream, this);
 }
Esempio n. 11
0
 public static void SerializeLengthDelimited(Stream stream, Magazine instance)
 {
     byte[] bytes = Magazine.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Esempio n. 12
0
 public void ResetToPool()
 {
     Magazine.ResetToPool(this);
 }
Esempio n. 13
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     Magazine.DeserializeLength(stream, size, this, isDelta);
 }
Esempio n. 14
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     Magazine.Deserialize(stream, this, isDelta);
 }
Esempio n. 15
0
 public void Load(ProtoBuf.Magazine mag)
 {
     contents = mag.contents;
     capacity = mag.capacity;
     ammoType = ItemManager.FindItemDefinition(mag.ammoType);
 }