Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
Fixed bundle reading for Unity 5.3+ bundles with LZMA
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Sep 14, 2016
1 parent f7948e5 commit 88d78e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Unity Studio/7zip/SevenZipHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,23 @@ public static MemoryStream StreamDecompress(MemoryStream newInStream)
return newOutStream;
}

public static MemoryStream StreamDecompress(MemoryStream newInStream, long outSize)
{
SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();

newInStream.Seek(0, 0);
MemoryStream newOutStream = new MemoryStream();

byte[] properties2 = new byte[5];
if (newInStream.Read(properties2, 0, 5) != 5)
throw (new Exception("input .lzma is too short"));
decoder.SetDecoderProperties(properties2);

long compressedSize = newInStream.Length - newInStream.Position;
decoder.Code(newInStream, newOutStream, compressedSize, outSize, null);

newOutStream.Position = 0;
return newOutStream;
}
}
}
2 changes: 1 addition & 1 deletion Unity Studio/BundleFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void readBundle(EndianStream b_Stream)
var uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = SevenZip.Compression.LZMA.SevenZipHelper.StreamDecompress(mstream);
var decoder = SevenZip.Compression.LZMA.SevenZipHelper.StreamDecompress(mstream, uncompressedSize);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
Expand Down

0 comments on commit 88d78e5

Please sign in to comment.