Пример #1
0
        public static byte[] ToBytes(StatStringData s)
        {
            List <byte> d = new List <byte>();

            d.AddRange(BitConverter.GetBytes(s.mapflags));
            d.Add(0);
            d.AddRange(BitConverter.GetBytes(s.mapwidth));
            d.AddRange(BitConverter.GetBytes(s.mapheight));
            d.AddRange(s.mapcrc);
            d.AddRange(ConvertUtils.fromStringZ(s.mappath));
            d.AddRange(ConvertUtils.fromStringZ(s.hostname));
            d.Add(0);
            d.AddRange(s.mapsha);
            return(d.ToArray());
        }
Пример #2
0
        public static StatStringData FromBytes(byte[] d)
        {
            if (d.Length < 4 + 2 + 2 + 4 + 20 + 2)
            {
                throw new Exception("Data Mismatch, bytes provided too small");
            }

            BinaryReader br = new BinaryReader(new MemoryStream(d));

            StatStringData s = new StatStringData();

            s.mapflags  = br.ReadInt32();
            s.mapwidth  = br.ReadInt16();
            s.mapheight = br.ReadInt16();
            s.mapcrc    = br.ReadBytes(4);
            s.mappath   = ConvertUtils.parseStringZ(br);
            s.hostname  = ConvertUtils.parseStringZ(br);
            s.mapsha    = br.ReadBytes(20);

            br.Dispose();

            return(s);
        }