public LoadFromBuffer ( [ buffer, int index, int length, NbtCompression compression ) : long | ||
buffer | [ | Stream from which data will be loaded. If |
index | int | The index into |
length | int | Maximum number of bytes to read from the given buffer. Must not be negative.
/// An |
compression | NbtCompression | Compression method to use for loading/saving this file. |
return | long |
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 }; }
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); }
// страшная вещь 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); }
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; }
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 }; }