mirror of https://github.com/libAthena/athena.git
* Finish modularization
This commit is contained in:
parent
e6d53f33a9
commit
e868c31253
|
@ -1,6 +1,7 @@
|
|||
CONFIG += staticlib c++11
|
||||
TEMPLATE= lib
|
||||
DESTDIR = ./lib
|
||||
INCLUDEPATH += $$PWD/include
|
||||
|
||||
# Uncomment this if you wish to use Qt with libAthena
|
||||
#DEFINES += ATHENA_USE_QT
|
||||
|
@ -29,6 +30,8 @@ CONFIG(release, release|debug): {
|
|||
OBJECTS_DIR = obj/release
|
||||
}
|
||||
|
||||
ATHENA_PRO=true
|
||||
|
||||
include(Athena.pri)
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
!contains($$INCLUDEPATH, $$PWD/include): {
|
||||
!contains(ATHENA_PRO, true): {
|
||||
INCLUDEPATH += $$PWD/include
|
||||
unix:LIBS += -lz
|
||||
win32:LIBS += -lzlib
|
||||
unix:LIBS += -lz -llzo2
|
||||
win32:LIBS += -lzlib -llzo2
|
||||
QMAKE_CXXFLAGS += -std=c++11
|
||||
}
|
||||
|
||||
ATHENA_CORE=true
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/Athena/Utility.cpp \
|
||||
$$PWD/src/Athena/FileReader.cpp \
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
!contains($$INCLUDEPATH, $$PWD/include): {
|
||||
include(AthenaCore.pri)
|
||||
!contains(ATHENA_CORE, true): {
|
||||
message("including core")
|
||||
include(AthenaCore.pri)
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
!contains($$INCLUDEPATH, $$PWD/include): {
|
||||
include(AthenaCore.pri)
|
||||
!contains(ATHENA_CORE, true): {
|
||||
message("including core")
|
||||
include(AthenaCore.pri)
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
|
@ -9,9 +10,6 @@ SOURCES += \
|
|||
$$PWD/src/Athena/WiiSave.cpp \
|
||||
$$PWD/src/Athena/WiiSaveReader.cpp \
|
||||
$$PWD/src/Athena/WiiSaveWriter.cpp \
|
||||
$$PWD/src/Athena/ZQuestFile.cpp \
|
||||
$$PWD/src/Athena/ZQuestFileReader.cpp \
|
||||
$$PWD/src/Athena/ZQuestFileWriter.cpp \
|
||||
$$PWD/src/bn.cpp \
|
||||
$$PWD/src/ec.cpp \
|
||||
$$PWD/src/md5.cpp \
|
||||
|
@ -19,27 +17,6 @@ SOURCES += \
|
|||
$$PWD/src/aes.c
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/include/Athena/ALTTPEnums.hpp \
|
||||
$$PWD/include/Athena/ALTTPFile.hpp \
|
||||
$$PWD/include/Athena/ALTTPFileReader.hpp \
|
||||
$$PWD/include/Athena/ALTTPFileWriter.hpp \
|
||||
$$PWD/include/Athena/ALTTPQuest.hpp \
|
||||
$$PWD/include/Athena/ALTTPStructs.hpp \
|
||||
$$PWD/include/Athena/Checksums.hpp \
|
||||
$$PWD/include/Athena/Compression.hpp \
|
||||
$$PWD/include/Athena/MCFile.hpp \
|
||||
$$PWD/include/Athena/MCFileReader.hpp \
|
||||
$$PWD/include/Athena/MCFileWriter.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordFile.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordFileReader.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordFileWriter.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordQuest.hpp \
|
||||
$$PWD/include/Athena/Sprite.hpp \
|
||||
$$PWD/include/Athena/SpriteFile.hpp \
|
||||
$$PWD/include/Athena/SpriteFileReader.hpp \
|
||||
$$PWD/include/Athena/SpriteFileWriter.hpp \
|
||||
$$PWD/include/Athena/SpriteFrame.hpp \
|
||||
$$PWD/include/Athena/SpritePart.hpp \
|
||||
$$PWD/include/Athena/WiiBanner.hpp \
|
||||
$$PWD/include/Athena/WiiFile.hpp \
|
||||
$$PWD/include/Athena/WiiImage.hpp \
|
||||
|
@ -49,6 +26,5 @@ HEADERS += \
|
|||
$$PWD/include/aes.h \
|
||||
$$PWD/include/bn.h \
|
||||
$$PWD/include/ec.h \
|
||||
$$PWD/include/lzo.h \
|
||||
$$PWD/include/md5.h \
|
||||
$$PWD/include/sha1.h
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
!contains($$INCLUDEPATH, $$PWD/include): {
|
||||
include(AthenaCore.pri)
|
||||
!contains(ATHENA_CORE, true): {
|
||||
message("including core")
|
||||
include(AthenaCore.pri)
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
|
@ -32,13 +33,4 @@ HEADERS += \
|
|||
$$PWD/include/Athena/SkywardSwordFile.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordFileReader.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordFileWriter.hpp \
|
||||
$$PWD/include/Athena/SkywardSwordQuest.hpp \
|
||||
$$PWD/include/Athena/Sprite.hpp \
|
||||
$$PWD/include/Athena/SpriteFile.hpp \
|
||||
$$PWD/include/Athena/SpriteFileReader.hpp \
|
||||
$$PWD/include/Athena/SpriteFileWriter.hpp \
|
||||
$$PWD/include/Athena/SpriteFrame.hpp \
|
||||
$$PWD/include/Athena/SpritePart.hpp \
|
||||
$$PWD/include/Athena/ZQuestFile.hpp \
|
||||
$$PWD/include/Athena/ZQuestFileReader.hpp \
|
||||
$$PWD/include/Athena/ZQuestFileWriter.hpp
|
||||
$$PWD/include/Athena/SkywardSwordQuest.hpp
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace io
|
|||
*/
|
||||
class ALTTPFileWriter : protected BinaryWriter
|
||||
{
|
||||
BINARYWRITER_BASE
|
||||
BINARYWRITER_BASE();
|
||||
|
||||
public:
|
||||
/*! \brief This constructor takes an existing buffer to write to.
|
||||
|
|
|
@ -167,13 +167,13 @@ public:
|
|||
*
|
||||
* \return Uint8* The buffer at the current position from the given length.
|
||||
*/
|
||||
atInt8* readBytes(atInt64 length);
|
||||
atInt8* readBytes(atUint64 length);
|
||||
|
||||
/*! \brief Reads a byte at the current position and advances the current position.
|
||||
*
|
||||
* \return Int8* The buffer at the current position from the given length.
|
||||
*/
|
||||
atUint8* readUBytes(atInt64 length);
|
||||
atUint8* readUBytes(atUint64 length);
|
||||
|
||||
/*! \brief Reads a Int16 and swaps to proper endianness depending on platform
|
||||
* and Stream settings, and advances the current position
|
||||
|
|
|
@ -292,8 +292,8 @@ private:
|
|||
}
|
||||
|
||||
#ifndef BINARYWRITER_BASE
|
||||
#define BINARYWRITER_BASE \
|
||||
#define BINARYWRITER_BASE() \
|
||||
private: \
|
||||
typedef Athena::io::BinaryWriter base;
|
||||
typedef Athena::io::BinaryWriter base
|
||||
#endif // BINARYWRITER_BASE
|
||||
#endif // __BINARY_WRITER_HPP__
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace io
|
|||
*/
|
||||
class MCFileWriter : protected BinaryWriter
|
||||
{
|
||||
BINARYWRITER_BASE
|
||||
BINARYWRITER_BASE();
|
||||
public:
|
||||
/*!
|
||||
* \brief This constructor takes an existing buffer to write to.
|
||||
|
|
|
@ -28,8 +28,7 @@ namespace io
|
|||
|
||||
class SkywardSwordFileWriter : public BinaryWriter
|
||||
{
|
||||
// Why does this fuck up my formatting in Qt Creator?
|
||||
BINARYWRITER_BASE
|
||||
BINARYWRITER_BASE();
|
||||
public:
|
||||
SkywardSwordFileWriter(atUint8* data, atUint64 len);
|
||||
SkywardSwordFileWriter(const std::string& filename);
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace io
|
|||
|
||||
class SpriteFileWriter : public BinaryWriter
|
||||
{
|
||||
BINARYWRITER_BASE;
|
||||
BINARYWRITER_BASE();
|
||||
public:
|
||||
SpriteFileWriter(atUint8* data, atUint64 length);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace io
|
|||
*/
|
||||
class WiiSaveWriter : protected BinaryWriter
|
||||
{
|
||||
BINARYWRITER_BASE
|
||||
BINARYWRITER_BASE();
|
||||
public:
|
||||
/*! \brief This constructor creates an instance from a file on disk.
|
||||
*
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace io
|
|||
*/
|
||||
class ZQuestFileWriter : protected BinaryWriter
|
||||
{
|
||||
BINARYWRITER_BASE
|
||||
BINARYWRITER_BASE();
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* LZO 1x decompression
|
||||
* copyright (c) 2006 Reimar Doeffinger
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef LZO_H
|
||||
#define LZO_H
|
||||
|
||||
#include "Athena/Types.hpp"
|
||||
|
||||
#define LZO_INPUT_DEPLETED 1
|
||||
#define LZO_OUTPUT_FULL 2
|
||||
#define LZO_INVALID_BACKPTR 4
|
||||
#define LZO_ERROR 8
|
||||
|
||||
#define LZO_INPUT_PADDING 4
|
||||
#define LZO_OUTPUT_PADDING 12
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -224,12 +224,12 @@ atUint8 BinaryReader::readUByte()
|
|||
return *(atUint8*)(m_data + m_position++);
|
||||
}
|
||||
|
||||
atInt8* BinaryReader::readBytes(atInt64 length)
|
||||
atInt8* BinaryReader::readBytes(atUint64 length)
|
||||
{
|
||||
return (atInt8*)readUBytes(length);
|
||||
}
|
||||
|
||||
atUint8* BinaryReader::readUBytes(atInt64 length)
|
||||
atUint8* BinaryReader::readUBytes(atUint64 length)
|
||||
{
|
||||
if (!m_data)
|
||||
loadData();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "Athena/Compression.hpp"
|
||||
#include "Athena/Exception.hpp"
|
||||
#include "lzo.h"
|
||||
#include <lzo/lzo1x.h>
|
||||
#include <iostream>
|
||||
#include <zlib.h>
|
||||
#include "LZ77/LZType10.hpp"
|
||||
|
@ -105,11 +105,13 @@ atInt32 compressZlib(const atUint8 *src, atUint32 srcLen, atUint8* dst, atUint32
|
|||
return ret;
|
||||
}
|
||||
|
||||
atInt32 decompressLZO(const atUint8* source, atInt32 sourceSize, atUint8* dst, atInt32& dstSize)
|
||||
atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8* dst, atInt32& dstSize)
|
||||
{
|
||||
int srcSize = sourceSize;
|
||||
int size = dstSize;
|
||||
int result = lzo1x_decode(dst, &size, (atUint8*)source, &sourceSize);
|
||||
dstSize = size;
|
||||
int result = lzo1x_decompress(source, srcSize, dst, (lzo_uintp)&size, NULL);
|
||||
dstSize -= size;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -354,8 +356,6 @@ atUint32 compressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst, bool e
|
|||
return retLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // Compression
|
||||
} // io
|
||||
} // zelda
|
||||
|
|
231
src/lzo.c
231
src/lzo.c
|
@ -1,231 +0,0 @@
|
|||
/*
|
||||
* LZO 1x decompression
|
||||
* Copyright (c) 2006 Reimar Doeffinger
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//! avoid e.g. MPlayers fast_memcpy, it slows things down here
|
||||
|
||||
#undef memcpy
|
||||
#include <string.h>
|
||||
#include "lzo.h"
|
||||
|
||||
//! define if we may write up to 12 bytes beyond the output buffer
|
||||
//#define OUTBUF_PADDED 1
|
||||
//! define if we may read up to 4 bytes beyond the input buffer
|
||||
//#define INBUF_PADDED 1
|
||||
typedef struct LZOContext {
|
||||
atUint8 *in, *in_end;
|
||||
atUint8 *out_start, *out, *out_end;
|
||||
int error;
|
||||
} LZOContext;
|
||||
|
||||
/**
|
||||
* \brief read one byte from input buffer, avoiding overrun
|
||||
* \return byte read
|
||||
*/
|
||||
static int get_byte(LZOContext *c) {
|
||||
if (c->in < c->in_end)
|
||||
return *c->in++;
|
||||
c->error |= LZO_INPUT_DEPLETED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief decode a length value in the coding used by lzo
|
||||
* \param x previous byte value
|
||||
* \param mask bits used from x
|
||||
* \return decoded length value
|
||||
*/
|
||||
static int get_len(LZOContext *c, int x, int mask) {
|
||||
int cnt = x & mask;
|
||||
if (!cnt) {
|
||||
while (!(x = get_byte(c))) cnt += 255;
|
||||
cnt += mask + x;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief copy bytes from input to output buffer with checking
|
||||
* \param cnt number of bytes to copy, must be > 0
|
||||
*/
|
||||
static void copy(LZOContext *c, int cnt) {
|
||||
register uint8_t *src = c->in;
|
||||
register uint8_t *dst = c->out;
|
||||
if (src + cnt > c->in_end) {
|
||||
cnt = (int)(c->in_end - src);
|
||||
c->error |= LZO_INPUT_DEPLETED;
|
||||
}
|
||||
if (dst + cnt > c->out_end) {
|
||||
cnt = (int)(c->out_end - dst);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
}
|
||||
|
||||
if (cnt <= 0) {
|
||||
c->error |= LZO_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
if (cnt > 0)
|
||||
#endif
|
||||
memcpy(dst, src, cnt);
|
||||
c->in = src + cnt;
|
||||
c->out = dst + cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief copy previously decoded bytes to current position
|
||||
* \param back how many bytes back we start
|
||||
* \param cnt number of bytes to copy, must be > 0
|
||||
*
|
||||
* cnt > back is valid, this will copy the bytes we just copied,
|
||||
* thus creating a repeating pattern with a period length of back.
|
||||
*/
|
||||
static void copy_backptr(LZOContext *c, int back, int cnt) {
|
||||
register uint8_t *src = &c->out[-back];
|
||||
register uint8_t *dst = c->out;
|
||||
if (src < c->out_start) {
|
||||
c->error |= LZO_INVALID_BACKPTR;
|
||||
return;
|
||||
}
|
||||
if (dst + cnt > c->out_end) {
|
||||
cnt = (int)(c->out_end - dst);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
}
|
||||
if (back == 1) {
|
||||
memset(dst, *src, cnt);
|
||||
dst += cnt;
|
||||
} else {
|
||||
#ifdef OUTBUF_PADDED
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
if (cnt > 0) {
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
dst[4] = src[4];
|
||||
dst[5] = src[5];
|
||||
dst[6] = src[6];
|
||||
dst[7] = src[7];
|
||||
src += 8;
|
||||
dst += 8;
|
||||
cnt -= 8;
|
||||
}
|
||||
#endif
|
||||
if (cnt > 0) {
|
||||
int blocklen = back;
|
||||
while (cnt > blocklen) {
|
||||
memcpy(dst, src, blocklen);
|
||||
dst += blocklen;
|
||||
cnt -= blocklen;
|
||||
blocklen <<= 1;
|
||||
}
|
||||
memcpy(dst, src, cnt);
|
||||
}
|
||||
dst += cnt;
|
||||
}
|
||||
c->out = dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief decode LZO 1x compressed data
|
||||
* \param out output buffer
|
||||
* \param outlen size of output buffer, number of bytes left are returned here
|
||||
* \param in input buffer
|
||||
* \param inlen size of input buffer, number of bytes left are returned here
|
||||
* \return 0 on success, otherwise error flags, see lzo.h
|
||||
*
|
||||
* make sure all buffers are appropriately padded, in must provide
|
||||
* LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
|
||||
*/
|
||||
int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen) {
|
||||
enum {COPY, BACKPTR} state = COPY;
|
||||
atInt32 x;
|
||||
LZOContext c;
|
||||
c.in = in;
|
||||
c.in_end = in + *inlen;
|
||||
c.out = c.out_start = out;
|
||||
c.out_end = out + * outlen;
|
||||
c.error = 0;
|
||||
x = get_byte(&c);
|
||||
if (x > 17) {
|
||||
copy(&c, x - 17);
|
||||
x = get_byte(&c);
|
||||
if (x < 16) c.error |= LZO_ERROR;
|
||||
}
|
||||
while (!c.error) {
|
||||
int cnt, back;
|
||||
if (x >> 4) {
|
||||
if (x >> 6) {
|
||||
cnt = (x >> 5) - 1;
|
||||
back = (get_byte(&c) << 3) + ((x >> 2) & 7) + 1;
|
||||
} else if (x >> 5) {
|
||||
cnt = get_len(&c, x, 31);
|
||||
x = get_byte(&c);
|
||||
back = (get_byte(&c) << 6) + (x >> 2) + 1;
|
||||
} else {
|
||||
cnt = get_len(&c, x, 7);
|
||||
back = (1 << 14) + ((x & 8) << 11);
|
||||
x = get_byte(&c);
|
||||
back += (get_byte(&c) << 6) + (x >> 2);
|
||||
if (back == (1 << 14)) {
|
||||
if (cnt != 1)
|
||||
c.error |= LZO_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else
|
||||
switch (state) {
|
||||
case COPY:
|
||||
cnt = get_len(&c, x, 15);
|
||||
copy(&c, cnt + 3);
|
||||
x = get_byte(&c);
|
||||
if (x >> 4)
|
||||
continue;
|
||||
cnt = 1;
|
||||
back = (1 << 11) + (get_byte(&c) << 2) + (x >> 2) + 1;
|
||||
break;
|
||||
case BACKPTR:
|
||||
cnt = 0;
|
||||
back = (get_byte(&c) << 2) + (x >> 2) + 1;
|
||||
break;
|
||||
}
|
||||
copy_backptr(&c, back, cnt + 2);
|
||||
cnt = x & 3;
|
||||
state = cnt ? BACKPTR : COPY;
|
||||
if (cnt)
|
||||
copy(&c, cnt);
|
||||
x = get_byte(&c);
|
||||
}
|
||||
*inlen = (atInt32)(c.in_end - c.in);
|
||||
*outlen = (atInt32)(c.out_end - c.out);
|
||||
return c.error;
|
||||
}
|
Loading…
Reference in New Issue