public static void Serialize(Stream stream, GameActorInfoDeltaView instance)
        {
            if (instance != null)
            {
                Int32Proxy.Serialize(stream, instance.DeltaMask);
                ByteProxy.Serialize(stream, instance.Id);

                if ((instance.DeltaMask & 1) != 0)
                {
                    EnumProxy <MemberAccessLevel> .Serialize(stream, (MemberAccessLevel)((int)instance.Changes[GameActorInfoDeltaView.Keys.AccessLevel]));
                }
                if ((instance.DeltaMask & 2) != 0)
                {
                    ByteProxy.Serialize(stream, (byte)instance.Changes[GameActorInfoDeltaView.Keys.ArmorPointCapacity]);
                }
                if ((instance.DeltaMask & 4) != 0)
                {
                    ByteProxy.Serialize(stream, (byte)instance.Changes[GameActorInfoDeltaView.Keys.ArmorPoints]);
                }
                if ((instance.DeltaMask & 8) != 0)
                {
                    EnumProxy <ChannelType> .Serialize(stream, (ChannelType)((int)instance.Changes[GameActorInfoDeltaView.Keys.Channel]));
                }
                if ((instance.DeltaMask & 16) != 0)
                {
                    StringProxy.Serialize(stream, (string)instance.Changes[GameActorInfoDeltaView.Keys.ClanTag]);
                }
                if ((instance.DeltaMask & 32) != 0)
                {
                    Int32Proxy.Serialize(stream, (int)instance.Changes[GameActorInfoDeltaView.Keys.Cmid]);
                }
                if ((instance.DeltaMask & 64) != 0)
                {
                    EnumProxy <FireMode> .Serialize(stream, (FireMode)((int)instance.Changes[GameActorInfoDeltaView.Keys.CurrentFiringMode]));
                }
                if ((instance.DeltaMask & 128) != 0)
                {
                    ByteProxy.Serialize(stream, (byte)instance.Changes[GameActorInfoDeltaView.Keys.CurrentWeaponSlot]);
                }
                if ((instance.DeltaMask & 256) != 0)
                {
                    Int16Proxy.Serialize(stream, (short)instance.Changes[GameActorInfoDeltaView.Keys.Deaths]);
                }
                if ((instance.DeltaMask & 512) != 0)
                {
                    ListProxy <int> .Serialize(stream, (List <int>) instance.Changes[GameActorInfoDeltaView.Keys.FunctionalItems], Int32Proxy.Serialize);
                }
                if ((instance.DeltaMask & 1024) != 0)
                {
                    ListProxy <int> .Serialize(stream, (List <int>) instance.Changes[GameActorInfoDeltaView.Keys.Gear], Int32Proxy.Serialize);
                }
                if ((instance.DeltaMask & 2048) != 0)
                {
                    Int16Proxy.Serialize(stream, (short)instance.Changes[GameActorInfoDeltaView.Keys.Health]);
                }
                if ((instance.DeltaMask & 4096) != 0)
                {
                    Int16Proxy.Serialize(stream, (short)instance.Changes[GameActorInfoDeltaView.Keys.Kills]);
                }
                if ((instance.DeltaMask & 8192) != 0)
                {
                    Int32Proxy.Serialize(stream, (int)instance.Changes[GameActorInfoDeltaView.Keys.Level]);
                }
                if ((instance.DeltaMask & 16384) != 0)
                {
                    UInt16Proxy.Serialize(stream, (ushort)instance.Changes[GameActorInfoDeltaView.Keys.Ping]);
                }
                if ((instance.DeltaMask & 32768) != 0)
                {
                    ByteProxy.Serialize(stream, (byte)instance.Changes[GameActorInfoDeltaView.Keys.PlayerId]);
                }
                if ((instance.DeltaMask & 65536) != 0)
                {
                    StringProxy.Serialize(stream, (string)instance.Changes[GameActorInfoDeltaView.Keys.PlayerName]);
                }
                if ((instance.DeltaMask & 131072) != 0)
                {
                    EnumProxy <PlayerStates> .Serialize(stream, (PlayerStates)((byte)instance.Changes[GameActorInfoDeltaView.Keys.PlayerState]));
                }
                if ((instance.DeltaMask & 262144) != 0)
                {
                    ListProxy <int> .Serialize(stream, (List <int>) instance.Changes[GameActorInfoDeltaView.Keys.QuickItems], Int32Proxy.Serialize);
                }
                if ((instance.DeltaMask & 524288) != 0)
                {
                    ByteProxy.Serialize(stream, (byte)instance.Changes[GameActorInfoDeltaView.Keys.Rank]);
                }
                if ((instance.DeltaMask & 1048576) != 0)
                {
                    ColorProxy.Serialize(stream, (Color)instance.Changes[GameActorInfoDeltaView.Keys.SkinColor]);
                }
                if ((instance.DeltaMask & 2097152) != 0)
                {
                    EnumProxy <SurfaceType> .Serialize(stream, (SurfaceType)((int)instance.Changes[GameActorInfoDeltaView.Keys.StepSound]));
                }
                if ((instance.DeltaMask & 4194304) != 0)
                {
                    EnumProxy <TeamID> .Serialize(stream, (TeamID)((int)instance.Changes[GameActorInfoDeltaView.Keys.TeamID]));
                }
                if ((instance.DeltaMask & 8388608) != 0)
                {
                    ListProxy <int> .Serialize(stream, (List <int>) instance.Changes[GameActorInfoDeltaView.Keys.Weapons], Int32Proxy.Serialize);
                }
            }
            else
            {
                Int32Proxy.Serialize(stream, 0);
            }
        }
Esempio n. 2
0
        public static void Serialize(Stream stream, GameActorInfoView instance)
        {
            int mask = 0;

            using (var bytes = new MemoryStream())
            {
                EnumProxy <MemberAccessLevel> .Serialize(bytes, instance.AccessLevel);

                ByteProxy.Serialize(bytes, instance.ArmorPointCapacity);
                ByteProxy.Serialize(bytes, instance.ArmorPoints);
                EnumProxy <ChannelType> .Serialize(bytes, instance.Channel);

                if (instance.ClanTag != null)
                {
                    StringProxy.Serialize(bytes, instance.ClanTag);
                }
                else
                {
                    mask |= 1;
                }

                Int32Proxy.Serialize(bytes, instance.Cmid);
                EnumProxy <FireMode> .Serialize(bytes, instance.CurrentFiringMode);

                ByteProxy.Serialize(bytes, instance.CurrentWeaponSlot);
                Int16Proxy.Serialize(bytes, instance.Deaths);

                if (instance.FunctionalItems != null)
                {
                    ListProxy <int> .Serialize(bytes, instance.FunctionalItems, new ListProxy <int> .Serializer <int>(Int32Proxy.Serialize));
                }
                else
                {
                    mask |= 2;
                }
                if (instance.Gear != null)
                {
                    ListProxy <int> .Serialize(bytes, instance.Gear, new ListProxy <int> .Serializer <int>(Int32Proxy.Serialize));
                }
                else
                {
                    mask |= 4;
                }

                Int16Proxy.Serialize(bytes, instance.Health);
                Int16Proxy.Serialize(bytes, instance.Kills);
                Int32Proxy.Serialize(bytes, instance.Level);
                UInt16Proxy.Serialize(bytes, instance.Ping);
                ByteProxy.Serialize(bytes, instance.PlayerId);

                if (instance.PlayerName != null)
                {
                    StringProxy.Serialize(bytes, instance.PlayerName);
                }
                else
                {
                    mask |= 8;
                }

                EnumProxy <PlayerStates> .Serialize(bytes, instance.PlayerState);

                if (instance.QuickItems != null)
                {
                    ListProxy <int> .Serialize(bytes, instance.QuickItems, new ListProxy <int> .Serializer <int>(Int32Proxy.Serialize));
                }
                else
                {
                    mask |= 16;
                }

                ByteProxy.Serialize(bytes, instance.Rank);
                ColorProxy.Serialize(bytes, instance.SkinColor);
                EnumProxy <SurfaceType> .Serialize(bytes, instance.StepSound);

                EnumProxy <TeamID> .Serialize(bytes, instance.TeamID);

                if (instance.Weapons != null)
                {
                    ListProxy <int> .Serialize(bytes, instance.Weapons, new ListProxy <int> .Serializer <int>(Int32Proxy.Serialize));
                }
                else
                {
                    mask |= 32;
                }

                Int32Proxy.Serialize(stream, ~mask);
                bytes.WriteTo(stream);
            }
        }