diff --git a/AssetStudioCLI/Exporter.cs b/AssetStudioCLI/Exporter.cs index 7b02c93..bbcdbc2 100644 --- a/AssetStudioCLI/Exporter.cs +++ b/AssetStudioCLI/Exporter.cs @@ -77,26 +77,6 @@ namespace AssetStudioCLI return true; } - public static bool ExportAssetBundle(AssetItem item, string exportPath) - { - if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) - return false; - var m_AssetBundle = (AssetBundle)item.Asset; - var str = JsonConvert.SerializeObject(m_AssetBundle, Formatting.Indented); - File.WriteAllText(exportFullPath, str); - return true; - } - - public static bool ExportIndexObject(AssetItem item, string exportPath) - { - if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) - return false; - var m_IndexObject = (IndexObject)item.Asset; - var str = JsonConvert.SerializeObject(m_IndexObject, Formatting.Indented); - File.WriteAllText(exportFullPath, str); - return true; - } - public static bool ExportMiHoYoBinData(AssetItem item, string exportPath) { string exportFullPath; @@ -271,14 +251,20 @@ namespace AssetStudioCLI return false; } - public static bool ExportMaterial(AssetItem item, string exportPath) + public static bool ExportJsonFile(AssetItem item, string exportPath) { if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) return false; - var m_Material = (Material)item.Asset; - var str = JsonConvert.SerializeObject(m_Material, Formatting.Indented); - File.WriteAllText(exportFullPath, str); - return true; + var str = JsonConvert.SerializeObject(item.Asset, Formatting.Indented); + if (!string.IsNullOrEmpty(str) && str != "{}") + { + File.WriteAllText(exportFullPath, str); + return true; + } + else + { + return ExportRawFile(item, exportPath); + } } public static bool ExportRawFile(AssetItem item, string exportPath) @@ -354,20 +340,14 @@ namespace AssetStudioCLI return ExportMovieTexture(item, exportPath); case ClassIDType.Sprite: return ExportSprite(item, exportPath); - case ClassIDType.Material: - return ExportMaterial(item, exportPath); case ClassIDType.Animator: return false; case ClassIDType.AnimationClip: return ExportAnimationClip(item, exportPath); - case ClassIDType.AssetBundle: - return ExportAssetBundle(item, exportPath); - case ClassIDType.IndexObject: - return ExportIndexObject(item, exportPath); case ClassIDType.MiHoYoBinData: return ExportMiHoYoBinData(item, exportPath); default: - return ExportRawFile(item, exportPath); + return ExportJsonFile(item, exportPath); } } diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index bda6c8e..2cff246 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -312,7 +312,7 @@ this.toolStripMenuItem16.Name = "toolStripMenuItem16"; this.toolStripMenuItem16.Size = new System.Drawing.Size(225, 22); this.toolStripMenuItem16.Text = "Specify AI version"; - this.toolStripMenuItem16.MouseHover += new System.EventHandler(this.toolStripMenuItem16_MouseHover); + this.toolStripMenuItem16.DropDownOpening += new System.EventHandler(this.toolStripMenuItem16_DropDownOpening); // // specifyAIVersion // diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index 22d3894..cbfffda 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -139,7 +139,6 @@ namespace AssetStudioGUI specifyGame.SelectedIndexChanged += new EventHandler(toolStripComboBox2_SelectedIndexChanged); Logger.Info($"Target Game is {Studio.Game.DisplayName}"); CABManager.LoadMap(Studio.Game); - Task.Run(() => AIVersionManager.FetchVersions()); } private void AssetStudioGUIForm_DragEnter(object sender, DragEventArgs e) @@ -788,30 +787,22 @@ namespace AssetStudioGUI case Sprite m_Sprite: PreviewSprite(assetItem, m_Sprite); break; - case Material m_Material: - PreviewMaterial(m_Material); - StatusStripUpdate("Can be exported to JSON file."); - break; case Animator _: StatusStripUpdate("Can be exported to FBX file."); - break; + goto default; case AnimationClip _: StatusStripUpdate("Can be exported with Animator or Objects or .anim file."); break; - case AssetBundle m_AssetBundle: - PreviewAssetBundle(m_AssetBundle); - StatusStripUpdate("Can be exported to JSON file."); - break; - case IndexObject m_IndexObject: - PreviewIndexObject(m_IndexObject); - StatusStripUpdate("Can be exported to JSON file."); - break; case MiHoYoBinData m_MiHoYoBinData: - PreviewMiHoYoBinData(m_MiHoYoBinData); + PreviewText(m_MiHoYoBinData.Str); StatusStripUpdate("Can be exported/previewed as JSON if data is a valid JSON (check XOR)."); break; default: var str = assetItem.Asset.Dump(); + if (string.IsNullOrEmpty(str)) + { + str = JsonConvert.SerializeObject(assetItem.Asset, Formatting.Indented); + } if (str != null) { textPreviewBox.Text = str; @@ -1041,23 +1032,6 @@ namespace AssetStudioGUI PreviewText(str); } - private void PreviewAssetBundle(AssetBundle m_AssetBundle) - { - var str = JsonConvert.SerializeObject(m_AssetBundle, Formatting.Indented); - PreviewText(str); - } - - private void PreviewIndexObject(IndexObject m_IndexObject) - { - var str = JsonConvert.SerializeObject(m_IndexObject, Formatting.Indented); - PreviewText(str); - } - - private void PreviewMiHoYoBinData(MiHoYoBinData m_MiHoYoBinData) - { - PreviewText(m_MiHoYoBinData.Str); - } - private void PreviewFont(Font m_Font) { if (m_Font.m_FontData != null) @@ -1273,12 +1247,6 @@ namespace AssetStudioGUI } } - private void PreviewMaterial(Material m_Material) - { - var str = JsonConvert.SerializeObject(m_Material, Formatting.Indented); - PreviewText(str); - } - private void PreviewTexture(DirectBitmap bitmap) { imageTexture?.Dispose(); @@ -2190,42 +2158,53 @@ namespace AssetStudioGUI } } - private void toolStripMenuItem16_MouseHover(object sender, EventArgs e) + private async void toolStripMenuItem16_DropDownOpening(object sender, EventArgs e) { - if (specifyAIVersion.Items.Count == 1 && AIVersionManager.Loaded) + if (specifyAIVersion.Enabled && await AIVersionManager.FetchVersions()) { - specifyAIVersion.Items.AddRange(AIVersionManager.GetVersions()); + UpdateVersionList(); } } private async void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e) { - if (specifyAIVersion.SelectedIndex == 0) return; - optionsToolStripMenuItem.DropDown.Visible = false; - string version = specifyAIVersion.SelectedItem.ToString(); - - Logger.Info($"Loading AI v{version}"); - specifyAIVersion.Enabled = false; - var path = AIVersionManager.GetAIPath(version); - if (string.IsNullOrEmpty(path)) + if (specifyAIVersion.SelectedIndex == 0) { - Logger.Warning("Invalid version, Aborting..."); - specifyAIVersion.SelectedIndex = 0; - SpecifyAIVersionUpdate(true); return; } - var needDownload = await AIVersionManager.NeedDownload(version); - if (needDownload) + optionsToolStripMenuItem.DropDown.Visible = false; + var version = specifyAIVersion.SelectedItem.ToString(); + + if (version.Contains(" ")) { - Logger.Info($"AI v{version} not found !"); - var json = await AIVersionManager.DownloadAI(version); - - File.WriteAllText(path, json); + version = version.Split(' ')[0]; } + + Logger.Info($"Loading AI v{version}"); + SpecifyAIVersionUpdate(false); + var path = await AIVersionManager.FetchAI(version); await Task.Run(() => ResourceIndex.FromFile(path)); + UpdateVersionList(); SpecifyAIVersionUpdate(true); } + private void UpdateVersionList() + { + var selectedIndex = specifyAIVersion.SelectedIndex; + specifyAIVersion.Items.Clear(); + specifyAIVersion.Items.Add("None"); + + var versions = AIVersionManager.GetVersions(); + foreach (var version in versions) + { + specifyAIVersion.Items.Add(version.Item1 + (version.Item2 ? " (cached)" : "")); + } + + specifyAIVersion.SelectedIndexChanged -= new EventHandler(toolStripComboBox1_SelectedIndexChanged); + specifyAIVersion.SelectedIndex = selectedIndex; + specifyAIVersion.SelectedIndexChanged += new EventHandler(toolStripComboBox1_SelectedIndexChanged); + } + private void toolStripComboBox2_SelectedIndexChanged(object sender, EventArgs e) { optionsToolStripMenuItem.DropDown.Visible = false; diff --git a/AssetStudioGUI/Exporter.cs b/AssetStudioGUI/Exporter.cs index cc4748b..18b45c0 100644 --- a/AssetStudioGUI/Exporter.cs +++ b/AssetStudioGUI/Exporter.cs @@ -107,26 +107,6 @@ namespace AssetStudioGUI return true; } - public static bool ExportAssetBundle(AssetItem item, string exportPath) - { - if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) - return false; - var m_AssetBundle = (AssetBundle)item.Asset; - var str = JsonConvert.SerializeObject(m_AssetBundle, Formatting.Indented); - File.WriteAllText(exportFullPath, str); - return true; - } - - public static bool ExportIndexObject(AssetItem item, string exportPath) - { - if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) - return false; - var m_IndexObject = (IndexObject)item.Asset; - var str = JsonConvert.SerializeObject(m_IndexObject, Formatting.Indented); - File.WriteAllText(exportFullPath, str); - return true; - } - public static bool ExportMiHoYoBinData(AssetItem item, string exportPath) { string exportFullPath; @@ -301,15 +281,21 @@ namespace AssetStudioGUI return false; } - public static bool ExportMaterial(AssetItem item, string exportPath) + public static bool ExportJsonFile(AssetItem item, string exportPath) { if (!TryExportFile(exportPath, item, ".json", out var exportFullPath)) return false; - var m_Material = (Material)item.Asset; - var str = JsonConvert.SerializeObject(m_Material, Formatting.Indented); + var str = JsonConvert.SerializeObject(item.Asset, Formatting.Indented); + if (!string.IsNullOrEmpty(str) && str != "{}") + { File.WriteAllText(exportFullPath, str); return true; } + else + { + return ExportRawFile(item, exportPath); + } + } public static bool ExportRawFile(AssetItem item, string exportPath) { @@ -440,20 +426,14 @@ namespace AssetStudioGUI return ExportMovieTexture(item, exportPath); case ClassIDType.Sprite: return ExportSprite(item, exportPath); - case ClassIDType.Material: - return ExportMaterial(item, exportPath); case ClassIDType.Animator: return ExportAnimator(item, exportPath); case ClassIDType.AnimationClip: return ExportAnimationClip(item, exportPath); - case ClassIDType.AssetBundle: - return ExportAssetBundle(item, exportPath); - case ClassIDType.IndexObject: - return ExportIndexObject(item, exportPath); case ClassIDType.MiHoYoBinData: return ExportMiHoYoBinData(item, exportPath); default: - return ExportRawFile(item, exportPath); + return ExportJsonFile(item, exportPath); } } diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index cf4d23d..8befaf0 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -459,12 +459,19 @@ namespace AssetStudioGUI Progress.Report(++i, objectCount); } } + + StatusStripUpdate("Building container list..."); + + i = 0; + Progress.Reset(); + var containersCount = containers.Count; foreach ((var pptr, var container) in containers) { if (pptr.TryGet(out var obj)) { objectAssetItemDic[obj].Container = container; } + Progress.Report(++i, containersCount); } foreach (var tmp in exportableAssets) {