mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-11-12 23:32:42 -05:00
Add option to extract raw byte array from MonoBehaviour assets
This commit is contained in:
@ -315,6 +315,31 @@ namespace AssetStudioCLI
|
||||
m_VideoClip.m_VideoData.WriteData(exportFullPath.Replace(".dat", "_data.dat"));
|
||||
}
|
||||
break;
|
||||
case MonoBehaviour m_MonoBehaviour when CLIOptions.f_rawByteArrayFromMono.Value:
|
||||
var reader = m_MonoBehaviour.reader;
|
||||
reader.Reset();
|
||||
var assetData = reader.ReadBytes(28); //PPtr<GameObject> m_GameObject, m_Enabled, PPtr<MonoScript>
|
||||
var assetNameLen = reader.ReadInt32();
|
||||
reader.Position -= 4;
|
||||
var assetNameBytes = reader.ReadBytes(assetNameLen + 4);
|
||||
if (assetNameLen > 0)
|
||||
reader.AlignStream();
|
||||
var arrayLen = reader.ReadInt32();
|
||||
if (arrayLen <= 0 || arrayLen > reader.Remaining)
|
||||
break;
|
||||
using (var outStream = new FileStream(exportFullPath.Replace(".dat", "_extracted.dat"), FileMode.Create))
|
||||
{
|
||||
reader.BaseStream.CopyTo(outStream, size: arrayLen);
|
||||
}
|
||||
using (var outStream = new FileStream(exportFullPath, FileMode.Create))
|
||||
{
|
||||
outStream.Write(assetData, 0, assetData.Length);
|
||||
outStream.Write(assetNameBytes, 0, assetNameBytes.Length);
|
||||
if (reader.Remaining > 0)
|
||||
reader.BaseStream.CopyTo(outStream, size: reader.Remaining);
|
||||
}
|
||||
Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\"");
|
||||
return true;
|
||||
}
|
||||
File.WriteAllBytes(exportFullPath, item.Asset.GetRawData());
|
||||
|
||||
|
||||
@ -128,6 +128,7 @@ namespace AssetStudioCLI.Options
|
||||
public static Option<bool> f_decompressToDisk;
|
||||
public static Option<bool> f_notRestoreExtensionName;
|
||||
public static Option<bool> f_avoidLoadingViaTypetree;
|
||||
public static Option<bool> f_rawByteArrayFromMono;
|
||||
public static Option<bool> f_loadAllAssets;
|
||||
|
||||
static CLIOptions()
|
||||
@ -557,6 +558,15 @@ namespace AssetStudioCLI.Options
|
||||
optionHelpGroup: HelpGroups.Advanced,
|
||||
isFlag: true
|
||||
);
|
||||
f_rawByteArrayFromMono = new GroupedOption<bool>
|
||||
(
|
||||
optionDefaultValue: false,
|
||||
optionName: "--raw-array",
|
||||
optionDescription: "(Flag) If specified, Studio will try to extract raw byte array from MonoBehaviour assets\n(Only for ExportRaw mode)\n",
|
||||
optionExample: "",
|
||||
optionHelpGroup: HelpGroups.Advanced,
|
||||
isFlag: true
|
||||
);
|
||||
f_loadAllAssets = new GroupedOption<bool>
|
||||
(
|
||||
optionDefaultValue: false,
|
||||
@ -741,6 +751,16 @@ namespace AssetStudioCLI.Options
|
||||
f_avoidLoadingViaTypetree.Value = true;
|
||||
flagIndexes.Add(i);
|
||||
break;
|
||||
case "--raw-array":
|
||||
if (o_workMode.Value != WorkMode.ExportRaw)
|
||||
{
|
||||
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{flag.Color(brightYellow)}] flag. This flag is not suitable for the current working mode [{o_workMode.Value}].\n");
|
||||
ShowOptionDescription(f_rawByteArrayFromMono, isFlag: true);
|
||||
return;
|
||||
}
|
||||
f_rawByteArrayFromMono.Value = true;
|
||||
flagIndexes.Add(i);
|
||||
break;
|
||||
case "--load-all":
|
||||
switch (o_workMode.Value)
|
||||
{
|
||||
@ -1431,6 +1451,10 @@ namespace AssetStudioCLI.Options
|
||||
sb.AppendLine($"# Restore TextAsset Extension: {!f_notRestoreExtensionName.Value}");
|
||||
sb.AppendLine($"# Max Parallel Export Tasks: {o_maxParallelExportTasks}");
|
||||
}
|
||||
if (o_workMode.Value == WorkMode.ExportRaw)
|
||||
{
|
||||
sb.AppendLine($"# Extract Raw Byte Array From MonoBehaviour: {f_rawByteArrayFromMono}");
|
||||
}
|
||||
sb.AppendLine(ShowCurrentFilter());
|
||||
sb.AppendLine($"# Filter With Regex: {f_filterWithRegex}");
|
||||
sb.AppendLine($"# Assembly Path: \"{o_assemblyPath}\"");
|
||||
|
||||
Reference in New Issue
Block a user