Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
- [Core] fix but with wrongly identified sigantures [GI]
Browse files Browse the repository at this point in the history
  • Loading branch information
Razmoth committed Jan 27, 2024
1 parent 2d965c0 commit 8735977
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 46 deletions.
2 changes: 1 addition & 1 deletion AssetStudio.CLI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion AssetStudio.GUI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions AssetStudio/AssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions AssetStudio/MhyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ public class MhyFile

public BundleFile.Header m_Header;
public List<StreamFile> 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);
Expand All @@ -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)
Expand Down
38 changes: 3 additions & 35 deletions AssetStudio/OffsetStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,10 @@ public IEnumerable<long> 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<byte>.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<byte>.Shared.Return(buffer, true);
Offset = AbsolutePosition;
yield return AbsolutePosition;
}
}
}
Expand Down

0 comments on commit 8735977

Please sign in to comment.