- [Core] Added Blb file parsing [GI]

This commit is contained in:
Razmoth
2023-09-19 13:22:50 +04:00
parent a7e7cb7702
commit dbec3e254e
7 changed files with 282 additions and 65 deletions

View File

@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace AssetStudio
{
public class OffsetStream : Stream
{
private const int BufferSize = 0x10000;
private readonly Stream _baseStream;
private long _offset;
@@ -64,5 +68,48 @@ namespace AssetStudio
public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException();
public override void SetLength(long value) => throw new NotImplementedException();
public override void Flush() => throw new NotImplementedException();
public IEnumerable<long> GetOffsets(string path)
{
if (AssetsHelper.TryGet(path, out var offsets))
{
foreach (var offset in offsets)
{
Offset = offset;
yield return offset;
}
}
else
{
using var reader = new FileReader(path, this, true);
var signature = reader.FileType switch
{
FileType.BundleFile => "UnityFS\x00",
FileType.BlbFile => "Blb\x02",
FileType.Mhy0File => "mhy0",
_ => throw new InvalidOperationException()
};
Logger.Verbose($"Prased signature: {signature}");
var signatureBytes = Encoding.UTF8.GetBytes(signature);
var buffer = BigArrayPool<byte>.Shared.Rent(BufferSize);
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++;
}
}
BigArrayPool<byte>.Shared.Return(buffer);
}
}
}
}