diff --git a/AssetStudio.CLI/Studio.cs b/AssetStudio.CLI/Studio.cs index 7910bf5..15e7e71 100644 --- a/AssetStudio.CLI/Studio.cs +++ b/AssetStudio.CLI/Studio.cs @@ -159,7 +159,7 @@ private static int ExtractMhyFile(FileReader reader, string savePath) Logger.Info($"Decompressing {reader.FileName} ..."); try { - var mhy0File = new MhyFile(reader, reader.FullPath, (Mhy)Game); + var mhy0File = new MhyFile(reader, (Mhy)Game); reader.Dispose(); if (mhy0File.fileList.Count > 0) { diff --git a/AssetStudio.GUI/Studio.cs b/AssetStudio.GUI/Studio.cs index c7d7454..353f15f 100644 --- a/AssetStudio.GUI/Studio.cs +++ b/AssetStudio.GUI/Studio.cs @@ -160,7 +160,7 @@ private static int ExtractMhyFile(FileReader reader, string savePath) StatusStripUpdate($"Decompressing {reader.FileName} ..."); try { - var mhy0File = new MhyFile(reader, reader.FullPath, (Mhy)Game); + var mhy0File = new MhyFile(reader, (Mhy)Game); reader.Dispose(); if (mhy0File.fileList.Count > 0) { diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index 76343ed..e7675c2 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -512,8 +512,8 @@ private void LoadMhyFile(FileReader reader, string originalPath = null, long ori } try { - var mhyFile = new MhyFile(reader, reader.FullPath, (Mhy)Game); - Logger.Verbose($"mhy total size: {mhyFile.TotalSize:X8}"); + var mhyFile = new MhyFile(reader, (Mhy)Game); + Logger.Verbose($"mhy total size: {mhyFile.m_Header.size:X8}"); foreach (var file in mhyFile.fileList) { var dummyPath = Path.Combine(Path.GetDirectoryName(reader.FullPath), file.fileName); diff --git a/AssetStudio/MhyFile.cs b/AssetStudio/MhyFile.cs index 91e9899..dbbea0f 100644 --- a/AssetStudio/MhyFile.cs +++ b/AssetStudio/MhyFile.cs @@ -14,15 +14,11 @@ public class MhyFile public BundleFile.Header m_Header; public List fileList; - public long Offset; public Mhy mhy; - public long TotalSize => 8 + m_Header.compressedBlocksInfoSize + m_BlocksInfo.Sum(x => x.compressedSize); - - public MhyFile(FileReader reader, string path, Mhy mhy) + public MhyFile(FileReader reader, Mhy mhy) { this.mhy = mhy; - Offset = reader.Position; reader.Endian = EndianType.LittleEndian; signature = reader.ReadStringToNull(4); @@ -40,9 +36,14 @@ public MhyFile(FileReader reader, string path, Mhy mhy) }; Logger.Verbose($"Header: {m_Header}"); ReadBlocksInfoAndDirectory(reader); - using var blocksStream = CreateBlocksStream(path); + using var blocksStream = CreateBlocksStream(reader.FullPath); ReadBlocks(reader, blocksStream); - ReadFiles(blocksStream, path); + ReadFiles(blocksStream, reader.FullPath); + m_Header.size = 8 + m_Header.compressedBlocksInfoSize + m_BlocksInfo.Sum(x => x.compressedSize); + while (reader.PeekChar() == '\0') + { + reader.Position++; + } } private void ReadBlocksInfoAndDirectory(FileReader reader) diff --git a/AssetStudio/OffsetStream.cs b/AssetStudio/OffsetStream.cs index 44c8ee1..46315e7 100644 --- a/AssetStudio/OffsetStream.cs +++ b/AssetStudio/OffsetStream.cs @@ -81,42 +81,10 @@ public IEnumerable GetOffsets(string path) } else { - using var reader = new FileReader(path, this, true); - var signature = reader.FileType switch + while (Remaining > 0) { - FileType.BundleFile => "UnityFS\x00", - FileType.BlbFile => "Blb\x02", - FileType.MhyFile => Encoding.UTF8.GetString(reader.ReadBytes(4)), - FileType.ENCRFile => "ENCR\x00", - _ => throw new InvalidOperationException() - }; - reader.Position = 0; - - Logger.Verbose($"Prased signature: {signature}"); - - var signatureBytes = Encoding.UTF8.GetBytes(signature); - var buffer = ArrayPool.Shared.Rent(BufferSize); - try - { - while (Remaining > 0) - { - var index = 0; - var absOffset = AbsolutePosition; - var read = Read(buffer); - while (index < read) - { - index = buffer.AsSpan(0, read).Search(signatureBytes, index); - if (index == -1) break; - var offset = absOffset + index; - Offset = offset; - yield return offset; - index++; - } - } - } - finally - { - ArrayPool.Shared.Return(buffer, true); + Offset = AbsolutePosition; + yield return AbsolutePosition; } } }