using LibXom.Data; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LibXom.Streams { public class XomStreamReader : IDisposable { private Stream xStream; public Stream BaseStream { get { return xStream; } } public int[] ReadCompressedIntArray() { int len = this.ReadCompressedInt(); int[] arr = new int[len]; for(int i = 0; i < len; i++) arr[i] = this.ReadCompressedInt(); return arr; } public int ReadCompressedInt() { return XomCompressor.ReadCompressedIntFromStream(xStream); } public byte[] ReadBytes(int amt) { byte[] buffer = new byte[amt]; xStream.Read(buffer, 0, amt); return buffer; } public bool ReadBool() { return (ReadByte() == 0x01); } public byte ReadByte() { return Convert.ToByte(xStream.ReadByte()); } public string ReadStrLen(int len) { byte[] buf = ReadBytes(len); int rlen = 0; for (rlen = 0; rlen < len; rlen++) if (buf[rlen] == 0) break; return Encoding.UTF8.GetString(buf, 0, rlen); } public string ReadCStr() { List cstr = new List(); while (true) { byte c = ReadByte(); if (c == 0) break; cstr.Add(c); } return Encoding.UTF8.GetString(cstr.ToArray()); } public void Skip(int amt) { xStream.Seek(amt, SeekOrigin.Current); } public float ReadFloat() { return BitConverter.ToSingle(ReadBytes(0x4)); } public int ReadInt32() { return BitConverter.ToInt32(ReadBytes(0x4)); } public int ReadInt32BE() { byte[] buffer = ReadBytes(0x4); buffer.Reverse(); return BitConverter.ToInt32(buffer); } public void Dispose() { this.xStream.Dispose(); } public XomStreamReader(Stream xStream) { this.xStream = xStream; } } }