コード例 #1
0
        public PlayerLifeStory Copy()
        {
            PlayerLifeStory playerLifeStory = Pool.Get <PlayerLifeStory>();

            this.CopyTo(playerLifeStory);
            return(playerLifeStory);
        }
コード例 #2
0
        public static void SerializeDelta(Stream stream, RespawnInformation instance, RespawnInformation previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.spawnOptions != null)
            {
                for (int i = 0; i < instance.spawnOptions.Count; i++)
                {
                    RespawnInformation.SpawnOptions item = instance.spawnOptions[i];
                    stream.WriteByte(10);
                    memoryStream.SetLength((long)0);
                    RespawnInformation.SpawnOptions.SerializeDelta(memoryStream, item, item);
                    uint length = (uint)memoryStream.Length;
                    ProtocolParser.WriteUInt32(stream, length);
                    stream.Write(memoryStream.GetBuffer(), 0, (int)length);
                }
            }
            if (instance.previousLife != null)
            {
                stream.WriteByte(18);
                memoryStream.SetLength((long)0);
                PlayerLifeStory.SerializeDelta(memoryStream, instance.previousLife, previous.previousLife);
                uint num = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, num);
                stream.Write(memoryStream.GetBuffer(), 0, (int)num);
            }
            stream.WriteByte(24);
            ProtocolParser.WriteBool(stream, instance.fadeIn);
            Pool.FreeMemoryStream(ref memoryStream);
        }
コード例 #3
0
        public static PlayerLifeStory Deserialize(Stream stream)
        {
            PlayerLifeStory playerLifeStory = Pool.Get <PlayerLifeStory>();

            PlayerLifeStory.Deserialize(stream, playerLifeStory, false);
            return(playerLifeStory);
        }
コード例 #4
0
        public static PlayerLifeStory DeserializeLength(Stream stream, int length)
        {
            PlayerLifeStory playerLifeStory = Pool.Get <PlayerLifeStory>();

            PlayerLifeStory.DeserializeLength(stream, length, playerLifeStory, false);
            return(playerLifeStory);
        }
コード例 #5
0
        public static void Serialize(Stream stream, PlayerLifeStory instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(165);
            stream.WriteByte(6);
            ProtocolParser.WriteSingle(stream, instance.secondsAlive);
            stream.WriteByte(173);
            stream.WriteByte(6);
            ProtocolParser.WriteSingle(stream, instance.metersWalked);
            stream.WriteByte(181);
            stream.WriteByte(6);
            ProtocolParser.WriteSingle(stream, instance.metersRun);
            stream.WriteByte(189);
            stream.WriteByte(6);
            ProtocolParser.WriteSingle(stream, instance.secondsSleeping);
            stream.WriteByte(192);
            stream.WriteByte(6);
            ProtocolParser.WriteUInt32(stream, instance.timeBorn);
            stream.WriteByte(200);
            stream.WriteByte(6);
            ProtocolParser.WriteUInt32(stream, instance.timeDied);
            if (instance.deathInfo != null)
            {
                stream.WriteByte(194);
                stream.WriteByte(12);
                memoryStream.SetLength((long)0);
                PlayerLifeStory.DeathInfo.Serialize(memoryStream, instance.deathInfo);
                uint length = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
コード例 #6
0
 public static PlayerLifeStory Deserialize(byte[] buffer, PlayerLifeStory instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         PlayerLifeStory.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
コード例 #7
0
 public virtual void WriteToStreamDelta(Stream stream, PlayerLifeStory previous)
 {
     if (previous == null)
     {
         PlayerLifeStory.Serialize(stream, this);
         return;
     }
     PlayerLifeStory.SerializeDelta(stream, this, previous);
 }
コード例 #8
0
        public static PlayerLifeStory Deserialize(byte[] buffer)
        {
            PlayerLifeStory playerLifeStory = Pool.Get <PlayerLifeStory>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                PlayerLifeStory.Deserialize(memoryStream, playerLifeStory, false);
            }
            return(playerLifeStory);
        }
コード例 #9
0
 public static byte[] SerializeToBytes(PlayerLifeStory instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         PlayerLifeStory.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
コード例 #10
0
        public static RespawnInformation DeserializeLengthDelimited(Stream stream, RespawnInformation instance, bool isDelta)
        {
            if (!isDelta && instance.spawnOptions == null)
            {
                instance.spawnOptions = Pool.Get <List <RespawnInformation.SpawnOptions> >();
            }
            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)
                {
                    instance.spawnOptions.Add(RespawnInformation.SpawnOptions.DeserializeLengthDelimited(stream));
                }
                else if (num != 18)
                {
                    if (num == 24)
                    {
                        instance.fadeIn = ProtocolParser.ReadBool(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);
                    }
                }
                else if (instance.previousLife != null)
                {
                    PlayerLifeStory.DeserializeLengthDelimited(stream, instance.previousLife, isDelta);
                }
                else
                {
                    instance.previousLife = PlayerLifeStory.DeserializeLengthDelimited(stream);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
コード例 #11
0
 public static void ResetToPool(PlayerLifeStory instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     instance.secondsAlive    = 0f;
     instance.metersWalked    = 0f;
     instance.metersRun       = 0f;
     instance.secondsSleeping = 0f;
     instance.timeBorn        = 0;
     instance.timeDied        = 0;
     if (instance.deathInfo != null)
     {
         instance.deathInfo.ResetToPool();
         instance.deathInfo = null;
     }
     Pool.Free <PlayerLifeStory>(ref instance);
 }
コード例 #12
0
 public void CopyTo(PlayerLifeStory instance)
 {
     instance.secondsAlive    = this.secondsAlive;
     instance.metersWalked    = this.metersWalked;
     instance.metersRun       = this.metersRun;
     instance.secondsSleeping = this.secondsSleeping;
     instance.timeBorn        = this.timeBorn;
     instance.timeDied        = this.timeDied;
     if (this.deathInfo == null)
     {
         instance.deathInfo = null;
         return;
     }
     if (instance.deathInfo == null)
     {
         instance.deathInfo = this.deathInfo.Copy();
         return;
     }
     this.deathInfo.CopyTo(instance.deathInfo);
 }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #15
0
        public static PlayerLifeStory Deserialize(Stream stream, PlayerLifeStory instance, bool isDelta)
        {
            while (true)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    break;
                }
                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 100:
                {
                    if (key.WireType != Wire.Fixed32)
                    {
                        continue;
                    }
                    instance.secondsAlive = ProtocolParser.ReadSingle(stream);
                    continue;
                }

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

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

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

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

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

                default:
                {
                    if (field == 200)
                    {
                        if (key.WireType != Wire.LengthDelimited)
                        {
                            continue;
                        }
                        if (instance.deathInfo != null)
                        {
                            PlayerLifeStory.DeathInfo.DeserializeLengthDelimited(stream, instance.deathInfo, isDelta);
                            continue;
                        }
                        else
                        {
                            instance.deathInfo = PlayerLifeStory.DeathInfo.DeserializeLengthDelimited(stream);
                            continue;
                        }
                    }
                    else
                    {
                        ProtocolParser.SkipKey(stream, key);
                        continue;
                    }
                }
                }
            }
            return(instance);
        }
コード例 #16
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     PlayerLifeStory.Deserialize(stream, this, isDelta);
 }
コード例 #17
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     PlayerLifeStory.DeserializeLength(stream, size, this, isDelta);
 }
コード例 #18
0
 public virtual void WriteToStream(Stream stream)
 {
     PlayerLifeStory.Serialize(stream, this);
 }
コード例 #19
0
 public byte[] ToProtoBytes()
 {
     return(PlayerLifeStory.SerializeToBytes(this));
 }
コード例 #20
0
 public void ToProto(Stream stream)
 {
     PlayerLifeStory.Serialize(stream, this);
 }
コード例 #21
0
 public void ResetToPool()
 {
     PlayerLifeStory.ResetToPool(this);
 }
コード例 #22
0
 public static void SerializeLengthDelimited(Stream stream, PlayerLifeStory instance)
 {
     byte[] bytes = PlayerLifeStory.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }