Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions AssetStudioCLI/Options/CLIOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ internal static class CLIOptions
public static Option<bool> f_avoidLoadingViaTypetree;
public static Option<bool> f_rawByteArrayFromMono;
public static Option<bool> f_loadAllAssets;
public static Option<bool> f_spriteWithCanvas;

static CLIOptions()
{
Expand Down Expand Up @@ -286,7 +287,7 @@ private static void InitOptions()
optionExample: "Example: \"--log-level warning\"\n",
optionHelpGroup: HelpGroups.Logger
);
o_logOutput = new GroupedOption<LogOutputMode>
o_logOutput = new GroupedOption<LogOutputMode>
(
optionDefaultValue: LogOutputMode.Console,
optionName: "--log-output <value>",
Expand Down Expand Up @@ -350,9 +351,9 @@ private static void InitOptions()
(
optionDefaultValue: false,
optionName: "--l2d-search-by-filename",
optionDescription: "(Flag) If specified, Studio will search for model-related Live2D assets by file name\n" +
optionDescription: "(Flag) If specified, Studio will search for model-related Live2D assets by file name\n" +
"rather than by container\n" +
"(Preferred option if all l2d assets of a single model are stored in a single file\n" +
"(Preferred option if all l2d assets of a single model are stored in a single file\n" +
"or containers are obfuscated)\n",
optionExample: "",
optionHelpGroup: HelpGroups.Live2D,
Expand Down Expand Up @@ -393,7 +394,7 @@ private static void InitOptions()
(
optionDefaultValue: AnimationExportMode.Auto,
optionName: "--fbx-animation",
optionDescription: "Specify the FBX animation export mode\n" +
optionDescription: "Specify the FBX animation export mode\n" +
"<Value: auto(default) | skip | all>\n" +
"Auto - Search for model-related animations and export model with them\n" +
"Skip - Don't export animations\n" +
Expand Down Expand Up @@ -468,7 +469,7 @@ private static void InitOptions()
(
optionDefaultValue: CompressionType.Auto,
optionName: "--blockinfo-comp <value>",
optionDescription: "Specify the compression type of bundle's blockInfo data\n" +
optionDescription: "Specify the compression type of bundle's blockInfo data\n" +
"<Value: auto(default) | zstd | oodle | lz4 | lzma>\n" +
"Auto - Use compression type specified in an asset bundle\n" +
"Zstd - Try to decompress as zstd archive\n" +
Expand Down Expand Up @@ -576,6 +577,15 @@ private static void InitOptions()
optionHelpGroup: HelpGroups.Advanced,
isFlag: true
);
f_spriteWithCanvas = new GroupedOption<bool>
(
optionDefaultValue: false,
optionName: "--sprite-with-canvas",
optionDescription: "(Flag) If specified, If specified, the exported sprite will include the entire canvas size instead of only the cropped section",
optionExample: "",
optionHelpGroup: HelpGroups.Advanced,
isFlag: true
);
#endregion
}

Expand Down Expand Up @@ -776,6 +786,10 @@ public static void ParseArgs(string[] args)
return;
}
break;
case "--sprite-with-canvas":
f_spriteWithCanvas.Value = true;
flagIndexes.Add(i);
break;
}
}
for (var i = 0; i < flagIndexes.Count; i++)
Expand Down Expand Up @@ -1067,35 +1081,35 @@ public static void ParseArgs(string[] args)
}
break;
case "--fbx-scale-factor":
{
var isFloat = float.TryParse(value, out var floatValue);
if (isFloat && floatValue >= 0 && floatValue <= 100)
{
o_fbxScaleFactor.Value = floatValue;
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported scale factor value: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_fbxScaleFactor);
return;
var isFloat = float.TryParse(value, out var floatValue);
if (isFloat && floatValue >= 0 && floatValue <= 100)
{
o_fbxScaleFactor.Value = floatValue;
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported scale factor value: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_fbxScaleFactor);
return;
}
break;
}
break;
}
case "--fbx-bone-size":
{
var isInt = int.TryParse(value, out var intValue);
if (isInt && intValue >= 0 && intValue <= 100)
{
o_fbxBoneSize.Value = intValue;
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported bone size value: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_fbxBoneSize);
return;
var isInt = int.TryParse(value, out var intValue);
if (isInt && intValue >= 0 && intValue <= 100)
{
o_fbxBoneSize.Value = intValue;
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported bone size value: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_fbxBoneSize);
return;
}
break;
}
break;
}
case "--fbx-animation":
switch (value.ToLower())
{
Expand Down Expand Up @@ -1165,28 +1179,28 @@ public static void ParseArgs(string[] args)
}
break;
case "--max-export-tasks":
{
var processorCount = Environment.ProcessorCount;
if (value.ToLower() == "max")
{
o_maxParallelExportTasks.Value = processorCount - 1;
}
else
{
var isInt = int.TryParse(value, out var intValue);
if (isInt && intValue >= 0 && intValue <= processorCount)
var processorCount = Environment.ProcessorCount;
if (value.ToLower() == "max")
{
o_maxParallelExportTasks.Value = Math.Min(intValue, processorCount - 1);
o_maxParallelExportTasks.Value = processorCount - 1;
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported number of parallel tasks: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_maxParallelExportTasks);
return;
var isInt = int.TryParse(value, out var intValue);
if (isInt && intValue >= 0 && intValue <= processorCount)
{
o_maxParallelExportTasks.Value = Math.Min(intValue, processorCount - 1);
}
else
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported number of parallel tasks: [{value.Color(brightRed)}].\n");
ShowOptionDescription(o_maxParallelExportTasks);
return;
}
}
break;
}
break;
}
case "--export-asset-list":
switch (value.ToLower())
{
Expand Down Expand Up @@ -1407,7 +1421,7 @@ public static void ShowCurrentOptions()
{
var unityVer = o_unityVersion.Value?.ToString();
unityVer = string.IsNullOrEmpty(unityVer) ? "ReadFromAsset" : unityVer;

var sb = new StringBuilder();
sb.AppendLine("[Current Options]");
sb.AppendLine($"# Working Mode: {o_workMode}");
Expand Down
3 changes: 2 additions & 1 deletion AssetStudioCLI/ParallelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public static bool ExportSprite(AssetItem item, string exportPath, out string de
debugLog = "";
var type = CLIOptions.o_imageFormat.Value;
var alphaMask = SpriteMaskMode.On;
var spriteWithCanvas = CLIOptions.f_spriteWithCanvas.Value;
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
return false;
var image = ((Sprite)item.Asset).GetImage(alphaMask);
var image = ((Sprite)item.Asset).GetImage(alphaMask, spriteWithCanvas: spriteWithCanvas);
if (image != null)
{
using (image)
Expand Down
4 changes: 3 additions & 1 deletion AssetStudioCLI/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AssetStudioModCLI <input path to asset file(s)/folder> [-m, --mode <value>]
[--export-asset-list <value>] [--assembly-folder <path>]
[--unity-version <text>] [--decompress-to-disk]
[--not-restore-extension] [--ignore-typetree]
[--load-all]
[--load-all] [--sprite-with-canvas]

General Options:
-m, --mode <value> Specify working mode
Expand Down Expand Up @@ -197,4 +197,6 @@ Advanced Options:

--load-all (Flag) If specified, Studio will load assets of all types
(Only for Dump, Info and ExportRaw modes)

--sprite-with-canvas (Flag) If specified, the exported sprite will include the entire canvas size instead of only the cropped section
```
Loading