예제 #1
0
        public static PersistantPlayer Deserialize(Stream stream)
        {
            PersistantPlayer persistantPlayer = Pool.Get <PersistantPlayer>();

            PersistantPlayer.Deserialize(stream, persistantPlayer, false);
            return(persistantPlayer);
        }
예제 #2
0
        public PersistantPlayer Copy()
        {
            PersistantPlayer persistantPlayer = Pool.Get <PersistantPlayer>();

            this.CopyTo(persistantPlayer);
            return(persistantPlayer);
        }
예제 #3
0
        public static PersistantPlayer DeserializeLength(Stream stream, int length)
        {
            PersistantPlayer persistantPlayer = Pool.Get <PersistantPlayer>();

            PersistantPlayer.DeserializeLength(stream, length, persistantPlayer, false);
            return(persistantPlayer);
        }
예제 #4
0
 public static PersistantPlayer Deserialize(byte[] buffer, PersistantPlayer instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         PersistantPlayer.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
예제 #5
0
 public virtual void WriteToStreamDelta(Stream stream, PersistantPlayer previous)
 {
     if (previous == null)
     {
         PersistantPlayer.Serialize(stream, this);
         return;
     }
     PersistantPlayer.SerializeDelta(stream, this, previous);
 }
예제 #6
0
 public static byte[] SerializeToBytes(PersistantPlayer instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         PersistantPlayer.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
예제 #7
0
        public static PersistantPlayer Deserialize(byte[] buffer)
        {
            PersistantPlayer persistantPlayer = Pool.Get <PersistantPlayer>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                PersistantPlayer.Deserialize(memoryStream, persistantPlayer, false);
            }
            return(persistantPlayer);
        }
예제 #8
0
 public static void ResetToPool(PersistantPlayer instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     if (instance.unlockedItems != null)
     {
         List <int> nums = instance.unlockedItems;
         Pool.FreeList <int>(ref nums);
         instance.unlockedItems = nums;
     }
     instance.protocolVersion = 0;
     Pool.Free <PersistantPlayer>(ref instance);
 }
예제 #9
0
        public static PersistantPlayer DeserializeLengthDelimited(Stream stream, PersistantPlayer instance, bool isDelta)
        {
            if (!isDelta && instance.unlockedItems == null)
            {
                instance.unlockedItems = Pool.Get <List <int> >();
            }
            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 != 24)
                {
                    Key  key   = ProtocolParser.ReadKey((byte)num, stream);
                    uint field = key.Field;
                    if (field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    if (field == 100)
                    {
                        if (key.WireType != Wire.Varint)
                        {
                            continue;
                        }
                        instance.protocolVersion = (int)ProtocolParser.ReadUInt64(stream);
                    }
                    else
                    {
                        ProtocolParser.SkipKey(stream, key);
                    }
                }
                else
                {
                    instance.unlockedItems.Add((int)ProtocolParser.ReadUInt64(stream));
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
예제 #10
0
        public static void Serialize(Stream stream, PersistantPlayer instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.unlockedItems != null)
            {
                for (int i = 0; i < instance.unlockedItems.Count; i++)
                {
                    int item = instance.unlockedItems[i];
                    stream.WriteByte(24);
                    ProtocolParser.WriteUInt64(stream, (ulong)item);
                }
            }
            stream.WriteByte(160);
            stream.WriteByte(6);
            ProtocolParser.WriteUInt64(stream, (ulong)instance.protocolVersion);
            Pool.FreeMemoryStream(ref memoryStream);
        }
예제 #11
0
 public static PersistantPlayer Deserialize(Stream stream, PersistantPlayer instance, bool isDelta)
 {
     if (!isDelta && instance.unlockedItems == null)
     {
         instance.unlockedItems = Pool.Get <List <int> >();
     }
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num != 24)
         {
             Key  key   = ProtocolParser.ReadKey((byte)num, stream);
             uint field = key.Field;
             if (field == 0)
             {
                 throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
             }
             if (field != 100)
             {
                 ProtocolParser.SkipKey(stream, key);
             }
             else if (key.WireType == Wire.Varint)
             {
                 instance.protocolVersion = (int)ProtocolParser.ReadUInt64(stream);
             }
         }
         else
         {
             instance.unlockedItems.Add((int)ProtocolParser.ReadUInt64(stream));
         }
     }
     return(instance);
 }
예제 #12
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     PersistantPlayer.Deserialize(stream, this, isDelta);
 }
예제 #13
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     PersistantPlayer.DeserializeLength(stream, size, this, isDelta);
 }
예제 #14
0
 public virtual void WriteToStream(Stream stream)
 {
     PersistantPlayer.Serialize(stream, this);
 }
예제 #15
0
 public byte[] ToProtoBytes()
 {
     return(PersistantPlayer.SerializeToBytes(this));
 }
예제 #16
0
 public void ToProto(Stream stream)
 {
     PersistantPlayer.Serialize(stream, this);
 }
예제 #17
0
        public static BasePlayer DeserializeLengthDelimited(Stream stream, BasePlayer 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 <= 50)
                {
                    if (num <= 16)
                    {
                        if (num == 10)
                        {
                            instance.name = ProtocolParser.ReadString(stream);
                            continue;
                        }
                        else if (num == 16)
                        {
                            instance.userid = ProtocolParser.ReadUInt64(stream);
                            continue;
                        }
                    }
                    else if (num == 26)
                    {
                        if (instance.inventory != null)
                        {
                            PlayerInventory.DeserializeLengthDelimited(stream, instance.inventory, isDelta);
                            continue;
                        }
                        else
                        {
                            instance.inventory = PlayerInventory.DeserializeLengthDelimited(stream);
                            continue;
                        }
                    }
                    else if (num != 34)
                    {
                        if (num == 50)
                        {
                            if (instance.modelState != null)
                            {
                                ModelState.DeserializeLengthDelimited(stream, instance.modelState, isDelta);
                                continue;
                            }
                            else
                            {
                                instance.modelState = ModelState.DeserializeLengthDelimited(stream);
                                continue;
                            }
                        }
                    }
                    else if (instance.metabolism != null)
                    {
                        PlayerMetabolism.DeserializeLengthDelimited(stream, instance.metabolism, isDelta);
                        continue;
                    }
                    else
                    {
                        instance.metabolism = PlayerMetabolism.DeserializeLengthDelimited(stream);
                        continue;
                    }
                }
                else if (num <= 64)
                {
                    if (num == 56)
                    {
                        instance.playerFlags = (int)ProtocolParser.ReadUInt64(stream);
                        continue;
                    }
                    else if (num == 64)
                    {
                        instance.heldEntity = ProtocolParser.ReadUInt32(stream);
                        continue;
                    }
                }
                else if (num == 77)
                {
                    instance.health = ProtocolParser.ReadSingle(stream);
                    continue;
                }
                else if (num != 82)
                {
                    if (num == 125)
                    {
                        instance.skinCol = ProtocolParser.ReadSingle(stream);
                        continue;
                    }
                }
                else if (instance.persistantData != null)
                {
                    PersistantPlayer.DeserializeLengthDelimited(stream, instance.persistantData, isDelta);
                    continue;
                }
                else
                {
                    instance.persistantData = PersistantPlayer.DeserializeLengthDelimited(stream);
                    continue;
                }
                Key  key   = ProtocolParser.ReadKey((byte)num, stream);
                uint field = key.Field;
                if (field == 0)
                {
                    throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                }
                switch (field)
                {
                case 16:
                {
                    if (key.WireType != Wire.Fixed32)
                    {
                        continue;
                    }
                    instance.skinTex = ProtocolParser.ReadSingle(stream);
                    continue;
                }

                case 17:
                {
                    if (key.WireType != Wire.Fixed32)
                    {
                        continue;
                    }
                    instance.skinMesh = ProtocolParser.ReadSingle(stream);
                    continue;
                }

                case 18:
                case 19:
                {
                    ProtocolParser.SkipKey(stream, key);
                    continue;
                }

                case 20:
                {
                    if (key.WireType != Wire.LengthDelimited)
                    {
                        continue;
                    }
                    if (instance.currentLife != null)
                    {
                        PlayerLifeStory.DeserializeLengthDelimited(stream, instance.currentLife, isDelta);
                        continue;
                    }
                    else
                    {
                        instance.currentLife = PlayerLifeStory.DeserializeLengthDelimited(stream);
                        continue;
                    }
                }

                case 21:
                {
                    if (key.WireType != Wire.LengthDelimited)
                    {
                        continue;
                    }
                    if (instance.previousLife != null)
                    {
                        PlayerLifeStory.DeserializeLengthDelimited(stream, instance.previousLife, isDelta);
                        continue;
                    }
                    else
                    {
                        instance.previousLife = PlayerLifeStory.DeserializeLengthDelimited(stream);
                        continue;
                    }
                }

                case 22:
                {
                    if (key.WireType != Wire.Varint)
                    {
                        continue;
                    }
                    instance.mounted = ProtocolParser.ReadUInt32(stream);
                    continue;
                }

                case 23:
                {
                    if (key.WireType != Wire.Varint)
                    {
                        continue;
                    }
                    instance.currentTeam = ProtocolParser.ReadUInt64(stream);
                    continue;
                }

                default:
                {
                    goto case 19;
                }
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
예제 #18
0
 public static void SerializeLengthDelimited(Stream stream, PersistantPlayer instance)
 {
     byte[] bytes = PersistantPlayer.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
예제 #19
0
 public void ResetToPool()
 {
     PersistantPlayer.ResetToPool(this);
 }
예제 #20
0
        public static void SerializeDelta(Stream stream, BasePlayer instance, BasePlayer previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.name != null && instance.name != previous.name)
            {
                stream.WriteByte(10);
                ProtocolParser.WriteString(stream, instance.name);
            }
            if (instance.userid != previous.userid)
            {
                stream.WriteByte(16);
                ProtocolParser.WriteUInt64(stream, instance.userid);
            }
            if (instance.inventory != null)
            {
                stream.WriteByte(26);
                memoryStream.SetLength((long)0);
                PlayerInventory.SerializeDelta(memoryStream, instance.inventory, previous.inventory);
                uint length = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            }
            if (instance.metabolism != null)
            {
                stream.WriteByte(34);
                memoryStream.SetLength((long)0);
                PlayerMetabolism.SerializeDelta(memoryStream, instance.metabolism, previous.metabolism);
                uint num = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, num);
                stream.Write(memoryStream.GetBuffer(), 0, (int)num);
            }
            if (instance.modelState != null)
            {
                stream.WriteByte(50);
                memoryStream.SetLength((long)0);
                ModelState.SerializeDelta(memoryStream, instance.modelState, previous.modelState);
                uint length1 = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length1);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length1);
            }
            if (instance.playerFlags != previous.playerFlags)
            {
                stream.WriteByte(56);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.playerFlags);
            }
            if (instance.heldEntity != previous.heldEntity)
            {
                stream.WriteByte(64);
                ProtocolParser.WriteUInt32(stream, instance.heldEntity);
            }
            if (instance.health != previous.health)
            {
                stream.WriteByte(77);
                ProtocolParser.WriteSingle(stream, instance.health);
            }
            if (instance.persistantData != null)
            {
                stream.WriteByte(82);
                memoryStream.SetLength((long)0);
                PersistantPlayer.SerializeDelta(memoryStream, instance.persistantData, previous.persistantData);
                uint num1 = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, num1);
                stream.Write(memoryStream.GetBuffer(), 0, (int)num1);
            }
            if (instance.skinCol != previous.skinCol)
            {
                stream.WriteByte(125);
                ProtocolParser.WriteSingle(stream, instance.skinCol);
            }
            if (instance.skinTex != previous.skinTex)
            {
                stream.WriteByte(133);
                stream.WriteByte(1);
                ProtocolParser.WriteSingle(stream, instance.skinTex);
            }
            if (instance.skinMesh != previous.skinMesh)
            {
                stream.WriteByte(141);
                stream.WriteByte(1);
                ProtocolParser.WriteSingle(stream, instance.skinMesh);
            }
            if (instance.currentLife != null)
            {
                stream.WriteByte(162);
                stream.WriteByte(1);
                memoryStream.SetLength((long)0);
                PlayerLifeStory.SerializeDelta(memoryStream, instance.currentLife, previous.currentLife);
                uint length2 = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length2);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length2);
            }
            if (instance.previousLife != null)
            {
                stream.WriteByte(170);
                stream.WriteByte(1);
                memoryStream.SetLength((long)0);
                PlayerLifeStory.SerializeDelta(memoryStream, instance.previousLife, previous.previousLife);
                uint num2 = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, num2);
                stream.Write(memoryStream.GetBuffer(), 0, (int)num2);
            }
            if (instance.mounted != previous.mounted)
            {
                stream.WriteByte(176);
                stream.WriteByte(1);
                ProtocolParser.WriteUInt32(stream, instance.mounted);
            }
            if (instance.currentTeam != previous.currentTeam)
            {
                stream.WriteByte(184);
                stream.WriteByte(1);
                ProtocolParser.WriteUInt64(stream, instance.currentTeam);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
예제 #21
0
 public void CopyTo(PersistantPlayer instance)
 {
     throw new NotImplementedException();
 }