diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index 5a60c70..4ed5ef4 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -15,7 +15,7 @@ namespace AssetStudio { public class AssetsManager { - public bool LoadingViaTypeTreeEnabled = true; + public bool LoadViaTypeTree = true; public ImportOptions Options = new ImportOptions(); public readonly List> OptionLoaders = new List>(); public readonly List AssetsFileList = new List(); @@ -154,6 +154,8 @@ namespace AssetStudio importFilesHash.Clear(); noexistFiles.Clear(); assetsFileListHash.Clear(); + if (AssetsFileList.Count == 0) + return; ReadAssets(); ProcessAssets(); @@ -188,6 +190,9 @@ namespace AssetStudio case FileType.ZipFile: LoadZipFile(reader); break; + case FileType.ResourceFile when !fromZip: + reader.Dispose(); + break; } return true; } @@ -277,7 +282,7 @@ namespace AssetStudio catch (NotSupportedException e) { Logger.Error(e.Message); - resourceFileReaders.TryAdd(reader.FileName, reader); + reader.Dispose(); return false; } catch (Exception e) @@ -648,7 +653,7 @@ namespace AssetStudio obj = new Animation(objectReader); break; case ClassIDType.AnimationClip: - obj = objectReader.serializedType?.m_Type != null && LoadingViaTypeTreeEnabled + obj = objectReader.serializedType?.m_Type != null && LoadViaTypeTree ? new AnimationClip(objectReader, TypeTreeHelper.ReadTypeByteArray(objectReader.serializedType.m_Type, objectReader), jsonOptions, objectInfo) : new AnimationClip(objectReader); break; @@ -680,7 +685,7 @@ namespace AssetStudio obj = new GameObject(objectReader); break; case ClassIDType.Material: - obj = objectReader.serializedType?.m_Type != null && LoadingViaTypeTreeEnabled + obj = objectReader.serializedType?.m_Type != null && LoadViaTypeTree ? new Material(objectReader, TypeTreeHelper.ReadTypeByteArray(objectReader.serializedType.m_Type, objectReader), jsonOptions) : new Material(objectReader); break; @@ -728,12 +733,12 @@ namespace AssetStudio obj = new TextAsset(objectReader); break; case ClassIDType.Texture2D: - obj = objectReader.serializedType?.m_Type != null && LoadingViaTypeTreeEnabled + obj = objectReader.serializedType?.m_Type != null && LoadViaTypeTree ? new Texture2D(objectReader, TypeTreeHelper.ReadTypeByteArray(objectReader.serializedType.m_Type, objectReader), jsonOptions) : new Texture2D(objectReader); break; case ClassIDType.Texture2DArray: - obj = objectReader.serializedType?.m_Type != null && LoadingViaTypeTreeEnabled + obj = objectReader.serializedType?.m_Type != null && LoadViaTypeTree ? new Texture2DArray(objectReader, TypeTreeHelper.ReadTypeByteArray(objectReader.serializedType.m_Type, objectReader), jsonOptions) : new Texture2DArray(objectReader); break; diff --git a/AssetStudio/Classes/Object.cs b/AssetStudio/Classes/Object.cs index ad2c6a1..fb21444 100644 --- a/AssetStudio/Classes/Object.cs +++ b/AssetStudio/Classes/Object.cs @@ -102,7 +102,7 @@ namespace AssetStudio { if (typeDict != null) { - return JsonSerializer.SerializeToDocument(typeDict); + return JsonSerializer.SerializeToDocument(typeDict, jsonOptions); } return JsonSerializer.SerializeToDocument(this, GetType(), jsonOptions); } diff --git a/AssetStudio/CubismModel.cs b/AssetStudio/CubismModel.cs index 0fc9ed5..d94386e 100644 --- a/AssetStudio/CubismModel.cs +++ b/AssetStudio/CubismModel.cs @@ -6,7 +6,6 @@ namespace AssetStudio { public string Name { get; set; } public string Container { get; set; } - public bool IsRoot { get; set; } public MonoBehaviour CubismModelMono { get; set; } public MonoBehaviour PhysicsController { get; set; } public MonoBehaviour FadeController { get; set; } @@ -21,7 +20,6 @@ namespace AssetStudio public CubismModel(GameObject m_GameObject) { Name = m_GameObject.m_Name; - IsRoot = m_GameObject.m_Transform.m_Father.IsNull; ModelGameObject = m_GameObject; RenderTextureList = new List(); ParamDisplayInfoList = new List(); diff --git a/AssetStudio/Extensions/BinaryReaderExtensions.cs b/AssetStudio/Extensions/BinaryReaderExtensions.cs index fbbf91a..2490754 100644 --- a/AssetStudio/Extensions/BinaryReaderExtensions.cs +++ b/AssetStudio/Extensions/BinaryReaderExtensions.cs @@ -27,7 +27,7 @@ namespace AssetStudio { var stringData = reader.ReadBytes(length); var result = Encoding.UTF8.GetString(stringData); - reader.AlignStream(4); + reader.AlignStream(); return result; } return ""; diff --git a/AssetStudio/TypeTreeHelper.cs b/AssetStudio/TypeTreeHelper.cs index c1a342a..c71c661 100644 --- a/AssetStudio/TypeTreeHelper.cs +++ b/AssetStudio/TypeTreeHelper.cs @@ -302,10 +302,11 @@ namespace AssetStudio case "TypelessData": { var size = reader.ReadInt32(); + var offset = size > 0 ? reader.BaseStream.Position : 0; var dic = new OrderedDictionary { - { "Offset", reader.BaseStream.Position }, - { "Size", size } + {"Offset", offset}, + {"Size", size} }; value = dic; reader.BaseStream.Position += size; diff --git a/AssetStudioCLI/Exporter.cs b/AssetStudioCLI/Exporter.cs index 3c26296..c9bbaad 100644 --- a/AssetStudioCLI/Exporter.cs +++ b/AssetStudioCLI/Exporter.cs @@ -107,19 +107,18 @@ namespace AssetStudioCLI { var m_TextAsset = (TextAsset)item.Asset; var extension = ".txt"; - var assetExtension = Path.GetExtension(m_TextAsset.m_Name); if (!CLIOptions.f_notRestoreExtensionName.Value) { - if (!string.IsNullOrEmpty(assetExtension)) + if (Path.HasExtension(m_TextAsset.m_Name)) { extension = ""; } - else if (!string.IsNullOrEmpty(item.Container)) + else { - var ext = Path.GetExtension(item.Container); - if (!string.IsNullOrEmpty(item.Container)) + var extFromContainer = Path.GetExtension(item.Container); + if (!string.IsNullOrEmpty(extFromContainer)) { - extension = ext; + extension = extFromContainer; } } } diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 91a0e56..f5f0552 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -94,7 +94,7 @@ namespace AssetStudioCLI.Options public static Option o_filenameFormat; public static Option o_outputFolder; public static Option f_overwriteExisting; - public static Option o_displayHelp; + public static Option f_displayHelp; //logger public static Option o_logLevel; public static Option o_logOutput; @@ -264,13 +264,14 @@ namespace AssetStudioCLI.Options optionHelpGroup: HelpGroups.General, isFlag: true ); - o_displayHelp = new GroupedOption + f_displayHelp = new GroupedOption ( optionDefaultValue: false, optionName: "-h, --help", optionDescription: "Display help and exit", optionExample: "", - optionHelpGroup: HelpGroups.General + optionHelpGroup: HelpGroups.General, + isFlag: true ); #endregion @@ -533,7 +534,7 @@ namespace AssetStudioCLI.Options ( optionDefaultValue: false, optionName: "--decompress-to-disk", - optionDescription: "(Flag) If not specified, only bundles larger than 2GB will be decompressed to disk\ninstead of memory\n", + optionDescription: "(Flag) If not specified, only bundles larger than 2GB will be decompressed to disk\ninstead of RAM\n", optionExample: "", optionHelpGroup: HelpGroups.Advanced, isFlag: true @@ -577,7 +578,7 @@ namespace AssetStudioCLI.Options if (args.Length == 0 || args.Any(x => x.ToLower() == "-h" || x.ToLower() == "--help" || x.ToLower() == "-?")) { - o_displayHelp.Value = true; + f_displayHelp.Value = true; return; } @@ -1030,6 +1031,7 @@ namespace AssetStudioCLI.Options case "monobehaviour": o_l2dMotionMode.Value = CubismLive2DExtractor.Live2DMotionMode.MonoBehaviour; break; + case "clip": case "animationclip": case "animationclipv2": o_l2dMotionMode.Value = CubismLive2DExtractor.Live2DMotionMode.AnimationClipV2; diff --git a/AssetStudioCLI/Program.cs b/AssetStudioCLI/Program.cs index 3d51e03..c76515f 100644 --- a/AssetStudioCLI/Program.cs +++ b/AssetStudioCLI/Program.cs @@ -13,7 +13,7 @@ namespace AssetStudioCLI { CLIRun(); } - else if (CLIOptions.o_displayHelp.Value) + else if (CLIOptions.f_displayHelp.Value) { CLIOptions.ShowHelp(); } diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index bc4e733..6bb8831 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -30,7 +30,7 @@ namespace AssetStudioCLI { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Progress.Default = new Progress(ShowCurProgressValue); - assetsManager.LoadingViaTypeTreeEnabled = !CLIOptions.f_avoidLoadingViaTypetree.Value; + assetsManager.LoadViaTypeTree = !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; diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index 43388da..8726ef9 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -395,6 +395,7 @@ this.specifyUnityVersionTextBox.Font = new System.Drawing.Font("Segoe UI", 9F); this.specifyUnityVersionTextBox.Name = "specifyUnityVersionTextBox"; this.specifyUnityVersionTextBox.Size = new System.Drawing.Size(100, 23); + this.specifyUnityVersionTextBox.ToolTipText = "Specify full Unity version, including letters at the end\r\nExample: 2017.4.39f1"; // // bundleDecompressionToolStripMenuItem // @@ -411,7 +412,7 @@ this.alwaysDecompressToDiskToolStripMenuItem.ShowShortcutKeys = false; this.alwaysDecompressToDiskToolStripMenuItem.Size = new System.Drawing.Size(217, 22); this.alwaysDecompressToDiskToolStripMenuItem.Text = "Always decompress to disk"; - this.alwaysDecompressToDiskToolStripMenuItem.ToolTipText = "If not selected, any bundles less than 2GB will be decompressed to memory"; + this.alwaysDecompressToDiskToolStripMenuItem.ToolTipText = "If not selected, any bundles less than 2GB will be decompressed to RAM"; this.alwaysDecompressToDiskToolStripMenuItem.Click += new System.EventHandler(this.alwaysDecompressToDiskToolStripMenuItem_Click); // // blockInfoCompressionTypeToolStripMenuItem diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index a53d45e..d978b77 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -317,9 +317,9 @@ namespace AssetStudioGUI allToolStripMenuItem.Checked = true; var log = $"Finished loading {assetsManager.AssetsFileList.Count} file(s) with {assetListView.Items.Count} exportable assets"; var unityVer = assetsManager.AssetsFileList[0].version; - var m_ObjectsCount = unityVer > 2020 ? - assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y => y.classID != (int)ClassIDType.Shader)) : - assetsManager.AssetsFileList.Sum(x => x.m_Objects.Count); + var m_ObjectsCount = unityVer > 2020 + ? assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y => y.classID != (int)ClassIDType.Shader)) + : assetsManager.AssetsFileList.Sum(x => x.m_Objects.Count); var objectsCount = assetsManager.AssetsFileList.Sum(x => x.Objects.Count); if (m_ObjectsCount != objectsCount) { @@ -483,16 +483,14 @@ namespace AssetStudioGUI { case ClassIDType.Texture2D: case ClassIDType.Sprite: + if (enablePreview.Checked && imageTexture != null) { - if (enablePreview.Checked && imageTexture != null) - { - previewPanel.Image = imageTexture.Bitmap; - } - else - { - previewPanel.Image = Properties.Resources.preview; - previewPanel.SizeMode = PictureBoxSizeMode.CenterImage; - } + previewPanel.Image = imageTexture.Bitmap; + } + else + { + previewPanel.Image = Properties.Resources.preview; + previewPanel.SizeMode = PictureBoxSizeMode.CenterImage; } break; case ClassIDType.Shader: @@ -504,34 +502,28 @@ namespace AssetStudioGUI fontPreviewBox.Visible = !fontPreviewBox.Visible; break; case ClassIDType.AudioClip: + FMODpanel.Visible = !FMODpanel.Visible; + + if (sound.hasHandle() && channel.hasHandle()) { - FMODpanel.Visible = !FMODpanel.Visible; - - if (sound.hasHandle() && channel.hasHandle()) + var result = channel.isPlaying(out var playing); + if (result == FMOD.RESULT.OK && playing) { - var result = channel.isPlaying(out var playing); - if (result == FMOD.RESULT.OK && playing) - { - channel.stop(); - FMODreset(); - } + channel.stop(); + FMODreset(); } - else if (FMODpanel.Visible) - { - PreviewAsset(lastSelectedItem); - } - - break; } - + else if (FMODpanel.Visible) + { + PreviewAsset(lastSelectedItem); + } + break; } - } else if (lastSelectedItem != null && enablePreview.Checked) { PreviewAsset(lastSelectedItem); } - Properties.Settings.Default.enablePreview = enablePreview.Checked; Properties.Settings.Default.Save(); } @@ -546,7 +538,6 @@ namespace AssetStudioGUI { assetInfoLabel.Visible = false; } - Properties.Settings.Default.displayInfo = displayInfo.Checked; Properties.Settings.Default.Save(); } @@ -756,42 +747,40 @@ namespace AssetStudioGUI assetListView.SelectedIndices.Clear(); selectedIndicesPrevList.Clear(); selectedAnimationAssetsList.Clear(); - if (sortColumn == 4) //FullSize + switch (sortColumn) { - visibleAssets.Sort((a, b) => - { - var asf = a.FullSize; - var bsf = b.FullSize; - return reverseSort ? bsf.CompareTo(asf) : asf.CompareTo(bsf); - }); - } - else if (sortColumn == 3) // PathID - { - visibleAssets.Sort((x, y) => - { - long pathID_X = x.m_PathID; - long pathID_Y = y.m_PathID; - return reverseSort ? pathID_Y.CompareTo(pathID_X) : pathID_X.CompareTo(pathID_Y); - }); - } - else if (sortColumn == 0) // Name - { - visibleAssets.Sort((a, b) => - { - var at = a.SubItems[sortColumn].Text; - var bt = b.SubItems[sortColumn].Text; - return reverseSort ? alphanumComparator.Compare(bt, at) : alphanumComparator.Compare(at, bt); - }); - } - else - { - visibleAssets.Sort((a, b) => - { - var at = a.SubItems[sortColumn].Text.AsSpan(); - var bt = b.SubItems[sortColumn].Text.AsSpan(); - - return reverseSort ? bt.CompareTo(at, StringComparison.OrdinalIgnoreCase) : at.CompareTo(bt, StringComparison.OrdinalIgnoreCase); - }); + case 4: //FullSize + visibleAssets.Sort((a, b) => + { + var asf = a.FullSize; + var bsf = b.FullSize; + return reverseSort ? bsf.CompareTo(asf) : asf.CompareTo(bsf); + }); + break; + case 3: //PathID + visibleAssets.Sort((x, y) => + { + long pathID_X = x.m_PathID; + long pathID_Y = y.m_PathID; + return reverseSort ? pathID_Y.CompareTo(pathID_X) : pathID_X.CompareTo(pathID_Y); + }); + break; + case 0: //Name + visibleAssets.Sort((a, b) => + { + var at = a.SubItems[sortColumn].Text; + var bt = b.SubItems[sortColumn].Text; + return reverseSort ? alphanumComparator.Compare(bt, at) : alphanumComparator.Compare(at, bt); + }); + break; + default: + visibleAssets.Sort((a, b) => + { + var at = a.SubItems[sortColumn].Text.AsSpan(); + var bt = b.SubItems[sortColumn].Text.AsSpan(); + return reverseSort ? bt.CompareTo(at, StringComparison.OrdinalIgnoreCase) : at.CompareTo(bt, StringComparison.OrdinalIgnoreCase); + }); + break; } assetListView.EndUpdate(); } @@ -813,20 +802,17 @@ namespace AssetStudioGUI lastSelectedItem = (AssetItem)e.Item; - if (!e.IsSelected) + if (!e.IsSelected) return; - + switch (tabControl2.SelectedIndex) { - case 0: //Preview - if (enablePreview.Checked) + case 0 when enablePreview.Checked: //Preview + PreviewAsset(lastSelectedItem); + if (displayInfo.Checked && lastSelectedItem.InfoText != null) { - PreviewAsset(lastSelectedItem); - if (displayInfo.Checked && lastSelectedItem.InfoText != null) - { - assetInfoLabel.Text = lastSelectedItem.InfoText; - assetInfoLabel.Visible = true; - } + assetInfoLabel.Text = lastSelectedItem.InfoText; + assetInfoLabel.Visible = true; } break; case 1: //Dump @@ -955,7 +941,7 @@ namespace AssetStudioGUI private void PreviewTexture2DArray(AssetItem assetItem, Texture2DArray m_Texture2DArray) { - assetItem.InfoText = + assetItem.InfoText = $"Width: {m_Texture2DArray.m_Width}\n" + $"Height: {m_Texture2DArray.m_Height}\n" + $"Graphics format: {m_Texture2DArray.m_Format}\n" + @@ -970,7 +956,11 @@ namespace AssetStudioGUI { var bitmap = new DirectBitmap(image); image.Dispose(); - assetItem.InfoText = $"Width: {m_Texture2D.m_Width}\nHeight: {m_Texture2D.m_Height}\nFormat: {m_Texture2D.m_TextureFormat}"; + + assetItem.InfoText = + $"Width: {m_Texture2D.m_Width}" + + $"\nHeight: {m_Texture2D.m_Height}" + + $"\nFormat: {m_Texture2D.m_TextureFormat}"; switch (m_Texture2D.m_TextureSettings.m_FilterMode) { case 0: assetItem.InfoText += "\nFilter mode: Point "; break; @@ -984,8 +974,8 @@ namespace AssetStudioGUI case 1: assetItem.InfoText += "\nWrap mode: Clamp"; break; } assetItem.InfoText += "\nChannels: "; - int validChannel = 0; - for (int i = 0; i < 4; i++) + var validChannel = 0; + for (var i = 0; i < 4; i++) { if (textureChannels[i]) { @@ -998,10 +988,10 @@ namespace AssetStudioGUI if (validChannel != 4) { var bytes = bitmap.Bits; - for (int i = 0; i < bitmap.Height; i++) + for (var i = 0; i < bitmap.Height; i++) { - int offset = Math.Abs(bitmap.Stride) * i; - for (int j = 0; j < bitmap.Width; j++) + var offset = Math.Abs(bitmap.Stride) * i; + for (var j = 0; j < bitmap.Width; j++) { bytes[offset] = textureChannels[0] ? bytes[offset] : validChannel == 1 && textureChannels[3] ? byte.MaxValue : byte.MinValue; bytes[offset + 1] = textureChannels[1] ? bytes[offset + 1] : validChannel == 1 && textureChannels[3] ? byte.MaxValue : byte.MinValue; @@ -1012,7 +1002,9 @@ namespace AssetStudioGUI } } var switchSwizzled = m_Texture2D.m_PlatformBlob.Length != 0; - assetItem.InfoText += assetItem.Asset.platform == BuildTarget.Switch ? $"\nUses texture swizzling: {switchSwizzled}" : ""; + assetItem.InfoText += assetItem.Asset.platform == BuildTarget.Switch + ? $"\nUses texture swizzling: {switchSwizzled}" + : ""; PreviewTexture(bitmap); StatusStripUpdate("'Ctrl'+'R'/'G'/'B'/'A' for Channel Toggle"); @@ -1173,7 +1165,10 @@ namespace AssetStudioGUI _ = system.getMasterChannelGroup(out var channelGroup); result = system.playSound(sound, channelGroup, paused, out channel); if (ERRCHECK(result)) return; - if (!paused) { timer.Start(); } + if (!paused) + { + timer.Start(); + } FMODpanel.Visible = true; @@ -1182,7 +1177,7 @@ namespace AssetStudioGUI FMODinfoLabel.Text = frequency + " Hz"; FMODtimerLabel.Text = $"00:00.00 / {(FMODlenms / 1000 / 60):00}:{(FMODlenms / 1000 % 60):00}.{(FMODlenms / 10 % 100):00}"; - + sound.getFormat(out _, out _, out var audioChannels, out _); switch (audioChannels) { @@ -1206,7 +1201,7 @@ namespace AssetStudioGUI sb.AppendLine($"Frame rate: {m_VideoClip.m_FrameRate:.0##}"); sb.AppendLine($"Split alpha: {m_VideoClip.m_HasSplitAlpha}"); assetItem.InfoText = sb.ToString(); - + StatusStripUpdate("Only supported export."); } @@ -1316,6 +1311,7 @@ namespace AssetStudioGUI if (m_Mesh.m_VertexCount > 0) { viewMatrixData = Matrix4.CreateRotationY(-MathF.PI / 4) * Matrix4.CreateRotationX(-MathF.PI / 6); + #region Vertices if (m_Mesh.m_Vertices == null || m_Mesh.m_Vertices.Length == 0) { @@ -1359,6 +1355,7 @@ namespace AssetStudioGUI float d = Math.Max(1e-5f, dist.Length); modelMatrixData = Matrix4.CreateTranslation(-offset) * Matrix4.CreateScale(2f / d); #endregion + #region Indicies indiceData = new int[m_Mesh.m_Indices.Count]; for (int i = 0; i < m_Mesh.m_Indices.Count; i = i + 3) @@ -1368,6 +1365,7 @@ namespace AssetStudioGUI indiceData[i + 2] = (int)m_Mesh.m_Indices[i + 2]; } #endregion + #region Normals if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0) { @@ -1386,6 +1384,7 @@ namespace AssetStudioGUI } else normalData = null; + // calculate normal by ourself normal2Data = new Vector3[m_Mesh.m_VertexCount]; int[] normalCalculatedCount = new int[m_Mesh.m_VertexCount]; @@ -1414,6 +1413,7 @@ namespace AssetStudioGUI normal2Data[i] /= normalCalculatedCount[i]; } #endregion + #region Colors if (m_Mesh.m_Colors != null && m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3) { @@ -1433,10 +1433,10 @@ namespace AssetStudioGUI for (int c = 0; c < m_Mesh.m_VertexCount; c++) { colorData[c] = new Vector4( - m_Mesh.m_Colors[c * 4], - m_Mesh.m_Colors[c * 4 + 1], - m_Mesh.m_Colors[c * 4 + 2], - m_Mesh.m_Colors[c * 4 + 3]); + m_Mesh.m_Colors[c * 4], + m_Mesh.m_Colors[c * 4 + 1], + m_Mesh.m_Colors[c * 4 + 2], + m_Mesh.m_Colors[c * 4 + 3]); } } else @@ -1448,6 +1448,7 @@ namespace AssetStudioGUI } } #endregion + glControl1.Visible = true; CreateVAO(); StatusStripUpdate("Using OpenGL Version: " + GL.GetString(StringName.Version) + "\n" @@ -1503,7 +1504,7 @@ namespace AssetStudioGUI { if (InvokeRequired) { - BeginInvoke(new Action(() => + BeginInvoke(new Action(() => { progressBar1.Value = value; progressBar1.Style = ProgressBarStyle.Continuous; @@ -1515,7 +1516,7 @@ namespace AssetStudioGUI progressBar1.Value = value; } - BeginInvoke(new Action(() => + BeginInvoke(new Action(() => { var max = progressBar1.Maximum; taskbar.SetProgressValue(value, max); @@ -1589,7 +1590,7 @@ namespace AssetStudioGUI { switch (tabControl2.SelectedIndex) { - case 0: //Preview + case 0 when enablePreview.Checked: //Preview if (lastPreviewItem != lastSelectedItem) { PreviewAsset(lastSelectedItem); @@ -1657,11 +1658,11 @@ namespace AssetStudioGUI break; } } - exportAnimatorWithSelectedAnimationClipMenuItem.Visible = (selectedTypes & SelectedAssetType.Animator) !=0 && (selectedTypes & SelectedAssetType.AnimationClip) != 0; + exportAnimatorWithSelectedAnimationClipMenuItem.Visible = (selectedTypes & SelectedAssetType.Animator) != 0 && (selectedTypes & SelectedAssetType.AnimationClip) != 0; exportAsLive2DModelToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) != 0; - exportL2DWithFadeLstToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) !=0 && (selectedTypes & SelectedAssetType.MonoBehaviourFadeLst) != 0; - exportL2DWithFadeToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) != 0 && (selectedTypes & SelectedAssetType.MonoBehaviourFade) !=0; - exportL2DWithClipsToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) !=0 && (selectedTypes & SelectedAssetType.AnimationClip) != 0; + exportL2DWithFadeLstToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) != 0 && (selectedTypes & SelectedAssetType.MonoBehaviourFadeLst) != 0; + exportL2DWithFadeToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) != 0 && (selectedTypes & SelectedAssetType.MonoBehaviourFade) != 0; + exportL2DWithClipsToolStripMenuItem.Visible = (selectedTypes & SelectedAssetType.MonoBehaviourMoc) != 0 && (selectedTypes & SelectedAssetType.AnimationClip) != 0; } var selectedElement = assetListView.HitTest(new Point(e.X, e.Y)); @@ -1733,7 +1734,7 @@ namespace AssetStudioGUI saveDirectoryBackup = saveFolderDialog.Folder; var exportPath = Path.Combine(saveFolderDialog.Folder, "GameObject") + Path.DirectorySeparatorChar; List animationList = null; - if(animation && selectedAnimationAssetsList.Count > 0) + if (animation && selectedAnimationAssetsList.Count > 0) { animationList = selectedAnimationAssetsList; } @@ -1960,6 +1961,7 @@ namespace AssetStudioGUI { visibleAssets = exportableAssets; } + if (listSearch.Text != " Filter ") { var mode = (ListSearchFilterMode)listSearchFilterMode.SelectedIndex; @@ -1986,14 +1988,10 @@ namespace AssetStudioGUI var regexOptions = RegexOptions.IgnoreCase | RegexOptions.Singleline; try { - if (mode == ListSearchFilterMode.RegexName) - { - visibleAssets = visibleAssets.FindAll(x => Regex.IsMatch(x.Text, pattern, regexOptions)); - } - else - { - visibleAssets = visibleAssets.FindAll(x => Regex.IsMatch(x.SubItems[1].Text, pattern, regexOptions)); - } + visibleAssets = mode == ListSearchFilterMode.RegexName + ? visibleAssets.FindAll(x => Regex.IsMatch(x.Text, pattern, regexOptions)) + : visibleAssets.FindAll(x => Regex.IsMatch(x.SubItems[1].Text, pattern, regexOptions)); + listSearch.BackColor = SystemInformation.HighContrast ? listSearch.BackColor : System.Drawing.Color.PaleGreen; listSearch.ForeColor = isDarkMode ? System.Drawing.Color.Black : listSearch.ForeColor; } @@ -2045,8 +2043,8 @@ namespace AssetStudioGUI var tex2dArrayImgPathIdSet = toExportAssets.FindAll(x => x.Type == ClassIDType.Texture2DArrayImage).Select(x => x.m_PathID).ToHashSet(); foreach (var pathId in tex2dArrayImgPathIdSet) { - toExportAssets = toExportAssets.Where(x => - x.Type != ClassIDType.Texture2DArray + toExportAssets = toExportAssets.Where(x => + x.Type != ClassIDType.Texture2DArray || (x.Type == ClassIDType.Texture2DArray && x.m_PathID != pathId)) .ToList(); } @@ -2338,24 +2336,25 @@ namespace AssetStudioGUI var selectedClips = new List(); foreach (var assetItem in selectedAssets) { - if (assetItem.Asset is MonoBehaviour m_MonoBehaviour && m_MonoBehaviour.m_Script.TryGet(out var m_Script)) + switch (assetItem.Asset) { - if (m_Script.m_ClassName == "CubismMoc") - { - selectedMocs.Add(m_MonoBehaviour); - } - else if (m_Script.m_ClassName == "CubismFadeMotionData") - { - selectedFadeMotions.Add(m_MonoBehaviour); - } - else if (m_Script.m_ClassName == "CubismFadeMotionList") - { - selectedFadeLst = m_MonoBehaviour; - } - } - else if (assetItem.Asset is AnimationClip m_AnimationClip) - { - selectedClips.Add(m_AnimationClip); + case MonoBehaviour m_MonoBehaviour when m_MonoBehaviour.m_Script.TryGet(out var m_Script): + switch (m_Script.m_ClassName) + { + case "CubismMoc": + selectedMocs.Add(m_MonoBehaviour); + break; + case "CubismFadeMotionData": + selectedFadeMotions.Add(m_MonoBehaviour); + break; + case "CubismFadeMotionList": + selectedFadeLst = m_MonoBehaviour; + break; + } + break; + case AnimationClip m_AnimationClip: + selectedClips.Add(m_AnimationClip); + break; } } if (selectedMocs.Count == 0) @@ -2501,7 +2500,7 @@ namespace AssetStudioGUI private void useAssetLoadingViaTypetreeToolStripMenuItem_CheckedChanged(object sender, EventArgs e) { var isEnabled = useAssetLoadingViaTypetreeToolStripMenuItem.Checked; - assetsManager.LoadingViaTypeTreeEnabled = isEnabled; + assetsManager.LoadViaTypeTree = isEnabled; Properties.Settings.Default.useTypetreeLoading = isEnabled; Properties.Settings.Default.Save(); } @@ -2729,7 +2728,7 @@ namespace AssetStudioGUI _ = system.getMasterChannelGroup(out var channelGroup); timer.Start(); var result = channel.isPlaying(out var playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2748,14 +2747,14 @@ namespace AssetStudioGUI { result = system.playSound(sound, channelGroup, false, out channel); if (ERRCHECK(result)) { return; } - FMODstatusLabel.Text = "Playing"; + FMODstatusLabel.Text = "Playing"; if (FMODprogressBar.Value > 0) { uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value; result = channel.setPosition(newms, FMOD.TIMEUNIT.MS); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2769,7 +2768,7 @@ namespace AssetStudioGUI if (sound.hasHandle() && channel.hasHandle()) { var result = channel.isPlaying(out var playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2778,6 +2777,7 @@ namespace AssetStudioGUI { result = channel.getPaused(out var paused); if (ERRCHECK(result)) { return; } + result = channel.setPaused(!paused); if (ERRCHECK(result)) { return; } @@ -2802,7 +2802,7 @@ namespace AssetStudioGUI if (channel.hasHandle()) { var result = channel.isPlaying(out var playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2811,6 +2811,7 @@ namespace AssetStudioGUI { result = channel.stop(); if (ERRCHECK(result)) { return; } + //channel = null; //don't FMODreset, it will nullify the sound timer.Stop(); @@ -2837,13 +2838,13 @@ namespace AssetStudioGUI if (channel.hasHandle()) { result = channel.isPlaying(out var playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } result = channel.getPaused(out var paused); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2851,7 +2852,7 @@ namespace AssetStudioGUI if (playing || paused) { result = channel.setMode(loopMode); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } @@ -2889,18 +2890,21 @@ namespace AssetStudioGUI uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value; var result = channel.setPosition(newms, FMOD.TIMEUNIT.MS); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } result = channel.isPlaying(out var playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { if (ERRCHECK(result)) { return; } } - if (playing) { timer.Start(); } + if (playing) + { + timer.Start(); + } } } @@ -2913,19 +2917,19 @@ namespace AssetStudioGUI if (channel.hasHandle()) { var result = channel.getPosition(out ms, FMOD.TIMEUNIT.MS); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { ERRCHECK(result); } result = channel.isPlaying(out playing); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { ERRCHECK(result); } result = channel.getPaused(out paused); - if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE)) + if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) { ERRCHECK(result); } @@ -3002,9 +3006,9 @@ namespace AssetStudioGUI GL.GenBuffers(1, out vboAddress); GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress); GL.BufferData(BufferTarget.ArrayBuffer, - (IntPtr)(data.Length * Vector3.SizeInBytes), - data, - BufferUsageHint.StaticDraw); + (IntPtr)(data.Length * Vector3.SizeInBytes), + data, + BufferUsageHint.StaticDraw); GL.VertexAttribPointer(address, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(address); } @@ -3014,9 +3018,9 @@ namespace AssetStudioGUI GL.GenBuffers(1, out vboAddress); GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress); GL.BufferData(BufferTarget.ArrayBuffer, - (IntPtr)(data.Length * Vector4.SizeInBytes), - data, - BufferUsageHint.StaticDraw); + (IntPtr)(data.Length * Vector4.SizeInBytes), + data, + BufferUsageHint.StaticDraw); GL.VertexAttribPointer(address, 4, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(address); } @@ -3032,9 +3036,9 @@ namespace AssetStudioGUI GL.GenBuffers(1, out address); GL.BindBuffer(BufferTarget.ElementArrayBuffer, address); GL.BufferData(BufferTarget.ElementArrayBuffer, - (IntPtr)(data.Length * sizeof(int)), - data, - BufferUsageHint.StaticDraw); + (IntPtr)(data.Length * sizeof(int)), + data, + BufferUsageHint.StaticDraw); } private void CreateVAO() diff --git a/AssetStudioGUI/Exporter.cs b/AssetStudioGUI/Exporter.cs index b7a6be9..b01929a 100644 --- a/AssetStudioGUI/Exporter.cs +++ b/AssetStudioGUI/Exporter.cs @@ -89,19 +89,18 @@ namespace AssetStudioGUI { var m_TextAsset = (TextAsset)item.Asset; var extension = ".txt"; - var assetExtension = Path.GetExtension(m_TextAsset.m_Name); if (Properties.Settings.Default.restoreExtensionName) { - if (!string.IsNullOrEmpty(assetExtension)) + if (Path.HasExtension(m_TextAsset.m_Name)) { extension = ""; } - else if (!string.IsNullOrEmpty(item.Container)) + else { - var ext = Path.GetExtension(item.Container); - if (!string.IsNullOrEmpty(item.Container)) + var extFromContainer = Path.GetExtension(item.Container); + if (!string.IsNullOrEmpty(extFromContainer)) { - extension = ext; + extension = extFromContainer; } } } diff --git a/AssetStudioUtility/AssemblyLoader.cs b/AssetStudioUtility/AssemblyLoader.cs index d2a7d0a..21ace37 100644 --- a/AssetStudioUtility/AssemblyLoader.cs +++ b/AssetStudioUtility/AssemblyLoader.cs @@ -33,28 +33,27 @@ namespace AssetStudio public TypeDefinition GetTypeDefinition(string assemblyName, string fullName) { - moduleDic.TryGetValue(assemblyName, out var module); - if (module == null && !assemblyName.Contains(".dll")) + if (!moduleDic.TryGetValue(assemblyName, out var module) && !assemblyName.EndsWith(".dll")) { - moduleDic.TryGetValue(assemblyName + ".dll", out module); + assemblyName += ".dll"; + moduleDic.TryGetValue(assemblyName, out module); } - if (module != null) + if (module == null) + return null; + + var typeDef = module.GetType(fullName); + if (typeDef == null && assemblyName == "UnityEngine.dll") { - var typeDef = module.GetType(fullName); - if (typeDef == null && assemblyName == "UnityEngine.dll") + foreach (var pair in moduleDic) { - foreach (var pair in moduleDic) + typeDef = pair.Value.GetType(fullName); + if (typeDef != null) { - typeDef = pair.Value.GetType(fullName); - if (typeDef != null) - { - break; - } + break; } } - return typeDef; } - return null; + return typeDef; } public void Clear()