[GUI] Rework some import options

- Added feature to load and export import options to a file (import options include unity version).
- Added option to always decompress bundles to disk. (Related issue: #58 )
This commit is contained in:
VaDiM
2025-07-27 20:41:33 +03:00
parent c20c07b5f2
commit 36bd3c8342
16 changed files with 568 additions and 239 deletions

View File

@ -30,6 +30,11 @@ namespace AssetStudioCLI
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Progress.Default = new Progress<int>(ShowCurProgressValue);
assetsManager.LoadingViaTypeTreeEnabled = !CLIOptions.f_avoidLoadingViaTypetree.Value;
assetsManager.Options.CustomUnityVersion = CLIOptions.o_unityVersion.Value;
assetsManager.Options.BundleOptions.CustomBlockInfoCompression = CLIOptions.o_bundleBlockInfoCompression.Value;
assetsManager.Options.BundleOptions.CustomBlockCompression = CLIOptions.o_bundleBlockCompression.Value;
assetsManager.OptionLoaders.Clear();
}
private static void ShowCurProgressValue(int value)
@ -94,7 +99,7 @@ namespace AssetStudioCLI
var count = 0;
var bundleStream = new OffsetStream(reader);
var bundleReader = new FileReader(reader.FullPath, bundleStream);
var bundleFile = new BundleFile(bundleReader, assetsManager.CustomBlockInfoCompression, assetsManager.CustomBlockCompression, assetsManager.SpecifyUnityVersion);
var bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions);
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
if (bundleFile.fileList.Count > 0)
{
@ -113,7 +118,7 @@ namespace AssetStudioCLI
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.CustomBlockInfoCompression, assetsManager.CustomBlockCompression, assetsManager.SpecifyUnityVersion, isMultiBundle: true);
bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions, isMultiBundle: true);
if (bundleFile.fileList.Count > 0)
{
count += ExtractStreamFile(extractPath, bundleFile.fileList);
@ -170,16 +175,13 @@ namespace AssetStudioCLI
public static bool LoadAssets()
{
var isLoaded = false;
assetsManager.SpecifyUnityVersion = CLIOptions.o_unityVersion.Value;
assetsManager.CustomBlockInfoCompression = CLIOptions.o_bundleBlockInfoCompression.Value;
assetsManager.CustomBlockCompression = CLIOptions.o_bundleBlockCompression.Value;
assetsManager.LoadingViaTypeTreeEnabled = !CLIOptions.f_avoidLoadingViaTypetree.Value;
if (!CLIOptions.f_loadAllAssets.Value)
{
assetsManager.SetAssetFilter(CLIOptions.o_exportAssetTypes.Value);
}
assetsManager.LoadFilesAndFolders(out _, CLIOptions.inputPathList);
if (assetsManager.assetsFileList.Count == 0)
if (assetsManager.AssetsFileList.Count == 0)
{
Logger.Warning("No Unity file can be loaded.");
}
@ -197,13 +199,13 @@ namespace AssetStudioCLI
var fileAssetsList = new List<AssetItem>();
var tex2dArrayAssetList = new List<AssetItem>();
var objectCount = assetsManager.assetsFileList.Sum(x => x.Objects.Count);
var objectCount = assetsManager.AssetsFileList.Sum(x => x.Objects.Count);
var objectAssetItemDic = new Dictionary<AssetStudio.Object, AssetItem>(objectCount);
var isL2dMode = CLIOptions.o_workMode.Value == WorkMode.Live2D;
Progress.Reset();
var i = 0;
foreach (var assetsFile in assetsManager.assetsFileList)
foreach (var assetsFile in assetsManager.AssetsFileList)
{
var preloadTable = new List<PPtr<AssetStudio.Object>>();
foreach (var asset in assetsFile.Objects)
@ -370,21 +372,21 @@ namespace AssetStudioCLI
BuildTreeStructure(objectAssetItemDic);
}
var log = $"Finished loading {assetsManager.assetsFileList.Count} files with {parsedAssetsList.Count} exportable assets";
var unityVer = assetsManager.assetsFileList[0].version;
var log = $"Finished loading {assetsManager.AssetsFileList.Count} files with {parsedAssetsList.Count} exportable assets";
var unityVer = assetsManager.AssetsFileList[0].version;
long m_ObjectsCount;
if (unityVer > 2020)
{
m_ObjectsCount = assetsManager.assetsFileList.Sum(x => x.m_Objects.LongCount(y =>
m_ObjectsCount = assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y =>
y.classID != (int)ClassIDType.Shader
&& CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID))
);
}
else
{
m_ObjectsCount = assetsManager.assetsFileList.Sum(x => x.m_Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID)));
m_ObjectsCount = assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID)));
}
var objectsCount = assetsManager.assetsFileList.Sum(x => x.Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => k == y.type)));
var objectsCount = assetsManager.AssetsFileList.Sum(x => x.Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => k == y.type)));
if (m_ObjectsCount != objectsCount)
{
log += $" and {m_ObjectsCount - objectsCount} assets failed to read";
@ -397,10 +399,10 @@ namespace AssetStudioCLI
Logger.Info("Building tree structure...");
var treeNodeDictionary = new Dictionary<GameObject, GameObjectNode>();
var assetsFileCount = assetsManager.assetsFileList.Count;
var assetsFileCount = assetsManager.AssetsFileList.Count;
int j = 0;
Progress.Reset();
foreach (var assetsFile in assetsManager.assetsFileList)
foreach (var assetsFile in assetsManager.AssetsFileList)
{
var fileNode = new BaseNode(assetsFile.fileName); //RootNode