2019-05-10 18:56:19 +02:00
|
|
|
#ifndef SUBFILE_H
|
|
|
|
#define SUBFILE_H
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
class IMG;
|
2019-05-16 20:23:37 +02:00
|
|
|
class QFile;
|
2019-05-10 18:56:19 +02:00
|
|
|
|
|
|
|
class SubFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type {Unknown, TRE, RGN, LBL, NET, TYP, GMP};
|
|
|
|
|
|
|
|
struct Handle
|
|
|
|
{
|
|
|
|
Handle() : blockNum(-1), blockPos(-1), pos(-1) {}
|
|
|
|
|
|
|
|
QByteArray data;
|
|
|
|
int blockNum;
|
|
|
|
int blockPos;
|
|
|
|
int pos;
|
|
|
|
};
|
|
|
|
|
2020-01-19 13:23:20 +01:00
|
|
|
SubFile(IMG *img)
|
|
|
|
: _gmpOffset(0), _img(img), _blocks(new QVector<quint16>()), _file(0) {}
|
2019-09-05 22:31:13 +02:00
|
|
|
SubFile(SubFile *gmp, quint32 offset) : _gmpOffset(offset), _img(gmp->_img),
|
2020-01-19 13:23:20 +01:00
|
|
|
_blocks(gmp->_blocks), _file(gmp->_file) {}
|
|
|
|
SubFile(QFile *file)
|
|
|
|
: _gmpOffset(0), _img(0), _blocks(0), _file(file) {}
|
|
|
|
~SubFile()
|
|
|
|
{
|
|
|
|
if (!_gmpOffset)
|
|
|
|
delete _blocks;
|
|
|
|
}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2019-09-05 22:31:13 +02:00
|
|
|
void addBlock(quint16 block) {_blocks->append(block);}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
|
|
|
bool seek(Handle &handle, quint32 pos) const;
|
|
|
|
bool readByte(Handle &handle, quint8 &val) const;
|
|
|
|
|
|
|
|
bool readUInt16(Handle &handle, quint16 &val) const
|
|
|
|
{
|
|
|
|
quint8 b0, b1;
|
|
|
|
if (!(readByte(handle, b0) && readByte(handle, b1)))
|
|
|
|
return false;
|
|
|
|
val = b0 | ((quint16)b1) << 8;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readInt16(Handle &handle, qint16 &val) const
|
|
|
|
{
|
|
|
|
if (!readUInt16(handle, (quint16&)val))
|
|
|
|
return false;
|
|
|
|
if((quint16)val > 0x7FFF)
|
|
|
|
val = (val & 0x7FFF) - 0x8000;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readUInt24(Handle &handle, quint32 &val) const
|
|
|
|
{
|
|
|
|
quint8 b0, b1, b2;
|
|
|
|
if (!(readByte(handle, b0) && readByte(handle, b1)
|
|
|
|
&& readByte(handle, b2)))
|
|
|
|
return false;
|
|
|
|
val = b0 | ((quint32)b1) << 8 | ((quint32)b2) << 16;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readInt24(Handle &handle, qint32 &val) const
|
|
|
|
{
|
|
|
|
if (!readUInt24(handle, (quint32&)val))
|
|
|
|
return false;
|
|
|
|
if (val > 0x7FFFFF)
|
|
|
|
val = (val & 0x7FFFFF) - 0x800000;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readUInt32(Handle &handle, quint32 &val) const
|
|
|
|
{
|
|
|
|
quint8 b0, b1, b2, b3;
|
|
|
|
if (!(readByte(handle, b0) && readByte(handle, b1)
|
|
|
|
&& readByte(handle, b2) && readByte(handle, b3)))
|
|
|
|
return false;
|
|
|
|
val = b0 | ((quint32)b1) << 8 | ((quint32)b2) << 16
|
|
|
|
| ((quint32)b3) << 24;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-18 08:37:33 +02:00
|
|
|
bool readVUInt32(Handle &hdl, quint32 &val) const;
|
|
|
|
|
2019-09-05 22:31:13 +02:00
|
|
|
quint16 offset() const {return _blocks->first();}
|
2019-05-16 20:23:37 +02:00
|
|
|
QString fileName() const;
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2019-09-05 22:31:13 +02:00
|
|
|
protected:
|
|
|
|
quint32 _gmpOffset;
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
private:
|
|
|
|
IMG *_img;
|
2019-09-05 22:31:13 +02:00
|
|
|
QVector<quint16> *_blocks;
|
2020-01-19 13:23:20 +01:00
|
|
|
QFile *_file;
|
2019-05-10 18:56:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SUBFILE_H
|