Some minor fixes

This commit is contained in:
VaDiM 2025-05-11 17:57:33 +03:00
parent b0a051fc47
commit 55406553f6
17 changed files with 84 additions and 57 deletions

View File

@ -91,9 +91,7 @@ namespace AssetStudio
public void LoadFilesAndFolders(params string[] path)
{
var pathList = new List<string>();
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<string> pathList)
{
var fileList = new List<string>();
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}");
}
}
}

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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)

View File

@ -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)
{

View File

@ -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;

View File

@ -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<byte>.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;

View File

@ -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

View File

@ -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

View File

@ -1123,8 +1123,8 @@ namespace AssetStudioGUI
}
}
soundBuff = BigArrayPool<byte>.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();

View File

@ -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<byte>.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;

View File

@ -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

View File

@ -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";

View File

@ -89,7 +89,7 @@ namespace AssetStudio
var buff = BigArrayPool<byte>.Shared.Rent(reader.Size);
try
{
reader.GetData(buff, out _);
_ = reader.GetData(buff);
if (switchSwizzled)
{
var unswizzledData = BigArrayPool<byte>.Shared.Rent(reader.Size);

View File

@ -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<Bgra32> ConvertToImage(this Texture2D m_Texture2D, bool flip)
{
var converter = new Texture2DConverter(m_Texture2D);
var uncroppedSize = converter.GetUncroppedSize();
var buff = BigArrayPool<byte>.Shared.Rent(converter.OutputDataSize);
var spanBuff = buff.AsSpan(0, converter.OutputDataSize);
try
{
if (!converter.DecodeTexture2D(buff))
@ -20,12 +21,13 @@ namespace AssetStudio
Image<Bgra32> image;
if (converter.UsesSwitchSwizzle)
{
image = Image.LoadPixelData<Bgra32>(buff, uncroppedSize.Width, uncroppedSize.Height);
var uncroppedSize = converter.GetUncroppedSize();
image = Image.LoadPixelData<Bgra32>(spanBuff, uncroppedSize.Width, uncroppedSize.Height);
image.Mutate(x => x.Crop(m_Texture2D.m_Width, m_Texture2D.m_Height));
}
else
{
image = Image.LoadPixelData<Bgra32>(buff, m_Texture2D.m_Width, m_Texture2D.m_Height);
image = Image.LoadPixelData<Bgra32>(spanBuff, m_Texture2D.m_Width, m_Texture2D.m_Height);
}
if (flip)

View File

@ -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<byte> data, Size imageSize, Size blockSize, int gobsPerBlock, Span<byte> 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;
}