internal void SaveChunk(AnvilChunk chunk)
        {
            RegionFile  f        = FetchRegion(chunk.Coord.RegionCoord);
            TagCompound chunkTag = chunk.BuildTag();

            using (Stream stream = f.WriteChunk(new ChunkCoord(chunk.Coord.X & 31, chunk.Coord.Z & 31)))
            {
                NBTFile.ToStream(stream, chunkTag);
            }
        }
Exemple #2
0
        /// <summary>
        /// 根绝salt生成nbt字节数组
        /// </summary>
        /// <param name="salt"></param>
        /// <returns></returns>
        public static byte[] GetSaltNBTDataArrayFromSaltString(string salt, bool is112)
        {
            MemoryStream ms  = new MemoryStream();
            TagCompound  tag = new TagCompound();

            tag.Add("salt", Encoding.UTF8.GetBytes(salt));
            NBTFile.ToStream(ms, tag, !is112);
            byte[] data = ms.ToArray();

            MemoryStream ms2 = new MemoryStream();

            using (BinaryWriter bw = new BinaryWriter(ms2))
            {
                bw.Write((byte)0);
                if (!is112)
                {
                    bw.WriteUInt16BE((UInt16)data.Length);
                }
                bw.Write(data);
            }
            return(ms2.ToArray());
        }
Exemple #3
0
        /// <summary>
        /// 获取nbt数据从md5和salt
        /// </summary>
        public static byte[] GetMd5NBTByteArray(bool isUseRSA, List <string> md5s, string salt, bool is112)
        {
            TagCompound tagCompound = new TagCompound();
            TagList     tagList     = new TagList();

            foreach (string md5 in md5s)
            {
                string newMd5   = EncryptionUtil.MD5(md5 + salt);
                byte[] md5bytes = Encoding.UTF8.GetBytes(newMd5);
                if (isUseRSA)
                {
                    md5bytes = ASACUtil.RSAEncodeMD5(md5bytes);
                }
                TagByteArray byteArray = new TagByteArray(md5bytes);
                tagList.Add(byteArray);
            }
            tagCompound.Add("md5s", tagList);

            MemoryStream tagCompoundMS = new MemoryStream();

            NBTFile.ToStream(tagCompoundMS, tagCompound, !is112);
            byte[] tagCompoundByteArray = tagCompoundMS.ToArray();
            return(tagCompoundByteArray);
        }