added option to support version stripped files, close #766

This commit is contained in:
Perfare 2021-06-29 10:32:19 +08:00
parent 973a1076e4
commit c1cddce031
4 changed files with 55 additions and 13 deletions

View File

@ -9,6 +9,7 @@ namespace AssetStudio
{ {
public class AssetsManager public class AssetsManager
{ {
public string SpecifyUnityVersion;
public List<SerializedFile> assetsFileList = new List<SerializedFile>(); public List<SerializedFile> assetsFileList = new List<SerializedFile>();
internal Dictionary<string, int> assetsFileIndexCache = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); internal Dictionary<string, int> assetsFileIndexCache = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
internal Dictionary<string, BinaryReader> resourceFileReaders = new Dictionary<string, BinaryReader>(StringComparer.OrdinalIgnoreCase); internal Dictionary<string, BinaryReader> resourceFileReaders = new Dictionary<string, BinaryReader>(StringComparer.OrdinalIgnoreCase);
@ -82,6 +83,7 @@ namespace AssetStudio
try try
{ {
var assetsFile = new SerializedFile(this, fullName, reader); var assetsFile = new SerializedFile(this, fullName, reader);
CheckStrippedVersion(assetsFile);
assetsFileList.Add(assetsFile); assetsFileList.Add(assetsFile);
assetsFileListHash.Add(assetsFile.fileName); assetsFileListHash.Add(assetsFile.fileName);
@ -130,10 +132,11 @@ namespace AssetStudio
{ {
var assetsFile = new SerializedFile(this, fullName, reader); var assetsFile = new SerializedFile(this, fullName, reader);
assetsFile.originalPath = originalPath; assetsFile.originalPath = originalPath;
if (assetsFile.header.m_Version < SerializedFileFormatVersion.kUnknown_7) if (!string.IsNullOrEmpty(unityVersion) && assetsFile.header.m_Version < SerializedFileFormatVersion.kUnknown_7)
{ {
assetsFile.SetVersion(unityVersion); assetsFile.SetVersion(unityVersion);
} }
CheckStrippedVersion(assetsFile);
assetsFileList.Add(assetsFile); assetsFileList.Add(assetsFile);
assetsFileListHash.Add(assetsFile.fileName); assetsFileListHash.Add(assetsFile.fileName);
} }
@ -218,6 +221,18 @@ namespace AssetStudio
} }
} }
public void CheckStrippedVersion(SerializedFile assetsFile)
{
if (assetsFile.IsVersionStripped && string.IsNullOrEmpty(SpecifyUnityVersion))
{
throw new Exception("The Unity version has been stripped, please set the version in the options");
}
if (!string.IsNullOrEmpty(SpecifyUnityVersion))
{
assetsFile.SetVersion(SpecifyUnityVersion);
}
}
public void Clear() public void Clear()
{ {
foreach (var assetsFile in assetsFileList) foreach (var assetsFile in assetsFileList)

View File

@ -219,11 +219,14 @@ namespace AssetStudio
public void SetVersion(string stringVersion) public void SetVersion(string stringVersion)
{ {
unityVersion = stringVersion; if (stringVersion != strippedVersion)
var buildSplit = Regex.Replace(stringVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); {
buildType = new BuildType(buildSplit[0]); unityVersion = stringVersion;
var versionSplit = Regex.Replace(stringVersion, @"\D", ".").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); var buildSplit = Regex.Replace(stringVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
version = versionSplit.Select(int.Parse).ToArray(); buildType = new BuildType(buildSplit[0]);
var versionSplit = Regex.Replace(stringVersion, @"\D", ".").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
version = versionSplit.Select(int.Parse).ToArray();
}
} }
private SerializedType ReadSerializedType(bool isRefType) private SerializedType ReadSerializedType(bool isRefType)
@ -371,6 +374,10 @@ namespace AssetStudio
ObjectsDic.Add(obj.m_PathID, obj); ObjectsDic.Add(obj.m_PathID, obj);
} }
public bool IsVersionStripped => unityVersion == strippedVersion;
private const string strippedVersion = "0.0.0";
public static bool IsSerializedFile(EndianBinaryReader reader) public static bool IsSerializedFile(EndianBinaryReader reader)
{ {
var fileSize = reader.BaseStream.Length; var fileSize = reader.BaseStream.Length;

View File

@ -41,6 +41,8 @@
this.displayAll = new System.Windows.Forms.ToolStripMenuItem(); this.displayAll = new System.Windows.Forms.ToolStripMenuItem();
this.enablePreview = new System.Windows.Forms.ToolStripMenuItem(); this.enablePreview = new System.Windows.Forms.ToolStripMenuItem();
this.displayInfo = new System.Windows.Forms.ToolStripMenuItem(); this.displayInfo = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem14 = new System.Windows.Forms.ToolStripMenuItem();
this.specifyUnityVersion = new System.Windows.Forms.ToolStripTextBox();
this.showExpOpt = new System.Windows.Forms.ToolStripMenuItem(); this.showExpOpt = new System.Windows.Forms.ToolStripMenuItem();
this.modelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.modelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportAllObjectssplitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.exportAllObjectssplitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
@ -210,6 +212,7 @@
this.displayAll, this.displayAll,
this.enablePreview, this.enablePreview,
this.displayInfo, this.displayInfo,
this.toolStripMenuItem14,
this.showExpOpt}); this.showExpOpt});
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21); this.optionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21);
@ -249,6 +252,20 @@
"t, audio bitrate, etc."; "t, audio bitrate, etc.";
this.displayInfo.CheckedChanged += new System.EventHandler(this.displayAssetInfo_Check); this.displayInfo.CheckedChanged += new System.EventHandler(this.displayAssetInfo_Check);
// //
// toolStripMenuItem14
//
this.toolStripMenuItem14.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.specifyUnityVersion});
this.toolStripMenuItem14.Name = "toolStripMenuItem14";
this.toolStripMenuItem14.Size = new System.Drawing.Size(223, 22);
this.toolStripMenuItem14.Text = "Specify Unity version";
//
// specifyUnityVersion
//
this.specifyUnityVersion.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F);
this.specifyUnityVersion.Name = "specifyUnityVersion";
this.specifyUnityVersion.Size = new System.Drawing.Size(100, 23);
//
// showExpOpt // showExpOpt
// //
this.showExpOpt.Name = "showExpOpt"; this.showExpOpt.Name = "showExpOpt";
@ -429,7 +446,7 @@
// toolStripSeparator2 // toolStripSeparator2
// //
this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(396, 6); this.toolStripSeparator2.Size = new System.Drawing.Size(281, 6);
// //
// toolStripMenuItem10 // toolStripMenuItem10
// //
@ -438,27 +455,27 @@
this.toolStripMenuItem12, this.toolStripMenuItem12,
this.toolStripMenuItem13}); this.toolStripMenuItem13});
this.toolStripMenuItem10.Name = "toolStripMenuItem10"; this.toolStripMenuItem10.Name = "toolStripMenuItem10";
this.toolStripMenuItem10.Size = new System.Drawing.Size(399, 34); this.toolStripMenuItem10.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItem10.Text = "Asset list to XML"; this.toolStripMenuItem10.Text = "Asset list to XML";
// //
// toolStripMenuItem11 // toolStripMenuItem11
// //
this.toolStripMenuItem11.Name = "toolStripMenuItem11"; this.toolStripMenuItem11.Name = "toolStripMenuItem11";
this.toolStripMenuItem11.Size = new System.Drawing.Size(270, 34); this.toolStripMenuItem11.Size = new System.Drawing.Size(165, 22);
this.toolStripMenuItem11.Text = "All assets"; this.toolStripMenuItem11.Text = "All assets";
this.toolStripMenuItem11.Click += new System.EventHandler(this.toolStripMenuItem11_Click); this.toolStripMenuItem11.Click += new System.EventHandler(this.toolStripMenuItem11_Click);
// //
// toolStripMenuItem12 // toolStripMenuItem12
// //
this.toolStripMenuItem12.Name = "toolStripMenuItem12"; this.toolStripMenuItem12.Name = "toolStripMenuItem12";
this.toolStripMenuItem12.Size = new System.Drawing.Size(270, 34); this.toolStripMenuItem12.Size = new System.Drawing.Size(165, 22);
this.toolStripMenuItem12.Text = "Selected assets"; this.toolStripMenuItem12.Text = "Selected assets";
this.toolStripMenuItem12.Click += new System.EventHandler(this.toolStripMenuItem12_Click); this.toolStripMenuItem12.Click += new System.EventHandler(this.toolStripMenuItem12_Click);
// //
// toolStripMenuItem13 // toolStripMenuItem13
// //
this.toolStripMenuItem13.Name = "toolStripMenuItem13"; this.toolStripMenuItem13.Name = "toolStripMenuItem13";
this.toolStripMenuItem13.Size = new System.Drawing.Size(270, 34); this.toolStripMenuItem13.Size = new System.Drawing.Size(165, 22);
this.toolStripMenuItem13.Text = "Filtered assets"; this.toolStripMenuItem13.Text = "Filtered assets";
this.toolStripMenuItem13.Click += new System.EventHandler(this.toolStripMenuItem13_Click); this.toolStripMenuItem13.Click += new System.EventHandler(this.toolStripMenuItem13_Click);
// //
@ -1178,6 +1195,8 @@
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem11; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem11;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem12; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem12;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem13; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem13;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem14;
private System.Windows.Forms.ToolStripTextBox specifyUnityVersion;
} }
} }

View File

@ -116,7 +116,7 @@ namespace AssetStudioGUI
if (paths.Length > 0) if (paths.Length > 0)
{ {
ResetForm(); ResetForm();
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
if (paths.Length == 1 && Directory.Exists(paths[0])) if (paths.Length == 1 && Directory.Exists(paths[0]))
{ {
await Task.Run(() => assetsManager.LoadFolder(paths[0])); await Task.Run(() => assetsManager.LoadFolder(paths[0]));
@ -125,7 +125,6 @@ namespace AssetStudioGUI
{ {
await Task.Run(() => assetsManager.LoadFiles(paths)); await Task.Run(() => assetsManager.LoadFiles(paths));
} }
BuildAssetStructures(); BuildAssetStructures();
} }
} }
@ -135,6 +134,7 @@ namespace AssetStudioGUI
if (openFileDialog1.ShowDialog() == DialogResult.OK) if (openFileDialog1.ShowDialog() == DialogResult.OK)
{ {
ResetForm(); ResetForm();
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
await Task.Run(() => assetsManager.LoadFiles(openFileDialog1.FileNames)); await Task.Run(() => assetsManager.LoadFiles(openFileDialog1.FileNames));
BuildAssetStructures(); BuildAssetStructures();
} }
@ -146,6 +146,7 @@ namespace AssetStudioGUI
if (openFolderDialog.ShowDialog(this) == DialogResult.OK) if (openFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
ResetForm(); ResetForm();
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
await Task.Run(() => assetsManager.LoadFolder(openFolderDialog.Folder)); await Task.Run(() => assetsManager.LoadFolder(openFolderDialog.Folder));
BuildAssetStructures(); BuildAssetStructures();
} }