Fix multiBundle file extraction

This commit is contained in:
VaDiM 2025-03-25 21:54:34 +03:00
parent 81ed77819a
commit e8ca265a43
2 changed files with 54 additions and 10 deletions

View File

@ -87,14 +87,36 @@ namespace AssetStudioCLI
private static int ExtractBundleFile(FileReader reader, string savePath) private static int ExtractBundleFile(FileReader reader, string savePath)
{ {
Logger.Info($"Decompressing {reader.FileName} ..."); Logger.Info($"Decompressing {reader.FileName} ...");
var bundleFile = new BundleFile(reader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
reader.Dispose(); Logger.Debug($"Bundle offset: {reader.Position}");
var count = 0;
var bundleStream = new OffsetStream(reader);
var bundleReader = new FileReader(reader.FullPath, bundleStream);
var bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
if (bundleFile.fileList.Length > 0) if (bundleFile.fileList.Length > 0)
{ {
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); count += ExtractStreamFile(extractPath, bundleFile.fileList);
return ExtractStreamFile(extractPath, bundleFile.fileList);
} }
return 0; while (bundleFile.IsMultiBundle)
{
bundleStream.Offset = reader.Position;
bundleReader = new FileReader($"{reader.FullPath}_0x{bundleStream.Offset:X}", bundleStream);
if (bundleReader.Position > 0)
{
bundleStream.Offset += bundleReader.Position;
bundleReader.FullPath = $"{reader.FullPath}_0x{bundleStream.Offset:X}";
bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}";
}
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
if (bundleFile.fileList.Length > 0)
{
count += ExtractStreamFile(extractPath, bundleFile.fileList);
}
}
bundleStream.Dispose();
return count;
} }
private static int ExtractWebDataFile(FileReader reader, string savePath) private static int ExtractWebDataFile(FileReader reader, string savePath)

View File

@ -135,14 +135,36 @@ namespace AssetStudioGUI
private static int ExtractBundleFile(FileReader reader, string savePath) private static int ExtractBundleFile(FileReader reader, string savePath)
{ {
Logger.Info($"Decompressing {reader.FileName} ..."); Logger.Info($"Decompressing {reader.FileName} ...");
var bundleFile = new BundleFile(reader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
reader.Dispose(); Logger.Debug($"Bundle offset: {reader.Position}");
var count = 0;
var bundleStream = new OffsetStream(reader);
var bundleReader = new FileReader(reader.FullPath, bundleStream);
var bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
if (bundleFile.fileList.Length > 0) if (bundleFile.fileList.Length > 0)
{ {
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); count += ExtractStreamFile(extractPath, bundleFile.fileList);
return ExtractStreamFile(extractPath, bundleFile.fileList);
} }
return 0; while (bundleFile.IsMultiBundle)
{
bundleStream.Offset = reader.Position;
bundleReader = new FileReader($"{reader.FullPath}_0x{bundleStream.Offset:X}", bundleStream);
if (bundleReader.Position > 0)
{
bundleStream.Offset += bundleReader.Position;
bundleReader.FullPath = $"{reader.FullPath}_0x{bundleStream.Offset:X}";
bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}";
}
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
if (bundleFile.fileList.Length > 0)
{
count += ExtractStreamFile(extractPath, bundleFile.fileList);
}
}
bundleStream.Dispose();
return count;
} }
private static int ExtractWebDataFile(FileReader reader, string savePath) private static int ExtractWebDataFile(FileReader reader, string savePath)