diff --git a/include/Athena/ALTTPFile.hpp b/include/Athena/ALTTPFile.hpp index d952ff6..4a1f067 100644 --- a/include/Athena/ALTTPFile.hpp +++ b/include/Athena/ALTTPFile.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -59,7 +60,7 @@ public: * \param val The new quest to assign to the given index * \throw InvalidOperationException on index out of range */ - void setQuest(Uint32 id, ALTTPQuest* val); + void setQuest(atUint32 id, ALTTPQuest* val); /*! \brief Returns the primary quest list * * \return The primary quest list @@ -73,13 +74,13 @@ public: * \return ALTTPQuest* * \throw InvalidOperationException on index out of range */ - ALTTPQuest* quest(Uint32 id) const; + ALTTPQuest* quest(atUint32 id) const; /*! \brief Returns the number of primary quests * * \return The number of quests */ - Uint32 questCount() const; + atUint32 questCount() const; private: @@ -89,3 +90,4 @@ private: } // zelda #endif // __ALTTP_FILE_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/ALTTPFileReader.hpp b/include/Athena/ALTTPFileReader.hpp index 293b467..6e07fb1 100644 --- a/include/Athena/ALTTPFileReader.hpp +++ b/include/Athena/ALTTPFileReader.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -44,7 +45,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - ALTTPFileReader(Uint8*, Uint64); + ALTTPFileReader(atUint8*, atUint64); /*! \brief This constructor creates an instance from a file on disk. * @@ -66,3 +67,4 @@ private: } // io } // zelda #endif // __ALTTP_FILE_READER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/ALTTPFileWriter.hpp b/include/Athena/ALTTPFileWriter.hpp index bf35f22..5d0df05 100644 --- a/include/Athena/ALTTPFileWriter.hpp +++ b/include/Athena/ALTTPFileWriter.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -43,7 +44,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - ALTTPFileWriter(Uint8*, Uint64); + ALTTPFileWriter(atUint8*, atUint64); /*! \brief This constructor creates an instance from a file on disk. * @@ -61,10 +62,11 @@ private: void writeRoomFlags(ALTTPRoomFlags*); void writeOverworldEvent(ALTTPOverworldEvent*); void writeDungeonItems(ALTTPDungeonItemFlags); - Uint16 calculateChecksum(Uint32 game); + atUint16 calculateChecksum(atUint32 game); }; } // io } // zelda #endif // __ALTTP_FILE_WRITER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/ALTTPQuest.hpp b/include/Athena/ALTTPQuest.hpp index e3c123a..057494a 100644 --- a/include/Athena/ALTTPQuest.hpp +++ b/include/Athena/ALTTPQuest.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -51,7 +52,7 @@ public: * \param rf * \param id */ - void setRoomFlags(ALTTPRoomFlags* rf, Uint32 id); + void setRoomFlags(ALTTPRoomFlags* rf, atUint32 id); /*! * \brief roomFlags @@ -64,7 +65,7 @@ public: * \param id * \return */ - ALTTPRoomFlags* roomFlags(Uint32 id); + ALTTPRoomFlags* roomFlags(atUint32 id); /*! * \brief setOverworldEvents @@ -77,7 +78,7 @@ public: * \param ow * \param id */ - void setOverworldEvents(ALTTPOverworldEvent* ow, Uint32 id); + void setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id); /*! * \brief overworldEvents @@ -90,7 +91,7 @@ public: * \param id * \return */ - ALTTPOverworldEvent* overworldEvent(Uint32 id) const; + ALTTPOverworldEvent* overworldEvent(atUint32 id) const; /*! * \brief setInventory @@ -108,25 +109,25 @@ public: * \brief setRupeeMax * \param val */ - void setRupeeMax(Uint16 val); + void setRupeeMax(atUint16 val); /*! * \brief rupeeMax * \return */ - Uint16 rupeeMax() const; + atUint16 rupeeMax() const; /*! * \brief setRupeeCurrent * \param val */ - void setRupeeCurrent(Uint16 val); + void setRupeeCurrent(atUint16 val); /*! * \brief rupeeCurrent * \return */ - Uint16 rupeeCurrent() const; + atUint16 rupeeCurrent() const; /*! * \brief setCompasses @@ -168,109 +169,109 @@ public: * \brief setWishingPond * \param val */ - void setWishingPond(Uint16 val); + void setWishingPond(atUint16 val); /*! * \brief wishingPond * \return */ - Uint16 wishingPond() const; + atUint16 wishingPond() const; /*! * \brief setHealthMax * \param val */ - void setHealthMax(Uint8 val); + void setHealthMax(atUint8 val); /*! * \brief healthMax * \return */ - Uint8 healthMax() const; + atUint8 healthMax() const; /*! * \brief setHealth * \param val */ - void setHealth(Uint8 val); + void setHealth(atUint8 val); /*! * \brief health * \return */ - Uint8 health() const; + atUint8 health() const; /*! * \brief setMagicPower * \param val */ - void setMagicPower(Uint8 val); + void setMagicPower(atUint8 val); /*! * \brief magicPower * \return */ - Uint8 magicPower() const; + atUint8 magicPower() const; /*! * \brief setKeys * \param val */ - void setKeys(Uint8 val); + void setKeys(atUint8 val); /*! * \brief keys * \return */ - Uint8 keys() const; + atUint8 keys() const; /*! * \brief setBombUpgrades * \param val */ - void setBombUpgrades(Uint8 val); + void setBombUpgrades(atUint8 val); /*! * \brief bombUpgrades * \return */ - Uint8 bombUpgrades() const; + atUint8 bombUpgrades() const; /*! * \brief setArrowUpgrades * \param val */ - void setArrowUpgrades(Uint8 val); + void setArrowUpgrades(atUint8 val); /*! * \brief arrowUpgrades * \return */ - Uint8 arrowUpgrades() const; + atUint8 arrowUpgrades() const; /*! * \brief setHealthFiller * \param val */ - void setHealthFiller(Uint8 val); + void setHealthFiller(atUint8 val); /*! * \brief healthFiller * \return */ - Uint8 healthFiller() const; + atUint8 healthFiller() const; /*! * \brief setMagicFiller * \param val */ - void setMagicFiller(Uint8 val); + void setMagicFiller(atUint8 val); /*! * \brief magicFiller * \return */ - Uint8 magicFiller() const; + atUint8 magicFiller() const; /*! * \brief setPendants @@ -288,37 +289,37 @@ public: * \brief setBombFiller * \param val */ - void setBombFiller(Uint8 val); + void setBombFiller(atUint8 val); /*! * \brief bombFiller * \return */ - Uint8 bombFiller() const; + atUint8 bombFiller() const; /*! * \brief setArrowFiller * \param val */ - void setArrowFiller(Uint8 val); + void setArrowFiller(atUint8 val); /*! * \brief arrowFiller * \return */ - Uint8 arrowFiller() const; + atUint8 arrowFiller() const; /*! * \brief setArrows * \param val */ - void setArrows(Uint8 val); + void setArrows(atUint8 val); /*! * \brief arrows * \return */ - Uint8 arrows() const; + atUint8 arrows() const; /*! * \brief setAbilityFlags @@ -360,27 +361,27 @@ public: * \brief setDungeonKeys * \param val */ - void setDungeonKeys(std::vector val); + void setDungeonKeys(std::vector val); /*! * \brief setDungeonKeys * \param id * \param val */ - void setDungeonKeys(Uint32 id, Uint8 val); + void setDungeonKeys(atUint32 id, atUint8 val); /*! * \brief dungeonKeys * \param id * \return */ - Uint8 dungeonKeys(Uint32 id) const; + atUint8 dungeonKeys(atUint32 id) const; /*! * \brief dungeonCount * \return */ - Uint32 dungeonCount() const; + atUint32 dungeonCount() const; /*! * \brief setProgressIndicator @@ -470,71 +471,71 @@ public: * \brief setOldManFlags * \param flags */ - void setOldManFlags(std::vector flags); + void setOldManFlags(std::vector flags); /*! * \brief setOldManFlag * \param id * \param val */ - void setOldManFlag(Uint32 id, Uint8 val); + void setOldManFlag(atUint32 id, atUint8 val); /*! * \brief oldManFlag * \param id * \return */ - Uint8 oldManFlag(Uint32 id); + atUint8 oldManFlag(atUint32 id); /*! * \brief oldManFlagCount * \return */ - Uint32 oldManFlagCount() const; + atUint32 oldManFlagCount() const; /*! * \brief setBombFlag * \param flag */ - void setBombFlag(Uint8 flag); + void setBombFlag(atUint8 flag); /*! * \brief bombFlag * \return */ - Uint8 bombFlag() const; + atUint8 bombFlag() const; /*! * \brief setUnknown1 * \param flags */ - void setUnknown1(std::vector flags); + void setUnknown1(std::vector flags); /*! * \brief setUnknown1 * \param id * \param val */ - void setUnknown1(Uint32 id, Uint8 val); + void setUnknown1(atUint32 id, atUint8 val); /*! * \brief unknown1 * \param id * \return */ - Uint8 unknown1(Uint32 id); + atUint8 unknown1(atUint32 id); /*! * \brief unknown1Count * \return */ - Uint32 unknown1Count() const; + atUint32 unknown1Count() const; /*! * \brief setPlayerName * \param playerName */ - void setPlayerName(std::vector playerName); + void setPlayerName(std::vector playerName); /*! * \brief setPlayerName * \param playerName @@ -544,7 +545,7 @@ public: * \brief playerName * \return */ - std::vector playerName() const; + std::vector playerName() const; /*! * \brief playerNameToString * \return @@ -567,101 +568,101 @@ public: * \brief setDungeonDeathTotals * \param val */ - void setDungeonDeathTotals(std::vector val); + void setDungeonDeathTotals(std::vector val); /*! * \brief setDungeonDeathTotal * \param id * \param val */ - void setDungeonDeathTotal(Uint32 id, Uint16 val); + void setDungeonDeathTotal(atUint32 id, atUint16 val); /*! * \brief dungeonDeathTotal * \param id * \return */ - Uint16 dungeonDeathTotal(Uint32 id) const; + atUint16 dungeonDeathTotal(atUint32 id) const; /*! * \brief dungeonDeathTotalCount * \return */ - Uint16 dungeonDeathTotalCount() const; + atUint16 dungeonDeathTotalCount() const; /*! * \brief setUnknown2 * \param val */ - void setUnknown2(Uint16 val); + void setUnknown2(atUint16 val); /*! * \brief unknown2 * \return */ - Uint16 unknown2() const; + atUint16 unknown2() const; /*! * \brief setDeathSaveCount * \param val */ - void setDeathSaveCount(Uint16 val); + void setDeathSaveCount(atUint16 val); /*! * \brief deathSaveCount * \return */ - Uint16 deathSaveCount() const; + atUint16 deathSaveCount() const; /*! * \brief setPostGameDeathCounter * \param val */ - void setPostGameDeathCounter(Int16 val); + void setPostGameDeathCounter(atInt16 val); /*! * \brief postGameDeathCounter * \return */ - Int16 postGameDeathCounter() const; + atInt16 postGameDeathCounter() const; /*! * \brief setChecksum * \param checksum */ - void setChecksum(Uint16 checksum); + void setChecksum(atUint16 checksum); /*! * \brief checksum * \return */ - Uint16 checksum() const; + atUint16 checksum() const; private: std::vector m_roomFlags; std::vector m_overworldEvents; ALTTPInventory* m_inventory; - Uint16 m_rupeeMax; - Uint16 m_rupeeCurrent; + atUint16 m_rupeeMax; + atUint16 m_rupeeCurrent; ALTTPDungeonItemFlags m_compasses; ALTTPDungeonItemFlags m_bigKeys; ALTTPDungeonItemFlags m_dungeonMaps; - Uint16 m_wishingPond; - Uint8 m_healthMax; - Uint8 m_health; - Uint8 m_magicPower; - Uint8 m_keys; - Uint8 m_bombUpgrades; - Uint8 m_arrowUpgrades; - Uint8 m_heartFiller; - Uint8 m_magicFiller; + atUint16 m_wishingPond; + atUint8 m_healthMax; + atUint8 m_health; + atUint8 m_magicPower; + atUint8 m_keys; + atUint8 m_bombUpgrades; + atUint8 m_arrowUpgrades; + atUint8 m_heartFiller; + atUint8 m_magicFiller; ALTTPPendants m_pendants; - Uint8 m_bombFiller; - Uint8 m_arrowFiller; - Uint8 m_arrows; + atUint8 m_bombFiller; + atUint8 m_arrowFiller; + atUint8 m_arrows; ALTTPAbilities m_abilityFlags; ALTTPCrystals m_crystals; ALTTPMagicUsage m_magicUsage; - std::vector m_dungeonKeys; + std::vector m_dungeonKeys; ALTTPProgressIndicator m_progressIndicator; ALTTPProgressFlags1 m_progressFlags1; ALTTPMapIcon m_mapIcon; @@ -669,18 +670,19 @@ private: ALTTPProgressFlags2 m_progressFlags2; ALTTPLightDarkWorldIndicator m_lightDarkWorldIndicator; ALTTPTagAlong m_tagAlong; - std::vector m_oldManFlags; - Uint8 m_bombFlag; - std::vector m_unknown1; - std::vector m_playerName; - Uint16 m_valid; - std::vector m_dungeonDeathTotals; - Uint16 m_unknown2; - Uint16 m_deathSaveCount; - Int16 m_postGameDeathCounter; - Uint16 m_checksum; + std::vector m_oldManFlags; + atUint8 m_bombFlag; + std::vector m_unknown1; + std::vector m_playerName; + atUint16 m_valid; + std::vector m_dungeonDeathTotals; + atUint16 m_unknown2; + atUint16 m_deathSaveCount; + atInt16 m_postGameDeathCounter; + atUint16 m_checksum; }; } // zelda #endif // __ALTTP_QUEST_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/BinaryReader.hpp b/include/Athena/BinaryReader.hpp index abeba5f..40cd306 100644 --- a/include/Athena/BinaryReader.hpp +++ b/include/Athena/BinaryReader.hpp @@ -40,7 +40,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - BinaryReader(const Uint8* data, Uint64 length); + BinaryReader(const atUint8* data, atUint64 length); /*! \brief This constructor creates an instance from a file on disk. * @@ -85,7 +85,7 @@ public: * \param position where in the buffer to seek * \param origin The Origin to seek \sa SeekOrigin */ - void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current); + void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); /*! \brief Returns whether or not the stream is at the end. @@ -98,13 +98,13 @@ public: * * \return Int64 The current position in the stream. */ - Uint64 position() const; + atUint64 position() const; /*! \brief Returns whether or not the stream is at the end. * * \return bool True if at end; False otherwise. */ - Uint64 length() const; + atUint64 length() const; /*! \brief Sets the buffer to the given one, deleting the current one.
* BEWARE: As this deletes the current buffer it WILL cause a loss of data @@ -115,7 +115,7 @@ public: * \param length The length of the new buffer. * \throw IOException */ - void setData(const Uint8* data, Uint64 length); + void setData(const atUint8* data, atUint64 length); /*! \brief Returns a copy of the current buffer.
@@ -125,7 +125,7 @@ public: * as Stream now owns the address, this is done to keep memory usage down. * \return Uint8* The copy of the buffer. */ - Uint8* data() const; + atUint8* data() const; /*! \brief Sets the target file * @@ -155,25 +155,25 @@ public: * * \return Int8 The value at the current position */ - Int8 readByte(); + atInt8 readByte(); /*! \brief Reads a byte at the current position and advances the current position * * \return Uint8 The value at the current position */ - Uint8 readUByte(); + atUint8 readUByte(); /*! \brief Reads a byte at the current position and advances the current position. * * \return Uint8* The buffer at the current position from the given length. */ - Int8* readBytes(Int64 length); + atInt8* readBytes(atInt64 length); /*! \brief Reads a byte at the current position and advances the current position. * * \return Int8* The buffer at the current position from the given length. */ - Uint8* readUBytes(Int64 length); + atUint8* readUBytes(atInt64 length); /*! \brief Reads a Int16 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -183,7 +183,7 @@ public: * \return Int16 The value at the current address * \throw IOException when address is out of range */ - Int16 readInt16(); + atInt16 readInt16(); /*! \brief Reads a Uint16 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -193,7 +193,7 @@ public: * \return Uint16 The value at the current address * \throw IOException when address is out of range */ - Uint16 readUint16(); + atUint16 readUint16(); /*! \brief Reads a Int32 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -203,7 +203,7 @@ public: * \return Int32 The value at the current address * \throw IOException when address is out of range */ - Int32 readInt32(); + atInt32 readInt32(); /*! \brief Reads a Uint32 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -213,7 +213,7 @@ public: * \return Uint32 The value at the current address * \throw IOException when address is out of range */ - Uint32 readUint32(); + atUint32 readUint32(); /*! \brief Reads a Int64 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -223,7 +223,7 @@ public: * \return Int64 The value at the current address * \throw IOException when address is out of range */ - Int64 readInt64(); + atInt64 readInt64(); /*! \brief Reads a Uint64 and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -233,7 +233,7 @@ public: * \return Uint64 The value at the current address * \throw IOException when address is out of range */ - Uint64 readUint64(); + atUint64 readUint64(); /*! \brief Reads a float and swaps to proper endianness depending on platform * and Stream settings, and advances the current position @@ -279,11 +279,11 @@ public: void setProgressCallback(std::function cb); protected: void loadData(); - Uint8* m_data; - Uint64 m_length; + atUint8* m_data; + atUint64 m_length; std::string m_filepath; //!< Path to the target file - Uint64 m_position; - Uint64 m_bitPosition; + atUint64 m_position; + atUint64 m_bitPosition; Endian m_endian; std::function m_progressCallback; }; diff --git a/include/Athena/BinaryWriter.hpp b/include/Athena/BinaryWriter.hpp index 8b6e97e..dca0337 100644 --- a/include/Athena/BinaryWriter.hpp +++ b/include/Athena/BinaryWriter.hpp @@ -41,7 +41,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - BinaryWriter(Uint8* data, Uint64 length); + BinaryWriter(atUint8* data, atUint64 length); /*! \brief This constructor creates an instance from a file on disk. * @@ -86,7 +86,7 @@ public: * \param position where in the buffer to seek * \param origin The Origin to seek \sa SeekOrigin */ - void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current); + void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); /*! \brief Returns whether or not the stream is at the end. @@ -100,13 +100,13 @@ public: * * \return Int64 The current position in the stream. */ - Uint64 position() const; + atUint64 position() const; /*! \brief Returns whether or not the stream is at the end. * * \return bool True if at end; False otherwise. */ - Uint64 length() const; + atUint64 length() const; /*! \brief Sets the buffer to the given one, deleting the current one.
* BEWARE: As this deletes the current buffer it WILL cause a loss of data @@ -117,7 +117,7 @@ public: * \param length The length of the new buffer. * \throw IOException */ - void setData(const Uint8* data, Uint64 length); + void setData(const atUint8* data, atUint64 length); /*! \brief Returns a copy of the current buffer.
@@ -127,7 +127,7 @@ public: * as Stream now owns the address, this is done to keep memory usage down. * \return Uint8* The copy of the buffer. */ - Uint8* data() const; + atUint8* data() const; /*! \brief Sets the target file * @@ -161,13 +161,13 @@ public: /*! \brief Writes a byte at the current position and advances the position by one byte. * \param byte The value to write */ - void writeUByte(Uint8 val); + void writeUByte(atUint8 val); /*! \brief Writes a byte at the current position and advances the position by one byte. * \param byte The value to write * \throw IOException */ - void writeByte(Int8 val); + void writeByte(atInt8 val); /*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length * however it's undefined behavior to try and write a buffer which is smaller than the given length. @@ -175,7 +175,7 @@ public: * \param data The buffer to write * \param length The amount to write */ - void writeUBytes(Uint8* data, Uint64 len); + void writeUBytes(atUint8* data, atUint64 len); /*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length * however it's undefined behavior to try and write a buffer which is smaller than the given length. @@ -183,7 +183,7 @@ public: * \param data The buffer to write * \param length The amount to write */ - void writeBytes(Int8* data, Uint64 len); + void writeBytes(atInt8* data, atUint64 len); /*! \brief Writes an Int16 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -191,7 +191,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeInt16(Int16 val); + void writeInt16(atInt16 val); /*! \brief Writes an Uint16 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings @@ -199,7 +199,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeUint16(Uint16); + void writeUint16(atUint16); /*! \brief Writes an Int32 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -207,7 +207,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeInt32(Int32); + void writeInt32(atInt32); /*! \brief Writes an Uint32 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -215,7 +215,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeUint32(Uint32); + void writeUint32(atUint32); /*! \brief Writes an Int64 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -223,7 +223,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeInt64(Int64); + void writeInt64(atInt64); /*! \brief Writes an Uint64 to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -231,7 +231,7 @@ public: * \sa Endian * \param val The value to write to the buffer */ - void writeUint64(Uint64); + void writeUint64(atUint64); /*! \brief Writes an float to the buffer and advances the buffer. * It also swaps the bytes depending on the platform and Stream settings. @@ -272,21 +272,21 @@ public: */ void writeString(const std::string& str); - void fill(Uint8 val, Uint64 length); - void fill(Int8 val, Uint64 length); + void fill(atUint8 val, atUint64 length); + void fill(atInt8 val, atUint64 length); void setProgressCallback(std::function cb); protected: void loadData(); - Uint8* m_data; - Uint64 m_length; + atUint8* m_data; + atUint64 m_length; std::string m_filepath; //!< Path to the target file - Uint64 m_position; - Uint64 m_bitPosition; + atUint64 m_position; + atUint64 m_bitPosition; Endian m_endian; std::function m_progressCallback; private: - void resize(Uint64 newSize); + void resize(atUint64 newSize); }; } } diff --git a/include/Athena/Checksums.hpp b/include/Athena/Checksums.hpp index 9d8ecb3..b1583a0 100644 --- a/include/Athena/Checksums.hpp +++ b/include/Athena/Checksums.hpp @@ -22,9 +22,9 @@ namespace Athena { namespace Checksums { -Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed = 0xFFFFFFFF); -Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed = 0xFFFF, Uint16 final = 0); -Uint16 crc16(const Uint8* data, Uint64 length); +atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed = 0xFFFFFFFF); +atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0); +atUint16 crc16(const atUint8* data, atUint64 length); } } #endif // CHECKSUMS_HPP diff --git a/include/Athena/Compression.hpp b/include/Athena/Compression.hpp index 0aeca4b..e92e843 100644 --- a/include/Athena/Compression.hpp +++ b/include/Athena/Compression.hpp @@ -25,15 +25,15 @@ namespace io namespace Compression { // Zlib compression - Int32 decompressZlib(Uint8* src, Uint32 srcLen, Uint8* dst, Uint32 dstLen); - Int32 compressZlib(const Uint8* src, Uint32 srcLen, Uint8* dst, Uint32 dstLen); + atInt32 decompressZlib(atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen); + atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen); // lzo compression - Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize); + atInt32 decompressLZO(atUint8* source, atInt32 sourceSize, atUint8* dest, atInt32& dstSize); // Yaz0 encoding - Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize); - Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data); + atUint32 yaz0Decode(atUint8* src, atUint8* dst, atUint32 uncompressedSize); + atUint32 yaz0Encode(atUint8* src, atUint32 srcSize, atUint8* data); } } diff --git a/include/Athena/FileReader.hpp b/include/Athena/FileReader.hpp index 13b0d50..010bd0d 100644 --- a/include/Athena/FileReader.hpp +++ b/include/Athena/FileReader.hpp @@ -39,24 +39,24 @@ public: void close(); bool isOpen() const; bool save(); - void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current); + void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); bool atEnd() const; - Uint64 position() const; - Uint64 length() const; + atUint64 position() const; + atUint64 length() const; void seekBit(int); bool readBit(); - Uint8 readUByte(); - Int8 readByte(); - Uint8* readUBytes(Uint64 len); - Int8* readBytes(Uint64 len); - Uint16 readUint16(); - Int16 readInt16(); - Uint32 readUint32(); - Int32 readInt32(); - Uint64 readUint64(); - Int64 readInt64(); + atUint8 readUByte(); + atInt8 readByte(); + atUint8* readUBytes(atUint64 len); + atInt8* readBytes(atUint64 len); + atUint16 readUint16(); + atInt16 readInt16(); + atUint32 readUint32(); + atInt32 readInt32(); + atUint64 readUint64(); + atInt64 readInt64(); double readDouble(); float readFloat(); bool readBool(); @@ -66,8 +66,8 @@ private: std::string m_filename; FILE* m_fileHandle; Endian m_endian; - Uint8 m_currentByte; - Uint8 m_bitShift; + atUint8 m_currentByte; + atUint8 m_bitShift; bool m_bitValid; }; } // io diff --git a/include/Athena/FileWriter.hpp b/include/Athena/FileWriter.hpp index 1c8a0f0..4554243 100644 --- a/include/Athena/FileWriter.hpp +++ b/include/Athena/FileWriter.hpp @@ -36,23 +36,23 @@ public: void close(); bool isOpen() const; bool save(); - void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current); + void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); bool atEnd() const; - Uint64 position() const; - Uint64 length() const; + atUint64 position() const; + atUint64 length() const; void writeBit (bool val); void seekBit (int bit); - void writeUByte (Uint8 val); - void writeByte (Int8 val); - void writeUBytes(Uint8* data, Uint64 len); - void writeBytes (Int8* data, Uint64 len); - void writeUint16(Uint16 val); - void writeInt16 (Int16 val); - void writeUint32(Uint32 val); - void writeInt32 (Int32 val); - void writeUint64(Uint64 val); - void writeInt64 (Int64 val); + void writeUByte (atUint8 val); + void writeByte (atInt8 val); + void writeUBytes(atUint8* data, atUint64 len); + void writeBytes (atInt8* data, atUint64 len); + void writeUint16(atUint16 val); + void writeInt16 (atInt16 val); + void writeUint32(atUint32 val); + void writeInt32 (atInt32 val); + void writeUint64(atUint64 val); + void writeInt64 (atInt64 val); void writeDouble(double val); void writeFloat (float val); void writeBool (bool val); @@ -62,9 +62,9 @@ private: std::string m_filename; FILE* m_fileHandle; Endian m_endian; - Uint8 m_currentByte; - Uint8 m_bytePosition; - Uint8 m_bitShift; + atUint8 m_currentByte; + atUint8 m_bytePosition; + atUint8 m_bitShift; bool m_bitValid; }; } diff --git a/include/Athena/MCFileReader.hpp b/include/Athena/MCFileReader.hpp index 619988d..4245b17 100644 --- a/include/Athena/MCFileReader.hpp +++ b/include/Athena/MCFileReader.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -43,7 +44,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - MCFileReader(Uint8*, Uint64); + MCFileReader(atUint8*, atUint64); /*! * \brief This constructor creates an instance from a file on disk. @@ -64,3 +65,4 @@ public: } // zelda #endif // __MCFILEREADER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/MCFileWriter.hpp b/include/Athena/MCFileWriter.hpp index f5f5f68..de2eefb 100644 --- a/include/Athena/MCFileWriter.hpp +++ b/include/Athena/MCFileWriter.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -44,7 +45,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - MCFileWriter(Uint8*, Uint64); + MCFileWriter(atUint8*, atUint64); /*! * \brief This constructor creates an instance from a file on disk. @@ -61,9 +62,9 @@ public: void writeFile(MCFile* file); private: - Uint16 calculateSlotChecksum(Uint32 game); - Uint16 calculateChecksum(Uint8* data, Uint32 length); - Uint8* reverse(Uint8* data, Uint32 length); + atUint16 calculateSlotChecksum(atUint32 game); + atUint16 calculateChecksum(atUint8* data, atUint32 length); + atUint8* reverse(atUint8* data, atUint32 length); void unscramble(); }; @@ -71,3 +72,4 @@ private: } // zelda #endif // __MCFILEWRITER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/SkywardSwordFile.hpp b/include/Athena/SkywardSwordFile.hpp index c1b420c..61870b3 100644 --- a/include/Athena/SkywardSwordFile.hpp +++ b/include/Athena/SkywardSwordFile.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -47,7 +48,7 @@ public: ~SkywardSwordFile(); void addQuest(SkywardSwordQuest* q); - SkywardSwordQuest* quest(Uint32 id); + SkywardSwordQuest* quest(atUint32 id); std::vector questList() const; void setRegion(Region region); @@ -56,8 +57,9 @@ private: Region m_region; // A vector is a bit overkill std::vector m_quests; - Uint32 m_numQuests; + atUint32 m_numQuests; }; } #endif // __SSFILE_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/SkywardSwordFileReader.hpp b/include/Athena/SkywardSwordFileReader.hpp index adc213b..82df715 100644 --- a/include/Athena/SkywardSwordFileReader.hpp +++ b/include/Athena/SkywardSwordFileReader.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -28,7 +29,7 @@ class SkywardSwordFileReader : public BinaryReader BINARYREADER_BASE(); public: - SkywardSwordFileReader(Uint8* data, Uint64 length); + SkywardSwordFileReader(atUint8* data, atUint64 length); SkywardSwordFileReader(const std::string& filename); SkywardSwordFile* read(); @@ -37,3 +38,4 @@ public: } // zelda #endif // __SSFILEREADER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/SkywardSwordFileWriter.hpp b/include/Athena/SkywardSwordFileWriter.hpp index 6ec6d22..0fd186f 100644 --- a/include/Athena/SkywardSwordFileWriter.hpp +++ b/include/Athena/SkywardSwordFileWriter.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -30,7 +31,7 @@ class SkywardSwordFileWriter : public BinaryWriter // Why does this fuck up my formatting in Qt Creator? BINARYWRITER_BASE public: - SkywardSwordFileWriter(Uint8* data, Uint64 len); + SkywardSwordFileWriter(atUint8* data, atUint64 len); SkywardSwordFileWriter(const std::string& filename); void write(SkywardSwordFile* file); @@ -38,3 +39,4 @@ public: } } #endif // __SSFILEWRITER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/SkywardSwordQuest.hpp b/include/Athena/SkywardSwordQuest.hpp index 3e07175..f611170 100644 --- a/include/Athena/SkywardSwordQuest.hpp +++ b/include/Athena/SkywardSwordQuest.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -26,19 +27,20 @@ namespace Athena class SkywardSwordQuest : public ZQuestFile { public: - SkywardSwordQuest(Uint8* data, Uint32 len); + SkywardSwordQuest(atUint8* data, atUint32 len); // TODO: Is len really needed? - void setSkipData(const Uint8* data, Uint32 len = 0x24); - Uint8* skipData() const; + void setSkipData(const atUint8* data, atUint32 len = 0x24); + atUint8* skipData() const; - Uint32 skipLength() const; + atUint32 skipLength() const; private: - Uint8* m_skipData; - Uint32 m_skipLength; + atUint8* m_skipData; + atUint32 m_skipLength; }; } // zelda #endif // SSQUEST_HPP +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/Sprite.hpp b/include/Athena/Sprite.hpp index 73a560e..ba2e798 100644 --- a/include/Athena/Sprite.hpp +++ b/include/Athena/Sprite.hpp @@ -78,20 +78,20 @@ public: #else QList stateIds() const; #endif - Uint32 stateCount() const; - void setCurrentState(Uint32 id); - Uint32 currentState() const; + atUint32 stateCount() const; + void setCurrentState(atUint32 id); + atUint32 currentState() const; bool addFrame(SpriteFrame* Frame); bool removeFrame(SpriteFrame* Frame); - SpriteFrame* Frame(Uint32 id); - void setFrame(Uint32 id); + SpriteFrame* Frame(atUint32 id); + void setFrame(atUint32 id); #ifndef ATHENA_USE_QT void setFrames(std::vector frames); #else void setFrames(QList frames); #endif - Uint32 frameCount() const; + atUint32 frameCount() const; #ifndef ATHENA_USE_QT std::vector frames() const; @@ -102,7 +102,7 @@ public: SpriteFile* container() const; void setCurrentFrame(SpriteFrame* frame); - void setCurrentFrame(Uint32 id); + void setCurrentFrame(atUint32 id); SpriteFrame* currentFrame() const; void advanceFrame(); @@ -129,8 +129,8 @@ private: QList m_stateIds; QList m_frames; #endif - Uint32 m_currentState; - Uint32 m_currentFrame; + atUint32 m_currentState; + atUint32 m_currentFrame; }; diff --git a/include/Athena/SpriteFile.hpp b/include/Athena/SpriteFile.hpp index 1d19b0c..4c04a05 100644 --- a/include/Athena/SpriteFile.hpp +++ b/include/Athena/SpriteFile.hpp @@ -53,32 +53,32 @@ public: /*! * \brief Major */ - static const Uint32 Major; + static const atUint32 Major; /*! * \brief Minor */ - static const Uint32 Minor; + static const atUint32 Minor; /*! * \brief Revision */ - static const Uint32 Revision; + static const atUint32 Revision; /*! * \brief Patch */ - static const Uint32 Build; + static const atUint32 Build; /*! * \brief Version */ - static const Uint32 Version; + static const atUint32 Version; /*! * \brief Magic */ - static const Uint32 Magic; + static const atUint32 Magic; /*! * \brief SSprite @@ -92,7 +92,7 @@ public: * \param originX * \param originY */ - SpriteFile(Uint32 width, Uint32 height, float originX, float originY); + SpriteFile(atUint32 width, atUint32 height, float originX, float originY); /*! * \brief SSpriteFile @@ -118,7 +118,7 @@ public slots: * \param width * \param height */ - void setSize(Uint32 width, Uint32 height); + void setSize(atUint32 width, atUint32 height); /*! * \brief setSize @@ -144,13 +144,13 @@ public slots: * \brief width * \return */ - Uint32 width() const; + atUint32 width() const; /*! * \brief height * \return */ - Uint32 height() const; + atUint32 height() const; /*! * \brief setOrigin @@ -209,14 +209,14 @@ public slots: * \param id * \return */ - STexture* texture(Uint32 id); + STexture* texture(atUint32 id); #ifndef ATHENA_USE_QT std::vector textures() const; #else QList textures() const; #endif - Uint32 textureCount() const; + atUint32 textureCount() const; /*! * \brief setTextures * \param textures @@ -250,7 +250,7 @@ public slots: QMap sprites() const; #endif - Uint32 spriteCount() const; + atUint32 spriteCount() const; #ifdef ATHENA_USE_QT signals: diff --git a/include/Athena/SpriteFileReader.hpp b/include/Athena/SpriteFileReader.hpp index cca6a08..f8c92f2 100644 --- a/include/Athena/SpriteFileReader.hpp +++ b/include/Athena/SpriteFileReader.hpp @@ -32,7 +32,7 @@ class SpriteFileReader : public BinaryReader { BINARYREADER_BASE(); public: - SpriteFileReader(Uint8* data, Uint64 length); + SpriteFileReader(atUint8* data, atUint64 length); SpriteFileReader(const std::string& filepath); Sakura::SpriteFile* readFile(); diff --git a/include/Athena/SpriteFileWriter.hpp b/include/Athena/SpriteFileWriter.hpp index 3aaa594..3c9e29c 100644 --- a/include/Athena/SpriteFileWriter.hpp +++ b/include/Athena/SpriteFileWriter.hpp @@ -32,7 +32,7 @@ class SpriteFileWriter : public BinaryWriter { BINARYWRITER_BASE; public: - SpriteFileWriter(Uint8* data, Uint64 length); + SpriteFileWriter(atUint8* data, atUint64 length); SpriteFileWriter(const std::string& filepath); diff --git a/include/Athena/SpriteFrame.hpp b/include/Athena/SpriteFrame.hpp index a93aced..576ebfd 100644 --- a/include/Athena/SpriteFrame.hpp +++ b/include/Athena/SpriteFrame.hpp @@ -71,7 +71,7 @@ public: QList parts() const; #endif - Uint32 partCount() const; + atUint32 partCount() const; void setRoot(Sprite* root); Sprite* root() const; diff --git a/include/Athena/SpritePart.hpp b/include/Athena/SpritePart.hpp index 2ec0fc4..92f3990 100644 --- a/include/Athena/SpritePart.hpp +++ b/include/Athena/SpritePart.hpp @@ -125,7 +125,7 @@ public: * \param width * \param height */ - void setSize(Uint32 width, Uint32 height); + void setSize(atUint32 width, atUint32 height); /*! * \brief setSize @@ -203,7 +203,7 @@ private: #endif bool m_flippedH; bool m_flippedV; - Uint32 m_frameIndex; + atUint32 m_frameIndex; }; } diff --git a/include/Athena/Stream.hpp b/include/Athena/Stream.hpp index aab052e..7007825 100644 --- a/include/Athena/Stream.hpp +++ b/include/Athena/Stream.hpp @@ -34,24 +34,24 @@ public: virtual bool isBigEndian() const= 0; virtual bool isLittleEndian()const= 0; virtual bool isOpen() const= 0; - virtual void seek(Int64, SeekOrigin)=0; + virtual void seek(atInt64, SeekOrigin)=0; virtual bool atEnd() const= 0; - virtual Uint64 position() const= 0; - virtual Uint64 length() const= 0; + virtual atUint64 position() const= 0; + virtual atUint64 length() const= 0; protected: virtual void seekBit (int){THROW_NOT_IMPLEMENTED_EXCEPTION();} // Reading virtual bool readBit() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Uint8 readUByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Int8 readByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Uint8* readUBytes(Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Int8* readBytes(Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Uint16 readUint16() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Int16 readInt16() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Uint32 readUint32() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Int32 readInt32() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Uint64 readUint64() {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual Int64 readInt64() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atUint8 readUByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atInt8 readByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atUint8* readUBytes(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atInt8* readBytes(atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atUint16 readUint16() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atInt16 readInt16() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atUint32 readUint32() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atInt32 readInt32() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atUint64 readUint64() {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual atInt64 readInt64() {THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual double readDouble() {THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual float readFloat() {THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual bool readBool() {THROW_NOT_IMPLEMENTED_EXCEPTION();} @@ -59,23 +59,23 @@ protected: virtual std::string readString() {THROW_NOT_IMPLEMENTED_EXCEPTION();} // Writing virtual void writeBit (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeUByte (Uint8){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeByte (Int8){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeUBytes(Uint8*, Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeBytes (Int8*, Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeUint16(Uint16){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeInt16 (Int16){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeUint32(Uint32){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeInt32 (Int32){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeUint64(Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void writeInt64 (Int64){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeUByte (atUint8){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeByte (atInt8){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeUBytes(atUint8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeBytes (atInt8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeUint16(atUint16){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeInt16 (atInt16){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeUint32(atUint32){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeInt32 (atInt32){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeUint64(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void writeInt64 (atInt64){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeDouble(double){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeFloat (float){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeBool (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeString(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeUnicode(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void fill(Uint8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} - virtual void fill(Int8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void fill(atUint8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void fill(atInt8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} }; } #endif // STREAM_HPP diff --git a/include/Athena/Types.hpp b/include/Athena/Types.hpp index 4630242..59903de 100644 --- a/include/Athena/Types.hpp +++ b/include/Athena/Types.hpp @@ -19,42 +19,42 @@ // 8 bits integer types #if UCHAR_MAX == 0xFF - typedef signed char Int8; - typedef unsigned char Uint8; + typedef signed char atInt8; + typedef unsigned char atUint8; #else #error No 8 bits integer type for this platform #endif // 16 bits integer types #if USHRT_MAX == 0xFFFF - typedef signed short Int16; - typedef unsigned short Uint16; + typedef signed short atInt16; + typedef unsigned short atUint16; #elif UINT_MAX == 0xFFFF - typedef signed int Int16; - typedef unsigned int Uint16; + typedef signed int atInt16; + typedef unsigned int atUint16; #elif ULONG_MAX == 0xFFFF - typedef signed long Int16; - typedef unsigned long Uint16; + typedef signed long atInt16; + typedef unsigned long atUint16; #else #error No 16 bits integer type for this platform #endif // 32 bits integer types #if USHRT_MAX == 0xFFFFFFFF - typedef signed short Int32; - typedef unsigned short Uint32; + typedef signed short atInt32; + typedef unsigned short atUint32; #elif UINT_MAX == 0xFFFFFFFF - typedef signed int Int32; - typedef unsigned int Uint32; + typedef signed int atInt32; + typedef unsigned int atUint32; #elif ULONG_MAX == 0xFFFFFFFF - typedef signed long Int32; - typedef unsigned long Uint32; + typedef signed long atInt32; + typedef unsigned long atUint32; #else #error No 32 bits integer type for this platform #endif -typedef signed long long Int64; -typedef unsigned long long Uint64; +typedef signed long long atInt64; +typedef unsigned long long atUint64; #ifndef NULL #ifdef __cplusplus diff --git a/include/Athena/Utility.hpp b/include/Athena/Utility.hpp index 6308229..0e660df 100644 --- a/include/Athena/Utility.hpp +++ b/include/Athena/Utility.hpp @@ -26,21 +26,21 @@ namespace Athena { namespace utility { -bool isEmpty(Int8*, Uint32); +bool isEmpty(atInt8*, atUint32); -Uint16 swapU16(Uint16 val ); -Int16 swap16 (Int16 val ); -Uint32 swapU32(Uint32 val); -Int32 swap32 (Int32 val ); -Uint64 swapU64(Uint64 val); -Int64 swap64 (Int64 val); +atUint16 swapU16(atUint16 val ); +atInt16 swap16 (atInt16 val ); +atUint32 swapU32(atUint32 val); +atInt32 swap32 (atInt32 val ); +atUint64 swapU64(atUint64 val); +atInt64 swap64 (atInt64 val); float swapFloat(float val); double swapDouble(double val); bool isSystemBigEndian(); -void fillRandom(Uint8 * rndArea, Uint8 count); +void fillRandom(atUint8 * rndArea, atUint8 count); std::vector split(const std::string &s, char delim); std::string join(const std::vector& elems, const std::string& delims); @@ -52,7 +52,7 @@ bool parseBool(const std::string& boolean, bool* valid = NULL); int countChar(const std::string& str, const char chr, int* lastOccur = NULL); -Uint64 fileSize(FILE* f); +atUint64 fileSize(FILE* f); } // utility } // Athena #endif diff --git a/include/Athena/WiiBanner.hpp b/include/Athena/WiiBanner.hpp index f1c83df..d0ca84e 100644 --- a/include/Athena/WiiBanner.hpp +++ b/include/Athena/WiiBanner.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -51,20 +52,20 @@ public: * \param m_banner * \param icons */ - WiiBanner(Uint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector icons); + WiiBanner(atUint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector icons); virtual ~WiiBanner(); /*! * \brief setGameID * \param id */ - void setGameID(Uint64 id); + void setGameID(atUint64 id); /*! * \brief gameID * \return */ - Uint64 gameID() const; + atUint64 gameID() const; /*! * \brief setBannerImage @@ -82,13 +83,13 @@ public: * \brief setBannerSize * \param size */ - void setBannerSize(Uint32 size); + void setBannerSize(atUint32 size); /*! * \brief bannerSize * \return */ - Uint32 bannerSize() const; + atUint32 bannerSize() const; /*! * \brief setTitle @@ -125,14 +126,14 @@ public: * \param id * \param icon */ - void setIcon(Uint32 id, WiiImage* icon); + void setIcon(atUint32 id, WiiImage* icon); /*! * \brief getIcon * \param id * \return */ - WiiImage* getIcon(Uint32 id) const; + WiiImage* getIcon(atUint32 id) const; /*! * \brief icons @@ -144,45 +145,45 @@ public: * \brief setAnimationSpeed * \param animSpeed */ - void setAnimationSpeed(Uint16 animSpeed); + void setAnimationSpeed(atUint16 animSpeed); /*! * \brief animationSpeed * \return */ - Uint16 animationSpeed() const; + atUint16 animationSpeed() const; /*! * \brief setPermissions * \param permissions */ - void setPermissions(Uint8 permissions); + void setPermissions(atUint8 permissions); /*! * \brief permissions * \return */ - Uint8 permissions() const; + atUint8 permissions() const; /*! * \brief setFlags * \param flags */ - void setFlags(Uint32 flags); + void setFlags(atUint32 flags); /*! * \brief flags * \return */ - Uint32 flags() const; + atUint32 flags() const; protected: private: - Uint64 m_gameId; + atUint64 m_gameId; WiiImage* m_banner; - Uint32 m_animSpeed; - Uint8 m_permissions; - Uint32 m_flags; - Uint32 m_bannerSize; + atUint32 m_animSpeed; + atUint8 m_permissions; + atUint32 m_flags; + atUint32 m_bannerSize; std::vector m_icons; std::string m_title; std::string m_subtitle; @@ -190,3 +191,4 @@ private: } // zelda #endif // WIIBANNER_H +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/WiiFile.hpp b/include/Athena/WiiFile.hpp index a3af946..85c196e 100644 --- a/include/Athena/WiiFile.hpp +++ b/include/Athena/WiiFile.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -23,9 +24,9 @@ namespace Athena { -const Uint8 SD_KEY [16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d}; -const Uint8 SD_IV [16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98}; -const Uint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93}; +const atUint8 SD_KEY [16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d}; +const atUint8 SD_IV [16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98}; +const atUint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93}; /*! \class WiiFile * \brief Wii file container class @@ -79,7 +80,7 @@ public: * \param data * \param length */ - WiiFile(const std::string& filename, Uint8 permissions, const Uint8* data, Uint32 length); + WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length); virtual ~WiiFile(); /*! @@ -98,12 +99,12 @@ public: * \brief setData * \param data */ - void setData(const Uint8* data); + void setData(const atUint8* data); /*! * \brief data * \return */ - Uint8* data() const; + atUint8* data() const; /*! * \brief setLength @@ -121,25 +122,25 @@ public: * \brief setPermissions * \param permissions */ - void setPermissions(const Uint8 permissions); + void setPermissions(const atUint8 permissions); /*! * \brief permissions * \return */ - Uint8 permissions() const; + atUint8 permissions() const; /*! * \brief setAttributes * \param attr */ - void setAttributes(const Uint8 attr); + void setAttributes(const atUint8 attr); /*! * \brief attributes * \return */ - Uint8 attributes() const; + atUint8 attributes() const; /*! * \brief setType @@ -167,13 +168,14 @@ public: protected: private: - Uint8 m_permissions; - Uint8 m_attributes; + atUint8 m_permissions; + atUint8 m_attributes; Type m_type; std::string m_filename; int m_fileLen; - Uint8* m_fileData; + atUint8* m_fileData; }; } // zelda #endif // WIIFILE_H +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/WiiImage.hpp b/include/Athena/WiiImage.hpp index 9a8ab21..100701d 100644 --- a/include/Athena/WiiImage.hpp +++ b/include/Athena/WiiImage.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -37,7 +38,7 @@ public: * \param height * \param data */ - WiiImage(Uint32 width, Uint32 height, Uint8* data); + WiiImage(atUint32 width, atUint32 height, atUint8* data); /*! * \brief ~WiiImage @@ -48,50 +49,51 @@ public: * \brief setWidth * \param width */ - void setWidth(const Uint32 width); + void setWidth(const atUint32 width); /*! * \brief width * \return */ - Uint32 width() const; + atUint32 width() const; /*! * \brief setHeight * \param height */ - void setHeight(const Uint32 height); + void setHeight(const atUint32 height); /*! * \brief height * \return */ - Uint32 height() const; + atUint32 height() const; /*! * \brief setData * \param data */ - void setData(const Uint8* data); + void setData(const atUint8* data); /*! * \brief data * \return */ - Uint8* data(); + atUint8* data(); /*! * \brief toRGBA * \return */ - Uint8* toRGBA(); + atUint8* toRGBA(); private: - Uint32 m_width; - Uint32 m_height; - Uint8* m_data; + atUint32 m_width; + atUint32 m_height; + atUint8* m_data; }; } // zelda #endif // WIIIMAGE_HPP +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/WiiSaveReader.hpp b/include/Athena/WiiSaveReader.hpp index 257f12b..4b2d61f 100644 --- a/include/Athena/WiiSaveReader.hpp +++ b/include/Athena/WiiSaveReader.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -45,7 +46,7 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - WiiSaveReader(const Uint8*, Uint64); + WiiSaveReader(const atUint8*, atUint64); /*! \brief This constructor creates an instance from a file on disk. * @@ -61,10 +62,11 @@ public: private: WiiBanner* readBanner(); WiiFile* readFile(); - WiiImage* readImage(Uint32 width, Uint32 height); - void readCerts(Uint32 totalSize); + WiiImage* readImage(atUint32 width, atUint32 height); + void readCerts(atUint32 totalSize); }; } // io } // zelda #endif // __WII_SAVE_READER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/WiiSaveWriter.hpp b/include/Athena/WiiSaveWriter.hpp index 9efdcd7..6edd09f 100644 --- a/include/Athena/WiiSaveWriter.hpp +++ b/include/Athena/WiiSaveWriter.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -56,15 +57,16 @@ public: * \param filepath * \return */ - bool writeSave(WiiSave* save, Uint8* macAddress, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId, const std::string& filepath = ""); + bool writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId, const std::string& filepath = ""); private: void writeBanner(WiiBanner* banner); - Uint32 writeFile(WiiFile* file); + atUint32 writeFile(WiiFile* file); void writeImage(WiiImage* image); - void writeCerts(Uint32 filesSize, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId); + void writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId); }; } // io } // zelda #endif // __WII_SAVE_WRITER_HPP__ +#endif // ATHENA_NO_SAVES diff --git a/include/Athena/ZQuestFile.hpp b/include/Athena/ZQuestFile.hpp index ce49264..f21e30e 100644 --- a/include/Athena/ZQuestFile.hpp +++ b/include/Athena/ZQuestFile.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -16,6 +17,7 @@ #ifndef ZQUEST_HPP #define ZQUEST_HPP + #include "Athena/Global.hpp" #include #include @@ -34,24 +36,24 @@ public: /*! * \brief The current major version of the ZQuest format */ - static const Uint32 Major; + static const atUint32 Major; /*! * \brief The current minor version of the ZQuest format */ - static const Uint32 Minor; + static const atUint32 Minor; /*! * \brief The current revision of the ZQuest format */ - static const Uint32 Revision; + static const atUint32 Revision; /*! * \brief The current version of the ZQuest format */ - static const Uint32 Version; + static const atUint32 Version; /*! * \brief The magic number used to identify the file e.g. "ZQS1" */ - static const Uint32 Magic; + static const atUint32 Magic; /*! * \enum Game @@ -96,7 +98,7 @@ public: * \param data * \param length */ - ZQuestFile(Game game, Endian endian, Uint8* data, Uint32 length, const std::string& gameString = std::string()); + ZQuestFile(Game game, Endian endian, atUint8* data, atUint32 length, const std::string& gameString = std::string()); ~ZQuestFile(); /*! @@ -128,19 +130,19 @@ public: * \param data The data to assign * \param length The length of the data */ - void setData(Uint8* data, Uint32 length); + void setData(atUint8* data, atUint32 length); /*! * \brief data * \return */ - Uint8* data() const; + atUint8* data() const; /*! * \brief length * \return */ - Uint32 length() const; + atUint32 length() const; void setGameString(const std::string& gameString); /*! @@ -154,11 +156,12 @@ private: Game m_game; std::string m_gameString; Endian m_endian; - Uint8* m_data; - Uint32 m_length; + atUint8* m_data; + atUint32 m_length; // Game strings support }; } // zelda #endif // ZQUEST_HPP +#endif // ATHENA_NO_ZQUEST diff --git a/include/Athena/ZQuestFileReader.hpp b/include/Athena/ZQuestFileReader.hpp index b5fe2d4..42acd11 100644 --- a/include/Athena/ZQuestFileReader.hpp +++ b/include/Athena/ZQuestFileReader.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -38,7 +39,7 @@ public: * \param data * \param length */ - ZQuestFileReader(Uint8* data, Uint64 length); + ZQuestFileReader(atUint8* data, atUint64 length); /*! * \brief ZQuestFileReader @@ -57,3 +58,5 @@ public: } // zelda #endif // __ZQUESTFILEREADER_HPP__ + +#endif // ATHENA_NO_ZQUEST diff --git a/include/Athena/ZQuestFileWriter.hpp b/include/Athena/ZQuestFileWriter.hpp index a8fa177..e319ce5 100644 --- a/include/Athena/ZQuestFileWriter.hpp +++ b/include/Athena/ZQuestFileWriter.hpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -38,7 +39,7 @@ public: * \param data * \param length */ - ZQuestFileWriter(Uint8* data, Uint64 length); + ZQuestFileWriter(atUint8* data, atUint64 length); /*! * \brief ZQuestFileWriter @@ -57,3 +58,5 @@ public: } // io } // zelda #endif // __ZQUESTFILEWRITER_HPP__ + +#endif // ATHENA_NO_ZQUEST diff --git a/include/aes.h b/include/aes.h index a81d2df..d454e17 100644 --- a/include/aes.h +++ b/include/aes.h @@ -7,9 +7,9 @@ extern "C" { #endif -void aes_encrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len); -void aes_decrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len); -void aes_set_key(const Uint8 *key ); +void aes_encrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len); +void aes_decrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len); +void aes_set_key(const atUint8 *key ); #ifdef __cplusplus } diff --git a/include/bn.h b/include/bn.h index 8b3429a..851ced8 100644 --- a/include/bn.h +++ b/include/bn.h @@ -4,12 +4,12 @@ #ifndef __DOXYGEN_IGNORE__ #include "Athena/Types.hpp" -int bn_compare(Uint8 *a, Uint8 *b, Uint32 n); -void bn_sub_modulus(Uint8 *a, Uint8 *N, Uint32 n); -void bn_add(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n); -void bn_mul(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n); -void bn_exp(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n, Uint8 *e, Uint32 en); -void bn_inv(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n); +int bn_compare(atUint8 *a, atUint8 *b, atUint32 n); +void bn_sub_modulus(atUint8 *a, atUint8 *N, atUint32 n); +void bn_add(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n); +void bn_mul(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n); +void bn_exp(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n, atUint8 *e, atUint32 en); +void bn_inv(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n); #endif // __DOXYGEN_IGNORE__ #endif // BN_H diff --git a/include/ec.h b/include/ec.h index 37df017..85cb494 100644 --- a/include/ec.h +++ b/include/ec.h @@ -2,9 +2,9 @@ #define EC_H #include "Athena/Types.hpp" -bool check_ec ( Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash ); -void make_ec_cert ( Uint8 *cert, Uint8 *sig, char *signer, char *name, Uint8 *priv, Uint32 key_id ); -void generate_ecdsa( Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash ); +bool check_ec ( atUint8 *ng, atUint8 *ap, atUint8 *sig, atUint8 *sig_hash ); +void make_ec_cert ( atUint8 *cert, atUint8 *sig, char *signer, char *name, atUint8 *priv, atUint32 key_id ); +void generate_ecdsa( atUint8 *R, atUint8 *S, atUint8 *k, atUint8 *hash ); #endif // EC_H diff --git a/include/lzo.h b/include/lzo.h index 0d8be34..d702f9a 100644 --- a/include/lzo.h +++ b/include/lzo.h @@ -36,7 +36,7 @@ typedef unsigned char uint8_t; extern "C" { #endif -int lzo1x_decode(Uint8 *out, Int32 *outlen, Uint8 *in, Int32 *inlen); +int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen); #ifdef __cplusplus } diff --git a/include/sha1.h b/include/sha1.h index b6bd088..7c6dc1a 100644 --- a/include/sha1.h +++ b/include/sha1.h @@ -37,7 +37,7 @@ void SHA1Input( SHA1Context *, -Uint8* getSha1( Uint8 * stuff, Uint32 stuff_size ); +atUint8* getSha1( atUint8 * stuff, atUint32 stuff_size ); #ifdef __cplusplus } diff --git a/src/Athena/ALTTPFile.cpp b/src/Athena/ALTTPFile.cpp index 2865975..5ba8956 100644 --- a/src/Athena/ALTTPFile.cpp +++ b/src/Athena/ALTTPFile.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -29,7 +30,7 @@ ALTTPFile::ALTTPFile(std::vector quests, std::vector b { } -void ALTTPFile::setQuest(Uint32 id, ALTTPQuest* val) +void ALTTPFile::setQuest(atUint32 id, ALTTPQuest* val) { if (id > m_quests.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -41,7 +42,7 @@ std::vector ALTTPFile::questList() const { return m_quests; } -ALTTPQuest* ALTTPFile::quest(Uint32 id) const +ALTTPQuest* ALTTPFile::quest(atUint32 id) const { if (id > m_quests.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -49,8 +50,10 @@ ALTTPQuest* ALTTPFile::quest(Uint32 id) const return m_quests[id]; } -Uint32 ALTTPFile::questCount() const +atUint32 ALTTPFile::questCount() const { return m_quests.size(); } } // zelda + +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/ALTTPFileReader.cpp b/src/Athena/ALTTPFileReader.cpp index bbf8bcc..3f3f7ed 100644 --- a/src/Athena/ALTTPFileReader.cpp +++ b/src/Athena/ALTTPFileReader.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -23,7 +24,7 @@ namespace Athena namespace io { -ALTTPFileReader::ALTTPFileReader(Uint8* data, Uint64 length) +ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length) : base(data, length) { } @@ -38,17 +39,17 @@ ALTTPFile* ALTTPFileReader::readFile() std::vector quests; std::vector backup; - for (Uint32 i = 0; i < 6; i++) + for (atUint32 i = 0; i < 6; i++) { // Temporary values to use for each save ALTTPQuest* quest = new ALTTPQuest(); std::vector roomFlags; std::vector owEvents; - std::vector dungeonKeys; - std::vector oldmanFlags; - std::vector unknown1; - std::vector playerName; - std::vector dungeonDeaths; + std::vector dungeonKeys; + std::vector oldmanFlags; + std::vector unknown1; + std::vector playerName; + std::vector dungeonDeaths; int j = 0x140; while ((j--) > 0) @@ -233,3 +234,5 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() } // io } // zelda + +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/ALTTPFileWriter.cpp b/src/Athena/ALTTPFileWriter.cpp index 4ac330d..3786beb 100644 --- a/src/Athena/ALTTPFileWriter.cpp +++ b/src/Athena/ALTTPFileWriter.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -24,7 +25,7 @@ namespace Athena namespace io { -ALTTPFileWriter::ALTTPFileWriter(Uint8* data, Uint64 length) +ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length) : base(data, length) { } @@ -37,7 +38,7 @@ ALTTPFileWriter::ALTTPFileWriter(const std::string& filename) void ALTTPFileWriter::writeFile(ALTTPFile* file) { ALTTPQuest* quest = NULL; - for (Uint32 i = 0; i < 6; i++) + for (atUint32 i = 0; i < 6; i++) { if (i < 3) quest = file->quest(i); @@ -54,7 +55,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) writeOverworldEvent(quest->overworldEvent(j)); } - base::writeBytes((Int8*)quest->inventory(), sizeof(ALTTPInventory)); + base::writeBytes((atInt8*)quest->inventory(), sizeof(ALTTPInventory)); base::writeUint16(quest->rupeeMax()); base::writeUint16(quest->rupeeCurrent()); writeDungeonItems(quest->compasses()); @@ -87,23 +88,23 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) base::writeBit(abilities.Read); base::writeBit(abilities.Unknown2); ALTTPCrystals crystals = quest->crystals(); - base::writeBytes((Int8*)&crystals, sizeof(ALTTPCrystals)); + base::writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals)); ALTTPMagicUsage magicUsage = quest->magicUsage(); - base::writeBytes((Int8*)&magicUsage, sizeof(ALTTPMagicUsage)); + base::writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage)); for (int j = 0; j < 0x010; j++) base::writeByte(quest->dungeonKeys(j)); base::seek(0x039); - base::writeByte((Int8)quest->progressIndicator()); + base::writeByte((atInt8)quest->progressIndicator()); ALTTPProgressFlags1 progress1 = quest->progressFlags1(); - base::writeBytes((Int8*)&progress1, sizeof(ALTTPProgressFlags1)); + base::writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1)); base::writeByte(quest->mapIcon()); base::writeByte(quest->startLocation()); ALTTPProgressFlags2 progress2 = quest->progressFlags2(); - base::writeBytes((Int8*)&progress2, sizeof(ALTTPProgressFlags2)); + base::writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2)); ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator(); - base::writeBytes((Int8*)&indicator, 1); + base::writeBytes((atInt8*)&indicator, 1); base::seek(1); base::writeByte(quest->tagAlong()); @@ -184,7 +185,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) base::writeBit(flags.SewerPassage); } -Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game) +atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game) { /* * ALTTP's checksum is very basic @@ -202,10 +203,10 @@ Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game) */ // First we start at 0 - Uint16 sum = 0; - for (Uint32 i = 0; i < 0x4FE; i += 2) + atUint16 sum = 0; + for (atUint32 i = 0; i < 0x4FE; i += 2) // Add each word one by one - sum += *(Uint16*)(m_data + (i + (0x500 * game))); + sum += *(atUint16*)(m_data + (i + (0x500 * game))); // Subtract it from 0x5a5a to get our true checksum return (0x5a5a - sum); @@ -220,3 +221,4 @@ Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game) } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/ALTTPQuest.cpp b/src/Athena/ALTTPQuest.cpp index ccc759a..e5d8eab 100644 --- a/src/Athena/ALTTPQuest.cpp +++ b/src/Athena/ALTTPQuest.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -38,7 +39,7 @@ void ALTTPQuest::setRoomFlags(std::vector rf) m_roomFlags = rf; } -void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, Uint32 id) +void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, atUint32 id) { m_roomFlags[id] = rf; } @@ -48,7 +49,7 @@ std::vector ALTTPQuest::roomFlags() return m_roomFlags; } -ALTTPRoomFlags* ALTTPQuest::roomFlags(Uint32 id) +ALTTPRoomFlags* ALTTPQuest::roomFlags(atUint32 id) { return m_roomFlags[id]; } @@ -58,7 +59,7 @@ void ALTTPQuest::setOverworldEvents(std::vector ow) m_overworldEvents = ow; } -void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, Uint32 id) +void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id) { m_overworldEvents[id] = ow; } @@ -68,7 +69,7 @@ std::vector ALTTPQuest::overworldEvents() const return m_overworldEvents; } -ALTTPOverworldEvent* ALTTPQuest::overworldEvent(Uint32 id) const +ALTTPOverworldEvent* ALTTPQuest::overworldEvent(atUint32 id) const { if (id > m_overworldEvents.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -85,22 +86,22 @@ ALTTPInventory* ALTTPQuest::inventory() const return m_inventory; } -void ALTTPQuest::setRupeeMax(Uint16 val) +void ALTTPQuest::setRupeeMax(atUint16 val) { m_rupeeMax = val; } -Uint16 ALTTPQuest::rupeeMax() const +atUint16 ALTTPQuest::rupeeMax() const { return m_rupeeMax; } -void ALTTPQuest::setRupeeCurrent(Uint16 val) +void ALTTPQuest::setRupeeCurrent(atUint16 val) { m_rupeeCurrent = val; } -Uint16 ALTTPQuest::rupeeCurrent() const +atUint16 ALTTPQuest::rupeeCurrent() const { return m_rupeeCurrent; } @@ -135,91 +136,91 @@ ALTTPDungeonItemFlags ALTTPQuest::dungeonMaps() const return m_dungeonMaps; } -void ALTTPQuest::setWishingPond(Uint16 val) +void ALTTPQuest::setWishingPond(atUint16 val) { m_wishingPond = val; } -Uint16 ALTTPQuest::wishingPond() const +atUint16 ALTTPQuest::wishingPond() const { return m_wishingPond; } -void ALTTPQuest::setHealthMax(Uint8 val) +void ALTTPQuest::setHealthMax(atUint8 val) { m_healthMax = val; } -Uint8 ALTTPQuest::healthMax() const +atUint8 ALTTPQuest::healthMax() const { return m_healthMax; } -void ALTTPQuest::setHealth(Uint8 val) +void ALTTPQuest::setHealth(atUint8 val) { m_health = val; } -Uint8 ALTTPQuest::health() const +atUint8 ALTTPQuest::health() const { return m_health; } -void ALTTPQuest::setMagicPower(Uint8 val) +void ALTTPQuest::setMagicPower(atUint8 val) { m_magicPower = val; } -Uint8 ALTTPQuest::magicPower() const +atUint8 ALTTPQuest::magicPower() const { return m_magicPower; } -void ALTTPQuest::setKeys(Uint8 val) +void ALTTPQuest::setKeys(atUint8 val) { m_keys = val; } -Uint8 ALTTPQuest::keys() const +atUint8 ALTTPQuest::keys() const { return m_keys; } -void ALTTPQuest::setBombUpgrades(Uint8 val) +void ALTTPQuest::setBombUpgrades(atUint8 val) { m_bombUpgrades = val; } -Uint8 ALTTPQuest::bombUpgrades() const +atUint8 ALTTPQuest::bombUpgrades() const { return m_bombUpgrades; } -void ALTTPQuest::setArrowUpgrades(Uint8 val) +void ALTTPQuest::setArrowUpgrades(atUint8 val) { m_arrowUpgrades = val; } -Uint8 ALTTPQuest::arrowUpgrades() const +atUint8 ALTTPQuest::arrowUpgrades() const { return m_arrowUpgrades; } -void ALTTPQuest::setHealthFiller(Uint8 val) +void ALTTPQuest::setHealthFiller(atUint8 val) { m_heartFiller = val; } -Uint8 ALTTPQuest::healthFiller() const +atUint8 ALTTPQuest::healthFiller() const { return m_heartFiller; } -void ALTTPQuest::setMagicFiller(Uint8 val) +void ALTTPQuest::setMagicFiller(atUint8 val) { m_heartFiller = val; } -Uint8 ALTTPQuest::magicFiller() const +atUint8 ALTTPQuest::magicFiller() const { return m_heartFiller; } @@ -234,31 +235,31 @@ ALTTPPendants ALTTPQuest::pendants() const return m_pendants; } -void ALTTPQuest::setBombFiller(Uint8 val) +void ALTTPQuest::setBombFiller(atUint8 val) { m_bombFiller = val; } -Uint8 ALTTPQuest::bombFiller() const +atUint8 ALTTPQuest::bombFiller() const { return m_bombFiller; } -void ALTTPQuest::setArrowFiller(Uint8 val) +void ALTTPQuest::setArrowFiller(atUint8 val) { m_arrowFiller = val; } -Uint8 ALTTPQuest::arrowFiller() const +atUint8 ALTTPQuest::arrowFiller() const { return m_arrowFiller; } -void ALTTPQuest::setArrows(Uint8 val) +void ALTTPQuest::setArrows(atUint8 val) { m_arrows = val; } -Uint8 ALTTPQuest::arrows() const +atUint8 ALTTPQuest::arrows() const { return m_arrows; } @@ -293,12 +294,12 @@ ALTTPMagicUsage ALTTPQuest::magicUsage() const return m_magicUsage; } -void ALTTPQuest::setDungeonKeys(std::vector val) +void ALTTPQuest::setDungeonKeys(std::vector val) { m_dungeonKeys = val; } -void ALTTPQuest::setDungeonKeys(Uint32 id, Uint8 val) +void ALTTPQuest::setDungeonKeys(atUint32 id, atUint8 val) { if (id > m_dungeonKeys.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -306,7 +307,7 @@ void ALTTPQuest::setDungeonKeys(Uint32 id, Uint8 val) m_dungeonKeys[id] = val; } -Uint8 ALTTPQuest::dungeonKeys(Uint32 id) const +atUint8 ALTTPQuest::dungeonKeys(atUint32 id) const { if (id > m_dungeonKeys.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -314,7 +315,7 @@ Uint8 ALTTPQuest::dungeonKeys(Uint32 id) const return m_dungeonKeys[id]; } -Uint32 ALTTPQuest::dungeonCount() const +atUint32 ALTTPQuest::dungeonCount() const { return m_dungeonKeys.size(); } @@ -390,12 +391,12 @@ ALTTPTagAlong ALTTPQuest::tagAlong() const return m_tagAlong; } -void ALTTPQuest::setOldManFlags(std::vector flags) +void ALTTPQuest::setOldManFlags(std::vector flags) { m_oldManFlags = flags; } -void ALTTPQuest::setOldManFlag(Uint32 id, Uint8 val) +void ALTTPQuest::setOldManFlag(atUint32 id, atUint8 val) { if (id > m_oldManFlags.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -403,7 +404,7 @@ void ALTTPQuest::setOldManFlag(Uint32 id, Uint8 val) m_oldManFlags[id] = val; } -Uint8 ALTTPQuest::oldManFlag(Uint32 id) +atUint8 ALTTPQuest::oldManFlag(atUint32 id) { if (id > m_oldManFlags.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -411,27 +412,27 @@ Uint8 ALTTPQuest::oldManFlag(Uint32 id) return m_oldManFlags[id]; } -Uint32 ALTTPQuest::oldManFlagCount() const +atUint32 ALTTPQuest::oldManFlagCount() const { return m_oldManFlags.size(); } -void ALTTPQuest::setBombFlag(Uint8 flag) +void ALTTPQuest::setBombFlag(atUint8 flag) { m_bombFlag = flag; } -Uint8 ALTTPQuest::bombFlag() const +atUint8 ALTTPQuest::bombFlag() const { return m_bombFlag; } -void ALTTPQuest::setUnknown1(std::vector flags) +void ALTTPQuest::setUnknown1(std::vector flags) { m_unknown1 = flags; } -void ALTTPQuest::setUnknown1(Uint32 id, Uint8 val) +void ALTTPQuest::setUnknown1(atUint32 id, atUint8 val) { if (id > m_unknown1.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -439,7 +440,7 @@ void ALTTPQuest::setUnknown1(Uint32 id, Uint8 val) m_unknown1[id] = val; } -Uint8 ALTTPQuest::unknown1(Uint32 id) +atUint8 ALTTPQuest::unknown1(atUint32 id) { if (id > m_unknown1.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -447,12 +448,12 @@ Uint8 ALTTPQuest::unknown1(Uint32 id) return m_unknown1[id]; } -Uint32 ALTTPQuest::unknown1Count() const +atUint32 ALTTPQuest::unknown1Count() const { return m_unknown1.size(); } -void ALTTPQuest::setPlayerName(std::vector playerName) +void ALTTPQuest::setPlayerName(std::vector playerName) { m_playerName = playerName; } @@ -464,30 +465,30 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) m_playerName.clear(); - for (Uint32 i = 0; i < 6; i++) + for (atUint32 i = 0; i < 6; i++) { if (i > playerName.size() - 1) { - m_playerName.push_back((Uint16)0xA9); + m_playerName.push_back((atUint16)0xA9); continue; } char c = playerName[i]; if (c >= 'A' && c <= 'P' && c != 'I') { - m_playerName.push_back((Uint16)(c - 'A')); + m_playerName.push_back((atUint16)(c - 'A')); continue; } if (c >= 'Q' && c <= 'Z') { - std::cout << std::hex << (Uint16)((c - 'Q') + 0x20) << std::endl; - m_playerName.push_back((Uint16)((c - 'Q') + 0x20)); + std::cout << std::hex << (atUint16)((c - 'Q') + 0x20) << std::endl; + m_playerName.push_back((atUint16)((c - 'Q') + 0x20)); continue; } if (c >= 'a' && c <= 'f') { - std::cout << std::hex << (Uint16)((c - 'a') + 0x2A) << std::endl; - m_playerName.push_back((Uint16)((c - 'a') + 0x2A)); + std::cout << std::hex << (atUint16)((c - 'a') + 0x2A) << std::endl; + m_playerName.push_back((atUint16)((c - 'a') + 0x2A)); continue; } if (c >= 'g' && c <= 'v') @@ -502,22 +503,22 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) m_playerName.push_back(0x44); continue; } - m_playerName.push_back((Uint16)((c - 'g') + 0x40)); + m_playerName.push_back((atUint16)((c - 'g') + 0x40)); continue; } if (c >= 'w' && c <= 'z') { - m_playerName.push_back((Uint16)((c - 'w') + 0x60)); + m_playerName.push_back((atUint16)((c - 'w') + 0x60)); continue; } if (c >= '0' && c <= '9') { - m_playerName.push_back((Uint16)((c - '0') + 0x64)); + m_playerName.push_back((atUint16)((c - '0') + 0x64)); continue; } if (c == '-' || c == '.') { - m_playerName.push_back((Uint16)(c - '-') + 0x80); + m_playerName.push_back((atUint16)(c - '-') + 0x80); continue; } @@ -533,7 +534,7 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) } } -std::vector ALTTPQuest::playerName() const +std::vector ALTTPQuest::playerName() const { return m_playerName; } @@ -541,11 +542,11 @@ std::vector ALTTPQuest::playerName() const std::string ALTTPQuest::playerNameToString() const { std::string ret; - std::vector::const_iterator iter = m_playerName.begin(); + std::vector::const_iterator iter = m_playerName.begin(); for (; iter != m_playerName.end(); ++iter) { - Int16 c = *iter; + atInt16 c = *iter; if (c >= 0x00 && c <= 0x0F) { @@ -615,12 +616,12 @@ bool ALTTPQuest::valid() return m_valid; } -void ALTTPQuest::setDungeonDeathTotals(std::vector val) +void ALTTPQuest::setDungeonDeathTotals(std::vector val) { m_dungeonDeathTotals = val; } -void ALTTPQuest::setDungeonDeathTotal(Uint32 id, Uint16 val) +void ALTTPQuest::setDungeonDeathTotal(atUint32 id, atUint16 val) { if (id > m_dungeonDeathTotals.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -628,7 +629,7 @@ void ALTTPQuest::setDungeonDeathTotal(Uint32 id, Uint16 val) m_dungeonDeathTotals[id] = val; } -Uint16 ALTTPQuest::dungeonDeathTotal(Uint32 id) const +atUint16 ALTTPQuest::dungeonDeathTotal(atUint32 id) const { if (id > m_dungeonDeathTotals.size()) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -636,48 +637,49 @@ Uint16 ALTTPQuest::dungeonDeathTotal(Uint32 id) const return m_dungeonDeathTotals[id]; } -Uint16 ALTTPQuest::dungeonDeathTotalCount() const +atUint16 ALTTPQuest::dungeonDeathTotalCount() const { return m_dungeonDeathTotals.size(); } -void ALTTPQuest::setUnknown2(Uint16 val) +void ALTTPQuest::setUnknown2(atUint16 val) { m_unknown2 = val; } -Uint16 ALTTPQuest::unknown2() const +atUint16 ALTTPQuest::unknown2() const { return m_unknown2; } -void ALTTPQuest::setDeathSaveCount(Uint16 val) +void ALTTPQuest::setDeathSaveCount(atUint16 val) { m_deathSaveCount = val; } -Uint16 ALTTPQuest::deathSaveCount() const +atUint16 ALTTPQuest::deathSaveCount() const { return m_deathSaveCount; } -void ALTTPQuest::setPostGameDeathCounter(Int16 val) +void ALTTPQuest::setPostGameDeathCounter(atInt16 val) { m_postGameDeathCounter = val; } -Int16 ALTTPQuest::postGameDeathCounter() const +atInt16 ALTTPQuest::postGameDeathCounter() const { return m_postGameDeathCounter; } -void ALTTPQuest::setChecksum(Uint16 checksum) +void ALTTPQuest::setChecksum(atUint16 checksum) { m_checksum = checksum; } -Uint16 ALTTPQuest::checksum() const +atUint16 ALTTPQuest::checksum() const { return m_checksum; } } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/BinaryReader.cpp b/src/Athena/BinaryReader.cpp index 36a04d3..b50167a 100644 --- a/src/Athena/BinaryReader.cpp +++ b/src/Athena/BinaryReader.cpp @@ -34,7 +34,7 @@ namespace Athena { namespace io { -BinaryReader::BinaryReader(const Uint8* data, Uint64 length) +BinaryReader::BinaryReader(const atUint8* data, atUint64 length) : m_length(length), m_position(0), m_bitPosition(0), @@ -46,7 +46,7 @@ BinaryReader::BinaryReader(const Uint8* data, Uint64 length) if (length == 0) THROW_INVALID_OPERATION_EXCEPTION("length cannot be 0"); - m_data = new Uint8[m_length]; + m_data = new atUint8[m_length]; memcpy(m_data, data, m_length); } @@ -93,22 +93,22 @@ bool BinaryReader::isOpen() const return m_data != nullptr; } -void BinaryReader::seek(Int64 position, SeekOrigin origin) +void BinaryReader::seek(atInt64 position, SeekOrigin origin) { switch (origin) { case SeekOrigin::Begin: - if ((position < 0 || (Int64)position > (Int64)m_length)) + if ((position < 0 || (atInt64)position > (atInt64)m_length)) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position); m_position = position; break; case SeekOrigin::Current: - if ((((Int64)m_position + position) < 0 || (m_position + position) > m_length)) + if ((((atInt64)m_position + position) < 0 || (m_position + position) > m_length)) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position); m_position += position; break; case SeekOrigin::End: - if ((((Int64)m_length - position < 0) || (m_length - position) > m_length)) + if ((((atInt64)m_length - position < 0) || (m_length - position) > m_length)) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position); m_position = m_length - position; break; @@ -120,30 +120,30 @@ bool BinaryReader::atEnd() const return m_position >= m_length; } -Uint64 BinaryReader::position() const +atUint64 BinaryReader::position() const { return m_position; } -Uint64 BinaryReader::length() const +atUint64 BinaryReader::length() const { return m_length; } -void BinaryReader::setData(const Uint8* data, Uint64 length) +void BinaryReader::setData(const atUint8* data, atUint64 length) { if (m_data) delete[] m_data; - m_data = (Uint8*)data; + m_data = (atUint8*)data; m_length = length; m_position = 0; m_bitPosition = 0; } -Uint8* BinaryReader::data() const +atUint8* BinaryReader::data() const { - Uint8* ret = new Uint8[m_length]; + atUint8* ret = new atUint8[m_length]; memset(ret, 0, m_length); memcpy(ret, m_data, m_length); return ret; @@ -177,19 +177,19 @@ bool BinaryReader::readBit() if (m_position > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - bool ret = (*(Uint8*)(m_data + m_position) & (1 << m_bitPosition)); + bool ret = (*(atUint8*)(m_data + m_position) & (1 << m_bitPosition)); m_bitPosition++; if (m_bitPosition > 7) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } return ret; } -Int8 BinaryReader::readByte() +atInt8 BinaryReader::readByte() { if (!m_data) loadData(); @@ -197,15 +197,15 @@ Int8 BinaryReader::readByte() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + 1 > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - return *(Int8*)(m_data + m_position++); + return *(atInt8*)(m_data + m_position++); } -Uint8 BinaryReader::readUByte() +atUint8 BinaryReader::readUByte() { if (!m_data) loadData(); @@ -216,20 +216,20 @@ Uint8 BinaryReader::readUByte() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + 1 > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - return *(Uint8*)(m_data + m_position++); + return *(atUint8*)(m_data + m_position++); } -Int8* BinaryReader::readBytes(Int64 length) +atInt8* BinaryReader::readBytes(atInt64 length) { - return (Int8*)readUBytes(length); + return (atInt8*)readUBytes(length); } -Uint8* BinaryReader::readUBytes(Int64 length) +atUint8* BinaryReader::readUBytes(atInt64 length) { if (!m_data) loadData(); @@ -237,21 +237,21 @@ Uint8* BinaryReader::readUBytes(Int64 length) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + length > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - Uint8* ret; - ret = new Uint8[length]; + atUint8* ret; + ret = new atUint8[length]; - memcpy(ret, (const Uint8*)(m_data + m_position), length); + memcpy(ret, (const atUint8*)(m_data + m_position), length); m_position += length; return ret; } -Int16 BinaryReader::readInt16() +atInt16 BinaryReader::readInt16() { if (!m_data) loadData(); @@ -259,25 +259,25 @@ Int16 BinaryReader::readInt16() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int16) > m_length) + if (m_position + sizeof(atInt16) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - Int16 ret = *(Int16*)(m_data + m_position); - m_position += sizeof(Int16); + atInt16 ret = *(atInt16*)(m_data + m_position); + m_position += sizeof(atInt16); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) ret = utility::swap16(ret); return ret; } -Uint16 BinaryReader::readUint16() +atUint16 BinaryReader::readUint16() { return readInt16(); } -Int32 BinaryReader::readInt32() +atInt32 BinaryReader::readInt32() { if (!m_data) loadData(); @@ -285,12 +285,12 @@ Int32 BinaryReader::readInt32() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int32) > m_length) + if (m_position + sizeof(atInt32) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - Int32 ret = *(Int32*)(m_data + m_position); + atInt32 ret = *(atInt32*)(m_data + m_position); m_position += 4; if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) @@ -298,12 +298,12 @@ Int32 BinaryReader::readInt32() return ret; } -Uint32 BinaryReader::readUint32() +atUint32 BinaryReader::readUint32() { return readInt32(); } -Int64 BinaryReader::readInt64() +atInt64 BinaryReader::readInt64() { if (!m_data) loadData(); @@ -311,12 +311,12 @@ Int64 BinaryReader::readInt64() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int64) > m_length) + if (m_position + sizeof(atInt64) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - Int64 ret = *(Int64*)(m_data + m_position); + atInt64 ret = *(atInt64*)(m_data + m_position); m_position += 8; if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) @@ -324,7 +324,7 @@ Int64 BinaryReader::readInt64() return ret; } -Uint64 BinaryReader::readUint64() +atUint64 BinaryReader::readUint64() { return readUint64(); } @@ -337,7 +337,7 @@ float BinaryReader::readFloat() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(float) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); @@ -358,7 +358,7 @@ double BinaryReader::readDouble() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(double) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); @@ -380,7 +380,7 @@ bool BinaryReader::readBool() if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(bool) > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); @@ -396,7 +396,7 @@ std::string BinaryReader::readUnicode() loadData(); std::string ret; std::vector tmp; - Uint16 chr = readUint16(); + atUint16 chr = readUint16(); for(;;) { if (!chr) @@ -412,7 +412,7 @@ std::string BinaryReader::readUnicode() std::string BinaryReader::readString() { std::string ret = ""; - Uint8 chr = readByte(); + atUint8 chr = readByte(); while (chr != 0) { @@ -431,7 +431,7 @@ void BinaryReader::setProgressCallback(std::function cb) void BinaryReader::loadData() { FILE* in; - Uint32 length; + atUint32 length; in = fopen(m_filepath.c_str(), "rb"); if (!in) @@ -443,17 +443,17 @@ void BinaryReader::loadData() #ifdef HW_RVL m_data = (Uint8*)memalign(32, length); #else - m_data = new Uint8[length]; + m_data = new atUint8[length]; #endif - Uint32 done = 0; - Uint32 blocksize = BLOCKSZ; + atUint32 done = 0; + atUint32 blocksize = BLOCKSZ; do { if (blocksize > length - done) blocksize = length - done; - Int32 ret = fread(m_data + done, 1, blocksize, in); + atInt32 ret = fread(m_data + done, 1, blocksize, in); if (ret < 0) THROW_IO_EXCEPTION("Error reading data from disk"); diff --git a/src/Athena/BinaryWriter.cpp b/src/Athena/BinaryWriter.cpp index 56d580f..6f4aa41 100644 --- a/src/Athena/BinaryWriter.cpp +++ b/src/Athena/BinaryWriter.cpp @@ -34,8 +34,8 @@ namespace Athena namespace io { -BinaryWriter::BinaryWriter(Uint8* data, Uint64 length) - : m_data((Uint8*)data), +BinaryWriter::BinaryWriter(atUint8* data, atUint64 length) + : m_data((atUint8*)data), m_length(length), m_position(0), m_bitPosition(0), @@ -54,7 +54,7 @@ BinaryWriter::BinaryWriter(const std::string& filename, std::function m_length = 0x10; m_bitPosition = 0; m_position = 0; - m_data = new Uint8[m_length]; + m_data = new atUint8[m_length]; if (!m_data) THROW_IO_EXCEPTION("Could not allocate memory!"); @@ -95,7 +95,7 @@ bool BinaryWriter::isOpen() const return m_data != nullptr; } -void BinaryWriter::seek(Int64 position, SeekOrigin origin) +void BinaryWriter::seek(atInt64 position, SeekOrigin origin) { switch (origin) { @@ -103,12 +103,12 @@ void BinaryWriter::seek(Int64 position, SeekOrigin origin) if (position < 0) THROW_IO_EXCEPTION("Position outside stream bounds"); - if ((Uint64)position > m_length) + if ((atUint64)position > m_length) resize(position); m_position = position; break; case SeekOrigin::Current: - if ((((Int64)m_position + position) < 0)) + if ((((atInt64)m_position + position) < 0)) THROW_IO_EXCEPTION("Position outside stream bounds"); if (m_position + position > m_length) @@ -117,10 +117,10 @@ void BinaryWriter::seek(Int64 position, SeekOrigin origin) m_position += position; break; case SeekOrigin::End: - if (((Int64)m_length - position) < 0) + if (((atInt64)m_length - position) < 0) THROW_IO_EXCEPTION("Position outside stream bounds"); - if ((Uint64)position > m_length) + if ((atUint64)position > m_length) resize(position); m_position = m_length - position; break; @@ -132,12 +132,12 @@ bool BinaryWriter::atEnd() const return m_position >= m_length; } -Uint64 BinaryWriter::position() const +atUint64 BinaryWriter::position() const { return m_position; } -Uint64 BinaryWriter::length() const +atUint64 BinaryWriter::length() const { return m_length; } @@ -152,20 +152,20 @@ std::string BinaryWriter::filepath() const return m_filepath; } -void BinaryWriter::setData(const Uint8* data, Uint64 length) +void BinaryWriter::setData(const atUint8* data, atUint64 length) { if (m_data) delete[] m_data; - m_data = (Uint8*)data; + m_data = (atUint8*)data; m_length = length; m_position = 0; m_bitPosition = 0; } -Uint8* BinaryWriter::data() const +atUint8* BinaryWriter::data() const { - Uint8* ret = new Uint8[m_length]; + atUint8* ret = new atUint8[m_length]; memset(ret, 0, m_length); memcpy(ret, m_data, m_length); return ret; @@ -184,14 +184,14 @@ void BinaryWriter::save(const std::string& filename) if (!out) THROW_FILE_NOT_FOUND_EXCEPTION(m_filepath); - Uint32 done = 0; - Uint32 blocksize = BLOCKSZ; + atUint32 done = 0; + atUint32 blocksize = BLOCKSZ; do { if (blocksize > m_length - done) blocksize = m_length - done; - Int32 ret = fwrite(m_data + done, 1, blocksize, out); + atInt32 ret = fwrite(m_data + done, 1, blocksize, out); if (ret < 0) THROW_IO_EXCEPTION("Error writing data to disk"); @@ -217,22 +217,22 @@ void BinaryWriter::writeBit(bool val) if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); - if (m_position + sizeof(Uint8) > m_length) - resize(m_position + sizeof(Uint8)); + if (m_position + sizeof(atUint8) > m_length) + resize(m_position + sizeof(atUint8)); if (val) - *(Uint8*)(m_data + m_position) |= (1 << m_bitPosition); + *(atUint8*)(m_data + m_position) |= (1 << m_bitPosition); else - *(Uint8*)(m_data + m_position) &= ~(1 << m_bitPosition); + *(atUint8*)(m_data + m_position) &= ~(1 << m_bitPosition); m_bitPosition++; if (m_bitPosition > 7) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } } -void BinaryWriter::writeUByte(Uint8 val) +void BinaryWriter::writeUByte(atUint8 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -240,17 +240,17 @@ void BinaryWriter::writeUByte(Uint8 val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + 1 > m_length) resize(m_position + 1); - *(Uint8*)(m_data + m_position) = val; + *(atUint8*)(m_data + m_position) = val; m_position++; } -void BinaryWriter::writeByte(Int8 val) +void BinaryWriter::writeByte(atInt8 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -258,7 +258,7 @@ void BinaryWriter::writeByte(Int8 val) writeUByte(val); } -void BinaryWriter::writeUBytes(Uint8* data, Uint64 length) +void BinaryWriter::writeUBytes(atUint8* data, atUint64 length) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -266,7 +266,7 @@ void BinaryWriter::writeUBytes(Uint8* data, Uint64 length) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (!data) @@ -274,20 +274,20 @@ void BinaryWriter::writeUBytes(Uint8* data, Uint64 length) if (m_position + length > m_length) resize(m_position + length); - memcpy((Int8*)(m_data + m_position), data, length); + memcpy((atInt8*)(m_data + m_position), data, length); m_position += length; } -void BinaryWriter::writeBytes(Int8* data, Uint64 length) +void BinaryWriter::writeBytes(atInt8* data, atUint64 length) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); - writeUBytes((Uint8*)data, length); + writeUBytes((atUint8*)data, length); } -void BinaryWriter::writeInt16(Int16 val) +void BinaryWriter::writeInt16(atInt16 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -295,20 +295,20 @@ void BinaryWriter::writeInt16(Int16 val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int16) > m_length) - resize(m_position + sizeof(Int16)); + if (m_position + sizeof(atInt16) > m_length) + resize(m_position + sizeof(atInt16)); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swap16(val); - *(Int16*)(m_data + m_position) = val; - m_position += sizeof(Int16); + *(atInt16*)(m_data + m_position) = val; + m_position += sizeof(atInt16); } -void BinaryWriter::writeUint16(Uint16 val) +void BinaryWriter::writeUint16(atUint16 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -316,7 +316,7 @@ void BinaryWriter::writeUint16(Uint16 val) writeInt16(val); } -void BinaryWriter::writeInt32(Int32 val) +void BinaryWriter::writeInt32(atInt32 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -324,20 +324,20 @@ void BinaryWriter::writeInt32(Int32 val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int32) > m_length) - resize(m_position + sizeof(Int32)); + if (m_position + sizeof(atInt32) > m_length) + resize(m_position + sizeof(atInt32)); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swap32(val); - *(Int32*)(m_data + m_position) = val; - m_position += sizeof(Int32); + *(atInt32*)(m_data + m_position) = val; + m_position += sizeof(atInt32); } -void BinaryWriter::writeUint32(Uint32 val) +void BinaryWriter::writeUint32(atUint32 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -345,41 +345,41 @@ void BinaryWriter::writeUint32(Uint32 val) writeInt32(val); } -void BinaryWriter::writeInt64(Int64 val) +void BinaryWriter::writeInt64(atInt64 val) { if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Int64) > m_length) - resize(m_position + sizeof(Int64)); + if (m_position + sizeof(atInt64) > m_length) + resize(m_position + sizeof(atInt64)); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swap64(val); - *(Int64*)(m_data + m_position) = val; - m_position += sizeof(Int64); + *(atInt64*)(m_data + m_position) = val; + m_position += sizeof(atInt64); } -void BinaryWriter::writeUint64(Uint64 val) +void BinaryWriter::writeUint64(atUint64 val) { if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } - if (m_position + sizeof(Uint64) > m_length) - resize(m_position + sizeof(Uint64)); + if (m_position + sizeof(atUint64) > m_length) + resize(m_position + sizeof(atUint64)); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU64(val); - *(Uint64*)(m_data + m_position) = val; - m_position += sizeof(Uint64); + *(atUint64*)(m_data + m_position) = val; + m_position += sizeof(atUint64); } void BinaryWriter::writeFloat(float val) @@ -387,7 +387,7 @@ void BinaryWriter::writeFloat(float val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(float) > m_length) @@ -405,7 +405,7 @@ void BinaryWriter::writeDouble(double val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(double) > m_length) @@ -423,7 +423,7 @@ void BinaryWriter::writeBool(bool val) if (m_bitPosition > 0) { m_bitPosition = 0; - m_position += sizeof(Uint8); + m_position += sizeof(atUint8); } if (m_position + sizeof(bool) > m_length) @@ -441,7 +441,7 @@ void BinaryWriter::writeUnicode(const std::string& str) utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp)); - for (Uint16 chr : tmp) + for (atUint16 chr : tmp) { if (chr != 0xFEFF) writeInt16(chr); @@ -451,7 +451,7 @@ void BinaryWriter::writeUnicode(const std::string& str) void BinaryWriter::writeString(const std::string& str) { - for (Uint8 c : str) + for (atUint8 c : str) { writeUByte(c); if (c == '\0') @@ -460,15 +460,15 @@ void BinaryWriter::writeString(const std::string& str) writeUByte(0); } -void BinaryWriter::fill(Uint8 val, Uint64 length) +void BinaryWriter::fill(atUint8 val, atUint64 length) { while ((length--) > 0) writeUByte(val); } -void BinaryWriter::fill(Int8 val, Uint64 length) +void BinaryWriter::fill(atInt8 val, atUint64 length) { - fill((Uint8)val, length); + fill((atUint8)val, length); } void BinaryWriter::setProgressCallback(std::function cb) @@ -476,7 +476,7 @@ void BinaryWriter::setProgressCallback(std::function cb) m_progressCallback = cb; } -void BinaryWriter::resize(Uint64 newSize) +void BinaryWriter::resize(atUint64 newSize) { if (newSize < m_length) THROW_INVALID_OPERATION_EXCEPTION("Stream::resize() -> New size cannot be less to the old size."); @@ -485,7 +485,7 @@ void BinaryWriter::resize(Uint64 newSize) #ifdef HW_RVL Uint8* newArray = (Uint8*)memalign(32, newSize); #else - Uint8* newArray = new Uint8[newSize]; + atUint8* newArray = new atUint8[newSize]; #endif memset(newArray, 0, newSize); diff --git a/src/Athena/Checksums.cpp b/src/Athena/Checksums.cpp index d2c3310..dd3a2f8 100644 --- a/src/Athena/Checksums.cpp +++ b/src/Athena/Checksums.cpp @@ -23,9 +23,9 @@ namespace Athena namespace Checksums { -Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed) +atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed) { - static const Uint32 crc32Table[256] = + static const atUint32 crc32Table[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, @@ -64,7 +64,7 @@ Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed) if (!data) return 0; - Uint32 checksum = seed; + atUint32 checksum = seed; int pos = 0; while (length--) @@ -73,9 +73,9 @@ Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed) return checksum ^ seed; } -Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final) +atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed, atUint16 final) { - static const Uint16 crc16CCITTTable [256] = + static const atUint16 crc16CCITTTable [256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, @@ -108,7 +108,7 @@ Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final) 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; - Uint16 checksum = seed; + atUint16 checksum = seed; int pos = 0; while (length--) @@ -117,9 +117,9 @@ Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final) return checksum ^ final; } -Uint16 crc16(const Uint8* data, Uint64 length) +atUint16 crc16(const atUint8* data, atUint64 length) { - static const Uint16 crc16Table[256] = + static const atUint16 crc16Table[256] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, @@ -155,8 +155,8 @@ Uint16 crc16(const Uint8* data, Uint64 length) 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; - Int32 pos = 0; - Uint16 checksum = 0; + atInt32 pos = 0; + atUint16 checksum = 0; while (length--) checksum = (crc16Table[(checksum ^ data[pos++]) & 0xFF] ^ (checksum >> 8)); return checksum; diff --git a/src/Athena/Compression.cpp b/src/Athena/Compression.cpp index 2403252..4f5eb3f 100644 --- a/src/Athena/Compression.cpp +++ b/src/Athena/Compression.cpp @@ -26,7 +26,7 @@ namespace io namespace Compression { -Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen) +atInt32 decompressZlib(atUint8 *src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) { z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; strm.total_in = strm.avail_in = srcLen; @@ -38,8 +38,8 @@ Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen) strm.zfree = Z_NULL; strm.opaque = Z_NULL; - Int32 err = -1; - Int32 ret = -1; + atInt32 err = -1; + atInt32 ret = -1; err = inflateInit(&strm); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib if (err == Z_OK) @@ -64,7 +64,7 @@ Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen) return ret; } -Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen) +atInt32 compressZlib(const atUint8 *src, atUint32 srcLen, atUint8 *dst, atUint32 dstLen) { z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; strm.total_in = strm.avail_in = srcLen; @@ -76,8 +76,8 @@ Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen) strm.zfree = Z_NULL; strm.opaque = Z_NULL; - Int32 err = -1; - Int32 ret = -1; + atInt32 err = -1; + atInt32 ret = -1; err = deflateInit(&strm, Z_BEST_COMPRESSION); @@ -103,7 +103,7 @@ Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen) return ret; } -Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize) +atInt32 decompressLZO(atUint8* source, atInt32 sourceSize, atUint8* dest, atInt32& dstSize) { int size = dstSize; int result = lzo1x_decode(dest, &size, source, &sourceSize); @@ -114,12 +114,12 @@ Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize //src points to the yaz0 source data (to the "real" source data, not at the header!) //dst points to a buffer uncompressedSize bytes large (you get uncompressedSize from //the second 4 bytes in the Yaz0 header). -Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize) +atUint32 yaz0Decode(atUint8* src, atUint8* dst, atUint32 uncompressedSize) { - Uint32 srcPlace = 0, dstPlace = 0; //current read/write positions + atUint32 srcPlace = 0, dstPlace = 0; //current read/write positions - Int32 validBitCount = 0; //number of valid bits left in "code" byte - Uint8 currCodeByte; + atInt32 validBitCount = 0; //number of valid bits left in "code" byte + atUint8 currCodeByte; while(dstPlace < uncompressedSize) { //read new "code" byte if the current one is used up @@ -140,14 +140,14 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize) else { //RLE part - Uint8 byte1 = src[srcPlace]; - Uint8 byte2 = src[srcPlace + 1]; + atUint8 byte1 = src[srcPlace]; + atUint8 byte2 = src[srcPlace + 1]; srcPlace += 2; - Uint32 dist = ((byte1 & 0xF) << 8) | byte2; - Uint32 copySource = dstPlace - (dist + 1); + atUint32 dist = ((byte1 & 0xF) << 8) | byte2; + atUint32 copySource = dstPlace - (dist + 1); - Uint32 numBytes = byte1 >> 4; + atUint32 numBytes = byte1 >> 4; if(numBytes == 0) { numBytes = src[srcPlace] + 0x12; @@ -157,7 +157,7 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize) numBytes += 2; //copy run - for(Uint32 i = 0; i < numBytes; ++i) + for(atUint32 i = 0; i < numBytes; ++i) { dst[dstPlace] = dst[copySource]; copySource++; @@ -176,26 +176,26 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize) // Yaz0 encode typedef struct { - Uint32 srcPos, dstPos; + atUint32 srcPos, dstPos; } yaz0_Ret; -Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos); -Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos); +atUint32 simpleEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos); +atUint32 nintendoEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos); -Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data) +atUint32 yaz0Encode(atUint8* src, atUint32 srcSize, atUint8* data) { yaz0_Ret r = { 0, 0 }; - Int32 pos = 0; - Uint8 dst[24]; // 8 codes * 3 bytes maximum - Uint32 dstSize = 0; - Uint32 i; + atInt32 pos = 0; + atUint8 dst[24]; // 8 codes * 3 bytes maximum + atUint32 dstSize = 0; + atUint32 i; - Uint32 validBitCount = 0; //number of valid bits left in "code" byte - Uint8 currCodeByte = 0; + atUint32 validBitCount = 0; //number of valid bits left in "code" byte + atUint8 currCodeByte = 0; while(r.srcPos < srcSize) { - Uint32 numBytes; - Uint32 matchPos; + atUint32 numBytes; + atUint32 matchPos; numBytes = nintendoEnc(src, srcSize, r.srcPos, &matchPos); if (numBytes < 3) { @@ -209,8 +209,8 @@ Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data) else { //RLE part - Uint32 dist = r.srcPos - matchPos - 1; - Uint8 byte1, byte2, byte3; + atUint32 dist = r.srcPos - matchPos - 1; + atUint8 byte1, byte2, byte3; if (numBytes >= 0x12) // 3 byte encoding { @@ -265,12 +265,12 @@ Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data) } // a lookahead encoding scheme for ngc Yaz0 -Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos) +atUint32 nintendoEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos) { - Uint32 numBytes = 1; - static Uint32 numBytes1; - static Uint32 matchPos; - static Int32 prevFlag = 0; + atUint32 numBytes = 1; + static atUint32 numBytes1; + static atUint32 matchPos; + static atInt32 prevFlag = 0; // if prevFlag is set, it means that the previous position was determined by look-ahead try. // so just use it. this is not the best optimization, but nintendo's choice for speed. @@ -297,11 +297,11 @@ Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos) } // simple and straight encoding scheme for Yaz0 -Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos) +atUint32 simpleEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos) { int startPos = pos - 0x1000, j, i; - Uint32 numBytes = 1; - Uint32 matchPos = 0; + atUint32 numBytes = 1; + atUint32 matchPos = 0; if (startPos < 0) startPos = 0; @@ -312,7 +312,7 @@ Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos) if (src[i+j] != src[j+pos]) break; } - if ((Uint32)j > numBytes) + if ((atUint32)j > numBytes) { numBytes = j; matchPos = i; diff --git a/src/Athena/FileReader.cpp b/src/Athena/FileReader.cpp index a520c44..5c4dc82 100644 --- a/src/Athena/FileReader.cpp +++ b/src/Athena/FileReader.cpp @@ -92,7 +92,7 @@ bool FileReader::isOpen() const return m_fileHandle != NULL; } -void FileReader::seek(Int64 pos, SeekOrigin origin) +void FileReader::seek(atInt64 pos, SeekOrigin origin) { if (fseeko64(m_fileHandle, pos, (int)origin) != 0) THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file"); @@ -106,7 +106,7 @@ bool FileReader::atEnd() const return feof(m_fileHandle) != 0; } -Uint64 FileReader::position() const +atUint64 FileReader::position() const { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open"); @@ -114,7 +114,7 @@ Uint64 FileReader::position() const return ftello64(m_fileHandle); } -Uint64 FileReader::length() const +atUint64 FileReader::length() const { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open"); @@ -141,14 +141,14 @@ bool FileReader::readBit() if (!m_bitValid) { int size = fread(&m_currentByte, 1, 1, m_fileHandle); - if (size != sizeof(Uint8)) + if (size != sizeof(atUint8)) THROW_IO_EXCEPTION("Error reading from file."); m_bitShift = 0; m_bitValid = true; } - Uint8 flag = (1 << m_bitShift); + atUint8 flag = (1 << m_bitShift); m_bitShift++; if (m_bitShift > 7) m_bitValid = false; @@ -156,49 +156,49 @@ bool FileReader::readBit() return ((m_currentByte & flag) == flag); } -Uint8 FileReader::readUByte() +atUint8 FileReader::readUByte() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); m_bitValid = false; - Uint8 val = 0; + atUint8 val = 0; fread(&val, 1, 1, m_fileHandle); return val; } -Int8 FileReader::readByte() +atInt8 FileReader::readByte() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); - return (Int8)readUByte(); + return (atInt8)readUByte(); } -Uint8* FileReader::readUBytes(Uint64 len) +atUint8* FileReader::readUBytes(atUint64 len) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); m_bitValid = false; - Uint8* val = new Uint8[len]; + atUint8* val = new atUint8[len]; fread(val, 1, len, m_fileHandle); return val; } -Int8* FileReader::readBytes(Uint64 len) +atInt8* FileReader::readBytes(atUint64 len) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); - return (Int8*)readUBytes(len); + return (atInt8*)readUBytes(len); } -Uint16 FileReader::readUint16() +atUint16 FileReader::readUint16() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); m_bitValid = false; - Uint16 val; - fread(&val, 1, sizeof(Uint16), m_fileHandle); + atUint16 val; + fread(&val, 1, sizeof(atUint16), m_fileHandle); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU16(val); @@ -206,22 +206,22 @@ Uint16 FileReader::readUint16() return val; } -Int16 FileReader::readInt16() +atInt16 FileReader::readInt16() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); - return (Int16)readUint16(); + return (atInt16)readUint16(); } -Uint32 FileReader::readUint32() +atUint32 FileReader::readUint32() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); m_bitValid = false; - Uint32 val; - fread(&val, 1, sizeof(Uint32), m_fileHandle); + atUint32 val; + fread(&val, 1, sizeof(atUint32), m_fileHandle); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU32(val); @@ -229,22 +229,22 @@ Uint32 FileReader::readUint32() return val; } -Int32 FileReader::readInt32() +atInt32 FileReader::readInt32() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); - return (Int32)readUint32(); + return (atInt32)readUint32(); } -Uint64 FileReader::readUint64() +atUint64 FileReader::readUint64() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); m_bitValid = false; - Uint64 val; - fread(&val, 1, sizeof(Uint64), m_fileHandle); + atUint64 val; + fread(&val, 1, sizeof(atUint64), m_fileHandle); if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU64(val); @@ -252,12 +252,12 @@ Uint64 FileReader::readUint64() return val; } -Int64 FileReader::readInt64() +atInt64 FileReader::readInt64() { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for reading"); - return (Int64)readUint64(); + return (atInt64)readUint64(); } double FileReader::readDouble() @@ -301,7 +301,7 @@ bool FileReader::readBool() std::string FileReader::readString() { std::string ret = ""; - Uint8 chr = readByte(); + atUint8 chr = readByte(); while (chr != 0) { diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index dafc532..fd01b6f 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -91,7 +91,7 @@ bool FileWriter::save() return true; } -void FileWriter::seek(Int64 pos, SeekOrigin origin) +void FileWriter::seek(atInt64 pos, SeekOrigin origin) { if (fseeko64(m_fileHandle, pos, (int)origin) != 0) THROW_IO_EXCEPTION("Unable to seek in file"); @@ -102,12 +102,12 @@ bool FileWriter::atEnd() const return feof(m_fileHandle) != 0; } -Uint64 FileWriter::position() const +atUint64 FileWriter::position() const { return ftello64(m_fileHandle); } -Uint64 FileWriter::length() const +atUint64 FileWriter::length() const { return utility::fileSize(m_fileHandle); } @@ -134,7 +134,7 @@ void FileWriter::writeBit(bool val) m_bitValid = false; fseeko64(m_fileHandle, m_bytePosition, (int)SeekOrigin::Begin); - if (fwrite(&m_currentByte, 1, 1, m_fileHandle) != sizeof(Int8)) + if (fwrite(&m_currentByte, 1, 1, m_fileHandle) != sizeof(atInt8)) THROW_IO_EXCEPTION("Unable to data to file"); } @@ -146,23 +146,23 @@ void FileWriter::seekBit(int bit) m_bitValid = true; } -void FileWriter::writeUByte(Uint8 val) +void FileWriter::writeUByte(atUint8 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); m_bitValid = false; - if (fwrite(&val, 1, sizeof(Uint8), m_fileHandle) != sizeof(Uint8)) + if (fwrite(&val, 1, sizeof(atUint8), m_fileHandle) != sizeof(atUint8)) THROW_IO_EXCEPTION("Unable to write to stream"); } -void FileWriter::writeByte(Int8 val) +void FileWriter::writeByte(atInt8 val) { writeUByte(val); } -void FileWriter::writeUBytes(Uint8* data, Uint64 len) +void FileWriter::writeUBytes(atUint8* data, atUint64 len) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -173,12 +173,12 @@ void FileWriter::writeUBytes(Uint8* data, Uint64 len) THROW_IO_EXCEPTION("Unable to write to stream"); } -void FileWriter::writeBytes(Int8* data, Uint64 len) +void FileWriter::writeBytes(atInt8* data, atUint64 len) { - writeUBytes((Uint8*)data, len); + writeUBytes((atUint8*)data, len); } -void FileWriter::writeUint16(Uint16 val) +void FileWriter::writeUint16(atUint16 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -188,16 +188,16 @@ void FileWriter::writeUint16(Uint16 val) if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU16(val); - if (fwrite(&val, 1, sizeof(Uint16), m_fileHandle) != sizeof(Uint16)) + if (fwrite(&val, 1, sizeof(atUint16), m_fileHandle) != sizeof(atUint16)) THROW_IO_EXCEPTION("Unable to write to stream"); } -void FileWriter::writeInt16(Int16 val) +void FileWriter::writeInt16(atInt16 val) { writeUint16(val); } -void FileWriter::writeUint32(Uint32 val) +void FileWriter::writeUint32(atUint32 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -207,16 +207,16 @@ void FileWriter::writeUint32(Uint32 val) if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU32(val); - if (fwrite(&val, 1, sizeof(Uint32), m_fileHandle) != sizeof(Uint32)) + if (fwrite(&val, 1, sizeof(atUint32), m_fileHandle) != sizeof(atUint32)) THROW_IO_EXCEPTION("Unable to write to stream"); } -void FileWriter::writeInt32(Int32 val) +void FileWriter::writeInt32(atInt32 val) { writeUint32(val); } -void FileWriter::writeUint64(Uint64 val) +void FileWriter::writeUint64(atUint64 val) { if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); @@ -226,11 +226,11 @@ void FileWriter::writeUint64(Uint64 val) if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian())) val = utility::swapU64(val); - if (fwrite(&val, 1, sizeof(Uint64), m_fileHandle) != sizeof(Uint64)) + if (fwrite(&val, 1, sizeof(atUint64), m_fileHandle) != sizeof(atUint64)) THROW_IO_EXCEPTION("Unable to write to stream"); } -void FileWriter::writeInt64(Int64 val) +void FileWriter::writeInt64(atInt64 val) { writeUint64(val); } @@ -293,7 +293,7 @@ void FileWriter::writeUnicode(const std::string& str) utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp)); - for (Uint16 chr : tmp) + for (atUint16 chr : tmp) { if (chr != 0xFEFF) writeInt16(chr); diff --git a/src/Athena/MCFileReader.cpp b/src/Athena/MCFileReader.cpp index 0a6b839..59903b9 100644 --- a/src/Athena/MCFileReader.cpp +++ b/src/Athena/MCFileReader.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -21,7 +22,7 @@ namespace Athena namespace io { -MCFileReader::MCFileReader(Uint8* data, Uint64 length) +MCFileReader::MCFileReader(atUint8* data, atUint64 length) : base(data, length) { } @@ -33,3 +34,4 @@ MCFileReader::MCFileReader(const std::string& filename) } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/MCFileWriter.cpp b/src/Athena/MCFileWriter.cpp index 3956eab..2e35f1a 100644 --- a/src/Athena/MCFileWriter.cpp +++ b/src/Athena/MCFileWriter.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -20,7 +21,7 @@ namespace Athena namespace io { -MCFileWriter::MCFileWriter(Uint8* data, Uint64 length) +MCFileWriter::MCFileWriter(atUint8* data, atUint64 length) : base(data, length) { } @@ -33,13 +34,13 @@ MCFileWriter::MCFileWriter(const std::string& filename) // TODO: Check the implementation, it seems to work fine, however it's not exactly correct, // looking at the disassembly, MC seems to do some weird checking that isn't being done with this solution // need to figure out what it's doing and whether it's relevant to the checksum. -Uint16 MCFileWriter::calculateSlotChecksum(Uint32 game) +atUint16 MCFileWriter::calculateSlotChecksum(atUint32 game) { - Uint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4); - Uint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500); + atUint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4); + atUint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500); first = (first + second) & 0xFFFF; - Uint16 result = first << 16; + atUint16 result = first << 16; second = ~first&0xFFFF; second += 1; result += second; @@ -47,14 +48,14 @@ Uint16 MCFileWriter::calculateSlotChecksum(Uint32 game) return result; } -Uint16 MCFileWriter::calculateChecksum(Uint8 *data, Uint32 length) +atUint16 MCFileWriter::calculateChecksum(atUint8 *data, atUint32 length) { - Uint16 sum = 0; + atUint16 sum = 0; int i = length; - for (Uint32 j = 0; j < length; j += 2) + for (atUint32 j = 0; j < length; j += 2) { - sum += *(Uint16*)(data + j) ^ i; + sum += *(atUint16*)(data + j) ^ i; i -= 2; } @@ -64,10 +65,10 @@ Uint16 MCFileWriter::calculateChecksum(Uint8 *data, Uint32 length) } // TODO: Rewrite this to be more optimized, the current solution takes quite a few cycles -Uint8* MCFileWriter::reverse(Uint8* data, Uint32 length) +atUint8* MCFileWriter::reverse(atUint8* data, atUint32 length) { - Uint32 a = 0; - Uint32 swap; + atUint32 a = 0; + atUint32 swap; for (;a<--length; a++) { @@ -86,14 +87,15 @@ void MCFileWriter::unscramble() if (!m_data) return; - for (Uint32 i = 0; i < m_length; i += 4) + for (atUint32 i = 0; i < m_length; i += 4) { - Uint32 block1 = *(Uint32*)reverse((m_data + i), 4); - Uint32 block2 = *(Uint32*)reverse((m_data + i + 4), 4); - *(Uint32*)(m_data + i) = block2; - *(Uint32*)(m_data + i + 4) = block1; + atUint32 block1 = *(atUint32*)reverse((m_data + i), 4); + atUint32 block2 = *(atUint32*)reverse((m_data + i + 4), 4); + *(atUint32*)(m_data + i) = block2; + *(atUint32*)(m_data + i + 4) = block1; } } } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/SkywardSwordFile.cpp b/src/Athena/SkywardSwordFile.cpp index 134564b..bedd66a 100644 --- a/src/Athena/SkywardSwordFile.cpp +++ b/src/Athena/SkywardSwordFile.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -44,7 +45,7 @@ void SkywardSwordFile::addQuest(Athena::SkywardSwordQuest *q) m_quests.push_back(q); } -SkywardSwordQuest *SkywardSwordFile::quest(Uint32 id) +SkywardSwordQuest *SkywardSwordFile::quest(atUint32 id) { if (id > m_quests.size() - 1) THROW_INVALID_OPERATION_EXCEPTION("index out of range"); @@ -69,3 +70,4 @@ Region SkywardSwordFile::region() const } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/SkywardSwordFileReader.cpp b/src/Athena/SkywardSwordFileReader.cpp index bb0c46e..a2c4c6c 100644 --- a/src/Athena/SkywardSwordFileReader.cpp +++ b/src/Athena/SkywardSwordFileReader.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -25,7 +26,7 @@ namespace Athena namespace io { -SkywardSwordFileReader::SkywardSwordFileReader(Uint8* data, Uint64 length) +SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length) : base(data, length) { base::setEndian(Endian::BigEndian); @@ -45,13 +46,13 @@ SkywardSwordFile* SkywardSwordFileReader::read() if (base::length() != 0xFBE0) THROW_INVALID_DATA_EXCEPTION("File not the expected size of 0xFBE0"); - Uint32 magic = base::readUint32(); + atUint32 magic = base::readUint32(); if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic) THROW_INVALID_DATA_EXCEPTION("Not a valid Skyward Sword save file"); base::seek(0x01C, SeekOrigin::Begin); - Uint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1) + atUint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1) if (headerSize != 0x1D) THROW_INVALID_DATA_EXCEPTION("Invalid header size, Corrupted data?"); @@ -61,8 +62,8 @@ SkywardSwordFile* SkywardSwordFileReader::read() file->setRegion((magic == SkywardSwordFile::USMagic ? Region::NTSC: (magic == SkywardSwordFile::JAMagic ? Region::NTSCJ: Region::PAL))); for (int i = 0; i < 3; i++) { - SkywardSwordQuest* q = new SkywardSwordQuest((Uint8*)base::readBytes(0x53C0), 0x53C0); - Uint64 pos = base::position(); + SkywardSwordQuest* q = new SkywardSwordQuest((atUint8*)base::readBytes(0x53C0), 0x53C0); + atUint64 pos = base::position(); // seek to the skip data for this particular quest base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); q->setSkipData(base::readUBytes(0x24)); @@ -82,3 +83,4 @@ SkywardSwordFile* SkywardSwordFileReader::read() } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/SkywardSwordFileWriter.cpp b/src/Athena/SkywardSwordFileWriter.cpp index d8d3d52..1f2bd56 100644 --- a/src/Athena/SkywardSwordFileWriter.cpp +++ b/src/Athena/SkywardSwordFileWriter.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -24,7 +25,7 @@ namespace Athena namespace io { -SkywardSwordFileWriter::SkywardSwordFileWriter(Uint8 *data, Uint64 len) +SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8 *data, atUint64 len) : base(data, len) { base::setEndian(Endian::BigEndian); @@ -41,7 +42,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file) if (!file) THROW_INVALID_OPERATION_EXCEPTION("file cannot be NULL"); - Uint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic : + atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic : (file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic)); base::writeUint32(magic); @@ -58,7 +59,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file) THROW_INVALID_DATA_EXCEPTION("q->skipData() not 0x24 bytes in length"); // Write the save data base::writeUBytes(q->data(), q->length()); - Uint64 pos = base::position(); + atUint64 pos = base::position(); // Write the slots skip data base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin); base::writeUBytes(q->skipData(), q->skipLength()); @@ -73,3 +74,4 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file) } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/SkywardSwordQuest.cpp b/src/Athena/SkywardSwordQuest.cpp index cfe20ba..41b98b0 100644 --- a/src/Athena/SkywardSwordQuest.cpp +++ b/src/Athena/SkywardSwordQuest.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -17,14 +18,14 @@ namespace Athena { -SkywardSwordQuest::SkywardSwordQuest(Uint8 *data, Uint32 len) +SkywardSwordQuest::SkywardSwordQuest(atUint8 *data, atUint32 len) : ZQuestFile(ZQuestFile::SS, Endian::BigEndian, data, len), m_skipData(nullptr), m_skipLength(0) { } -void SkywardSwordQuest::setSkipData(const Uint8 *data, Uint32 len) +void SkywardSwordQuest::setSkipData(const atUint8 *data, atUint32 len) { if (m_skipData) { @@ -32,18 +33,19 @@ void SkywardSwordQuest::setSkipData(const Uint8 *data, Uint32 len) m_skipData = nullptr; } - m_skipData = (Uint8*)data; + m_skipData = (atUint8*)data; m_skipLength = len; } -Uint8 *SkywardSwordQuest::skipData() const +atUint8 *SkywardSwordQuest::skipData() const { return m_skipData; } -Uint32 SkywardSwordQuest::skipLength() const +atUint32 SkywardSwordQuest::skipLength() const { return m_skipLength; } } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/Sprite.cpp b/src/Athena/Sprite.cpp index 0119269..5940360 100644 --- a/src/Athena/Sprite.cpp +++ b/src/Athena/Sprite.cpp @@ -146,12 +146,12 @@ QList Sprite::stateIds() const return m_stateIds; } -Uint32 Sprite::stateCount() const +atUint32 Sprite::stateCount() const { return m_stateIds.size(); } -void Sprite::setCurrentState(const Uint32 id) +void Sprite::setCurrentState(const atUint32 id) { if (id >= m_stateIds.size()) return; @@ -162,7 +162,7 @@ void Sprite::setCurrentState(const Uint32 id) #endif } -Uint32 Sprite::currentState() const +atUint32 Sprite::currentState() const { return m_currentState; } @@ -197,7 +197,7 @@ bool Sprite::removeFrame(SpriteFrame* frame) return false; } -void Sprite::setFrame(Uint32 id) +void Sprite::setFrame(atUint32 id) { if (id > m_frames.size()) return; @@ -228,7 +228,7 @@ void Sprite::setFrames(QList frames) #endif -Uint32 Sprite::frameCount() const +atUint32 Sprite::frameCount() const { return m_frames.size(); } @@ -249,7 +249,7 @@ SpriteFile* Sprite::container() const void Sprite::setCurrentFrame(SpriteFrame* frame) { - Uint32 id = 0; + atUint32 id = 0; for (SpriteFrame* tmpFrame : m_frames) { if (tmpFrame == frame) @@ -261,7 +261,7 @@ void Sprite::setCurrentFrame(SpriteFrame* frame) } } -void Sprite::setCurrentFrame(Uint32 id) +void Sprite::setCurrentFrame(atUint32 id) { if (id >= m_frames.size()) return; diff --git a/src/Athena/SpriteFile.cpp b/src/Athena/SpriteFile.cpp index 6f932eb..b155819 100644 --- a/src/Athena/SpriteFile.cpp +++ b/src/Athena/SpriteFile.cpp @@ -22,20 +22,20 @@ namespace Athena { namespace Sakura { -const Uint32 SpriteFile::Major = 1; -const Uint32 SpriteFile::Minor = 0; -const Uint32 SpriteFile::Revision = 2; -const Uint32 SpriteFile::Build = 0; -const Uint32 SpriteFile::Version = Major | (Minor << 8) | (Revision << 16) | (Build << 24); +const atUint32 SpriteFile::Major = 1; +const atUint32 SpriteFile::Minor = 0; +const atUint32 SpriteFile::Revision = 2; +const atUint32 SpriteFile::Build = 0; +const atUint32 SpriteFile::Version = Major | (Minor << 8) | (Revision << 16) | (Build << 24); -const Uint32 SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24); +const atUint32 SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24); SpriteFile::SpriteFile() { } -SpriteFile::SpriteFile(Uint32 width, Uint32 height, float originX, float originY) +SpriteFile::SpriteFile(atUint32 width, atUint32 height, float originX, float originY) : m_size(width, height), m_origin(originX, originY) { @@ -63,7 +63,7 @@ SpriteFile::~SpriteFile() m_sprites.clear(); } -void SpriteFile::setSize(Uint32 width, Uint32 height) +void SpriteFile::setSize(atUint32 width, atUint32 height) { #ifndef ATHENA_USE_QT setSize(Vector2Di(width, height)); @@ -93,7 +93,7 @@ QSize SpriteFile::size() const return m_size; } -Uint32 SpriteFile::width() const +atUint32 SpriteFile::width() const { #ifndef ATHENA_USE_QT return m_size.x; @@ -102,7 +102,7 @@ Uint32 SpriteFile::width() const #endif } -Uint32 SpriteFile::height() const +atUint32 SpriteFile::height() const { #ifndef ATHENA_USE_QT return m_size.y; @@ -179,7 +179,7 @@ void SpriteFile::removeTexture(int id) delete tex; } -STexture* SpriteFile::texture(Uint32 id) +STexture* SpriteFile::texture(atUint32 id) { if (id >= m_textures.size()) return NULL; @@ -196,7 +196,7 @@ QList SpriteFile::textures() const return m_textures; } -Uint32 SpriteFile::textureCount() const +atUint32 SpriteFile::textureCount() const { return m_textures.size(); } @@ -294,7 +294,7 @@ QMap SpriteFile::sprites() const return m_sprites; } -Uint32 SpriteFile::spriteCount() const +atUint32 SpriteFile::spriteCount() const { return m_sprites.size(); } diff --git a/src/Athena/SpriteFileReader.cpp b/src/Athena/SpriteFileReader.cpp index d3918f6..89189bc 100644 --- a/src/Athena/SpriteFileReader.cpp +++ b/src/Athena/SpriteFileReader.cpp @@ -27,7 +27,7 @@ namespace Athena { namespace io { -SpriteFileReader::SpriteFileReader(Uint8* data, Uint64 length) +SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length) : base(data, length) { } @@ -43,12 +43,12 @@ Sakura::SpriteFile* SpriteFileReader::readFile() Sakura::SpriteFile* ret = NULL; try { - Uint32 magic = base::readUint32(); + atUint32 magic = base::readUint32(); if (magic != Sakura::SpriteFile::Magic) THROW_INVALID_DATA_EXCEPTION("Not a valid Sakura Sprite container"); - Uint32 version = base::readUint32(); + atUint32 version = base::readUint32(); // TODO: Make this more verbose if (version != Sakura::SpriteFile::Version) @@ -59,13 +59,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. - Uint16 textureCount = base::readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states + atUint16 textureCount = base::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. - Uint32 width = base::readUint32(); - Uint32 height = base::readUint32(); + atUint32 width = base::readUint32(); + atUint32 height = base::readUint32(); float originX = base::readFloat(); float originY = base::readFloat(); - Uint16 spriteCount = base::readUint16(); + atUint16 spriteCount = base::readUint16(); // Lets go ahead and create or new container. ret = new Sakura::SpriteFile(width, height, originX, originY); @@ -75,7 +75,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. - Uint32 reserved = base::readUint32(); + atUint32 reserved = base::readUint32(); UNUSED(reserved); // Next we have to load the textures @@ -89,7 +89,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() QList textures; #endif - for (Uint16 i = 0; i < textureCount; i++) + for (atUint16 i = 0; i < textureCount; i++) { Sakura::STexture* texture = new Sakura::STexture; texture->Filepath = base::readString(); @@ -111,7 +111,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() QMap sprites; #endif - for (Uint16 i = 0; i < spriteCount; i++) + for (atUint16 i = 0; i < spriteCount; i++) { Sakura::Sprite* sprite = new Sakura::Sprite(ret); #ifndef ATHENA_USE_QT @@ -120,8 +120,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() QString name = QString::fromStdString(base::readString()); #endif sprite->setName(name); - Uint16 frameCount = base::readUint16(); - Uint16 stateCount = base::readUint16(); + atUint16 frameCount = base::readUint16(); + atUint16 stateCount = base::readUint16(); // Each state id corresponds to a texture held in the parent class std::vector stateIds; @@ -144,11 +144,11 @@ Sakura::SpriteFile* SpriteFileReader::readFile() QList frames; #endif - for (Uint32 k = 0; k < frameCount; k++) + for (atUint32 k = 0; k < frameCount; k++) { Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite); frame->setFrameTime(base::readFloat()); - Uint16 partCount = base::readUint16(); + atUint16 partCount = base::readUint16(); #ifndef ATHENA_USE_QT @@ -156,7 +156,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() #else QList parts; #endif - for (Uint8 j = 0; j < partCount; j++) + for (atUint8 j = 0; j < partCount; j++) { Sakura::SpritePart* part = new Sakura::SpritePart(frame); #ifndef ATHENA_USE_QT @@ -173,8 +173,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() float texXOff = base::readFloat(); float texYOff = base::readFloat(); part->setTextureOffset(texXOff, texYOff); - Uint32 width = base::readUint32(); - Uint32 height = base::readUint32(); + atUint32 width = base::readUint32(); + atUint32 height = base::readUint32(); part->setSize(width, height); bool flippedH = base::readBool(); part->setFlippedHorizontally(flippedH); diff --git a/src/Athena/SpriteFileWriter.cpp b/src/Athena/SpriteFileWriter.cpp index 2407629..9a919d5 100644 --- a/src/Athena/SpriteFileWriter.cpp +++ b/src/Athena/SpriteFileWriter.cpp @@ -25,7 +25,7 @@ namespace Athena { namespace io { -SpriteFileWriter::SpriteFileWriter(Uint8 *data, Uint64 length) +SpriteFileWriter::SpriteFileWriter(atUint8 *data, atUint64 length) : base(data, length) { } diff --git a/src/Athena/SpriteFrame.cpp b/src/Athena/SpriteFrame.cpp index 0cd22c1..a284790 100644 --- a/src/Athena/SpriteFrame.cpp +++ b/src/Athena/SpriteFrame.cpp @@ -57,7 +57,7 @@ QList SpriteFrame::parts() const return m_parts; } -Uint32 SpriteFrame::partCount() const +atUint32 SpriteFrame::partCount() const { return m_parts.size(); } diff --git a/src/Athena/SpritePart.cpp b/src/Athena/SpritePart.cpp index accc9f0..49572b2 100644 --- a/src/Athena/SpritePart.cpp +++ b/src/Athena/SpritePart.cpp @@ -138,7 +138,7 @@ QPoint SpritePart::textureOffset() const return m_textureOffset; } -void SpritePart::setSize(Uint32 width, Uint32 height) +void SpritePart::setSize(atUint32 width, atUint32 height) { #ifndef ATHENA_USE_QT setSize(Vector2Di(width, height)); diff --git a/src/Athena/Utility.cpp b/src/Athena/Utility.cpp index 626eca1..b26a0f7 100644 --- a/src/Athena/Utility.cpp +++ b/src/Athena/Utility.cpp @@ -27,59 +27,59 @@ namespace Athena { namespace utility { -bool isEmpty(Int8* buf, Uint32 size) +bool isEmpty(atInt8* buf, atUint32 size) { return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1); } -Uint16 swapU16(Uint16 val ) +atUint16 swapU16(atUint16 val ) { - return (Uint16)swap16(val); + return (atUint16)swap16(val); } -Int16 swap16(Int16 val ) +atInt16 swap16(atInt16 val ) { return (val = (val << 8) | ((val >> 8) & 0xFF)); } -Uint32 swapU32(Uint32 val) +atUint32 swapU32(atUint32 val) { - return (Uint32)swap32(val); + return (atUint32)swap32(val); } -int swap32(Int32 val ) +int swap32(atInt32 val ) { val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16; val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8; return val; } -Uint64 swapU64(Uint64 val) +atUint64 swapU64(atUint64 val) { - return (Uint64)swap64(val); + return (atUint64)swap64(val); } -Int64 swap64(Int64 val) +atInt64 swap64(atInt64 val) { - return (val = ((Int64)((((Int64)(val) & 0xFF00000000000000ULL) >> 56) | - (((Int64)(val) & 0x00FF000000000000ULL) >> 40) | - (((Int64)(val) & 0x0000FF0000000000ULL) >> 24) | - (((Int64)(val) & 0x000000FF00000000ULL) >> 8) | - (((Int64)(val) & 0x00000000FF000000ULL) << 8) | - (((Int64)(val) & 0x0000000000FF0000ULL) << 24) | - (((Int64)(val) & 0x000000000000FF00ULL) << 40) | - (((Int64)(val) & 0x00000000000000FFULL) << 56)))); + return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) | + (((atInt64)(val) & 0x00FF000000000000ULL) >> 40) | + (((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) | + (((atInt64)(val) & 0x000000FF00000000ULL) >> 8) | + (((atInt64)(val) & 0x00000000FF000000ULL) << 8) | + (((atInt64)(val) & 0x0000000000FF0000ULL) << 24) | + (((atInt64)(val) & 0x000000000000FF00ULL) << 40) | + (((atInt64)(val) & 0x00000000000000FFULL) << 56)))); } bool isSystemBigEndian() { - Uint8* test = (Uint8*)"\xFE\xFF"; - return (*(Uint16*)test == 0xFEFF); + atUint8* test = (atUint8*)"\xFE\xFF"; + return (*(atUint16*)test == 0xFEFF); } -void fillRandom(Uint8 * rndArea, Uint8 count) +void fillRandom(atUint8 * rndArea, atUint8 count) { - for(Uint16 i = 0; i < count; i++) + for(atUint16 i = 0; i < count; i++) rndArea[i]=rand(); } @@ -112,7 +112,7 @@ double swapDouble(double val) retFloat[6] = convFloat[1]; retFloat[7] = convFloat[0]; - return (double)((Uint64)retVal); + return (double)((atUint64)retVal); } @@ -228,11 +228,11 @@ int countChar(const std::string& str, const char chr, int* lastOccur) return ret; } -Uint64 fileSize(FILE* f) +atUint64 fileSize(FILE* f) { - Uint64 oldPos = ftello64(f); + atUint64 oldPos = ftello64(f); fseeko64(f, 0, SEEK_END); - Uint64 size = ftello64(f); + atUint64 size = ftello64(f); fseeko64(f, oldPos, SEEK_SET); return size; } diff --git a/src/Athena/WiiBanner.cpp b/src/Athena/WiiBanner.cpp index ec02021..66a38df 100644 --- a/src/Athena/WiiBanner.cpp +++ b/src/Athena/WiiBanner.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -32,7 +33,7 @@ WiiBanner::WiiBanner() : { } -WiiBanner::WiiBanner(Uint32 gameId, const std::string& title, +WiiBanner::WiiBanner(atUint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* banner, std::vector icons) : m_gameId(gameId), m_banner(banner), @@ -50,12 +51,12 @@ WiiBanner::~WiiBanner() m_icons.clear(); } -void WiiBanner::setGameID(Uint64 id) +void WiiBanner::setGameID(atUint64 id) { m_gameId = id; } -Uint64 WiiBanner::gameID() const +atUint64 WiiBanner::gameID() const { return m_gameId; } @@ -84,7 +85,7 @@ void WiiBanner::addIcon(WiiImage* icon) m_icons.push_back(icon); } -void WiiBanner::setIcon(Uint32 id, WiiImage* icon) +void WiiBanner::setIcon(atUint32 id, WiiImage* icon) { if (m_icons[id] != NULL) { @@ -93,7 +94,7 @@ void WiiBanner::setIcon(Uint32 id, WiiImage* icon) } } -WiiImage* WiiBanner::getIcon(Uint32 id) const +WiiImage* WiiBanner::getIcon(atUint32 id) const { if (!m_icons[id]) return NULL; @@ -115,44 +116,45 @@ WiiImage* WiiBanner::bannerImage() const return m_banner; } -void WiiBanner::setAnimationSpeed(Uint16 animSpeed) +void WiiBanner::setAnimationSpeed(atUint16 animSpeed) { m_animSpeed = animSpeed; } -Uint16 WiiBanner::animationSpeed() const +atUint16 WiiBanner::animationSpeed() const { return m_animSpeed; } -void WiiBanner::setPermissions(Uint8 permissions) +void WiiBanner::setPermissions(atUint8 permissions) { m_permissions = permissions; } -Uint8 WiiBanner::permissions() const +atUint8 WiiBanner::permissions() const { return m_permissions; } -void WiiBanner::setBannerSize(Uint32 size) +void WiiBanner::setBannerSize(atUint32 size) { m_bannerSize = size; } -Uint32 WiiBanner::bannerSize() const +atUint32 WiiBanner::bannerSize() const { return m_bannerSize; } -void WiiBanner::setFlags(Uint32 flags) +void WiiBanner::setFlags(atUint32 flags) { m_flags = flags; } -Uint32 WiiBanner::flags() const +atUint32 WiiBanner::flags() const { return m_flags; } } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/WiiFile.cpp b/src/Athena/WiiFile.cpp index 6795584..45a2f35 100644 --- a/src/Athena/WiiFile.cpp +++ b/src/Athena/WiiFile.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -41,13 +42,13 @@ WiiFile::WiiFile(const std::string& filename) : { } -WiiFile::WiiFile(const std::string& filename, Uint8 permissions, const Uint8* data, Uint32 length) : +WiiFile::WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length) : m_permissions(permissions), m_attributes(0), m_type(WiiFile::File), m_filename(filename), m_fileLen(length), - m_fileData((Uint8*)data) + m_fileData((atUint8*)data) { } @@ -68,27 +69,27 @@ std::string WiiFile::filename() const return m_filename; } -void WiiFile::setPermissions(const Uint8 permissions) +void WiiFile::setPermissions(const atUint8 permissions) { - m_permissions = (Uint8)permissions; + m_permissions = (atUint8)permissions; } -Uint8 WiiFile::permissions() const +atUint8 WiiFile::permissions() const { return m_permissions; } -void WiiFile::setData(const Uint8* data) +void WiiFile::setData(const atUint8* data) { if (m_fileData) { delete[] m_fileData; m_fileData = NULL; } - m_fileData = (Uint8*)data; + m_fileData = (atUint8*)data; } -Uint8* WiiFile::data() const +atUint8* WiiFile::data() const { return m_fileData; } @@ -103,12 +104,12 @@ int WiiFile::length() const return m_fileLen; } -void WiiFile::setAttributes(const Uint8 attr) +void WiiFile::setAttributes(const atUint8 attr) { m_attributes = attr; } -Uint8 WiiFile::attributes() const +atUint8 WiiFile::attributes() const { return m_attributes; } @@ -134,3 +135,4 @@ bool WiiFile::isFile() const } } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/WiiImage.cpp b/src/Athena/WiiImage.cpp index 1284242..14f95e6 100644 --- a/src/Athena/WiiImage.cpp +++ b/src/Athena/WiiImage.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -21,7 +22,7 @@ namespace Athena { -WiiImage::WiiImage(Uint32 width, Uint32 height, Uint8* data) : +WiiImage::WiiImage(atUint32 width, atUint32 height, atUint8* data) : m_width(width), m_height(height), m_data(data) @@ -35,29 +36,29 @@ WiiImage::~WiiImage() m_data = NULL; } -Uint8* WiiImage::data() +atUint8* WiiImage::data() { return m_data; } -Uint32 WiiImage::width() const +atUint32 WiiImage::width() const { return m_width; } -Uint32 WiiImage::height() const +atUint32 WiiImage::height() const { return m_height; } -Uint8 *WiiImage::toRGBA() +atUint8 *WiiImage::toRGBA() { - Uint32 x, y; - Uint32 x1, y1; - Uint32 iv; - Uint8* bitmapdata = NULL; + atUint32 x, y; + atUint32 x1, y1; + atUint32 iv; + atUint8* bitmapdata = NULL; - bitmapdata = new Uint8[m_width * m_height * 4]; + bitmapdata = new atUint8[m_width * m_height * 4]; if(bitmapdata == NULL) return NULL; @@ -69,29 +70,29 @@ Uint8 *WiiImage::toRGBA() { for(x = x1; x < (x1 + 4); x++) { - Uint16 oldpixel = *(Uint16*)(m_data + ((iv++) * 2)); + atUint16 oldpixel = *(atUint16*)(m_data + ((iv++) * 2)); //if((x >= m_width) || (y >= m_height)) // continue; oldpixel = utility::swapU16(oldpixel); if(oldpixel & (1 << 15)) { // RGB5 - Uint8 b = (((oldpixel >> 10) & 0x1F) * 255) / 31; - Uint8 g = (((oldpixel >> 5) & 0x1F) * 255) / 31; - Uint8 r = (((oldpixel >> 0) & 0x1F) * 255) / 31; - Uint8 a = 255; - Uint8 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); - (*(Uint32**)&bitmapdata)[x + (y * m_width)] = rgba; + atUint8 b = (((oldpixel >> 10) & 0x1F) * 255) / 31; + atUint8 g = (((oldpixel >> 5) & 0x1F) * 255) / 31; + atUint8 r = (((oldpixel >> 0) & 0x1F) * 255) / 31; + atUint8 a = 255; + atUint8 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); + (*(atUint32**)&bitmapdata)[x + (y * m_width)] = rgba; } else { // RGB4A3 - Uint8 a = (((oldpixel >> 12) & 0x7) * 255) / 7; - Uint8 b = (((oldpixel >> 8) & 0xF) * 255) / 15; - Uint8 g = (((oldpixel >> 4) & 0xF) * 255) / 15; - Uint8 r = (((oldpixel >> 0) & 0xF) * 255) / 15; - Uint32 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); - (*(Uint32**)&bitmapdata)[x + (y * m_width)] = rgba; + atUint8 a = (((oldpixel >> 12) & 0x7) * 255) / 7; + atUint8 b = (((oldpixel >> 8) & 0xF) * 255) / 15; + atUint8 g = (((oldpixel >> 4) & 0xF) * 255) / 15; + atUint8 r = (((oldpixel >> 0) & 0xF) * 255) / 15; + atUint32 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); + (*(atUint32**)&bitmapdata)[x + (y * m_width)] = rgba; } } } @@ -101,3 +102,4 @@ Uint8 *WiiImage::toRGBA() } } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/WiiSaveReader.cpp b/src/Athena/WiiSaveReader.cpp index d538e1a..a2f11dd 100644 --- a/src/Athena/WiiSaveReader.cpp +++ b/src/Athena/WiiSaveReader.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -36,7 +37,7 @@ namespace Athena namespace io { -WiiSaveReader::WiiSaveReader(const Uint8* data, Uint64 length) +WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length) : base(data, length) { setEndian(Endian::BigEndian); @@ -61,25 +62,25 @@ WiiSave* WiiSaveReader::readSave() THROW_INVALID_DATA_EXCEPTION("Invalid banner"); ret->setBanner(banner); - Uint32 bkVer = base::readUint32(); + atUint32 bkVer = base::readUint32(); if (bkVer != 0x00000070) THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header size"); - Uint32 bkMagic = base::readUint32(); + atUint32 bkMagic = base::readUint32(); bkMagic = bkMagic; if (bkMagic != 0x426B0001) THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header magic"); - Uint32 ngId = base::readUint32(); + atUint32 ngId = base::readUint32(); ngId = ngId; - Uint32 numFiles = base::readUint32(); + atUint32 numFiles = base::readUint32(); /*int fileSize =*/ base::readUint32(); base::seek(8); // skip unknown data; - Uint32 totalSize = base::readUint32(); + atUint32 totalSize = base::readUint32(); base::seek(64); // Unknown (Most likely padding) base::seek(8); base::seek(6); @@ -87,7 +88,7 @@ WiiSave* WiiSaveReader::readSave() base::seek(0x10); std::unordered_map files; - for (Uint32 i = 0; i < numFiles; ++i) + for (atUint32 i = 0; i < numFiles; ++i) { WiiFile* file = readFile(); if (file) @@ -110,18 +111,18 @@ WiiSave* WiiSaveReader::readSave() WiiBanner* WiiSaveReader::readBanner() { - Uint8* dec = new Uint8[0xF0C0]; + atUint8* dec = new atUint8[0xF0C0]; memset(dec, 0, 0xF0C0); - Uint8* data = (Uint8*)base::readBytes(0xF0C0); - Uint8* oldData = base::data(); - Uint64 oldPos = base::position(); - Uint64 oldLen = base::length(); - Uint64 gameId; - Uint32 bannerSize; - Uint8 permissions; - Uint8 md5[16]; - Uint8 md5Calc[16]; - Uint8 tmpIV[26]; + atUint8* data = (atUint8*)base::readBytes(0xF0C0); + atUint8* oldData = base::data(); + atUint64 oldPos = base::position(); + atUint64 oldLen = base::length(); + atUint64 gameId; + atUint32 bannerSize; + atUint8 permissions; + atUint8 md5[16]; + atUint8 md5Calc[16]; + atUint8 tmpIV[26]; memcpy(tmpIV, SD_IV, 16); std::cout << "Decrypting: banner.bin..."; @@ -232,11 +233,11 @@ WiiBanner* WiiSaveReader::readBanner() return banner; } -WiiImage* WiiSaveReader::readImage(Uint32 width, Uint32 height) +WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height) { - Uint8* image = (Uint8*)base::readBytes(width*height*2); + atUint8* image = (atUint8*)base::readBytes(width*height*2); - if (!utility::isEmpty((Int8*)image, width*height*2)) + if (!utility::isEmpty((atInt8*)image, width*height*2)) return new WiiImage(width, height, image); return NULL; @@ -245,15 +246,15 @@ WiiImage* WiiSaveReader::readImage(Uint32 width, Uint32 height) WiiFile* WiiSaveReader::readFile() { - Uint32 fileLen; - Uint8 permissions; - Uint8 attributes; - Uint8 type; + atUint32 fileLen; + atUint8 permissions; + atUint8 attributes; + atUint8 type; std::string name; - Uint8* filedata; + atUint8* filedata; WiiFile* ret; - Uint32 magic = base::readUint32(); + atUint32 magic = base::readUint32(); if (magic != 0x03adf17e) { std::cerr << "Not a valid File entry header: 0x" << std::hex << magic << std::endl; @@ -269,18 +270,18 @@ WiiFile* WiiSaveReader::readFile() ret->setPermissions(permissions); ret->setAttributes(attributes); ret->setType((WiiFile::Type)type); - Uint8* iv = (Uint8*)base::readBytes(0x10); + atUint8* iv = (atUint8*)base::readBytes(0x10); base::seek(0x20); if (type == WiiFile::File) { // Read file data int roundedLen = (fileLen + 63) & ~63; - filedata = (Uint8*)base::readBytes(roundedLen); + filedata = (atUint8*)base::readBytes(roundedLen); // Decrypt file std::cout << "Decrypting: " << ret->filename() << "..."; - Uint8* decData = new Uint8[roundedLen]; + atUint8* decData = new atUint8[roundedLen]; aes_set_key(SD_KEY); aes_decrypt(iv, filedata, decData, roundedLen); delete filedata; @@ -293,19 +294,19 @@ WiiFile* WiiSaveReader::readFile() } -void WiiSaveReader::readCerts(Uint32 totalSize) +void WiiSaveReader::readCerts(atUint32 totalSize) { std::cout << "Reading certs..." << std::endl; - Uint32 dataSize = totalSize - 0x340; - Uint8* sig = (Uint8*)base::readBytes(0x40); - Uint8* ngCert = (Uint8*)base::readBytes(0x180); - Uint8* apCert = (Uint8*)base::readBytes(0x180); + atUint32 dataSize = totalSize - 0x340; + atUint8* sig = (atUint8*)base::readBytes(0x40); + atUint8* ngCert = (atUint8*)base::readBytes(0x180); + atUint8* apCert = (atUint8*)base::readBytes(0x180); base::seek(0xF0C0, SeekOrigin::Begin); - Uint8* data = (Uint8*)base::readBytes(dataSize); - Uint8* hash; + atUint8* data = (atUint8*)base::readBytes(dataSize); + atUint8* hash; hash = getSha1(data, dataSize); - Uint8* hash2 = getSha1(hash, 20); + atUint8* hash2 = getSha1(hash, 20); std::cout << "validating..." << std::endl; std::cout << (check_ec(ngCert, apCert, sig, hash2) ? "ok" : "invalid") << "..."; @@ -314,3 +315,4 @@ void WiiSaveReader::readCerts(Uint32 totalSize) } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/WiiSaveWriter.cpp b/src/Athena/WiiSaveWriter.cpp index 277d70a..990f624 100644 --- a/src/Athena/WiiSaveWriter.cpp +++ b/src/Athena/WiiSaveWriter.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_SAVES // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -51,7 +52,7 @@ WiiSaveWriter::WiiSaveWriter(const std::string &filename) } -bool WiiSaveWriter::writeSave(WiiSave *save, Uint8 *macAddress, Uint32 ngId, Uint8 *ngPriv, Uint8 *ngSig, Uint32 ngKeyId,const std::string &filepath) +bool WiiSaveWriter::writeSave(WiiSave *save, atUint8 *macAddress, atUint32 ngId, atUint8 *ngPriv, atUint8 *ngSig, atUint32 ngKeyId,const std::string &filepath) { if (!save) THROW_INVALID_OPERATION_EXCEPTION("save cannot be NULL"); @@ -69,10 +70,10 @@ bool WiiSaveWriter::writeSave(WiiSave *save, Uint8 *macAddress, Uint32 ngId, Uin base::writeUint32(0); // totalSize base::seek(64); base::writeUint64(save->banner()->gameID()); - base::writeBytes((Int8*)macAddress, 6); + base::writeBytes((atInt8*)macAddress, 6); base::seek(2); // unknown; base::seek(0x10); // padding; - Uint32 totalSize = 0; + atUint32 totalSize = 0; for (std::unordered_map::const_iterator iter = save->fileList().begin(); iter != save->fileList().end(); ++iter) { totalSize += writeFile(iter->second); @@ -97,9 +98,9 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner) base::setEndian(Endian::BigEndian); base::writeInt64(banner->gameID()); base::writeInt32((0x60a0+0x1200)*banner->icons().size()); - base::writeByte((Int8)banner->permissions()); + base::writeByte((atInt8)banner->permissions()); base::seek(1); - base::writeBytes((Int8*)MD5_BLANKER, 16); + base::writeBytes((atInt8*)MD5_BLANKER, 16); base::seek(2); base::writeInt32(0x5749424E); // WIBN base::writeInt32(banner->flags()); @@ -117,12 +118,12 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner) base::seek(0x00C0, SeekOrigin::Begin); WiiImage* bannerImage = banner->bannerImage(); - base::writeBytes((Int8*)bannerImage->data(), bannerImage->width()*bannerImage->height()*2); + base::writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height()*2); // For empty icons - Uint8* tmpIcon = new Uint8[48*48*2]; + atUint8* tmpIcon = new atUint8[48*48*2]; memset(tmpIcon, 0, 48*48*2); - for (Uint32 i = 0; i < 8; ++i) + for (atUint32 i = 0; i < 8; ++i) { if (i < banner->icons().size()) { @@ -130,32 +131,32 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner) } else { - base::writeBytes((Int8*)tmpIcon, 48*48*2); + base::writeBytes((atInt8*)tmpIcon, 48*48*2); } } delete[] tmpIcon; // delete tmp buffer; - Uint8* hash = new Uint8[0x10]; - MD5Hash::MD5(hash, (Uint8*)base::data(), 0xF0C0); + atUint8* hash = new atUint8[0x10]; + MD5Hash::MD5(hash, (atUint8*)base::data(), 0xF0C0); base::seek(0x0E, SeekOrigin::Begin); - base::writeBytes((Int8*)hash, 0x10); + base::writeBytes((atInt8*)hash, 0x10); aes_set_key(SD_KEY); - Uint8 data[0xF0C0]; + atUint8 data[0xF0C0]; memcpy(data, base::data(), 0xF0C0); - Uint8 tmpIV[26]; + atUint8 tmpIV[26]; memcpy(tmpIV, SD_IV, 16); aes_encrypt(tmpIV, data, data, 0xF0C0); base::seek(0, SeekOrigin::Begin); - base::writeBytes((Int8*)data, 0xF0C0); + base::writeBytes((atInt8*)data, 0xF0C0); base::seek(0xF0C0, SeekOrigin::Begin); } -Uint32 WiiSaveWriter::writeFile(WiiFile *file) +atUint32 WiiSaveWriter::writeFile(WiiFile *file) { - Uint32 ret = 0x80; + atUint32 ret = 0x80; // Write the File magic base::writeUint32(0x03ADF17E); @@ -164,28 +165,28 @@ Uint32 WiiSaveWriter::writeFile(WiiFile *file) base::writeByte(file->attributes()); base::writeByte(file->type()); - Uint8 name[0x45]; + atUint8 name[0x45]; utility::fillRandom(name, 0x45); memcpy(name, file->filename().c_str(), file->filename().size()); name[file->filename().size()] = '\0'; - base::writeBytes((Int8*)name, 0x45); - Uint8 iv[16]; + base::writeBytes((atInt8*)name, 0x45); + atUint8 iv[16]; utility::fillRandom(iv, 0x10); - base::writeBytes((Int8*)iv, 0x10); - Uint8 crap[0x20]; + base::writeBytes((atInt8*)iv, 0x10); + atUint8 crap[0x20]; utility::fillRandom(crap, 0x20); - base::writeBytes((Int8*)crap, 0x20); + base::writeBytes((atInt8*)crap, 0x20); if (file->type() == WiiFile::File) { int roundedSize = (file->length() + 63) & ~63; - Uint8* data = new Uint8[roundedSize]; + atUint8* data = new atUint8[roundedSize]; memset(data, 0, roundedSize); aes_set_key(SD_KEY); aes_encrypt(iv, file->data(), data, roundedSize); - base::writeBytes((Int8*)data, roundedSize); + base::writeBytes((atInt8*)data, roundedSize); ret += roundedSize; delete[] data; } @@ -196,22 +197,22 @@ Uint32 WiiSaveWriter::writeFile(WiiFile *file) void WiiSaveWriter::writeImage(WiiImage* image) { - Int8* data = (Int8*)image->data(); + atInt8* data = (atInt8*)image->data(); base::writeBytes(data, image->width() * image->height() * 2); } -void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uint8 *ngSig, Uint32 ngKeyId) +void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8 *ngPriv, atUint8 *ngSig, atUint32 ngKeyId) { - Uint8 sig[0x40]; - Uint8 ngCert[0x180]; - Uint8 apCert[0x180]; - Uint8* hash; - Uint8 apPriv[30]; - Uint8 apSig[60]; + atUint8 sig[0x40]; + atUint8 ngCert[0x180]; + atUint8 apCert[0x180]; + atUint8* hash; + atUint8 apPriv[30]; + atUint8 apSig[60]; char signer[64]; char name[64]; - Uint8* data; - Uint32 dataSize; + atUint8* data; + atUint32 dataSize; sprintf(signer, "Root-CA00000001-MS00000002"); sprintf(name, "NG%08x", ngId); @@ -232,12 +233,12 @@ void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uin delete[] hash; dataSize = filesSize + 0x80; - data = new Uint8[dataSize]; - Uint8* rawData = base::data(); + data = new atUint8[dataSize]; + atUint8* rawData = base::data(); memcpy(data, rawData + 0xF0C0, dataSize); hash = getSha1(data, dataSize); - Uint8* hash2 = getSha1(hash, 20); + atUint8* hash2 = getSha1(hash, 20); delete[] hash; delete[] data; @@ -246,13 +247,14 @@ void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uin if (!utility::isSystemBigEndian()) stuff = utility::swap32(stuff); - *(Uint32*)(sig+60) = stuff; + *(atUint32*)(sig+60) = stuff; delete[] hash2; - base::writeBytes((Int8*)sig, 0x40); - base::writeBytes((Int8*)ngCert, 0x180); - base::writeBytes((Int8*)apCert, 0x180); + base::writeBytes((atInt8*)sig, 0x40); + base::writeBytes((atInt8*)ngCert, 0x180); + base::writeBytes((atInt8*)apCert, 0x180); } } // io } // zelda +#endif // ATHENA_NO_SAVES diff --git a/src/Athena/ZQuestFile.cpp b/src/Athena/ZQuestFile.cpp index 8e61316..5530efd 100644 --- a/src/Athena/ZQuestFile.cpp +++ b/src/Athena/ZQuestFile.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -14,6 +15,7 @@ // along with libAthena. If not, see #include "Athena/ZQuestFile.hpp" + #include namespace Athena @@ -43,13 +45,13 @@ void initGameStrings() GameStrings.push_back("A Link Between Worlds"); } -const Uint32 ZQuestFile::Major = 2; -const Uint32 ZQuestFile::Minor = 0; -const Uint32 ZQuestFile::Revision = 0; +const atUint32 ZQuestFile::Major = 2; +const atUint32 ZQuestFile::Minor = 0; +const atUint32 ZQuestFile::Revision = 0; -const Uint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16); +const atUint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16); -const Uint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24); +const atUint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24); ZQuestFile::ZQuestFile() : m_game(NoGame), @@ -60,7 +62,7 @@ ZQuestFile::ZQuestFile() initGameStrings(); } -ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, Uint8* data, Uint32 length, const std::string& gameString) +ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, atUint8* data, atUint32 length, const std::string& gameString) : m_game(game), m_gameString(gameString), m_endian(endian), @@ -103,14 +105,14 @@ Endian ZQuestFile::endian() const return m_endian; } -void ZQuestFile::setData(Uint8* data, Uint32 length) +void ZQuestFile::setData(atUint8* data, atUint32 length) { // ensure we're not overwritting our data without freeing first // or assigning unnecessisarily if (!m_data || m_data != data) { delete[] m_data; - m_data = new Uint8[length]; + m_data = new atUint8[length]; // Why is this memcpy needed? // I get SIGABRT without it, need to research memcpy(m_data, data, length); @@ -118,13 +120,13 @@ void ZQuestFile::setData(Uint8* data, Uint32 length) } } -Uint8* ZQuestFile::data() const +atUint8* ZQuestFile::data() const { return m_data; } -Uint32 ZQuestFile::length() const +atUint32 ZQuestFile::length() const { return m_length; } @@ -146,3 +148,5 @@ const std::vector ZQuestFile::gameStringList() return GameStrings; } } + +#endif // ATHENA_NO_ZQUEST diff --git a/src/Athena/ZQuestFileReader.cpp b/src/Athena/ZQuestFileReader.cpp index 992fb74..a31da79 100644 --- a/src/Athena/ZQuestFileReader.cpp +++ b/src/Athena/ZQuestFileReader.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -20,6 +21,7 @@ #include "Athena/InvalidDataException.hpp" #include "Athena/Checksums.hpp" #include "Athena/Utility.hpp" + #include #include @@ -28,7 +30,7 @@ namespace Athena namespace io { -ZQuestFileReader::ZQuestFileReader(Uint8 *data, Uint64 length) +ZQuestFileReader::ZQuestFileReader(atUint8 *data, atUint64 length) : base(data, length) { } @@ -40,12 +42,12 @@ ZQuestFileReader::ZQuestFileReader(const std::string &filename) ZQuestFile *ZQuestFileReader::read() { - Uint32 magic, version, compressedLen, uncompressedLen; + atUint32 magic, version, compressedLen, uncompressedLen; ZQuestFile::Game game = ZQuestFile::NoGame; std::string gameString; - Uint16 BOM; - Uint32 checksum; - Uint8* data; + atUint16 BOM; + atUint32 checksum; + atUint8* data; magic = base::readUint32(); @@ -83,7 +85,7 @@ ZQuestFile *ZQuestFileReader::read() base::seek(0x0A); } - data = (Uint8*)base::readBytes(compressedLen); // compressedLen is always the total file size + data = (atUint8*)base::readBytes(compressedLen); // compressedLen is always the total file size if (version >= ZQUEST_VERSION_CHECK(2, 0, 0)) { @@ -101,8 +103,8 @@ ZQuestFile *ZQuestFileReader::read() if (compressedLen != uncompressedLen) { - Uint8* dst = new Uint8[uncompressedLen]; - Uint32 dstLen = io::Compression::decompressZlib(data, compressedLen, dst, uncompressedLen); + atUint8* dst = new atUint8[uncompressedLen]; + atUint32 dstLen = io::Compression::decompressZlib(data, compressedLen, dst, uncompressedLen); if (dstLen != uncompressedLen) { @@ -121,3 +123,5 @@ ZQuestFile *ZQuestFileReader::read() } // io } // zelda + +#endif diff --git a/src/Athena/ZQuestFileWriter.cpp b/src/Athena/ZQuestFileWriter.cpp index c1d0864..66bd66e 100644 --- a/src/Athena/ZQuestFileWriter.cpp +++ b/src/Athena/ZQuestFileWriter.cpp @@ -1,3 +1,4 @@ +#ifndef ATHENA_NO_ZQUEST // This file is part of libAthena. // // libAthena is free software: you can redistribute it and/or modify @@ -24,7 +25,7 @@ namespace Athena namespace io { -ZQuestFileWriter::ZQuestFileWriter(Uint8* data, Uint64 length) +ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length) : base(data, length) { } @@ -41,11 +42,11 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) base::writeUint32(ZQuestFile::Magic); base::writeUint32(ZQuestFile::Version); - Uint8* questData = quest->data(); - Uint32 compLen; + atUint8* questData = quest->data(); + atUint32 compLen; if (compress) { - Uint8* compData = new Uint8[quest->length() + 0x40]; // add 20 bytes because sometimes the file grows with compression + atUint8* compData = new atUint8[quest->length() + 0x40]; // add 20 bytes because sometimes the file grows with compression compLen = quest->length() + 0x40; compLen = io::Compression::compressZlib(questData, quest->length(), compData, compLen); @@ -72,7 +73,7 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) } base::writeUint32(quest->length()); - base::writeBytes((Int8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A); + 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); @@ -88,3 +89,5 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) } // io } // zelda + +#endif // ATHENA_NO_ZQUEST diff --git a/src/aes.c b/src/aes.c index 9d6175e..d38ab2a 100644 --- a/src/aes.c +++ b/src/aes.c @@ -25,38 +25,38 @@ /* Fixed Data */ -static Uint8 InCo[4]={0xB,0xD,0x9,0xE}; /* Inverse Coefficients */ +static atUint8 InCo[4]={0xB,0xD,0x9,0xE}; /* Inverse Coefficients */ -static Uint8 fbsub[256]; -static Uint8 rbsub[256]; -static Uint8 ptab[256],ltab[256]; -static Uint32 ftable[256]; -static Uint32 rtable[256]; -static Uint32 rco[30]; +static atUint8 fbsub[256]; +static atUint8 rbsub[256]; +static atUint8 ptab[256],ltab[256]; +static atUint32 ftable[256]; +static atUint32 rtable[256]; +static atUint32 rco[30]; /* Parameter-dependent data */ int Nk,Nb,Nr; -Uint8 fi[24],ri[24]; -Uint32 fkey[120]; -Uint32 rkey[120]; +atUint8 fi[24],ri[24]; +atUint32 fkey[120]; +atUint32 rkey[120]; -static Uint32 pack(const Uint8 *b) +static atUint32 pack(const atUint8 *b) { /* pack bytes into a 32-bit Word */ - return ((Uint32)b[3]<<24)|((Uint32)b[2]<<16)|((Uint32)b[1]<<8)|(Uint32)b[0]; + return ((atUint32)b[3]<<24)|((atUint32)b[2]<<16)|((atUint32)b[1]<<8)|(atUint32)b[0]; } -static void unpack(Uint32 a,Uint8 *b) +static void unpack(atUint32 a,atUint8 *b) { /* unpack bytes from a word */ - b[0]=(Uint8)a; - b[1]=(Uint8)(a>>8); - b[2]=(Uint8)(a>>16); - b[3]=(Uint8)(a>>24); + b[0]=(atUint8)a; + b[1]=(atUint8)(a>>8); + b[2]=(atUint8)(a>>16); + b[3]=(atUint8)(a>>24); } -static Uint8 xtime(Uint8 a) +static atUint8 xtime(atUint8 a) { - Uint8 b; + atUint8 b; if (a&0x80) b=0x1B; else b=0; a<<=1; @@ -64,15 +64,15 @@ static Uint8 xtime(Uint8 a) return a; } -static Uint8 bmul(Uint8 x,Uint8 y) +static atUint8 bmul(atUint8 x,atUint8 y) { /* x.y= AntiLog(Log(x) + Log(y)) */ if (x && y) return ptab[(ltab[x]+ltab[y])%255]; else return 0; } -static Uint32 SubByte(Uint32 a) +static atUint32 SubByte(atUint32 a) { - Uint8 b[4]; + atUint8 b[4]; unpack(a,b); b[0]=fbsub[b[0]]; b[1]=fbsub[b[1]]; @@ -81,18 +81,18 @@ static Uint32 SubByte(Uint32 a) return pack(b); } -static Uint8 product(Uint32 x,Uint32 y) +static atUint8 product(atUint32 x,atUint32 y) { /* dot product of two 4-byte arrays */ - Uint8 xb[4],yb[4]; + atUint8 xb[4],yb[4]; unpack(x,xb); unpack(y,yb); return bmul(xb[0],yb[0])^bmul(xb[1],yb[1])^bmul(xb[2],yb[2])^bmul(xb[3],yb[3]); } -static Uint32 InvMixCol(Uint32 x) +static atUint32 InvMixCol(atUint32 x) { /* matrix Multiplication */ - Uint32 y,m; - Uint8 b[4]; + atUint32 y,m; + atUint8 b[4]; m=pack(InCo); b[3]=product(m,x); @@ -106,9 +106,9 @@ static Uint32 InvMixCol(Uint32 x) return y; } -Uint8 ByteSub(Uint8 x) +atUint8 ByteSub(atUint8 x) { - Uint8 y=ptab[255-ltab[x]]; /* multiplicative inverse */ + atUint8 y=ptab[255-ltab[x]]; /* multiplicative inverse */ x=y; x=ROTL(x); y^=x; x=ROTL(x); y^=x; x=ROTL(x); @@ -120,7 +120,7 @@ Uint8 ByteSub(Uint8 x) void gentables(void) { /* generate tables */ int i; - Uint8 y,b[4]; + atUint8 y,b[4]; /* use 3 as primitive root to generate power and log tables */ @@ -139,7 +139,7 @@ void gentables(void) rbsub[0x63]=0; for (i=1;i<256;i++) { - y=ByteSub((Uint8)i); + y=ByteSub((atUint8)i); fbsub[i]=y; rbsub[y]=i; } @@ -164,14 +164,14 @@ void gentables(void) } } -void gkey(int nb,int nk, const Uint8 *key) +void gkey(int nb,int nk, const atUint8 *key) { /* blocksize=32*nb bits. Key=32*nk bits */ /* currently nb,bk = 4, 6 or 8 */ /* key comes as 4*Nk bytes */ /* Key Scheduler. Create expanded encryption key */ int i,j,k,m,N; int C1,C2,C3; - Uint32 CipherKey[8]; + atUint32 CipherKey[8]; Nb=nb; Nk=nk; @@ -236,10 +236,10 @@ void gkey(int nb,int nk, const Uint8 *key) * Instead of just one ftable[], I could have 4, the other * * 3 pre-rotated to save the ROTL8, ROTL16 and ROTL24 overhead */ -void encrypt(Uint8 *buff) +void encrypt(atUint8 *buff) { int i,j,k,m; - Uint32 a[8],b[8],*x,*y,*t; + atUint32 a[8],b[8],*x,*y,*t; for (i=j=0;i>8)])^ - ROTL16(ftable[(Uint8)(x[fi[m+1]]>>16)])^ - ROTL24(ftable[(Uint8)(x[fi[m+2]]>>24)]); + y[j]=fkey[k++]^ftable[(atUint8)x[j]]^ + ROTL8(ftable[(atUint8)(x[fi[m]]>>8)])^ + ROTL16(ftable[(atUint8)(x[fi[m+1]]>>16)])^ + ROTL24(ftable[(atUint8)(x[fi[m+2]]>>24)]); } t=x; x=y; y=t; /* swap pointers */ } @@ -270,23 +270,23 @@ void encrypt(Uint8 *buff) /* Last Round - unroll if possible */ for (m=j=0;j>8)])^ - ROTL16((Uint32)fbsub[(Uint8)(x[fi[m+1]]>>16)])^ - ROTL24((Uint32)fbsub[(Uint8)(x[fi[m+2]]>>24)]); + y[j]=fkey[k++]^(atUint32)fbsub[(atUint8)x[j]]^ + ROTL8((atUint32)fbsub[(atUint8)(x[fi[m]]>>8)])^ + ROTL16((atUint32)fbsub[(atUint8)(x[fi[m+1]]>>16)])^ + ROTL24((atUint32)fbsub[(atUint8)(x[fi[m+2]]>>24)]); } for (i=j=0;i>8)])^ - ROTL16(rtable[(Uint8)(x[ri[m+1]]>>16)])^ - ROTL24(rtable[(Uint8)(x[ri[m+2]]>>24)]); + y[j]=rkey[k++]^rtable[(atUint8)x[j]]^ + ROTL8(rtable[(atUint8)(x[ri[m]]>>8)])^ + ROTL16(rtable[(atUint8)(x[ri[m+1]]>>16)])^ + ROTL24(rtable[(atUint8)(x[ri[m+2]]>>24)]); } t=x; x=y; y=t; /* swap pointers */ } @@ -316,28 +316,28 @@ void decrypt(Uint8 *buff) /* Last Round - unroll if possible */ for (m=j=0;j>8)])^ - ROTL16((Uint32)rbsub[(Uint8)(x[ri[m+1]]>>16)])^ - ROTL24((Uint32)rbsub[(Uint8)(x[ri[m+2]]>>24)]); + y[j]=rkey[k++]^(atUint32)rbsub[(atUint8)x[j]]^ + ROTL8((atUint32)rbsub[(atUint8)(x[ri[m]]>>8)])^ + ROTL16((atUint32)rbsub[(atUint8)(x[ri[m+1]]>>16)])^ + ROTL24((atUint32)rbsub[(atUint8)(x[ri[m+2]]>>24)]); } for (i=j=0;i> 4]; @@ -122,10 +122,10 @@ static void elt_square_to_wide(Uint8 *d, Uint8 *a) } } -static void wide_reduce(Uint8 *d) +static void wide_reduce(atUint8 *d) { - Uint32 i; - Uint8 x; + atUint32 i; + atUint8 x; for (i = 0; i < 30; i++) { x = d[i]; @@ -147,9 +147,9 @@ static void wide_reduce(Uint8 *d) d[30] &= 1; } -static void elt_square(Uint8 *d, Uint8 *a) +static void elt_square(atUint8 *d, atUint8 *a) { - Uint8 wide[60]; + atUint8 wide[60]; elt_square_to_wide(wide, a); wide_reduce(wide); @@ -157,9 +157,9 @@ static void elt_square(Uint8 *d, Uint8 *a) elt_copy(d, wide + 30); } -static void itoh_tsujii(Uint8 *d, Uint8 *a, Uint8 *b, Uint32 j) +static void itoh_tsujii(atUint8 *d, atUint8 *a, atUint8 *b, atUint32 j) { - Uint8 t[30]; + atUint8 t[30]; elt_copy(t, a); while (j--) { @@ -170,10 +170,10 @@ static void itoh_tsujii(Uint8 *d, Uint8 *a, Uint8 *b, Uint32 j) elt_mul(d, t, b); } -static void elt_inv(Uint8 *d, Uint8 *a) +static void elt_inv(atUint8 *d, atUint8 *a) { - Uint8 t[30]; - Uint8 s[30]; + atUint8 t[30]; + atUint8 s[30]; itoh_tsujii(t, a, a, 1); itoh_tsujii(s, t, a, 1); @@ -212,15 +212,15 @@ static int point_is_on_curve(u8 *p) return elt_is_zero(s); } */ -static int point_is_zero(Uint8 *p) +static int point_is_zero(atUint8 *p) { return elt_is_zero(p) && elt_is_zero(p + 30); } -static void point_double(Uint8 *r, Uint8 *p) +static void point_double(atUint8 *r, atUint8 *p) { - Uint8 s[30], t[30]; - Uint8 *px, *py, *rx, *ry; + atUint8 s[30], t[30]; + atUint8 *px, *py, *rx, *ry; px = p; py = p + 30; @@ -249,10 +249,10 @@ static void point_double(Uint8 *r, Uint8 *p) elt_add(ry, ry, t); } -static void point_add(Uint8 *r, Uint8 *p, Uint8 *q) +static void point_add(atUint8 *r, atUint8 *p, atUint8 *q) { - Uint8 s[30], t[30], u[30]; - Uint8 *px, *py, *qx, *qy, *rx, *ry; + atUint8 s[30], t[30], u[30]; + atUint8 *px, *py, *qx, *qy, *rx, *ry; px = p; py = p + 30; @@ -302,10 +302,10 @@ static void point_add(Uint8 *r, Uint8 *p, Uint8 *q) elt_add(ry, s, rx); } -static void point_mul(Uint8 *d, Uint8 *a, Uint8 *b) // a is bignum +static void point_mul(atUint8 *d, atUint8 *a, atUint8 *b) // a is bignum { - Uint32 i; - Uint8 mask; + atUint32 i; + atUint8 mask; elt_zero(d); elt_zero(d + 30); @@ -318,13 +318,13 @@ static void point_mul(Uint8 *d, Uint8 *a, Uint8 *b) // a is bignum } } -void generate_ecdsa(Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash) +void generate_ecdsa(atUint8 *R, atUint8 *S, atUint8 *k, atUint8 *hash) { - Uint8 e[30]; - Uint8 kk[30]; - Uint8 m[30]; - Uint8 minv[30]; - Uint8 mG[60]; + atUint8 e[30]; + atUint8 kk[30]; + atUint8 m[30]; + atUint8 minv[30]; + atUint8 mG[60]; //FILE *fp; elt_zero(e); @@ -351,12 +351,12 @@ void generate_ecdsa(Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash) bn_mul(S, minv, kk, ec_N, 30); } -bool check_ecdsa(Uint8 *Q, Uint8 *R, Uint8 *S, Uint8 *hash) +bool check_ecdsa(atUint8 *Q, atUint8 *R, atUint8 *S, atUint8 *hash) { - Uint8 Sinv[30]; - Uint8 e[30]; - Uint8 w1[30], w2[30]; - Uint8 r1[60], r2[60]; + atUint8 Sinv[30]; + atUint8 e[30]; + atUint8 w1[30], w2[30]; + atUint8 r1[60], r2[60]; bn_inv(Sinv, S, ec_N, 30); @@ -377,16 +377,16 @@ bool check_ecdsa(Uint8 *Q, Uint8 *R, Uint8 *S, Uint8 *hash) return (bn_compare(r1, R, 30) == 0); } -void ec_priv_to_pub(Uint8 *k, Uint8 *Q) +void ec_priv_to_pub(atUint8 *k, atUint8 *Q) { point_mul(Q, k, ec_G); } -bool check_ec(Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash) +bool check_ec(atUint8 *ng, atUint8 *ap, atUint8 *sig, atUint8 *sig_hash) { - Uint8* ap_hash; - Uint8 *ng_Q, *ap_R, *ap_S; - Uint8 *ap_Q, *sig_R, *sig_S; + atUint8* ap_hash; + atUint8 *ng_Q, *ap_R, *ap_S; + atUint8 *ap_Q, *sig_R, *sig_S; ng_Q = ng + 0x0108; ap_R = ap + 0x04; @@ -402,21 +402,21 @@ bool check_ec(Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash) && check_ecdsa(ap_Q, sig_R, sig_S, sig_hash); } -void make_ec_cert(Uint8 *cert, Uint8 *sig, char *signer, char *name, Uint8 *priv, Uint32 key_id ) +void make_ec_cert(atUint8 *cert, atUint8 *sig, char *signer, char *name, atUint8 *priv, atUint32 key_id ) { memset(cert, 0, 0x180); - *(Uint32*)(cert) = 0x10002; + *(atUint32*)(cert) = 0x10002; if (!Athena::utility::isSystemBigEndian()) - *(Uint32*)(cert) = Athena::utility::swapU32(*(Uint32*)(cert)); + *(atUint32*)(cert) = Athena::utility::swapU32(*(atUint32*)(cert)); memcpy((char*)cert + 4, sig, 60); strcpy((char*)cert + 0x80, signer); - *(Uint32*)(cert + 0xc0) = 2; + *(atUint32*)(cert + 0xc0) = 2; if (!Athena::utility::isSystemBigEndian()) - *(Uint32*)(cert + 0xc0) = Athena::utility::swapU32(*(Uint32*)(cert + 0xc0)); + *(atUint32*)(cert + 0xc0) = Athena::utility::swapU32(*(atUint32*)(cert + 0xc0)); strcpy((char*)cert + 0xc4, name); - *(Uint32*)(cert + 0x104) = key_id; + *(atUint32*)(cert + 0x104) = key_id; if (!Athena::utility::isSystemBigEndian()) - *(Uint32*)(cert + 0x104) = Athena::utility::swapU32(*(Uint32*)(cert + 0x104)); + *(atUint32*)(cert + 0x104) = Athena::utility::swapU32(*(atUint32*)(cert + 0x104)); ec_priv_to_pub(priv, cert + 0x108); } diff --git a/src/lzo.c b/src/lzo.c index 6ce580b..e1d85e0 100644 --- a/src/lzo.c +++ b/src/lzo.c @@ -28,8 +28,8 @@ //! define if we may read up to 4 bytes beyond the input buffer //#define INBUF_PADDED 1 typedef struct LZOContext { - Uint8 *in, *in_end; - Uint8 *out_start, *out, *out_end; + atUint8 *in, *in_end; + atUint8 *out_start, *out, *out_end; int error; } LZOContext; @@ -166,9 +166,9 @@ static void copy_backptr(LZOContext *c, int back, int cnt) { * make sure all buffers are appropriately padded, in must provide * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes */ -int lzo1x_decode(Uint8 *out, Int32 *outlen, Uint8 *in, Int32 *inlen) { +int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen) { enum {COPY, BACKPTR} state = COPY; - Int32 x; + atInt32 x; LZOContext c; c.in = in; c.in_end = in + *inlen; diff --git a/src/sha1.cpp b/src/sha1.cpp index 0584a90..dca61be 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -372,15 +372,15 @@ void SHA1PadMessage(SHA1Context *context) SHA1ProcessMessageBlock(context); } -Uint8* getSha1( Uint8 * stuff, Uint32 stuff_size ) +atUint8* getSha1( atUint8 * stuff, atUint32 stuff_size ) { SHA1Context sha; SHA1Reset( &sha ); - SHA1Input( &sha, (const Uint8*)stuff, stuff_size ); + SHA1Input( &sha, (const atUint8*)stuff, stuff_size ); if( !SHA1Result( &sha ) ) return 0; - Uint8* ret = new Uint8[20]; + atUint8* ret = new atUint8[20]; memset(ret, 0, 20); for( int i = 0; i < 5 ; i++ )