void ReadCompressedSegment(BundleSegment segment) { m_input.Position = segment.Offset; int method = segment.Compression & 0x3F; if (1 == method) { m_buffer_len = LzmaDecompressBlock(segment.PackedSize, segment.UnpackedSize); return; } if (null == m_packed || segment.PackedSize > m_packed.Length) { m_packed = new byte[segment.PackedSize]; } int packed_size = m_input.Read(m_packed, 0, (int)segment.PackedSize); var output = PrepareBuffer(segment.UnpackedSize); if (3 == method || 2 == method) { m_buffer_len = Lz4Compressor.DecompressBlock(m_packed, packed_size, output, (int)segment.UnpackedSize); } else { throw new NotImplementedException("Not supported Unity asset bundle compression."); } }
void ReadCompressedSegment(BundleSegment segment) { m_input.Position = segment.Offset; if (null == m_packed || segment.PackedSize > m_packed.Length) { m_packed = new byte[segment.PackedSize]; } int packed_size = m_input.Read(m_packed, 0, (int)segment.PackedSize); if (null == m_buffer || segment.UnpackedSize > m_buffer.Length) { m_buffer = new byte[segment.UnpackedSize]; } if (3 == segment.Compression) { m_buffer_len = Lz4Compressor.DecompressBlock(m_packed, packed_size, m_buffer, (int)segment.UnpackedSize); } else { throw new NotImplementedException("Not supported Unity asset bundle compression."); } }
public override ArcFile TryOpen(ArcView file) { if (!file.View.AsciiEqual(0, "UnityFS\0")) { return(null); } int arc_version = Binary.BigEndian(file.View.ReadInt32(8)); if (arc_version != 6) { return(null); } long data_offset; byte[] index_data; using (var input = file.CreateStream()) { input.Position = 0xC; input.ReadCString(Encoding.UTF8); input.ReadCString(Encoding.UTF8); long file_size = Binary.BigEndian(input.ReadInt64()); int packed_index_size = Binary.BigEndian(input.ReadInt32()); int index_size = Binary.BigEndian(input.ReadInt32()); int flags = Binary.BigEndian(input.ReadInt32()); long index_offset; if (0 == (flags & 0x80)) { index_offset = input.Position; data_offset = index_offset + packed_index_size; } else { index_offset = file_size - packed_index_size; data_offset = input.Position; } input.Position = index_offset; var packed = input.ReadBytes(packed_index_size); switch (flags & 0x3F) { case 0: index_data = packed; break; case 1: index_data = UnpackLzma(packed, index_size); break; case 3: index_data = new byte[index_size]; Lz4Compressor.DecompressBlock(packed, packed.Length, index_data, index_data.Length); break; default: return(null); } } var index = new AssetDeserializer(file, data_offset); using (var input = new BinMemoryStream(index_data)) index.Parse(input); var dir = index.LoadObjects(); return(new UnityBundle(file, this, dir, index.Segments, index.Bundles)); }
public static string GetLibraryName() { return(Lz4Compressor.GetLibraryName()); }