public void LoadLocation(Stream stream) { byte[] locationBuffer = new byte[4096]; stream.Seek(0, SeekOrigin.Begin); stream.Read(locationBuffer, 0, locationBuffer.Length); for (int i = 0; i < 1024; i++) { locations[i] = new ChunkLocation(locationBuffer, i * 4); } }
public ChunkData(Stream stream, ChunkLocation location) { byte[] loadBuffer = new byte[location.SectorCount * 4096]; stream.Seek(location.Offset * 4096, SeekOrigin.Begin); stream.Read(loadBuffer, 0, loadBuffer.Length); // Javaのビッグエンディアンで記述されている為必要なら反転 if (BitConverter.IsLittleEndian) { Array.Reverse(loadBuffer, 0, 4); } uint dataLength = BitConverter.ToUInt32(loadBuffer, 0); // 直前に反転させた場合念のため元に戻す if (BitConverter.IsLittleEndian) { Array.Reverse(loadBuffer, 0, 4); } if (1 == loadBuffer[4]) { CompressionType = ChunkCompressionType.GZip; } else if (2 == loadBuffer[4]) { CompressionType = ChunkCompressionType.Zlib; } else { throw new InvalidDataException("Unknown chunk compression type."); } // length(4byte), 圧縮方式(1byte), RFC1950ヘッダ(2byte:0x789C)をスキップしたデータを渡す // lengthは圧縮方式とRFC1950ヘッダも含む為3byte減らす chunkNBTBinary = Decompress(loadBuffer, 7, (int)dataLength - 3, CompressionType); // キャッシュへ登録 cacheCompressData = new byte[dataLength - 3]; Buffer.BlockCopy(loadBuffer, 7, cacheCompressData, 0, cacheCompressData.Length); doUseCache = true; #if DEBUG originalSectorDump = loadBuffer; #endif }