LoadFromBuffer() 공개 메소드

Loads NBT data from a byte array. Existing RootTag will be replaced. FileName will be set to null.
is null. If an unrecognized/unsupported value was given for ; /// if or is less than zero; /// if the sum of and is greater than the length of . If NBT stream extends beyond the given . If file compression could not be detected or decompressing failed. If an error occurred while parsing data in NBT format.
public LoadFromBuffer ( [ buffer, int index, int length, NbtCompression compression ) : long
buffer [ Stream from which data will be loaded. If is set to AutoDetect, this stream must support seeking.
index int The index into at which the stream begins. Must not be negative.
length int Maximum number of bytes to read from the given buffer. Must not be negative. /// An is thrown if NBT stream is longer than the given length.
compression NbtCompression Compression method to use for loading/saving this file.
리턴 long
예제 #1
0
        public NbtWrapper ReadNBT()
        {
            if (!this.ReadBoolean())
            {
                return null;
            }

            byte[] nbt = new byte[this.ReadInt32(15)];
            for (int nbtIndex = 0; nbtIndex < nbt.Length; nbtIndex++)
            {
                nbt[nbtIndex] = (byte)this.ReadInt32(8);
            }

            var nbtFile = new NbtFile();
            nbtFile.LoadFromBuffer(nbt, 0, nbt.Length, NbtCompression.GZip);
            NbtCompound rootTag = nbtFile.RootTag;

            return new NbtWrapper { OriginalData = nbt, RootTag = rootTag };
        }
예제 #2
0
 public void ReadPacket(MinecraftStream stream)
 {
     X = stream.ReadInt32();
     Y = stream.ReadInt16();
     Z = stream.ReadInt32();
     Action = stream.ReadUInt8();
     var length = stream.ReadInt16();
     var data = stream.ReadUInt8Array(length);
     Nbt = new NbtFile();
     Nbt.LoadFromBuffer(data, 0, length, NbtCompression.GZip, null);
 }
예제 #3
0
파일: Program.cs 프로젝트: Uzere/nlctest
        // страшная вещь
        static void GetData(string from, string to) {
            // эту функцию не следует вообще смотреть
            // страшный, одноразовый, write-only код, задача которого 1 раз распарсить mca файл и самоуничтожиться
            // однако, последняя функция не сработала, поэтому он всё ещё здесь
            var file = File.ReadAllBytes(from);
            for (var chx = 0; chx < 16; chx++) {
                for (var chz = 0; chz < 24; chz++) {
                    var index = SwapEndian(BitConverter.ToUInt32(file, 4 * (32 * chz + chx)));

                    var size = index & 0xFF;
                    var offset = (index >> 8) * 4096; // тут даже есть куча магических констант
                    //Console.WriteLine("{0} {1} {2} {3}", chx, chz, offset, size);
                    //Console.SetCursorPosition(chx, chz);
                    //Console.WriteLine("{0}", size);

                    if (offset != 0 && size != 0) {
                        var nbt = new NbtFile();
                        var length = SwapEndian(BitConverter.ToUInt32(file, (int)offset));
                        nbt.LoadFromBuffer(file, (int)offset + 5, (int)length, NbtCompression.AutoDetect);

                        if (chz < 16) {
                            continue;
                        }

                        var sections = nbt.RootTag.Get<NbtCompound>("Level").Get<NbtList>("Sections");
                        foreach (var section in sections) {
                            //Console.Write("{0}", ((NbtCompound)section).Get<NbtByte>("Y").Value // о, отладочный вывод
                            var sy = ((NbtCompound)section).Get<NbtByte>("Y").Value;
                            var blocks = ((NbtCompound)section).Get<NbtByteArray>("Blocks").Value;
                            for (var by = 0; by < 16; by++) {
                                for (var bz = 0; bz < 16; bz++) {
                                    for (var bx = 0; bx < 16; bx++) {
                                        var gx = chx * 16 + bx;
                                        var gy = sy * 16 + by;
                                        var gz = (chz - 16) * 16 + bz;
                                        chunks[
                                            ((gy / 64) * 4 * 2 + (gz / 64) * 4 + (gx / 64)) * 64 * 64 * 64 * 4 // непонятные формулы
                                            + (64 * 64 * (gy % 64) + 64 * (gz % 64) + (gx % 64)) * 4 // неведомые константы
                                            + 3
                                            ] = blocks[by * 16 * 16 + bz * 16 + bx];
                                        //if(gy==0)Console.WriteLine("{0} {1} {2}", gx, gy, gz); // мм, комментарии с кодом
                                        /* if(gy==0 && gx<32 && gz<32) {
                                             Console.SetCursorPosition(gx, gz);
                                             Console.WriteLine("{0}", blocks[by * 16 * 16 + bz * 16 + bx]%10);
                                         }*/
                                        if (gy == 0 && blocks[by * 16 * 16 + bz * 16 + bx] != 7) {
                                            //Console.WriteLine("{0} {1} {2}", gx, gy, gz);
                                        }
                                    }
                                }

                            }
                        }

                    }

                }
            }

            File.WriteAllBytes(to + "1.bin", chunks);
        }
예제 #4
0
파일: Packets.cs 프로젝트: umby24/Craft.Net
 public NetworkMode ReadPacket(MinecraftStream stream, NetworkMode mode, PacketDirection direction)
 {
     X = stream.ReadInt32();
     Y = stream.ReadInt16();
     Z = stream.ReadInt32();
     Action = stream.ReadUInt8();
     var length = stream.ReadInt16();
     var data = stream.ReadUInt8Array(length);
     Nbt = new NbtFile();
     Nbt.LoadFromBuffer(data, 0, length, NbtCompression.GZip, null);
     return mode;
 }
예제 #5
0
        public ItemStack ToItemStack()
        {
            NbtWrapper nbt = null;
            if (this.NBTData != null)
            {
                var nbtFile = new NbtFile();
                nbtFile.LoadFromBuffer(this.NBTData, 0, this.NBTData.Length, NbtCompression.GZip);

                nbt = new NbtWrapper { RootTag = nbtFile.RootTag, OriginalData = this.NBTData };
            }

            return new ItemStack
            {
                ItemId = this.ItemId,
                Size = this.Size,
                Damage = this.Damage,
                NBT = nbt
            };
        }