mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-11-12 23:32:42 -05:00
Update FileReader & EndianSpanReader
This commit is contained in:
@ -57,7 +57,7 @@ namespace AssetStudio
|
|||||||
}
|
}
|
||||||
isBigEndian = BitConverter.ToBoolean(modelData, 5);
|
isBigEndian = BitConverter.ToBoolean(modelData, 5);
|
||||||
|
|
||||||
var modelDataSpan = modelData.AsSpan();
|
var modelDataSpan = new ReadOnlySpan<byte>(modelData, 0, modelDataSize);
|
||||||
//offsets
|
//offsets
|
||||||
var countInfoTableOffset = (int)modelDataSpan.ReadUInt32(64, isBigEndian);
|
var countInfoTableOffset = (int)modelDataSpan.ReadUInt32(64, isBigEndian);
|
||||||
var canvasInfoOffset = (int)modelDataSpan.ReadUInt32(68, isBigEndian);
|
var canvasInfoOffset = (int)modelDataSpan.ReadUInt32(68, isBigEndian);
|
||||||
@ -74,8 +74,8 @@ namespace AssetStudio
|
|||||||
//model
|
//model
|
||||||
PartCount = modelDataSpan.ReadUInt32(countInfoTableOffset, isBigEndian);
|
PartCount = modelDataSpan.ReadUInt32(countInfoTableOffset, isBigEndian);
|
||||||
ParamCount = modelDataSpan.ReadUInt32(countInfoTableOffset + 20, isBigEndian);
|
ParamCount = modelDataSpan.ReadUInt32(countInfoTableOffset + 20, isBigEndian);
|
||||||
PartNames = ReadMocStrings(modelData, (int)partIdsOffset, (int)PartCount);
|
PartNames = ReadMocStrings(modelDataSpan, (int)partIdsOffset, (int)PartCount);
|
||||||
ParamNames = ReadMocStrings(modelData, (int)parameterIdsOffset, (int)ParamCount);
|
ParamNames = ReadMocStrings(modelDataSpan, (int)parameterIdsOffset, (int)ParamCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveMoc3(string savePath)
|
public void SaveMoc3(string savePath)
|
||||||
@ -102,7 +102,7 @@ namespace AssetStudio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<string> ReadMocStrings(Span<byte> data, int index, int count)
|
private static HashSet<string> ReadMocStrings(ReadOnlySpan<byte> data, int index, int count)
|
||||||
{
|
{
|
||||||
const int strLen = 64;
|
const int strLen = 64;
|
||||||
var strHashSet = new HashSet<string>();
|
var strHashSet = new HashSet<string>();
|
||||||
|
|||||||
@ -8,10 +8,10 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
public static uint ReadUInt32(this Span<byte> data, int start, bool isBigEndian)
|
public static uint ReadUInt32(this Span<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return SpanToUInt32(data, start, isBigEndian);
|
return ReadUInt32((ReadOnlySpan<byte>)data, start, isBigEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint SpanToUInt32(Span<byte> data, int start, bool isBigEndian)
|
public static uint ReadUInt32(this ReadOnlySpan<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return isBigEndian
|
return isBigEndian
|
||||||
? BinaryPrimitives.ReadUInt32BigEndian(data.Slice(start))
|
? BinaryPrimitives.ReadUInt32BigEndian(data.Slice(start))
|
||||||
@ -20,10 +20,10 @@ namespace AssetStudio
|
|||||||
|
|
||||||
public static long ReadUInt16(this Span<byte> data, int start, bool isBigEndian)
|
public static long ReadUInt16(this Span<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return SpanToUInt16(data, start, isBigEndian);
|
return ReadUInt16((ReadOnlySpan<byte>)data, start, isBigEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint SpanToUInt16(Span<byte> data, int start, bool isBigEndian)
|
public static uint ReadUInt16(this ReadOnlySpan<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return isBigEndian
|
return isBigEndian
|
||||||
? BinaryPrimitives.ReadUInt16BigEndian(data.Slice(start))
|
? BinaryPrimitives.ReadUInt16BigEndian(data.Slice(start))
|
||||||
@ -32,10 +32,10 @@ namespace AssetStudio
|
|||||||
|
|
||||||
public static long ReadInt64(this Span<byte> data, int start, bool isBigEndian)
|
public static long ReadInt64(this Span<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return SpanToInt64(data, start, isBigEndian);
|
return ReadInt64((ReadOnlySpan<byte>)data, start, isBigEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long SpanToInt64(Span<byte> data, int start, bool isBigEndian)
|
public static long ReadInt64(this ReadOnlySpan<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return isBigEndian
|
return isBigEndian
|
||||||
? BinaryPrimitives.ReadInt64BigEndian(data.Slice(start))
|
? BinaryPrimitives.ReadInt64BigEndian(data.Slice(start))
|
||||||
@ -44,20 +44,20 @@ namespace AssetStudio
|
|||||||
|
|
||||||
public static float ReadSingle(this Span<byte> data, int start, bool isBigEndian)
|
public static float ReadSingle(this Span<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return SpanToSingle(data, start, isBigEndian);
|
return ReadSingle((ReadOnlySpan<byte>)data, start, isBigEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public static float SpanToSingle(Span<byte> data, int start, bool isBigEndian)
|
public static float ReadSingle(this ReadOnlySpan<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
var bytes = data.Slice(start, 4);
|
var bytes = data.Slice(start, 4).ToArray();
|
||||||
if ((isBigEndian && BitConverter.IsLittleEndian) || (!isBigEndian && !BitConverter.IsLittleEndian))
|
if ((isBigEndian && BitConverter.IsLittleEndian) || (!isBigEndian && !BitConverter.IsLittleEndian))
|
||||||
bytes.Reverse();
|
bytes.AsSpan().Reverse();
|
||||||
|
|
||||||
return BitConverter.ToSingle(bytes.ToArray(), 0);
|
return BitConverter.ToSingle(bytes, 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static float SpanToSingle(Span<byte> data, int start, bool isBigEndian)
|
public static float ReadSingle(this ReadOnlySpan<byte> data, int start, bool isBigEndian)
|
||||||
{
|
{
|
||||||
return isBigEndian
|
return isBigEndian
|
||||||
? BinaryPrimitives.ReadSingleBigEndian(data[start..])
|
? BinaryPrimitives.ReadSingleBigEndian(data[start..])
|
||||||
@ -66,6 +66,11 @@ namespace AssetStudio
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static string ReadStringToNull(this Span<byte> data, int maxLength = 32767)
|
public static string ReadStringToNull(this Span<byte> data, int maxLength = 32767)
|
||||||
|
{
|
||||||
|
return ReadStringToNull((ReadOnlySpan<byte>)data, maxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ReadStringToNull(this ReadOnlySpan<byte> data, int maxLength = 32767)
|
||||||
{
|
{
|
||||||
Span<byte> bytes = stackalloc byte[maxLength];
|
Span<byte> bytes = stackalloc byte[maxLength];
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace AssetStudio
|
|||||||
private static readonly byte[] brotliMagic = { 0x62, 0x72, 0x6F, 0x74, 0x6C, 0x69 };
|
private static readonly byte[] brotliMagic = { 0x62, 0x72, 0x6F, 0x74, 0x6C, 0x69 };
|
||||||
private static readonly byte[] zipMagic = { 0x50, 0x4B, 0x03, 0x04 };
|
private static readonly byte[] zipMagic = { 0x50, 0x4B, 0x03, 0x04 };
|
||||||
private static readonly byte[] zipSpannedMagic = { 0x50, 0x4B, 0x07, 0x08 };
|
private static readonly byte[] zipSpannedMagic = { 0x50, 0x4B, 0x07, 0x08 };
|
||||||
private static readonly byte[] unityFsMagic = {0x55, 0x6E, 0x69, 0x74, 0x79, 0x46, 0x53};
|
private static readonly byte[] unityFsMagic = {0x55, 0x6E, 0x69, 0x74, 0x79, 0x46, 0x53, 0x00};
|
||||||
private static readonly int headerBuffLen = 1152;
|
private static readonly int headerBuffLen = 1152;
|
||||||
private static byte[] headerBuff = new byte[headerBuffLen];
|
private static byte[] headerBuff = new byte[headerBuffLen];
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ namespace AssetStudio
|
|||||||
CheckBundleDataOffset(buff);
|
CheckBundleDataOffset(buff);
|
||||||
return FileType.BundleFile;
|
return FileType.BundleFile;
|
||||||
case "UnityWebData1.0":
|
case "UnityWebData1.0":
|
||||||
return FileType.WebFile;
|
|
||||||
case "TuanjieWebData1.0":
|
case "TuanjieWebData1.0":
|
||||||
return FileType.WebFile;
|
return FileType.WebFile;
|
||||||
default:
|
default:
|
||||||
@ -83,7 +82,7 @@ namespace AssetStudio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsSerializedFile(Span<byte> buff)
|
private bool IsSerializedFile(ReadOnlySpan<byte> buff)
|
||||||
{
|
{
|
||||||
var fileSize = BaseStream.Length;
|
var fileSize = BaseStream.Length;
|
||||||
if (fileSize < 20)
|
if (fileSize < 20)
|
||||||
@ -129,12 +128,10 @@ namespace AssetStudio
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Position = firstOffset;
|
var pos = firstOffset + 12;
|
||||||
_ = this.ReadStringToNull();
|
pos += buff.Slice(pos).ReadStringToNull().Length + 1;
|
||||||
_ = this.ReadUInt32();
|
pos += buff.Slice(pos).ReadStringToNull().Length + 1;
|
||||||
_ = this.ReadStringToNull();
|
var bundleSize = buff.ReadInt64(pos, Endian == EndianType.BigEndian);
|
||||||
_ = this.ReadStringToNull();
|
|
||||||
var bundleSize = this.ReadInt64();
|
|
||||||
if (bundleSize > 200 && firstOffset + bundleSize < lastOffset)
|
if (bundleSize > 200 && firstOffset + bundleSize < lastOffset)
|
||||||
{
|
{
|
||||||
Position = firstOffset;
|
Position = firstOffset;
|
||||||
|
|||||||
Reference in New Issue
Block a user