Beispiel #1
0
        public override uint Deserialize(byte[] s, uint offset = 0)
        {
            // deserialize Width
            byte tmp23;

            tmp23   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp23 == 1)
            {
                Width   = BitConverter.ToInt32(s, (int)offset);
                offset += sizeof(int);
            }
            else
            {
                Width = null;
            }

            // deserialize Height
            byte tmp24;

            tmp24   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp24 == 1)
            {
                Height  = BitConverter.ToInt32(s, (int)offset);
                offset += sizeof(int);
            }
            else
            {
                Height = null;
            }

            // deserialize Board
            byte tmp25;

            tmp25   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp25 == 1)
            {
                byte tmp26;
                tmp26   = (byte)s[(int)offset];
                offset += sizeof(byte);
                byte[] tmp27 = new byte[sizeof(uint)];
                Array.Copy(s, offset, tmp27, 0, tmp26);
                offset += tmp26;
                uint tmp28;
                tmp28 = BitConverter.ToUInt32(tmp27, (int)0);

                Board = new List <List <ECell?> >();
                for (uint tmp29 = 0; tmp29 < tmp28; tmp29++)
                {
                    List <ECell?> tmp30;
                    byte          tmp31;
                    tmp31   = (byte)s[(int)offset];
                    offset += sizeof(byte);
                    if (tmp31 == 1)
                    {
                        byte tmp32;
                        tmp32   = (byte)s[(int)offset];
                        offset += sizeof(byte);
                        byte[] tmp33 = new byte[sizeof(uint)];
                        Array.Copy(s, offset, tmp33, 0, tmp32);
                        offset += tmp32;
                        uint tmp34;
                        tmp34 = BitConverter.ToUInt32(tmp33, (int)0);

                        tmp30 = new List <ECell?>();
                        for (uint tmp35 = 0; tmp35 < tmp34; tmp35++)
                        {
                            ECell?tmp36;
                            byte  tmp37;
                            tmp37   = (byte)s[(int)offset];
                            offset += sizeof(byte);
                            if (tmp37 == 1)
                            {
                                sbyte tmp38;
                                tmp38   = (sbyte)s[(int)offset];
                                offset += sizeof(sbyte);
                                tmp36   = (ECell)tmp38;
                            }
                            else
                            {
                                tmp36 = null;
                            }
                            tmp30.Add(tmp36);
                        }
                    }
                    else
                    {
                        tmp30 = null;
                    }
                    Board.Add(tmp30);
                }
            }
            else
            {
                Board = null;
            }

            // deserialize Scores
            byte tmp39;

            tmp39   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp39 == 1)
            {
                byte tmp40;
                tmp40   = (byte)s[(int)offset];
                offset += sizeof(byte);
                byte[] tmp41 = new byte[sizeof(uint)];
                Array.Copy(s, offset, tmp41, 0, tmp40);
                offset += tmp40;
                uint tmp42;
                tmp42 = BitConverter.ToUInt32(tmp41, (int)0);

                Scores = new Dictionary <string, int?>();
                for (uint tmp43 = 0; tmp43 < tmp42; tmp43++)
                {
                    string tmp44;
                    byte   tmp46;
                    tmp46   = (byte)s[(int)offset];
                    offset += sizeof(byte);
                    if (tmp46 == 1)
                    {
                        byte tmp47;
                        tmp47   = (byte)s[(int)offset];
                        offset += sizeof(byte);
                        byte[] tmp48 = new byte[sizeof(uint)];
                        Array.Copy(s, offset, tmp48, 0, tmp47);
                        offset += tmp47;
                        uint tmp49;
                        tmp49 = BitConverter.ToUInt32(tmp48, (int)0);

                        tmp44   = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(s.Skip((int)offset).Take((int)tmp49).ToArray());
                        offset += tmp49;
                    }
                    else
                    {
                        tmp44 = null;
                    }

                    int? tmp45;
                    byte tmp50;
                    tmp50   = (byte)s[(int)offset];
                    offset += sizeof(byte);
                    if (tmp50 == 1)
                    {
                        tmp45   = BitConverter.ToInt32(s, (int)offset);
                        offset += sizeof(int);
                    }
                    else
                    {
                        tmp45 = null;
                    }

                    Scores[tmp44] = tmp45;
                }
            }
            else
            {
                Scores = null;
            }

            // deserialize Pacman
            byte tmp51;

            tmp51   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp51 == 1)
            {
                Pacman = new Pacman();
                offset = Pacman.Deserialize(s, offset);
            }
            else
            {
                Pacman = null;
            }

            // deserialize Ghosts
            byte tmp52;

            tmp52   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp52 == 1)
            {
                byte tmp53;
                tmp53   = (byte)s[(int)offset];
                offset += sizeof(byte);
                byte[] tmp54 = new byte[sizeof(uint)];
                Array.Copy(s, offset, tmp54, 0, tmp53);
                offset += tmp53;
                uint tmp55;
                tmp55 = BitConverter.ToUInt32(tmp54, (int)0);

                Ghosts = new List <Ghost>();
                for (uint tmp56 = 0; tmp56 < tmp55; tmp56++)
                {
                    Ghost tmp57;
                    byte  tmp58;
                    tmp58   = (byte)s[(int)offset];
                    offset += sizeof(byte);
                    if (tmp58 == 1)
                    {
                        tmp57  = new Ghost();
                        offset = tmp57.Deserialize(s, offset);
                    }
                    else
                    {
                        tmp57 = null;
                    }
                    Ghosts.Add(tmp57);
                }
            }
            else
            {
                Ghosts = null;
            }

            // deserialize Constants
            byte tmp59;

            tmp59   = (byte)s[(int)offset];
            offset += sizeof(byte);
            if (tmp59 == 1)
            {
                Constants = new Constants();
                offset    = Constants.Deserialize(s, offset);
            }
            else
            {
                Constants = null;
            }

            return(offset);
        }
Beispiel #2
0
        public override byte[] Serialize()
        {
            List <byte> s = new List <byte>();

            // serialize Width
            s.Add((byte)((Width == null) ? 0 : 1));
            if (Width != null)
            {
                s.AddRange(BitConverter.GetBytes((int)Width));
            }

            // serialize Height
            s.Add((byte)((Height == null) ? 0 : 1));
            if (Height != null)
            {
                s.AddRange(BitConverter.GetBytes((int)Height));
            }

            // serialize Board
            s.Add((byte)((Board == null) ? 0 : 1));
            if (Board != null)
            {
                List <byte> tmp14 = new List <byte>();
                tmp14.AddRange(BitConverter.GetBytes((uint)Board.Count()));
                while (tmp14.Count > 0 && tmp14.Last() == 0)
                {
                    tmp14.RemoveAt(tmp14.Count - 1);
                }
                s.Add((byte)tmp14.Count);
                s.AddRange(tmp14);

                foreach (var tmp15 in Board)
                {
                    s.Add((byte)((tmp15 == null) ? 0 : 1));
                    if (tmp15 != null)
                    {
                        List <byte> tmp16 = new List <byte>();
                        tmp16.AddRange(BitConverter.GetBytes((uint)tmp15.Count()));
                        while (tmp16.Count > 0 && tmp16.Last() == 0)
                        {
                            tmp16.RemoveAt(tmp16.Count - 1);
                        }
                        s.Add((byte)tmp16.Count);
                        s.AddRange(tmp16);

                        foreach (var tmp17 in tmp15)
                        {
                            s.Add((byte)((tmp17 == null) ? 0 : 1));
                            if (tmp17 != null)
                            {
                                s.Add((byte)((sbyte)tmp17));
                            }
                        }
                    }
                }
            }

            // serialize Scores
            s.Add((byte)((Scores == null) ? 0 : 1));
            if (Scores != null)
            {
                List <byte> tmp18 = new List <byte>();
                tmp18.AddRange(BitConverter.GetBytes((uint)Scores.Count()));
                while (tmp18.Count > 0 && tmp18.Last() == 0)
                {
                    tmp18.RemoveAt(tmp18.Count - 1);
                }
                s.Add((byte)tmp18.Count);
                s.AddRange(tmp18);

                foreach (var tmp19 in Scores)
                {
                    s.Add((byte)((tmp19.Key == null) ? 0 : 1));
                    if (tmp19.Key != null)
                    {
                        List <byte> tmp20 = new List <byte>();
                        tmp20.AddRange(BitConverter.GetBytes((uint)tmp19.Key.Count()));
                        while (tmp20.Count > 0 && tmp20.Last() == 0)
                        {
                            tmp20.RemoveAt(tmp20.Count - 1);
                        }
                        s.Add((byte)tmp20.Count);
                        s.AddRange(tmp20);

                        s.AddRange(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(tmp19.Key));
                    }

                    s.Add((byte)((tmp19.Value == null) ? 0 : 1));
                    if (tmp19.Value != null)
                    {
                        s.AddRange(BitConverter.GetBytes((int)tmp19.Value));
                    }
                }
            }

            // serialize Pacman
            s.Add((byte)((Pacman == null) ? 0 : 1));
            if (Pacman != null)
            {
                s.AddRange(Pacman.Serialize());
            }

            // serialize Ghosts
            s.Add((byte)((Ghosts == null) ? 0 : 1));
            if (Ghosts != null)
            {
                List <byte> tmp21 = new List <byte>();
                tmp21.AddRange(BitConverter.GetBytes((uint)Ghosts.Count()));
                while (tmp21.Count > 0 && tmp21.Last() == 0)
                {
                    tmp21.RemoveAt(tmp21.Count - 1);
                }
                s.Add((byte)tmp21.Count);
                s.AddRange(tmp21);

                foreach (var tmp22 in Ghosts)
                {
                    s.Add((byte)((tmp22 == null) ? 0 : 1));
                    if (tmp22 != null)
                    {
                        s.AddRange(tmp22.Serialize());
                    }
                }
            }

            // serialize Constants
            s.Add((byte)((Constants == null) ? 0 : 1));
            if (Constants != null)
            {
                s.AddRange(Constants.Serialize());
            }

            return(s.ToArray());
        }