This commit is contained in:
Jack Andersen 2017-01-03 19:24:49 -10:00
commit 1ae2b844de
47 changed files with 943 additions and 1087 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "easy-ecc"]
path = extern/easy-ecc
url = https://github.com/libAthena/easy-ecc.git

View File

@ -14,7 +14,7 @@ if(NOT TARGET AthenaCore AND NOT Athena_BINARY_DIR)
endif() endif()
# These are IMPORTED targets created by AthenaTargets.cmake # These are IMPORTED targets created by AthenaTargets.cmake
set(ATHENA_LIBRARIES AthenaCore AthenaSakura AthenaZelda AthenaWiiSave) set(ATHENA_LIBRARIES athena-core athena-wiisave athena-sakura athena-zelda)
# Set icon location if on windows # Set icon location if on windows
if(WIN32 AND NOT CYGWIN) if(WIN32 AND NOT CYGWIN)

View File

@ -19,7 +19,7 @@ set(ATHENA_VERSION
add_subdirectory(extern) add_subdirectory(extern)
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${EASYECC_INCLUDE_DIR}) include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
if (NOT MSVC) if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
@ -103,8 +103,8 @@ add_library(athena-wiisave EXCLUDE_FROM_ALL
src/athena/WiiSave.cpp src/athena/WiiSave.cpp
src/athena/WiiSaveReader.cpp src/athena/WiiSaveReader.cpp
src/athena/WiiSaveWriter.cpp src/athena/WiiSaveWriter.cpp
# src/bn.cpp src/bn.cpp
# src/ec.cpp src/ec.cpp
src/md5.cpp src/md5.cpp
src/sha1.cpp src/sha1.cpp
src/aes.cpp src/aes.cpp
@ -116,8 +116,8 @@ add_library(athena-wiisave EXCLUDE_FROM_ALL
include/athena/WiiSaveReader.hpp include/athena/WiiSaveReader.hpp
include/athena/WiiSaveWriter.hpp include/athena/WiiSaveWriter.hpp
include/aes.hpp include/aes.hpp
# include/bn.h include/bn.hpp
# include/ec.h include/ec.hpp
include/md5.h include/md5.h
include/sha1.h include/sha1.h
) )
@ -156,6 +156,9 @@ add_library(athena-zelda EXCLUDE_FROM_ALL
include/athena/SkywardSwordFileReader.hpp include/athena/SkywardSwordFileReader.hpp
include/athena/SkywardSwordFileWriter.hpp include/athena/SkywardSwordFileWriter.hpp
include/athena/SkywardSwordQuest.hpp include/athena/SkywardSwordQuest.hpp
include/athena/ZQuestFile.hpp
include/athena/ZQuestFileReader.hpp
include/athena/ZQuestFileWriter.hpp
) )
# Icon # Icon

View File

@ -1,4 +1,3 @@
add_subdirectory(lzo) add_subdirectory(lzo)
add_subdirectory(zlib) add_subdirectory(zlib)
add_subdirectory(yaml) add_subdirectory(yaml)
add_subdirectory(easy-ecc)

1
extern/easy-ecc vendored

@ -1 +0,0 @@
Subproject commit da2748507cbe429d3e1be918c54cfba3be06d4b2

View File

@ -21,8 +21,6 @@ namespace io
*/ */
class ALTTPFileReader : protected MemoryCopyReader class ALTTPFileReader : protected MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to read from. /*! \brief This constructor takes an existing buffer to read from.
* *

View File

@ -20,8 +20,6 @@ namespace io
*/ */
class ALTTPFileWriter : protected MemoryCopyWriter class ALTTPFileWriter : protected MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to write to. /*! \brief This constructor takes an existing buffer to write to.
* *

View File

@ -29,7 +29,7 @@
#define PRISize "zu" #define PRISize "zu"
#endif #endif
// clang-format off
#ifndef AT_PRETTY_FUNCTION #ifndef AT_PRETTY_FUNCTION
# if defined(__PRETTY_FUNCTION__) || defined(__GNUC__) # if defined(__PRETTY_FUNCTION__) || defined(__GNUC__)
# define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__ # define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__
@ -45,7 +45,7 @@
# define AT_PRETTY_FUNCTION "<unknown>" # define AT_PRETTY_FUNCTION "<unknown>"
# endif # endif
#endif #endif
// clang-format on
#ifdef GEKKO #ifdef GEKKO
#include "gekko_support.h" #include "gekko_support.h"
@ -133,7 +133,8 @@ enum Endian
}; };
} // Athena } // Athena
typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line, const char* fmt, ...); typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line,
const char* fmt, ...);
atEXCEPTION_HANDLER atGetExceptionHandler(); atEXCEPTION_HANDLER atGetExceptionHandler();
/** /**
@ -148,7 +149,9 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef NDEBUG #ifndef NDEBUG
#define atDebug(fmt, ...) \ #define atDebug(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
@ -157,25 +160,33 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#endif #endif
#define atMessage(fmt, ...) \ #define atMessage(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define atWarning(fmt, ...) \ #define atWarning(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define atError(fmt, ...) \ #define atError(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define atFatal(fmt, ...) \ #define atFatal(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
@ -183,7 +194,9 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#ifndef NDEBUG #ifndef NDEBUG
#define atDebug(fmt...) \ #define atDebug(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0) } while (0)
@ -192,25 +205,33 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#endif // NDEBUG #endif // NDEBUG
#define atMessage(fmt...) \ #define atMessage(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0) } while (0)
#define atWarning(fmt...) \ #define atWarning(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0) } while (0)
#define atError(fmt...) \ #define atError(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0) } while (0)
#define atFatal(fmt...) \ #define atFatal(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \ if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0) } while (0)

View File

@ -20,7 +20,6 @@ namespace io
*/ */
class MCFileReader : public MemoryCopyReader class MCFileReader : public MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
/*! /*!
* \brief This constructor takes an existing buffer to read from. * \brief This constructor takes an existing buffer to read from.

View File

@ -21,7 +21,6 @@ namespace io
*/ */
class MCFileWriter : protected MemoryCopyWriter class MCFileWriter : protected MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
/*! /*!
* \brief This constructor takes an existing buffer to write to. * \brief This constructor takes an existing buffer to write to.

View File

@ -121,18 +121,5 @@ protected:
} // io } // io
} // Athena } // Athena
#ifndef MEMORYREADER_BASE
#define MEMORYREADER_BASE() \
private: \
typedef athena::io::MemoryReader base
#endif // MEMORYREADER_BASE
#ifndef MEMORYCOPYREADER_BASE
#define MEMORYCOPYREADER_BASE() \
private: \
typedef athena::io::MemoryCopyReader base
#endif // MEMORYCOPYREADER_BASE
#endif // MEMORYREADER_HPP #endif // MEMORYREADER_HPP

View File

@ -161,16 +161,4 @@ private:
} }
} }
#ifndef MEMORYWRITER_BASE
#define MEMORYWRITER_BASE() \
private: \
typedef athena::io::MemoryWriter base
#endif // BINARYWRITER_BASE
#ifndef MEMORYCOPYWRITER_BASE
#define MEMORYCOPYWRITER_BASE() \
private: \
typedef athena::io::MemoryCopyWriter base
#endif // BINARYWRITER_BASE
#endif // MEMORYWRITER_HPP #endif // MEMORYWRITER_HPP

View File

@ -10,9 +10,7 @@ namespace io
{ {
class SkywardSwordFileReader : public MemoryCopyReader class SkywardSwordFileReader : public MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
SkywardSwordFileReader(atUint8* data, atUint64 length); SkywardSwordFileReader(atUint8* data, atUint64 length);
SkywardSwordFileReader(const std::string& filename); SkywardSwordFileReader(const std::string& filename);

View File

@ -12,7 +12,6 @@ namespace io
class SkywardSwordFileWriter : public MemoryCopyWriter class SkywardSwordFileWriter : public MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
SkywardSwordFileWriter(atUint8* data, atUint64 len); SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(const std::string& filename); SkywardSwordFileWriter(const std::string& filename);

View File

@ -43,17 +43,16 @@ public:
void setSkipData(std::unique_ptr<atUint8[]>&& data); void setSkipData(std::unique_ptr<atUint8[]>&& data);
atUint8* skipData() const; atUint8* skipData() const;
atUint32 slotChecksum(); atUint32 slotChecksum();
atUint32 skipChecksum(); atUint32 skipChecksum();
void fixChecksums(); void fixChecksums();
void setNew(bool isNew); void setNew(bool isNew);
bool isNew() const; bool isNew() const;
private: private:
std::unique_ptr<atUint8[]> m_skipData; std::unique_ptr<atUint8[]> m_skipData;
}; };
} // Athena } // Athena
#endif // SSQUEST_HPP #endif // SSQUEST_HPP

View File

@ -1,15 +1,8 @@
#ifndef SSPRITE_HPP #ifndef SSPRITE_HPP
#define SSPRITE_HPP #define SSPRITE_HPP
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#include <string> #include <string>
#else
#include <QObject>
#include <QPoint>
#include <QString>
#include <QList>
#endif
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
namespace athena namespace athena
@ -19,35 +12,18 @@ namespace Sakura
class SpriteFile; class SpriteFile;
class SpriteFrame; class SpriteFrame;
#ifndef ATHENA_USE_QT
class Sprite class Sprite
{ {
#else
class Sprite : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(qreal currentState READ currentState WRITE setCurrentState)
Q_PROPERTY(qreal stateCount READ stateCount CONSTANT)
#endif
public: public:
Sprite(SpriteFile* root); Sprite(SpriteFile* root);
Sprite(SpriteFile* root, const std::string& name); Sprite(SpriteFile* root, const std::string& name);
virtual ~Sprite(); virtual ~Sprite();
virtual void setPosition(const float x, const float y); virtual void setPosition(const float x, const float y);
#ifndef ATHENA_USE_QT
virtual void setPosition(const Vector2Df& pos); virtual void setPosition(const Vector2Df& pos);
virtual Vector2Df position() const; virtual Vector2Df position() const;
void setName(const std::string& name); void setName(const std::string& name);
std::string name() const; std::string name() const;
#else
virtual void setPosition(const QPoint& pos);
virtual QPoint position() const;
void setName(const QString& name);
QString name() const;
#endif
void addStateId(int id); void addStateId(int id);
@ -58,11 +34,7 @@ public:
*/ */
int stateId(int index) const; int stateId(int index) const;
void setStateIds(std::vector<int> ids); void setStateIds(std::vector<int> ids);
#ifndef ATHENA_USE_QT
std::vector<int> stateIds() const; std::vector<int> stateIds() const;
#else
QList<int> stateIds() const;
#endif
atUint32 stateCount() const; atUint32 stateCount() const;
void setCurrentState(atUint32 id); void setCurrentState(atUint32 id);
atUint32 currentState() const; atUint32 currentState() const;
@ -71,18 +43,10 @@ public:
bool removeFrame(SpriteFrame* Frame); bool removeFrame(SpriteFrame* Frame);
SpriteFrame* Frame(atUint32 id); SpriteFrame* Frame(atUint32 id);
void setFrame(atUint32 id); void setFrame(atUint32 id);
#ifndef ATHENA_USE_QT
void setFrames(std::vector<SpriteFrame*> frames); void setFrames(std::vector<SpriteFrame*> frames);
#else
void setFrames(QList<SpriteFrame*> frames);
#endif
atUint32 frameCount() const; atUint32 frameCount() const;
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*> frames() const; std::vector<SpriteFrame*> frames() const;
#else
QList<SpriteFrame*> frames() const;
#endif
SpriteFile* container() const; SpriteFile* container() const;
@ -95,36 +59,17 @@ public:
void setRoot(SpriteFile* root); void setRoot(SpriteFile* root);
SpriteFile* root() const; SpriteFile* root() const;
#ifdef ATHENA_USE_QT
signals:
void frameChanged(SpriteFrame* frame);
void nameChanged(QString);
void stateChanged(quint32);
#endif
private: private:
SpriteFile* m_root; SpriteFile* m_root;
#ifndef ATHENA_USE_QT
std::string m_name; std::string m_name;
Vector2Df m_position; Vector2Df m_position;
std::vector<int> m_stateIds; //!< Stores the texture id's for each state. std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<SpriteFrame*> m_frames; std::vector<SpriteFrame*> m_frames;
#else
QString m_name;
QPoint m_position;
QList<int> m_stateIds;
QList<SpriteFrame*> m_frames;
#endif
atUint32 m_currentState; atUint32 m_currentState;
atUint32 m_currentFrame; atUint32 m_currentFrame;
}; };
} // Sakura } // Sakura
} // zelda } // zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(Uint32)
Q_DECLARE_METATYPE(athena::Sakura::Sprite*)
#endif
#endif // SSPRITE_HPP #endif // SSPRITE_HPP

View File

@ -1,16 +1,8 @@
#ifndef SSPRITEFILE_HPP #ifndef SSPRITEFILE_HPP
#define SSPRITEFILE_HPP #define SSPRITEFILE_HPP
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
#else
#include <QObject>
#include <QMap>
#include <QList>
#include <QSize>
#include <QPoint>
#endif
#include <string> #include <string>
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
@ -26,14 +18,8 @@ struct STexture
}; };
class Sprite; class Sprite;
#ifndef ATHENA_USE_QT
class SpriteFile class SpriteFile
{ {
#else
class SpriteFile : public QObject
{
Q_OBJECT
#endif
public: public:
/*! /*!
* \brief Major * \brief Major
@ -109,21 +95,13 @@ public slots:
* \brief setSize * \brief setSize
* \param size * \param size
*/ */
#ifndef ATHENA_USE_QT
void setSize(const Vector2Di& size); void setSize(const Vector2Di& size);
#else
void setSize(const QSize& size);
#endif
/*! /*!
* \brief size * \brief size
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Di size() const; Vector2Di size() const;
#else
QSize size() const;
#endif
/*! /*!
* \brief width * \brief width
@ -148,21 +126,13 @@ public slots:
* \brief setOrigin * \brief setOrigin
* \param origin * \param origin
*/ */
#ifndef ATHENA_USE_QT
void setOrigin(const Vector2Df& origin); void setOrigin(const Vector2Df& origin);
#else
void setOrigin(const QPoint& origin);
#endif
/*! /*!
* \brief origin * \brief origin
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df origin() const; Vector2Df origin() const;
#else
QPoint origin() const;
#endif
/*! /*!
@ -195,71 +165,33 @@ public slots:
* \return * \return
*/ */
STexture* texture(atUint32 id); STexture* texture(atUint32 id);
#ifndef ATHENA_USE_QT
std::vector<STexture*> textures() const; std::vector<STexture*> textures() const;
#else
QList<STexture*> textures() const;
#endif
atUint32 textureCount() const; atUint32 textureCount() const;
/*! /*!
* \brief setTextures * \brief setTextures
* \param textures * \param textures
*/ */
#ifndef ATHENA_USE_QT
void setTextures(std::vector<STexture*> textures); void setTextures(std::vector<STexture*> textures);
#else
void setTextures(QList<STexture*> textures);
#endif
void addSprite(Sprite* sprite); void addSprite(Sprite* sprite);
#ifndef ATHENA_USE_QT
void removeSprite(const std::string& name); void removeSprite(const std::string& name);
#else
void removeSprite(const QString& name);
#endif
void removeSprite(Sprite* sprite); void removeSprite(Sprite* sprite);
#ifndef ATHENA_USE_QT
void setSprites(std::unordered_map<std::string, Sprite*> sprites); void setSprites(std::unordered_map<std::string, Sprite*> sprites);
#else
void setSprites(QMap<QString, Sprite*> sprites);
#endif
#ifndef ATHENA_USE_QT
Sprite* sprite(const std::string& name); Sprite* sprite(const std::string& name);
std::unordered_map<std::string, Sprite*> sprites() const; std::unordered_map<std::string, Sprite*> sprites() const;
#else
Sprite* sprite(const QString& name);
QMap<QString, Sprite*> sprites() const;
#endif
atUint32 spriteCount() const; atUint32 spriteCount() const;
#ifdef ATHENA_USE_QT
signals:
void originChanged(QPoint);
void sizeChanged(QSize);
#endif
private: private:
#ifndef ATHENA_USE_QT
std::vector<STexture*> m_textures; std::vector<STexture*> m_textures;
Vector2Di m_size; Vector2Di m_size;
Vector2Df m_origin; Vector2Df m_origin;
std::unordered_map<std::string, Sprite*> m_sprites; std::unordered_map<std::string, Sprite*> m_sprites;
#else
QList<STexture*> m_textures;
QSize m_size;
QPoint m_origin;
QMap<QString, Sprite*> m_sprites;
#endif
}; };
} // Sakura } // Sakura
} // Zelda } // Zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpriteFile*)
Q_DECLARE_METATYPE(athena::Sakura::STexture*)
#endif
#endif // SSPRITE_HPP #endif // SSPRITE_HPP

View File

@ -15,7 +15,6 @@ namespace io
class SpriteFileReader : public MemoryCopyReader class SpriteFileReader : public MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
SpriteFileReader(atUint8* data, atUint64 length); SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(const std::string& filepath); SpriteFileReader(const std::string& filepath);

View File

@ -15,7 +15,6 @@ namespace io
class SpriteFileWriter : public MemoryCopyWriter class SpriteFileWriter : public MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
SpriteFileWriter(atUint8* data, atUint64 length); SpriteFileWriter(atUint8* data, atUint64 length);

View File

@ -4,13 +4,7 @@
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#else
#include <QObject>
#include <QList>
#endif
namespace athena namespace athena
{ {
namespace Sakura namespace Sakura
@ -19,15 +13,8 @@ namespace Sakura
class Sprite; class Sprite;
class SpritePart; class SpritePart;
#ifndef ATHENA_USE_QT
class SpriteFrame class SpriteFrame
{ {
#else
class SpriteFrame : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal frameTime READ frameTime WRITE setFrameTime)
#endif
public: public:
/*! /*!
* \brief SSpriteFrame * \brief SSpriteFrame
@ -48,37 +35,20 @@ public:
*/ */
float frameTime() const; float frameTime() const;
#ifndef ATHENA_USE_QT
void setParts(std::vector<SpritePart*> parts); void setParts(std::vector<SpritePart*> parts);
std::vector<SpritePart*> parts() const; std::vector<SpritePart*> parts() const;
#else
void setParts(QList<SpritePart*> parts);
QList<SpritePart*> parts() const;
#endif
atUint32 partCount() const; atUint32 partCount() const;
void setRoot(Sprite* root); void setRoot(Sprite* root);
Sprite* root() const; Sprite* root() const;
#ifdef ATHENA_USE_QT
signals:
void frameTimeChanged(float);
#endif
private: private:
Sprite* m_root; Sprite* m_root;
float m_frameTime; float m_frameTime;
#ifndef ATHENA_USE_QT
std::vector<SpritePart*> m_parts; std::vector<SpritePart*> m_parts;
#else
QList<SpritePart*> m_parts;
#endif
}; };
} // Sakura } // Sakura
} // zelda } // zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpriteFrame*);
#endif
#endif // SSPRITEFRAME_HPP #endif // SSPRITEFRAME_HPP

View File

@ -2,14 +2,7 @@
#define SSPRITEPART_HPP #define SSPRITEPART_HPP
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#else
# include <QObject>
# include <QPoint>
# include <QSize>
# include <QString>
#endif
#include <string> #include <string>
@ -19,35 +12,15 @@ namespace Sakura
{ {
class SpriteFrame; class SpriteFrame;
#ifndef ATHENA_USE_QT
class SpritePart class SpritePart
{ {
#else
class SpritePart : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(bool hasCollision READ hasCollision WRITE setCollision)
Q_PROPERTY(bool flippedHorizontally READ flippedHorizontally WRITE setFlippedHorizontally)
Q_PROPERTY(bool flippedVertically READ flippedVertically WRITE setFlippedVertically)
Q_PROPERTY(QPoint offset READ offset WRITE setOffset)
Q_PROPERTY(QPoint textureOffset READ textureOffset WRITE setTextureOffset)
Q_PROPERTY(QSize size READ size WRITE setSize)
#endif
public: public:
SpritePart(SpriteFrame* root); SpritePart(SpriteFrame* root);
SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false); SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false);
virtual ~SpritePart(); virtual ~SpritePart();
#ifndef ATHENA_USE_QT
void setName(const std::string& name); void setName(const std::string& name);
std::string name() const; std::string name() const;
#else
void setName(const QString& name);
QString name() const;
#endif
void setCollision(bool col); void setCollision(bool col);
bool hasCollision() const; bool hasCollision() const;
@ -57,26 +30,13 @@ public:
* \param y * \param y
*/ */
void setOffset(float x, float y); void setOffset(float x, float y);
/*!
* \brief setOffset
* \param offset
*/
#ifndef ATHENA_USE_QT
void setOffset(const Vector2Df& offset); void setOffset(const Vector2Df& offset);
#else
void setOffset(const QPoint& offset);
#endif
/*! /*!
* \brief offset * \brief offset
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df offset() const; Vector2Df offset() const;
#else
QPoint offset() const;
#endif
/*! /*!
* \brief setTextureOffset * \brief setTextureOffset
@ -89,22 +49,13 @@ public:
* \brief setTextureOffset * \brief setTextureOffset
* \param texOff * \param texOff
*/ */
#ifndef ATHENA_USE_QT
void setTextureOffset(const Vector2Df& offset); void setTextureOffset(const Vector2Df& offset);
#else
void setTextureOffset(const QPoint& offset);
#endif
/*! /*!
* \brief textureOffset * \brief textureOffset
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df textureOffset() const; Vector2Df textureOffset() const;
#else
QPoint textureOffset() const;
#endif
/*! /*!
* \brief setSize * \brief setSize
* \param width * \param width
@ -116,21 +67,12 @@ public:
* \brief setSize * \brief setSize
* \param size * \param size
*/ */
#ifndef ATHENA_USE_QT
void setSize(const Vector2Di& size); void setSize(const Vector2Di& size);
#else
void setSize(const QSize& size);
#endif
/*! /*!
* \brief size * \brief size
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Di size() const; Vector2Di size() const;
#else
QSize size() const;
#endif
/*! /*!
* \brief setFlippedHorizontally * \brief setFlippedHorizontally
@ -159,42 +101,19 @@ public:
void setRoot(SpriteFrame* root); void setRoot(SpriteFrame* root);
SpriteFrame* root() const; SpriteFrame* root() const;
#ifdef ATHENA_USE_QT
signals:
void nameChanged(QString);
void orientationChanged(bool, bool);
void offsetChanged(QPoint);
void textureOffsetChanged(QPoint);
void sizeChanged(QSize);
void collisionChanged(bool);
#endif
private: private:
SpriteFrame* m_root; SpriteFrame* m_root;
#ifndef ATHENA_USE_QT
std::string m_name; std::string m_name;
#else
QString m_name;
#endif
bool m_hasCollision; bool m_hasCollision;
#ifndef ATHENA_USE_QT
Vector2Df m_offset; Vector2Df m_offset;
Vector2Df m_textureOffset; Vector2Df m_textureOffset;
Vector2Di m_size; Vector2Di m_size;
#else
QPoint m_offset;
QPoint m_textureOffset;
QSize m_size;
#endif
bool m_flippedH; bool m_flippedH;
bool m_flippedV; bool m_flippedV;
atUint32 m_frameIndex; atUint32 m_frameIndex;
}; };
} }
} }
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpritePart*)
#endif
#endif // SSPRITEPART_HPP #endif // SSPRITEPART_HPP

View File

@ -21,9 +21,8 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk. * all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class WiiSaveReader : protected MemoryCopyReader class WiiSaveReader : public MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to read from. /*! \brief This constructor takes an existing buffer to read from.
* *

View File

@ -22,7 +22,6 @@ namespace io
*/ */
class WiiSaveWriter : protected MemoryCopyWriter class WiiSaveWriter : protected MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
/*! \brief This constructor creates an instance from a file on disk. /*! \brief This constructor creates an instance from a file on disk.
* *

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST #ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef ZQUEST_HPP #ifndef ZQUEST_HPP
#define ZQUEST_HPP #define ZQUEST_HPP

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST #ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ZQUESTFILEREADER_HPP__ #ifndef __ZQUESTFILEREADER_HPP__
#define __ZQUESTFILEREADER_HPP__ #define __ZQUESTFILEREADER_HPP__
@ -31,7 +16,6 @@ namespace io
*/ */
class ZQuestFileReader : protected MemoryCopyReader class ZQuestFileReader : protected MemoryCopyReader
{ {
MEMORYCOPYREADER_BASE();
public: public:
/*! /*!

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST #ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ZQUESTFILEWRITER_HPP__ #ifndef __ZQUESTFILEWRITER_HPP__
#define __ZQUESTFILEWRITER_HPP__ #define __ZQUESTFILEWRITER_HPP__
@ -31,8 +16,6 @@ namespace io
*/ */
class ZQuestFileWriter : protected MemoryCopyWriter class ZQuestFileWriter : protected MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
/*! /*!
* \brief ZQuestFileWriter * \brief ZQuestFileWriter

15
include/bn.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef BN_H
#define BN_H
#include "athena/Types.hpp"
namespace bignum
{
int compare(const atUint8* a, const atUint8* b, atUint32 n);
void subModulus(atUint8* a, const atUint8* N, atUint32 n);
void add(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n);
void mul(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n);
void exp(atUint8* d, const atUint8* a, const atUint8* N, atUint32 n, atUint8* e, atUint32 en);
void inv(atUint8* d, atUint8* a, const atUint8* N, atUint32 n);
}
#endif // BN_H

13
include/ec.hpp Normal file
View File

@ -0,0 +1,13 @@
#ifndef EC_H
#define EC_H
#include "athena/Types.hpp"
namespace ecc
{
void checkEC(atUint8* ng, atUint8* ap, atUint8* sig, atUint8* sigHash, bool& apValid, bool& ngValid);
void makeECCert(atUint8* cert, atUint8* sig, const char* signer, const char* name, atUint8* priv, atUint32 keyId);
void createECDSA(atUint8* R, atUint8* S, atUint8* k, atUint8* hash);
}
#endif // EC_H

View File

@ -6,5 +6,5 @@ Name: libAthena
Description: Basic cross platform IO library Description: Basic cross platform IO library
Version: @ATHENA_VERSION@ Version: @ATHENA_VERSION@
Cflags: -I${includedir}/Athena -std=c++11 Cflags: -I${includedir}/Athena -std=c++11
Libs: -L${libdir} -lAthenaCore -lAthenaSakura -lAthenaZelda -lAthenaWiiSave Libs: -L${libdir} -lathena-core -lathena-sakura -lathena-zelda -lathena-wiiSave
Requires: zlib Requires: zlib

View File

@ -10,12 +10,12 @@ namespace io
{ {
ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length) ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
ALTTPFileReader::ALTTPFileReader(const std::string& filename) ALTTPFileReader::ALTTPFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }
@ -52,22 +52,22 @@ ALTTPFile* ALTTPFileReader::readFile()
quest->setOverworldEvents(owEvents); quest->setOverworldEvents(owEvents);
quest->setInventory(*(ALTTPInventory*)base::readBytes(sizeof(ALTTPInventory)).get()); quest->setInventory(*(ALTTPInventory*)readBytes(sizeof(ALTTPInventory)).get());
quest->setRupeeMax(base::readUint16()); quest->setRupeeMax(readUint16());
quest->setRupeeCurrent(base::readUint16()); quest->setRupeeCurrent(readUint16());
quest->setCompasses(readDungeonFlags()); quest->setCompasses(readDungeonFlags());
quest->setBigKeys(readDungeonFlags()); quest->setBigKeys(readDungeonFlags());
quest->setDungeonMaps(readDungeonFlags()); quest->setDungeonMaps(readDungeonFlags());
quest->setWishingPond(base::readUint16()); quest->setWishingPond(readUint16());
quest->setHealthMax(base::readByte()); quest->setHealthMax(readByte());
quest->setHealth(base::readByte()); quest->setHealth(readByte());
quest->setMagicPower(base::readByte()); quest->setMagicPower(readByte());
quest->setKeys(base::readByte()); quest->setKeys(readByte());
quest->setBombUpgrades(base::readByte()); quest->setBombUpgrades(readByte());
quest->setArrowUpgrades(base::readByte()); quest->setArrowUpgrades(readByte());
quest->setHealthFiller(base::readByte()); quest->setHealthFiller(readByte());
quest->setMagicFiller(base::readByte()); quest->setMagicFiller(readByte());
atUint8 pendantsByte = base::readUByte(); atUint8 pendantsByte = readUByte();
ALTTPPendants pendants; ALTTPPendants pendants;
pendants.Courage = pendantsByte & 1; pendants.Courage = pendantsByte & 1;
pendants.Wisdom = (pendantsByte >> 1) & 1; pendants.Wisdom = (pendantsByte >> 1) & 1;
@ -78,11 +78,11 @@ ALTTPFile* ALTTPFileReader::readFile()
pendants.Unused4 = false; pendants.Unused4 = false;
pendants.Unused5 = false; pendants.Unused5 = false;
quest->setPendants(pendants); quest->setPendants(pendants);
quest->setBombFiller(base::readByte()); quest->setBombFiller(readByte());
quest->setArrowFiller(base::readByte()); quest->setArrowFiller(readByte());
quest->setArrows(base::readByte()); quest->setArrows(readByte());
base::seek(1); seek(1);
atUint8 abilitiesByte = base::readUByte(); atUint8 abilitiesByte = readUByte();
ALTTPAbilities abilities; ALTTPAbilities abilities;
abilities.Nothing = abilitiesByte & 1; abilities.Nothing = abilitiesByte & 1;
abilities.Swim = (abilitiesByte >> 1) & 1; abilities.Swim = (abilitiesByte >> 1) & 1;
@ -93,42 +93,42 @@ ALTTPFile* ALTTPFileReader::readFile()
abilities.Read = (abilitiesByte >> 6) & 1; abilities.Read = (abilitiesByte >> 6) & 1;
abilities.Unknown2 = (abilitiesByte >> 7) & 1; abilities.Unknown2 = (abilitiesByte >> 7) & 1;
quest->setAbilityFlags(abilities); quest->setAbilityFlags(abilities);
quest->setCrystals(*(ALTTPCrystals*)base::readBytes(sizeof(ALTTPCrystals)).get()); quest->setCrystals(*(ALTTPCrystals*)readBytes(sizeof(ALTTPCrystals)).get());
quest->setMagicUsage(*(ALTTPMagicUsage*)base::readBytes(sizeof(ALTTPMagicUsage)).get()); quest->setMagicUsage(*(ALTTPMagicUsage*)readBytes(sizeof(ALTTPMagicUsage)).get());
j = 0x10; j = 0x10;
while ((j--) > 0) while ((j--) > 0)
{ {
dungeonKeys.push_back(base::readByte()); dungeonKeys.push_back(readByte());
} }
quest->setDungeonKeys(dungeonKeys); quest->setDungeonKeys(dungeonKeys);
base::seek(0x039); seek(0x039);
quest->setProgressIndicator((ALTTPProgressIndicator)base::readByte()); quest->setProgressIndicator((ALTTPProgressIndicator)readByte());
quest->setProgressFlags1(*(ALTTPProgressFlags1*)base::readBytes(sizeof(ALTTPProgressFlags1)).get()); quest->setProgressFlags1(*(ALTTPProgressFlags1*)readBytes(sizeof(ALTTPProgressFlags1)).get());
quest->setMapIcon((ALTTPMapIcon)base::readByte()); quest->setMapIcon((ALTTPMapIcon)readByte());
quest->setStartLocation((ALTTPStartLocation)base::readByte()); quest->setStartLocation((ALTTPStartLocation)readByte());
quest->setProgressFlags2(*(ALTTPProgressFlags2*)base::readBytes(sizeof(ALTTPProgressFlags2)).get()); quest->setProgressFlags2(*(ALTTPProgressFlags2*)readBytes(sizeof(ALTTPProgressFlags2)).get());
quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)base::readBytes(1).get()); quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)readBytes(1).get());
base::seek(1); seek(1);
quest->setTagAlong((ALTTPTagAlong)base::readByte()); quest->setTagAlong((ALTTPTagAlong)readByte());
j = 6; j = 6;
while ((j--) > 0) while ((j--) > 0)
{ {
oldmanFlags.push_back(base::readByte()); oldmanFlags.push_back(readByte());
} }
quest->setOldManFlags(oldmanFlags); quest->setOldManFlags(oldmanFlags);
quest->setBombFlag(base::readByte()); quest->setBombFlag(readByte());
j = 5; j = 5;
while ((j--) > 0) while ((j--) > 0)
{ {
unknown1.push_back(base::readByte()); unknown1.push_back(readByte());
} }
quest->setUnknown1(unknown1); quest->setUnknown1(unknown1);
@ -137,28 +137,28 @@ ALTTPFile* ALTTPFileReader::readFile()
while ((j--) > 0) while ((j--) > 0)
{ {
playerName.push_back(base::readUint16()); playerName.push_back(readUint16());
} }
quest->setPlayerName(playerName); quest->setPlayerName(playerName);
quest->setValid((base::readUint16() == 0x55AA)); quest->setValid((readUint16() == 0x55AA));
j = 0x0D; j = 0x0D;
while ((j--) > 0) while ((j--) > 0)
{ {
dungeonDeaths.push_back(base::readUint16()); dungeonDeaths.push_back(readUint16());
} }
quest->setDungeonDeathTotals(dungeonDeaths); quest->setDungeonDeathTotals(dungeonDeaths);
quest->setUnknown2(base::readUint16()); quest->setUnknown2(readUint16());
quest->setDeathSaveCount(base::readUint16()); quest->setDeathSaveCount(readUint16());
quest->setPostGameDeathCounter(base::readInt16()); quest->setPostGameDeathCounter(readInt16());
base::seek(0xF7); seek(0xF7);
quest->setChecksum(base::readUint16()); quest->setChecksum(readUint16());
if (i < 3) if (i < 3)
quests.push_back(quest); quests.push_back(quest);
@ -172,7 +172,7 @@ ALTTPFile* ALTTPFileReader::readFile()
ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
{ {
ALTTPRoomFlags* flags = new ALTTPRoomFlags; ALTTPRoomFlags* flags = new ALTTPRoomFlags;
atUint8 flagsByte = base::readUByte(); atUint8 flagsByte = readUByte();
flags->Chest1 = flagsByte & 1; flags->Chest1 = flagsByte & 1;
flags->Chest2 = (flagsByte >> 1) & 1; flags->Chest2 = (flagsByte >> 1) & 1;
flags->Chest3 = (flagsByte >> 2) & 1; flags->Chest3 = (flagsByte >> 2) & 1;
@ -181,7 +181,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
flags->Quadrant2 = (flagsByte >> 5) & 1; flags->Quadrant2 = (flagsByte >> 5) & 1;
flags->Quadrant3 = (flagsByte >> 6) & 1; flags->Quadrant3 = (flagsByte >> 6) & 1;
flags->Quadrant4 = (flagsByte >> 7) & 1; flags->Quadrant4 = (flagsByte >> 7) & 1;
flagsByte = base::readUByte(); flagsByte = readUByte();
flags->Door1 = flagsByte & 1; flags->Door1 = flagsByte & 1;
flags->Door2 = (flagsByte >> 1) & 1; flags->Door2 = (flagsByte >> 1) & 1;
flags->Door3 = (flagsByte >> 2) & 1; flags->Door3 = (flagsByte >> 2) & 1;
@ -197,7 +197,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent() ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent()
{ {
ALTTPOverworldEvent* event = new ALTTPOverworldEvent; ALTTPOverworldEvent* event = new ALTTPOverworldEvent;
atUint8 flagsByte = base::readUByte(); atUint8 flagsByte = readUByte();
event->Unused1 = flagsByte & 1; event->Unused1 = flagsByte & 1;
event->HeartPiece = (flagsByte >> 1) & 1; event->HeartPiece = (flagsByte >> 1) & 1;
event->Overlay = (flagsByte >> 2) & 1; event->Overlay = (flagsByte >> 2) & 1;
@ -212,7 +212,7 @@ ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent()
ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
{ {
ALTTPDungeonItemFlags flags; ALTTPDungeonItemFlags flags;
atUint8 flagsByte = base::readUByte(); atUint8 flagsByte = readUByte();
flags.Unused1 = flagsByte & 1; flags.Unused1 = flagsByte & 1;
flags.Unused2 = (flagsByte >> 1) & 1; flags.Unused2 = (flagsByte >> 1) & 1;
flags.GanonsTower = (flagsByte >> 2) & 1; flags.GanonsTower = (flagsByte >> 2) & 1;
@ -221,7 +221,7 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
flags.TowerOfHera = (flagsByte >> 5) & 1; flags.TowerOfHera = (flagsByte >> 5) & 1;
flags.IcePalace = (flagsByte >> 6) & 1; flags.IcePalace = (flagsByte >> 6) & 1;
flags.SkullWoods = (flagsByte >> 7) & 1; flags.SkullWoods = (flagsByte >> 7) & 1;
flagsByte = base::readUByte(); flagsByte = readUByte();
flags.MiseryMire = flagsByte & 1; flags.MiseryMire = flagsByte & 1;
flags.DarkPalace = (flagsByte >> 1) & 1; flags.DarkPalace = (flagsByte >> 1) & 1;
flags.SwampPalace = (flagsByte >> 2) & 1; flags.SwampPalace = (flagsByte >> 2) & 1;

View File

@ -10,12 +10,12 @@ namespace io
{ {
ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length) ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
ALTTPFileWriter::ALTTPFileWriter(const std::string& filename) ALTTPFileWriter::ALTTPFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }
@ -40,31 +40,31 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
writeOverworldEvent(quest->overworldEvent(j)); writeOverworldEvent(quest->overworldEvent(j));
} }
base::writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory)); writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory));
base::writeUint16(quest->rupeeMax()); writeUint16(quest->rupeeMax());
base::writeUint16(quest->rupeeCurrent()); writeUint16(quest->rupeeCurrent());
writeDungeonItems(quest->compasses()); writeDungeonItems(quest->compasses());
writeDungeonItems(quest->bigKeys()); writeDungeonItems(quest->bigKeys());
writeDungeonItems(quest->dungeonMaps()); writeDungeonItems(quest->dungeonMaps());
base::writeUint16(quest->wishingPond()); writeUint16(quest->wishingPond());
base::writeByte(quest->healthMax()); writeByte(quest->healthMax());
base::writeByte(quest->health()); writeByte(quest->health());
base::writeByte(quest->magicPower()); writeByte(quest->magicPower());
base::writeByte(quest->keys()); writeByte(quest->keys());
base::writeByte(quest->bombUpgrades()); writeByte(quest->bombUpgrades());
base::writeByte(quest->arrowUpgrades()); writeByte(quest->arrowUpgrades());
base::writeByte(quest->healthFiller()); writeByte(quest->healthFiller());
base::writeByte(quest->magicFiller()); writeByte(quest->magicFiller());
ALTTPPendants pendants = quest->pendants(); ALTTPPendants pendants = quest->pendants();
atUint8 pendantsByte = 0; atUint8 pendantsByte = 0;
pendantsByte |= pendants.Courage; pendantsByte |= pendants.Courage;
pendantsByte |= pendants.Wisdom << 1; pendantsByte |= pendants.Wisdom << 1;
pendantsByte |= pendants.Power << 2; pendantsByte |= pendants.Power << 2;
base::writeUByte(pendantsByte); writeUByte(pendantsByte);
base::writeByte(quest->bombFiller()); writeByte(quest->bombFiller());
base::writeByte(quest->arrowFiller()); writeByte(quest->arrowFiller());
base::writeByte(quest->arrows()); writeByte(quest->arrows());
base::seek(1); seek(1);
ALTTPAbilities abilities = quest->abilityFlags(); ALTTPAbilities abilities = quest->abilityFlags();
atUint8 abilitiesByte = 0; atUint8 abilitiesByte = 0;
abilitiesByte |= abilities.Nothing; abilitiesByte |= abilities.Nothing;
@ -75,51 +75,51 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
abilitiesByte |= abilities.Talk << 5; abilitiesByte |= abilities.Talk << 5;
abilitiesByte |= abilities.Read << 6; abilitiesByte |= abilities.Read << 6;
abilitiesByte |= abilities.Unknown2 << 7; abilitiesByte |= abilities.Unknown2 << 7;
base::writeUByte(abilitiesByte); writeUByte(abilitiesByte);
ALTTPCrystals crystals = quest->crystals(); ALTTPCrystals crystals = quest->crystals();
base::writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals)); writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals));
ALTTPMagicUsage magicUsage = quest->magicUsage(); ALTTPMagicUsage magicUsage = quest->magicUsage();
base::writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage)); writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage));
for (int j = 0; j < 0x010; j++) for (int j = 0; j < 0x010; j++)
base::writeByte(quest->dungeonKeys(j)); writeByte(quest->dungeonKeys(j));
base::seek(0x039); seek(0x039);
base::writeByte((atInt8)quest->progressIndicator()); writeByte((atInt8)quest->progressIndicator());
ALTTPProgressFlags1 progress1 = quest->progressFlags1(); ALTTPProgressFlags1 progress1 = quest->progressFlags1();
base::writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1)); writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1));
base::writeByte(quest->mapIcon()); writeByte(quest->mapIcon());
base::writeByte(quest->startLocation()); writeByte(quest->startLocation());
ALTTPProgressFlags2 progress2 = quest->progressFlags2(); ALTTPProgressFlags2 progress2 = quest->progressFlags2();
base::writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2)); writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2));
ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator(); ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator();
base::writeBytes((atInt8*)&indicator, 1); writeBytes((atInt8*)&indicator, 1);
base::seek(1); seek(1);
base::writeByte(quest->tagAlong()); writeByte(quest->tagAlong());
for (int j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
base::writeByte(quest->oldManFlag(j)); writeByte(quest->oldManFlag(j));
base::writeByte(quest->bombFlag()); writeByte(quest->bombFlag());
for (int j = 0; j < 5; j++) for (int j = 0; j < 5; j++)
base::writeByte(quest->unknown1(j)); writeByte(quest->unknown1(j));
for (int j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
base::writeUint16(quest->playerName()[j]); writeUint16(quest->playerName()[j]);
base::writeUint16((quest->valid() == true ? 0x55AA : 0)); writeUint16((quest->valid() == true ? 0x55AA : 0));
for (int j = 0; j < 0x0D; j++) for (int j = 0; j < 0x0D; j++)
base::writeUint16(quest->dungeonDeathTotal(j)); writeUint16(quest->dungeonDeathTotal(j));
base::writeUint16(quest->unknown2()); writeUint16(quest->unknown2());
base::writeUint16(quest->deathSaveCount()); writeUint16(quest->deathSaveCount());
base::writeUint16(quest->postGameDeathCounter()); writeUint16(quest->postGameDeathCounter());
base::seek(0xF7); seek(0xF7);
base::writeUint16(calculateChecksum(i)); writeUint16(calculateChecksum(i));
} }
} }
@ -134,7 +134,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags)
flagsByte |= flags->Quadrant2 << 5; flagsByte |= flags->Quadrant2 << 5;
flagsByte |= flags->Quadrant3 << 6; flagsByte |= flags->Quadrant3 << 6;
flagsByte |= flags->Quadrant4 << 7; flagsByte |= flags->Quadrant4 << 7;
base::writeUByte(flagsByte); writeUByte(flagsByte);
flagsByte = 0; flagsByte = 0;
flagsByte |= flags->Door1; flagsByte |= flags->Door1;
flagsByte |= flags->Door2 << 1; flagsByte |= flags->Door2 << 1;
@ -144,7 +144,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags)
flagsByte |= flags->Key << 5; flagsByte |= flags->Key << 5;
flagsByte |= flags->KeyOrChest << 6; flagsByte |= flags->KeyOrChest << 6;
flagsByte |= flags->ChestOrTile << 7; flagsByte |= flags->ChestOrTile << 7;
base::writeUByte(flagsByte); writeUByte(flagsByte);
} }
void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event) void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event)
@ -158,7 +158,7 @@ void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event)
flagsByte |= event->Unused4 << 5; flagsByte |= event->Unused4 << 5;
flagsByte |= event->Set << 6; flagsByte |= event->Set << 6;
flagsByte |= event->Unused5 << 7; flagsByte |= event->Unused5 << 7;
base::writeUByte(flagsByte); writeUByte(flagsByte);
} }
void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
@ -172,7 +172,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
flagsByte |= flags.IcePalace << 5; flagsByte |= flags.IcePalace << 5;
flagsByte |= flags.SkullWoods << 6; flagsByte |= flags.SkullWoods << 6;
flagsByte |= flags.MiseryMire << 7; flagsByte |= flags.MiseryMire << 7;
base::writeUByte(flagsByte); writeUByte(flagsByte);
flagsByte = 0; flagsByte = 0;
flagsByte |= flags.DarkPalace; flagsByte |= flags.DarkPalace;
flagsByte |= flags.SwampPalace << 1; flagsByte |= flags.SwampPalace << 1;
@ -181,7 +181,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
flagsByte |= flags.EasternPalace << 4; flagsByte |= flags.EasternPalace << 4;
flagsByte |= flags.HyruleCastle << 5; flagsByte |= flags.HyruleCastle << 5;
flagsByte |= flags.SewerPassage << 6; flagsByte |= flags.SewerPassage << 6;
base::writeUByte(flagsByte); writeUByte(flagsByte);
} }
atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game) atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game)

View File

@ -8,22 +8,22 @@ namespace io
static const atUint32 SCRAMBLE_VALUE = 0x5A424741; static const atUint32 SCRAMBLE_VALUE = 0x5A424741;
MCFileReader::MCFileReader(atUint8* data, atUint64 length) MCFileReader::MCFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
MCFileReader::MCFileReader(const std::string& filename) MCFileReader::MCFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }
MCFile* MCFileReader::readFile() MCFile* MCFileReader::readFile()
{ {
bool isScrambled = base::readUint32() != SCRAMBLE_VALUE; bool isScrambled = readUint32() != SCRAMBLE_VALUE;
base::m_position = 0; m_position = 0;
if (isScrambled) if (isScrambled)
MCFile::unscramble(base::m_dataCopy.get(), base::m_length); MCFile::unscramble(m_dataCopy.get(), m_length);
return nullptr; return nullptr;
} }

View File

@ -6,12 +6,12 @@ namespace io
{ {
MCFileWriter::MCFileWriter(atUint8* data, atUint64 length) MCFileWriter::MCFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
MCFileWriter::MCFileWriter(const std::string& filename) MCFileWriter::MCFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }

View File

@ -9,28 +9,28 @@ namespace io
{ {
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length) SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename) SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
SkywardSwordFile* SkywardSwordFileReader::read() SkywardSwordFile* SkywardSwordFileReader::read()
{ {
SkywardSwordFile* file = NULL; SkywardSwordFile* file = NULL;
if (base::length() != 0xFBE0) if (length() != 0xFBE0)
{ {
atError("File not the expected size of 0xFBE0"); atError("File not the expected size of 0xFBE0");
return nullptr; return nullptr;
} }
atUint32 magic = base::readUint32(); atUint32 magic = readUint32();
if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic) if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic)
{ {
@ -38,8 +38,8 @@ SkywardSwordFile* SkywardSwordFileReader::read()
return nullptr; return nullptr;
} }
base::seek(0x01C, SeekOrigin::Begin); seek(0x01C, SeekOrigin::Begin);
atUint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1) atUint32 headerSize = readUint32(); // Seems to be (headerSize - 1)
if (headerSize != 0x1D) if (headerSize != 0x1D)
{ {
@ -53,12 +53,12 @@ SkywardSwordFile* SkywardSwordFileReader::read()
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
SkywardSwordQuest* q = new SkywardSwordQuest(base::readUBytes(0x53C0), 0x53C0); SkywardSwordQuest* q = new SkywardSwordQuest(readUBytes(0x53C0), 0x53C0);
atUint64 pos = base::position(); atUint64 pos = position();
// seek to the skip data for this particular quest // seek to the skip data for this particular quest
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
q->setSkipData(base::readUBytes(0x24)); q->setSkipData(readUBytes(0x24));
base::seek(pos, SeekOrigin::Begin); seek(pos, SeekOrigin::Begin);
file->addQuest(q); file->addQuest(q);
} }

View File

@ -8,15 +8,15 @@ namespace io
{ {
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len) SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len)
: base(data, len) : MemoryCopyWriter(data, len)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename) SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
void SkywardSwordFileWriter::write(SkywardSwordFile* file) void SkywardSwordFileWriter::write(SkywardSwordFile* file)
@ -30,9 +30,9 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file)
atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic : atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic :
(file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic)); (file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic));
base::writeUint32(magic); writeUint32(magic);
base::seek(0x1C, SeekOrigin::Begin); seek(0x1C, SeekOrigin::Begin);
base::writeUint32(0x1D); writeUint32(0x1D);
std::vector<SkywardSwordQuest*> quests = file->questList(); std::vector<SkywardSwordQuest*> quests = file->questList();
int i = 0; int i = 0;
@ -48,17 +48,17 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file)
// Update the checksums // Update the checksums
q->fixChecksums(); q->fixChecksums();
// Write the save data // Write the save data
base::writeUBytes(q->data(), q->length()); writeUBytes(q->data(), q->length());
atUint64 pos = base::position(); atUint64 pos = position();
// Write the slots skip data // Write the slots skip data
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
base::writeUBytes(q->skipData(), 0x24); writeUBytes(q->skipData(), 0x24);
base::seek(pos, SeekOrigin::Begin); seek(pos, SeekOrigin::Begin);
i++; i++;
} }
// write those padding bytes // write those padding bytes
base::seek(0xFBE0, SeekOrigin::Begin); seek(0xFBE0, SeekOrigin::Begin);
save(); save();
} }

View File

@ -22,21 +22,12 @@ Sprite::Sprite(SpriteFile* root, const std::string& name)
: m_root(root), : m_root(root),
m_currentState(0) m_currentState(0)
{ {
#ifdef ATHENA_USE_QT
m_name = QString::fromStdString(name);
#else
m_name = name; m_name = name;
#endif
} }
Sprite::~Sprite() Sprite::~Sprite()
{ {
#ifndef ATHENA_USE_QT
for (SpriteFrame* frame : m_frames) for (SpriteFrame* frame : m_frames)
#else
foreach (SpriteFrame* frame, m_frames)
#endif
{ {
delete frame; delete frame;
frame = NULL; frame = NULL;
@ -47,49 +38,25 @@ Sprite::~Sprite()
void Sprite::setPosition(const float x, const float y) void Sprite::setPosition(const float x, const float y)
{ {
#ifndef ATHENA_USE_QT
setPosition(Vector2Df(x, y)); setPosition(Vector2Df(x, y));
#else
setPosition(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void Sprite::setPosition(const Vector2Df& pos) void Sprite::setPosition(const Vector2Df& pos)
#else
void Sprite::setPosition(const QPoint& pos)
#endif
{ {
m_position = pos; m_position = pos;
} }
#ifndef ATHENA_USE_QT
Vector2Df Sprite::position() const Vector2Df Sprite::position() const
#else
QPoint Sprite::position() const
#endif
{ {
return m_position; return m_position;
} }
#ifndef ATHENA_USE_QT
void Sprite::setName(const std::string& name) void Sprite::setName(const std::string& name)
#else
void Sprite::setName(const QString& name)
#endif
{ {
m_name = name; m_name = name;
#ifdef ATHENA_USE_QT
emit nameChanged(name);
#endif
} }
#ifndef ATHENA_USE_QT
std::string Sprite::name() const std::string Sprite::name() const
#else
QString Sprite::name() const
#endif
{ {
return m_name; return m_name;
} }
@ -116,18 +83,10 @@ void Sprite::setStateIds(std::vector<int> ids)
if (ids.size() == 0) if (ids.size() == 0)
return; return;
#ifndef ATHENA_USE_QT
m_stateIds = ids; m_stateIds = ids;
#else
m_stateIds = QList<int>::fromVector(QVector<int>::fromStdVector(ids));
#endif
} }
#ifndef ATHENA_USE_QT
std::vector<int> Sprite::stateIds() const std::vector<int> Sprite::stateIds() const
#else
QList<int> Sprite::stateIds() const
#endif
{ {
return m_stateIds; return m_stateIds;
} }
@ -143,9 +102,6 @@ void Sprite::setCurrentState(const atUint32 id)
return; return;
m_currentState = id; m_currentState = id;
#ifdef ATHENA_USE_QT
emit stateChanged(id);
#endif
} }
atUint32 Sprite::currentState() const atUint32 Sprite::currentState() const
@ -170,7 +126,6 @@ bool Sprite::addFrame(SpriteFrame* part)
bool Sprite::removeFrame(SpriteFrame* frame) bool Sprite::removeFrame(SpriteFrame* frame)
{ {
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*>::iterator iter = std::find(m_frames.begin(), m_frames.end(), frame); std::vector<SpriteFrame*>::iterator iter = std::find(m_frames.begin(), m_frames.end(), frame);
if (iter != m_frames.end()) if (iter != m_frames.end())
@ -178,13 +133,6 @@ bool Sprite::removeFrame(SpriteFrame* frame)
m_frames.erase(iter); m_frames.erase(iter);
return true; return true;
} }
#else
if (m_frames.removeOne(frame))
return true;
#endif
return false; return false;
} }
@ -194,7 +142,6 @@ void Sprite::setFrame(atUint32 id)
return; return;
} }
#ifndef ATHENA_USE_QT
void Sprite::setFrames(std::vector<SpriteFrame*> frames) void Sprite::setFrames(std::vector<SpriteFrame*> frames)
{ {
if (frames.size() == 0) if (frames.size() == 0)
@ -213,13 +160,6 @@ void Sprite::setFrames(std::vector<SpriteFrame*> frames)
m_frames = frames; m_frames = frames;
} }
#else
void Sprite::setFrames(QList<SpriteFrame*> frames)
{
m_frames.clear();
m_frames = frames;
}
#endif
atUint32 Sprite::frameCount() const atUint32 Sprite::frameCount() const
@ -227,11 +167,7 @@ atUint32 Sprite::frameCount() const
return (atUint32)m_frames.size(); return (atUint32)m_frames.size();
} }
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*> Sprite::frames() const std::vector<SpriteFrame*> Sprite::frames() const
#else
QList<SpriteFrame*> Sprite::frames() const
#endif
{ {
return m_frames; return m_frames;
} }
@ -263,9 +199,6 @@ void Sprite::setCurrentFrame(atUint32 id)
return; return;
m_currentFrame = id; m_currentFrame = id;
#ifdef ATHENA_USE_QT
emit frameChanged(currentFrame());
#endif
} }
SpriteFrame* Sprite::currentFrame() const SpriteFrame* Sprite::currentFrame() const

View File

@ -26,11 +26,7 @@ SpriteFile::SpriteFile(atUint32 width, atUint32 height, float originX, float ori
{ {
} }
#ifndef ATHENA_USE_QT
SpriteFile::SpriteFile(const Vector2Di& size, const Vector2Df& origin) SpriteFile::SpriteFile(const Vector2Di& size, const Vector2Df& origin)
#else
SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
#endif
: m_size(size), : m_size(size),
m_origin(origin) m_origin(origin)
{ {
@ -38,113 +34,64 @@ SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
SpriteFile::~SpriteFile() SpriteFile::~SpriteFile()
{ {
#ifndef ATHENA_USE_QT
for (std::pair<std::string, Sprite*> sprite : m_sprites) for (std::pair<std::string, Sprite*> sprite : m_sprites)
{ {
delete sprite.second; delete sprite.second;
sprite.second = NULL; sprite.second = NULL;
} }
#endif
m_sprites.clear(); m_sprites.clear();
} }
void SpriteFile::setSize(atUint32 width, atUint32 height) void SpriteFile::setSize(atUint32 width, atUint32 height)
{ {
#ifndef ATHENA_USE_QT
setSize(Vector2Di(width, height)); setSize(Vector2Di(width, height));
#else
setSize(QSize(width, height));
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setSize(const Vector2Di& size) void SpriteFile::setSize(const Vector2Di& size)
#else
void SpriteFile::setSize(const QSize& size)
#endif
{ {
m_size = size; m_size = size;
#ifdef ATHENA_USE_QT
emit sizeChanged(size);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Di SpriteFile::size() const Vector2Di SpriteFile::size() const
#else
QSize SpriteFile::size() const
#endif
{ {
return m_size; return m_size;
} }
atUint32 SpriteFile::width() const atUint32 SpriteFile::width() const
{ {
#ifndef ATHENA_USE_QT
return m_size.x; return m_size.x;
#else
return m_size.width();
#endif
} }
atUint32 SpriteFile::height() const atUint32 SpriteFile::height() const
{ {
#ifndef ATHENA_USE_QT
return m_size.y; return m_size.y;
#else
return m_size.height();
#endif
} }
void SpriteFile::setOrigin(const float x, const float y) void SpriteFile::setOrigin(const float x, const float y)
{ {
#ifndef ATHENA_USE_QT
setOrigin(Vector2Df(x, y)); setOrigin(Vector2Df(x, y));
#else
setOrigin(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setOrigin(const Vector2Df& origin) void SpriteFile::setOrigin(const Vector2Df& origin)
#else
void SpriteFile::setOrigin(const QPoint& origin)
#endif
{ {
m_origin = origin; m_origin = origin;
#ifdef ATHENA_USE_QT
emit originChanged(origin);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpriteFile::origin() const Vector2Df SpriteFile::origin() const
#else
QPoint SpriteFile::origin() const
#endif
{ {
return m_origin; return m_origin;
} }
float SpriteFile::originX() const float SpriteFile::originX() const
{ {
#ifndef ATHENA_USE_QT
return m_origin.x; return m_origin.x;
#else
return m_origin.x();
#endif
} }
float SpriteFile::originY() const float SpriteFile::originY() const
{ {
#ifndef ATHENA_USE_QT
return m_origin.y; return m_origin.y;
#else
return m_origin.y();
#endif
} }
bool SpriteFile::addTexture(STexture* texture) bool SpriteFile::addTexture(STexture* texture)
@ -174,11 +121,7 @@ STexture* SpriteFile::texture(atUint32 id)
return m_textures[id]; return m_textures[id];
} }
#ifndef ATHENA_USE_QT
std::vector<STexture*> SpriteFile::textures() const std::vector<STexture*> SpriteFile::textures() const
#else
QList<STexture*> SpriteFile::textures() const
#endif
{ {
return m_textures; return m_textures;
} }
@ -190,25 +133,15 @@ atUint32 SpriteFile::textureCount() const
void SpriteFile::addSprite(Sprite* sprite) void SpriteFile::addSprite(Sprite* sprite)
{ {
#ifndef ATHENA_USE_QT
std::string name(sprite->name()); std::string name(sprite->name());
athena::utility::tolower(name); athena::utility::tolower(name);
if (m_sprites.find(name) != m_sprites.end()) if (m_sprites.find(name) != m_sprites.end())
return; return;
#else
QString name = sprite->name().toLower();
if (m_sprites.contains(name))
return;
#endif
m_sprites[name] = sprite; m_sprites[name] = sprite;
} }
#ifndef ATHENA_USE_QT
void SpriteFile::removeSprite(const std::string& name) void SpriteFile::removeSprite(const std::string& name)
{ {
std::string tmpName(name); std::string tmpName(name);
@ -218,19 +151,12 @@ void SpriteFile::removeSprite(const std::string& name)
if (iterator != m_sprites.end()) if (iterator != m_sprites.end())
m_sprites.erase(iterator); m_sprites.erase(iterator);
} }
#else
void SpriteFile::removeSprite(const QString& name)
{
m_sprites.remove(name.toLower());
}
#endif
void SpriteFile::removeSprite(Sprite* sprite) void SpriteFile::removeSprite(Sprite* sprite)
{ {
removeSprite(sprite->name()); removeSprite(sprite->name());
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites) void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites)
{ {
if (sprites.size() == 0) if (sprites.size() == 0)
@ -249,18 +175,7 @@ void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites)
m_sprites = sprites; m_sprites = sprites;
} }
#else
void SpriteFile::setSprites(QMap<QString, Sprite*> sprites)
{
if (sprites.size() == 0)
return;
m_sprites.clear();
m_sprites = sprites;
}
#endif
#ifndef ATHENA_USE_QT
Sprite* SpriteFile::sprite(const std::string& name) Sprite* SpriteFile::sprite(const std::string& name)
{ {
std::string nameLow(name); std::string nameLow(name);
@ -271,21 +186,8 @@ Sprite* SpriteFile::sprite(const std::string& name)
return m_sprites[nameLow]; return m_sprites[nameLow];
} }
#else
Sprite* SpriteFile::sprite(const QString& name)
{
if (!m_sprites.contains(name.toLower()))
return NULL;
return m_sprites[name.toLower()];
}
#endif
#ifndef ATHENA_USE_QT
std::unordered_map<std::string, Sprite*> SpriteFile::sprites() const std::unordered_map<std::string, Sprite*> SpriteFile::sprites() const
#else
QMap<QString, Sprite*> SpriteFile::sprites() const
#endif
{ {
return m_sprites; return m_sprites;
} }
@ -295,7 +197,6 @@ atUint32 SpriteFile::spriteCount() const
return (atUint32)m_sprites.size(); return (atUint32)m_sprites.size();
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setTextures(std::vector<STexture*> textures) void SpriteFile::setTextures(std::vector<STexture*> textures)
{ {
if (textures.size() == 0) if (textures.size() == 0)
@ -314,15 +215,6 @@ void SpriteFile::setTextures(std::vector<STexture*> textures)
m_textures = textures; m_textures = textures;
} }
#else
void SpriteFile::setTextures(QList<STexture*> textures)
{
if (textures.size() == 0)
return;
m_textures.clear();
m_textures = textures;
}
#endif
} // Sakura } // Sakura
} // zelda } // zelda

View File

@ -10,12 +10,12 @@ namespace athena
namespace io namespace io
{ {
SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length) SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
SpriteFileReader::SpriteFileReader(const std::string& filepath) SpriteFileReader::SpriteFileReader(const std::string& filepath)
: base(filepath) : MemoryCopyReader(filepath)
{ {
} }
@ -24,7 +24,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{ {
Sakura::SpriteFile* ret = NULL; Sakura::SpriteFile* ret = NULL;
atUint32 magic = base::readUint32(); atUint32 magic = readUint32();
if (magic != Sakura::SpriteFile::Magic) if (magic != Sakura::SpriteFile::Magic)
{ {
@ -32,7 +32,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
return nullptr; return nullptr;
} }
atUint32 version = base::readUint32(); atUint32 version = readUint32();
// TODO: Make this more verbose // TODO: Make this more verbose
if (version != Sakura::SpriteFile::Version) if (version != Sakura::SpriteFile::Version)
@ -46,13 +46,13 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
// Such as the texture count, it's dimensions, and it's origin. // Such as the texture count, it's dimensions, and it's origin.
// After that we have the number of sprites contained in this // After that we have the number of sprites contained in this
// sprite container. // sprite container.
atUint16 textureCount = base::readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states atUint16 textureCount = readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
// This is probably overkill, but it's better safe than sorry. // This is probably overkill, but it's better safe than sorry.
atUint32 width = base::readUint32(); atUint32 width = readUint32();
atUint32 height = base::readUint32(); atUint32 height = readUint32();
float originX = base::readFloat(); float originX = readFloat();
float originY = base::readFloat(); float originY = readFloat();
atUint16 spriteCount = base::readUint16(); atUint16 spriteCount = readUint16();
// Lets go ahead and create or new container. // Lets go ahead and create or new container.
ret = new Sakura::SpriteFile(width, height, originX, originY); ret = new Sakura::SpriteFile(width, height, originX, originY);
@ -62,7 +62,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
// to migrate this code to Big Endian based systems, such as the wii // to migrate this code to Big Endian based systems, such as the wii
// which require data to be 32 byte aligned, or it causes some issues. // which require data to be 32 byte aligned, or it causes some issues.
// It's also convenient to have this, for later expansion. // It's also convenient to have this, for later expansion.
atUint32 reserved = base::readUint32(); atUint32 reserved = readUint32();
UNUSED(reserved); UNUSED(reserved);
// Next we have to load the textures // Next we have to load the textures
@ -79,8 +79,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
for (atUint16 i = 0; i < textureCount; i++) for (atUint16 i = 0; i < textureCount; i++)
{ {
Sakura::STexture* texture = new Sakura::STexture; Sakura::STexture* texture = new Sakura::STexture;
texture->Filepath = base::readString(); texture->Filepath = readString();
texture->Preload = base::readBool(); texture->Preload = readBool();
textures.push_back(texture); textures.push_back(texture);
} }
@ -102,19 +102,19 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{ {
Sakura::Sprite* sprite = new Sakura::Sprite(ret); Sakura::Sprite* sprite = new Sakura::Sprite(ret);
#ifndef ATHENA_USE_QT #ifndef ATHENA_USE_QT
std::string name = base::readString(); std::string name = readString();
#else #else
QString name = QString::fromStdString(base::readString()); QString name = QString::fromStdString(readString());
#endif #endif
sprite->setName(name); sprite->setName(name);
atUint16 frameCount = base::readUint16(); atUint16 frameCount = readUint16();
atUint16 stateCount = base::readUint16(); atUint16 stateCount = readUint16();
// Each state id corresponds to a texture held in the parent class // Each state id corresponds to a texture held in the parent class
std::vector<int> stateIds; std::vector<int> stateIds;
for (int j = 0; j < stateCount; j++) for (int j = 0; j < stateCount; j++)
stateIds.push_back(base::readUint16()); stateIds.push_back(readUint16());
sprite->setStateIds(stateIds); sprite->setStateIds(stateIds);
@ -135,8 +135,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
for (atUint32 k = 0; k < frameCount; k++) for (atUint32 k = 0; k < frameCount; k++)
{ {
Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite); Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite);
frame->setFrameTime(base::readFloat()); frame->setFrameTime(readFloat());
atUint16 partCount = base::readUint16(); atUint16 partCount = readUint16();
#ifndef ATHENA_USE_QT #ifndef ATHENA_USE_QT
@ -149,25 +149,25 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{ {
Sakura::SpritePart* part = new Sakura::SpritePart(frame); Sakura::SpritePart* part = new Sakura::SpritePart(frame);
#ifndef ATHENA_USE_QT #ifndef ATHENA_USE_QT
std::string name = base::readString(); std::string name = readString();
#else #else
QString name = QString::fromStdString(base::readString()); QString name = QString::fromStdString(readString());
#endif #endif
part->setName(name); part->setName(name);
part->setCollision(base::readBool()); part->setCollision(readBool());
float xOff = base::readFloat(); float xOff = readFloat();
float yOff = base::readFloat(); float yOff = readFloat();
part->setOffset(xOff, yOff); part->setOffset(xOff, yOff);
float texXOff = base::readFloat(); float texXOff = readFloat();
float texYOff = base::readFloat(); float texYOff = readFloat();
part->setTextureOffset(texXOff, texYOff); part->setTextureOffset(texXOff, texYOff);
atUint32 width = base::readUint32(); atUint32 width = readUint32();
atUint32 height = base::readUint32(); atUint32 height = readUint32();
part->setSize(width, height); part->setSize(width, height);
bool flippedH = base::readBool(); bool flippedH = readBool();
part->setFlippedHorizontally(flippedH); part->setFlippedHorizontally(flippedH);
bool flippedV = base::readBool(); bool flippedV = readBool();
part->setFlippedVertically(flippedV); part->setFlippedVertically(flippedV);
parts.push_back(part); parts.push_back(part);

View File

@ -9,12 +9,12 @@ namespace athena
namespace io namespace io
{ {
SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length) SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
SpriteFileWriter::SpriteFileWriter(const std::string& filepath) SpriteFileWriter::SpriteFileWriter(const std::string& filepath)
: base(filepath) : MemoryCopyWriter(filepath)
{ {
} }
@ -26,73 +26,51 @@ void SpriteFileWriter::writeFile(Sakura::SpriteFile* file)
return; return;
} }
base::writeUint32(Sakura::SpriteFile::Magic); writeUint32(Sakura::SpriteFile::Magic);
base::writeUint32(Sakura::SpriteFile::Version); writeUint32(Sakura::SpriteFile::Version);
base::writeUint16(file->textureCount()); writeUint16(file->textureCount());
base::writeUint32(file->width()); writeUint32(file->width());
base::writeUint32(file->height()); writeUint32(file->height());
base::writeFloat(file->originX()); writeFloat(file->originX());
base::writeFloat(file->originY()); writeFloat(file->originY());
base::writeUint16(file->spriteCount()); writeUint16(file->spriteCount());
base::writeUint32(0xFFFFFFFF); writeUint32(0xFFFFFFFF);
for (Sakura::STexture* texture : file->textures()) for (Sakura::STexture* texture : file->textures())
{ {
base::writeString(texture->Filepath); writeString(texture->Filepath);
base::writeBool(texture->Preload); writeBool(texture->Preload);
} }
#ifndef ATHENA_USE_QT
for (std::pair<std::string, Sakura::Sprite*> spritePair : file->sprites()) for (std::pair<std::string, Sakura::Sprite*> spritePair : file->sprites())
{ {
Sakura::Sprite* sprite = spritePair.second; Sakura::Sprite* sprite = spritePair.second;
base::writeString(sprite->name()); writeString(sprite->name());
#else writeUint16(sprite->frameCount());
writeUint16(sprite->stateCount());
foreach (Sakura::Sprite* sprite, file->sprites().values())
{
base::writeString(sprite->name().toStdString());
#endif
base::writeUint16(sprite->frameCount());
base::writeUint16(sprite->stateCount());
for (int id : sprite->stateIds()) for (int id : sprite->stateIds())
base::writeUint16(id); writeUint16(id);
for (Sakura::SpriteFrame* frame : sprite->frames()) for (Sakura::SpriteFrame* frame : sprite->frames())
{ {
base::writeFloat(frame->frameTime()); writeFloat(frame->frameTime());
base::writeUint16(frame->partCount()); writeUint16(frame->partCount());
for (Sakura::SpritePart* part : frame->parts()) for (Sakura::SpritePart* part : frame->parts())
{ {
#ifndef ATHENA_USE_QT writeString(part->name());
base::writeString(part->name()); writeBool(part->hasCollision());
#else writeFloat(part->offset().x);
base::writeString(part->name().toStdString()); writeFloat(part->offset().y);
#endif writeFloat(part->textureOffset().x);
base::writeBool(part->hasCollision()); writeFloat(part->textureOffset().y);
#ifndef ATHENA_USE_QT writeUint32(part->size().x);
base::writeFloat(part->offset().x); writeUint32(part->size().y);
base::writeFloat(part->offset().y); writeBool(part->flippedHorizontally());
base::writeFloat(part->textureOffset().x); writeBool(part->flippedVertically());
base::writeFloat(part->textureOffset().y);
base::writeUint32(part->size().x);
base::writeUint32(part->size().y);
#else
base::writeFloat(part->offset().x());
base::writeFloat(part->offset().y());
base::writeFloat(part->textureOffset().x());
base::writeFloat(part->textureOffset().y());
base::writeUint32(part->size().width());
base::writeUint32(part->size().height());
#endif
base::writeBool(part->flippedHorizontally());
base::writeBool(part->flippedVertically());
} }
} }
} }

View File

@ -19,25 +19,14 @@ SpriteFrame::SpriteFrame(Sprite* root)
void SpriteFrame::setFrameTime(float frameTime) void SpriteFrame::setFrameTime(float frameTime)
{ {
m_frameTime = frameTime; m_frameTime = frameTime;
#ifdef ATHENA_USE_QT
emit frameTimeChanged(frameTime);
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFrame::setParts(std::vector<SpritePart*> parts) void SpriteFrame::setParts(std::vector<SpritePart*> parts)
#else
void SpriteFrame::setParts(QList<SpritePart*> parts)
#endif
{ {
m_parts = parts; m_parts = parts;
} }
#ifndef ATHENA_USE_QT
std::vector<SpritePart*> SpriteFrame::parts() const std::vector<SpritePart*> SpriteFrame::parts() const
#else
QList<SpritePart*> SpriteFrame::parts() const
#endif
{ {
return m_parts; return m_parts;
} }

View File

@ -18,34 +18,19 @@ SpritePart::SpritePart(SpriteFrame* root, const std::string& name, bool hasColli
: m_root(root), : m_root(root),
m_hasCollision(hasCollision) m_hasCollision(hasCollision)
{ {
#ifdef ATHENA_USE_QT
m_name = QString::fromStdString(name);
#else
m_name = name; m_name = name;
#endif
} }
SpritePart::~SpritePart() SpritePart::~SpritePart()
{ {
} }
#ifndef ATHENA_USE_QT
void SpritePart::setName(const std::string& name) void SpritePart::setName(const std::string& name)
#else
void SpritePart::setName(const QString& name)
#endif
{ {
m_name = name; m_name = name;
#ifdef ATHENA_USE_QT
emit nameChanged(name);
#endif
} }
#ifndef ATHENA_USE_QT
std::string SpritePart::name() const std::string SpritePart::name() const
#else
QString SpritePart::name() const
#endif
{ {
return m_name; return m_name;
} }
@ -53,9 +38,6 @@ QString SpritePart::name() const
void SpritePart::setCollision(bool col) void SpritePart::setCollision(bool col)
{ {
m_hasCollision = col; m_hasCollision = col;
#ifdef ATHENA_USE_QT
emit collisionChanged(col);
#endif
} }
bool SpritePart::hasCollision() const bool SpritePart::hasCollision() const
@ -65,90 +47,45 @@ bool SpritePart::hasCollision() const
void SpritePart::setOffset(float x, float y) void SpritePart::setOffset(float x, float y)
{ {
#ifndef ATHENA_USE_QT
setOffset(Vector2Df(x, y)); setOffset(Vector2Df(x, y));
#else
setOffset(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setOffset(const Vector2Df& offset) void SpritePart::setOffset(const Vector2Df& offset)
#else
void SpritePart::setOffset(const QPoint& offset)
#endif
{ {
m_offset = offset; m_offset = offset;
#ifdef ATHENA_USE_QT
emit offsetChanged(offset);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpritePart::offset() const Vector2Df SpritePart::offset() const
#else
QPoint SpritePart::offset() const
#endif
{ {
return m_offset; return m_offset;
} }
void SpritePart::setTextureOffset(float x, float y) void SpritePart::setTextureOffset(float x, float y)
{ {
#ifndef ATHENA_USE_QT
setTextureOffset(Vector2Df(x, y)); setTextureOffset(Vector2Df(x, y));
#else
setTextureOffset(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setTextureOffset(const Vector2Df& offset) void SpritePart::setTextureOffset(const Vector2Df& offset)
#else
void SpritePart::setTextureOffset(const QPoint& offset)
#endif
{ {
m_textureOffset = offset; m_textureOffset = offset;
#ifdef ATHENA_USE_QT
emit textureOffsetChanged(offset);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpritePart::textureOffset() const Vector2Df SpritePart::textureOffset() const
#else
QPoint SpritePart::textureOffset() const
#endif
{ {
return m_textureOffset; return m_textureOffset;
} }
void SpritePart::setSize(atUint32 width, atUint32 height) void SpritePart::setSize(atUint32 width, atUint32 height)
{ {
#ifndef ATHENA_USE_QT
setSize(Vector2Di(width, height)); setSize(Vector2Di(width, height));
#else
setSize(QSize(width, height));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setSize(const Vector2Di& size) void SpritePart::setSize(const Vector2Di& size)
#else
void SpritePart::setSize(const QSize& size)
#endif
{ {
m_size = size; m_size = size;
#ifdef ATHENA_USE_QT
emit sizeChanged(size);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Di SpritePart::size() const Vector2Di SpritePart::size() const
#else
QSize SpritePart::size() const
#endif
{ {
return m_size; return m_size;
} }
@ -156,9 +93,6 @@ QSize SpritePart::size() const
void SpritePart::setFlippedHorizontally(const bool val) void SpritePart::setFlippedHorizontally(const bool val)
{ {
m_flippedH = val; m_flippedH = val;
#ifdef ATHENA_USE_QT
emit orientationChanged(val, flippedVertically());
#endif
} }
bool SpritePart::flippedHorizontally() const bool SpritePart::flippedHorizontally() const
@ -169,9 +103,6 @@ bool SpritePart::flippedHorizontally() const
void SpritePart::setFlippedVertically(const bool val) void SpritePart::setFlippedVertically(const bool val)
{ {
m_flippedV = val; m_flippedV = val;
#ifdef ATHENA_USE_QT
emit orientationChanged(flippedHorizontally(), val);
#endif
} }
bool SpritePart::flippedVertically() const bool SpritePart::flippedVertically() const

View File

@ -7,7 +7,7 @@
#include "athena/FileWriter.hpp" #include "athena/FileWriter.hpp"
#include "md5.h" #include "md5.h"
#include "aes.hpp" #include "aes.hpp"
#include "ecc.h" #include "ec.hpp"
#include "sha1.h" #include "sha1.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
@ -20,13 +20,13 @@ namespace io
{ {
WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length) WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
WiiSaveReader::WiiSaveReader(const std::string& filename) WiiSaveReader::WiiSaveReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
@ -50,7 +50,7 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
} }
ret->setBanner(banner); ret->setBanner(banner);
atUint32 bkVer = base::readUint32(); atUint32 bkVer = readUint32();
if (bkVer != 0x00000070) if (bkVer != 0x00000070)
{ {
@ -58,7 +58,7 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
return nullptr; return nullptr;
} }
atUint32 bkMagic = base::readUint32(); atUint32 bkMagic = readUint32();
if (bkMagic != 0x426B0001) if (bkMagic != 0x426B0001)
{ {
@ -66,18 +66,18 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
return nullptr; return nullptr;
} }
/*atUint32 ngId =*/ base::readUint32(); /*atUint32 ngId =*/ readUint32();
atUint32 numFiles = base::readUint32(); atUint32 numFiles = readUint32();
/*int fileSize =*/ base::readUint32(); /*int fileSize =*/ readUint32();
base::seek(8); // skip unknown data; seek(8); // skip unknown data;
atUint32 totalSize = base::readUint32(); atUint32 totalSize = readUint32();
base::seek(64); // Unknown (Most likely padding) seek(64); // Unknown (Most likely padding)
base::seek(8); seek(8);
base::seek(6); seek(6);
base::seek(2); seek(2);
base::seek(0x10); seek(0x10);
std::vector<WiiFile*> files; std::vector<WiiFile*> files;
@ -99,10 +99,10 @@ WiiBanner* WiiSaveReader::readBanner()
{ {
atUint8* dec = new atUint8[0xF0C0]; atUint8* dec = new atUint8[0xF0C0];
memset(dec, 0, 0xF0C0); memset(dec, 0, 0xF0C0);
std::unique_ptr<atUint8[]> data = base::readUBytes(0xF0C0); std::unique_ptr<atUint8[]> buf = readUBytes(0xF0C0);
atUint8* oldData = base::data(); atUint8* oldData = data();
atUint64 oldPos = base::position(); atUint64 oldPos = position();
atUint64 oldLen = base::length(); atUint64 oldLen = length();
atUint64 gameId; atUint64 gameId;
atUint32 bannerSize; atUint32 bannerSize;
atUint8 permissions; atUint8 permissions;
@ -114,7 +114,7 @@ WiiBanner* WiiSaveReader::readBanner()
std::cout << "Decrypting: banner.bin..."; std::cout << "Decrypting: banner.bin...";
std::unique_ptr<IAES> aes = NewAES(); std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY); aes->setKey(SD_KEY);
aes->decrypt(tmpIV, data.get(), dec, 0xF0C0); aes->decrypt(tmpIV, buf.get(), dec, 0xF0C0);
std::cout << "done" << std::endl; std::cout << "done" << std::endl;
memset(md5, 0, 16); memset(md5, 0, 16);
@ -144,22 +144,22 @@ WiiBanner* WiiSaveReader::readBanner()
std::cerr << std::hex << (int)(md5Calc[i]); std::cerr << std::hex << (int)(md5Calc[i]);
std::cerr << std::endl; std::cerr << std::endl;
base::setData(oldData, oldLen); setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin); seek(oldPos, SeekOrigin::Begin);
atError("MD5 Mismatch"); atError("MD5 Mismatch");
return nullptr; return nullptr;
} }
// Set the binary reader buffer; // Set the binary reader buffer;
base::setData(dec, 0xF0C0); setData(dec, 0xF0C0);
// Start reading the header // Start reading the header
gameId = base::readUint64(); gameId = readUint64();
bannerSize = base::readUint32(); bannerSize = readUint32();
permissions = base::readByte(); permissions = readByte();
/* unk =*/ base::readByte(); /* unk =*/ readByte();
base::seek(0x10); seek(0x10);
// skip padding // skip padding
base::seek(2); seek(2);
int magic; int magic;
int flags; int flags;
@ -167,31 +167,31 @@ WiiBanner* WiiSaveReader::readBanner()
std::string gameTitle; std::string gameTitle;
std::string subTitle; std::string subTitle;
magic = base::readUint32(); magic = readUint32();
// Ensure that the header magic is valid. // Ensure that the header magic is valid.
if (magic != 0x5749424E) if (magic != 0x5749424E)
{ {
// Make sure to reset m_reader values back to the old ones. // Make sure to reset m_reader values back to the old ones.
base::setData(oldData, oldLen); setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin); seek(oldPos, SeekOrigin::Begin);
atError("Invalid Header Magic"); atError("Invalid Header Magic");
return nullptr; return nullptr;
} }
flags = base::readUint32(); flags = readUint32();
animSpeed = base::readUint16(); animSpeed = readUint16();
base::seek(22); seek(22);
gameTitle = base::readWStringAsString(); gameTitle = readWStringAsString();
if (base::position() != 0x0080) if (position() != 0x0080)
base::seek(0x0080, SeekOrigin::Begin); seek(0x0080, SeekOrigin::Begin);
subTitle = base::readWStringAsString(); subTitle = readWStringAsString();
if (base::position() != 0x00C0) if (position() != 0x00C0)
base::seek(0x00C0, SeekOrigin::Begin); seek(0x00C0, SeekOrigin::Begin);
WiiBanner* banner = new WiiBanner; WiiBanner* banner = new WiiBanner;
banner->setGameID(gameId); banner->setGameID(gameId);
@ -227,14 +227,14 @@ WiiBanner* WiiSaveReader::readBanner()
} }
} }
base::setData(oldData, oldLen); setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin); seek(oldPos, SeekOrigin::Begin);
return banner; return banner;
} }
WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height) WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height)
{ {
std::unique_ptr<atUint8[]> image = base::readUBytes(width * height * 2); std::unique_ptr<atUint8[]> image = readUBytes(width * height * 2);
if (!utility::isEmpty((atInt8*)image.get(), width * height * 2)) if (!utility::isEmpty((atInt8*)image.get(), width * height * 2))
return new WiiImage(width, height, std::move(image)); return new WiiImage(width, height, std::move(image));
@ -252,7 +252,7 @@ WiiFile* WiiSaveReader::readFile()
std::string name; std::string name;
WiiFile* ret; WiiFile* ret;
atUint32 magic = base::readUint32(); atUint32 magic = readUint32();
if (magic != 0x03adf17e) if (magic != 0x03adf17e)
{ {
@ -260,23 +260,23 @@ WiiFile* WiiSaveReader::readFile()
return NULL; return NULL;
} }
fileLen = base::readUint32(); fileLen = readUint32();
permissions = base::readByte(); permissions = readByte();
attributes = base::readByte(); attributes = readByte();
type = (WiiFile::Type)base::readByte(); type = (WiiFile::Type)readByte();
name = std::string((const char*)base::readBytes(0x45).get()); name = std::string((const char*)readBytes(0x45).get());
ret = new WiiFile(std::string(name)); ret = new WiiFile(std::string(name));
ret->setPermissions(permissions); ret->setPermissions(permissions);
ret->setAttributes(attributes); ret->setAttributes(attributes);
ret->setType((WiiFile::Type)type); ret->setType((WiiFile::Type)type);
std::unique_ptr<atUint8[]> iv = base::readUBytes(0x10); std::unique_ptr<atUint8[]> iv = readUBytes(0x10);
base::seek(0x20); seek(0x20);
if (type == WiiFile::File) if (type == WiiFile::File)
{ {
// Read file data // Read file data
int roundedLen = (fileLen + 63) & ~63; int roundedLen = (fileLen + 63) & ~63;
std::unique_ptr<atUint8[]> filedata = base::readUBytes(roundedLen); std::unique_ptr<atUint8[]> filedata = readUBytes(roundedLen);
// Decrypt file // Decrypt file
std::cout << "Decrypting: " << ret->filename() << "..."; std::cout << "Decrypting: " << ret->filename() << "...";
@ -294,35 +294,26 @@ WiiFile* WiiSaveReader::readFile()
void WiiSaveReader::readCerts(atUint32 totalSize) void WiiSaveReader::readCerts(atUint32 totalSize)
{ {
#if 0
std::cout << "Reading certs..." << std::endl; std::cout << "Reading certs..." << std::endl;
atUint32 dataSize = totalSize - 0x340; atUint32 dataSize = totalSize - 0x340;
std::unique_ptr<atUint8[]> sig = base::readUBytes(0x40); std::unique_ptr<atUint8[]> sig = readUBytes(0x40);
std::unique_ptr<atUint8[]> ngCert = base::readUBytes(0x180); std::unique_ptr<atUint8[]> ngCert = readUBytes(0x180);
std::unique_ptr<atUint8[]> apCert = base::readUBytes(0x180); std::unique_ptr<atUint8[]> apCert = readUBytes(0x180);
base::seek(0xF0C0, SeekOrigin::Begin); seek(0xF0C0, SeekOrigin::Begin);
std::unique_ptr<atUint8[]> data = base::readUBytes(dataSize); std::unique_ptr<atUint8[]> data = readUBytes(dataSize);
atUint8* hash; atUint8* hash;
std::cout << "validating..." << std::endl; std::cout << "validating..." << std::endl;
hash = getSha1(data.get(), dataSize); hash = getSha1(data.get(), dataSize);
atUint8* hash2 = getSha1(hash, 20); atUint8* hash2 = getSha1(hash, 20);
bool failed = false; bool ngValid = false;
bool apValid = false;
ecc::checkEC(ngCert.get(), apCert.get(), sig.get(), hash2, apValid, ngValid);
if (!ecdsa_verify(ngCert.get(), hash, sig.get())) if (apValid)
{ std::cout << "AP Certificate ok" << std::endl;
std::cout << "NGCert failure" << std::endl; if (ngValid)
failed = true; std::cout << "NG Certificate ok" << std::endl;
}
if (!ecdsa_verify(apCert.get(), hash2, sig.get()))
{
std::cout << "APCert failure" << std::endl;
failed = true;
}
if (!failed)
std::cout << "certificates ok" << std::endl;
#endif
} }
WiiFile* WiiSaveReader::buildTree(std::vector<WiiFile*> files) WiiFile* WiiSaveReader::buildTree(std::vector<WiiFile*> files)

View File

@ -10,7 +10,7 @@
#include "athena/Utility.hpp" #include "athena/Utility.hpp"
#include "aes.hpp" #include "aes.hpp"
#include "ecc.h" #include "ec.hpp"
#include "md5.h" #include "md5.h"
#include "sha1.h" #include "sha1.h"
@ -28,9 +28,9 @@ namespace io
{ {
WiiSaveWriter::WiiSaveWriter(const std::string& filename) WiiSaveWriter::WiiSaveWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
@ -47,18 +47,18 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
writeBanner(save->banner()); writeBanner(save->banner());
base::writeUint32(0x70); writeUint32(0x70);
base::writeUint32(0x426B0001); writeUint32(0x426B0001);
base::writeUint32(ngId); // NG-ID writeUint32(ngId); // NG-ID
base::writeUint32(save->fileCount()); writeUint32(save->fileCount());
base::writeUint32(0); // Size of files; writeUint32(0); // Size of files;
base::seek(8); seek(8);
base::writeUint32(0); // totalSize writeUint32(0); // totalSize
base::seek(64); seek(64);
base::writeUint64(save->banner()->gameID()); writeUint64(save->banner()->gameID());
base::writeBytes((atInt8*)macAddress, 6); writeBytes((atInt8*)macAddress, 6);
base::seek(2); // unknown; seek(2); // unknown;
base::seek(0x10); // padding; seek(0x10); // padding;
atUint32 totalSize = 0; atUint32 totalSize = 0;
for (WiiFile* file : save->allFiles()) for (WiiFile* file : save->allFiles())
@ -66,47 +66,47 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
totalSize += writeFile(file); totalSize += writeFile(file);
} }
atUint64 pos = base::position(); atUint64 pos = position();
// Write size data // Write size data
base::seek(0xF0C0 + 0x10, SeekOrigin::Begin); seek(0xF0C0 + 0x10, SeekOrigin::Begin);
base::writeUint32(totalSize); writeUint32(totalSize);
base::seek(0xF0C0 + 0x1C, SeekOrigin::Begin); seek(0xF0C0 + 0x1C, SeekOrigin::Begin);
base::writeUint32(totalSize + 0x3c0); writeUint32(totalSize + 0x3c0);
base::seek(pos, SeekOrigin::Begin); seek(pos, SeekOrigin::Begin);
writeCerts(totalSize, ngId, ngPriv, ngSig, ngKeyId); writeCerts(totalSize, ngId, ngPriv, ngSig, ngKeyId);
base::save(); this->save();
return true; return true;
} }
void WiiSaveWriter::writeBanner(WiiBanner* banner) void WiiSaveWriter::writeBanner(WiiBanner* banner)
{ {
base::setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
base::writeInt64(banner->gameID()); writeInt64(banner->gameID());
base::writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size()); writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size());
base::writeByte((atInt8)banner->permissions()); writeByte((atInt8)banner->permissions());
base::seek(1); seek(1);
base::writeBytes((atInt8*)MD5_BLANKER, 16); writeBytes((atInt8*)MD5_BLANKER, 16);
base::seek(2); seek(2);
base::writeInt32(0x5749424E); // WIBN writeInt32(0x5749424E); // WIBN
base::writeInt32(banner->flags()); writeInt32(banner->flags());
base::writeInt16(banner->animationSpeed()); writeInt16(banner->animationSpeed());
base::seek(22); seek(22);
base::writeStringAsWString(banner->title()); writeStringAsWString(banner->title());
if (base::position() != 0x0080) if (position() != 0x0080)
base::seek(0x0080, SeekOrigin::Begin); seek(0x0080, SeekOrigin::Begin);
base::writeStringAsWString(banner->subtitle()); writeStringAsWString(banner->subtitle());
if (base::position() != 0x00C0) if (position() != 0x00C0)
base::seek(0x00C0, SeekOrigin::Begin); seek(0x00C0, SeekOrigin::Begin);
WiiImage* bannerImage = banner->bannerImage(); WiiImage* bannerImage = banner->bannerImage();
base::writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height() * 2); writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height() * 2);
// For empty icons // For empty icons
atUint8* tmpIcon = new atUint8[48 * 48 * 2]; atUint8* tmpIcon = new atUint8[48 * 48 * 2];
@ -120,28 +120,28 @@ void WiiSaveWriter::writeBanner(WiiBanner* banner)
} }
else else
{ {
base::writeBytes((atInt8*)tmpIcon, 48 * 48 * 2); writeBytes((atInt8*)tmpIcon, 48 * 48 * 2);
} }
} }
delete[] tmpIcon; // delete tmp buffer; delete[] tmpIcon; // delete tmp buffer;
atUint8* hash = new atUint8[0x10]; atUint8* hash = new atUint8[0x10];
MD5Hash::MD5(hash, (atUint8*)base::data(), 0xF0C0); MD5Hash::MD5(hash, (atUint8*)data(), 0xF0C0);
base::seek(0x0E, SeekOrigin::Begin); seek(0x0E, SeekOrigin::Begin);
base::writeBytes((atInt8*)hash, 0x10); writeBytes((atInt8*)hash, 0x10);
std::unique_ptr<IAES> aes = NewAES(); std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY); aes->setKey(SD_KEY);
atUint8 data[0xF0C0]; atUint8 data[0xF0C0];
memcpy(data, base::data(), 0xF0C0); memcpy(data, this->data(), 0xF0C0);
atUint8 tmpIV[26]; atUint8 tmpIV[26];
memcpy(tmpIV, SD_IV, 16); memcpy(tmpIV, SD_IV, 16);
aes->encrypt(tmpIV, data, data, 0xF0C0); aes->encrypt(tmpIV, data, data, 0xF0C0);
base::seek(0, SeekOrigin::Begin); seek(0, SeekOrigin::Begin);
base::writeBytes((atInt8*)data, 0xF0C0); writeBytes((atInt8*)data, 0xF0C0);
base::seek(0xF0C0, SeekOrigin::Begin); seek(0xF0C0, SeekOrigin::Begin);
} }
atUint32 WiiSaveWriter::writeFile(WiiFile* file) atUint32 WiiSaveWriter::writeFile(WiiFile* file)
@ -149,23 +149,23 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
atUint32 ret = 0x80; atUint32 ret = 0x80;
// Write the File magic // Write the File magic
base::writeUint32(0x03ADF17E); writeUint32(0x03ADF17E);
base::writeUint32(file->length()); writeUint32(file->length());
base::writeByte(file->permissions()); writeByte(file->permissions());
base::writeByte(file->attributes()); writeByte(file->attributes());
base::writeByte(file->type()); writeByte(file->type());
atUint8 name[0x45]; atUint8 name[0x45];
utility::fillRandom(name, 0x45); utility::fillRandom(name, 0x45);
memcpy(name, file->fullpath().c_str(), file->fullpath().size()); memcpy(name, file->fullpath().c_str(), file->fullpath().size());
name[file->fullpath().size()] = '\0'; name[file->fullpath().size()] = '\0';
base::writeBytes((atInt8*)name, 0x45); writeBytes((atInt8*)name, 0x45);
atUint8 iv[16]; atUint8 iv[16];
utility::fillRandom(iv, 0x10); utility::fillRandom(iv, 0x10);
base::writeBytes((atInt8*)iv, 0x10); writeBytes((atInt8*)iv, 0x10);
atUint8 crap[0x20]; atUint8 crap[0x20];
utility::fillRandom(crap, 0x20); utility::fillRandom(crap, 0x20);
base::writeBytes((atInt8*)crap, 0x20); writeBytes((atInt8*)crap, 0x20);
if (file->type() == WiiFile::File) if (file->type() == WiiFile::File)
{ {
@ -177,7 +177,7 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
aes->setKey(SD_KEY); aes->setKey(SD_KEY);
aes->encrypt(iv, file->data(), data, roundedSize); aes->encrypt(iv, file->data(), data, roundedSize);
base::writeBytes((atInt8*)data, roundedSize); writeBytes((atInt8*)data, roundedSize);
ret += roundedSize; ret += roundedSize;
delete[] data; delete[] data;
} }
@ -189,12 +189,11 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
void WiiSaveWriter::writeImage(WiiImage* image) void WiiSaveWriter::writeImage(WiiImage* image)
{ {
atInt8* data = (atInt8*)image->data(); atInt8* data = (atInt8*)image->data();
base::writeBytes(data, image->width() * image->height() * 2); writeBytes(data, image->width() * image->height() * 2);
} }
void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId) void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId)
{ {
#if 0
atUint8 sig[0x40]; atUint8 sig[0x40];
atUint8 ngCert[0x180]; atUint8 ngCert[0x180];
atUint8 apCert[0x180]; atUint8 apCert[0x180];
@ -203,12 +202,12 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
atUint8 apSig[60]; atUint8 apSig[60];
char signer[64]; char signer[64];
char name[64]; char name[64];
atUint8* data; atUint8* buf;
atUint32 dataSize; atUint32 dataSize;
sprintf(signer, "Root-CA00000001-MS00000002"); sprintf(signer, "Root-CA00000001-MS00000002");
sprintf(name, "NG%08x", ngId); sprintf(name, "NG%08x", ngId);
make_ec_cert(ngCert, ngSig, signer, name, ngPriv, ngKeyId); ecc::makeECCert(ngCert, ngSig, signer, name, ngPriv, ngKeyId);
memset(apPriv, 0, 30); memset(apPriv, 0, 30);
apPriv[10] = 1; apPriv[10] = 1;
@ -217,24 +216,24 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
sprintf(signer, "Root-CA00000001-MS00000002-NG%08x", ngId); sprintf(signer, "Root-CA00000001-MS00000002-NG%08x", ngId);
sprintf(name, "AP%08x%08x", 1, 2); sprintf(name, "AP%08x%08x", 1, 2);
make_ec_cert(apCert, apSig, signer, name, apPriv, 0); ecc::makeECCert(apCert, apSig, signer, name, apPriv, 0);
hash = getSha1(apCert + 0x80, 0x100); hash = getSha1(apCert + 0x80, 0x100);
generate_ecdsa(apSig, apSig + 30, ngPriv, hash); ecc::createECDSA(apSig, apSig + 30, ngPriv, hash);
make_ec_cert(apCert, apSig, signer, name, apPriv, 0); ecc::makeECCert(apCert, apSig, signer, name, apPriv, 0);
delete[] hash; delete[] hash;
dataSize = filesSize + 0x80; dataSize = filesSize + 0x80;
data = new atUint8[dataSize]; buf = new atUint8[dataSize];
atUint8* rawData = base::data(); atUint8* rawData = data();
memcpy(data, rawData + 0xF0C0, dataSize); memcpy(buf, rawData + 0xF0C0, dataSize);
hash = getSha1(data, dataSize); hash = getSha1(buf, dataSize);
atUint8* hash2 = getSha1(hash, 20); atUint8* hash2 = getSha1(hash, 20);
delete[] hash; delete[] hash;
delete[] data; delete[] buf;
generate_ecdsa(sig, sig + 30, apPriv, hash2); ecc::createECDSA(sig, sig + 30, apPriv, hash2);
int stuff = 0x2f536969; int stuff = 0x2f536969;
if (!utility::isSystemBigEndian()) if (!utility::isSystemBigEndian())
@ -243,10 +242,9 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
*(atUint32*)(sig + 60) = stuff; *(atUint32*)(sig + 60) = stuff;
delete[] hash2; delete[] hash2;
base::writeBytes((atInt8*)sig, 0x40); writeBytes((atInt8*)sig, 0x40);
base::writeBytes((atInt8*)ngCert, 0x180); writeBytes((atInt8*)ngCert, 0x180);
base::writeBytes((atInt8*)apCert, 0x180); writeBytes((atInt8*)apCert, 0x180);
#endif
} }
} // io } // io

View File

@ -13,12 +13,12 @@ namespace io
{ {
ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length) ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
ZQuestFileReader::ZQuestFileReader(const std::string& filename) ZQuestFileReader::ZQuestFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }
@ -30,7 +30,7 @@ ZQuestFile* ZQuestFileReader::read()
atUint16 BOM; atUint16 BOM;
atUint32 checksum = 0; atUint32 checksum = 0;
magic = base::readUint32(); magic = readUint32();
if ((magic & 0x00FFFFFF) != (ZQuestFile::Magic & 0x00FFFFFF)) if ((magic & 0x00FFFFFF) != (ZQuestFile::Magic & 0x00FFFFFF))
{ {
@ -38,7 +38,7 @@ ZQuestFile* ZQuestFileReader::read()
return nullptr; return nullptr;
} }
version = base::readUint32(); version = readUint32();
if (version > ZQuestFile::Version) if (version > ZQuestFile::Version)
{ {
@ -46,12 +46,12 @@ ZQuestFile* ZQuestFileReader::read()
return nullptr; return nullptr;
} }
compressedLen = base::readUint32(); compressedLen = readUint32();
uncompressedLen = base::readUint32(); uncompressedLen = readUint32();
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0)) if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
{ {
gameString = std::string((const char*)base::readBytes(0x0A).get(), 0x0A); gameString = std::string((const char*)readBytes(0x0A).get(), 0x0A);
for (size_t i = 0; i < ZQuestFile::gameStringList().size(); i++) for (size_t i = 0; i < ZQuestFile::gameStringList().size(); i++)
{ {
@ -63,17 +63,17 @@ ZQuestFile* ZQuestFileReader::read()
} }
} }
BOM = base::readUint16(); BOM = readUint16();
checksum = base::readUint32(); checksum = readUint32();
} }
else else
{ {
game = (ZQuestFile::Game)base::readUint32(); game = (ZQuestFile::Game)readUint32();
BOM = base::readUint16(); BOM = readUint16();
base::seek(0x0A); seek(0x0A);
} }
std::unique_ptr<atUint8[]> data = base::readUBytes(compressedLen); // compressedLen is always the total file size std::unique_ptr<atUint8[]> data = readUBytes(compressedLen); // compressedLen is always the total file size
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0)) if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
{ {

View File

@ -9,12 +9,12 @@ namespace io
{ {
ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length) ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
ZQuestFileWriter::ZQuestFileWriter(const std::string& filename) ZQuestFileWriter::ZQuestFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }
@ -26,8 +26,8 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
return; return;
} }
base::writeUint32(ZQuestFile::Magic); writeUint32(ZQuestFile::Magic);
base::writeUint32(ZQuestFile::Version); writeUint32(ZQuestFile::Version);
atUint8* questData = quest->data(); atUint8* questData = quest->data();
atUint32 compLen; atUint32 compLen;
@ -44,28 +44,28 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
// Delete the compressed data since we won't be using it // Delete the compressed data since we won't be using it
delete[] compData; delete[] compData;
compData = NULL; compData = NULL;
base::writeUint32(quest->length()); writeUint32(quest->length());
} }
else else
{ {
// Don't do delete on data // Don't do delete on data
questData = compData; questData = compData;
base::writeUint32(compLen); writeUint32(compLen);
} }
} }
else else
{ {
compLen = quest->length(); compLen = quest->length();
base::writeUint32(quest->length()); writeUint32(quest->length());
} }
base::writeUint32(quest->length()); writeUint32(quest->length());
base::writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A); writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
base::writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF); writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
base::writeUint32(athena::Checksums::crc32(questData, compLen)); writeUint32(athena::Checksums::crc32(questData, compLen));
base::writeUBytes(questData, compLen); writeUBytes(questData, compLen);
base::save(); save();
// Delete compressed data to prevent memory leaks // Delete compressed data to prevent memory leaks
if (questData != quest->data()) if (questData != quest->data())

98
src/bn.cpp Normal file
View File

@ -0,0 +1,98 @@
#include <string.h>
#include <stdio.h>
#include "bn.hpp"
namespace bignum
{
void subModulus(atUint8* a, const atUint8* N, atUint32 n)
{
atUint8 c = 0;
for (atUint32 i = n - 1; i < n; i--)
{
atUint32 dig = N[i] + c;
c = (a[i] < dig);
a[i] -= dig;
}
}
void add(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n)
{
atUint8 c = 0;
for (atUint32 i = n - 1; i < n; i--)
{
atUint32 dig = a[i] + b[i] + c;
c = (dig >= 0x100);
d[i] = dig;
}
if (c)
subModulus(d, N, n);
if (compare(d, N, n) >= 0)
subModulus(d, N, n);
}
void mul(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n)
{
memset(d, 0, n);
for (atUint32 i = 0; i < n; i++)
{
for (atUint8 mask = 0x80; mask != 0; mask >>= 1)
{
add(d, d, d, N, n);
if ((a[i] & mask) != 0)
add(d, d, b, N, n);
}
}
}
void exp(atUint8* d, const atUint8* a, const atUint8* N, atUint32 n, atUint8* e, atUint32 en)
{
atUint8 t[512];
memset(d, 0, n);
d[n - 1] = 1;
for (atUint32 i = 0; i < en; i++)
{
for (atUint8 mask = 0x80; mask != 0; mask >>= 1)
{
mul(t, d, d, N, n);
if ((e[i] & mask) != 0)
mul(d, t, a, N, n);
else
memcpy(d, t, n);
}
}
}
void inv(atUint8* d, atUint8* a, const atUint8* N, atUint32 n)
{
atUint8 t[512], s[512];
memcpy(t, N, n);
memset(s, 0, n);
s[n - 1] = 2;
subModulus(t, s, n);
exp(d, a, N, n, t, n);
}
int compare(const atUint8* a, const atUint8* b, atUint32 n)
{
for (atUint32 i = 0; i < n; i++)
{
if (a[i] < b[i])
return -1;
if (a[i] > b[i])
return 1;
}
return 0;
}
}

320
src/ec.cpp Normal file
View File

@ -0,0 +1,320 @@
#include <string.h>
#include "athena/Utility.hpp"
#include "bn.hpp"
#include "ec.hpp"
#include "sha1.h"
namespace ecc
{
static int checkZero(const atUint8* d) { return !memcmp(d, d + 1, 29) && d[0] == 0; }
static void add(atUint8* d, const atUint8* a, const atUint8* b)
{
for (atUint32 i = 0; i < 30; i++)
d[i] = a[i] ^ b[i];
}
static void multiply(atUint8* d, const atUint8* a, const atUint8* b)
{
memset(d, 0, 30);
for (atUint32 n = 0, i = 0, mask = 1; n < 233; n++)
{
atUint8 x, y;
atUint8 carry = d[0] & 1;
x = 0;
for (atUint32 i = 0; i < 29; i++)
{
y = d[i + 1];
d[i] = x ^ (y >> 7);
x = y << 1;
}
d[29] = x ^ carry;
d[20] ^= carry << 2;
if ((a[i] & mask) != 0)
add(d, d, b);
mask >>= 1;
if (mask == 0)
{
mask = 0x80;
i++;
}
}
}
static void squareToWide(atUint8* d, const atUint8* a)
{
static const atUint8 sq[16] = {0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15,
0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55};
for (atUint32 i = 0; i < 30; i++)
{
d[2 * i] = sq[a[i] >> 4];
d[2 * i + 1] = sq[a[i] & 15];
}
}
static void wideReduce(atUint8* d)
{
atUint32 i;
atUint8 x;
for (i = 0; i < 30; i++)
{
x = d[i];
d[i + 19] ^= x >> 7;
d[i + 20] ^= x << 1;
d[i + 29] ^= x >> 1;
d[i + 30] ^= x << 7;
}
x = d[30] & ~1;
d[49] ^= x >> 7;
d[50] ^= x << 1;
d[59] ^= x >> 1;
d[30] &= 1;
}
static void square(atUint8* d, const atUint8* a)
{
atUint8 wide[60];
squareToWide(wide, a);
wideReduce(wide);
memcpy(d, wide + 30, 30);
}
static void itInvert(atUint8* d, const atUint8* a, const atUint8* b, atUint32 j)
{
atUint8 t[30];
memcpy(t, a, 32);
while (j--)
{
square(d, t);
memcpy(t, d, 30);
}
multiply(d, t, b);
}
static void invert(atUint8* d, const atUint8* a)
{
atUint8 t[30];
atUint8 s[30];
itInvert(t, a, a, 1);
itInvert(s, t, a, 1);
itInvert(t, s, s, 3);
itInvert(s, t, a, 1);
itInvert(t, s, s, 7);
itInvert(s, t, t, 14);
itInvert(t, s, a, 1);
itInvert(s, t, t, 29);
itInvert(t, s, s, 58);
itInvert(s, t, t, 116);
square(d, s);
}
static void pointDouble(atUint8* r, const atUint8* p)
{
atUint8 s[30], t[30];
const atUint8* px = p;
const atUint8* py = p + 30;
atUint8* rx = r;
atUint8* ry = r + 30;
if (checkZero(px))
{
memset(rx, 0, 30);
memset(ry, 0, 30);
return;
}
invert(t, px);
multiply(s, py, t);
add(s, s, px);
square(t, px);
square(rx, s);
add(rx, rx, s);
rx[29] ^= 1;
multiply(ry, s, rx);
add(ry, ry, rx);
add(ry, ry, t);
}
static void pointAdd(atUint8* r, const atUint8* p, const atUint8* q)
{
atUint8 s[30], t[30], u[30];
const atUint8* px = p;
const atUint8* py = p + 30;
const atUint8* qx = q;
const atUint8* qy = q + 30;
atUint8* rx = r;
atUint8* ry = r + 30;
if (checkZero(p) && checkZero(p + 30))
{
memcpy(rx, qx, 30);
memcpy(ry, qy, 30);
return;
}
if (checkZero(p) && checkZero(p + 30))
{
memcpy(rx, px, 30);
memcpy(ry, py, 30);
return;
}
add(u, px, qx);
if (checkZero(u))
{
add(u, py, qy);
if (checkZero(u))
pointDouble(r, p);
else
{
memset(rx, 0, 30);
memset(ry, 0, 30);
}
return;
}
invert(t, u);
add(u, py, qy);
multiply(s, t, u);
square(t, s);
add(t, t, s);
add(t, t, qx);
t[29] ^= 1;
multiply(u, s, t);
add(s, u, py);
add(rx, t, px);
add(ry, s, rx);
}
static void pointMultiply(atUint8* d, const atUint8* a, const atUint8* b)
{
memset(d, 0, 30);
memset(d + 30, 0, 30);
for (atUint32 i = 0; i < 30; i++)
{
for (atUint8 mask = 0x80; mask != 0; mask >>= 1)
{
pointDouble(d, d);
if ((a[i] & mask) != 0)
pointAdd(d, d, b);
}
}
}
static const atUint8 ecG[60] = {0x00, 0xfa, 0xc9, 0xdf, 0xcb, 0xac, 0x83, 0x13, 0xbb, 0x21, 0x39, 0xf1,
0xbb, 0x75, 0x5f, 0xef, 0x65, 0xbc, 0x39, 0x1f, 0x8b, 0x36, 0xf8, 0xf8,
0xeb, 0x73, 0x71, 0xfd, 0x55, 0x8b, 0x01, 0x00, 0x6a, 0x08, 0xa4, 0x19,
0x03, 0x35, 0x06, 0x78, 0xe5, 0x85, 0x28, 0xbe, 0xbf, 0x8a, 0x0b, 0xef,
0xf8, 0x67, 0xa7, 0xca, 0x36, 0x71, 0x6f, 0x7e, 0x01, 0xf8, 0x10, 0x52};
static const atUint8 ecN[30] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xe9, 0x74, 0xe7, 0x2f,
0x8a, 0x69, 0x22, 0x03, 0x1d, 0x26, 0x03, 0xcf, 0xe0, 0xd7};
bool checkECDSA(atUint8* Q, atUint8* R, atUint8* S, atUint8* hash)
{
atUint8 Sinv[30];
atUint8 e[30];
atUint8 w1[30], w2[30];
atUint8 r1[60], r2[60];
bignum::inv(Sinv, S, ecN, 30);
memset(e, 0, 30);
memcpy(e + 10, hash, 20);
bignum::mul(w1, e, Sinv, ecN, 30);
bignum::mul(w2, R, Sinv, ecN, 30);
pointMultiply(r1, w1, ecG);
pointMultiply(r2, w2, Q);
pointAdd(r1, r1, r2);
if (bignum::compare(r1, ecN, 30) >= 0)
bignum::subModulus(r1, ecN, 30);
return (bignum::compare(r1, R, 30) == 0);
}
void makeECCert(atUint8* cert, atUint8* sig, const char* signer, const char* name, atUint8* priv, atUint32 keyId)
{
memset(cert, 0, 0x180);
*(atUint32*)(cert) = 0x10002;
if (!athena::utility::isSystemBigEndian())
*(atUint32*)(cert) = athena::utility::swapU32(*(atUint32*)(cert));
memcpy((char*)cert + 4, sig, 60);
strcpy((char*)cert + 0x80, signer);
*(atUint32*)(cert + 0xc0) = 2;
if (!athena::utility::isSystemBigEndian())
*(atUint32*)(cert + 0xc0) = athena::utility::swapU32(*(atUint32*)(cert + 0xc0));
strcpy((char*)cert + 0xc4, name);
*(atUint32*)(cert + 0x104) = keyId;
if (!athena::utility::isSystemBigEndian())
*(atUint32*)(cert + 0x104) = athena::utility::swapU32(*(atUint32*)(cert + 0x104));
pointMultiply(cert + 0x108, priv, ecG);
}
void createECDSA(atUint8* R, atUint8* S, atUint8* k, atUint8* hash)
{
atUint8 e[30];
atUint8 kk[30];
atUint8 m[30];
atUint8 minv[30];
atUint8 mG[60];
memset(e, 0, 30);
memcpy(e + 10, hash, 20);
athena::utility::fillRandom(m, sizeof(m));
m[0] = 0;
pointMultiply(mG, m, ecG);
memcpy(R, mG, 30);
if (bignum::compare(R, ecN, 30) >= 0)
bignum::subModulus(R, ecN, 30);
memcpy(kk, k, 30);
if (bignum::compare(kk, ecN, 30) >= 0)
bignum::subModulus(kk, ecN, 30);
bignum::mul(S, R, kk, ecN, 30);
bignum::add(kk, S, e, ecN, 30);
bignum::inv(minv, m, ecN, 30);
bignum::mul(S, minv, kk, ecN, 30);
}
void checkEC(atUint8* ng, atUint8* ap, atUint8* sig, atUint8* sigHash, bool& apValid, bool& ngValid)
{
atUint8* apHash = getSha1(ap + 0x80, 0x100);
ngValid = checkECDSA(ng + 0x0108, ap + 0x04, ap + 0x22, apHash);
apValid = checkECDSA(ap + 0x0108, sig, sig + 30, sigHash);
}
}