diff --git a/.gitmodules b/.gitmodules index 4226383..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "easy-ecc"] - path = extern/easy-ecc - url = https://github.com/libAthena/easy-ecc.git diff --git a/AthenaConfig.cmake.in b/AthenaConfig.cmake.in index 7792c5e..6647cef 100644 --- a/AthenaConfig.cmake.in +++ b/AthenaConfig.cmake.in @@ -14,7 +14,7 @@ if(NOT TARGET AthenaCore AND NOT Athena_BINARY_DIR) endif() # 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 if(WIN32 AND NOT CYGWIN) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3c37b4..d314df9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(ATHENA_VERSION 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) 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/WiiSaveReader.cpp src/athena/WiiSaveWriter.cpp -# src/bn.cpp -# src/ec.cpp + src/bn.cpp + src/ec.cpp src/md5.cpp src/sha1.cpp src/aes.cpp @@ -116,8 +116,8 @@ add_library(athena-wiisave EXCLUDE_FROM_ALL include/athena/WiiSaveReader.hpp include/athena/WiiSaveWriter.hpp include/aes.hpp -# include/bn.h -# include/ec.h + include/bn.hpp + include/ec.hpp include/md5.h include/sha1.h ) @@ -156,6 +156,9 @@ add_library(athena-zelda EXCLUDE_FROM_ALL include/athena/SkywardSwordFileReader.hpp include/athena/SkywardSwordFileWriter.hpp include/athena/SkywardSwordQuest.hpp + include/athena/ZQuestFile.hpp + include/athena/ZQuestFileReader.hpp + include/athena/ZQuestFileWriter.hpp ) # Icon diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 4600c53..211f1c0 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -1,4 +1,3 @@ add_subdirectory(lzo) add_subdirectory(zlib) add_subdirectory(yaml) -add_subdirectory(easy-ecc) diff --git a/extern/easy-ecc b/extern/easy-ecc deleted file mode 160000 index da27485..0000000 --- a/extern/easy-ecc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit da2748507cbe429d3e1be918c54cfba3be06d4b2 diff --git a/include/athena/ALTTPFileReader.hpp b/include/athena/ALTTPFileReader.hpp index a256ad4..8a22193 100644 --- a/include/athena/ALTTPFileReader.hpp +++ b/include/athena/ALTTPFileReader.hpp @@ -21,8 +21,6 @@ namespace io */ class ALTTPFileReader : protected MemoryCopyReader { - MEMORYCOPYREADER_BASE(); - public: /*! \brief This constructor takes an existing buffer to read from. * diff --git a/include/athena/ALTTPFileWriter.hpp b/include/athena/ALTTPFileWriter.hpp index 65a80d5..eb1b3bb 100644 --- a/include/athena/ALTTPFileWriter.hpp +++ b/include/athena/ALTTPFileWriter.hpp @@ -20,8 +20,6 @@ namespace io */ class ALTTPFileWriter : protected MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); - public: /*! \brief This constructor takes an existing buffer to write to. * diff --git a/include/athena/Global.hpp b/include/athena/Global.hpp index ea7a792..d4a91e1 100644 --- a/include/athena/Global.hpp +++ b/include/athena/Global.hpp @@ -11,11 +11,11 @@ #include #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) #endif #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif #if !defined(S_ISLNK) @@ -29,7 +29,7 @@ #define PRISize "zu" #endif - +// clang-format off #ifndef AT_PRETTY_FUNCTION # if defined(__PRETTY_FUNCTION__) || defined(__GNUC__) # define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__ @@ -45,7 +45,7 @@ # define AT_PRETTY_FUNCTION "" # endif #endif - +// clang-format on #ifdef GEKKO #include "gekko_support.h" @@ -77,34 +77,34 @@ typedef struct stat64 atStat64_t; #define _STR(s) #s #ifndef ENABLE_BITWISE_ENUM -#define ENABLE_BITWISE_ENUM(type)\ -constexpr type operator|(type a, type b)\ -{\ - using T = std::underlying_type_t;\ - return type(static_cast(a) | static_cast(b));\ -}\ -constexpr type operator&(type a, type b)\ -{\ - using T = std::underlying_type_t;\ - return type(static_cast(a) & static_cast(b));\ -}\ -inline type& operator|=(type& a, const type& b)\ -{\ - using T = std::underlying_type_t;\ - a = type(static_cast(a) | static_cast(b));\ - return a;\ -}\ -inline type& operator&=(type& a, const type& b)\ -{\ - using T = std::underlying_type_t;\ - a = type(static_cast(a) & static_cast(b));\ - return a;\ -}\ -inline type operator~(const type& key)\ -{\ - using T = std::underlying_type_t;\ - return type(~static_cast(key));\ -} +#define ENABLE_BITWISE_ENUM(type) \ + constexpr type operator|(type a, type b) \ + { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) | static_cast(b)); \ + } \ + constexpr type operator&(type a, type b) \ + { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) & static_cast(b)); \ + } \ + inline type& operator|=(type& a, const type& b) \ + { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) | static_cast(b)); \ + return a; \ + } \ + inline type& operator&=(type& a, const type& b) \ + { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) & static_cast(b)); \ + return a; \ + } \ + inline type operator~(const type& key) \ + { \ + using T = std::underlying_type_t; \ + return type(~static_cast(key)); \ + } #endif namespace athena @@ -133,7 +133,8 @@ enum Endian }; } // 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(); /** @@ -147,73 +148,93 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian); #ifdef _MSC_VER #ifndef NDEBUG -#define atDebug(fmt, ...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ -} while(0) +#define atDebug(fmt, ...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ + } while (0) #else #define atDebug(fmt, ...) #endif -#define atMessage(fmt, ...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ -} while(0) +#define atMessage(fmt, ...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ + } while (0) -#define atWarning(fmt, ...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ -} while(0) +#define atWarning(fmt, ...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ + } while (0) -#define atError(fmt, ...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ -} while(0) +#define atError(fmt, ...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ + } while (0) -#define atFatal(fmt, ...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ -} while(0) +#define atFatal(fmt, ...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ + } while (0) #elif defined(__GNUC__) #ifndef NDEBUG -#define atDebug(fmt...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ -} while(0) +#define atDebug(fmt...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ + } while (0) #else // _MSC_VER #define atDebug(fmt, ...) #endif // NDEBUG -#define atMessage(fmt...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ -} while(0) +#define atMessage(fmt...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ + } while (0) -#define atWarning(fmt...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ -} while(0) +#define atWarning(fmt...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ + } while (0) -#define atError(fmt...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ -} while(0) +#define atError(fmt...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ + } while (0) -#define atFatal(fmt...) \ - do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ - if (__handler) \ - __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ -} while(0) +#define atFatal(fmt...) \ + do \ + { \ + atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ + if (__handler) \ + __handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ + } while (0) #endif // defined(__GNUC__) #endif // GLOBAL_HPP diff --git a/include/athena/MCFileReader.hpp b/include/athena/MCFileReader.hpp index a80c35d..dbac9ad 100644 --- a/include/athena/MCFileReader.hpp +++ b/include/athena/MCFileReader.hpp @@ -20,7 +20,6 @@ namespace io */ class MCFileReader : public MemoryCopyReader { - MEMORYCOPYREADER_BASE(); public: /*! * \brief This constructor takes an existing buffer to read from. diff --git a/include/athena/MCFileWriter.hpp b/include/athena/MCFileWriter.hpp index 023fc2e..0e2c0a1 100644 --- a/include/athena/MCFileWriter.hpp +++ b/include/athena/MCFileWriter.hpp @@ -21,7 +21,6 @@ namespace io */ class MCFileWriter : protected MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); public: /*! * \brief This constructor takes an existing buffer to write to. diff --git a/include/athena/MemoryReader.hpp b/include/athena/MemoryReader.hpp index e09c266..2390cc9 100644 --- a/include/athena/MemoryReader.hpp +++ b/include/athena/MemoryReader.hpp @@ -121,18 +121,5 @@ protected: } // io } // 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 diff --git a/include/athena/MemoryWriter.hpp b/include/athena/MemoryWriter.hpp index ee78102..669bc18 100644 --- a/include/athena/MemoryWriter.hpp +++ b/include/athena/MemoryWriter.hpp @@ -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 diff --git a/include/athena/SkywardSwordFileReader.hpp b/include/athena/SkywardSwordFileReader.hpp index 1b46f5c..f1c906e 100644 --- a/include/athena/SkywardSwordFileReader.hpp +++ b/include/athena/SkywardSwordFileReader.hpp @@ -10,9 +10,7 @@ namespace io { class SkywardSwordFileReader : public MemoryCopyReader { - MEMORYCOPYREADER_BASE(); public: - SkywardSwordFileReader(atUint8* data, atUint64 length); SkywardSwordFileReader(const std::string& filename); diff --git a/include/athena/SkywardSwordFileWriter.hpp b/include/athena/SkywardSwordFileWriter.hpp index 77c2ac8..fbe26c8 100644 --- a/include/athena/SkywardSwordFileWriter.hpp +++ b/include/athena/SkywardSwordFileWriter.hpp @@ -12,7 +12,6 @@ namespace io class SkywardSwordFileWriter : public MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); public: SkywardSwordFileWriter(atUint8* data, atUint64 len); SkywardSwordFileWriter(const std::string& filename); diff --git a/include/athena/SkywardSwordQuest.hpp b/include/athena/SkywardSwordQuest.hpp index c415834..618e69e 100644 --- a/include/athena/SkywardSwordQuest.hpp +++ b/include/athena/SkywardSwordQuest.hpp @@ -43,17 +43,16 @@ public: void setSkipData(std::unique_ptr&& data); atUint8* skipData() const; - atUint32 slotChecksum(); atUint32 skipChecksum(); void fixChecksums(); void setNew(bool isNew); bool isNew() const; + private: std::unique_ptr m_skipData; }; - } // Athena #endif // SSQUEST_HPP diff --git a/include/athena/Sprite.hpp b/include/athena/Sprite.hpp index a9e9d57..fa494fd 100644 --- a/include/athena/Sprite.hpp +++ b/include/athena/Sprite.hpp @@ -1,15 +1,8 @@ #ifndef SSPRITE_HPP #define SSPRITE_HPP -#ifndef ATHENA_USE_QT #include #include -#else -#include -#include -#include -#include -#endif #include "athena/SakuraGlobal.hpp" namespace athena @@ -19,35 +12,18 @@ namespace Sakura class SpriteFile; class SpriteFrame; -#ifndef ATHENA_USE_QT 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: Sprite(SpriteFile* root); Sprite(SpriteFile* root, const std::string& name); virtual ~Sprite(); virtual void setPosition(const float x, const float y); -#ifndef ATHENA_USE_QT virtual void setPosition(const Vector2Df& pos); virtual Vector2Df position() const; void setName(const std::string& name); 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); @@ -58,11 +34,7 @@ public: */ int stateId(int index) const; void setStateIds(std::vector ids); -#ifndef ATHENA_USE_QT std::vector stateIds() const; -#else - QList stateIds() const; -#endif atUint32 stateCount() const; void setCurrentState(atUint32 id); atUint32 currentState() const; @@ -71,18 +43,10 @@ public: bool removeFrame(SpriteFrame* Frame); SpriteFrame* Frame(atUint32 id); void setFrame(atUint32 id); -#ifndef ATHENA_USE_QT void setFrames(std::vector frames); -#else - void setFrames(QList frames); -#endif atUint32 frameCount() const; -#ifndef ATHENA_USE_QT std::vector frames() const; -#else - QList frames() const; -#endif SpriteFile* container() const; @@ -95,36 +59,17 @@ public: void setRoot(SpriteFile* root); SpriteFile* root() const; -#ifdef ATHENA_USE_QT -signals: - void frameChanged(SpriteFrame* frame); - void nameChanged(QString); - void stateChanged(quint32); -#endif private: - SpriteFile* m_root; -#ifndef ATHENA_USE_QT - std::string m_name; - Vector2Df m_position; - std::vector m_stateIds; //!< Stores the texture id's for each state. + SpriteFile* m_root; + std::string m_name; + Vector2Df m_position; + std::vector m_stateIds; //!< Stores the texture id's for each state. std::vector m_frames; -#else - QString m_name; - QPoint m_position; - QList m_stateIds; - QList m_frames; -#endif - atUint32 m_currentState; - atUint32 m_currentFrame; + atUint32 m_currentState; + atUint32 m_currentFrame; }; - } // Sakura } // zelda -#ifdef ATHENA_USE_QT -Q_DECLARE_METATYPE(Uint32) -Q_DECLARE_METATYPE(athena::Sakura::Sprite*) -#endif - #endif // SSPRITE_HPP diff --git a/include/athena/SpriteFile.hpp b/include/athena/SpriteFile.hpp index b383152..bf8ffe7 100644 --- a/include/athena/SpriteFile.hpp +++ b/include/athena/SpriteFile.hpp @@ -1,16 +1,8 @@ #ifndef SSPRITEFILE_HPP #define SSPRITEFILE_HPP -#ifndef ATHENA_USE_QT #include #include -#else -#include -#include -#include -#include -#include -#endif #include #include "athena/SakuraGlobal.hpp" @@ -26,14 +18,8 @@ struct STexture }; class Sprite; -#ifndef ATHENA_USE_QT class SpriteFile { -#else -class SpriteFile : public QObject -{ - Q_OBJECT -#endif public: /*! * \brief Major @@ -109,21 +95,13 @@ public slots: * \brief setSize * \param size */ -#ifndef ATHENA_USE_QT void setSize(const Vector2Di& size); -#else - void setSize(const QSize& size); -#endif /*! * \brief size * \return */ -#ifndef ATHENA_USE_QT Vector2Di size() const; -#else - QSize size() const; -#endif /*! * \brief width @@ -148,21 +126,13 @@ public slots: * \brief setOrigin * \param origin */ -#ifndef ATHENA_USE_QT void setOrigin(const Vector2Df& origin); -#else - void setOrigin(const QPoint& origin); -#endif /*! * \brief origin * \return */ -#ifndef ATHENA_USE_QT Vector2Df origin() const; -#else - QPoint origin() const; -#endif /*! @@ -195,71 +165,33 @@ public slots: * \return */ STexture* texture(atUint32 id); - -#ifndef ATHENA_USE_QT std::vector textures() const; -#else - QList textures() const; -#endif + atUint32 textureCount() const; /*! * \brief setTextures * \param textures */ - -#ifndef ATHENA_USE_QT void setTextures(std::vector textures); -#else - void setTextures(QList textures); -#endif void addSprite(Sprite* sprite); -#ifndef ATHENA_USE_QT void removeSprite(const std::string& name); -#else - void removeSprite(const QString& name); -#endif void removeSprite(Sprite* sprite); -#ifndef ATHENA_USE_QT void setSprites(std::unordered_map sprites); -#else - void setSprites(QMap sprites); -#endif -#ifndef ATHENA_USE_QT Sprite* sprite(const std::string& name); std::unordered_map sprites() const; -#else - Sprite* sprite(const QString& name); - QMap sprites() const; -#endif atUint32 spriteCount() const; -#ifdef ATHENA_USE_QT -signals: - void originChanged(QPoint); - void sizeChanged(QSize); -#endif private: -#ifndef ATHENA_USE_QT std::vector m_textures; Vector2Di m_size; Vector2Df m_origin; std::unordered_map m_sprites; -#else - QList m_textures; - QSize m_size; - QPoint m_origin; - QMap m_sprites; -#endif }; } // Sakura } // Zelda -#ifdef ATHENA_USE_QT -Q_DECLARE_METATYPE(athena::Sakura::SpriteFile*) -Q_DECLARE_METATYPE(athena::Sakura::STexture*) -#endif #endif // SSPRITE_HPP diff --git a/include/athena/SpriteFileReader.hpp b/include/athena/SpriteFileReader.hpp index 071b462..c98adab 100644 --- a/include/athena/SpriteFileReader.hpp +++ b/include/athena/SpriteFileReader.hpp @@ -15,7 +15,6 @@ namespace io class SpriteFileReader : public MemoryCopyReader { - MEMORYCOPYREADER_BASE(); public: SpriteFileReader(atUint8* data, atUint64 length); SpriteFileReader(const std::string& filepath); diff --git a/include/athena/SpriteFileWriter.hpp b/include/athena/SpriteFileWriter.hpp index 9f174bd..db8c3cd 100644 --- a/include/athena/SpriteFileWriter.hpp +++ b/include/athena/SpriteFileWriter.hpp @@ -15,7 +15,6 @@ namespace io class SpriteFileWriter : public MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); public: SpriteFileWriter(atUint8* data, atUint64 length); diff --git a/include/athena/SpriteFrame.hpp b/include/athena/SpriteFrame.hpp index 965741e..c22d605 100644 --- a/include/athena/SpriteFrame.hpp +++ b/include/athena/SpriteFrame.hpp @@ -4,13 +4,7 @@ #include "athena/SakuraGlobal.hpp" -#ifndef ATHENA_USE_QT #include -#else -#include -#include -#endif - namespace athena { namespace Sakura @@ -19,15 +13,8 @@ namespace Sakura class Sprite; class SpritePart; -#ifndef ATHENA_USE_QT class SpriteFrame { -#else -class SpriteFrame : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal frameTime READ frameTime WRITE setFrameTime) -#endif public: /*! * \brief SSpriteFrame @@ -48,37 +35,20 @@ public: */ float frameTime() const; -#ifndef ATHENA_USE_QT void setParts(std::vector parts); std::vector parts() const; -#else - void setParts(QList parts); - QList parts() const; -#endif atUint32 partCount() const; void setRoot(Sprite* root); Sprite* root() const; -#ifdef ATHENA_USE_QT -signals: - void frameTimeChanged(float); -#endif private: Sprite* m_root; float m_frameTime; -#ifndef ATHENA_USE_QT std::vector m_parts; -#else - QList m_parts; -#endif }; } // Sakura } // zelda -#ifdef ATHENA_USE_QT -Q_DECLARE_METATYPE(athena::Sakura::SpriteFrame*); -#endif - #endif // SSPRITEFRAME_HPP diff --git a/include/athena/SpritePart.hpp b/include/athena/SpritePart.hpp index 0b84d54..93aa34a 100644 --- a/include/athena/SpritePart.hpp +++ b/include/athena/SpritePart.hpp @@ -2,14 +2,7 @@ #define SSPRITEPART_HPP #include "athena/SakuraGlobal.hpp" -#ifndef ATHENA_USE_QT -# include -#else -# include -# include -# include -# include -#endif +#include #include @@ -19,35 +12,15 @@ namespace Sakura { class SpriteFrame; -#ifndef ATHENA_USE_QT 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: SpritePart(SpriteFrame* root); SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false); virtual ~SpritePart(); - -#ifndef ATHENA_USE_QT void setName(const std::string& name); std::string name() const; -#else - void setName(const QString& name); - QString name() const; -#endif - void setCollision(bool col); bool hasCollision() const; @@ -57,26 +30,13 @@ public: * \param y */ void setOffset(float x, float y); - - /*! - * \brief setOffset - * \param offset - */ -#ifndef ATHENA_USE_QT void setOffset(const Vector2Df& offset); -#else - void setOffset(const QPoint& offset); -#endif /*! * \brief offset * \return */ -#ifndef ATHENA_USE_QT Vector2Df offset() const; -#else - QPoint offset() const; -#endif /*! * \brief setTextureOffset @@ -89,22 +49,13 @@ public: * \brief setTextureOffset * \param texOff */ -#ifndef ATHENA_USE_QT void setTextureOffset(const Vector2Df& offset); -#else - void setTextureOffset(const QPoint& offset); -#endif - /*! - * \brief textureOffset - * \return - */ -#ifndef ATHENA_USE_QT +/*! + * \brief textureOffset + * \return + */ Vector2Df textureOffset() const; -#else - QPoint textureOffset() const; -#endif - /*! * \brief setSize * \param width @@ -112,25 +63,16 @@ public: */ void setSize(atUint32 width, atUint32 height); - /*! - * \brief setSize - * \param size - */ -#ifndef ATHENA_USE_QT +/*! + * \brief setSize + * \param size + */ void setSize(const Vector2Di& size); -#else - void setSize(const QSize& size); -#endif - - /*! - * \brief size - * \return - */ -#ifndef ATHENA_USE_QT +/*! + * \brief size + * \return + */ Vector2Di size() const; -#else - QSize size() const; -#endif /*! * \brief setFlippedHorizontally @@ -159,42 +101,19 @@ public: void setRoot(SpriteFrame* root); 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: - SpriteFrame* m_root; -#ifndef ATHENA_USE_QT - std::string m_name; -#else - QString m_name; -#endif - bool m_hasCollision; -#ifndef ATHENA_USE_QT - Vector2Df m_offset; - Vector2Df m_textureOffset; - Vector2Di m_size; -#else - QPoint m_offset; - QPoint m_textureOffset; - QSize m_size; -#endif - bool m_flippedH; - bool m_flippedV; - atUint32 m_frameIndex; + SpriteFrame* m_root; + std::string m_name; + bool m_hasCollision; + Vector2Df m_offset; + Vector2Df m_textureOffset; + Vector2Di m_size; + bool m_flippedH; + bool m_flippedV; + atUint32 m_frameIndex; }; - } } -#ifdef ATHENA_USE_QT -Q_DECLARE_METATYPE(athena::Sakura::SpritePart*) -#endif #endif // SSPRITEPART_HPP diff --git a/include/athena/WiiSaveReader.hpp b/include/athena/WiiSaveReader.hpp index 1c15242..a5da129 100644 --- a/include/athena/WiiSaveReader.hpp +++ b/include/athena/WiiSaveReader.hpp @@ -21,9 +21,8 @@ namespace io * all work is done using a memory buffer, and not read directly from the disk. * \sa BinaryReader */ -class WiiSaveReader : protected MemoryCopyReader +class WiiSaveReader : public MemoryCopyReader { - MEMORYCOPYREADER_BASE(); public: /*! \brief This constructor takes an existing buffer to read from. * diff --git a/include/athena/WiiSaveWriter.hpp b/include/athena/WiiSaveWriter.hpp index db4e43d..07c340c 100644 --- a/include/athena/WiiSaveWriter.hpp +++ b/include/athena/WiiSaveWriter.hpp @@ -22,7 +22,6 @@ namespace io */ class WiiSaveWriter : protected MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); public: /*! \brief This constructor creates an instance from a file on disk. * diff --git a/include/athena/ZQuestFile.hpp b/include/athena/ZQuestFile.hpp index 8c87fdb..07944e8 100644 --- a/include/athena/ZQuestFile.hpp +++ b/include/athena/ZQuestFile.hpp @@ -1,19 +1,4 @@ #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 - #ifndef ZQUEST_HPP #define ZQUEST_HPP diff --git a/include/athena/ZQuestFileReader.hpp b/include/athena/ZQuestFileReader.hpp index 273d6fd..24431d8 100644 --- a/include/athena/ZQuestFileReader.hpp +++ b/include/athena/ZQuestFileReader.hpp @@ -1,19 +1,4 @@ #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 - #ifndef __ZQUESTFILEREADER_HPP__ #define __ZQUESTFILEREADER_HPP__ @@ -31,7 +16,6 @@ namespace io */ class ZQuestFileReader : protected MemoryCopyReader { - MEMORYCOPYREADER_BASE(); public: /*! diff --git a/include/athena/ZQuestFileWriter.hpp b/include/athena/ZQuestFileWriter.hpp index e33a424..7c09fb1 100644 --- a/include/athena/ZQuestFileWriter.hpp +++ b/include/athena/ZQuestFileWriter.hpp @@ -1,19 +1,4 @@ #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 - #ifndef __ZQUESTFILEWRITER_HPP__ #define __ZQUESTFILEWRITER_HPP__ @@ -31,8 +16,6 @@ namespace io */ class ZQuestFileWriter : protected MemoryCopyWriter { - MEMORYCOPYWRITER_BASE(); - public: /*! * \brief ZQuestFileWriter diff --git a/include/bn.hpp b/include/bn.hpp new file mode 100644 index 0000000..a3c1d43 --- /dev/null +++ b/include/bn.hpp @@ -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 diff --git a/include/ec.hpp b/include/ec.hpp new file mode 100644 index 0000000..8a9b42c --- /dev/null +++ b/include/ec.hpp @@ -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 + diff --git a/libAthena.pc.in b/libAthena.pc.in index ec5d727..97704ca 100644 --- a/libAthena.pc.in +++ b/libAthena.pc.in @@ -6,5 +6,5 @@ Name: libAthena Description: Basic cross platform IO library Version: @ATHENA_VERSION@ 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 diff --git a/src/athena/ALTTPFileReader.cpp b/src/athena/ALTTPFileReader.cpp index 8d4068a..f8a1cc8 100644 --- a/src/athena/ALTTPFileReader.cpp +++ b/src/athena/ALTTPFileReader.cpp @@ -10,12 +10,12 @@ namespace io { ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyReader(data, length) { } ALTTPFileReader::ALTTPFileReader(const std::string& filename) - : base(filename) + : MemoryCopyReader(filename) { } @@ -52,22 +52,22 @@ ALTTPFile* ALTTPFileReader::readFile() quest->setOverworldEvents(owEvents); - quest->setInventory(*(ALTTPInventory*)base::readBytes(sizeof(ALTTPInventory)).get()); - quest->setRupeeMax(base::readUint16()); - quest->setRupeeCurrent(base::readUint16()); + quest->setInventory(*(ALTTPInventory*)readBytes(sizeof(ALTTPInventory)).get()); + quest->setRupeeMax(readUint16()); + quest->setRupeeCurrent(readUint16()); quest->setCompasses(readDungeonFlags()); quest->setBigKeys(readDungeonFlags()); quest->setDungeonMaps(readDungeonFlags()); - quest->setWishingPond(base::readUint16()); - quest->setHealthMax(base::readByte()); - quest->setHealth(base::readByte()); - quest->setMagicPower(base::readByte()); - quest->setKeys(base::readByte()); - quest->setBombUpgrades(base::readByte()); - quest->setArrowUpgrades(base::readByte()); - quest->setHealthFiller(base::readByte()); - quest->setMagicFiller(base::readByte()); - atUint8 pendantsByte = base::readUByte(); + quest->setWishingPond(readUint16()); + quest->setHealthMax(readByte()); + quest->setHealth(readByte()); + quest->setMagicPower(readByte()); + quest->setKeys(readByte()); + quest->setBombUpgrades(readByte()); + quest->setArrowUpgrades(readByte()); + quest->setHealthFiller(readByte()); + quest->setMagicFiller(readByte()); + atUint8 pendantsByte = readUByte(); ALTTPPendants pendants; pendants.Courage = pendantsByte & 1; pendants.Wisdom = (pendantsByte >> 1) & 1; @@ -78,11 +78,11 @@ ALTTPFile* ALTTPFileReader::readFile() pendants.Unused4 = false; pendants.Unused5 = false; quest->setPendants(pendants); - quest->setBombFiller(base::readByte()); - quest->setArrowFiller(base::readByte()); - quest->setArrows(base::readByte()); - base::seek(1); - atUint8 abilitiesByte = base::readUByte(); + quest->setBombFiller(readByte()); + quest->setArrowFiller(readByte()); + quest->setArrows(readByte()); + seek(1); + atUint8 abilitiesByte = readUByte(); ALTTPAbilities abilities; abilities.Nothing = abilitiesByte & 1; abilities.Swim = (abilitiesByte >> 1) & 1; @@ -93,42 +93,42 @@ ALTTPFile* ALTTPFileReader::readFile() abilities.Read = (abilitiesByte >> 6) & 1; abilities.Unknown2 = (abilitiesByte >> 7) & 1; quest->setAbilityFlags(abilities); - quest->setCrystals(*(ALTTPCrystals*)base::readBytes(sizeof(ALTTPCrystals)).get()); - quest->setMagicUsage(*(ALTTPMagicUsage*)base::readBytes(sizeof(ALTTPMagicUsage)).get()); + quest->setCrystals(*(ALTTPCrystals*)readBytes(sizeof(ALTTPCrystals)).get()); + quest->setMagicUsage(*(ALTTPMagicUsage*)readBytes(sizeof(ALTTPMagicUsage)).get()); j = 0x10; while ((j--) > 0) { - dungeonKeys.push_back(base::readByte()); + dungeonKeys.push_back(readByte()); } quest->setDungeonKeys(dungeonKeys); - base::seek(0x039); - quest->setProgressIndicator((ALTTPProgressIndicator)base::readByte()); - quest->setProgressFlags1(*(ALTTPProgressFlags1*)base::readBytes(sizeof(ALTTPProgressFlags1)).get()); - quest->setMapIcon((ALTTPMapIcon)base::readByte()); - quest->setStartLocation((ALTTPStartLocation)base::readByte()); - quest->setProgressFlags2(*(ALTTPProgressFlags2*)base::readBytes(sizeof(ALTTPProgressFlags2)).get()); - quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)base::readBytes(1).get()); - base::seek(1); - quest->setTagAlong((ALTTPTagAlong)base::readByte()); + seek(0x039); + quest->setProgressIndicator((ALTTPProgressIndicator)readByte()); + quest->setProgressFlags1(*(ALTTPProgressFlags1*)readBytes(sizeof(ALTTPProgressFlags1)).get()); + quest->setMapIcon((ALTTPMapIcon)readByte()); + quest->setStartLocation((ALTTPStartLocation)readByte()); + quest->setProgressFlags2(*(ALTTPProgressFlags2*)readBytes(sizeof(ALTTPProgressFlags2)).get()); + quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)readBytes(1).get()); + seek(1); + quest->setTagAlong((ALTTPTagAlong)readByte()); j = 6; while ((j--) > 0) { - oldmanFlags.push_back(base::readByte()); + oldmanFlags.push_back(readByte()); } quest->setOldManFlags(oldmanFlags); - quest->setBombFlag(base::readByte()); + quest->setBombFlag(readByte()); j = 5; while ((j--) > 0) { - unknown1.push_back(base::readByte()); + unknown1.push_back(readByte()); } quest->setUnknown1(unknown1); @@ -137,28 +137,28 @@ ALTTPFile* ALTTPFileReader::readFile() while ((j--) > 0) { - playerName.push_back(base::readUint16()); + playerName.push_back(readUint16()); } quest->setPlayerName(playerName); - quest->setValid((base::readUint16() == 0x55AA)); + quest->setValid((readUint16() == 0x55AA)); j = 0x0D; while ((j--) > 0) { - dungeonDeaths.push_back(base::readUint16()); + dungeonDeaths.push_back(readUint16()); } quest->setDungeonDeathTotals(dungeonDeaths); - quest->setUnknown2(base::readUint16()); - quest->setDeathSaveCount(base::readUint16()); - quest->setPostGameDeathCounter(base::readInt16()); + quest->setUnknown2(readUint16()); + quest->setDeathSaveCount(readUint16()); + quest->setPostGameDeathCounter(readInt16()); - base::seek(0xF7); + seek(0xF7); - quest->setChecksum(base::readUint16()); + quest->setChecksum(readUint16()); if (i < 3) quests.push_back(quest); @@ -172,7 +172,7 @@ ALTTPFile* ALTTPFileReader::readFile() ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() { ALTTPRoomFlags* flags = new ALTTPRoomFlags; - atUint8 flagsByte = base::readUByte(); + atUint8 flagsByte = readUByte(); flags->Chest1 = flagsByte & 1; flags->Chest2 = (flagsByte >> 1) & 1; flags->Chest3 = (flagsByte >> 2) & 1; @@ -181,7 +181,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() flags->Quadrant2 = (flagsByte >> 5) & 1; flags->Quadrant3 = (flagsByte >> 6) & 1; flags->Quadrant4 = (flagsByte >> 7) & 1; - flagsByte = base::readUByte(); + flagsByte = readUByte(); flags->Door1 = flagsByte & 1; flags->Door2 = (flagsByte >> 1) & 1; flags->Door3 = (flagsByte >> 2) & 1; @@ -197,7 +197,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent() { ALTTPOverworldEvent* event = new ALTTPOverworldEvent; - atUint8 flagsByte = base::readUByte(); + atUint8 flagsByte = readUByte(); event->Unused1 = flagsByte & 1; event->HeartPiece = (flagsByte >> 1) & 1; event->Overlay = (flagsByte >> 2) & 1; @@ -212,7 +212,7 @@ ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent() ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() { ALTTPDungeonItemFlags flags; - atUint8 flagsByte = base::readUByte(); + atUint8 flagsByte = readUByte(); flags.Unused1 = flagsByte & 1; flags.Unused2 = (flagsByte >> 1) & 1; flags.GanonsTower = (flagsByte >> 2) & 1; @@ -221,7 +221,7 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() flags.TowerOfHera = (flagsByte >> 5) & 1; flags.IcePalace = (flagsByte >> 6) & 1; flags.SkullWoods = (flagsByte >> 7) & 1; - flagsByte = base::readUByte(); + flagsByte = readUByte(); flags.MiseryMire = flagsByte & 1; flags.DarkPalace = (flagsByte >> 1) & 1; flags.SwampPalace = (flagsByte >> 2) & 1; diff --git a/src/athena/ALTTPFileWriter.cpp b/src/athena/ALTTPFileWriter.cpp index a555e35..10f68d1 100644 --- a/src/athena/ALTTPFileWriter.cpp +++ b/src/athena/ALTTPFileWriter.cpp @@ -10,12 +10,12 @@ namespace io { ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyWriter(data, length) { } ALTTPFileWriter::ALTTPFileWriter(const std::string& filename) - : base(filename) + : MemoryCopyWriter(filename) { } @@ -40,31 +40,31 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) writeOverworldEvent(quest->overworldEvent(j)); } - base::writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory)); - base::writeUint16(quest->rupeeMax()); - base::writeUint16(quest->rupeeCurrent()); + writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory)); + writeUint16(quest->rupeeMax()); + writeUint16(quest->rupeeCurrent()); writeDungeonItems(quest->compasses()); writeDungeonItems(quest->bigKeys()); writeDungeonItems(quest->dungeonMaps()); - base::writeUint16(quest->wishingPond()); - base::writeByte(quest->healthMax()); - base::writeByte(quest->health()); - base::writeByte(quest->magicPower()); - base::writeByte(quest->keys()); - base::writeByte(quest->bombUpgrades()); - base::writeByte(quest->arrowUpgrades()); - base::writeByte(quest->healthFiller()); - base::writeByte(quest->magicFiller()); + writeUint16(quest->wishingPond()); + writeByte(quest->healthMax()); + writeByte(quest->health()); + writeByte(quest->magicPower()); + writeByte(quest->keys()); + writeByte(quest->bombUpgrades()); + writeByte(quest->arrowUpgrades()); + writeByte(quest->healthFiller()); + writeByte(quest->magicFiller()); ALTTPPendants pendants = quest->pendants(); atUint8 pendantsByte = 0; pendantsByte |= pendants.Courage; pendantsByte |= pendants.Wisdom << 1; pendantsByte |= pendants.Power << 2; - base::writeUByte(pendantsByte); - base::writeByte(quest->bombFiller()); - base::writeByte(quest->arrowFiller()); - base::writeByte(quest->arrows()); - base::seek(1); + writeUByte(pendantsByte); + writeByte(quest->bombFiller()); + writeByte(quest->arrowFiller()); + writeByte(quest->arrows()); + seek(1); ALTTPAbilities abilities = quest->abilityFlags(); atUint8 abilitiesByte = 0; abilitiesByte |= abilities.Nothing; @@ -75,51 +75,51 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) abilitiesByte |= abilities.Talk << 5; abilitiesByte |= abilities.Read << 6; abilitiesByte |= abilities.Unknown2 << 7; - base::writeUByte(abilitiesByte); + writeUByte(abilitiesByte); ALTTPCrystals crystals = quest->crystals(); - base::writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals)); + writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals)); ALTTPMagicUsage magicUsage = quest->magicUsage(); - base::writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage)); + writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage)); for (int j = 0; j < 0x010; j++) - base::writeByte(quest->dungeonKeys(j)); + writeByte(quest->dungeonKeys(j)); - base::seek(0x039); - base::writeByte((atInt8)quest->progressIndicator()); + seek(0x039); + writeByte((atInt8)quest->progressIndicator()); ALTTPProgressFlags1 progress1 = quest->progressFlags1(); - base::writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1)); - base::writeByte(quest->mapIcon()); - base::writeByte(quest->startLocation()); + writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1)); + writeByte(quest->mapIcon()); + writeByte(quest->startLocation()); ALTTPProgressFlags2 progress2 = quest->progressFlags2(); - base::writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2)); + writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2)); ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator(); - base::writeBytes((atInt8*)&indicator, 1); - base::seek(1); - base::writeByte(quest->tagAlong()); + writeBytes((atInt8*)&indicator, 1); + seek(1); + writeByte(quest->tagAlong()); 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++) - base::writeByte(quest->unknown1(j)); + writeByte(quest->unknown1(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++) - base::writeUint16(quest->dungeonDeathTotal(j)); + writeUint16(quest->dungeonDeathTotal(j)); - base::writeUint16(quest->unknown2()); - base::writeUint16(quest->deathSaveCount()); - base::writeUint16(quest->postGameDeathCounter()); + writeUint16(quest->unknown2()); + writeUint16(quest->deathSaveCount()); + writeUint16(quest->postGameDeathCounter()); - base::seek(0xF7); - base::writeUint16(calculateChecksum(i)); + seek(0xF7); + writeUint16(calculateChecksum(i)); } } @@ -134,7 +134,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags) flagsByte |= flags->Quadrant2 << 5; flagsByte |= flags->Quadrant3 << 6; flagsByte |= flags->Quadrant4 << 7; - base::writeUByte(flagsByte); + writeUByte(flagsByte); flagsByte = 0; flagsByte |= flags->Door1; flagsByte |= flags->Door2 << 1; @@ -144,7 +144,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags) flagsByte |= flags->Key << 5; flagsByte |= flags->KeyOrChest << 6; flagsByte |= flags->ChestOrTile << 7; - base::writeUByte(flagsByte); + writeUByte(flagsByte); } void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event) @@ -158,7 +158,7 @@ void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event) flagsByte |= event->Unused4 << 5; flagsByte |= event->Set << 6; flagsByte |= event->Unused5 << 7; - base::writeUByte(flagsByte); + writeUByte(flagsByte); } void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) @@ -172,7 +172,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) flagsByte |= flags.IcePalace << 5; flagsByte |= flags.SkullWoods << 6; flagsByte |= flags.MiseryMire << 7; - base::writeUByte(flagsByte); + writeUByte(flagsByte); flagsByte = 0; flagsByte |= flags.DarkPalace; flagsByte |= flags.SwampPalace << 1; @@ -181,7 +181,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) flagsByte |= flags.EasternPalace << 4; flagsByte |= flags.HyruleCastle << 5; flagsByte |= flags.SewerPassage << 6; - base::writeUByte(flagsByte); + writeUByte(flagsByte); } atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game) diff --git a/src/athena/MCFileReader.cpp b/src/athena/MCFileReader.cpp index 43eb862..b8f93ea 100644 --- a/src/athena/MCFileReader.cpp +++ b/src/athena/MCFileReader.cpp @@ -8,22 +8,22 @@ namespace io static const atUint32 SCRAMBLE_VALUE = 0x5A424741; MCFileReader::MCFileReader(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyReader(data, length) { } MCFileReader::MCFileReader(const std::string& filename) - : base(filename) + : MemoryCopyReader(filename) { } MCFile* MCFileReader::readFile() { - bool isScrambled = base::readUint32() != SCRAMBLE_VALUE; - base::m_position = 0; + bool isScrambled = readUint32() != SCRAMBLE_VALUE; + m_position = 0; if (isScrambled) - MCFile::unscramble(base::m_dataCopy.get(), base::m_length); + MCFile::unscramble(m_dataCopy.get(), m_length); return nullptr; } diff --git a/src/athena/MCFileWriter.cpp b/src/athena/MCFileWriter.cpp index 968084f..d579daa 100644 --- a/src/athena/MCFileWriter.cpp +++ b/src/athena/MCFileWriter.cpp @@ -6,12 +6,12 @@ namespace io { MCFileWriter::MCFileWriter(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyWriter(data, length) { } MCFileWriter::MCFileWriter(const std::string& filename) - : base(filename) + : MemoryCopyWriter(filename) { } diff --git a/src/athena/SkywardSwordFileReader.cpp b/src/athena/SkywardSwordFileReader.cpp index 9a65489..1727ae3 100644 --- a/src/athena/SkywardSwordFileReader.cpp +++ b/src/athena/SkywardSwordFileReader.cpp @@ -9,28 +9,28 @@ namespace io { 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) - : base(filename) + : MemoryCopyReader(filename) { - base::setEndian(Endian::BigEndian); + setEndian(Endian::BigEndian); } SkywardSwordFile* SkywardSwordFileReader::read() { SkywardSwordFile* file = NULL; - if (base::length() != 0xFBE0) + if (length() != 0xFBE0) { atError("File not the expected size of 0xFBE0"); return nullptr; } - atUint32 magic = base::readUint32(); + atUint32 magic = readUint32(); if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic) { @@ -38,8 +38,8 @@ SkywardSwordFile* SkywardSwordFileReader::read() return nullptr; } - base::seek(0x01C, SeekOrigin::Begin); - atUint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1) + seek(0x01C, SeekOrigin::Begin); + atUint32 headerSize = readUint32(); // Seems to be (headerSize - 1) if (headerSize != 0x1D) { @@ -53,12 +53,12 @@ SkywardSwordFile* SkywardSwordFileReader::read() for (int i = 0; i < 3; i++) { - SkywardSwordQuest* q = new SkywardSwordQuest(base::readUBytes(0x53C0), 0x53C0); - atUint64 pos = base::position(); + SkywardSwordQuest* q = new SkywardSwordQuest(readUBytes(0x53C0), 0x53C0); + atUint64 pos = position(); // seek to the skip data for this particular quest - base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); - q->setSkipData(base::readUBytes(0x24)); - base::seek(pos, SeekOrigin::Begin); + seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); + q->setSkipData(readUBytes(0x24)); + seek(pos, SeekOrigin::Begin); file->addQuest(q); } diff --git a/src/athena/SkywardSwordFileWriter.cpp b/src/athena/SkywardSwordFileWriter.cpp index 9d5d869..aefdf09 100644 --- a/src/athena/SkywardSwordFileWriter.cpp +++ b/src/athena/SkywardSwordFileWriter.cpp @@ -8,15 +8,15 @@ namespace io { 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) - : base(filename) + : MemoryCopyWriter(filename) { - base::setEndian(Endian::BigEndian); + setEndian(Endian::BigEndian); } void SkywardSwordFileWriter::write(SkywardSwordFile* file) @@ -30,9 +30,9 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file) atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic : (file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic)); - base::writeUint32(magic); - base::seek(0x1C, SeekOrigin::Begin); - base::writeUint32(0x1D); + writeUint32(magic); + seek(0x1C, SeekOrigin::Begin); + writeUint32(0x1D); std::vector quests = file->questList(); int i = 0; @@ -48,17 +48,17 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file) // Update the checksums q->fixChecksums(); // Write the save data - base::writeUBytes(q->data(), q->length()); - atUint64 pos = base::position(); + writeUBytes(q->data(), q->length()); + atUint64 pos = position(); // Write the slots skip data - base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); - base::writeUBytes(q->skipData(), 0x24); - base::seek(pos, SeekOrigin::Begin); + seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); + writeUBytes(q->skipData(), 0x24); + seek(pos, SeekOrigin::Begin); i++; } // write those padding bytes - base::seek(0xFBE0, SeekOrigin::Begin); + seek(0xFBE0, SeekOrigin::Begin); save(); } diff --git a/src/athena/Sprite.cpp b/src/athena/Sprite.cpp index 697aec2..d48844f 100644 --- a/src/athena/Sprite.cpp +++ b/src/athena/Sprite.cpp @@ -22,21 +22,12 @@ Sprite::Sprite(SpriteFile* root, const std::string& name) : m_root(root), m_currentState(0) { -#ifdef ATHENA_USE_QT - m_name = QString::fromStdString(name); -#else m_name = name; -#endif } Sprite::~Sprite() { -#ifndef ATHENA_USE_QT - for (SpriteFrame* frame : m_frames) -#else - foreach (SpriteFrame* frame, m_frames) -#endif { delete frame; frame = NULL; @@ -47,49 +38,25 @@ Sprite::~Sprite() void Sprite::setPosition(const float x, const float y) { -#ifndef ATHENA_USE_QT setPosition(Vector2Df(x, y)); -#else - setPosition(QPoint(x, y)); -#endif } -#ifndef ATHENA_USE_QT void Sprite::setPosition(const Vector2Df& pos) -#else -void Sprite::setPosition(const QPoint& pos) -#endif { m_position = pos; } -#ifndef ATHENA_USE_QT Vector2Df Sprite::position() const -#else -QPoint Sprite::position() const -#endif { return m_position; } -#ifndef ATHENA_USE_QT void Sprite::setName(const std::string& name) -#else -void Sprite::setName(const QString& name) -#endif { m_name = name; - -#ifdef ATHENA_USE_QT - emit nameChanged(name); -#endif } -#ifndef ATHENA_USE_QT std::string Sprite::name() const -#else -QString Sprite::name() const -#endif { return m_name; } @@ -116,18 +83,10 @@ void Sprite::setStateIds(std::vector ids) if (ids.size() == 0) return; -#ifndef ATHENA_USE_QT m_stateIds = ids; -#else - m_stateIds = QList::fromVector(QVector::fromStdVector(ids)); -#endif } -#ifndef ATHENA_USE_QT std::vector Sprite::stateIds() const -#else -QList Sprite::stateIds() const -#endif { return m_stateIds; } @@ -143,9 +102,6 @@ void Sprite::setCurrentState(const atUint32 id) return; m_currentState = id; -#ifdef ATHENA_USE_QT - emit stateChanged(id); -#endif } atUint32 Sprite::currentState() const @@ -170,7 +126,6 @@ bool Sprite::addFrame(SpriteFrame* part) bool Sprite::removeFrame(SpriteFrame* frame) { -#ifndef ATHENA_USE_QT std::vector::iterator iter = std::find(m_frames.begin(), m_frames.end(), frame); if (iter != m_frames.end()) @@ -178,13 +133,6 @@ bool Sprite::removeFrame(SpriteFrame* frame) m_frames.erase(iter); return true; } - -#else - - if (m_frames.removeOne(frame)) - return true; - -#endif return false; } @@ -194,7 +142,6 @@ void Sprite::setFrame(atUint32 id) return; } -#ifndef ATHENA_USE_QT void Sprite::setFrames(std::vector frames) { if (frames.size() == 0) @@ -213,13 +160,6 @@ void Sprite::setFrames(std::vector frames) m_frames = frames; } -#else -void Sprite::setFrames(QList frames) -{ - m_frames.clear(); - m_frames = frames; -} -#endif atUint32 Sprite::frameCount() const @@ -227,11 +167,7 @@ atUint32 Sprite::frameCount() const return (atUint32)m_frames.size(); } -#ifndef ATHENA_USE_QT std::vector Sprite::frames() const -#else -QList Sprite::frames() const -#endif { return m_frames; } @@ -263,9 +199,6 @@ void Sprite::setCurrentFrame(atUint32 id) return; m_currentFrame = id; -#ifdef ATHENA_USE_QT - emit frameChanged(currentFrame()); -#endif } SpriteFrame* Sprite::currentFrame() const diff --git a/src/athena/SpriteFile.cpp b/src/athena/SpriteFile.cpp index 5b0f59b..8df907c 100644 --- a/src/athena/SpriteFile.cpp +++ b/src/athena/SpriteFile.cpp @@ -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) -#else -SpriteFile::SpriteFile(const QSize& size, const QPoint& origin) -#endif : m_size(size), m_origin(origin) { @@ -38,113 +34,64 @@ SpriteFile::SpriteFile(const QSize& size, const QPoint& origin) SpriteFile::~SpriteFile() { -#ifndef ATHENA_USE_QT - for (std::pair sprite : m_sprites) { delete sprite.second; sprite.second = NULL; } -#endif m_sprites.clear(); } void SpriteFile::setSize(atUint32 width, atUint32 height) { -#ifndef ATHENA_USE_QT setSize(Vector2Di(width, height)); -#else - setSize(QSize(width, height)); -#endif } -#ifndef ATHENA_USE_QT void SpriteFile::setSize(const Vector2Di& size) -#else -void SpriteFile::setSize(const QSize& size) -#endif { m_size = size; -#ifdef ATHENA_USE_QT - emit sizeChanged(size); -#endif } -#ifndef ATHENA_USE_QT Vector2Di SpriteFile::size() const -#else -QSize SpriteFile::size() const -#endif { return m_size; } atUint32 SpriteFile::width() const { -#ifndef ATHENA_USE_QT return m_size.x; -#else - return m_size.width(); -#endif } atUint32 SpriteFile::height() const { -#ifndef ATHENA_USE_QT return m_size.y; -#else - return m_size.height(); -#endif } void SpriteFile::setOrigin(const float x, const float y) { -#ifndef ATHENA_USE_QT setOrigin(Vector2Df(x, y)); -#else - setOrigin(QPoint(x, y)); -#endif } -#ifndef ATHENA_USE_QT void SpriteFile::setOrigin(const Vector2Df& origin) -#else -void SpriteFile::setOrigin(const QPoint& origin) -#endif { m_origin = origin; -#ifdef ATHENA_USE_QT - emit originChanged(origin); -#endif } -#ifndef ATHENA_USE_QT Vector2Df SpriteFile::origin() const -#else -QPoint SpriteFile::origin() const -#endif { return m_origin; } float SpriteFile::originX() const { -#ifndef ATHENA_USE_QT return m_origin.x; -#else - return m_origin.x(); -#endif } float SpriteFile::originY() const { -#ifndef ATHENA_USE_QT return m_origin.y; -#else - return m_origin.y(); -#endif } bool SpriteFile::addTexture(STexture* texture) @@ -174,11 +121,7 @@ STexture* SpriteFile::texture(atUint32 id) return m_textures[id]; } -#ifndef ATHENA_USE_QT std::vector SpriteFile::textures() const -#else -QList SpriteFile::textures() const -#endif { return m_textures; } @@ -190,25 +133,15 @@ atUint32 SpriteFile::textureCount() const void SpriteFile::addSprite(Sprite* sprite) { -#ifndef ATHENA_USE_QT std::string name(sprite->name()); athena::utility::tolower(name); if (m_sprites.find(name) != m_sprites.end()) return; -#else - QString name = sprite->name().toLower(); - - if (m_sprites.contains(name)) - return; - -#endif - m_sprites[name] = sprite; } -#ifndef ATHENA_USE_QT void SpriteFile::removeSprite(const std::string& name) { std::string tmpName(name); @@ -218,19 +151,12 @@ void SpriteFile::removeSprite(const std::string& name) if (iterator != m_sprites.end()) m_sprites.erase(iterator); } -#else -void SpriteFile::removeSprite(const QString& name) -{ - m_sprites.remove(name.toLower()); -} -#endif void SpriteFile::removeSprite(Sprite* sprite) { removeSprite(sprite->name()); } -#ifndef ATHENA_USE_QT void SpriteFile::setSprites(std::unordered_map sprites) { if (sprites.size() == 0) @@ -249,18 +175,7 @@ void SpriteFile::setSprites(std::unordered_map sprites) m_sprites = sprites; } -#else -void SpriteFile::setSprites(QMap sprites) -{ - if (sprites.size() == 0) - return; - m_sprites.clear(); - m_sprites = sprites; -} -#endif - -#ifndef ATHENA_USE_QT Sprite* SpriteFile::sprite(const std::string& name) { std::string nameLow(name); @@ -271,21 +186,8 @@ Sprite* SpriteFile::sprite(const std::string& name) 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 SpriteFile::sprites() const -#else -QMap SpriteFile::sprites() const -#endif { return m_sprites; } @@ -295,7 +197,6 @@ atUint32 SpriteFile::spriteCount() const return (atUint32)m_sprites.size(); } -#ifndef ATHENA_USE_QT void SpriteFile::setTextures(std::vector textures) { if (textures.size() == 0) @@ -314,15 +215,6 @@ void SpriteFile::setTextures(std::vector textures) m_textures = textures; } -#else -void SpriteFile::setTextures(QList textures) -{ - if (textures.size() == 0) - return; - m_textures.clear(); - m_textures = textures; -} -#endif } // Sakura } // zelda diff --git a/src/athena/SpriteFileReader.cpp b/src/athena/SpriteFileReader.cpp index 764fdf7..d88f2c5 100644 --- a/src/athena/SpriteFileReader.cpp +++ b/src/athena/SpriteFileReader.cpp @@ -10,12 +10,12 @@ namespace athena namespace io { SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyReader(data, length) { } SpriteFileReader::SpriteFileReader(const std::string& filepath) - : base(filepath) + : MemoryCopyReader(filepath) { } @@ -24,7 +24,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() { Sakura::SpriteFile* ret = NULL; - atUint32 magic = base::readUint32(); + atUint32 magic = readUint32(); if (magic != Sakura::SpriteFile::Magic) { @@ -32,7 +32,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() return nullptr; } - atUint32 version = base::readUint32(); + atUint32 version = readUint32(); // TODO: Make this more verbose 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. // After that we have the number of sprites contained in this // 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. - atUint32 width = base::readUint32(); - atUint32 height = base::readUint32(); - float originX = base::readFloat(); - float originY = base::readFloat(); - atUint16 spriteCount = base::readUint16(); + atUint32 width = readUint32(); + atUint32 height = readUint32(); + float originX = readFloat(); + float originY = readFloat(); + atUint16 spriteCount = readUint16(); // Lets go ahead and create or new container. 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 // which require data to be 32 byte aligned, or it causes some issues. // It's also convenient to have this, for later expansion. - atUint32 reserved = base::readUint32(); + atUint32 reserved = readUint32(); UNUSED(reserved); // Next we have to load the textures @@ -79,8 +79,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() for (atUint16 i = 0; i < textureCount; i++) { Sakura::STexture* texture = new Sakura::STexture; - texture->Filepath = base::readString(); - texture->Preload = base::readBool(); + texture->Filepath = readString(); + texture->Preload = readBool(); textures.push_back(texture); } @@ -102,19 +102,19 @@ Sakura::SpriteFile* SpriteFileReader::readFile() { Sakura::Sprite* sprite = new Sakura::Sprite(ret); #ifndef ATHENA_USE_QT - std::string name = base::readString(); + std::string name = readString(); #else - QString name = QString::fromStdString(base::readString()); + QString name = QString::fromStdString(readString()); #endif sprite->setName(name); - atUint16 frameCount = base::readUint16(); - atUint16 stateCount = base::readUint16(); + atUint16 frameCount = readUint16(); + atUint16 stateCount = readUint16(); // Each state id corresponds to a texture held in the parent class std::vector stateIds; for (int j = 0; j < stateCount; j++) - stateIds.push_back(base::readUint16()); + stateIds.push_back(readUint16()); sprite->setStateIds(stateIds); @@ -135,8 +135,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() for (atUint32 k = 0; k < frameCount; k++) { Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite); - frame->setFrameTime(base::readFloat()); - atUint16 partCount = base::readUint16(); + frame->setFrameTime(readFloat()); + atUint16 partCount = readUint16(); #ifndef ATHENA_USE_QT @@ -149,25 +149,25 @@ Sakura::SpriteFile* SpriteFileReader::readFile() { Sakura::SpritePart* part = new Sakura::SpritePart(frame); #ifndef ATHENA_USE_QT - std::string name = base::readString(); + std::string name = readString(); #else - QString name = QString::fromStdString(base::readString()); + QString name = QString::fromStdString(readString()); #endif part->setName(name); - part->setCollision(base::readBool()); + part->setCollision(readBool()); - float xOff = base::readFloat(); - float yOff = base::readFloat(); + float xOff = readFloat(); + float yOff = readFloat(); part->setOffset(xOff, yOff); - float texXOff = base::readFloat(); - float texYOff = base::readFloat(); + float texXOff = readFloat(); + float texYOff = readFloat(); part->setTextureOffset(texXOff, texYOff); - atUint32 width = base::readUint32(); - atUint32 height = base::readUint32(); + atUint32 width = readUint32(); + atUint32 height = readUint32(); part->setSize(width, height); - bool flippedH = base::readBool(); + bool flippedH = readBool(); part->setFlippedHorizontally(flippedH); - bool flippedV = base::readBool(); + bool flippedV = readBool(); part->setFlippedVertically(flippedV); parts.push_back(part); diff --git a/src/athena/SpriteFileWriter.cpp b/src/athena/SpriteFileWriter.cpp index d5c380e..fdf034e 100644 --- a/src/athena/SpriteFileWriter.cpp +++ b/src/athena/SpriteFileWriter.cpp @@ -9,12 +9,12 @@ namespace athena namespace io { SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyWriter(data, length) { } SpriteFileWriter::SpriteFileWriter(const std::string& filepath) - : base(filepath) + : MemoryCopyWriter(filepath) { } @@ -26,73 +26,51 @@ void SpriteFileWriter::writeFile(Sakura::SpriteFile* file) return; } - base::writeUint32(Sakura::SpriteFile::Magic); - base::writeUint32(Sakura::SpriteFile::Version); + writeUint32(Sakura::SpriteFile::Magic); + writeUint32(Sakura::SpriteFile::Version); - base::writeUint16(file->textureCount()); - base::writeUint32(file->width()); - base::writeUint32(file->height()); - base::writeFloat(file->originX()); - base::writeFloat(file->originY()); - base::writeUint16(file->spriteCount()); + writeUint16(file->textureCount()); + writeUint32(file->width()); + writeUint32(file->height()); + writeFloat(file->originX()); + writeFloat(file->originY()); + writeUint16(file->spriteCount()); - base::writeUint32(0xFFFFFFFF); + writeUint32(0xFFFFFFFF); for (Sakura::STexture* texture : file->textures()) { - base::writeString(texture->Filepath); - base::writeBool(texture->Preload); + writeString(texture->Filepath); + writeBool(texture->Preload); } -#ifndef ATHENA_USE_QT - for (std::pair spritePair : file->sprites()) { Sakura::Sprite* sprite = spritePair.second; - base::writeString(sprite->name()); -#else - - foreach (Sakura::Sprite* sprite, file->sprites().values()) - { - - base::writeString(sprite->name().toStdString()); -#endif - base::writeUint16(sprite->frameCount()); - base::writeUint16(sprite->stateCount()); + writeString(sprite->name()); + writeUint16(sprite->frameCount()); + writeUint16(sprite->stateCount()); for (int id : sprite->stateIds()) - base::writeUint16(id); + writeUint16(id); for (Sakura::SpriteFrame* frame : sprite->frames()) { - base::writeFloat(frame->frameTime()); - base::writeUint16(frame->partCount()); + writeFloat(frame->frameTime()); + writeUint16(frame->partCount()); for (Sakura::SpritePart* part : frame->parts()) { -#ifndef ATHENA_USE_QT - base::writeString(part->name()); -#else - base::writeString(part->name().toStdString()); -#endif - base::writeBool(part->hasCollision()); -#ifndef ATHENA_USE_QT - base::writeFloat(part->offset().x); - base::writeFloat(part->offset().y); - base::writeFloat(part->textureOffset().x); - 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()); + writeString(part->name()); + writeBool(part->hasCollision()); + writeFloat(part->offset().x); + writeFloat(part->offset().y); + writeFloat(part->textureOffset().x); + writeFloat(part->textureOffset().y); + writeUint32(part->size().x); + writeUint32(part->size().y); + writeBool(part->flippedHorizontally()); + writeBool(part->flippedVertically()); } } } diff --git a/src/athena/SpriteFrame.cpp b/src/athena/SpriteFrame.cpp index adfd244..1b2e4c3 100644 --- a/src/athena/SpriteFrame.cpp +++ b/src/athena/SpriteFrame.cpp @@ -19,25 +19,14 @@ SpriteFrame::SpriteFrame(Sprite* root) void SpriteFrame::setFrameTime(float frameTime) { m_frameTime = frameTime; -#ifdef ATHENA_USE_QT - emit frameTimeChanged(frameTime); -#endif } -#ifndef ATHENA_USE_QT void SpriteFrame::setParts(std::vector parts) -#else -void SpriteFrame::setParts(QList parts) -#endif { m_parts = parts; } -#ifndef ATHENA_USE_QT std::vector SpriteFrame::parts() const -#else -QList SpriteFrame::parts() const -#endif { return m_parts; } diff --git a/src/athena/SpritePart.cpp b/src/athena/SpritePart.cpp index 508aaa4..f9a2e04 100644 --- a/src/athena/SpritePart.cpp +++ b/src/athena/SpritePart.cpp @@ -18,34 +18,19 @@ SpritePart::SpritePart(SpriteFrame* root, const std::string& name, bool hasColli : m_root(root), m_hasCollision(hasCollision) { -#ifdef ATHENA_USE_QT - m_name = QString::fromStdString(name); -#else m_name = name; -#endif } SpritePart::~SpritePart() { } -#ifndef ATHENA_USE_QT void SpritePart::setName(const std::string& name) -#else -void SpritePart::setName(const QString& name) -#endif { m_name = name; -#ifdef ATHENA_USE_QT - emit nameChanged(name); -#endif } -#ifndef ATHENA_USE_QT std::string SpritePart::name() const -#else -QString SpritePart::name() const -#endif { return m_name; } @@ -53,9 +38,6 @@ QString SpritePart::name() const void SpritePart::setCollision(bool col) { m_hasCollision = col; -#ifdef ATHENA_USE_QT - emit collisionChanged(col); -#endif } bool SpritePart::hasCollision() const @@ -65,90 +47,45 @@ bool SpritePart::hasCollision() const void SpritePart::setOffset(float x, float y) { -#ifndef ATHENA_USE_QT setOffset(Vector2Df(x, y)); -#else - setOffset(QPoint(x, y)); -#endif } -#ifndef ATHENA_USE_QT void SpritePart::setOffset(const Vector2Df& offset) -#else -void SpritePart::setOffset(const QPoint& offset) -#endif { m_offset = offset; -#ifdef ATHENA_USE_QT - emit offsetChanged(offset); -#endif } -#ifndef ATHENA_USE_QT Vector2Df SpritePart::offset() const -#else -QPoint SpritePart::offset() const -#endif { return m_offset; } void SpritePart::setTextureOffset(float x, float y) { -#ifndef ATHENA_USE_QT setTextureOffset(Vector2Df(x, y)); -#else - setTextureOffset(QPoint(x, y)); -#endif } -#ifndef ATHENA_USE_QT void SpritePart::setTextureOffset(const Vector2Df& offset) -#else -void SpritePart::setTextureOffset(const QPoint& offset) -#endif { m_textureOffset = offset; -#ifdef ATHENA_USE_QT - emit textureOffsetChanged(offset); -#endif } -#ifndef ATHENA_USE_QT Vector2Df SpritePart::textureOffset() const -#else -QPoint SpritePart::textureOffset() const -#endif { return m_textureOffset; } void SpritePart::setSize(atUint32 width, atUint32 height) { -#ifndef ATHENA_USE_QT setSize(Vector2Di(width, height)); -#else - setSize(QSize(width, height)); -#endif } -#ifndef ATHENA_USE_QT void SpritePart::setSize(const Vector2Di& size) -#else -void SpritePart::setSize(const QSize& size) -#endif { m_size = size; -#ifdef ATHENA_USE_QT - emit sizeChanged(size); -#endif } -#ifndef ATHENA_USE_QT Vector2Di SpritePart::size() const -#else -QSize SpritePart::size() const -#endif { return m_size; } @@ -156,9 +93,6 @@ QSize SpritePart::size() const void SpritePart::setFlippedHorizontally(const bool val) { m_flippedH = val; -#ifdef ATHENA_USE_QT - emit orientationChanged(val, flippedVertically()); -#endif } bool SpritePart::flippedHorizontally() const @@ -169,9 +103,6 @@ bool SpritePart::flippedHorizontally() const void SpritePart::setFlippedVertically(const bool val) { m_flippedV = val; -#ifdef ATHENA_USE_QT - emit orientationChanged(flippedHorizontally(), val); -#endif } bool SpritePart::flippedVertically() const diff --git a/src/athena/WiiSaveReader.cpp b/src/athena/WiiSaveReader.cpp index 1bbf069..eea3300 100644 --- a/src/athena/WiiSaveReader.cpp +++ b/src/athena/WiiSaveReader.cpp @@ -7,7 +7,7 @@ #include "athena/FileWriter.hpp" #include "md5.h" #include "aes.hpp" -#include "ecc.h" +#include "ec.hpp" #include "sha1.h" #include #include @@ -20,13 +20,13 @@ namespace io { WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyReader(data, length) { setEndian(Endian::BigEndian); } WiiSaveReader::WiiSaveReader(const std::string& filename) - : base(filename) + : MemoryCopyReader(filename) { setEndian(Endian::BigEndian); } @@ -50,7 +50,7 @@ std::unique_ptr WiiSaveReader::readSave() } ret->setBanner(banner); - atUint32 bkVer = base::readUint32(); + atUint32 bkVer = readUint32(); if (bkVer != 0x00000070) { @@ -58,7 +58,7 @@ std::unique_ptr WiiSaveReader::readSave() return nullptr; } - atUint32 bkMagic = base::readUint32(); + atUint32 bkMagic = readUint32(); if (bkMagic != 0x426B0001) { @@ -66,18 +66,18 @@ std::unique_ptr WiiSaveReader::readSave() return nullptr; } - /*atUint32 ngId =*/ base::readUint32(); - atUint32 numFiles = base::readUint32(); + /*atUint32 ngId =*/ readUint32(); + atUint32 numFiles = readUint32(); - /*int fileSize =*/ base::readUint32(); - base::seek(8); // skip unknown data; + /*int fileSize =*/ readUint32(); + seek(8); // skip unknown data; - atUint32 totalSize = base::readUint32(); - base::seek(64); // Unknown (Most likely padding) - base::seek(8); - base::seek(6); - base::seek(2); - base::seek(0x10); + atUint32 totalSize = readUint32(); + seek(64); // Unknown (Most likely padding) + seek(8); + seek(6); + seek(2); + seek(0x10); std::vector files; @@ -99,10 +99,10 @@ WiiBanner* WiiSaveReader::readBanner() { atUint8* dec = new atUint8[0xF0C0]; memset(dec, 0, 0xF0C0); - std::unique_ptr data = base::readUBytes(0xF0C0); - atUint8* oldData = base::data(); - atUint64 oldPos = base::position(); - atUint64 oldLen = base::length(); + std::unique_ptr buf = readUBytes(0xF0C0); + atUint8* oldData = data(); + atUint64 oldPos = position(); + atUint64 oldLen = length(); atUint64 gameId; atUint32 bannerSize; atUint8 permissions; @@ -114,7 +114,7 @@ WiiBanner* WiiSaveReader::readBanner() std::cout << "Decrypting: banner.bin..."; std::unique_ptr aes = NewAES(); aes->setKey(SD_KEY); - aes->decrypt(tmpIV, data.get(), dec, 0xF0C0); + aes->decrypt(tmpIV, buf.get(), dec, 0xF0C0); std::cout << "done" << std::endl; memset(md5, 0, 16); @@ -144,22 +144,22 @@ WiiBanner* WiiSaveReader::readBanner() std::cerr << std::hex << (int)(md5Calc[i]); std::cerr << std::endl; - base::setData(oldData, oldLen); - base::seek(oldPos, SeekOrigin::Begin); + setData(oldData, oldLen); + seek(oldPos, SeekOrigin::Begin); atError("MD5 Mismatch"); return nullptr; } // Set the binary reader buffer; - base::setData(dec, 0xF0C0); + setData(dec, 0xF0C0); // Start reading the header - gameId = base::readUint64(); - bannerSize = base::readUint32(); - permissions = base::readByte(); - /* unk =*/ base::readByte(); - base::seek(0x10); + gameId = readUint64(); + bannerSize = readUint32(); + permissions = readByte(); + /* unk =*/ readByte(); + seek(0x10); // skip padding - base::seek(2); + seek(2); int magic; int flags; @@ -167,31 +167,31 @@ WiiBanner* WiiSaveReader::readBanner() std::string gameTitle; std::string subTitle; - magic = base::readUint32(); + magic = readUint32(); // Ensure that the header magic is valid. if (magic != 0x5749424E) { // Make sure to reset m_reader values back to the old ones. - base::setData(oldData, oldLen); - base::seek(oldPos, SeekOrigin::Begin); + setData(oldData, oldLen); + seek(oldPos, SeekOrigin::Begin); atError("Invalid Header Magic"); return nullptr; } - flags = base::readUint32(); - animSpeed = base::readUint16(); - base::seek(22); + flags = readUint32(); + animSpeed = readUint16(); + seek(22); - gameTitle = base::readWStringAsString(); + gameTitle = readWStringAsString(); - if (base::position() != 0x0080) - base::seek(0x0080, SeekOrigin::Begin); + if (position() != 0x0080) + seek(0x0080, SeekOrigin::Begin); - subTitle = base::readWStringAsString(); + subTitle = readWStringAsString(); - if (base::position() != 0x00C0) - base::seek(0x00C0, SeekOrigin::Begin); + if (position() != 0x00C0) + seek(0x00C0, SeekOrigin::Begin); WiiBanner* banner = new WiiBanner; banner->setGameID(gameId); @@ -227,14 +227,14 @@ WiiBanner* WiiSaveReader::readBanner() } } - base::setData(oldData, oldLen); - base::seek(oldPos, SeekOrigin::Begin); + setData(oldData, oldLen); + seek(oldPos, SeekOrigin::Begin); return banner; } WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height) { - std::unique_ptr image = base::readUBytes(width * height * 2); + std::unique_ptr image = readUBytes(width * height * 2); if (!utility::isEmpty((atInt8*)image.get(), width * height * 2)) return new WiiImage(width, height, std::move(image)); @@ -252,7 +252,7 @@ WiiFile* WiiSaveReader::readFile() std::string name; WiiFile* ret; - atUint32 magic = base::readUint32(); + atUint32 magic = readUint32(); if (magic != 0x03adf17e) { @@ -260,23 +260,23 @@ WiiFile* WiiSaveReader::readFile() return NULL; } - fileLen = base::readUint32(); - permissions = base::readByte(); - attributes = base::readByte(); - type = (WiiFile::Type)base::readByte(); - name = std::string((const char*)base::readBytes(0x45).get()); + fileLen = readUint32(); + permissions = readByte(); + attributes = readByte(); + type = (WiiFile::Type)readByte(); + name = std::string((const char*)readBytes(0x45).get()); ret = new WiiFile(std::string(name)); ret->setPermissions(permissions); ret->setAttributes(attributes); ret->setType((WiiFile::Type)type); - std::unique_ptr iv = base::readUBytes(0x10); - base::seek(0x20); + std::unique_ptr iv = readUBytes(0x10); + seek(0x20); if (type == WiiFile::File) { // Read file data int roundedLen = (fileLen + 63) & ~63; - std::unique_ptr filedata = base::readUBytes(roundedLen); + std::unique_ptr filedata = readUBytes(roundedLen); // Decrypt file std::cout << "Decrypting: " << ret->filename() << "..."; @@ -294,35 +294,26 @@ WiiFile* WiiSaveReader::readFile() void WiiSaveReader::readCerts(atUint32 totalSize) { -#if 0 std::cout << "Reading certs..." << std::endl; atUint32 dataSize = totalSize - 0x340; - std::unique_ptr sig = base::readUBytes(0x40); - std::unique_ptr ngCert = base::readUBytes(0x180); - std::unique_ptr apCert = base::readUBytes(0x180); - base::seek(0xF0C0, SeekOrigin::Begin); - std::unique_ptr data = base::readUBytes(dataSize); + std::unique_ptr sig = readUBytes(0x40); + std::unique_ptr ngCert = readUBytes(0x180); + std::unique_ptr apCert = readUBytes(0x180); + seek(0xF0C0, SeekOrigin::Begin); + std::unique_ptr data = readUBytes(dataSize); atUint8* hash; std::cout << "validating..." << std::endl; hash = getSha1(data.get(), dataSize); 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())) - { - std::cout << "NGCert failure" << std::endl; - failed = true; - } - 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 + if (apValid) + std::cout << "AP Certificate ok" << std::endl; + if (ngValid) + std::cout << "NG Certificate ok" << std::endl; } WiiFile* WiiSaveReader::buildTree(std::vector files) diff --git a/src/athena/WiiSaveWriter.cpp b/src/athena/WiiSaveWriter.cpp index 5c48906..00af417 100644 --- a/src/athena/WiiSaveWriter.cpp +++ b/src/athena/WiiSaveWriter.cpp @@ -10,7 +10,7 @@ #include "athena/Utility.hpp" #include "aes.hpp" -#include "ecc.h" +#include "ec.hpp" #include "md5.h" #include "sha1.h" @@ -28,9 +28,9 @@ namespace io { 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()); - base::writeUint32(0x70); - base::writeUint32(0x426B0001); - base::writeUint32(ngId); // NG-ID - base::writeUint32(save->fileCount()); - base::writeUint32(0); // Size of files; - base::seek(8); - base::writeUint32(0); // totalSize - base::seek(64); - base::writeUint64(save->banner()->gameID()); - base::writeBytes((atInt8*)macAddress, 6); - base::seek(2); // unknown; - base::seek(0x10); // padding; + writeUint32(0x70); + writeUint32(0x426B0001); + writeUint32(ngId); // NG-ID + writeUint32(save->fileCount()); + writeUint32(0); // Size of files; + seek(8); + writeUint32(0); // totalSize + seek(64); + writeUint64(save->banner()->gameID()); + writeBytes((atInt8*)macAddress, 6); + seek(2); // unknown; + seek(0x10); // padding; atUint32 totalSize = 0; for (WiiFile* file : save->allFiles()) @@ -66,47 +66,47 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, totalSize += writeFile(file); } - atUint64 pos = base::position(); + atUint64 pos = position(); // Write size data - base::seek(0xF0C0 + 0x10, SeekOrigin::Begin); - base::writeUint32(totalSize); - base::seek(0xF0C0 + 0x1C, SeekOrigin::Begin); - base::writeUint32(totalSize + 0x3c0); - base::seek(pos, SeekOrigin::Begin); + seek(0xF0C0 + 0x10, SeekOrigin::Begin); + writeUint32(totalSize); + seek(0xF0C0 + 0x1C, SeekOrigin::Begin); + writeUint32(totalSize + 0x3c0); + seek(pos, SeekOrigin::Begin); writeCerts(totalSize, ngId, ngPriv, ngSig, ngKeyId); - base::save(); + this->save(); return true; } void WiiSaveWriter::writeBanner(WiiBanner* banner) { - base::setEndian(Endian::BigEndian); - base::writeInt64(banner->gameID()); - base::writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size()); - base::writeByte((atInt8)banner->permissions()); - base::seek(1); - base::writeBytes((atInt8*)MD5_BLANKER, 16); - base::seek(2); - base::writeInt32(0x5749424E); // WIBN - base::writeInt32(banner->flags()); - base::writeInt16(banner->animationSpeed()); - base::seek(22); + setEndian(Endian::BigEndian); + writeInt64(banner->gameID()); + writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size()); + writeByte((atInt8)banner->permissions()); + seek(1); + writeBytes((atInt8*)MD5_BLANKER, 16); + seek(2); + writeInt32(0x5749424E); // WIBN + writeInt32(banner->flags()); + writeInt16(banner->animationSpeed()); + seek(22); - base::writeStringAsWString(banner->title()); + writeStringAsWString(banner->title()); - if (base::position() != 0x0080) - base::seek(0x0080, SeekOrigin::Begin); + if (position() != 0x0080) + seek(0x0080, SeekOrigin::Begin); - base::writeStringAsWString(banner->subtitle()); + writeStringAsWString(banner->subtitle()); - if (base::position() != 0x00C0) - base::seek(0x00C0, SeekOrigin::Begin); + if (position() != 0x00C0) + seek(0x00C0, SeekOrigin::Begin); 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 atUint8* tmpIcon = new atUint8[48 * 48 * 2]; @@ -120,28 +120,28 @@ void WiiSaveWriter::writeBanner(WiiBanner* banner) } else { - base::writeBytes((atInt8*)tmpIcon, 48 * 48 * 2); + writeBytes((atInt8*)tmpIcon, 48 * 48 * 2); } } delete[] tmpIcon; // delete tmp buffer; atUint8* hash = new atUint8[0x10]; - MD5Hash::MD5(hash, (atUint8*)base::data(), 0xF0C0); - base::seek(0x0E, SeekOrigin::Begin); - base::writeBytes((atInt8*)hash, 0x10); + MD5Hash::MD5(hash, (atUint8*)data(), 0xF0C0); + seek(0x0E, SeekOrigin::Begin); + writeBytes((atInt8*)hash, 0x10); std::unique_ptr aes = NewAES(); aes->setKey(SD_KEY); atUint8 data[0xF0C0]; - memcpy(data, base::data(), 0xF0C0); + memcpy(data, this->data(), 0xF0C0); atUint8 tmpIV[26]; memcpy(tmpIV, SD_IV, 16); aes->encrypt(tmpIV, data, data, 0xF0C0); - base::seek(0, SeekOrigin::Begin); - base::writeBytes((atInt8*)data, 0xF0C0); - base::seek(0xF0C0, SeekOrigin::Begin); + seek(0, SeekOrigin::Begin); + writeBytes((atInt8*)data, 0xF0C0); + seek(0xF0C0, SeekOrigin::Begin); } atUint32 WiiSaveWriter::writeFile(WiiFile* file) @@ -149,23 +149,23 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file) atUint32 ret = 0x80; // Write the File magic - base::writeUint32(0x03ADF17E); - base::writeUint32(file->length()); - base::writeByte(file->permissions()); - base::writeByte(file->attributes()); - base::writeByte(file->type()); + writeUint32(0x03ADF17E); + writeUint32(file->length()); + writeByte(file->permissions()); + writeByte(file->attributes()); + writeByte(file->type()); atUint8 name[0x45]; utility::fillRandom(name, 0x45); memcpy(name, file->fullpath().c_str(), file->fullpath().size()); name[file->fullpath().size()] = '\0'; - base::writeBytes((atInt8*)name, 0x45); + writeBytes((atInt8*)name, 0x45); atUint8 iv[16]; utility::fillRandom(iv, 0x10); - base::writeBytes((atInt8*)iv, 0x10); + writeBytes((atInt8*)iv, 0x10); atUint8 crap[0x20]; utility::fillRandom(crap, 0x20); - base::writeBytes((atInt8*)crap, 0x20); + writeBytes((atInt8*)crap, 0x20); if (file->type() == WiiFile::File) { @@ -177,7 +177,7 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file) aes->setKey(SD_KEY); aes->encrypt(iv, file->data(), data, roundedSize); - base::writeBytes((atInt8*)data, roundedSize); + writeBytes((atInt8*)data, roundedSize); ret += roundedSize; delete[] data; } @@ -189,12 +189,11 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file) void WiiSaveWriter::writeImage(WiiImage* image) { 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) { -#if 0 atUint8 sig[0x40]; atUint8 ngCert[0x180]; atUint8 apCert[0x180]; @@ -203,12 +202,12 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri atUint8 apSig[60]; char signer[64]; char name[64]; - atUint8* data; + atUint8* buf; atUint32 dataSize; sprintf(signer, "Root-CA00000001-MS00000002"); 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); 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(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); - generate_ecdsa(apSig, apSig + 30, ngPriv, hash); - make_ec_cert(apCert, apSig, signer, name, apPriv, 0); + ecc::createECDSA(apSig, apSig + 30, ngPriv, hash); + ecc::makeECCert(apCert, apSig, signer, name, apPriv, 0); delete[] hash; dataSize = filesSize + 0x80; - data = new atUint8[dataSize]; - atUint8* rawData = base::data(); - memcpy(data, rawData + 0xF0C0, dataSize); + buf = new atUint8[dataSize]; + atUint8* rawData = data(); + memcpy(buf, rawData + 0xF0C0, dataSize); - hash = getSha1(data, dataSize); + hash = getSha1(buf, dataSize); atUint8* hash2 = getSha1(hash, 20); delete[] hash; - delete[] data; + delete[] buf; - generate_ecdsa(sig, sig + 30, apPriv, hash2); + ecc::createECDSA(sig, sig + 30, apPriv, hash2); int stuff = 0x2f536969; if (!utility::isSystemBigEndian()) @@ -243,10 +242,9 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri *(atUint32*)(sig + 60) = stuff; delete[] hash2; - base::writeBytes((atInt8*)sig, 0x40); - base::writeBytes((atInt8*)ngCert, 0x180); - base::writeBytes((atInt8*)apCert, 0x180); -#endif + writeBytes((atInt8*)sig, 0x40); + writeBytes((atInt8*)ngCert, 0x180); + writeBytes((atInt8*)apCert, 0x180); } } // io diff --git a/src/athena/ZQuestFileReader.cpp b/src/athena/ZQuestFileReader.cpp index a88ec2e..47fb1f9 100644 --- a/src/athena/ZQuestFileReader.cpp +++ b/src/athena/ZQuestFileReader.cpp @@ -13,12 +13,12 @@ namespace io { ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyReader(data, length) { } ZQuestFileReader::ZQuestFileReader(const std::string& filename) - : base(filename) + : MemoryCopyReader(filename) { } @@ -30,7 +30,7 @@ ZQuestFile* ZQuestFileReader::read() atUint16 BOM; atUint32 checksum = 0; - magic = base::readUint32(); + magic = readUint32(); if ((magic & 0x00FFFFFF) != (ZQuestFile::Magic & 0x00FFFFFF)) { @@ -38,7 +38,7 @@ ZQuestFile* ZQuestFileReader::read() return nullptr; } - version = base::readUint32(); + version = readUint32(); if (version > ZQuestFile::Version) { @@ -46,12 +46,12 @@ ZQuestFile* ZQuestFileReader::read() return nullptr; } - compressedLen = base::readUint32(); - uncompressedLen = base::readUint32(); + compressedLen = readUint32(); + uncompressedLen = readUint32(); 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++) { @@ -63,17 +63,17 @@ ZQuestFile* ZQuestFileReader::read() } } - BOM = base::readUint16(); - checksum = base::readUint32(); + BOM = readUint16(); + checksum = readUint32(); } else { - game = (ZQuestFile::Game)base::readUint32(); - BOM = base::readUint16(); - base::seek(0x0A); + game = (ZQuestFile::Game)readUint32(); + BOM = readUint16(); + seek(0x0A); } - std::unique_ptr data = base::readUBytes(compressedLen); // compressedLen is always the total file size + std::unique_ptr data = readUBytes(compressedLen); // compressedLen is always the total file size if (version >= ZQUEST_VERSION_CHECK(2, 0, 0)) { diff --git a/src/athena/ZQuestFileWriter.cpp b/src/athena/ZQuestFileWriter.cpp index ed118ae..212d3c1 100644 --- a/src/athena/ZQuestFileWriter.cpp +++ b/src/athena/ZQuestFileWriter.cpp @@ -9,12 +9,12 @@ namespace io { ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length) - : base(data, length) + : MemoryCopyWriter(data, length) { } ZQuestFileWriter::ZQuestFileWriter(const std::string& filename) - : base(filename) + : MemoryCopyWriter(filename) { } @@ -26,8 +26,8 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) return; } - base::writeUint32(ZQuestFile::Magic); - base::writeUint32(ZQuestFile::Version); + writeUint32(ZQuestFile::Magic); + writeUint32(ZQuestFile::Version); atUint8* questData = quest->data(); 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[] compData; compData = NULL; - base::writeUint32(quest->length()); + writeUint32(quest->length()); } else { // Don't do delete on data questData = compData; - base::writeUint32(compLen); + writeUint32(compLen); } } else { compLen = quest->length(); - base::writeUint32(quest->length()); + writeUint32(quest->length()); } - base::writeUint32(quest->length()); - base::writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A); - base::writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF); - base::writeUint32(athena::Checksums::crc32(questData, compLen)); - base::writeUBytes(questData, compLen); + writeUint32(quest->length()); + writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A); + writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF); + writeUint32(athena::Checksums::crc32(questData, compLen)); + writeUBytes(questData, compLen); - base::save(); + save(); // Delete compressed data to prevent memory leaks if (questData != quest->data()) diff --git a/src/bn.cpp b/src/bn.cpp new file mode 100644 index 0000000..a4d0a62 --- /dev/null +++ b/src/bn.cpp @@ -0,0 +1,98 @@ +#include +#include + +#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; +} +} diff --git a/src/ec.cpp b/src/ec.cpp new file mode 100644 index 0000000..7241827 --- /dev/null +++ b/src/ec.cpp @@ -0,0 +1,320 @@ +#include +#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); +} +}