Skip to content

Commit e8ca265

Browse files
committed
Fix multiBundle file extraction
1 parent 81ed778 commit e8ca265

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

AssetStudioCLI/Studio.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,36 @@ public static int ExtractFile(string fileName, string savePath)
8787
private static int ExtractBundleFile(FileReader reader, string savePath)
8888
{
8989
Logger.Info($"Decompressing {reader.FileName} ...");
90-
var bundleFile = new BundleFile(reader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
91-
reader.Dispose();
90+
91+
Logger.Debug($"Bundle offset: {reader.Position}");
92+
var count = 0;
93+
var bundleStream = new OffsetStream(reader);
94+
var bundleReader = new FileReader(reader.FullPath, bundleStream);
95+
var bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
96+
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
9297
if (bundleFile.fileList.Length > 0)
9398
{
94-
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
95-
return ExtractStreamFile(extractPath, bundleFile.fileList);
99+
count += ExtractStreamFile(extractPath, bundleFile.fileList);
96100
}
97-
return 0;
101+
while (bundleFile.IsMultiBundle)
102+
{
103+
bundleStream.Offset = reader.Position;
104+
bundleReader = new FileReader($"{reader.FullPath}_0x{bundleStream.Offset:X}", bundleStream);
105+
if (bundleReader.Position > 0)
106+
{
107+
bundleStream.Offset += bundleReader.Position;
108+
bundleReader.FullPath = $"{reader.FullPath}_0x{bundleStream.Offset:X}";
109+
bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}";
110+
}
111+
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
112+
bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
113+
if (bundleFile.fileList.Length > 0)
114+
{
115+
count += ExtractStreamFile(extractPath, bundleFile.fileList);
116+
}
117+
}
118+
bundleStream.Dispose();
119+
return count;
98120
}
99121

100122
private static int ExtractWebDataFile(FileReader reader, string savePath)

AssetStudioGUI/Studio.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,36 @@ public static int ExtractFile(string fileName, string savePath)
135135
private static int ExtractBundleFile(FileReader reader, string savePath)
136136
{
137137
Logger.Info($"Decompressing {reader.FileName} ...");
138-
var bundleFile = new BundleFile(reader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
139-
reader.Dispose();
138+
139+
Logger.Debug($"Bundle offset: {reader.Position}");
140+
var count = 0;
141+
var bundleStream = new OffsetStream(reader);
142+
var bundleReader = new FileReader(reader.FullPath, bundleStream);
143+
var bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
144+
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
140145
if (bundleFile.fileList.Length > 0)
141146
{
142-
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
143-
return ExtractStreamFile(extractPath, bundleFile.fileList);
147+
count += ExtractStreamFile(extractPath, bundleFile.fileList);
144148
}
145-
return 0;
149+
while (bundleFile.IsMultiBundle)
150+
{
151+
bundleStream.Offset = reader.Position;
152+
bundleReader = new FileReader($"{reader.FullPath}_0x{bundleStream.Offset:X}", bundleStream);
153+
if (bundleReader.Position > 0)
154+
{
155+
bundleStream.Offset += bundleReader.Position;
156+
bundleReader.FullPath = $"{reader.FullPath}_0x{bundleStream.Offset:X}";
157+
bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}";
158+
}
159+
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
160+
bundleFile = new BundleFile(bundleReader, assetsManager.ZstdEnabled, assetsManager.SpecifyUnityVersion);
161+
if (bundleFile.fileList.Length > 0)
162+
{
163+
count += ExtractStreamFile(extractPath, bundleFile.fileList);
164+
}
165+
}
166+
bundleStream.Dispose();
167+
return count;
146168
}
147169

148170
private static int ExtractWebDataFile(FileReader reader, string savePath)

0 commit comments

Comments
 (0)