- [Core] Update file foramt.
This commit is contained in:
@@ -8,8 +8,6 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
public class BlbFile
|
public class BlbFile
|
||||||
{
|
{
|
||||||
private const uint DefaultUncompressedSize = 0x20000;
|
|
||||||
|
|
||||||
private List<BundleFile.StorageBlock> m_BlocksInfo;
|
private List<BundleFile.StorageBlock> m_BlocksInfo;
|
||||||
private List<BundleFile.Node> m_DirectoryInfo;
|
private List<BundleFile.Node> m_DirectoryInfo;
|
||||||
|
|
||||||
@@ -34,7 +32,7 @@ namespace AssetStudio
|
|||||||
version = 6,
|
version = 6,
|
||||||
unityVersion = "5.x.x",
|
unityVersion = "5.x.x",
|
||||||
unityRevision = "2017.4.30f1",
|
unityRevision = "2017.4.30f1",
|
||||||
flags = (ArchiveFlags)0x43
|
flags = 0
|
||||||
};
|
};
|
||||||
m_Header.compressedBlocksInfoSize = size;
|
m_Header.compressedBlocksInfoSize = size;
|
||||||
m_Header.uncompressedBlocksInfoSize = size;
|
m_Header.uncompressedBlocksInfoSize = size;
|
||||||
@@ -57,9 +55,10 @@ namespace AssetStudio
|
|||||||
var lastUncompressedSize = reader.ReadUInt32();
|
var lastUncompressedSize = reader.ReadUInt32();
|
||||||
|
|
||||||
reader.Position += 4;
|
reader.Position += 4;
|
||||||
var offset = reader.ReadInt64();
|
var blobOffset = reader.ReadInt32();
|
||||||
|
var blobSize = reader.ReadUInt32();
|
||||||
var compressionType = (CompressionType)reader.ReadByte();
|
var compressionType = (CompressionType)reader.ReadByte();
|
||||||
var serializedFileVersion = (SerializedFileFormatVersion)reader.ReadByte();
|
var uncompressedSize = (uint)1 << reader.ReadByte();
|
||||||
reader.AlignStream();
|
reader.AlignStream();
|
||||||
|
|
||||||
var blocksInfoCount = reader.ReadInt32();
|
var blocksInfoCount = reader.ReadInt32();
|
||||||
@@ -67,7 +66,7 @@ namespace AssetStudio
|
|||||||
|
|
||||||
var blocksInfoOffset = reader.Position + reader.ReadInt64();
|
var blocksInfoOffset = reader.Position + reader.ReadInt64();
|
||||||
var nodesInfoOffset = reader.Position + reader.ReadInt64();
|
var nodesInfoOffset = reader.Position + reader.ReadInt64();
|
||||||
var bundleInfoOffset = reader.Position + reader.ReadInt64();
|
var flagInfoOffset = reader.Position + reader.ReadInt64();
|
||||||
|
|
||||||
reader.Position = blocksInfoOffset;
|
reader.Position = blocksInfoOffset;
|
||||||
m_BlocksInfo = new List<BundleFile.StorageBlock>();
|
m_BlocksInfo = new List<BundleFile.StorageBlock>();
|
||||||
@@ -77,8 +76,8 @@ namespace AssetStudio
|
|||||||
m_BlocksInfo.Add(new BundleFile.StorageBlock
|
m_BlocksInfo.Add(new BundleFile.StorageBlock
|
||||||
{
|
{
|
||||||
compressedSize = reader.ReadUInt32(),
|
compressedSize = reader.ReadUInt32(),
|
||||||
uncompressedSize = i == blocksInfoCount - 1 ? lastUncompressedSize : DefaultUncompressedSize,
|
uncompressedSize = i == blocksInfoCount - 1 ? lastUncompressedSize : uncompressedSize,
|
||||||
flags = (StorageBlockFlags)0x43
|
flags = (StorageBlockFlags)compressionType
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger.Verbose($"Block {i} Info: {m_BlocksInfo[i]}");
|
Logger.Verbose($"Block {i} Info: {m_BlocksInfo[i]}");
|
||||||
@@ -95,9 +94,19 @@ namespace AssetStudio
|
|||||||
size = reader.ReadInt32()
|
size = reader.ReadInt32()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var pos = reader.Position;
|
||||||
|
reader.Position = flagInfoOffset;
|
||||||
|
var flag = reader.ReadUInt32();
|
||||||
|
if (i >= 0x20)
|
||||||
|
{
|
||||||
|
flag = reader.ReadUInt32();
|
||||||
|
}
|
||||||
|
m_DirectoryInfo[i].flags = (uint)(flag & (1 << i)) * 4;
|
||||||
|
reader.Position = pos;
|
||||||
|
|
||||||
var pathOffset = reader.Position + reader.ReadInt64();
|
var pathOffset = reader.Position + reader.ReadInt64();
|
||||||
|
|
||||||
var pos = reader.Position;
|
pos = reader.Position;
|
||||||
reader.Position = pathOffset;
|
reader.Position = pathOffset;
|
||||||
m_DirectoryInfo[i].path = reader.ReadStringToNull();
|
m_DirectoryInfo[i].path = reader.ReadStringToNull();
|
||||||
reader.Position = pos;
|
reader.Position = pos;
|
||||||
@@ -118,34 +127,55 @@ namespace AssetStudio
|
|||||||
return blocksStream;
|
return blocksStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadBlocks(EndianBinaryReader reader, Stream blocksStream)
|
private void ReadBlocks(FileReader reader, Stream blocksStream)
|
||||||
{
|
{
|
||||||
foreach (var blockInfo in m_BlocksInfo)
|
foreach (var blockInfo in m_BlocksInfo)
|
||||||
{
|
{
|
||||||
var compressedSize = (int)blockInfo.compressedSize;
|
var compressionType = (CompressionType)(blockInfo.flags & StorageBlockFlags.CompressionTypeMask);
|
||||||
var uncompressedSize = (int)blockInfo.uncompressedSize;
|
Logger.Verbose($"Block compression type {compressionType}");
|
||||||
|
switch (compressionType) //kStorageBlockCompressionTypeMask
|
||||||
var compressedBytes = ArrayPool<byte>.Shared.Rent(compressedSize);
|
|
||||||
var uncompressedBytes = ArrayPool<byte>.Shared.Rent(uncompressedSize);
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
reader.Read(compressedBytes, 0, compressedSize);
|
case CompressionType.None: //None
|
||||||
|
{
|
||||||
|
reader.BaseStream.CopyTo(blocksStream, blockInfo.compressedSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CompressionType.Lzma: //LZMA
|
||||||
|
{
|
||||||
|
SevenZipHelper.StreamDecompress(reader.BaseStream, blocksStream, blockInfo.compressedSize, blockInfo.uncompressedSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CompressionType.Lz4: //LZ4
|
||||||
|
case CompressionType.Lz4HC: //LZ4HC
|
||||||
|
{
|
||||||
|
var compressedSize = (int)blockInfo.compressedSize;
|
||||||
|
var uncompressedSize = (int)blockInfo.uncompressedSize;
|
||||||
|
|
||||||
var compressedBytesSpan = compressedBytes.AsSpan(0, compressedSize);
|
var compressedBytes = ArrayPool<byte>.Shared.Rent(compressedSize);
|
||||||
var uncompressedBytesSpan = uncompressedBytes.AsSpan(0, uncompressedSize);
|
var uncompressedBytes = ArrayPool<byte>.Shared.Rent(uncompressedSize);
|
||||||
|
|
||||||
var numWrite = LZ4.Decompress(compressedBytesSpan, uncompressedBytesSpan);
|
try
|
||||||
if (numWrite != uncompressedSize)
|
{
|
||||||
{
|
var compressedBytesSpan = compressedBytes.AsSpan(0, compressedSize);
|
||||||
throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
|
var uncompressedBytesSpan = uncompressedBytes.AsSpan(0, uncompressedSize);
|
||||||
}
|
|
||||||
|
|
||||||
blocksStream.Write(uncompressedBytes, 0, uncompressedSize);
|
reader.Read(compressedBytesSpan);
|
||||||
}
|
var numWrite = LZ4.Decompress(compressedBytesSpan, uncompressedBytesSpan);
|
||||||
finally
|
if (numWrite != uncompressedSize)
|
||||||
{
|
{
|
||||||
ArrayPool<byte>.Shared.Return(compressedBytes, true);
|
throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
|
||||||
ArrayPool<byte>.Shared.Return(uncompressedBytes, true);
|
}
|
||||||
|
blocksStream.Write(uncompressedBytesSpan);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ArrayPool<byte>.Shared.Return(compressedBytes, true);
|
||||||
|
ArrayPool<byte>.Shared.Return(uncompressedBytes, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new IOException($"Unsupported compression type {compressionType}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user