mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-07-15 11:04:16 -04:00
cleanup code
This commit is contained in:
@ -20,115 +20,115 @@ namespace Unity_Studio
|
||||
|
||||
public EndianStream(Stream stream, EndianType endian) : base(stream) { }
|
||||
|
||||
public long Position { get { return base.BaseStream.Position; } set { base.BaseStream.Position = value; } }
|
||||
public long Position { get { return BaseStream.Position; } set { BaseStream.Position = value; } }
|
||||
|
||||
public override short ReadInt16()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a16 = base.ReadBytes(2);
|
||||
a16 = ReadBytes(2);
|
||||
Array.Reverse(a16);
|
||||
return BitConverter.ToInt16(a16, 0);
|
||||
}
|
||||
else return base.ReadInt16();
|
||||
return base.ReadInt16();
|
||||
}
|
||||
|
||||
public override int ReadInt32()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a32 = base.ReadBytes(4);
|
||||
a32 = ReadBytes(4);
|
||||
Array.Reverse(a32);
|
||||
return BitConverter.ToInt32(a32, 0);
|
||||
}
|
||||
else return base.ReadInt32();
|
||||
return base.ReadInt32();
|
||||
}
|
||||
|
||||
public override long ReadInt64()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a64 = base.ReadBytes(8);
|
||||
a64 = ReadBytes(8);
|
||||
Array.Reverse(a64);
|
||||
return BitConverter.ToInt64(a64, 0);
|
||||
}
|
||||
else return base.ReadInt64();
|
||||
return base.ReadInt64();
|
||||
}
|
||||
|
||||
public override ushort ReadUInt16()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a16 = base.ReadBytes(2);
|
||||
a16 = ReadBytes(2);
|
||||
Array.Reverse(a16);
|
||||
return BitConverter.ToUInt16(a16, 0);
|
||||
}
|
||||
else return base.ReadUInt16();
|
||||
return base.ReadUInt16();
|
||||
}
|
||||
|
||||
public override uint ReadUInt32()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a32 = base.ReadBytes(4);
|
||||
a32 = ReadBytes(4);
|
||||
Array.Reverse(a32);
|
||||
return BitConverter.ToUInt32(a32, 0);
|
||||
}
|
||||
else return base.ReadUInt32();
|
||||
return base.ReadUInt32();
|
||||
}
|
||||
|
||||
public override ulong ReadUInt64()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a64 = base.ReadBytes(8);
|
||||
a64 = ReadBytes(8);
|
||||
Array.Reverse(a64);
|
||||
return BitConverter.ToUInt64(a64, 0);
|
||||
}
|
||||
else return base.ReadUInt64();
|
||||
return base.ReadUInt64();
|
||||
}
|
||||
|
||||
public override float ReadSingle()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a32 = base.ReadBytes(4);
|
||||
a32 = ReadBytes(4);
|
||||
Array.Reverse(a32);
|
||||
return BitConverter.ToSingle(a32, 0);
|
||||
}
|
||||
else return base.ReadSingle();
|
||||
return base.ReadSingle();
|
||||
}
|
||||
|
||||
public override double ReadDouble()
|
||||
{
|
||||
if (endian == EndianType.BigEndian)
|
||||
{
|
||||
a64 = base.ReadBytes(8);
|
||||
a64 = ReadBytes(8);
|
||||
Array.Reverse(a64);
|
||||
return BitConverter.ToUInt64(a64, 0);
|
||||
}
|
||||
else return base.ReadDouble();
|
||||
return base.ReadDouble();
|
||||
}
|
||||
|
||||
public string ReadASCII(int length)
|
||||
{
|
||||
return Encoding.ASCII.GetString(base.ReadBytes(length));
|
||||
return Encoding.ASCII.GetString(ReadBytes(length));
|
||||
}
|
||||
|
||||
public void AlignStream(int alignment)
|
||||
{
|
||||
long pos = base.BaseStream.Position;
|
||||
long pos = BaseStream.Position;
|
||||
//long padding = alignment - pos + (pos / alignment) * alignment;
|
||||
//if (padding != alignment) { base.BaseStream.Position += padding; }
|
||||
if ((pos % alignment) != 0) { base.BaseStream.Position += alignment - (pos % alignment); }
|
||||
if ((pos % alignment) != 0) { BaseStream.Position += alignment - (pos % alignment); }
|
||||
}
|
||||
|
||||
public string ReadAlignedString(int length)
|
||||
{
|
||||
if (length > 0 && length < (base.BaseStream.Length - base.BaseStream.Position))//crude failsafe
|
||||
if (length > 0 && length < (BaseStream.Length - BaseStream.Position))//crude failsafe
|
||||
{
|
||||
byte[] stringData = new byte[length];
|
||||
base.Read(stringData, 0, length);
|
||||
Read(stringData, 0, length);
|
||||
var result = Encoding.UTF8.GetString(stringData); //must verify strange characters in PS3
|
||||
|
||||
/*string result = "";
|
||||
@ -142,7 +142,7 @@ namespace Unity_Studio
|
||||
AlignStream(4);
|
||||
return result;
|
||||
}
|
||||
else { return ""; }
|
||||
return "";
|
||||
}
|
||||
|
||||
public string ReadStringToNull()
|
||||
|
Reference in New Issue
Block a user