2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_IOSTREAMS_HPP__
|
|
|
|
#define __URDE_IOSTREAMS_HPP__
|
2015-08-23 23:58:07 +00:00
|
|
|
|
2016-04-11 07:10:28 +00:00
|
|
|
#include "GCNTypes.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include <athena/IStreamReader.hpp>
|
|
|
|
#include <athena/IStreamWriter.hpp>
|
|
|
|
#include <athena/MemoryReader.hpp>
|
2016-04-11 07:10:28 +00:00
|
|
|
#include <athena/MemoryWriter.hpp>
|
2015-08-23 23:58:07 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-23 23:58:07 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
using CInputStream = athena::io::IStreamReader;
|
|
|
|
using COutputStream = athena::io::IStreamWriter;
|
2015-08-23 23:58:07 +00:00
|
|
|
|
2016-03-19 19:19:43 +00:00
|
|
|
struct CBitStreamReader : athena::io::MemoryCopyReader
|
2016-03-15 23:44:59 +00:00
|
|
|
{
|
2016-03-19 19:19:43 +00:00
|
|
|
u32 x1c_val = 0;
|
|
|
|
u32 x20_bitOffset = 0;
|
|
|
|
public:
|
2016-03-20 04:10:29 +00:00
|
|
|
static s32 GetBitCount(s32 maxVal)
|
2016-03-19 19:19:43 +00:00
|
|
|
{
|
|
|
|
s32 ret = 0;
|
2016-03-20 04:10:29 +00:00
|
|
|
while (maxVal != 0)
|
2016-03-19 19:19:43 +00:00
|
|
|
{
|
2016-03-20 04:10:29 +00:00
|
|
|
maxVal /= 2;
|
2016-03-19 19:19:43 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBitStreamReader(const void* data, atUint64 length)
|
|
|
|
: MemoryCopyReader(data, length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CBitStreamReader(const std::string& filename)
|
|
|
|
: MemoryCopyReader(filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
atUint64 readUBytesToBuf(void *buf, atUint64 len)
|
|
|
|
{
|
|
|
|
x20_bitOffset = 0;
|
|
|
|
atUint64 tmp = MemoryCopyReader::readUBytesToBuf(buf, len);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 ReadEncoded(u32 key);
|
2016-03-15 23:44:59 +00:00
|
|
|
};
|
|
|
|
|
2016-03-20 04:10:29 +00:00
|
|
|
class CBitStreamWriter : public athena::io::MemoryCopyWriter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
u32 x14_val = 0;
|
|
|
|
u32 x18_bitOffset = 32;
|
|
|
|
public:
|
|
|
|
static inline u32 GetBitCount(u32 maxVal) { return CBitStreamReader::GetBitCount(maxVal); }
|
|
|
|
|
|
|
|
CBitStreamWriter(atUint8* data = nullptr, atUint64 length=0x10)
|
|
|
|
: MemoryCopyWriter(data, length)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CBitStreamWriter(const std::string& filename)
|
|
|
|
: MemoryCopyWriter(filename)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void writeUBytes(const atUint8 *data, atUint64 len)
|
|
|
|
{
|
|
|
|
x14_val = 0;
|
|
|
|
x18_bitOffset = 0x20;
|
|
|
|
MemoryCopyWriter::writeUBytes(data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteEncoded(u32 val, u32 bitCount);
|
|
|
|
};
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
using CMemoryInStream = athena::io::MemoryReader;
|
2015-08-23 23:58:07 +00:00
|
|
|
|
|
|
|
class CZipInputStream : public CInputStream
|
|
|
|
{
|
|
|
|
std::unique_ptr<u8[]> x24_compBuf;
|
|
|
|
std::unique_ptr<CInputStream> x28_strm;
|
|
|
|
z_stream x30_zstrm = {};
|
|
|
|
public:
|
|
|
|
CZipInputStream(std::unique_ptr<CInputStream>&& strm);
|
|
|
|
~CZipInputStream();
|
|
|
|
atUint64 readUBytesToBuf(void *buf, atUint64 len);
|
2016-03-04 23:04:53 +00:00
|
|
|
void seek(atInt64, athena::SeekOrigin) {}
|
2015-08-23 23:58:07 +00:00
|
|
|
atUint64 position() const {return 0;}
|
|
|
|
atUint64 length() const {return 0;}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_IOSTREAMS_HPP__
|