コード例 #1
0
ファイル: VillageData.cs プロジェクト: circa94/CoCSharp
        public int Unknown4; // 0

        /// <summary>
        /// Reads the <see cref="VillageData"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="VillageData"/>.
        /// </param>
        /// <exception cref="NotImplementedException">Compressed set to false.</exception>
        /// <exception cref="InvalidMessageException">Home data array is null.</exception>
        public void Read(MessageReader reader)
        {
            if (!Compressed)
                throw new NotImplementedException("Uncompressed Village definition is not implemented.");

            Unknown1 = reader.ReadInt32(); // 0
            UserID = reader.ReadInt64();
            ShieldDuration = TimeSpan.FromSeconds(reader.ReadInt32());
            Unknown2 = reader.ReadInt32(); // 1200
            Unknown3 = reader.ReadInt32(); // 60
            Compressed = reader.ReadBoolean();

            var homeData = reader.ReadBytes();
            if (homeData == null)
                throw new InvalidMessageException("No data was provided about Village.");

            using (var br = new BinaryReader(new MemoryStream(homeData))) // little endian
            {
                var decompressedLength = br.ReadInt32();
                var compressedHome = br.ReadBytes(homeData.Length - 4); // -4 to remove the decompressedLength bytes read
                var homeJson = ZlibStream.UncompressString(compressedHome);
                Home = Village.FromJson(homeJson);
            }

            Unknown4 = reader.ReadInt32();
        }