mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-14 11:18:47 -05:00
Improve support for legacy Unity versions (WIP). Close #103
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace AssetStudio
|
||||
@@ -54,5 +55,66 @@ namespace AssetStudio
|
||||
{
|
||||
Position = byteStart;
|
||||
}
|
||||
|
||||
public override short ReadInt16()
|
||||
{
|
||||
if (Remaining < 2)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return base.ReadInt16();
|
||||
}
|
||||
|
||||
public override ushort ReadUInt16()
|
||||
{
|
||||
if (Remaining < 2)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return base.ReadUInt16();
|
||||
}
|
||||
|
||||
public override int ReadInt32()
|
||||
{
|
||||
if (Remaining < 4)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return base.ReadInt32();
|
||||
}
|
||||
|
||||
public override uint ReadUInt32()
|
||||
{
|
||||
if (Remaining < 4)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return base.ReadUInt32();
|
||||
}
|
||||
|
||||
public override float ReadSingle()
|
||||
{
|
||||
if (Remaining < 4)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return base.ReadSingle();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectReaderExtensions
|
||||
{
|
||||
public static string ReadAlignedString(this ObjectReader reader)
|
||||
{
|
||||
var needAlign = reader.version >= (2, 1); //aligned only since v2.1
|
||||
return reader.ReadAlignedString(needAlign);
|
||||
}
|
||||
|
||||
public static string[] ReadStringArray(this ObjectReader reader)
|
||||
{
|
||||
var length = reader.ReadInt32();
|
||||
var list = new List<string>();
|
||||
var needAlign = reader.version >= (2, 1);
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
list.Add(reader.ReadAlignedString(needAlign));
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user