diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index 2082c44..2db2439 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -91,9 +91,7 @@ namespace AssetStudio public void LoadFilesAndFolders(params string[] path) { - var pathList = new List(); - pathList.AddRange(path); - LoadFilesAndFolders(out _, pathList); + LoadFilesAndFolders(out _, path); } public void LoadFilesAndFolders(out string parentPath, params string[] path) @@ -106,15 +104,15 @@ namespace AssetStudio public void LoadFilesAndFolders(out string parentPath, List pathList) { var fileList = new List(); - bool filesInPath = false; + var filesInPath = false; parentPath = ""; foreach (var path in pathList) { var fullPath = Path.GetFullPath(path); if (Directory.Exists(fullPath)) { - var parent = Directory.GetParent(fullPath).FullName; - if (!filesInPath && (parentPath == "" || parentPath.Length > parent.Length)) + var parent = Directory.GetParent(fullPath)?.FullName; + if (!filesInPath && (parentPath == "" || parentPath?.Length > parent?.Length)) { parentPath = parent; } @@ -241,6 +239,7 @@ namespace AssetStudio else { noexistFiles.Add(sharedFilePath); + Logger.Warning($"Dependency wasn't found: {sharedFilePath}"); } } } diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index 0ae233d..f7b9e8f 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -399,6 +399,8 @@ namespace AssetStudio private void ReadBlocks(FileReader reader, CompressionType customBlockCompression, Stream blocksStream) { + Logger.Debug($"Block compression: {(CompressionType)m_BlocksInfo.Max(x => x.flags)}"); + var showCustomTypeWarning = true; foreach (var blockInfo in m_BlocksInfo) { @@ -420,7 +422,6 @@ namespace AssetStudio showCustomTypeWarning = false; } } - Logger.Debug($"Block compression: {compressionType}"); long numWrite; var errorMsg = string.Empty; diff --git a/AssetStudio/CommonString.cs b/AssetStudio/CommonString.cs index 975a0e2..5814866 100644 --- a/AssetStudio/CommonString.cs +++ b/AssetStudio/CommonString.cs @@ -115,7 +115,7 @@ namespace AssetStudio {1138, "m_PrefabAsset"}, {1152, "FileSize"}, {1161, "Hash128"}, - {1169, "RenderingLayerMask"}, + {1169, "RenderingLayerMask"}, }; } } diff --git a/AssetStudio/ImportHelper.cs b/AssetStudio/ImportHelper.cs index 3e8f1a1..20c633c 100644 --- a/AssetStudio/ImportHelper.cs +++ b/AssetStudio/ImportHelper.cs @@ -68,7 +68,7 @@ namespace AssetStudio } catch (System.Exception e) { - Logger.Warning($"Error while decompressing gzip file {reader.FullPath}\r\n{e}"); + Logger.Warning($"Error while decompressing Gzip file {reader.FullPath}\n{e}"); reader.Dispose(); return null; } @@ -76,15 +76,24 @@ namespace AssetStudio public static FileReader DecompressBrotli(FileReader reader) { - using (reader) + try { - var stream = new MemoryStream(); - using (var brotliStream = new BrotliInputStream(reader.BaseStream)) + using (reader) { - brotliStream.CopyTo(stream); + var stream = new MemoryStream(); + using (var brotliStream = new BrotliInputStream(reader.BaseStream)) + { + brotliStream.CopyTo(stream); + } + stream.Position = 0; + return new FileReader(reader.FullPath, stream); } - stream.Position = 0; - return new FileReader(reader.FullPath, stream); + } + catch (System.Exception e) + { + Logger.Warning($"Error while decompressing Brotli file {reader.FullPath}\n{e}"); + reader.Dispose(); + return null; } } } diff --git a/AssetStudio/ResourceReader.cs b/AssetStudio/ResourceReader.cs index 9c97ebb..85415e6 100644 --- a/AssetStudio/ResourceReader.cs +++ b/AssetStudio/ResourceReader.cs @@ -84,15 +84,16 @@ namespace AssetStudio } } - public void GetData(byte[] buff, out int read, int startIndex = 0) + public int GetData(byte[] buff, int startIndex = 0) { - read = -1; + int dataLen; var binaryReader = GetReader(); lock (binaryReader) { binaryReader.BaseStream.Position = Offset; - read = binaryReader.Read(buff, startIndex, (int)size); + dataLen = binaryReader.Read(buff, startIndex, (int)size); } + return dataLen; } public void WriteData(string path) diff --git a/AssetStudio/TypeTreeHelper.cs b/AssetStudio/TypeTreeHelper.cs index 237653d..2f21bb3 100644 --- a/AssetStudio/TypeTreeHelper.cs +++ b/AssetStudio/TypeTreeHelper.cs @@ -29,11 +29,11 @@ namespace AssetStudio var m_Nodes = m_Type.m_Nodes; try { - for (int i = 0; i < m_Nodes.Count; i++) + for (var i = 0; i < m_Nodes.Count; i++) { ReadStringValue(sb, m_Nodes, reader, ref i); + readed = reader.Position - reader.byteStart; } - readed = reader.Position - reader.byteStart; } catch (Exception) { @@ -206,8 +206,8 @@ namespace AssetStudio var m_Node = m_Nodes[i]; var varNameStr = m_Node.m_Name; obj[varNameStr] = ReadValue(m_Nodes, reader, ref i); + readed = reader.Position - reader.byteStart; } - readed = reader.Position - reader.byteStart; } catch (Exception) { diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 99325de..a7790f7 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -1007,7 +1007,7 @@ namespace AssetStudioCLI.Options switch (value.ToLower()) { case "auto": - o_bundleBlockInfoCompression.Value = CompressionType.Zstd; + o_bundleBlockInfoCompression.Value = CompressionType.Auto; break; case "zstd": o_bundleBlockInfoCompression.Value = CompressionType.Zstd; @@ -1032,7 +1032,7 @@ namespace AssetStudioCLI.Options switch (value.ToLower()) { case "auto": - o_bundleBlockCompression.Value = CompressionType.Zstd; + o_bundleBlockCompression.Value = CompressionType.Auto; break; case "zstd": o_bundleBlockCompression.Value = CompressionType.Zstd; diff --git a/AssetStudioCLI/ParallelExporter.cs b/AssetStudioCLI/ParallelExporter.cs index 348c1d7..c66c6d4 100644 --- a/AssetStudioCLI/ParallelExporter.cs +++ b/AssetStudioCLI/ParallelExporter.cs @@ -97,13 +97,13 @@ namespace AssetStudioCLI public static bool ExportAudioClip(AssetItem item, string exportPath, out string debugLog) { debugLog = string.Empty; - string exportFullPath; var m_AudioClip = (AudioClip)item.Asset; var m_AudioData = BigArrayPool.Shared.Rent(m_AudioClip.m_AudioData.Size); try { - m_AudioClip.m_AudioData.GetData(m_AudioData, out var read); - if (read <= 0) + string exportFullPath; + var dataLen = m_AudioClip.m_AudioData.GetData(m_AudioData); + if (dataLen <= 0) { Logger.Error($"Export error. \"{item.Text}\": AudioData was not found"); return false; diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index 70a0b9a..30f6b31 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -738,7 +738,7 @@ namespace AssetStudioCLI } catch (Exception ex) { - Logger.Error($"{asset.SourceFile.originalPath}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : Export error\n{ex}"); + Logger.Error($"{asset.SourceFile.originalPath ?? asset.SourceFile.fullName}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : Export error\n{ex}"); } if (isExported) @@ -763,7 +763,7 @@ namespace AssetStudioCLI } catch (Exception ex) { - Logger.Error($"{asset.SourceFile.originalPath}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : Export error\n{ex}"); + Logger.Error($"{asset.SourceFile.originalPath ?? asset.SourceFile.fullName}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : Export error\n{ex}"); } }); ParallelExporter.ClearHash(); @@ -1084,7 +1084,10 @@ namespace AssetStudioCLI { foreach (var assetKvp in containers) { - l2dContainers[assetKvp.Key] = Path.GetFileName(assetKvp.Key.assetsFile.originalPath); + var container = string.IsNullOrEmpty(assetKvp.Key.assetsFile.originalPath) + ? assetKvp.Key.assetsFile.fullName + : assetKvp.Key.assetsFile.originalPath; + l2dContainers[assetKvp.Key] = container; } } var mocPathDict = GenerateMocPathDict(mocDict, l2dContainers, searchByFilename); @@ -1141,16 +1144,19 @@ namespace AssetStudioCLI try { var cubismExtractor = new Live2DExtractor(assetGroupKvp); + var filename = string.IsNullOrEmpty(cubismExtractor.MocMono.assetsFile.originalPath) + ? Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.fileName) + : Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); string modelPath; switch (modelGroupOption) { case Live2DModelGroupOption.SourceFileName: - modelPath = Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); + modelPath = filename; break; case Live2DModelGroupOption.ModelName: modelPath = !string.IsNullOrEmpty(cubismExtractor.Model?.Name) ? cubismExtractor.Model.Name - : Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); + : filename; break; default: //ContainerPath var container = searchByFilename && cubismExtractor.Model != null diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index d969656..d1f7a31 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -298,8 +298,8 @@ this.useAssetLoadingViaTypetreeToolStripMenuItem.Name = "useAssetLoadingViaTypetreeToolStripMenuItem"; this.useAssetLoadingViaTypetreeToolStripMenuItem.Size = new System.Drawing.Size(241, 22); this.useAssetLoadingViaTypetreeToolStripMenuItem.Text = "Parse assets using their typetree"; - this.useAssetLoadingViaTypetreeToolStripMenuItem.ToolTipText = "(Applies to assets with typetree included). Slower but more correct parsing. Only" + - " for Texture2D and AnimationClip assets for now."; + this.useAssetLoadingViaTypetreeToolStripMenuItem.ToolTipText = "(Applies to assets with typetree included). Slower but can parse non-standard ass" + + "ets. Only for Texture2D, AnimationClip and Material assets for now."; this.useAssetLoadingViaTypetreeToolStripMenuItem.CheckedChanged += new System.EventHandler(this.useAssetLoadingViaTypetreeToolStripMenuItem_CheckedChanged); // // assetLoadingToolStripSeparator diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index f0e09a5..aa16c13 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -1123,8 +1123,8 @@ namespace AssetStudioGUI } } soundBuff = BigArrayPool.Shared.Rent(m_AudioClip.m_AudioData.Size); - m_AudioClip.m_AudioData.GetData(soundBuff, out var read); - if (read <= 0) + var dataLen = m_AudioClip.m_AudioData.GetData(soundBuff); + if (dataLen <= 0) return; var exinfo = new FMOD.CREATESOUNDEXINFO(); @@ -1550,6 +1550,9 @@ namespace AssetStudioGUI private void ResetForm() { + if (Studio.assetsManager.assetsFileList.Count > 0) + Logger.Info("Resetting program..."); + Text = guiTitle; Studio.assetsManager.Clear(); Studio.assemblyLoader.Clear(); diff --git a/AssetStudioGUI/ParallelExport.cs b/AssetStudioGUI/ParallelExport.cs index f3fe5e4..af7fe23 100644 --- a/AssetStudioGUI/ParallelExport.cs +++ b/AssetStudioGUI/ParallelExport.cs @@ -95,14 +95,14 @@ namespace AssetStudioGUI public static bool ExportAudioClip(AssetItem item, string exportPath, out string debugLog) { - debugLog = ""; - string exportFullPath; + debugLog = string.Empty; var m_AudioClip = (AudioClip)item.Asset; var m_AudioData = BigArrayPool.Shared.Rent(m_AudioClip.m_AudioData.Size); try { - m_AudioClip.m_AudioData.GetData(m_AudioData, out var read); - if (read <= 0) + string exportFullPath; + var dataLen = m_AudioClip.m_AudioData.GetData(m_AudioData); + if (dataLen <= 0) { Logger.Warning($"Failed to export \"{item.Text}\": AudioData was not found"); return false; diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index eba18b9..5b25b37 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -1182,7 +1182,10 @@ namespace AssetStudioGUI { foreach (var assetKvp in l2dAssetContainers) { - l2dContainers[assetKvp.Key] = Path.GetFileName(assetKvp.Key.assetsFile.originalPath); + var container = string.IsNullOrEmpty(assetKvp.Key.assetsFile.originalPath) + ? assetKvp.Key.assetsFile.fullName + : assetKvp.Key.assetsFile.originalPath; + l2dContainers[assetKvp.Key] = container; } } var mocPathDict = GenerateMocPathDict(mocDict, l2dContainers, searchByFilename); @@ -1243,16 +1246,19 @@ namespace AssetStudioGUI try { var cubismExtractor = new Live2DExtractor(assetGroupKvp, selClipMotions, selFadeMotions, selFadeLst); + var filename = string.IsNullOrEmpty(cubismExtractor.MocMono.assetsFile.originalPath) + ? Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.fileName) + : Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); string modelPath; switch (modelGroupOption) { case Live2DModelGroupOption.SourceFileName: - modelPath = Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); + modelPath = filename; break; case Live2DModelGroupOption.ModelName: modelPath = !string.IsNullOrEmpty(cubismExtractor.Model?.Name) ? cubismExtractor.Model.Name - : Path.GetFileNameWithoutExtension(cubismExtractor.MocMono.assetsFile.originalPath); + : filename; break; default: //ContainerPath var container = searchByFilename && cubismExtractor.Model != null diff --git a/AssetStudioUtility/Audio/AudioClipConverter.cs b/AssetStudioUtility/Audio/AudioClipConverter.cs index 7c5044c..bbacf10 100644 --- a/AssetStudioUtility/Audio/AudioClipConverter.cs +++ b/AssetStudioUtility/Audio/AudioClipConverter.cs @@ -130,8 +130,8 @@ namespace AssetStudio debugLog += "[Legacy wav converter] Generating wav header..\n"; var buffer = new byte[audioSize + 44]; - m_AudioClip.m_AudioData.GetData(buffer, out var read, 44); - if (read > 0) + var dataLen = m_AudioClip.m_AudioData.GetData(buffer, 44); + if (dataLen > 0) { var wavHeader = new WavHeader(audioSize, audioFormat, channels, (uint)sampleRate, bits); wavHeader.WriteToArray(buffer); @@ -141,16 +141,16 @@ namespace AssetStudio private static void ReadAsPcm16(IntPtr srcPtr, byte[] destBuffer, int offset, uint pcmDataLen, ref string debugLog) { - var pcmFloatSample = new byte[4]; + var pcmFloatVal = new byte[4]; for (var i = 0; i < pcmDataLen; i += 4) { for (var j = 0; j < 4; j++) { - pcmFloatSample[j] = Marshal.ReadByte(srcPtr, i + j); + pcmFloatVal[j] = Marshal.ReadByte(srcPtr, i + j); } - var pcm16Sample = (short)MathHelper.Clamp(BitConverter.ToSingle(pcmFloatSample, 0) * short.MaxValue, short.MinValue, short.MaxValue); - destBuffer[offset] = (byte)(pcm16Sample & 255); - destBuffer[offset + 1] = (byte)(pcm16Sample >> 8); + var pcm16Val = (short)MathHelper.Clamp(BitConverter.ToSingle(pcmFloatVal, 0) * short.MaxValue, short.MinValue, short.MaxValue); + destBuffer[offset] = (byte)(pcm16Val & 255); + destBuffer[offset + 1] = (byte)(pcm16Val >> 8); offset += 2; } debugLog += "Finished PCMFLOAT -> PCM16 converting\n"; diff --git a/AssetStudioUtility/Texture2DConverter.cs b/AssetStudioUtility/Texture2DConverter.cs index 7a1c3f4..8e39187 100644 --- a/AssetStudioUtility/Texture2DConverter.cs +++ b/AssetStudioUtility/Texture2DConverter.cs @@ -89,7 +89,7 @@ namespace AssetStudio var buff = BigArrayPool.Shared.Rent(reader.Size); try { - reader.GetData(buff, out _); + _ = reader.GetData(buff); if (switchSwizzled) { var unswizzledData = BigArrayPool.Shared.Rent(reader.Size); diff --git a/AssetStudioUtility/Texture2DExtensions.cs b/AssetStudioUtility/Texture2DExtensions.cs index 0bf338c..308a77d 100644 --- a/AssetStudioUtility/Texture2DExtensions.cs +++ b/AssetStudioUtility/Texture2DExtensions.cs @@ -1,7 +1,8 @@ -using SixLabors.ImageSharp; +using System; +using System.IO; +using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using System.IO; namespace AssetStudio { @@ -10,8 +11,8 @@ namespace AssetStudio public static Image ConvertToImage(this Texture2D m_Texture2D, bool flip) { var converter = new Texture2DConverter(m_Texture2D); - var uncroppedSize = converter.GetUncroppedSize(); var buff = BigArrayPool.Shared.Rent(converter.OutputDataSize); + var spanBuff = buff.AsSpan(0, converter.OutputDataSize); try { if (!converter.DecodeTexture2D(buff)) @@ -20,12 +21,13 @@ namespace AssetStudio Image image; if (converter.UsesSwitchSwizzle) { - image = Image.LoadPixelData(buff, uncroppedSize.Width, uncroppedSize.Height); + var uncroppedSize = converter.GetUncroppedSize(); + image = Image.LoadPixelData(spanBuff, uncroppedSize.Width, uncroppedSize.Height); image.Mutate(x => x.Crop(m_Texture2D.m_Width, m_Texture2D.m_Height)); } else { - image = Image.LoadPixelData(buff, m_Texture2D.m_Width, m_Texture2D.m_Height); + image = Image.LoadPixelData(spanBuff, m_Texture2D.m_Width, m_Texture2D.m_Height); } if (flip) diff --git a/AssetStudioUtility/Texture2DSwitchDeswizzler.cs b/AssetStudioUtility/Texture2DSwitchDeswizzler.cs index 58d9c7f..9db21c2 100644 --- a/AssetStudioUtility/Texture2DSwitchDeswizzler.cs +++ b/AssetStudioUtility/Texture2DSwitchDeswizzler.cs @@ -43,7 +43,7 @@ namespace AssetStudio return (a + b - 1) / b; } - internal static void Unswizzle(byte[] data, Size imageSize, Size blockSize, int gobsPerBlock, byte[] newData) + internal static void Unswizzle(ReadOnlySpan data, Size imageSize, Size blockSize, int gobsPerBlock, Span newData) { int width = imageSize.Width; int height = imageSize.Height; @@ -69,7 +69,7 @@ namespace AssetStudio int gobDstY = (i * gobsPerBlock + k) * GOB_Y_TEXEL_COUNT + gobY; int gobDstLinPos = gobDstY * blockCountX * TEXEL_BYTE_SIZE + gobDstX * TEXEL_BYTE_SIZE; - Buffer.BlockCopy(data, srcPos, newData, gobDstLinPos, TEXEL_BYTE_SIZE); + data.Slice(srcPos, TEXEL_BYTE_SIZE).CopyTo(newData.Slice(gobDstLinPos)); srcPos += TEXEL_BYTE_SIZE; }