Use standard integer types

This commit is contained in:
Phillip Stephens 2025-04-26 09:34:02 -07:00
parent d2d54fe6ef
commit 9e0486c1f6
93 changed files with 1248 additions and 1257 deletions

View File

@ -4,31 +4,31 @@
class LZBase {
public:
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3,
atInt32 blockSize = 8);
explicit LZBase(int32_t minimumOffset = 1, int32_t slidingWindow = 4096, int32_t minimumMatch = 3,
int32_t blockSize = 8);
virtual ~LZBase();
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual uint32_t compress(const uint8_t* src, uint8_t** dest, uint32_t srcLength) = 0;
virtual uint32_t decompress(const uint8_t* src, uint8_t** dest, uint32_t srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow() const;
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer() const;
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch() const;
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize() const;
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset() const;
void setSlidingWindow(int32_t SlidingWindow);
int32_t slidingWindow() const;
void setReadAheadBuffer(int32_t ReadAheadBuffer);
int32_t readAheadBuffer() const;
void setMinMatch(int32_t minimumMatch);
int32_t minMatch() const;
void setBlockSize(int32_t BlockSize);
int32_t blockSize() const;
void setMinimumOffset(uint32_t minimumOffset);
uint32_t minimumOffset() const;
protected:
LZLengthOffset search(const atUint8* posPtr, const atUint8* dataBegin, const atUint8* dataEnd) const;
LZLengthOffset search(const uint8_t* posPtr, const uint8_t* dataBegin, const uint8_t* dataEnd) const;
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;
atInt32 m_minMatch; // Minimum number of bytes that have to matched to go through with compression
atInt32 m_blockSize;
atUint32 m_minOffset;
int32_t m_slidingWindow;
int32_t m_readAheadBuffer;
int32_t m_minMatch; // Minimum number of bytes that have to matched to go through with compression
int32_t m_blockSize;
uint32_t m_minOffset;
LZLookupTable m_lookupTable;
};

View File

@ -6,8 +6,8 @@
#include <athena/Types.hpp>
struct LZLengthOffset {
atUint32 length; // The number of bytes compressed
atUint16 offset; // How far back in sliding window where bytes that match the lookAheadBuffer is located
uint32_t length; // The number of bytes compressed
uint16_t offset; // How far back in sliding window where bytes that match the lookAheadBuffer is located
bool operator==(const LZLengthOffset& lo_pair) const { return length == lo_pair.length && offset == lo_pair.offset; }
bool operator!=(const LZLengthOffset& lo_pair) const { return !operator==(lo_pair); }
};
@ -15,16 +15,16 @@ struct LZLengthOffset {
class LZLookupTable {
public:
LZLookupTable();
explicit LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
explicit LZLookupTable(int32_t minimumMatch, int32_t slidingWindow = 4096, int32_t lookAheadWindow = 18);
~LZLookupTable();
LZLengthOffset search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
void setLookAheadWindow(atInt32 lookAheadWindow);
LZLengthOffset search(const uint8_t* curPos, const uint8_t* dataBegin, const uint8_t* dataEnd);
void setLookAheadWindow(int32_t lookAheadWindow);
private:
using LookupTable = std::multimap<std::vector<uint8_t>, int32_t>;
LookupTable table;
atInt32 m_minimumMatch = 3;
atInt32 m_slidingWindow = 4096;
atInt32 m_lookAheadWindow = 18;
int32_t m_minimumMatch = 3;
int32_t m_slidingWindow = 4096;
int32_t m_lookAheadWindow = 18;
std::vector<uint8_t> m_buffer;
};

View File

@ -4,8 +4,8 @@
class LZType10 : public LZBase {
public:
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLength) override;
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen) override;
explicit LZType10(int32_t minimumOffset = 1, int32_t SlidingWindow = 4096, int32_t MinimumMatch = 3,
int32_t BlockSize = 8);
uint32_t compress(const uint8_t* src, uint8_t** dstBuf, uint32_t srcLength) override;
uint32_t decompress(const uint8_t* src, uint8_t** dst, uint32_t srcLen) override;
};

View File

@ -4,8 +4,8 @@
class LZType11 : public LZBase {
public:
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dst, atUint32 srcLength) override;
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) override;
explicit LZType11(int32_t MinimumOffset = 1, int32_t SlidingWindow = 4096, int32_t MinimumMatch = 3,
int32_t BlockSize = 8);
uint32_t compress(const uint8_t* src, uint8_t** dst, uint32_t srcLength) override;
uint32_t decompress(const uint8_t* src, uint8_t** dst, uint32_t srcLength) override;
};

View File

@ -40,7 +40,7 @@ public:
* \param val The new quest to assign to the given index
* \throw InvalidOperationException on index out of range
*/
void setQuest(atUint32 id, ALTTPQuest* val);
void setQuest(uint32_t id, ALTTPQuest* val);
/*! \brief Returns the primary quest list
*
* \return The primary quest list
@ -54,13 +54,13 @@ public:
* \return ALTTPQuest*
* \throw InvalidOperationException on index out of range
*/
ALTTPQuest* quest(atUint32 id) const;
ALTTPQuest* quest(uint32_t id) const;
/*! \brief Returns the number of primary quests
*
* \return The number of quests
*/
atUint32 questCount() const;
uint32_t questCount() const;
private:
std::vector<ALTTPQuest*> m_quests;

View File

@ -23,7 +23,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(atUint8*, atUint64);
ALTTPFileReader(uint8_t*, uint64_t);
/*! \brief This constructor creates an instance from a file on disk.
*

View File

@ -22,7 +22,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(atUint8*, atUint64);
ALTTPFileWriter(uint8_t*, uint64_t);
/*! \brief This constructor creates an instance from a file on disk.
*
@ -40,7 +40,7 @@ private:
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
void writeDungeonItems(ALTTPDungeonItemFlags);
atUint16 calculateChecksum(atUint32 game);
uint16_t calculateChecksum(uint32_t game);
};
} // namespace io

View File

@ -33,7 +33,7 @@ public:
* \param rf
* \param id
*/
void setRoomFlags(ALTTPRoomFlags* rf, atUint32 id);
void setRoomFlags(ALTTPRoomFlags* rf, uint32_t id);
/*!
* \brief roomFlags
@ -46,7 +46,7 @@ public:
* \param id
* \return
*/
ALTTPRoomFlags* roomFlags(atUint32 id);
ALTTPRoomFlags* roomFlags(uint32_t id);
/*!
* \brief setOverworldEvents
@ -59,7 +59,7 @@ public:
* \param ow
* \param id
*/
void setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id);
void setOverworldEvents(ALTTPOverworldEvent* ow, uint32_t id);
/*!
* \brief overworldEvents
@ -72,7 +72,7 @@ public:
* \param id
* \return
*/
ALTTPOverworldEvent* overworldEvent(atUint32 id) const;
ALTTPOverworldEvent* overworldEvent(uint32_t id) const;
/*!
* \brief setInventory
@ -90,25 +90,25 @@ public:
* \brief setRupeeMax
* \param val
*/
void setRupeeMax(atUint16 val);
void setRupeeMax(uint16_t val);
/*!
* \brief rupeeMax
* \return
*/
atUint16 rupeeMax() const;
uint16_t rupeeMax() const;
/*!
* \brief setRupeeCurrent
* \param val
*/
void setRupeeCurrent(atUint16 val);
void setRupeeCurrent(uint16_t val);
/*!
* \brief rupeeCurrent
* \return
*/
atUint16 rupeeCurrent() const;
uint16_t rupeeCurrent() const;
/*!
* \brief setCompasses
@ -150,109 +150,109 @@ public:
* \brief setWishingPond
* \param val
*/
void setWishingPond(atUint16 val);
void setWishingPond(uint16_t val);
/*!
* \brief wishingPond
* \return
*/
atUint16 wishingPond() const;
uint16_t wishingPond() const;
/*!
* \brief setHealthMax
* \param val
*/
void setHealthMax(atUint8 val);
void setHealthMax(uint8_t val);
/*!
* \brief healthMax
* \return
*/
atUint8 healthMax() const;
uint8_t healthMax() const;
/*!
* \brief setHealth
* \param val
*/
void setHealth(atUint8 val);
void setHealth(uint8_t val);
/*!
* \brief health
* \return
*/
atUint8 health() const;
uint8_t health() const;
/*!
* \brief setMagicPower
* \param val
*/
void setMagicPower(atUint8 val);
void setMagicPower(uint8_t val);
/*!
* \brief magicPower
* \return
*/
atUint8 magicPower() const;
uint8_t magicPower() const;
/*!
* \brief setKeys
* \param val
*/
void setKeys(atUint8 val);
void setKeys(uint8_t val);
/*!
* \brief keys
* \return
*/
atUint8 keys() const;
uint8_t keys() const;
/*!
* \brief setBombUpgrades
* \param val
*/
void setBombUpgrades(atUint8 val);
void setBombUpgrades(uint8_t val);
/*!
* \brief bombUpgrades
* \return
*/
atUint8 bombUpgrades() const;
uint8_t bombUpgrades() const;
/*!
* \brief setArrowUpgrades
* \param val
*/
void setArrowUpgrades(atUint8 val);
void setArrowUpgrades(uint8_t val);
/*!
* \brief arrowUpgrades
* \return
*/
atUint8 arrowUpgrades() const;
uint8_t arrowUpgrades() const;
/*!
* \brief setHealthFiller
* \param val
*/
void setHealthFiller(atUint8 val);
void setHealthFiller(uint8_t val);
/*!
* \brief healthFiller
* \return
*/
atUint8 healthFiller() const;
uint8_t healthFiller() const;
/*!
* \brief setMagicFiller
* \param val
*/
void setMagicFiller(atUint8 val);
void setMagicFiller(uint8_t val);
/*!
* \brief magicFiller
* \return
*/
atUint8 magicFiller() const;
uint8_t magicFiller() const;
/*!
* \brief setPendants
@ -270,37 +270,37 @@ public:
* \brief setBombFiller
* \param val
*/
void setBombFiller(atUint8 val);
void setBombFiller(uint8_t val);
/*!
* \brief bombFiller
* \return
*/
atUint8 bombFiller() const;
uint8_t bombFiller() const;
/*!
* \brief setArrowFiller
* \param val
*/
void setArrowFiller(atUint8 val);
void setArrowFiller(uint8_t val);
/*!
* \brief arrowFiller
* \return
*/
atUint8 arrowFiller() const;
uint8_t arrowFiller() const;
/*!
* \brief setArrows
* \param val
*/
void setArrows(atUint8 val);
void setArrows(uint8_t val);
/*!
* \brief arrows
* \return
*/
atUint8 arrows() const;
uint8_t arrows() const;
/*!
* \brief setAbilityFlags
@ -342,27 +342,27 @@ public:
* \brief setDungeonKeys
* \param val
*/
void setDungeonKeys(std::vector<atUint8> val);
void setDungeonKeys(std::vector<uint8_t> val);
/*!
* \brief setDungeonKeys
* \param id
* \param val
*/
void setDungeonKeys(atUint32 id, atUint8 val);
void setDungeonKeys(uint32_t id, uint8_t val);
/*!
* \brief dungeonKeys
* \param id
* \return
*/
atUint8 dungeonKeys(atUint32 id) const;
uint8_t dungeonKeys(uint32_t id) const;
/*!
* \brief dungeonCount
* \return
*/
atUint32 dungeonCount() const;
uint32_t dungeonCount() const;
/*!
* \brief setProgressIndicator
@ -452,71 +452,71 @@ public:
* \brief setOldManFlags
* \param flags
*/
void setOldManFlags(std::vector<atUint8> flags);
void setOldManFlags(std::vector<uint8_t> flags);
/*!
* \brief setOldManFlag
* \param id
* \param val
*/
void setOldManFlag(atUint32 id, atUint8 val);
void setOldManFlag(uint32_t id, uint8_t val);
/*!
* \brief oldManFlag
* \param id
* \return
*/
atUint8 oldManFlag(atUint32 id);
uint8_t oldManFlag(uint32_t id);
/*!
* \brief oldManFlagCount
* \return
*/
atUint32 oldManFlagCount() const;
uint32_t oldManFlagCount() const;
/*!
* \brief setBombFlag
* \param flag
*/
void setBombFlag(atUint8 flag);
void setBombFlag(uint8_t flag);
/*!
* \brief bombFlag
* \return
*/
atUint8 bombFlag() const;
uint8_t bombFlag() const;
/*!
* \brief setUnknown1
* \param flags
*/
void setUnknown1(std::vector<atUint8> flags);
void setUnknown1(std::vector<uint8_t> flags);
/*!
* \brief setUnknown1
* \param id
* \param val
*/
void setUnknown1(atUint32 id, atUint8 val);
void setUnknown1(uint32_t id, uint8_t val);
/*!
* \brief unknown1
* \param id
* \return
*/
atUint8 unknown1(atUint32 id);
uint8_t unknown1(uint32_t id);
/*!
* \brief unknown1Count
* \return
*/
atUint32 unknown1Count() const;
uint32_t unknown1Count() const;
/*!
* \brief setPlayerName
* \param playerName
*/
void setPlayerName(std::vector<atUint16> playerName);
void setPlayerName(std::vector<uint16_t> playerName);
/*!
* \brief setPlayerName
* \param playerName
@ -526,7 +526,7 @@ public:
* \brief playerName
* \return
*/
std::vector<atUint16> playerName() const;
std::vector<uint16_t> playerName() const;
/*!
* \brief playerNameToString
* \return
@ -549,102 +549,102 @@ public:
* \brief setDungeonDeathTotals
* \param val
*/
void setDungeonDeathTotals(std::vector<atUint16> val);
void setDungeonDeathTotals(std::vector<uint16_t> val);
/*!
* \brief setDungeonDeathTotal
* \param id
* \param val
*/
void setDungeonDeathTotal(atUint32 id, atUint16 val);
void setDungeonDeathTotal(uint32_t id, uint16_t val);
/*!
* \brief dungeonDeathTotal
* \param id
* \return
*/
atUint16 dungeonDeathTotal(atUint32 id) const;
uint16_t dungeonDeathTotal(uint32_t id) const;
/*!
* \brief dungeonDeathTotalCount
* \return
*/
atUint16 dungeonDeathTotalCount() const;
uint16_t dungeonDeathTotalCount() const;
/*!
* \brief setUnknown2
* \param val
*/
void setUnknown2(atUint16 val);
void setUnknown2(uint16_t val);
/*!
* \brief unknown2
* \return
*/
atUint16 unknown2() const;
uint16_t unknown2() const;
/*!
* \brief setDeathSaveCount
* \param val
*/
void setDeathSaveCount(atUint16 val);
void setDeathSaveCount(uint16_t val);
/*!
* \brief deathSaveCount
* \return
*/
atUint16 deathSaveCount() const;
uint16_t deathSaveCount() const;
/*!
* \brief setPostGameDeathCounter
* \param val
*/
void setPostGameDeathCounter(atInt16 val);
void setPostGameDeathCounter(int16_t val);
/*!
* \brief postGameDeathCounter
* \return
*/
atInt16 postGameDeathCounter() const;
int16_t postGameDeathCounter() const;
/*!
* \brief setChecksum
* \param checksum
*/
void setChecksum(atUint16 checksum);
void setChecksum(uint16_t checksum);
/*!
* \brief checksum
* \return
*/
atUint16 checksum() const;
uint16_t checksum() const;
private:
std::vector<ALTTPRoomFlags*> m_roomFlags;
std::vector<ALTTPOverworldEvent*> m_overworldEvents;
ALTTPInventory m_inventory;
atUint16 m_rupeeMax;
atUint16 m_rupeeCurrent;
uint16_t m_rupeeMax;
uint16_t m_rupeeCurrent;
ALTTPDungeonItemFlags m_compasses;
ALTTPDungeonItemFlags m_bigKeys;
ALTTPDungeonItemFlags m_dungeonMaps;
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;
uint16_t m_wishingPond;
uint8_t m_healthMax;
uint8_t m_health;
uint8_t m_magicPower;
uint8_t m_keys;
uint8_t m_bombUpgrades;
uint8_t m_arrowUpgrades;
uint8_t m_heartFiller;
uint8_t m_magicFiller;
ALTTPPendants m_pendants;
atUint8 m_bombFiller;
atUint8 m_arrowFiller;
atUint8 m_arrows;
uint8_t m_bombFiller;
uint8_t m_arrowFiller;
uint8_t m_arrows;
ALTTPAbilities m_abilityFlags;
ALTTPCrystals m_crystals;
ALTTPMagicUsage m_magicUsage;
std::vector<atUint8> m_dungeonKeys;
std::vector<uint8_t> m_dungeonKeys;
ALTTPProgressIndicator m_progressIndicator;
ALTTPProgressFlags1 m_progressFlags1;
ALTTPMapIcon m_mapIcon;
@ -652,16 +652,16 @@ private:
ALTTPProgressFlags2 m_progressFlags2;
ALTTPLightDarkWorldIndicator m_lightDarkWorldIndicator;
ALTTPTagAlong m_tagAlong;
std::vector<atUint8> m_oldManFlags;
atUint8 m_bombFlag;
std::vector<atUint8> m_unknown1;
std::vector<atUint16> m_playerName;
std::vector<uint8_t> m_oldManFlags;
uint8_t m_bombFlag;
std::vector<uint8_t> m_unknown1;
std::vector<uint16_t> m_playerName;
bool m_valid;
std::vector<atUint16> m_dungeonDeathTotals;
atUint16 m_unknown2;
atUint16 m_deathSaveCount;
atInt16 m_postGameDeathCounter;
atUint16 m_checksum;
std::vector<uint16_t> m_dungeonDeathTotals;
uint16_t m_unknown2;
uint16_t m_deathSaveCount;
int16_t m_postGameDeathCounter;
uint16_t m_checksum;
};
} // namespace athena

View File

@ -92,7 +92,7 @@ struct ALTTPDungeonItemFlags {
bool IcePalace : 1;
bool SkullWoods : 1;
};
atUint8 flags1;
uint8_t flags1;
};
union {
@ -106,7 +106,7 @@ struct ALTTPDungeonItemFlags {
bool HyruleCastle : 1; // unused exist in original game
bool SewerPassage : 1; // unused exist in original game
};
atUint8 flags2;
uint8_t flags2;
};
};

View File

@ -3,9 +3,9 @@
#include "athena/Types.hpp"
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF,
atUint64 final = 0xFFFFFFFFFFFFFFFF);
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed = 0xFFFFFFFF, atUint32 final = 0xFFFFFFFF);
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0);
atUint16 crc16(const atUint8* data, atUint64 length, atUint16 seed = 0, atUint16 final = 0);
uint64_t crc64(const uint8_t* data, uint64_t length, uint64_t seed = 0xFFFFFFFFFFFFFFFF,
uint64_t final = 0xFFFFFFFFFFFFFFFF);
uint32_t crc32(const uint8_t* data, uint64_t length, uint32_t seed = 0xFFFFFFFF, uint32_t final = 0xFFFFFFFF);
uint16_t crc16CCITT(const uint8_t* data, uint64_t length, uint16_t seed = 0xFFFF, uint16_t final = 0);
uint16_t crc16(const uint8_t* data, uint64_t length, uint16_t seed = 0, uint16_t final = 0);
} // namespace athena::checksums

View File

@ -4,8 +4,8 @@
namespace athena::io::Compression {
// Zlib compression
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
int32_t decompressZlib(const uint8_t* src, uint32_t srcLen, uint8_t* dst, uint32_t dstLen);
int32_t compressZlib(const uint8_t* src, uint32_t srcLen, uint8_t* dst, uint32_t dstLen);
#if AT_LZOKAY
// lzo compression
@ -13,9 +13,9 @@ atInt32 decompressLZO(const atUint8* source, atInt32 sourceSize, atUint8* dst, a
#endif
// Yaz0 encoding
atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize);
atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data);
uint32_t yaz0Decode(const uint8_t* src, uint8_t* dst, uint32_t uncompressedSize);
uint32_t yaz0Encode(const uint8_t* src, uint32_t srcSize, uint8_t* data);
atUint32 decompressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst);
atUint32 compressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst, bool extended = false);
uint32_t decompressLZ77(const uint8_t* src, uint32_t srcLen, uint8_t** dst);
uint32_t compressLZ77(const uint8_t* src, uint32_t srcLen, uint8_t** dst, bool extended = false);
} // namespace athena::io::Compression

View File

@ -24,8 +24,8 @@ public:
std::string extension() const;
static std::string extension(std::string_view path) { return FileInfo(path).extension(); }
atUint64 size() const;
static atUint64 size(std::string_view path) { return FileInfo(path).size(); }
uint64_t size() const;
static uint64_t size(std::string_view path) { return FileInfo(path).size(); }
bool exists() const;
static bool exists(std::string_view path) { return FileInfo(path).exists(); }

View File

@ -10,8 +10,8 @@
namespace athena::io {
class FileReader : public IStreamReader {
public:
explicit FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
explicit FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
explicit FileReader(std::string_view filename, int32_t cacheSize = (32 * 1024), bool globalErr = true);
explicit FileReader(std::wstring_view filename, int32_t cacheSize = (32 * 1024), bool globalErr = true);
~FileReader() override;
std::string filename() const {
@ -33,12 +33,12 @@ public:
void open();
void close();
bool isOpen() const { return m_fileHandle != nullptr; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
atUint64 position() const override;
atUint64 length() const override;
atUint64 readUBytesToBuf(void* buf, atUint64 len) override;
void seek(int64_t pos, SeekOrigin origin = SeekOrigin::Current) override;
uint64_t position() const override;
uint64_t length() const override;
uint64_t readUBytesToBuf(void* buf, uint64_t len) override;
void setCacheSize(const atInt32 blockSize);
void setCacheSize(const int32_t blockSize);
#if _WIN32
using HandleType = void*;
@ -55,11 +55,11 @@ protected:
std::string m_filename;
#endif
HandleType m_fileHandle;
atUint64 m_fileSize;
std::unique_ptr<atUint8[]> m_cacheData;
atInt32 m_blockSize;
atInt32 m_curBlock;
atUint64 m_offset;
uint64_t m_fileSize;
std::unique_ptr<uint8_t[]> m_cacheData;
int32_t m_blockSize;
int32_t m_curBlock;
uint64_t m_offset;
bool m_globalErr;
};
} // namespace athena::io

View File

@ -30,10 +30,10 @@ public:
void open(bool overwrite = true);
void close();
bool isOpen() const { return m_fileHandle != nullptr; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
atUint64 position() const override;
atUint64 length() const override;
void writeUBytes(const atUint8* data, atUint64 len) override;
void seek(int64_t pos, SeekOrigin origin = SeekOrigin::Current) override;
uint64_t position() const override;
uint64_t length() const override;
void writeUBytes(const uint8_t* data, uint64_t len) override;
#ifdef _WIN32
using HandleType = void*;
@ -61,7 +61,7 @@ class TransactionalFileWriter : public IStreamWriter {
#endif
bool m_overwrite, m_globalErr;
std::vector<uint8_t> m_deferredBuffer;
atUint64 m_position = 0;
uint64_t m_position = 0;
public:
explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
@ -94,10 +94,10 @@ public:
m_position = 0;
}
atUint64 position() const override { return m_position; }
atUint64 length() const override { return m_deferredBuffer.size(); }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
void writeUBytes(const atUint8* data, atUint64 len) override;
uint64_t position() const override { return m_position; }
uint64_t length() const override { return m_deferredBuffer.size(); }
void seek(int64_t pos, SeekOrigin origin = SeekOrigin::Current) override;
void writeUBytes(const uint8_t* data, uint64_t len) override;
~TransactionalFileWriter() override { flush(); }
};

View File

@ -12,10 +12,10 @@ public:
Endian endian() const { return m_endian; }
bool isBigEndian() const { return (m_endian == Endian::Big); }
bool isLittleEndian() const { return (m_endian == Endian::Little); }
virtual void seek(atInt64, SeekOrigin) = 0;
virtual void seek(int64_t, SeekOrigin) = 0;
virtual bool atEnd() const = 0;
virtual atUint64 position() const = 0;
virtual atUint64 length() const = 0;
virtual uint64_t position() const = 0;
virtual uint64_t length() const = 0;
bool hasError() const { return m_hasError; }
protected:

View File

@ -24,7 +24,7 @@ public:
* @param position where in the buffer to seek
* @param origin The Origin to seek relative to
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override = 0;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override = 0;
/** @brief Sets the buffer's position relative to the next 64-byte aligned position.<br />
*/
@ -52,33 +52,33 @@ public:
*
* @return The current position in the stream.
*/
atUint64 position() const override = 0;
uint64_t position() const override = 0;
/** @brief Returns the length of the file.
*
* @return True length of the file.
*/
atUint64 length() const override = 0;
uint64_t length() const override = 0;
/** @brief Reads a byte at the current position and advances the current position
*
* @return The value at the current position
*/
atInt8 readByte() {
atInt8 val = 0;
int8_t readByte() {
int8_t val = 0;
readUBytesToBuf(&val, 1);
return val;
}
template <class T>
atInt8 readVal(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
int8_t readVal(std::enable_if_t<std::is_same_v<T, int8_t>>* = nullptr) {
return readByte();
}
template <class T>
atInt8 readValLittle(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
int8_t readValLittle(std::enable_if_t<std::is_same_v<T, int8_t>>* = nullptr) {
return readByte();
}
template <class T>
atInt8 readValBig(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
int8_t readValBig(std::enable_if_t<std::is_same_v<T, int8_t>>* = nullptr) {
return readByte();
}
@ -86,17 +86,17 @@ public:
*
* @return The value at the current position
*/
atUint8 readUByte() { return readByte(); }
uint8_t readUByte() { return readByte(); }
template <class T>
atUint8 readVal(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
uint8_t readVal(std::enable_if_t<std::is_same_v<T, uint8_t>>* = nullptr) {
return readUByte();
}
template <class T>
atUint8 readValLittle(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
uint8_t readValLittle(std::enable_if_t<std::is_same_v<T, uint8_t>>* = nullptr) {
return readUByte();
}
template <class T>
atUint8 readValBig(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
uint8_t readValBig(std::enable_if_t<std::is_same_v<T, uint8_t>>* = nullptr) {
return readUByte();
}
@ -104,8 +104,8 @@ public:
*
* @return The buffer at the current position from the given length.
*/
std::unique_ptr<atInt8[]> readBytes(atUint64 length) {
auto buf = std::make_unique<atInt8[]>(length);
std::unique_ptr<int8_t[]> readBytes(uint64_t length) {
auto buf = std::make_unique<int8_t[]>(length);
readUBytesToBuf(buf.get(), length);
return buf;
}
@ -114,8 +114,8 @@ public:
*
* @return The buffer at the current position from the given length.
*/
std::unique_ptr<atUint8[]> readUBytes(atUint64 length) {
auto buf = std::make_unique<atUint8[]>(length);
std::unique_ptr<uint8_t[]> readUBytes(uint64_t length) {
auto buf = std::make_unique<uint8_t[]>(length);
readUBytesToBuf(buf.get(), length);
return buf;
}
@ -125,7 +125,7 @@ public:
* @param len The length of the buffer
* @return How much data was actually read, useful for detecting read errors.
*/
atUint64 readBytesToBuf(void* buf, atUint64 len) { return readUBytesToBuf(buf, len); }
uint64_t readBytesToBuf(void* buf, uint64_t len) { return readUBytesToBuf(buf, len); }
/** @brief Attempts to read a fixed length of data into a pre-allocated buffer, this function is client defined
* and must be implemented.
@ -133,20 +133,20 @@ public:
* @param len The length of the buffer
* @return How much data was actually read, useful for detecting read errors.
*/
virtual atUint64 readUBytesToBuf(void* buf, atUint64 len) = 0;
virtual uint64_t readUBytesToBuf(void* buf, uint64_t len) = 0;
/** @brief Reads a Int16 and swaps to endianness specified by setEndian depending on platform
* and advances the current position
*
* @return The value at the current address
*/
atInt16 readInt16() {
atInt16 val = 0;
int16_t readInt16() {
int16_t val = 0;
readUBytesToBuf(&val, 2);
return m_endian == Endian::Big ? utility::BigInt16(val) : utility::LittleInt16(val);
}
template <class T>
atInt16 readVal(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
int16_t readVal(std::enable_if_t<std::is_same_v<T, int16_t>>* = nullptr) {
return readInt16();
}
@ -155,13 +155,13 @@ public:
*
* @return The value at the current address
*/
atInt16 readInt16Little() {
atInt16 val = 0;
int16_t readInt16Little() {
int16_t val = 0;
readUBytesToBuf(&val, 2);
return utility::LittleInt16(val);
}
template <class T>
atInt16 readValLittle(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
int16_t readValLittle(std::enable_if_t<std::is_same_v<T, int16_t>>* = nullptr) {
return readInt16Little();
}
@ -170,13 +170,13 @@ public:
*
* @return The value at the current address
*/
atInt16 readInt16Big() {
atInt16 val = 0;
int16_t readInt16Big() {
int16_t val = 0;
readUBytesToBuf(&val, 2);
return utility::BigInt16(val);
}
template <class T>
atInt16 readValBig(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
int16_t readValBig(std::enable_if_t<std::is_same_v<T, int16_t>>* = nullptr) {
return readInt16Big();
}
@ -185,9 +185,9 @@ public:
*
* @return The value at the current address
*/
atUint16 readUint16() { return readInt16(); }
uint16_t readUint16() { return readInt16(); }
template <class T>
atUint16 readVal(std::enable_if_t<std::is_same_v<T, atUint16>>* = 0) {
uint16_t readVal(std::enable_if_t<std::is_same_v<T, uint16_t>>* = 0) {
return readUint16();
}
@ -196,13 +196,13 @@ public:
*
* @return The value at the current address
*/
atUint16 readUint16Little() {
atUint16 val = 0;
uint16_t readUint16Little() {
uint16_t val = 0;
readUBytesToBuf(&val, 2);
return utility::LittleUint16(val);
}
template <class T>
atUint16 readValLittle(std::enable_if_t<std::is_same_v<T, atUint16>>* = nullptr) {
uint16_t readValLittle(std::enable_if_t<std::is_same_v<T, uint16_t>>* = nullptr) {
return readUint16Little();
}
@ -211,13 +211,13 @@ public:
*
* @return The value at the current address
*/
atUint16 readUint16Big() {
atUint16 val = 0;
uint16_t readUint16Big() {
uint16_t val = 0;
readUBytesToBuf(&val, 2);
return utility::BigUint16(val);
}
template <class T>
atUint16 readValBig(std::enable_if_t<std::is_same_v<T, atUint16>>* = nullptr) {
uint16_t readValBig(std::enable_if_t<std::is_same_v<T, uint16_t>>* = nullptr) {
return readUint16Big();
}
@ -226,13 +226,13 @@ public:
*
* @return The value at the current address
*/
atInt32 readInt32() {
atInt32 val = 0;
int32_t readInt32() {
int32_t val = 0;
readUBytesToBuf(&val, 4);
return m_endian == Endian::Big ? utility::BigInt32(val) : utility::LittleInt32(val);
}
template <class T>
atInt32 readVal(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
int32_t readVal(std::enable_if_t<std::is_same_v<T, int32_t>>* = nullptr) {
return readInt32();
}
@ -241,13 +241,13 @@ public:
*
* @return The value at the current address
*/
atInt32 readInt32Little() {
atInt32 val = 0;
int32_t readInt32Little() {
int32_t val = 0;
readUBytesToBuf(&val, 4);
return utility::LittleInt32(val);
}
template <class T>
atInt32 readValLittle(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
int32_t readValLittle(std::enable_if_t<std::is_same_v<T, int32_t>>* = nullptr) {
return readInt32Little();
}
@ -256,13 +256,13 @@ public:
*
* @return The value at the current address
*/
atInt32 readInt32Big() {
atInt32 val = 0;
int32_t readInt32Big() {
int32_t val = 0;
readUBytesToBuf(&val, 4);
return utility::BigInt32(val);
}
template <class T>
atInt32 readValBig(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
int32_t readValBig(std::enable_if_t<std::is_same_v<T, int32_t>>* = nullptr) {
return readInt32Big();
}
@ -271,9 +271,9 @@ public:
*
* @return The value at the current address
*/
atUint32 readUint32() { return readInt32(); }
uint32_t readUint32() { return readInt32(); }
template <class T>
atUint32 readVal(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
uint32_t readVal(std::enable_if_t<std::is_same_v<T, uint32_t>>* = nullptr) {
return readUint32();
}
@ -282,13 +282,13 @@ public:
*
* @return The value at the current address
*/
atUint32 readUint32Little() {
atUint32 val = 0;
uint32_t readUint32Little() {
uint32_t val = 0;
readUBytesToBuf(&val, 4);
return utility::LittleUint32(val);
}
template <class T>
atInt32 readValLittle(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
int32_t readValLittle(std::enable_if_t<std::is_same_v<T, uint32_t>>* = nullptr) {
return readUint32Little();
}
@ -297,13 +297,13 @@ public:
*
* @return The value at the current address
*/
atUint32 readUint32Big() {
atUint32 val = 0;
uint32_t readUint32Big() {
uint32_t val = 0;
readUBytesToBuf(&val, 4);
return utility::BigUint32(val);
}
template <class T>
atUint32 readValBig(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
uint32_t readValBig(std::enable_if_t<std::is_same_v<T, uint32_t>>* = nullptr) {
return readUint32Big();
}
@ -312,13 +312,13 @@ public:
*
* @return The value at the current address
*/
atInt64 readInt64() {
atInt64 val = 0;
int64_t readInt64() {
int64_t val = 0;
readUBytesToBuf(&val, 8);
return m_endian == Endian::Big ? utility::BigInt64(val) : utility::LittleInt64(val);
}
template <class T>
atInt64 readVal(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
int64_t readVal(std::enable_if_t<std::is_same_v<T, int64_t>>* = nullptr) {
return readInt64();
}
@ -327,13 +327,13 @@ public:
*
* @return The value at the current address
*/
atInt64 readInt64Little() {
atInt64 val = 0;
int64_t readInt64Little() {
int64_t val = 0;
readUBytesToBuf(&val, 8);
return utility::LittleInt64(val);
}
template <class T>
atInt64 readValLittle(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
int64_t readValLittle(std::enable_if_t<std::is_same_v<T, int64_t>>* = nullptr) {
return readInt64Little();
}
@ -342,13 +342,13 @@ public:
*
* @return The value at the current address
*/
atInt64 readInt64Big() {
atInt64 val = 0;
int64_t readInt64Big() {
int64_t val = 0;
readUBytesToBuf(&val, 8);
return utility::BigInt64(val);
}
template <class T>
atInt64 readValBig(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
int64_t readValBig(std::enable_if_t<std::is_same_v<T, int64_t>>* = nullptr) {
return readInt64Big();
}
@ -357,9 +357,9 @@ public:
*
* @return The value at the current address
*/
atUint64 readUint64() { return readInt64(); }
uint64_t readUint64() { return readInt64(); }
template <class T>
atUint64 readVal(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
uint64_t readVal(std::enable_if_t<std::is_same_v<T, uint64_t>>* = nullptr) {
return readUint64();
}
@ -368,13 +368,13 @@ public:
*
* @return The value at the current address
*/
atUint64 readUint64Little() {
atUint64 val = 0;
uint64_t readUint64Little() {
uint64_t val = 0;
readUBytesToBuf(&val, 8);
return utility::LittleUint64(val);
}
template <class T>
atUint64 readValLittle(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
uint64_t readValLittle(std::enable_if_t<std::is_same_v<T, uint64_t>>* = nullptr) {
return readUint64Little();
}
@ -383,13 +383,13 @@ public:
*
* @return The value at the current address
*/
atUint64 readUint64Big() {
atUint64 val = 0;
uint64_t readUint64Big() {
uint64_t val = 0;
readUBytesToBuf(&val, 8);
return utility::BigUint64(val);
}
template <class T>
atUint64 readValBig(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
uint64_t readValBig(std::enable_if_t<std::is_same_v<T, uint64_t>>* = nullptr) {
return readUint64Big();
}
@ -488,7 +488,7 @@ public:
* @return The value at the current address
*/
bool readBool() {
atUint8 val = false;
uint8_t val = false;
readUBytesToBuf(&val, 1);
return val != 0;
}
@ -927,13 +927,13 @@ public:
*
* @return The read string
*/
std::string readString(atInt32 fixedLen = -1, bool doSeek = true) {
std::string readString(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::string();
std::string ret;
atUint8 chr = readByte();
uint8_t chr = readByte();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;
@ -961,14 +961,14 @@ public:
*
* @return The read wstring
*/
std::wstring readWString(atInt32 fixedLen = -1, bool doSeek = true) {
std::wstring readWString(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::wstring();
std::wstring ret;
atUint16 chr = readUint16();
uint16_t chr = readUint16();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;
@ -997,14 +997,14 @@ public:
*
* @return The read wstring
*/
std::wstring readWStringLittle(atInt32 fixedLen = -1, bool doSeek = true) {
std::wstring readWStringLittle(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::wstring();
std::wstring ret;
atUint16 chr = readUint16Little();
uint16_t chr = readUint16Little();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;
@ -1033,13 +1033,13 @@ public:
*
* @return The read wstring
*/
std::wstring readWStringBig(atInt32 fixedLen = -1, bool doSeek = true) {
std::wstring readWStringBig(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::wstring();
std::wstring ret;
atUint16 chr = readUint16Big();
uint16_t chr = readUint16Big();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;
@ -1068,13 +1068,13 @@ public:
*
* @return The read wstring
*/
std::u16string readU16StringBig(atInt32 fixedLen = -1, bool doSeek = true) {
std::u16string readU16StringBig(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::u16string();
std::u16string ret;
char16_t chr = readUint16Big();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;
@ -1103,13 +1103,13 @@ public:
*
* @return The read wstring
*/
std::u32string readU32StringBig(atInt32 fixedLen = -1, bool doSeek = true) {
std::u32string readU32StringBig(int32_t fixedLen = -1, bool doSeek = true) {
if (fixedLen == 0)
return std::u32string();
std::u32string ret;
char32_t chr = readUint32Big();
atInt32 i;
int32_t i;
for (i = 1; chr != 0; ++i) {
ret += chr;

View File

@ -19,7 +19,7 @@ public:
* @param position where in the buffer to seek
* @param origin The location to seek relative to
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override = 0;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override = 0;
/** @brief Sets the buffers position relative to the next 32-byte aligned position.<br />
*/
@ -27,11 +27,11 @@ public:
/** @brief Writes zero up to specified absolute offset.<br />
*/
void writeZeroTo(atInt64 pos) {
atInt64 delta = pos - position();
void writeZeroTo(int64_t pos) {
int64_t delta = pos - position();
if (delta <= 0)
return;
for (atInt64 i = 0; i < delta; ++i)
for (int64_t i = 0; i < delta; ++i)
writeUByte(0);
}
@ -45,29 +45,29 @@ public:
*
* @return The current position in the stream.
*/
atUint64 position() const override = 0;
uint64_t position() const override = 0;
/** @brief Returns whether or not the stream is at the end.
*
* @return True if at end; False otherwise.
*/
atUint64 length() const override = 0;
uint64_t length() const override = 0;
/** @brief Writes a byte at the current position and advances the position by one byte.
* @param val The value to write
*/
void writeUByte(atUint8 val) { writeUBytes(&val, 1); }
void writeVal(atUint8 val) { writeUByte(val); }
void writeValLittle(atUint8 val) { writeUByte(val); }
void writeValBig(atUint8 val) { writeUByte(val); }
void writeUByte(uint8_t val) { writeUBytes(&val, 1); }
void writeVal(uint8_t val) { writeUByte(val); }
void writeValLittle(uint8_t val) { writeUByte(val); }
void writeValBig(uint8_t val) { writeUByte(val); }
/** @brief Writes a byte at the current position and advances the position by one byte.
* @param val The value to write
*/
void writeByte(atInt8 val) { writeUByte(val); }
void writeVal(atInt8 val) { writeByte(val); }
void writeValLittle(atInt8 val) { writeByte(val); }
void writeValBig(atInt8 val) { writeByte(val); }
void writeByte(int8_t val) { writeUByte(val); }
void writeVal(int8_t val) { writeByte(val); }
void writeValLittle(int8_t val) { writeByte(val); }
void writeValBig(int8_t val) { writeByte(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.
@ -75,7 +75,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
virtual void writeUBytes(const atUint8* data, atUint64 length) = 0;
virtual void writeUBytes(const uint8_t* data, uint64_t length) = 0;
/** @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.
@ -83,14 +83,14 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeBytes(const void* data, atUint64 length) { writeUBytes(reinterpret_cast<const atUint8*>(data), length); }
void writeBytes(const void* data, uint64_t length) { writeUBytes(reinterpret_cast<const uint8_t*>(data), length); }
/** @brief Writes an Int16 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param val The value to write to the buffer
*/
void writeInt16(atInt16 val) {
void writeInt16(int16_t val) {
if (m_endian == Endian::Big) {
utility::BigInt16(val);
} else {
@ -98,60 +98,60 @@ public:
}
writeBytes(&val, sizeof(val));
}
void writeVal(atInt16 val) { writeInt16(val); }
void writeVal(int16_t val) { writeInt16(val); }
/** @brief Writes an Int16 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt16Little(atInt16 val) {
void writeInt16Little(int16_t val) {
utility::LittleInt16(val);
writeBytes(&val, sizeof(val));
}
void writeValLittle(atInt16 val) { writeInt16Little(val); }
void writeValLittle(int16_t val) { writeInt16Little(val); }
/** @brief Writes an Int16 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt16Big(atInt16 val) {
void writeInt16Big(int16_t val) {
utility::BigInt16(val);
writeBytes(&val, sizeof(val));
}
void writeValBig(atInt16 val) { writeInt16Big(val); }
void writeValBig(int16_t val) { writeInt16Big(val); }
/** @brief Writes an Uint16 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings
*
* @param val The value to write to the buffer
*/
void writeUint16(atUint16 val) { writeInt16(val); }
void writeVal(atUint16 val) { writeUint16(val); }
void writeUint16(uint16_t val) { writeInt16(val); }
void writeVal(uint16_t val) { writeUint16(val); }
/** @brief Writes an Uint16 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform
*
* @param val The value to write to the buffer
*/
void writeUint16Little(atUint16 val) { writeInt16Little(val); }
void writeValLittle(atUint16 val) { writeUint16Little(val); }
void writeUint16Little(uint16_t val) { writeInt16Little(val); }
void writeValLittle(uint16_t val) { writeUint16Little(val); }
/** @brief Writes an Uint16 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform
*
* @param val The value to write to the buffer
*/
void writeUint16Big(atUint16 val) { writeInt16Big(val); }
void writeValBig(atUint16 val) { writeUint16Big(val); }
void writeUint16Big(uint16_t val) { writeInt16Big(val); }
void writeValBig(uint16_t val) { writeUint16Big(val); }
/** @brief Writes an Int32 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param val The value to write to the buffer
*/
void writeInt32(atInt32 val) {
void writeInt32(int32_t val) {
if (m_endian == Endian::Big) {
utility::BigInt32(val);
} else {
@ -159,60 +159,60 @@ public:
}
writeBytes(&val, sizeof(val));
}
void writeVal(atInt32 val) { writeInt32(val); }
void writeVal(int32_t val) { writeInt32(val); }
/** @brief Writes an Int32 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt32Little(atInt32 val) {
void writeInt32Little(int32_t val) {
utility::LittleInt32(val);
writeBytes(&val, sizeof(val));
}
void writeValLittle(atInt32 val) { writeInt32Little(val); }
void writeValLittle(int32_t val) { writeInt32Little(val); }
/** @brief Writes an Int32 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt32Big(atInt32 val) {
void writeInt32Big(int32_t val) {
utility::BigInt32(val);
writeBytes(&val, sizeof(val));
}
void writeValBig(atInt32 val) { writeInt32Big(val); }
void writeValBig(int32_t val) { writeInt32Big(val); }
/** @brief Writes an Uint32 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param val The value to write to the buffer
*/
void writeUint32(atUint32 val) { writeInt32(val); }
void writeVal(atUint32 val) { writeUint32(val); }
void writeUint32(uint32_t val) { writeInt32(val); }
void writeVal(uint32_t val) { writeUint32(val); }
/** @brief Writes an Uint32 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeUint32Little(atUint32 val) { writeInt32Little(val); }
void writeValLittle(atUint32 val) { writeUint32Little(val); }
void writeUint32Little(uint32_t val) { writeInt32Little(val); }
void writeValLittle(uint32_t val) { writeUint32Little(val); }
/** @brief Writes an Uint32 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeUint32Big(atUint32 val) { writeInt32Big(val); }
void writeValBig(atUint32 val) { writeUint32Big(val); }
void writeUint32Big(uint32_t val) { writeInt32Big(val); }
void writeValBig(uint32_t val) { writeUint32Big(val); }
/** @brief Writes an Int64 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param val The value to write to the buffer
*/
void writeInt64(atInt64 val) {
void writeInt64(int64_t val) {
if (m_endian == Endian::Big) {
utility::BigInt64(val);
} else {
@ -220,53 +220,53 @@ public:
}
writeBytes(&val, sizeof(val));
}
void writeVal(atInt64 val) { writeInt64(val); }
void writeVal(int64_t val) { writeInt64(val); }
/** @brief Writes an Int64 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt64Little(atInt64 val) {
void writeInt64Little(int64_t val) {
utility::LittleInt64(val);
writeBytes(&val, sizeof(val));
}
void writeValLittle(atInt64 val) { writeInt64Little(val); }
void writeValLittle(int64_t val) { writeInt64Little(val); }
/** @brief Writes an Int64 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeInt64Big(atInt64 val) {
void writeInt64Big(int64_t val) {
utility::BigInt64(val);
writeBytes(&val, sizeof(val));
}
void writeValBig(atInt64 val) { writeInt64Big(val); }
void writeValBig(int64_t val) { writeInt64Big(val); }
/** @brief Writes an Uint64 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param val The value to write to the buffer
*/
void writeUint64(atUint64 val) { writeInt64(val); }
void writeVal(atUint64 val) { writeUint64(val); }
void writeUint64(uint64_t val) { writeInt64(val); }
void writeVal(uint64_t val) { writeUint64(val); }
/** @brief Writes an Uint64 to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeUint64Little(atUint64 val) { writeInt64Little(val); }
void writeValLittle(atUint64 val) { writeUint64Little(val); }
void writeUint64Little(uint64_t val) { writeInt64Little(val); }
void writeValLittle(uint64_t val) { writeUint64Little(val); }
/** @brief Writes an Uint64 to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param val The value to write to the buffer
*/
void writeUint64Big(atUint64 val) { writeInt64Big(val); }
void writeValBig(atUint64 val) { writeUint64Big(val); }
void writeUint64Big(uint64_t val) { writeInt64Big(val); }
void writeValBig(uint64_t val) { writeUint64Big(val); }
/** @brief Writes an float to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
@ -348,7 +348,7 @@ public:
* @param val The value to write to the buffer
*/
void writeBool(bool val) {
const auto u8Value = atUint8(val);
const auto u8Value = uint8_t(val);
writeUBytes(&u8Value, sizeof(u8Value));
}
void writeVal(bool val) { writeBool(val); }
@ -651,7 +651,7 @@ public:
*
* Endianness is set with setEndian
*/
void writeStringAsWString(std::string_view str, atInt32 fixedLen = -1) {
void writeStringAsWString(std::string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
std::string tmpStr = std::string("\xEF\xBB\xBF") + str.data();
@ -666,11 +666,11 @@ public:
}
buf += len;
if (wc != 0xFEFF)
writeUint16(atUint16(wc));
writeUint16(uint16_t(wc));
}
writeUint16(0);
} else {
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
utf8proc_int32_t wc = 0;
if (*buf) {
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
@ -686,7 +686,7 @@ public:
continue;
}
writeUint16(atUint16(wc));
writeUint16(uint16_t(wc));
}
}
}
@ -699,7 +699,7 @@ public:
*
* Endianness is little
*/
void writeStringAsWStringLittle(std::string_view str, atInt32 fixedLen = -1) {
void writeStringAsWStringLittle(std::string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
std::string tmpStr = std::string("\xEF\xBB\xBF") + str.data();
@ -714,11 +714,11 @@ public:
}
buf += len;
if (wc != 0xFEFF)
writeUint16Little(atUint16(wc));
writeUint16Little(uint16_t(wc));
}
writeUint16Little(0);
} else {
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
utf8proc_int32_t wc = 0;
if (*buf) {
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
@ -734,7 +734,7 @@ public:
continue;
}
writeUint16Little(atUint16(wc));
writeUint16Little(uint16_t(wc));
}
}
}
@ -747,7 +747,7 @@ public:
*
* Endianness is big
*/
void writeStringAsWStringBig(std::string_view str, atInt32 fixedLen = -1) {
void writeStringAsWStringBig(std::string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
@ -763,11 +763,11 @@ public:
}
buf += len;
if (wc != 0xFEFF)
writeUint16Big(atUint16(wc));
writeUint16Big(uint16_t(wc));
}
writeUint16Big(0);
} else {
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
utf8proc_int32_t wc = 0;
if (*buf) {
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
@ -783,7 +783,7 @@ public:
continue;
}
writeUint16Big(atUint16(wc));
writeUint16Big(uint16_t(wc));
}
}
}
@ -793,12 +793,12 @@ public:
* @param str The string to write to the buffer
* @param fixedLen If not -1, the number of characters to zero-fill string to
*/
void writeString(std::string_view str, atInt32 fixedLen = -1) {
void writeString(std::string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
if (fixedLen < 0) {
for (atUint8 c : str) {
for (uint8_t c : str) {
writeUByte(c);
if (c == '\0')
@ -807,8 +807,8 @@ public:
writeUByte(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
atUint8 chr;
for (int32_t i = 0; i < fixedLen; ++i) {
uint8_t chr;
if (it == str.end())
chr = 0;
else
@ -826,12 +826,12 @@ public:
*
* Endianness is set with setEndian
*/
void writeWString(std::wstring_view str, atInt32 fixedLen = -1) {
void writeWString(std::wstring_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
if (fixedLen < 0) {
for (atUint16 c : str) {
for (uint16_t c : str) {
writeUint16(c);
if (c == L'\0')
@ -840,8 +840,8 @@ public:
writeUint16(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
atUint16 chr;
for (int32_t i = 0; i < fixedLen; ++i) {
uint16_t chr;
if (it == str.end())
chr = 0;
else
@ -859,12 +859,12 @@ public:
*
* Endianness is little
*/
void writeWStringLittle(std::wstring_view str, atInt32 fixedLen = -1) {
void writeWStringLittle(std::wstring_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
if (fixedLen < 0) {
for (atUint16 c : str) {
for (uint16_t c : str) {
writeUint16Little(c);
if (c == L'\0')
@ -873,8 +873,8 @@ public:
writeUint16Little(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
atUint16 chr;
for (int32_t i = 0; i < fixedLen; ++i) {
uint16_t chr;
if (it == str.end())
chr = 0;
else
@ -892,7 +892,7 @@ public:
*
* Endianness is big
*/
void writeWStringBig(std::wstring_view str, atInt32 fixedLen = -1) {
void writeWStringBig(std::wstring_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
@ -906,7 +906,7 @@ public:
writeUint16Big(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
wchar_t chr;
if (it == str.end())
chr = 0;
@ -925,7 +925,7 @@ public:
*
* Endianness is big
*/
void writeU16StringBig(std::u16string_view str, atInt32 fixedLen = -1) {
void writeU16StringBig(std::u16string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
@ -939,7 +939,7 @@ public:
writeUint16Big(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
char16_t chr;
if (it == str.end())
chr = 0;
@ -958,7 +958,7 @@ public:
*
* Endianness is big
*/
void writeU32StringBig(std::u32string_view str, atInt32 fixedLen = -1) {
void writeU32StringBig(std::u32string_view str, int32_t fixedLen = -1) {
if (fixedLen == 0)
return;
@ -972,7 +972,7 @@ public:
writeUint32Big(0);
} else {
auto it = str.begin();
for (atInt32 i = 0; i < fixedLen; ++i) {
for (int32_t i = 0; i < fixedLen; ++i) {
char32_t chr;
if (it == str.end())
chr = 0;
@ -984,15 +984,15 @@ public:
}
void writeValBig(std::u32string_view val) { writeU32StringBig(val); }
void fill(atUint8 val, atUint64 length) {
void fill(uint8_t val, uint64_t length) {
if (length == 0)
return;
const std::vector<atUint8> tmp(length, val);
const std::vector<uint8_t> tmp(length, val);
writeUBytes(tmp.data(), length);
}
void fill(atInt8 val, atUint64 length) { fill((atUint8)val, length); }
void fill(int8_t val, uint64_t length) { fill((uint8_t)val, length); }
/** @brief Performs automatic std::vector enumeration writes using numeric type T
* @param vector The std::vector read from when writing data

View File

@ -19,7 +19,7 @@ public:
MCFile();
static atUint8* unscramble(atUint8* data, atUint64 length);
static uint8_t* unscramble(uint8_t* data, uint64_t length);
private:
MCSlot* m_slots[3];

View File

@ -23,7 +23,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileReader(atUint8*, atUint64);
MCFileReader(uint8_t*, uint64_t);
/*!
* \brief This constructor creates an instance from a file on disk.

View File

@ -24,7 +24,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileWriter(atUint8*, atUint64);
MCFileWriter(uint8_t*, uint64_t);
/*!
* \brief This constructor creates an instance from a file on disk.
@ -40,10 +40,10 @@ public:
*/
void writeFile(MCFile* file);
static atUint16 calculateChecksum(atUint8* data, atUint32 length);
static uint16_t calculateChecksum(uint8_t* data, uint32_t length);
private:
atUint16 calculateSlotChecksum(atUint32 game);
uint16_t calculateSlotChecksum(uint32_t game);
};
} // namespace io

View File

@ -6,7 +6,7 @@
namespace athena {
class MCSlot : public ZQuestFile {
public:
MCSlot(std::unique_ptr<atUint8[]>&& data, atUint32 length);
MCSlot(std::unique_ptr<uint8_t[]>&& data, uint32_t length);
};
} // namespace athena

View File

@ -28,26 +28,26 @@ public:
* \param takeOwnership Memory will be freed with the reader if set.
* \param globalErr Whether or not global errors are enabled.
*/
explicit MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true);
explicit MemoryReader(const void* data, uint64_t length, bool takeOwnership = false, bool globalErr = true);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* \param position where in the buffer to seek
* \param origin The Origin to seek \sa SeekOrigin
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override;
/*! \brief Returns the current position in the stream.
*
* \return Int64 The current position in the stream.
*/
atUint64 position() const override { return m_position; }
uint64_t position() const override { return m_position; }
/*! \brief Returns whether or not the stream is at the end.
*
* \return bool True if at end; False otherwise.
*/
atUint64 length() const override { return m_length; }
uint64_t length() const override { return m_length; }
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
@ -59,7 +59,7 @@ public:
* \param takeOwnership Memory will be freed with the reader if set
* \throw IOException
*/
void setData(const atUint8* data, atUint64 length, bool takeOwnership = false);
void setData(const uint8_t* data, uint64_t length, bool takeOwnership = false);
/*! \brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
@ -68,19 +68,19 @@ public:
* as Stream now owns the address, this is done to keep memory usage down.
* \return Uint8* The copy of the buffer.
*/
atUint8* data() const;
uint8_t* data() const;
/*! \brief Reads a specified number of bytes to user-allocated buffer
* \param buf User-allocated buffer pointer
* \param len Length to read
* \return Number of bytes read
*/
atUint64 readUBytesToBuf(void* buf, atUint64 len) override;
uint64_t readUBytesToBuf(void* buf, uint64_t len) override;
protected:
const void* m_data = nullptr;
atUint64 m_length = 0;
atUint64 m_position = 0;
uint64_t m_length = 0;
uint64_t m_position = 0;
bool m_owns = false;
bool m_globalErr = true;
};
@ -92,7 +92,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
explicit MemoryCopyReader(const void* data, atUint64 length);
explicit MemoryCopyReader(const void* data, uint64_t length);
/*! \brief This constructor creates an instance from a file on disk.
*
@ -100,11 +100,11 @@ public:
*/
explicit MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); }
void setData(const atUint8* data, atUint64 length);
void setData(const uint8_t* data, uint64_t length);
protected:
void loadData();
std::unique_ptr<atUint8[]> m_dataCopy;
std::unique_ptr<uint8_t[]> m_dataCopy;
std::string m_filepath; //!< Path to the target file
};

View File

@ -26,26 +26,26 @@ public:
* @param takeOwnership Whether or not this writer takes ownership of the supplied data buffer.
* If true, the buffer will be deleted by this when the destructor executes.
*/
explicit MemoryWriter(atUint8* data, atUint64 length, bool takeOwnership = false);
explicit MemoryWriter(uint8_t* data, uint64_t length, bool takeOwnership = false);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
atUint64 position() const override { return m_position; }
uint64_t position() const override { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
atUint64 length() const override { return m_length; }
uint64_t length() const override { return m_length; }
bool isOpen() const { return true; }
@ -54,14 +54,14 @@ public:
* @param length The length of the new buffer.
* @param takeOwnership Whether the Stream now owns the buffer.
*/
void setData(atUint8* data, atUint64 length, bool takeOwnership = false);
void setData(uint8_t* data, uint64_t length, bool takeOwnership = false);
/*! @brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
* directly edit the buffer and use setData to set the new information.<br />
* @return Uint8* The copy of the buffer.
*/
atUint8* data() const;
uint8_t* data() const;
/*! @brief Sets the target file
*
@ -87,13 +87,13 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 length) override;
void writeUBytes(const uint8_t* data, uint64_t length) override;
protected:
MemoryWriter() = default;
atUint8* m_data = nullptr;
atUint64 m_length = 0;
atUint64 m_position = 0;
uint8_t* m_data = nullptr;
uint64_t m_length = 0;
uint64_t m_position = 0;
bool m_bufferOwned = false;
std::string m_filepath; //!< Path to the target file
};
@ -105,7 +105,7 @@ public:
* @param data The existing buffer
* @param length The length of the existing buffer
*/
explicit MemoryCopyWriter(atUint8* data = nullptr, atUint64 length = 0x10);
explicit MemoryCopyWriter(uint8_t* data = nullptr, uint64_t length = 0x10);
/*! @brief This constructor creates an instance from a file on disk.
*
@ -118,7 +118,7 @@ public:
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
@ -129,7 +129,7 @@ public:
* @param length The length of the new buffer.
* @throw IOException
*/
void setData(const atUint8* data, atUint64 length);
void setData(const uint8_t* data, uint64_t length);
/*! @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.
@ -137,13 +137,13 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 length) override;
void writeUBytes(const uint8_t* data, uint64_t length) override;
protected:
std::unique_ptr<atUint8[]> m_dataCopy;
std::unique_ptr<uint8_t[]> m_dataCopy;
private:
void resize(atUint64 newSize);
void resize(uint64_t newSize);
};
} // namespace athena::io

View File

@ -19,7 +19,7 @@ public:
~SkywardSwordFile();
void addQuest(SkywardSwordQuest* q);
SkywardSwordQuest* quest(atUint32 id);
SkywardSwordQuest* quest(uint32_t id);
std::vector<SkywardSwordQuest*> questList() const;
void setRegion(Region region);
@ -29,7 +29,7 @@ private:
Region m_region;
// A vector is a bit overkill
std::vector<SkywardSwordQuest*> m_quests;
atUint32 m_numQuests;
uint32_t m_numQuests;
};
} // namespace athena

View File

@ -7,7 +7,7 @@ class SkywardSwordFile;
namespace io {
class SkywardSwordFileReader : public MemoryCopyReader {
public:
SkywardSwordFileReader(atUint8* data, atUint64 length);
SkywardSwordFileReader(uint8_t* data, uint64_t length);
SkywardSwordFileReader(const std::string& filename);
SkywardSwordFile* read();

View File

@ -9,7 +9,7 @@ namespace io {
class SkywardSwordFileWriter : public MemoryCopyWriter {
public:
SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(uint8_t* data, uint64_t len);
SkywardSwordFileWriter(const std::string& filename);
void write(SkywardSwordFile* file);

View File

@ -11,40 +11,40 @@ class SkywardSwordQuest : public ZQuestFile {
public:
enum AmmoType { Arrows, Bombs, Seeds };
SkywardSwordQuest(std::unique_ptr<atUint8[]>&& data, atUint32 len);
SkywardSwordQuest(std::unique_ptr<uint8_t[]>&& data, uint32_t len);
void setPlayerName(const std::string& name);
std::string playerName() const;
void setRupeeCount(atUint16 value);
atUint16 rupeeCount();
void setAmmoCount(AmmoType type, atUint32 count);
atUint32 ammoCount(AmmoType type);
void setMaxHP(atUint16 val);
atUint16 maxHP();
void setRupeeCount(uint16_t value);
uint16_t rupeeCount();
void setAmmoCount(AmmoType type, uint32_t count);
uint32_t ammoCount(AmmoType type);
void setMaxHP(uint16_t val);
uint16_t maxHP();
float maxHearts();
void setSpawnHP(atUint16 val);
atUint16 spawnHP();
void setSpawnHP(uint16_t val);
uint16_t spawnHP();
float spawnHearts();
void setCurrentHP(atUint16 val);
atUint16 currentHP();
void setCurrentHP(uint16_t val);
uint16_t currentHP();
float currentHearts();
std::string currentLocation();
std::string currentArea();
std::string currentLocationCopy();
void setSkipData(std::unique_ptr<atUint8[]>&& data);
atUint8* skipData() const;
void setSkipData(std::unique_ptr<uint8_t[]>&& data);
uint8_t* skipData() const;
atUint32 slotChecksum();
atUint32 skipChecksum();
uint32_t slotChecksum();
uint32_t skipChecksum();
void fixChecksums();
void setNew(bool isNew);
bool isNew() const;
private:
std::unique_ptr<atUint8[]> m_skipData;
std::unique_ptr<uint8_t[]> m_skipData;
};
} // namespace athena

View File

@ -30,23 +30,23 @@ public:
int stateId(int index) const;
void setStateIds(std::vector<int> ids);
std::vector<int> stateIds() const;
atUint32 stateCount() const;
void setCurrentState(atUint32 id);
atUint32 currentState() const;
uint32_t stateCount() const;
void setCurrentState(uint32_t id);
uint32_t currentState() const;
bool addFrame(SpriteFrame* Frame);
bool removeFrame(SpriteFrame* Frame);
SpriteFrame* Frame(atUint32 id);
void setFrame(atUint32 id);
SpriteFrame* Frame(uint32_t id);
void setFrame(uint32_t id);
void setFrames(std::vector<SpriteFrame*> frames);
atUint32 frameCount() const;
uint32_t frameCount() const;
std::vector<SpriteFrame*> frames() const;
SpriteFile* container() const;
void setCurrentFrame(SpriteFrame* frame);
void setCurrentFrame(atUint32 id);
void setCurrentFrame(uint32_t id);
SpriteFrame* currentFrame() const;
void advanceFrame();
@ -61,8 +61,8 @@ private:
Vector2Df m_position;
std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<SpriteFrame*> m_frames;
atUint32 m_currentState;
atUint32 m_currentFrame;
uint32_t m_currentState;
uint32_t m_currentFrame;
};
} // namespace athena::Sakura

View File

@ -19,32 +19,32 @@ public:
/*!
* \brief Major
*/
static const atUint32 Major;
static const uint32_t Major;
/*!
* \brief Minor
*/
static const atUint32 Minor;
static const uint32_t Minor;
/*!
* \brief Revision
*/
static const atUint32 Revision;
static const uint32_t Revision;
/*!
* \brief Patch
*/
static const atUint32 Build;
static const uint32_t Build;
/*!
* \brief Version
*/
static const atUint32 Version;
static const uint32_t Version;
/*!
* \brief Magic
*/
static const atUint32 Magic;
static const uint32_t Magic;
/*!
* \brief SSprite
@ -58,7 +58,7 @@ public:
* \param originX
* \param originY
*/
SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
SpriteFile(uint32_t width, uint32_t height, float originX, float originY);
/*!
* \brief SSpriteFile
@ -84,7 +84,7 @@ public slots:
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
void setSize(uint32_t width, uint32_t height);
/*!
* \brief setSize
@ -102,13 +102,13 @@ public slots:
* \brief width
* \return
*/
atUint32 width() const;
uint32_t width() const;
/*!
* \brief height
* \return
*/
atUint32 height() const;
uint32_t height() const;
/*!
* \brief setOrigin
@ -158,10 +158,10 @@ public slots:
* \param id
* \return
*/
STexture* texture(atUint32 id);
STexture* texture(uint32_t id);
std::vector<STexture*> textures() const;
atUint32 textureCount() const;
uint32_t textureCount() const;
/*!
* \brief setTextures
* \param textures
@ -177,7 +177,7 @@ public slots:
Sprite* sprite(const std::string& name);
std::unordered_map<std::string, Sprite*> sprites() const;
atUint32 spriteCount() const;
uint32_t spriteCount() const;
private:
std::vector<STexture*> m_textures;

View File

@ -11,7 +11,7 @@ namespace io {
class SpriteFileReader : public MemoryCopyReader {
public:
SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(uint8_t* data, uint64_t length);
SpriteFileReader(const std::string& filepath);
Sakura::SpriteFile* readFile();

View File

@ -11,7 +11,7 @@ namespace io {
class SpriteFileWriter : public MemoryCopyWriter {
public:
SpriteFileWriter(atUint8* data, atUint64 length);
SpriteFileWriter(uint8_t* data, uint64_t length);
SpriteFileWriter(std::string_view filepath);

View File

@ -31,7 +31,7 @@ public:
void setParts(std::vector<SpritePart*> parts);
std::vector<SpritePart*> parts() const;
atUint32 partCount() const;
uint32_t partCount() const;
void setRoot(Sprite* root);
Sprite* root() const;

View File

@ -56,7 +56,7 @@ public:
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
void setSize(uint32_t width, uint32_t height);
/*!
* \brief setSize
@ -105,6 +105,6 @@ private:
Vector2Di m_size;
bool m_flippedH;
bool m_flippedV;
atUint32 m_frameIndex;
uint32_t m_frameIndex;
};
} // namespace athena::Sakura

View File

@ -3,15 +3,6 @@
#include <cinttypes>
#include <cstdint>
using atInt8 = std::int8_t;
using atUint8 = std::uint8_t;
using atInt16 = std::int16_t;
using atUint16 = std::uint16_t;
using atInt32 = std::int32_t;
using atUint32 = std::uint32_t;
using atInt64 = std::int64_t;
using atUint64 = std::uint64_t;
// Vector types
#include "simd/simd.hpp"
struct atVec2f {

View File

@ -10,7 +10,7 @@
#include "athena/Types.hpp"
namespace athena::utility {
inline bool isEmpty(atInt8* buf, atUint32 size) { return !std::memcmp(buf, buf + 1, size - 1); }
inline bool isEmpty(int8_t* buf, uint32_t size) { return !std::memcmp(buf, buf + 1, size - 1); }
#if _WIN32
constexpr bool isSystemBigEndian() { return false; }
#else
@ -25,7 +25,7 @@ constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? ::athena::End
#define BSWAP_CONSTEXPR constexpr
#endif
BSWAP_CONSTEXPR atInt16 swap16(atInt16 val) {
BSWAP_CONSTEXPR int16_t swap16(int16_t val) {
#if __GNUC__
return __builtin_bswap16(val);
#elif _MSC_VER
@ -34,8 +34,8 @@ BSWAP_CONSTEXPR atInt16 swap16(atInt16 val) {
return (val = (val << 8) | ((val >> 8) & 0xFF));
#endif
}
BSWAP_CONSTEXPR atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
BSWAP_CONSTEXPR atInt32 swap32(atInt32 val) {
BSWAP_CONSTEXPR uint16_t swapU16(uint16_t val) { return (uint16_t)swap16(val); }
BSWAP_CONSTEXPR int32_t swap32(int32_t val) {
#if __GNUC__
return __builtin_bswap32(val);
#elif _MSC_VER
@ -46,8 +46,8 @@ BSWAP_CONSTEXPR atInt32 swap32(atInt32 val) {
return val;
#endif
}
BSWAP_CONSTEXPR atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
BSWAP_CONSTEXPR atInt64 swap64(atInt64 val) {
BSWAP_CONSTEXPR uint32_t swapU32(uint32_t val) { return (uint32_t)swap32(val); }
BSWAP_CONSTEXPR int64_t swap64(int64_t val) {
#if __GNUC__
return __builtin_bswap64(val);
#elif _MSC_VER
@ -60,90 +60,90 @@ BSWAP_CONSTEXPR atInt64 swap64(atInt64 val) {
(((atInt64)(val)&0x000000000000FF00ULL) << 40) | (((atInt64)(val)&0x00000000000000FFULL) << 56))));
#endif
}
BSWAP_CONSTEXPR atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
BSWAP_CONSTEXPR uint64_t swapU64(uint64_t val) { return (uint64_t)swap64(val); }
BSWAP_CONSTEXPR float swapFloat(float val) {
union { float f; atInt32 i; } uval1 = {val};
union { atInt32 i; float f; } uval2 = {swap32(uval1.i)};
union { float f; int32_t i; } uval1 = {val};
union { int32_t i; float f; } uval2 = {swap32(uval1.i)};
return uval2.f;
}
BSWAP_CONSTEXPR double swapDouble(double val) {
union { double f; atInt64 i; } uval1 = {val};
union { atInt64 i; double f; } uval2 = {swap64(uval1.i)};
union { double f; int64_t i; } uval1 = {val};
union { int64_t i; double f; } uval2 = {swap64(uval1.i)};
return uval2.f;
}
BSWAP_CONSTEXPR atInt16 LittleInt16(atInt16& val) {
BSWAP_CONSTEXPR int16_t LittleInt16(int16_t& val) {
if constexpr (athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
return val;
}
BSWAP_CONSTEXPR atUint16 LittleUint16(atUint16& val) {
atInt16 ret = val;
BSWAP_CONSTEXPR uint16_t LittleUint16(uint16_t& val) {
int16_t ret = val;
LittleInt16(ret);
val = ret;
return val;
}
BSWAP_CONSTEXPR atInt16 BigInt16(atInt16& val) {
BSWAP_CONSTEXPR int16_t BigInt16(int16_t& val) {
if constexpr (!athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
return val;
}
BSWAP_CONSTEXPR atUint16 BigUint16(atUint16& val) {
atInt16 ret = val;
BSWAP_CONSTEXPR uint16_t BigUint16(uint16_t& val) {
int16_t ret = val;
BigInt16(ret);
val = ret;
return val;
}
BSWAP_CONSTEXPR atInt32 LittleInt32(atInt32& val) {
BSWAP_CONSTEXPR int32_t LittleInt32(int32_t& val) {
if constexpr (athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
return val;
}
BSWAP_CONSTEXPR atUint32 LittleUint32(atUint32& val) {
atInt32 ret = val;
BSWAP_CONSTEXPR uint32_t LittleUint32(uint32_t& val) {
int32_t ret = val;
LittleInt32(ret);
val = ret;
return val;
}
BSWAP_CONSTEXPR atInt32 BigInt32(atInt32& val) {
BSWAP_CONSTEXPR int32_t BigInt32(int32_t& val) {
if constexpr (!athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
return val;
}
BSWAP_CONSTEXPR atUint32 BigUint32(atUint32& val) {
atInt32 ret = val;
BSWAP_CONSTEXPR uint32_t BigUint32(uint32_t& val) {
int32_t ret = val;
BigInt32(ret);
val = ret;
return val;
}
BSWAP_CONSTEXPR atInt64 LittleInt64(atInt64& val) {
BSWAP_CONSTEXPR int64_t LittleInt64(int64_t& val) {
if constexpr (athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
return val;
}
BSWAP_CONSTEXPR atUint64 LittleUint64(atUint64& val) {
atInt64 ret = val;
BSWAP_CONSTEXPR uint64_t LittleUint64(uint64_t& val) {
int64_t ret = val;
LittleInt64(ret);
val = ret;
return val;
}
BSWAP_CONSTEXPR atInt64 BigInt64(atInt64& val) {
BSWAP_CONSTEXPR int64_t BigInt64(int64_t& val) {
if constexpr (!athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
return val;
}
BSWAP_CONSTEXPR atUint64 BigUint64(atUint64& val) {
atInt64 ret = val;
BSWAP_CONSTEXPR uint64_t BigUint64(uint64_t& val) {
int64_t ret = val;
BigInt64(ret);
val = ret;
@ -175,9 +175,9 @@ BSWAP_CONSTEXPR double BigDouble(double val) {
return val;
}
void fillRandom(atUint8* rndArea, atUint64 count);
void fillRandom(uint8_t* rndArea, uint64_t count);
std::vector<std::string> split(std::string_view s, char delim);
atUint64 rand64();
uint64_t rand64();
std::string join(const std::vector<std::string>& elems, std::string_view delims);
void tolower(std::string& str);
void toupper(std::string& str);
@ -193,9 +193,9 @@ std::string& rtrim(std::string& s);
// trim from both ends
std::string& trim(std::string& s);
atUint64 fileSize(std::string_view filename);
uint64_t fileSize(std::string_view filename);
#ifdef _WIN32
atUint64 fileSize(std::wstring_view filename);
uint64_t fileSize(std::wstring_view filename);
#endif
std::string wideToUtf8(std::wstring_view src);

View File

@ -22,19 +22,19 @@ public:
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
void seek(int64_t position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
atUint64 position() const override { return m_position; }
uint64_t position() const override { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
atUint64 length() const override { return m_data.size(); }
uint64_t length() const override { return m_data.size(); }
bool isOpen() const { return true; }
@ -48,11 +48,11 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 length) override;
void writeUBytes(const uint8_t* data, uint64_t length) override;
protected:
std::vector<uint8_t> m_data;
atUint64 m_position = 0;
uint64_t m_position = 0;
};
} // namespace athena::io

View File

@ -27,7 +27,7 @@ public:
* \param m_banner
* \param icons
*/
WiiBanner(atUint32 gameId, const std::u16string& title, const std::u16string& subtitle, WiiImage* m_banner,
WiiBanner(uint32_t gameId, const std::u16string& title, const std::u16string& subtitle, WiiImage* m_banner,
std::vector<WiiImage*> icons);
virtual ~WiiBanner();
@ -35,13 +35,13 @@ public:
* \brief setGameID
* \param id
*/
void setGameID(atUint64 id);
void setGameID(uint64_t id);
/*!
* \brief gameID
* \return
*/
atUint64 gameID() const;
uint64_t gameID() const;
/*!
* \brief setBannerImage
@ -59,13 +59,13 @@ public:
* \brief setBannerSize
* \param size
*/
void setBannerSize(atUint32 size);
void setBannerSize(uint32_t size);
/*!
* \brief bannerSize
* \return
*/
atUint32 bannerSize() const;
uint32_t bannerSize() const;
/*!
* \brief setTitle
@ -102,14 +102,14 @@ public:
* \param id
* \param icon
*/
void setIcon(atUint32 id, WiiImage* icon);
void setIcon(uint32_t id, WiiImage* icon);
/*!
* \brief getIcon
* \param id
* \return
*/
WiiImage* getIcon(atUint32 id) const;
WiiImage* getIcon(uint32_t id) const;
/*!
* \brief icons
@ -121,46 +121,46 @@ public:
* \brief setAnimationSpeed
* \param animSpeed
*/
void setAnimationSpeed(atUint16 animSpeed);
void setAnimationSpeed(uint16_t animSpeed);
/*!
* \brief animationSpeed
* \return
*/
atUint16 animationSpeed() const;
uint16_t animationSpeed() const;
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(atUint8 permissions);
void setPermissions(uint8_t permissions);
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
uint8_t permissions() const;
/*!
* \brief setFlags
* \param flags
*/
void setFlags(atUint32 flags);
void setFlags(uint32_t flags);
/*!
* \brief flags
* \return
*/
atUint32 flags() const;
uint32_t flags() const;
protected:
private:
atUint64 m_gameId;
uint64_t m_gameId;
WiiImage* m_banner;
atUint32 m_animSpeed;
atUint8 m_permissions;
atUint32 m_flags;
atUint32 m_bannerSize;
uint32_t m_animSpeed;
uint8_t m_permissions;
uint32_t m_flags;
uint32_t m_bannerSize;
std::vector<WiiImage*> m_icons;
std::u16string m_title;
std::u16string m_subtitle;

View File

@ -7,11 +7,11 @@
namespace athena {
const atUint8 SD_KEY[16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08,
const uint8_t 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,
const uint8_t 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,
const uint8_t MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17,
0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
/*! \class WiiFile
@ -59,7 +59,7 @@ public:
* \param data
* \param length
*/
WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length);
WiiFile(const std::string& filename, uint8_t permissions, const uint8_t* data, uint32_t length);
virtual ~WiiFile();
/*!
@ -78,12 +78,12 @@ public:
* \brief setData
* \param data
*/
void setData(const atUint8* data);
void setData(const uint8_t* data);
/*!
* \brief data
* \return
*/
atUint8* data() const;
uint8_t* data() const;
/*!
* \brief setLength
@ -101,25 +101,25 @@ public:
* \brief setPermissions
* \param permissions
*/
void setPermissions(const atUint8 permissions);
void setPermissions(const uint8_t permissions);
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
uint8_t permissions() const;
/*!
* \brief setAttributes
* \param attr
*/
void setAttributes(const atUint8 attr);
void setAttributes(const uint8_t attr);
/*!
* \brief attributes
* \return
*/
atUint8 attributes() const;
uint8_t attributes() const;
/*!
* \brief setType
@ -188,7 +188,7 @@ public:
* \brief fileCount
* \return
*/
atUint32 fileCount();
uint32_t fileCount();
/*!
* \brief allChildren
@ -204,12 +204,12 @@ public:
protected:
private:
atUint8 m_permissions;
atUint8 m_attributes;
uint8_t m_permissions;
uint8_t m_attributes;
Type m_type;
std::string m_filename;
int m_fileLen;
atUint8* m_fileData;
uint8_t* m_fileData;
WiiFile* m_parent;
std::vector<WiiFile*> m_children;
};

View File

@ -20,54 +20,54 @@ public:
* \param height
* \param data
*/
WiiImage(atUint32 width, atUint32 height, std::unique_ptr<atUint8[]>&& data);
WiiImage(uint32_t width, uint32_t height, std::unique_ptr<uint8_t[]>&& data);
/*!
* \brief setWidth
* \param width
*/
void setWidth(const atUint32 width);
void setWidth(const uint32_t width);
/*!
* \brief width
* \return
*/
atUint32 width() const;
uint32_t width() const;
/*!
* \brief setHeight
* \param height
*/
void setHeight(const atUint32 height);
void setHeight(const uint32_t height);
/*!
* \brief height
* \return
*/
atUint32 height() const;
uint32_t height() const;
/*!
* \brief setData
* \param data
*/
void setData(const atUint8* data);
void setData(const uint8_t* data);
/*!
* \brief data
* \return
*/
atUint8* data();
uint8_t* data();
/*!
* \brief toRGBA
* \return
*/
atUint8* toRGBA();
uint8_t* toRGBA();
private:
atUint32 m_width;
atUint32 m_height;
std::unique_ptr<atUint8[]> m_data;
uint32_t m_width;
uint32_t m_height;
std::unique_ptr<uint8_t[]> m_data;
};
} // namespace athena

View File

@ -48,7 +48,7 @@ public:
*/
WiiFile* file(const std::string& filename);
atUint32 fileCount() const;
uint32_t fileCount() const;
/*!
* \brief fileList
* \return

View File

@ -25,7 +25,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
WiiSaveReader(const atUint8*, atUint64);
WiiSaveReader(const uint8_t*, uint64_t);
/*! \brief This constructor creates an instance from a file on disk.
*
@ -42,8 +42,8 @@ public:
private:
WiiBanner* readBanner();
WiiFile* readFile();
WiiImage* readImage(atUint32 width, atUint32 height);
void readCerts(atUint32 totalSize);
WiiImage* readImage(uint32_t width, uint32_t height);
void readCerts(uint32_t totalSize);
WiiFile* buildTree(std::vector<WiiFile*> files);
};

View File

@ -36,14 +36,14 @@ public:
* \param filepath
* \return
*/
bool writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId,
bool writeSave(WiiSave* save, uint8_t* macAddress, uint32_t ngId, uint8_t* ngPriv, uint8_t* ngSig, uint32_t ngKeyId,
const std::string& filepath = "");
private:
void writeBanner(WiiBanner* banner);
atUint32 writeFile(WiiFile* file);
uint32_t writeFile(WiiFile* file);
void writeImage(WiiImage* image);
void writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId);
void writeCerts(uint32_t filesSize, uint32_t ngId, uint8_t* ngPriv, uint8_t* ngSig, uint32_t ngKeyId);
};
} // namespace io

View File

@ -18,24 +18,24 @@ public:
/*!
* \brief The current major version of the ZQuest format
*/
static const atUint32 Major;
static const uint32_t Major;
/*!
* \brief The current minor version of the ZQuest format
*/
static const atUint32 Minor;
static const uint32_t Minor;
/*!
* \brief The current revision of the ZQuest format
*/
static const atUint32 Revision;
static const uint32_t Revision;
/*!
* \brief The current version of the ZQuest format
*/
static const atUint32 Version;
static const uint32_t Version;
/*!
* \brief The magic number used to identify the file e.g. "ZQS1"
*/
static const atUint32 Magic;
static const uint32_t Magic;
/*!
* \enum Game
@ -79,7 +79,7 @@ public:
* \param data
* \param length
*/
ZQuestFile(Game game, Endian endian, std::unique_ptr<atUint8[]>&& data, atUint32 length,
ZQuestFile(Game game, Endian endian, std::unique_ptr<uint8_t[]>&& data, uint32_t length,
const std::string& gameString = std::string());
/*!
@ -111,19 +111,19 @@ public:
* \param data The data to assign
* \param length The length of the data
*/
void setData(std::unique_ptr<atUint8[]>&& data, atUint32 length);
void setData(std::unique_ptr<uint8_t[]>&& data, uint32_t length);
/*!
* \brief data
* \return
*/
atUint8* data() const;
uint8_t* data() const;
/*!
* \brief length
* \return
*/
atUint32 length() const;
uint32_t length() const;
void setGameString(const std::string& gameString);
/*!
@ -138,8 +138,8 @@ protected:
Game m_game;
std::string m_gameString;
Endian m_endian;
std::unique_ptr<atUint8[]> m_data;
atUint32 m_length;
std::unique_ptr<uint8_t[]> m_data;
uint32_t m_length;
// Game strings support
};

View File

@ -20,7 +20,7 @@ public:
* \param data
* \param length
*/
ZQuestFileReader(atUint8* data, atUint64 length);
ZQuestFileReader(uint8_t* data, uint64_t length);
/*!
* \brief ZQuestFileReader

View File

@ -19,7 +19,7 @@ public:
* \param data
* \param length
*/
ZQuestFileWriter(atUint8* data, atUint64 length);
ZQuestFileWriter(uint8_t* data, uint64_t length);
/*!
* \brief ZQuestFileWriter

View File

@ -2,10 +2,10 @@
#include "athena/Types.hpp"
namespace bignum {
int compare(const atUint8* a, const atUint8* b, atUint32 n);
void subModulus(atUint8* a, const atUint8* N, atUint32 n);
void add(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n);
void mul(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n);
void exp(atUint8* d, const atUint8* a, const atUint8* N, atUint32 n, atUint8* e, atUint32 en);
void inv(atUint8* d, atUint8* a, const atUint8* N, atUint32 n);
int compare(const uint8_t* a, const uint8_t* b, uint32_t n);
void subModulus(uint8_t* a, const uint8_t* N, uint32_t n);
void add(uint8_t* d, uint8_t* a, const uint8_t* b, const uint8_t* N, uint32_t n);
void mul(uint8_t* d, uint8_t* a, const uint8_t* b, const uint8_t* N, uint32_t n);
void exp(uint8_t* d, const uint8_t* a, const uint8_t* N, uint32_t n, uint8_t* e, uint32_t en);
void inv(uint8_t* d, uint8_t* a, const uint8_t* N, uint32_t n);
} // namespace bignum

View File

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

View File

@ -37,7 +37,7 @@ void SHA1Input(SHA1Context*,
atUint8* getSha1(atUint8* stuff, atUint32 stuff_size);
uint8_t* getSha1(uint8_t* stuff, uint32_t stuff_size);
#ifdef __cplusplus
}

View File

@ -26,12 +26,12 @@ int subMatch(const uint8_t* str1, const uint8_t* str2, const int len) {
// Up to 4096 bytes Up to 18 bytes
// Sliding Window
// Up to 4114 bytes
LZLengthOffset windowSearch(const atUint8* beginSearchPtr, const atUint8* searchPosPtr, const atUint8* endLABufferPtr,
const atUint8* startLBPtr) {
atInt32 size = (atUint32)(endLABufferPtr - beginSearchPtr); // Size of the entire sliding window
atInt32 n = (atUint32)(endLABufferPtr - searchPosPtr);
LZLengthOffset windowSearch(const uint8_t* beginSearchPtr, const uint8_t* searchPosPtr, const uint8_t* endLABufferPtr,
const uint8_t* startLBPtr) {
int32_t size = (uint32_t)(endLABufferPtr - beginSearchPtr); // Size of the entire sliding window
int32_t n = (uint32_t)(endLABufferPtr - searchPosPtr);
LZLengthOffset result = {0, 0};
atInt32 temp = 0;
int32_t temp = 0;
if (n > size) // If the string that is being looked for is bigger than the string that is being searched
return result;
@ -44,12 +44,12 @@ LZLengthOffset windowSearch(const atUint8* beginSearchPtr, const atUint8* search
do {
temp = subMatch(startLBPtr, searchPosPtr, n);
if (result.length < (atUint32)temp) {
if (result.length < (uint32_t)temp) {
result.length = temp;
result.offset = (atInt32)(searchPosPtr - startLBPtr);
result.offset = (int32_t)(searchPosPtr - startLBPtr);
}
if (result.length == (atUint32)n)
if (result.length == (uint32_t)n)
return result;
// ReadAheadBuffer is the maximum size of a character match
@ -60,7 +60,7 @@ LZLengthOffset windowSearch(const atUint8* beginSearchPtr, const atUint8* search
}
} // Anonymous namespace
LZBase::LZBase(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimumMatch, atInt32 blockSize)
LZBase::LZBase(int32_t minimumOffset, int32_t slidingWindow, int32_t minimumMatch, int32_t blockSize)
: m_slidingWindow(slidingWindow)
, m_readAheadBuffer(minimumMatch)
, m_minMatch(minimumMatch)
@ -69,25 +69,25 @@ LZBase::LZBase(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimumMatc
LZBase::~LZBase() = default;
void LZBase::setSlidingWindow(atInt32 slidingWindow) { m_slidingWindow = slidingWindow; }
void LZBase::setSlidingWindow(int32_t slidingWindow) { m_slidingWindow = slidingWindow; }
atInt32 LZBase::slidingWindow() const { return m_slidingWindow; }
int32_t LZBase::slidingWindow() const { return m_slidingWindow; }
void LZBase::setReadAheadBuffer(atInt32 readAheadBuffer) { m_readAheadBuffer = readAheadBuffer; }
void LZBase::setReadAheadBuffer(int32_t readAheadBuffer) { m_readAheadBuffer = readAheadBuffer; }
atInt32 LZBase::readAheadBuffer() const { return m_readAheadBuffer; }
int32_t LZBase::readAheadBuffer() const { return m_readAheadBuffer; }
void LZBase::setMinMatch(atInt32 minimumMatch) { m_minMatch = minimumMatch; }
void LZBase::setMinMatch(int32_t minimumMatch) { m_minMatch = minimumMatch; }
atInt32 LZBase::minMatch() const { return m_minMatch; }
int32_t LZBase::minMatch() const { return m_minMatch; }
void LZBase::setBlockSize(atInt32 blockSize) { m_blockSize = blockSize; }
void LZBase::setBlockSize(int32_t blockSize) { m_blockSize = blockSize; }
atInt32 LZBase::blockSize() const { return m_blockSize; }
int32_t LZBase::blockSize() const { return m_blockSize; }
void LZBase::setMinimumOffset(atUint32 minimumOffset) { m_minOffset = minimumOffset; }
void LZBase::setMinimumOffset(uint32_t minimumOffset) { m_minOffset = minimumOffset; }
atUint32 LZBase::minimumOffset() const { return m_minOffset; }
uint32_t LZBase::minimumOffset() const { return m_minOffset; }
/*
DerricMc:
@ -100,7 +100,7 @@ atUint32 LZBase::minimumOffset() const { return m_minOffset; }
and 17 bytes did match then 17 bytes match is return).
*/
LZLengthOffset LZBase::search(const atUint8* posPtr, const atUint8* dataBegin, const atUint8* dataEnd) const {
LZLengthOffset LZBase::search(const uint8_t* posPtr, const uint8_t* dataBegin, const uint8_t* dataEnd) const {
LZLengthOffset results = {0, 0};
// Returns negative 1 for Search failures since the current position is passed the size to be compressed
@ -109,7 +109,7 @@ LZLengthOffset LZBase::search(const atUint8* posPtr, const atUint8* dataBegin, c
return results;
}
const atUint8* searchWindow;
const uint8_t* searchWindow;
// LookAheadBuffer is ReadAheadBuffer Size if there are more bytes than ReadAheadBufferSize waiting
// to be compressed else the number of remaining bytes is the LookAheadBuffer
const int lookAheadBuffer_len =
@ -121,7 +121,7 @@ LZLengthOffset LZBase::search(const atUint8* posPtr, const atUint8* dataBegin, c
else
searchWindow = dataBegin;
const atUint8* endPos = posPtr + lookAheadBuffer_len;
const uint8_t* endPos = posPtr + lookAheadBuffer_len;
if (!((posPtr - dataBegin < 1) || (dataEnd - posPtr < m_minMatch)))
results = windowSearch(searchWindow, posPtr, endPos, posPtr - m_minOffset);

View File

@ -3,7 +3,7 @@
LZLookupTable::LZLookupTable() : m_buffer(m_minimumMatch) {}
LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt32 lookAheadWindow) {
LZLookupTable::LZLookupTable(int32_t minimumMatch, int32_t slidingWindow, int32_t lookAheadWindow) {
if (minimumMatch > 0)
m_minimumMatch = minimumMatch;
else
@ -21,14 +21,14 @@ LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt3
LZLookupTable::~LZLookupTable() = default;
void LZLookupTable::setLookAheadWindow(atInt32 lookAheadWindow) {
void LZLookupTable::setLookAheadWindow(int32_t lookAheadWindow) {
if (lookAheadWindow > 0)
m_lookAheadWindow = lookAheadWindow;
else
m_lookAheadWindow = 18;
}
LZLengthOffset LZLookupTable::search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd) {
LZLengthOffset LZLookupTable::search(const uint8_t* curPos, const uint8_t* dataBegin, const uint8_t* dataEnd) {
LZLengthOffset loPair = {0, 0};
// Returns negative 1 for search failures since the current position is passed the size to be compressed
@ -38,7 +38,7 @@ LZLengthOffset LZLookupTable::search(const atUint8* curPos, const atUint8* dataB
}
std::copy(curPos, curPos + m_minimumMatch, m_buffer.begin());
int32_t currentOffset = static_cast<atInt32>(curPos - dataBegin);
int32_t currentOffset = static_cast<int32_t>(curPos - dataBegin);
// Find code
if (currentOffset > 0 && (dataEnd - curPos) >= m_minimumMatch) {
@ -60,13 +60,13 @@ LZLengthOffset LZLookupTable::search(const atUint8* curPos, const atUint8* dataB
// Store the longest match found so far into length_offset struct.
// When lengths are the same the closer offset to the lookahead buffer wins
if (loPair.length < (atUint32)matchLength) {
if (loPair.length < (uint32_t)matchLength) {
loPair.length = matchLength;
loPair.offset = currentOffset - iter->second;
}
// Found the longest match so break out of loop
if (loPair.length == (atUint32)m_lookAheadWindow)
if (loPair.length == (uint32_t)m_lookAheadWindow)
break;
}
}
@ -75,7 +75,7 @@ LZLengthOffset LZLookupTable::search(const atUint8* curPos, const atUint8* dataB
// Insert code
table.insert(std::make_pair(m_buffer, currentOffset));
for (atUint32 i = 1; i < loPair.length; i++) {
for (uint32_t i = 1; i < loPair.length; i++) {
if (dataEnd - (curPos + i) < m_minimumMatch)
break;

View File

@ -8,46 +8,46 @@
#include <athena/MemoryWriter.hpp>
LZType10::LZType10(atInt32 MinimumOffset, atInt32 SlidingWindow, atInt32 MinimumMatch, atInt32 BlockSize)
LZType10::LZType10(int32_t MinimumOffset, int32_t SlidingWindow, int32_t MinimumMatch, int32_t BlockSize)
: LZBase(MinimumOffset, SlidingWindow, MinimumMatch, BlockSize) {
// ReadAheadBuffer is normalize between (minumum match) and(minimum match + 15) so that matches fit within
// 4-bits.
m_readAheadBuffer = m_minMatch + 0xF;
}
atUint32 LZType10::compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLength) {
atUint32 encodeSize = (srcLength << 8) | (0x10);
uint32_t LZType10::compress(const uint8_t* src, uint8_t** dstBuf, uint32_t srcLength) {
uint32_t encodeSize = (srcLength << 8) | (0x10);
encodeSize = athena::utility::LittleUint32(encodeSize); // File size needs to be written as little endian always
athena::io::MemoryCopyWriter outbuf("tmp");
outbuf.writeUint32(encodeSize);
const atUint8* ptrStart = src;
const atUint8* ptrEnd = src + srcLength;
const uint8_t* ptrStart = src;
const uint8_t* ptrEnd = src + srcLength;
// At most their will be two bytes written if the bytes can be compressed. So if all bytes in the block can be
// compressed it would take blockSize*2 bytes
auto compressedBytes = std::unique_ptr<atUint8[]>(new atUint8[m_blockSize * 2]); // Holds the compressed bytes yet to be written
auto compressedBytes = std::unique_ptr<uint8_t[]>(new uint8_t[m_blockSize * 2]); // Holds the compressed bytes yet to be written
while (ptrStart < ptrEnd) {
atUint8 blockLen = 0;
uint8_t blockLen = 0;
// In Binary represents 1 if byte is compressed or 0 if not compressed
// For example 01001000 means that the second and fifth byte in the blockSize from the left is compressed
atUint8* ptrBytes = compressedBytes.get();
uint8_t* ptrBytes = compressedBytes.get();
for (atInt32 i = 0; i < m_blockSize; i++) {
for (int32_t i = 0; i < m_blockSize; i++) {
// length_offset searchResult=Search(ptrStart, filedata, ptrEnd);
const LZLengthOffset searchResult = m_lookupTable.search(ptrStart, src, ptrEnd);
// If the number of bytes to be compressed is at least the size of the Minimum match
if (searchResult.length >= static_cast<atUint32>(m_minMatch)) {
if (searchResult.length >= static_cast<uint32_t>(m_minMatch)) {
// Gotta swap the bytes since system is wii is big endian and most computers are little endian
atUint16 lenOff = (((searchResult.length - m_minMatch) & 0xF) << 12) | ((searchResult.offset - 1) & 0xFFF);
uint16_t lenOff = (((searchResult.length - m_minMatch) & 0xF) << 12) | ((searchResult.offset - 1) & 0xFFF);
athena::utility::BigUint16(lenOff);
memcpy(ptrBytes, &lenOff, sizeof(atUint16));
memcpy(ptrBytes, &lenOff, sizeof(uint16_t));
ptrBytes += sizeof(atUint16);
ptrBytes += sizeof(uint16_t);
ptrStart += searchResult.length;
@ -60,7 +60,7 @@ atUint32 LZType10::compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLe
}
outbuf.writeByte(blockLen);
outbuf.writeUBytes(compressedBytes.get(), static_cast<atUint64>(ptrBytes - compressedBytes.get()));
outbuf.writeUBytes(compressedBytes.get(), static_cast<uint64_t>(ptrBytes - compressedBytes.get()));
}
// Add zeros until the file is a multiple of 4
@ -70,16 +70,16 @@ atUint32 LZType10::compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLe
*dstBuf = outbuf.data();
outbuf.save();
return static_cast<atUint32>(outbuf.length());
return static_cast<uint32_t>(outbuf.length());
}
atUint32 LZType10::decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) {
uint32_t LZType10::decompress(const uint8_t* src, uint8_t** dst, uint32_t srcLength) {
if (*src != 0x10) {
return 0;
}
// Size of data when it is uncompressed
atUint32 uncompressedSize;
uint32_t uncompressedSize;
std::memcpy(&uncompressedSize, src, sizeof(uncompressedSize));
// The compressed file has the filesize encoded in little endian
@ -88,28 +88,28 @@ atUint32 LZType10::decompress(const atUint8* src, atUint8** dst, atUint32 srcLen
// first byte is the encode flag
uncompressedSize = uncompressedSize >> 8;
auto uncompressedData = std::unique_ptr<atUint8[]>(new atUint8[uncompressedSize]);
atUint8* outputPtr = uncompressedData.get();
atUint8* outputEndPtr = uncompressedData.get() + uncompressedSize;
const atUint8* inputPtr = src + 4;
const atUint8* inputEndPtr = src + srcLength;
auto uncompressedData = std::unique_ptr<uint8_t[]>(new uint8_t[uncompressedSize]);
uint8_t* outputPtr = uncompressedData.get();
uint8_t* outputEndPtr = uncompressedData.get() + uncompressedSize;
const uint8_t* inputPtr = src + 4;
const uint8_t* inputEndPtr = src + srcLength;
while (inputPtr < inputEndPtr && outputPtr < outputEndPtr) {
const atUint8 isCompressed = *inputPtr++;
const uint8_t isCompressed = *inputPtr++;
for (atUint32 i = 0; i < static_cast<atUint32>(m_blockSize); i++) {
for (uint32_t i = 0; i < static_cast<uint32_t>(m_blockSize); i++) {
// Checks to see if the next byte is compressed by looking
// at its binary representation - E.g 10010000
// This says that the first extracted byte and the four extracted byte is compressed
if ((isCompressed >> (7 - i)) & 0x1) {
atUint16 lenOff;
memcpy(&lenOff, inputPtr, sizeof(atUint16));
uint16_t lenOff;
memcpy(&lenOff, inputPtr, sizeof(uint16_t));
athena::utility::BigUint16(lenOff);
inputPtr += sizeof(atUint16); // Move forward two bytes
inputPtr += sizeof(uint16_t); // Move forward two bytes
// length offset pair has been decoded.
LZLengthOffset decoding;
decoding.length = (lenOff >> 12) + m_minMatch;
decoding.offset = static_cast<atUint16>((lenOff & 0xFFF) + 1);
decoding.offset = static_cast<uint16_t>((lenOff & 0xFFF) + 1);
if ((outputPtr - decoding.offset) < uncompressedData.get()) {
// If the offset to look for uncompressed is passed the current uncompresed data then the data is not

View File

@ -8,41 +8,41 @@
#include <athena/MemoryWriter.hpp>
LZType11::LZType11(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimumMatch, atInt32 blockSize)
LZType11::LZType11(int32_t minimumOffset, int32_t slidingWindow, int32_t minimumMatch, int32_t blockSize)
: LZBase(minimumOffset, slidingWindow, minimumMatch, blockSize) {
m_readAheadBuffer = (0xF + 0xFF + 0xFFFF + m_minMatch);
m_lookupTable.setLookAheadWindow(m_readAheadBuffer);
}
atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLength) {
uint32_t LZType11::compress(const uint8_t* src, uint8_t** dst, uint32_t srcLength) {
athena::io::MemoryCopyWriter outbuff("tmp");
if (srcLength > 0xFFFFFF) { // If length is greater than 24 bits or 16 Megs
atUint32 encodeFlag = 0x11;
uint32_t encodeFlag = 0x11;
athena::utility::LittleUint32(encodeFlag);
athena::utility::LittleUint32(srcLength); // Filesize data is little endian
outbuff.writeUint32(encodeFlag);
outbuff.writeUint32(srcLength);
} else {
atUint32 encodeSize = (srcLength << 8) | (0x11);
uint32_t encodeSize = (srcLength << 8) | (0x11);
athena::utility::LittleUint32(encodeSize);
outbuff.writeUint32(encodeSize);
}
const atUint8* ptrStart = src;
const atUint8* ptrEnd = src + srcLength;
const uint8_t* ptrStart = src;
const uint8_t* ptrEnd = src + srcLength;
// At most their will be two bytes written if the bytes can be compressed. So if all bytes in the block can be
// compressed it would take blockSize*2 bytes
// Holds the compressed bytes yet to be written
auto compressedBytes = std::unique_ptr<atUint8[]>(new atUint8[m_blockSize * 2]);
auto compressedBytes = std::unique_ptr<uint8_t[]>(new uint8_t[m_blockSize * 2]);
const atUint8 maxTwoByteMatch = 0xF + 1;
const atUint8 minThreeByteMatch = maxTwoByteMatch + 1; // Minimum Three byte match is maximum TwoByte match + 1
const atUint16 maxThreeByteMatch = 0xFF + minThreeByteMatch;
const atUint16 minFourByteMatch = maxThreeByteMatch + 1; // Minimum Four byte match is maximum Three Byte match + 1
const atInt32 maxFourByteMatch = 0xFFFF + minFourByteMatch;
const uint8_t maxTwoByteMatch = 0xF + 1;
const uint8_t minThreeByteMatch = maxTwoByteMatch + 1; // Minimum Three byte match is maximum TwoByte match + 1
const uint16_t maxThreeByteMatch = 0xFF + minThreeByteMatch;
const uint16_t minFourByteMatch = maxThreeByteMatch + 1; // Minimum Four byte match is maximum Three Byte match + 1
const int32_t maxFourByteMatch = 0xFFFF + minFourByteMatch;
/*
Normaliazation Example: If MIN_MATCH is 3 then 3 gets mapped to 2 and 16 gets mapped to 15.
@ -59,36 +59,36 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt
In the four byte case the first 4 bits a 0001
*/
while (ptrStart < ptrEnd) {
atUint8 blockSize = 0;
uint8_t blockSize = 0;
// In Binary represents 1 if byte is compressed or 0 if not compressed
// For example 01001000 means that the second and fifth byte in the blockSize from the left is compressed
atUint8* ptrBytes = compressedBytes.get();
uint8_t* ptrBytes = compressedBytes.get();
for (atInt32 i = 0; i < m_blockSize; i++) {
for (int32_t i = 0; i < m_blockSize; i++) {
// length_offset searchResult=Search(filedata,ptrStart,ptrEnd);
const LZLengthOffset searchResult = m_lookupTable.search(ptrStart, src, ptrEnd);
// If the number of bytes to be compressed is at least the size of the Minimum match
if (searchResult.length >= static_cast<atUint32>(m_minMatch)) {
if (searchResult.length >= static_cast<uint32_t>(m_minMatch)) {
// Gotta swap the bytes since system is wii is big endian and most computers are little endian
if (searchResult.length <= maxTwoByteMatch) {
atUint16 lenOff = ((((searchResult.length - 1) & 0xF) << 12) | // Bits 15-12
uint16_t lenOff = ((((searchResult.length - 1) & 0xF) << 12) | // Bits 15-12
((searchResult.offset - 1) & 0xFFF) // Bits 11-0
);
athena::utility::BigUint16(lenOff);
memcpy(ptrBytes, &lenOff, 2);
ptrBytes += 2;
} else if (searchResult.length <= maxThreeByteMatch) {
atUint32 lenOff = ((((searchResult.length - minThreeByteMatch) & 0xFF) << 12) | // Bits 20-12
uint32_t lenOff = ((((searchResult.length - minThreeByteMatch) & 0xFF) << 12) | // Bits 20-12
((searchResult.offset - 1) & 0xFFF) // Bits 11-0
);
athena::utility::BigUint32(lenOff);
memcpy(ptrBytes, reinterpret_cast<atUint8*>(&lenOff) + 1,
memcpy(ptrBytes, reinterpret_cast<uint8_t*>(&lenOff) + 1,
3); // Make sure to copy the lower 24 bits. 0x12345678- This statement copies 0x123456
ptrBytes += 3;
} else if (searchResult.length <= static_cast<atUint32>(maxFourByteMatch)) {
atUint32 lenOff = ((1 << 28) | // Bits 31-28 Flag to say that this is four bytes
} else if (searchResult.length <= static_cast<uint32_t>(maxFourByteMatch)) {
uint32_t lenOff = ((1 << 28) | // Bits 31-28 Flag to say that this is four bytes
(((searchResult.length - minFourByteMatch) & 0xFFFF) << 12) | // Bits 28-12
((searchResult.offset - 1) & 0xFFF) // Bits 11-0
);
@ -108,7 +108,7 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt
}
outbuff.writeByte(blockSize);
outbuff.writeUBytes(compressedBytes.get(), static_cast<atUint64>(ptrBytes - compressedBytes.get()));
outbuff.writeUBytes(compressedBytes.get(), static_cast<uint64_t>(ptrBytes - compressedBytes.get()));
}
// Add zeros until the file is a multiple of 4
@ -117,66 +117,66 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt
}
*dst = outbuff.data();
return static_cast<atUint32>(outbuff.length());
return static_cast<uint32_t>(outbuff.length());
}
atUint32 LZType11::decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) {
uint32_t LZType11::decompress(const uint8_t* src, uint8_t** dst, uint32_t srcLength) {
if (*src != 0x11) {
return 0;
}
atUint32 uncompressedLen;
uint32_t uncompressedLen;
std::memcpy(&uncompressedLen, src, sizeof(uncompressedLen));
athena::utility::LittleUint32(uncompressedLen); // The compressed file has the filesize encoded in little endian
uncompressedLen = uncompressedLen >> 8; // First byte is the encode flag
atUint32 currentOffset = 4;
uint32_t currentOffset = 4;
// If the filesize var is zero then the true filesize is over 14MB and must be read in from the next 4 bytes
if (uncompressedLen == 0) {
atUint32 filesize;
uint32_t filesize;
std::memcpy(&filesize, src + 4, sizeof(filesize));
filesize = athena::utility::LittleUint32(filesize);
currentOffset += 4;
}
auto uncompressedData = std::unique_ptr<atUint8[]>(new atUint8[uncompressedLen]);
atUint8* outputPtr = uncompressedData.get();
atUint8* outputEndPtr = uncompressedData.get() + uncompressedLen;
const atUint8* inputPtr = src + currentOffset;
const atUint8* inputEndPtr = src + srcLength;
auto uncompressedData = std::unique_ptr<uint8_t[]>(new uint8_t[uncompressedLen]);
uint8_t* outputPtr = uncompressedData.get();
uint8_t* outputEndPtr = uncompressedData.get() + uncompressedLen;
const uint8_t* inputPtr = src + currentOffset;
const uint8_t* inputEndPtr = src + srcLength;
LZLengthOffset decoding;
const atUint8 maxTwoByteMatch = 0xF + 1;
const atUint8 threeByteDenorm = maxTwoByteMatch + 1; // Amount to add to length when compression is 3 bytes
const atUint16 maxThreeByteMatch = 0xFF + threeByteDenorm;
const atUint16 fourByteDenorm = maxThreeByteMatch + 1;
const uint8_t maxTwoByteMatch = 0xF + 1;
const uint8_t threeByteDenorm = maxTwoByteMatch + 1; // Amount to add to length when compression is 3 bytes
const uint16_t maxThreeByteMatch = 0xFF + threeByteDenorm;
const uint16_t fourByteDenorm = maxThreeByteMatch + 1;
while (inputPtr < inputEndPtr && outputPtr < outputEndPtr) {
const atUint8 isCompressed = *inputPtr++;
const uint8_t isCompressed = *inputPtr++;
for (atInt32 i = 0; i < m_blockSize; i++) {
for (int32_t i = 0; i < m_blockSize; i++) {
// Checks to see if the next byte is compressed by looking
// at its binary representation - E.g 10010000
// This says that the first extracted byte and the four extracted byte is compressed
if ((isCompressed >> (7 - i)) & 0x1) {
const atUint8 metaDataSize = *inputPtr >> 4; // Look at the top 4 bits
const uint8_t metaDataSize = *inputPtr >> 4; // Look at the top 4 bits
if (metaDataSize >= 2) { // Two Bytes of Length/Offset MetaData
atUint16 lenOff = 0;
uint16_t lenOff = 0;
memcpy(&lenOff, inputPtr, 2);
inputPtr += 2;
athena::utility::BigUint16(lenOff);
decoding.length = (lenOff >> 12) + 1;
decoding.offset = (lenOff & 0xFFF) + 1;
} else if (metaDataSize == 0) { // Three Bytes of Length/Offset MetaData
atUint32 lenOff = 0;
memcpy(reinterpret_cast<atUint8*>(&lenOff) + 1, inputPtr, 3);
uint32_t lenOff = 0;
memcpy(reinterpret_cast<uint8_t*>(&lenOff) + 1, inputPtr, 3);
inputPtr += 3;
athena::utility::BigUint32(lenOff);
decoding.length = (lenOff >> 12) + threeByteDenorm;
decoding.offset = (lenOff & 0xFFF) + 1;
} else if (metaDataSize == 1) { // Four Bytes of Length/Offset MetaData
atUint32 lenOff = 0;
uint32_t lenOff = 0;
memcpy(&lenOff, inputPtr, 4);
inputPtr += 4;
athena::utility::BigUint32(lenOff);

View File

@ -7,7 +7,7 @@ ALTTPFile::ALTTPFile() {}
ALTTPFile::ALTTPFile(std::vector<ALTTPQuest*> quests, std::vector<ALTTPQuest*> backup)
: m_quests(quests), m_backup(backup) {}
void ALTTPFile::setQuest(atUint32 id, ALTTPQuest* val) {
void ALTTPFile::setQuest(uint32_t id, ALTTPQuest* val) {
if (id > m_quests.size()) {
atWarning("index out of range");
return;
@ -17,7 +17,7 @@ void ALTTPFile::setQuest(atUint32 id, ALTTPQuest* val) {
}
std::vector<ALTTPQuest*> ALTTPFile::questList() const { return m_quests; }
ALTTPQuest* ALTTPFile::quest(atUint32 id) const {
ALTTPQuest* ALTTPFile::quest(uint32_t id) const {
if (id > m_quests.size()) {
atWarning("index out of range");
return nullptr;
@ -26,5 +26,5 @@ ALTTPQuest* ALTTPFile::quest(atUint32 id) const {
return m_quests[id];
}
atUint32 ALTTPFile::questCount() const { return (atUint32)m_quests.size(); }
uint32_t ALTTPFile::questCount() const { return (uint32_t)m_quests.size(); }
} // namespace athena

View File

@ -6,7 +6,7 @@
namespace athena::io {
ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {}
ALTTPFileReader::ALTTPFileReader(uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {}
ALTTPFileReader::ALTTPFileReader(const std::string& filename) : MemoryCopyReader(filename) {}
@ -14,16 +14,16 @@ ALTTPFile* ALTTPFileReader::readFile() {
std::vector<ALTTPQuest*> quests;
std::vector<ALTTPQuest*> backup;
for (atUint32 i = 0; i < 6; i++) {
for (uint32_t i = 0; i < 6; i++) {
// Temporary values to use for each save
ALTTPQuest* quest = new ALTTPQuest();
std::vector<ALTTPRoomFlags*> roomFlags;
std::vector<ALTTPOverworldEvent*> owEvents;
std::vector<atUint8> dungeonKeys;
std::vector<atUint8> oldmanFlags;
std::vector<atUint8> unknown1;
std::vector<atUint16> playerName;
std::vector<atUint16> dungeonDeaths;
std::vector<uint8_t> dungeonKeys;
std::vector<uint8_t> oldmanFlags;
std::vector<uint8_t> unknown1;
std::vector<uint16_t> playerName;
std::vector<uint16_t> dungeonDeaths;
int j = 0x140;
@ -55,7 +55,7 @@ ALTTPFile* ALTTPFileReader::readFile() {
quest->setArrowUpgrades(readByte());
quest->setHealthFiller(readByte());
quest->setMagicFiller(readByte());
atUint8 pendantsByte = readUByte();
uint8_t pendantsByte = readUByte();
ALTTPPendants pendants;
pendants.Courage = pendantsByte & 1;
pendants.Wisdom = (pendantsByte >> 1) & 1;
@ -70,7 +70,7 @@ ALTTPFile* ALTTPFileReader::readFile() {
quest->setArrowFiller(readByte());
quest->setArrows(readByte());
seek(1);
atUint8 abilitiesByte = readUByte();
uint8_t abilitiesByte = readUByte();
ALTTPAbilities abilities;
abilities.Nothing = abilitiesByte & 1;
abilities.Swim = (abilitiesByte >> 1) & 1;
@ -154,7 +154,7 @@ ALTTPFile* ALTTPFileReader::readFile() {
ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() {
ALTTPRoomFlags* flags = new ALTTPRoomFlags;
atUint8 flagsByte = readUByte();
uint8_t flagsByte = readUByte();
flags->Chest1 = flagsByte & 1;
flags->Chest2 = (flagsByte >> 1) & 1;
flags->Chest3 = (flagsByte >> 2) & 1;
@ -178,7 +178,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags() {
ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent() {
ALTTPOverworldEvent* event = new ALTTPOverworldEvent;
atUint8 flagsByte = readUByte();
uint8_t flagsByte = readUByte();
event->Unused1 = flagsByte & 1;
event->HeartPiece = (flagsByte >> 1) & 1;
event->Overlay = (flagsByte >> 2) & 1;
@ -192,7 +192,7 @@ ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent() {
ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() {
ALTTPDungeonItemFlags flags;
atUint8 flagsByte = readUByte();
uint8_t flagsByte = readUByte();
flags.Unused1 = flagsByte & 1;
flags.Unused2 = (flagsByte >> 1) & 1;
flags.GanonsTower = (flagsByte >> 2) & 1;

View File

@ -7,14 +7,14 @@ namespace athena {
namespace io {
ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length) : MemoryCopyWriter(data, length) {}
ALTTPFileWriter::ALTTPFileWriter(uint8_t* data, uint64_t length) : MemoryCopyWriter(data, length) {}
ALTTPFileWriter::ALTTPFileWriter(const std::string& filename) : MemoryCopyWriter(filename) {}
void ALTTPFileWriter::writeFile(ALTTPFile* file) {
ALTTPQuest* quest = NULL;
for (atUint32 i = 0; i < 6; i++) {
for (uint32_t i = 0; i < 6; i++) {
if (i < 3)
quest = file->quest(i);
else
@ -28,7 +28,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) {
writeOverworldEvent(quest->overworldEvent(j));
}
writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory));
writeBytes((int8_t*)&quest->inventory(), sizeof(ALTTPInventory));
writeUint16(quest->rupeeMax());
writeUint16(quest->rupeeCurrent());
writeDungeonItems(quest->compasses());
@ -44,7 +44,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) {
writeByte(quest->healthFiller());
writeByte(quest->magicFiller());
ALTTPPendants pendants = quest->pendants();
atUint8 pendantsByte = 0;
uint8_t pendantsByte = 0;
pendantsByte |= pendants.Courage;
pendantsByte |= pendants.Wisdom << 1;
pendantsByte |= pendants.Power << 2;
@ -54,7 +54,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) {
writeByte(quest->arrows());
seek(1);
ALTTPAbilities abilities = quest->abilityFlags();
atUint8 abilitiesByte = 0;
uint8_t abilitiesByte = 0;
abilitiesByte |= abilities.Nothing;
abilitiesByte |= abilities.Swim << 1;
abilitiesByte |= abilities.Dash << 2;
@ -65,23 +65,23 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) {
abilitiesByte |= abilities.Unknown2 << 7;
writeUByte(abilitiesByte);
ALTTPCrystals crystals = quest->crystals();
writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals));
writeBytes((int8_t*)&crystals, sizeof(ALTTPCrystals));
ALTTPMagicUsage magicUsage = quest->magicUsage();
writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage));
writeBytes((int8_t*)&magicUsage, sizeof(ALTTPMagicUsage));
for (int j = 0; j < 0x010; j++)
writeByte(quest->dungeonKeys(j));
seek(0x039);
writeByte((atInt8)quest->progressIndicator());
writeByte((int8_t)quest->progressIndicator());
ALTTPProgressFlags1 progress1 = quest->progressFlags1();
writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1));
writeBytes((int8_t*)&progress1, sizeof(ALTTPProgressFlags1));
writeByte(quest->mapIcon());
writeByte(quest->startLocation());
ALTTPProgressFlags2 progress2 = quest->progressFlags2();
writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2));
writeBytes((int8_t*)&progress2, sizeof(ALTTPProgressFlags2));
ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator();
writeBytes((atInt8*)&indicator, 1);
writeBytes((int8_t*)&indicator, 1);
seek(1);
writeByte(quest->tagAlong());
@ -111,7 +111,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file) {
}
void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags) {
atUint8 flagsByte = 0;
uint8_t flagsByte = 0;
flagsByte |= flags->Chest1;
flagsByte |= flags->Chest2 << 1;
flagsByte |= flags->Chest3 << 2;
@ -134,7 +134,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags) {
}
void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event) {
atUint8 flagsByte = 0;
uint8_t flagsByte = 0;
flagsByte |= event->Unused1;
flagsByte |= event->HeartPiece << 1;
flagsByte |= event->Overlay << 2;
@ -147,7 +147,7 @@ void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event) {
}
void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) {
atUint8 flagsByte = 0;
uint8_t flagsByte = 0;
flagsByte |= flags.Unused1;
flagsByte |= flags.Unused2 << 1;
flagsByte |= flags.GanonsTower << 2;
@ -168,7 +168,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags) {
writeUByte(flagsByte);
}
atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game) {
uint16_t ALTTPFileWriter::calculateChecksum(uint32_t game) {
/*
* ALTTP's checksum is very basic
* It adds each word up and then subtracts the sum from 0x5a5a
@ -185,11 +185,11 @@ atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game) {
*/
// First we start at 0
atUint16 sum = 0;
uint16_t sum = 0;
for (atUint32 i = 0; i < 0x4FE; i += 2)
for (uint32_t i = 0; i < 0x4FE; i += 2)
// Add each word one by one
sum += *(atUint16*)(m_data + (i + (0x500 * game)));
sum += *(uint16_t*)(m_data + (i + (0x500 * game)));
// Subtract it from 0x5a5a to get our true checksum
return (0x5a5a - sum);

View File

@ -15,19 +15,19 @@ ALTTPQuest::~ALTTPQuest() {
void ALTTPQuest::setRoomFlags(std::vector<ALTTPRoomFlags*> rf) { m_roomFlags = rf; }
void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, atUint32 id) { m_roomFlags[id] = rf; }
void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, uint32_t id) { m_roomFlags[id] = rf; }
std::vector<ALTTPRoomFlags*> ALTTPQuest::roomFlags() { return m_roomFlags; }
ALTTPRoomFlags* ALTTPQuest::roomFlags(atUint32 id) { return m_roomFlags[id]; }
ALTTPRoomFlags* ALTTPQuest::roomFlags(uint32_t id) { return m_roomFlags[id]; }
void ALTTPQuest::setOverworldEvents(std::vector<ALTTPOverworldEvent*> ow) { m_overworldEvents = ow; }
void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id) { m_overworldEvents[id] = ow; }
void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, uint32_t id) { m_overworldEvents[id] = ow; }
std::vector<ALTTPOverworldEvent*> ALTTPQuest::overworldEvents() const { return m_overworldEvents; }
ALTTPOverworldEvent* ALTTPQuest::overworldEvent(atUint32 id) const {
ALTTPOverworldEvent* ALTTPQuest::overworldEvent(uint32_t id) const {
if (id > m_overworldEvents.size() - 1) {
atWarning("index out of range");
return nullptr;
@ -40,13 +40,13 @@ void ALTTPQuest::setInventory(const ALTTPInventory& inv) { m_inventory = inv; }
const ALTTPInventory& ALTTPQuest::inventory() const { return m_inventory; }
void ALTTPQuest::setRupeeMax(atUint16 val) { m_rupeeMax = val; }
void ALTTPQuest::setRupeeMax(uint16_t val) { m_rupeeMax = val; }
atUint16 ALTTPQuest::rupeeMax() const { return m_rupeeMax; }
uint16_t ALTTPQuest::rupeeMax() const { return m_rupeeMax; }
void ALTTPQuest::setRupeeCurrent(atUint16 val) { m_rupeeCurrent = val; }
void ALTTPQuest::setRupeeCurrent(uint16_t val) { m_rupeeCurrent = val; }
atUint16 ALTTPQuest::rupeeCurrent() const { return m_rupeeCurrent; }
uint16_t ALTTPQuest::rupeeCurrent() const { return m_rupeeCurrent; }
void ALTTPQuest::setCompasses(ALTTPDungeonItemFlags flags) { m_compasses = flags; }
@ -60,55 +60,55 @@ void ALTTPQuest::setDungeonMaps(ALTTPDungeonItemFlags flags) { m_dungeonMaps = f
ALTTPDungeonItemFlags ALTTPQuest::dungeonMaps() const { return m_dungeonMaps; }
void ALTTPQuest::setWishingPond(atUint16 val) { m_wishingPond = val; }
void ALTTPQuest::setWishingPond(uint16_t val) { m_wishingPond = val; }
atUint16 ALTTPQuest::wishingPond() const { return m_wishingPond; }
uint16_t ALTTPQuest::wishingPond() const { return m_wishingPond; }
void ALTTPQuest::setHealthMax(atUint8 val) { m_healthMax = val; }
void ALTTPQuest::setHealthMax(uint8_t val) { m_healthMax = val; }
atUint8 ALTTPQuest::healthMax() const { return m_healthMax; }
uint8_t ALTTPQuest::healthMax() const { return m_healthMax; }
void ALTTPQuest::setHealth(atUint8 val) { m_health = val; }
void ALTTPQuest::setHealth(uint8_t val) { m_health = val; }
atUint8 ALTTPQuest::health() const { return m_health; }
uint8_t ALTTPQuest::health() const { return m_health; }
void ALTTPQuest::setMagicPower(atUint8 val) { m_magicPower = val; }
void ALTTPQuest::setMagicPower(uint8_t val) { m_magicPower = val; }
atUint8 ALTTPQuest::magicPower() const { return m_magicPower; }
uint8_t ALTTPQuest::magicPower() const { return m_magicPower; }
void ALTTPQuest::setKeys(atUint8 val) { m_keys = val; }
void ALTTPQuest::setKeys(uint8_t val) { m_keys = val; }
atUint8 ALTTPQuest::keys() const { return m_keys; }
uint8_t ALTTPQuest::keys() const { return m_keys; }
void ALTTPQuest::setBombUpgrades(atUint8 val) { m_bombUpgrades = val; }
void ALTTPQuest::setBombUpgrades(uint8_t val) { m_bombUpgrades = val; }
atUint8 ALTTPQuest::bombUpgrades() const { return m_bombUpgrades; }
uint8_t ALTTPQuest::bombUpgrades() const { return m_bombUpgrades; }
void ALTTPQuest::setArrowUpgrades(atUint8 val) { m_arrowUpgrades = val; }
void ALTTPQuest::setArrowUpgrades(uint8_t val) { m_arrowUpgrades = val; }
atUint8 ALTTPQuest::arrowUpgrades() const { return m_arrowUpgrades; }
uint8_t ALTTPQuest::arrowUpgrades() const { return m_arrowUpgrades; }
void ALTTPQuest::setHealthFiller(atUint8 val) { m_heartFiller = val; }
void ALTTPQuest::setHealthFiller(uint8_t val) { m_heartFiller = val; }
atUint8 ALTTPQuest::healthFiller() const { return m_heartFiller; }
void ALTTPQuest::setMagicFiller(atUint8 val) { m_heartFiller = val; }
uint8_t ALTTPQuest::healthFiller() const { return m_heartFiller; }
void ALTTPQuest::setMagicFiller(uint8_t val) { m_heartFiller = val; }
atUint8 ALTTPQuest::magicFiller() const { return m_heartFiller; }
uint8_t ALTTPQuest::magicFiller() const { return m_heartFiller; }
void ALTTPQuest::setPendants(ALTTPPendants val) { m_pendants = val; }
ALTTPPendants ALTTPQuest::pendants() const { return m_pendants; }
void ALTTPQuest::setBombFiller(atUint8 val) { m_bombFiller = val; }
void ALTTPQuest::setBombFiller(uint8_t val) { m_bombFiller = val; }
atUint8 ALTTPQuest::bombFiller() const { return m_bombFiller; }
uint8_t ALTTPQuest::bombFiller() const { return m_bombFiller; }
void ALTTPQuest::setArrowFiller(atUint8 val) { m_arrowFiller = val; }
void ALTTPQuest::setArrowFiller(uint8_t val) { m_arrowFiller = val; }
atUint8 ALTTPQuest::arrowFiller() const { return m_arrowFiller; }
void ALTTPQuest::setArrows(atUint8 val) { m_arrows = val; }
uint8_t ALTTPQuest::arrowFiller() const { return m_arrowFiller; }
void ALTTPQuest::setArrows(uint8_t val) { m_arrows = val; }
atUint8 ALTTPQuest::arrows() const { return m_arrows; }
uint8_t ALTTPQuest::arrows() const { return m_arrows; }
void ALTTPQuest::setAbilityFlags(ALTTPAbilities val) { m_abilityFlags = val; }
@ -122,9 +122,9 @@ void ALTTPQuest::setMagicUsage(ALTTPMagicUsage val) { m_magicUsage = val; }
ALTTPMagicUsage ALTTPQuest::magicUsage() const { return m_magicUsage; }
void ALTTPQuest::setDungeonKeys(std::vector<atUint8> val) { m_dungeonKeys = val; }
void ALTTPQuest::setDungeonKeys(std::vector<uint8_t> val) { m_dungeonKeys = val; }
void ALTTPQuest::setDungeonKeys(atUint32 id, atUint8 val) {
void ALTTPQuest::setDungeonKeys(uint32_t id, uint8_t val) {
if (id > m_dungeonKeys.size() - 1) {
atWarning("index out of range");
return;
@ -133,7 +133,7 @@ void ALTTPQuest::setDungeonKeys(atUint32 id, atUint8 val) {
m_dungeonKeys[id] = val;
}
atUint8 ALTTPQuest::dungeonKeys(atUint32 id) const {
uint8_t ALTTPQuest::dungeonKeys(uint32_t id) const {
if (id > m_dungeonKeys.size() - 1) {
atWarning("index out of range");
return 0;
@ -142,7 +142,7 @@ atUint8 ALTTPQuest::dungeonKeys(atUint32 id) const {
return m_dungeonKeys[id];
}
atUint32 ALTTPQuest::dungeonCount() const { return (atUint32)m_dungeonKeys.size(); }
uint32_t ALTTPQuest::dungeonCount() const { return (uint32_t)m_dungeonKeys.size(); }
void ALTTPQuest::setProgressIndicator(ALTTPProgressIndicator val) { m_progressIndicator = val; }
@ -172,9 +172,9 @@ void ALTTPQuest::setTagAlong(ALTTPTagAlong val) { m_tagAlong = val; }
ALTTPTagAlong ALTTPQuest::tagAlong() const { return m_tagAlong; }
void ALTTPQuest::setOldManFlags(std::vector<atUint8> flags) { m_oldManFlags = flags; }
void ALTTPQuest::setOldManFlags(std::vector<uint8_t> flags) { m_oldManFlags = flags; }
void ALTTPQuest::setOldManFlag(atUint32 id, atUint8 val) {
void ALTTPQuest::setOldManFlag(uint32_t id, uint8_t val) {
if (id > m_oldManFlags.size() - 1) {
atWarning("index out of range");
return;
@ -183,7 +183,7 @@ void ALTTPQuest::setOldManFlag(atUint32 id, atUint8 val) {
m_oldManFlags[id] = val;
}
atUint8 ALTTPQuest::oldManFlag(atUint32 id) {
uint8_t ALTTPQuest::oldManFlag(uint32_t id) {
if (id > m_oldManFlags.size() - 1) {
atWarning("index out of range");
return 0;
@ -191,15 +191,15 @@ atUint8 ALTTPQuest::oldManFlag(atUint32 id) {
return m_oldManFlags[id];
}
atUint32 ALTTPQuest::oldManFlagCount() const { return (atUint32)m_oldManFlags.size(); }
uint32_t ALTTPQuest::oldManFlagCount() const { return (uint32_t)m_oldManFlags.size(); }
void ALTTPQuest::setBombFlag(atUint8 flag) { m_bombFlag = flag; }
void ALTTPQuest::setBombFlag(uint8_t flag) { m_bombFlag = flag; }
atUint8 ALTTPQuest::bombFlag() const { return m_bombFlag; }
uint8_t ALTTPQuest::bombFlag() const { return m_bombFlag; }
void ALTTPQuest::setUnknown1(std::vector<atUint8> flags) { m_unknown1 = flags; }
void ALTTPQuest::setUnknown1(std::vector<uint8_t> flags) { m_unknown1 = flags; }
void ALTTPQuest::setUnknown1(atUint32 id, atUint8 val) {
void ALTTPQuest::setUnknown1(uint32_t id, uint8_t val) {
if (id > m_unknown1.size()) {
atWarning("index out of range");
return;
@ -208,7 +208,7 @@ void ALTTPQuest::setUnknown1(atUint32 id, atUint8 val) {
m_unknown1[id] = val;
}
atUint8 ALTTPQuest::unknown1(atUint32 id) {
uint8_t ALTTPQuest::unknown1(uint32_t id) {
if (id > m_unknown1.size()) {
atWarning("index out of range");
return 0;
@ -217,9 +217,9 @@ atUint8 ALTTPQuest::unknown1(atUint32 id) {
return m_unknown1[id];
}
atUint32 ALTTPQuest::unknown1Count() const { return (atUint32)m_unknown1.size(); }
uint32_t ALTTPQuest::unknown1Count() const { return (uint32_t)m_unknown1.size(); }
void ALTTPQuest::setPlayerName(std::vector<atUint16> playerName) { m_playerName = playerName; }
void ALTTPQuest::setPlayerName(std::vector<uint16_t> playerName) { m_playerName = playerName; }
void ALTTPQuest::setPlayerName(const std::string& playerName) {
if (playerName == std::string() || playerName.size() > 6) {
@ -229,9 +229,9 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) {
m_playerName.clear();
for (atUint32 i = 0; i < 6; i++) {
for (uint32_t i = 0; i < 6; i++) {
if (i > playerName.size() - 1) {
m_playerName.push_back((atUint16)0xA9);
m_playerName.push_back((uint16_t)0xA9);
continue;
}
@ -239,19 +239,19 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) {
if (c >= 'A' && c <= 'P' && c != 'I') {
m_playerName.push_back((atUint16)(c - 'A'));
m_playerName.push_back((uint16_t)(c - 'A'));
continue;
}
if (c >= 'Q' && c <= 'Z') {
std::cout << std::hex << (atUint16)((c - 'Q') + 0x20) << std::endl;
m_playerName.push_back((atUint16)((c - 'Q') + 0x20));
std::cout << std::hex << (uint16_t)((c - 'Q') + 0x20) << std::endl;
m_playerName.push_back((uint16_t)((c - 'Q') + 0x20));
continue;
}
if (c >= 'a' && c <= 'f') {
std::cout << std::hex << (atUint16)((c - 'a') + 0x2A) << std::endl;
m_playerName.push_back((atUint16)((c - 'a') + 0x2A));
std::cout << std::hex << (uint16_t)((c - 'a') + 0x2A) << std::endl;
m_playerName.push_back((uint16_t)((c - 'a') + 0x2A));
continue;
}
@ -266,22 +266,22 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) {
continue;
}
m_playerName.push_back((atUint16)((c - 'g') + 0x40));
m_playerName.push_back((uint16_t)((c - 'g') + 0x40));
continue;
}
if (c >= 'w' && c <= 'z') {
m_playerName.push_back((atUint16)((c - 'w') + 0x60));
m_playerName.push_back((uint16_t)((c - 'w') + 0x60));
continue;
}
if (c >= '0' && c <= '9') {
m_playerName.push_back((atUint16)((c - '0') + 0x64));
m_playerName.push_back((uint16_t)((c - '0') + 0x64));
continue;
}
if (c == '-' || c == '.') {
m_playerName.push_back((atUint16)(c - '-') + 0x80);
m_playerName.push_back((uint16_t)(c - '-') + 0x80);
continue;
}
@ -313,12 +313,12 @@ void ALTTPQuest::setPlayerName(const std::string& playerName) {
}
}
std::vector<atUint16> ALTTPQuest::playerName() const { return m_playerName; }
std::vector<uint16_t> ALTTPQuest::playerName() const { return m_playerName; }
std::string ALTTPQuest::playerNameToString() const {
std::string ret;
for (atInt16 c : m_playerName) {
for (int16_t c : m_playerName) {
if (c >= 0x00 && c <= 0x0F) {
ret.push_back((char)('A' + c));
continue;
@ -397,9 +397,9 @@ void ALTTPQuest::setValid(bool val) { m_valid = val; }
bool ALTTPQuest::valid() { return m_valid; }
void ALTTPQuest::setDungeonDeathTotals(std::vector<atUint16> val) { m_dungeonDeathTotals = val; }
void ALTTPQuest::setDungeonDeathTotals(std::vector<uint16_t> val) { m_dungeonDeathTotals = val; }
void ALTTPQuest::setDungeonDeathTotal(atUint32 id, atUint16 val) {
void ALTTPQuest::setDungeonDeathTotal(uint32_t id, uint16_t val) {
if (id > m_dungeonDeathTotals.size()) {
atWarning("index out of range");
return;
@ -408,7 +408,7 @@ void ALTTPQuest::setDungeonDeathTotal(atUint32 id, atUint16 val) {
m_dungeonDeathTotals[id] = val;
}
atUint16 ALTTPQuest::dungeonDeathTotal(atUint32 id) const {
uint16_t ALTTPQuest::dungeonDeathTotal(uint32_t id) const {
if (id > m_dungeonDeathTotals.size()) {
atWarning("index out of range");
return 0;
@ -417,21 +417,21 @@ atUint16 ALTTPQuest::dungeonDeathTotal(atUint32 id) const {
return m_dungeonDeathTotals[id];
}
atUint16 ALTTPQuest::dungeonDeathTotalCount() const { return (atUint16)m_dungeonDeathTotals.size(); }
uint16_t ALTTPQuest::dungeonDeathTotalCount() const { return (uint16_t)m_dungeonDeathTotals.size(); }
void ALTTPQuest::setUnknown2(atUint16 val) { m_unknown2 = val; }
void ALTTPQuest::setUnknown2(uint16_t val) { m_unknown2 = val; }
atUint16 ALTTPQuest::unknown2() const { return m_unknown2; }
uint16_t ALTTPQuest::unknown2() const { return m_unknown2; }
void ALTTPQuest::setDeathSaveCount(atUint16 val) { m_deathSaveCount = val; }
atUint16 ALTTPQuest::deathSaveCount() const { return m_deathSaveCount; }
void ALTTPQuest::setDeathSaveCount(uint16_t val) { m_deathSaveCount = val; }
uint16_t ALTTPQuest::deathSaveCount() const { return m_deathSaveCount; }
void ALTTPQuest::setPostGameDeathCounter(atInt16 val) { m_postGameDeathCounter = val; }
void ALTTPQuest::setPostGameDeathCounter(int16_t val) { m_postGameDeathCounter = val; }
atInt16 ALTTPQuest::postGameDeathCounter() const { return m_postGameDeathCounter; }
int16_t ALTTPQuest::postGameDeathCounter() const { return m_postGameDeathCounter; }
void ALTTPQuest::setChecksum(atUint16 checksum) { m_checksum = checksum; }
void ALTTPQuest::setChecksum(uint16_t checksum) { m_checksum = checksum; }
atUint16 ALTTPQuest::checksum() const { return m_checksum; }
uint16_t ALTTPQuest::checksum() const { return m_checksum; }
} // namespace athena

View File

@ -1,8 +1,8 @@
#include "athena/Checksums.hpp"
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed, atUint64 final) {
static const atUint64 crc64Table[256] = {
uint64_t crc64(const uint8_t* data, uint64_t length, uint64_t seed, uint64_t final) {
static const uint64_t crc64Table[256] = {
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF,
0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D,
0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847,
@ -60,7 +60,7 @@ atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed, atUint64 fin
if (!data)
return seed;
atUint64 checksum = seed;
uint64_t checksum = seed;
int pos = 0;
while (length--)
@ -69,8 +69,8 @@ atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed, atUint64 fin
return checksum ^ final;
}
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed, atUint32 final) {
static const atUint32 crc32Table[256] = {
uint32_t crc32(const uint8_t* data, uint64_t length, uint32_t seed, uint32_t final) {
static const uint32_t crc32Table[256] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
@ -104,7 +104,7 @@ atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed, atUint32 fin
if (!data)
return seed;
atUint32 checksum = seed;
uint32_t checksum = seed;
int pos = 0;
while (length--)
@ -113,8 +113,8 @@ atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed, atUint32 fin
return checksum ^ final;
}
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed, atUint16 final) {
static const atUint16 crc16CCITTTable[256] = {
uint16_t crc16CCITT(const uint8_t* data, uint64_t length, uint16_t seed, uint16_t final) {
static const uint16_t crc16CCITTTable[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad,
0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a,
0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b,
@ -135,7 +135,7 @@ atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed, atUint1
0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0};
atUint16 checksum = seed;
uint16_t checksum = seed;
int pos = 0;
while (length--)
@ -144,12 +144,12 @@ atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed, atUint1
return checksum ^ final;
}
atUint16 crc16(const atUint8* data, atUint64 length, atUint16 seed, atUint64 final) {
uint16_t crc16(const uint8_t* data, uint64_t length, uint16_t seed, uint64_t final) {
if (data == nullptr) {
return seed;
}
static const atUint16 crc16Table[256] = {
static const uint16_t crc16Table[256] = {
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1,
0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40,
0xC901, 0x09C0, 0x0880, 0xC841, 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1,
@ -170,8 +170,8 @@ atUint16 crc16(const atUint8* data, atUint64 length, atUint16 seed, atUint64 fin
0x4C80, 0x8C41, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341,
0x4100, 0x81C1, 0x8081, 0x4040};
atInt32 pos = 0;
atUint16 checksum = seed;
int32_t pos = 0;
uint16_t checksum = seed;
while (length--)
checksum = (crc16Table[(checksum ^ data[pos++]) & 0xFF] ^ (checksum >> 8));

View File

@ -10,7 +10,7 @@
namespace athena::io::Compression {
void zlibInitZStrm(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen, z_stream& strm) {
void zlibInitZStrm(const uint8_t* src, uint32_t srcLen, uint8_t* dst, uint32_t dstLen, z_stream& strm) {
strm.avail_in = srcLen;
strm.avail_out = dstLen;
strm.next_in = const_cast<Bytef*>(src);
@ -19,8 +19,8 @@ void zlibInitZStrm(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 d
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
}
atInt32 zlibInflate(z_stream& strm, atInt32 bits) {
atInt32 ret = inflateInit2(&strm, bits);
int32_t zlibInflate(z_stream& strm, int32_t bits) {
int32_t ret = inflateInit2(&strm, bits);
if (ret == Z_OK) {
ret = inflate(&strm, Z_FINISH);
if (ret == Z_STREAM_END) {
@ -29,12 +29,12 @@ atInt32 zlibInflate(z_stream& strm, atInt32 bits) {
}
return ret;
}
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
int32_t decompressZlib(const uint8_t* src, uint32_t srcLen, uint8_t* dst, uint32_t dstLen) {
z_stream strm = {};
zlibInitZStrm(src, srcLen, dst, dstLen, strm);
// 15 window bits, and the | 16 tells zlib to to detect if using gzip or zlib
atInt32 ret = zlibInflate(strm, MAX_WBITS | 16);
int32_t ret = zlibInflate(strm, MAX_WBITS | 16);
if (ret != Z_STREAM_END) {
// Try again without gzip
zlibInitZStrm(src, srcLen, dst, dstLen, strm);
@ -49,7 +49,7 @@ atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint
return ret;
}
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
int32_t compressZlib(const uint8_t* src, uint32_t srcLen, uint8_t* dst, uint32_t dstLen) {
z_stream strm = {};
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
@ -60,8 +60,8 @@ atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
atInt32 err = -1;
atInt32 ret = -1;
int32_t err = -1;
int32_t ret = -1;
err = deflateInit(&strm, Z_BEST_COMPRESSION);
@ -97,11 +97,11 @@ atInt32 decompressLZO(const atUint8* source, const atInt32 sourceSize, atUint8*
// 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).
atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize) {
atUint32 srcPlace = 0, dstPlace = 0; // current read/write positions
uint32_t yaz0Decode(const uint8_t* src, uint8_t* dst, uint32_t uncompressedSize) {
uint32_t srcPlace = 0, dstPlace = 0; // current read/write positions
atInt32 validBitCount = 0; // number of valid bits left in "code" byte
atUint8 currCodeByte;
int32_t validBitCount = 0; // number of valid bits left in "code" byte
uint8_t currCodeByte;
while (dstPlace < uncompressedSize) {
// read new "code" byte if the current one is used up
@ -118,14 +118,14 @@ atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize)
srcPlace++;
} else {
// RLE part
atUint8 byte1 = src[srcPlace];
atUint8 byte2 = src[srcPlace + 1];
uint8_t byte1 = src[srcPlace];
uint8_t byte2 = src[srcPlace + 1];
srcPlace += 2;
atUint32 dist = ((byte1 & 0xF) << 8) | byte2;
atUint32 copySource = dstPlace - (dist + 1);
uint32_t dist = ((byte1 & 0xF) << 8) | byte2;
uint32_t copySource = dstPlace - (dist + 1);
atUint32 numBytes = byte1 >> 4;
uint32_t numBytes = byte1 >> 4;
if (numBytes == 0) {
numBytes = src[srcPlace] + 0x12;
@ -134,7 +134,7 @@ atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize)
numBytes += 2;
// copy run
for (atUint32 i = 0; i < numBytes; ++i) {
for (uint32_t i = 0; i < numBytes; ++i) {
dst[dstPlace] = dst[copySource];
copySource++;
dstPlace++;
@ -151,25 +151,25 @@ atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize)
// Yaz0 encode
typedef struct {
atUint32 srcPos, dstPos;
uint32_t srcPos, dstPos;
} yaz0_Ret;
atUint32 simpleEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMatchPos);
atUint32 nintendoEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMatchPos);
uint32_t simpleEnc(const uint8_t* src, int32_t size, int32_t pos, uint32_t* pMatchPos);
uint32_t nintendoEnc(const uint8_t* src, int32_t size, int32_t pos, uint32_t* pMatchPos);
atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data) {
uint32_t yaz0Encode(const uint8_t* src, uint32_t srcSize, uint8_t* data) {
yaz0_Ret r = {0, 0};
atInt32 pos = 0;
atUint8 dst[24]; // 8 codes * 3 bytes maximum
atUint32 dstSize = 0;
atUint32 i;
int32_t pos = 0;
uint8_t dst[24]; // 8 codes * 3 bytes maximum
uint32_t dstSize = 0;
uint32_t i;
atUint32 validBitCount = 0; // number of valid bits left in "code" byte
atUint8 currCodeByte = 0;
uint32_t validBitCount = 0; // number of valid bits left in "code" byte
uint8_t currCodeByte = 0;
while (r.srcPos < srcSize) {
atUint32 numBytes;
atUint32 matchPos;
uint32_t numBytes;
uint32_t matchPos;
numBytes = nintendoEnc(src, srcSize, r.srcPos, &matchPos);
if (numBytes < 3) {
@ -181,8 +181,8 @@ atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data) {
currCodeByte |= (0x80 >> validBitCount);
} else {
// RLE part
atUint32 dist = r.srcPos - matchPos - 1;
atUint8 byte1, byte2, byte3;
uint32_t dist = r.srcPos - matchPos - 1;
uint8_t byte1, byte2, byte3;
if (numBytes >= 0x12) // 3 byte encoding
{
@ -244,11 +244,11 @@ atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data) {
}
// a lookahead encoding scheme for ngc Yaz0
atUint32 nintendoEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMatchPos) {
atUint32 numBytes = 1;
static atUint32 numBytes1;
static atUint32 matchPos;
static atInt32 prevFlag = 0;
uint32_t nintendoEnc(const uint8_t* src, int32_t size, int32_t pos, uint32_t* pMatchPos) {
uint32_t numBytes = 1;
static uint32_t numBytes1;
static uint32_t matchPos;
static int32_t 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.
@ -278,10 +278,10 @@ atUint32 nintendoEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pM
}
// simple and straight encoding scheme for Yaz0
atUint32 simpleEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMatchPos) {
uint32_t simpleEnc(const uint8_t* src, int32_t size, int32_t pos, uint32_t* pMatchPos) {
int startPos = pos - 0x1000, j, i;
atUint32 numBytes = 1;
atUint32 matchPos = 0;
uint32_t numBytes = 1;
uint32_t matchPos = 0;
if (startPos < 0)
startPos = 0;
@ -292,7 +292,7 @@ atUint32 simpleEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMat
break;
}
if ((atUint32)j > numBytes) {
if ((uint32_t)j > numBytes) {
numBytes = j;
matchPos = i;
}
@ -306,7 +306,7 @@ atUint32 simpleEnc(const atUint8* src, atInt32 size, atInt32 pos, atUint32* pMat
return numBytes;
}
atUint32 decompressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst) {
uint32_t decompressLZ77(const uint8_t* src, uint32_t srcLen, uint8_t** dst) {
if (*src == 0x11) {
return LZType11().decompress(src, dst, srcLen);
}
@ -314,7 +314,7 @@ atUint32 decompressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst) {
return LZType10(2).decompress(src, dst, srcLen);
}
atUint32 compressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst, bool extended) {
uint32_t compressLZ77(const uint8_t* src, uint32_t srcLen, uint8_t** dst, bool extended) {
if (extended)
return LZType11().compress(src, dst, srcLen);

View File

@ -50,7 +50,7 @@ bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data(
bool Dir::touch() {
std::srand(std::time(nullptr));
atUint64 tmp = utility::rand64();
uint64_t tmp = utility::rand64();
std::string tmpFile = std::format("{:016X}.tmp", tmp);
bool ret = FileInfo(m_path + "/" + tmpFile).touch();
if (ret)

View File

@ -69,7 +69,7 @@ std::string FileInfo::extension() const {
return m_path.substr(pos + 1);
}
atUint64 FileInfo::size() const { return utility::fileSize(m_path); }
uint64_t FileInfo::size() const { return utility::fileSize(m_path); }
bool FileInfo::exists() const {
atStat64_t st;

View File

@ -8,14 +8,14 @@
#include "win32_largefilewrapper.h"
namespace athena::io {
FileReader::FileReader(std::string_view filename, atInt32 cacheSize, bool globalErr)
FileReader::FileReader(std::string_view filename, int32_t cacheSize, bool globalErr)
: m_fileHandle(nullptr), m_cacheData(nullptr), m_offset(0), m_globalErr(globalErr) {
m_filename = utility::utf8ToWide(filename);
open();
setCacheSize(cacheSize);
}
FileReader::FileReader(std::wstring_view filename, atInt32 cacheSize, bool globalErr)
FileReader::FileReader(std::wstring_view filename, int32_t cacheSize, bool globalErr)
: m_fileHandle(nullptr), m_cacheData(nullptr), m_offset(0), m_globalErr(globalErr) {
m_filename = filename;
open();
@ -64,13 +64,13 @@ void FileReader::close() {
return;
}
void FileReader::seek(atInt64 pos, SeekOrigin origin) {
void FileReader::seek(int64_t pos, SeekOrigin origin) {
if (!isOpen())
return;
// check block position
if (m_blockSize > 0) {
atUint64 oldOff = m_offset;
uint64_t oldOff = m_offset;
switch (origin) {
case SeekOrigin::Begin:
m_offset = pos;
@ -97,7 +97,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
SetFilePointerEx(m_fileHandle, li, nullptr, FILE_BEGIN);
DWORD readSz;
ReadFile(m_fileHandle, m_cacheData.get(), m_blockSize, &readSz, nullptr);
m_curBlock = (atInt32)block;
m_curBlock = (int32_t)block;
}
} else {
LARGE_INTEGER li;
@ -110,7 +110,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
}
}
atUint64 FileReader::position() const {
uint64_t FileReader::position() const {
if (!isOpen()) {
if (m_globalErr)
atError("File not open");
@ -127,7 +127,7 @@ atUint64 FileReader::position() const {
}
}
atUint64 FileReader::length() const {
uint64_t FileReader::length() const {
if (!isOpen()) {
if (m_globalErr)
atError("File not open");
@ -139,7 +139,7 @@ atUint64 FileReader::length() const {
return res.QuadPart;
}
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
uint64_t FileReader::readUBytesToBuf(void* buf, uint64_t len) {
if (!isOpen()) {
if (m_globalErr)
atError("File not open for reading");
@ -154,16 +154,16 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
} else {
LARGE_INTEGER fs;
GetFileSizeEx(m_fileHandle, &fs);
if (m_offset >= atUint64(fs.QuadPart))
if (m_offset >= uint64_t(fs.QuadPart))
return 0;
if (m_offset + len >= atUint64(fs.QuadPart))
if (m_offset + len >= uint64_t(fs.QuadPart))
len = fs.QuadPart - m_offset;
size_t block = m_offset / m_blockSize;
atUint64 cacheOffset = m_offset % m_blockSize;
atUint64 cacheSize;
atUint64 rem = len;
atUint8* dst = (atUint8*)buf;
uint64_t cacheOffset = m_offset % m_blockSize;
uint64_t cacheSize;
uint64_t rem = len;
uint8_t* dst = (uint8_t*)buf;
while (rem) {
if (block != m_curBlock) {
@ -172,7 +172,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
SetFilePointerEx(m_fileHandle, li, nullptr, FILE_BEGIN);
DWORD readSz;
ReadFile(m_fileHandle, m_cacheData.get(), m_blockSize, &readSz, nullptr);
m_curBlock = (atInt32)block;
m_curBlock = (int32_t)block;
}
cacheSize = rem;
@ -186,19 +186,19 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
++block;
}
m_offset += len;
return dst - (atUint8*)buf;
return dst - (uint8_t*)buf;
}
}
void FileReader::setCacheSize(const atInt32 blockSize) {
void FileReader::setCacheSize(const int32_t blockSize) {
m_blockSize = blockSize;
if (m_blockSize > length())
m_blockSize = (atInt32)length();
m_blockSize = (int32_t)length();
m_curBlock = -1;
if (m_blockSize > 0)
m_cacheData.reset(new atUint8[m_blockSize]);
m_cacheData.reset(new uint8_t[m_blockSize]);
}
} // namespace athena::io

View File

@ -3,7 +3,7 @@
#include <cstring>
namespace athena::io {
void TransactionalFileWriter::seek(atInt64 pos, SeekOrigin origin) {
void TransactionalFileWriter::seek(int64_t pos, SeekOrigin origin) {
switch (origin) {
case SeekOrigin::Begin:
m_position = pos;
@ -16,8 +16,8 @@ void TransactionalFileWriter::seek(atInt64 pos, SeekOrigin origin) {
}
}
void TransactionalFileWriter::writeUBytes(const atUint8* data, atUint64 len) {
atUint64 neededSz = m_position + len;
void TransactionalFileWriter::writeUBytes(const uint8_t* data, uint64_t len) {
uint64_t neededSz = m_position + len;
if (neededSz > m_deferredBuffer.size()) {
m_deferredBuffer.reserve(neededSz * 2);
m_deferredBuffer.resize(neededSz);

View File

@ -76,7 +76,7 @@ void FileWriter::close() {
MoveFileExW(tmpFilename.c_str(), m_filename.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
}
void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
void FileWriter::seek(int64_t pos, SeekOrigin origin) {
if (!isOpen()) {
if (m_globalErr)
atError("Unable to seek in file, not open");
@ -93,16 +93,16 @@ void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
}
}
atUint64 FileWriter::position() const {
uint64_t FileWriter::position() const {
LARGE_INTEGER li = {};
LARGE_INTEGER res;
SetFilePointerEx(m_fileHandle, li, &res, FILE_CURRENT);
return static_cast<atUint64>(res.QuadPart);
return static_cast<uint64_t>(res.QuadPart);
}
atUint64 FileWriter::length() const { return utility::fileSize(m_filename); }
uint64_t FileWriter::length() const { return utility::fileSize(m_filename); }
void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
void FileWriter::writeUBytes(const uint8_t* data, uint64_t len) {
if (!isOpen()) {
if (m_globalErr) {
atError("File not open for writing");
@ -111,9 +111,9 @@ void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
return;
}
atUint64 remaining = len;
uint64_t remaining = len;
do {
const auto toWrite = static_cast<DWORD>(std::min(remaining, atUint64{std::numeric_limits<DWORD>::max()}));
const auto toWrite = static_cast<DWORD>(std::min(remaining, uint64_t{std::numeric_limits<DWORD>::max()}));
DWORD written = 0;
if (WriteFile(m_fileHandle, data, toWrite, &written, nullptr) == FALSE) {

View File

@ -7,9 +7,9 @@ const char MCFile::VERSION_US[33] = "AGBZELDA:THE MINISH CAP:ZELDA 5\0";
MCFile::MCFile() {}
// TODO: Rewrite this to be more optimized, the current solution takes quite a few cycles
atUint8* reverse(atUint8* data, atUint32 length) {
atUint32 a = 0;
atUint32 swap;
uint8_t* reverse(uint8_t* data, uint32_t length) {
uint32_t a = 0;
uint32_t swap;
for (; a < --length; a++) {
swap = data[a];
@ -20,15 +20,15 @@ atUint8* reverse(atUint8* data, atUint32 length) {
return data;
}
atUint8* MCFile::unscramble(atUint8* data, atUint64 length) {
uint8_t* MCFile::unscramble(uint8_t* data, uint64_t length) {
if (!data)
return nullptr;
for (atUint32 i = 0; i < length; i += 8) {
atUint32 block1 = *(atUint32*)reverse((data + i), 4);
atUint32 block2 = *(atUint32*)reverse((data + i + 4), 4);
*(atUint32*)(data + i) = block2;
*(atUint32*)(data + i + 4) = block1;
for (uint32_t i = 0; i < length; i += 8) {
uint32_t block1 = *(uint32_t*)reverse((data + i), 4);
uint32_t block2 = *(uint32_t*)reverse((data + i + 4), 4);
*(uint32_t*)(data + i) = block2;
*(uint32_t*)(data + i + 4) = block1;
}
return data;

View File

@ -4,8 +4,8 @@ namespace athena {
namespace io {
static const atUint32 SCRAMBLE_VALUE = 0x5A424741;
MCFileReader::MCFileReader(atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {}
static const uint32_t SCRAMBLE_VALUE = 0x5A424741;
MCFileReader::MCFileReader(uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {}
MCFileReader::MCFileReader(const std::string& filename) : MemoryCopyReader(filename) {}

View File

@ -2,19 +2,19 @@
namespace athena::io {
MCFileWriter::MCFileWriter(atUint8* data, atUint64 length) : MemoryCopyWriter(data, length) {}
MCFileWriter::MCFileWriter(uint8_t* data, uint64_t length) : MemoryCopyWriter(data, length) {}
MCFileWriter::MCFileWriter(const std::string& filename) : MemoryCopyWriter(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.
atUint16 MCFileWriter::calculateSlotChecksum(atUint32 game) {
atUint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4);
atUint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500);
uint16_t MCFileWriter::calculateSlotChecksum(uint32_t game) {
uint16_t first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4);
uint16_t second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500);
first = (first + second) & 0xFFFF;
atUint16 result = first << 16;
uint16_t result = first << 16;
second = ~first & 0xFFFF;
second += 1;
result += second;
@ -22,12 +22,12 @@ atUint16 MCFileWriter::calculateSlotChecksum(atUint32 game) {
return result;
}
atUint16 MCFileWriter::calculateChecksum(atUint8* data, atUint32 length) {
atUint16 sum = 0;
uint16_t MCFileWriter::calculateChecksum(uint8_t* data, uint32_t length) {
uint16_t sum = 0;
int i = length;
for (atUint32 j = 0; j < length; j += 2) {
sum += *(atUint16*)(data + j) ^ i;
for (uint32_t j = 0; j < length; j += 2) {
sum += *(uint16_t*)(data + j) ^ i;
i -= 2;
}

View File

@ -2,7 +2,7 @@
namespace athena {
MCSlot::MCSlot(std::unique_ptr<atUint8[]>&& data, atUint32 length)
MCSlot::MCSlot(std::unique_ptr<uint8_t[]>&& data, uint32_t length)
: ZQuestFile(ZQuestFile::MC, Endian::Little, std::move(data), length) {}
} // namespace athena

View File

@ -9,7 +9,7 @@
#endif // HW_RVL
namespace athena::io {
MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership, bool globalErr)
MemoryReader::MemoryReader(const void* data, uint64_t length, bool takeOwnership, bool globalErr)
: m_data(data), m_length(length), m_position(0), m_owns(takeOwnership), m_globalErr(globalErr) {
if (!data) {
if (m_globalErr)
@ -21,10 +21,10 @@ MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership
MemoryReader::~MemoryReader() {
if (m_owns)
delete[] static_cast<const atUint8*>(m_data);
delete[] static_cast<const uint8_t*>(m_data);
}
MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) {
MemoryCopyReader::MemoryCopyReader(const void* data, uint64_t length) : MemoryReader(data, length, false) {
if (!data) {
if (m_globalErr)
atError("data cannot be NULL");
@ -32,15 +32,15 @@ MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryRe
return;
}
m_dataCopy.reset(new atUint8[m_length]);
m_dataCopy.reset(new uint8_t[m_length]);
m_data = m_dataCopy.get();
memmove(m_dataCopy.get(), data, m_length);
}
void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
void MemoryReader::seek(int64_t position, SeekOrigin origin) {
switch (origin) {
case SeekOrigin::Begin:
if ((position < 0 || atInt64(position) > atInt64(m_length))) {
if ((position < 0 || int64_t(position) > int64_t(m_length))) {
if (m_globalErr)
atFatal("Position {:08X} outside stream bounds ", position);
m_position = m_length;
@ -48,11 +48,11 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
return;
}
m_position = atUint64(position);
m_position = uint64_t(position);
break;
case SeekOrigin::Current:
if (((atInt64(m_position) + position) < 0 || (m_position + atUint64(position)) > m_length)) {
if (((int64_t(m_position) + position) < 0 || (m_position + uint64_t(position)) > m_length)) {
if (m_globalErr)
atFatal("Position {:08X} outside stream bounds ", position);
m_position = (position < 0 ? 0 : m_length);
@ -64,7 +64,7 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
break;
case SeekOrigin::End:
if ((((atInt64)m_length - position < 0) || (m_length - position) > m_length)) {
if ((((int64_t)m_length - position < 0) || (m_length - position) > m_length)) {
if (m_globalErr)
atFatal("Position {:08X} outside stream bounds ", position);
m_position = m_length;
@ -77,31 +77,31 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
}
}
void MemoryReader::setData(const atUint8* data, atUint64 length, bool takeOwnership) {
void MemoryReader::setData(const uint8_t* data, uint64_t length, bool takeOwnership) {
if (m_owns)
delete[] static_cast<const atUint8*>(m_data);
m_data = (atUint8*)data;
delete[] static_cast<const uint8_t*>(m_data);
m_data = (uint8_t*)data;
m_length = length;
m_position = 0;
m_owns = takeOwnership;
}
void MemoryCopyReader::setData(const atUint8* data, atUint64 length) {
m_dataCopy.reset(new atUint8[length]);
void MemoryCopyReader::setData(const uint8_t* data, uint64_t length) {
m_dataCopy.reset(new uint8_t[length]);
m_data = m_dataCopy.get();
memmove(m_dataCopy.get(), data, length);
m_length = length;
m_position = 0;
}
atUint8* MemoryReader::data() const {
atUint8* ret = new atUint8[m_length];
uint8_t* MemoryReader::data() const {
uint8_t* ret = new uint8_t[m_length];
memset(ret, 0, m_length);
memmove(ret, m_data, m_length);
return ret;
}
atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) {
uint64_t MemoryReader::readUBytesToBuf(void* buf, uint64_t length) {
if (m_position >= m_length) {
if (m_globalErr)
atError("Position {:08X} outside stream bounds ", m_position);
@ -111,14 +111,14 @@ atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) {
}
length = std::min(length, m_length - m_position);
memmove(buf, static_cast<const atUint8*>(m_data) + m_position, length);
memmove(buf, static_cast<const uint8_t*>(m_data) + m_position, length);
m_position += length;
return length;
}
void MemoryCopyReader::loadData() {
FILE* in;
atUint64 length;
uint64_t length;
in = fopen(m_filepath.c_str(), "rb");
if (!in) {
@ -131,17 +131,17 @@ void MemoryCopyReader::loadData() {
rewind(in);
length = utility::fileSize(m_filepath);
m_dataCopy.reset(new atUint8[length]);
m_dataCopy.reset(new uint8_t[length]);
m_data = m_dataCopy.get();
atUint64 done = 0;
atUint64 blocksize = BLOCKSZ;
uint64_t done = 0;
uint64_t blocksize = BLOCKSZ;
do {
if (blocksize > length - done)
blocksize = length - done;
atInt64 ret = fread(m_dataCopy.get() + done, 1, blocksize, in);
int64_t ret = fread(m_dataCopy.get() + done, 1, blocksize, in);
if (ret < 0) {
if (m_globalErr)

View File

@ -9,7 +9,7 @@
namespace athena::io {
MemoryWriter::MemoryWriter(atUint8* data, atUint64 length, bool takeOwnership)
MemoryWriter::MemoryWriter(uint8_t* data, uint64_t length, bool takeOwnership)
: m_data(data), m_length(length), m_bufferOwned(takeOwnership) {
if (!data) {
atError("data cannot be NULL");
@ -25,7 +25,7 @@ MemoryWriter::~MemoryWriter() {
m_length = 0;
}
MemoryCopyWriter::MemoryCopyWriter(atUint8* data, atUint64 length) {
MemoryCopyWriter::MemoryCopyWriter(uint8_t* data, uint64_t length) {
m_data = data;
m_length = length;
m_position = 0;
@ -36,7 +36,7 @@ MemoryCopyWriter::MemoryCopyWriter(atUint8* data, atUint64 length) {
setError();
return;
}
m_dataCopy.reset(new atUint8[length]);
m_dataCopy.reset(new uint8_t[length]);
m_data = m_dataCopy.get();
if (data)
memmove(m_data, data, length);
@ -46,7 +46,7 @@ MemoryCopyWriter::MemoryCopyWriter(std::string_view filename) {
m_filepath = filename;
m_length = 0x10;
m_position = 0;
m_dataCopy.reset(new atUint8[m_length]);
m_dataCopy.reset(new uint8_t[m_length]);
m_data = m_dataCopy.get();
m_bufferOwned = false;
@ -57,7 +57,7 @@ MemoryCopyWriter::MemoryCopyWriter(std::string_view filename) {
}
}
void MemoryWriter::seek(atInt64 position, SeekOrigin origin) {
void MemoryWriter::seek(int64_t position, SeekOrigin origin) {
switch (origin) {
case SeekOrigin::Begin:
if (position < 0) {
@ -66,7 +66,7 @@ void MemoryWriter::seek(atInt64 position, SeekOrigin origin) {
return;
}
if ((atUint64)position > m_length) {
if ((uint64_t)position > m_length) {
atError("data exceeds available buffer space");
setError();
return;
@ -76,7 +76,7 @@ void MemoryWriter::seek(atInt64 position, SeekOrigin origin) {
break;
case SeekOrigin::Current:
if ((((atInt64)m_position + position) < 0)) {
if ((((int64_t)m_position + position) < 0)) {
atError("Position outside stream bounds");
setError();
return;
@ -92,13 +92,13 @@ void MemoryWriter::seek(atInt64 position, SeekOrigin origin) {
break;
case SeekOrigin::End:
if (((atInt64)m_length - position) < 0) {
if (((int64_t)m_length - position) < 0) {
atError("Position outside stream bounds");
setError();
return;
}
if ((atUint64)position > m_length) {
if ((uint64_t)position > m_length) {
atError("data exceeds available buffer space");
setError();
return;
@ -109,7 +109,7 @@ void MemoryWriter::seek(atInt64 position, SeekOrigin origin) {
}
}
void MemoryCopyWriter::seek(atInt64 position, SeekOrigin origin) {
void MemoryCopyWriter::seek(int64_t position, SeekOrigin origin) {
switch (origin) {
case SeekOrigin::Begin:
if (position < 0) {
@ -118,14 +118,14 @@ void MemoryCopyWriter::seek(atInt64 position, SeekOrigin origin) {
return;
}
if ((atUint64)position > m_length)
if ((uint64_t)position > m_length)
resize(position);
m_position = position;
break;
case SeekOrigin::Current:
if ((((atInt64)m_position + position) < 0)) {
if ((((int64_t)m_position + position) < 0)) {
atError("Position outside stream bounds");
setError();
return;
@ -138,13 +138,13 @@ void MemoryCopyWriter::seek(atInt64 position, SeekOrigin origin) {
break;
case SeekOrigin::End:
if (((atInt64)m_length - position) < 0) {
if (((int64_t)m_length - position) < 0) {
atError("Position outside stream bounds");
setError();
return;
}
if ((atUint64)position > m_length)
if ((uint64_t)position > m_length)
resize(position);
m_position = m_length - position;
@ -152,7 +152,7 @@ void MemoryCopyWriter::seek(atInt64 position, SeekOrigin origin) {
}
}
void MemoryWriter::setData(atUint8* data, atUint64 length, bool takeOwnership) {
void MemoryWriter::setData(uint8_t* data, uint64_t length, bool takeOwnership) {
if (m_bufferOwned)
delete m_data;
@ -162,8 +162,8 @@ void MemoryWriter::setData(atUint8* data, atUint64 length, bool takeOwnership) {
m_bufferOwned = takeOwnership;
}
void MemoryCopyWriter::setData(const atUint8* data, atUint64 length) {
m_dataCopy.reset(new atUint8[length]);
void MemoryCopyWriter::setData(const uint8_t* data, uint64_t length) {
m_dataCopy.reset(new uint8_t[length]);
m_data = m_dataCopy.get();
memmove(m_data, data, length);
m_length = length;
@ -171,8 +171,8 @@ void MemoryCopyWriter::setData(const atUint8* data, atUint64 length) {
m_bufferOwned = false;
}
atUint8* MemoryWriter::data() const {
atUint8* ret = new atUint8[m_length];
uint8_t* MemoryWriter::data() const {
uint8_t* ret = new uint8_t[m_length];
memset(ret, 0, m_length);
memmove(ret, m_data, m_length);
return ret;
@ -197,15 +197,15 @@ void MemoryWriter::save(std::string_view filename) {
return;
}
atUint64 done = 0;
atUint64 blocksize = BLOCKSZ;
uint64_t done = 0;
uint64_t blocksize = BLOCKSZ;
do {
if (blocksize > m_length - done) {
blocksize = m_length - done;
}
const atInt64 ret = std::fwrite(m_data + done, 1, blocksize, out.get());
const int64_t ret = std::fwrite(m_data + done, 1, blocksize, out.get());
if (ret < 0) {
atError("Error writing data to disk");
@ -221,7 +221,7 @@ void MemoryWriter::save(std::string_view filename) {
} while (done < m_length);
}
void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length) {
void MemoryWriter::writeUBytes(const uint8_t* data, uint64_t length) {
if (!data) {
atError("data cannnot be NULL");
setError();
@ -239,7 +239,7 @@ void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length) {
m_position += length;
}
void MemoryCopyWriter::writeUBytes(const atUint8* data, atUint64 length) {
void MemoryCopyWriter::writeUBytes(const uint8_t* data, uint64_t length) {
if (!data) {
atError("data cannnot be NULL");
setError();
@ -254,14 +254,14 @@ void MemoryCopyWriter::writeUBytes(const atUint8* data, atUint64 length) {
m_position += length;
}
void MemoryCopyWriter::resize(atUint64 newSize) {
void MemoryCopyWriter::resize(uint64_t newSize) {
if (newSize < m_length) {
atError("New size cannot be less to the old size.");
return;
}
// Allocate and copy new buffer
auto newArray = std::make_unique<atUint8[]>(newSize);
auto newArray = std::make_unique<uint8_t[]>(newSize);
if (m_dataCopy) {
std::memmove(newArray.get(), m_dataCopy.get(), m_length);
}

View File

@ -17,7 +17,7 @@ void SkywardSwordFile::addQuest(athena::SkywardSwordQuest* q) {
m_quests.push_back(q);
}
SkywardSwordQuest* SkywardSwordFile::quest(atUint32 id) {
SkywardSwordQuest* SkywardSwordFile::quest(uint32_t id) {
if (id > m_quests.size() - 1) {
atWarning("index out of range");
return nullptr;

View File

@ -5,7 +5,7 @@
namespace athena::io {
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {
SkywardSwordFileReader::SkywardSwordFileReader(uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {
setEndian(Endian::Big);
}
@ -21,7 +21,7 @@ SkywardSwordFile* SkywardSwordFileReader::read() {
return nullptr;
}
atUint32 magic = readUint32();
uint32_t magic = readUint32();
if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic) {
atError("Not a valid Skyward Sword save file");
@ -29,7 +29,7 @@ SkywardSwordFile* SkywardSwordFileReader::read() {
}
seek(0x01C, SeekOrigin::Begin);
atUint32 headerSize = readUint32(); // Seems to be (headerSize - 1)
uint32_t headerSize = readUint32(); // Seems to be (headerSize - 1)
if (headerSize != 0x1D) {
atError("Invalid header size, Corrupted data?");
@ -44,7 +44,7 @@ SkywardSwordFile* SkywardSwordFileReader::read() {
for (int i = 0; i < 3; i++) {
SkywardSwordQuest* q = new SkywardSwordQuest(readUBytes(0x53C0), 0x53C0);
atUint64 pos = position();
uint64_t pos = position();
// seek to the skip data for this particular quest
seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
q->setSkipData(readUBytes(0x24));

View File

@ -4,7 +4,7 @@
namespace athena::io {
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len) : MemoryCopyWriter(data, len) {
SkywardSwordFileWriter::SkywardSwordFileWriter(uint8_t* data, uint64_t len) : MemoryCopyWriter(data, len) {
setEndian(Endian::Big);
}
@ -18,7 +18,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file) {
return;
}
atUint32 magic = (file->region() == Region::NTSC
uint32_t magic = (file->region() == Region::NTSC
? SkywardSwordFile::USMagic
: (file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic));
@ -39,7 +39,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file) {
q->fixChecksums();
// Write the save data
writeUBytes(q->data(), q->length());
atUint64 pos = position();
uint64_t pos = position();
// Write the slots skip data
seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
writeUBytes(q->skipData(), 0x24);

View File

@ -7,47 +7,47 @@
namespace athena {
namespace priv {
static const atUint32 NAME_OFFSET = 0x08D4;
static const atUint32 RUPEE_COUNT_OFFSET = 0x0A5E;
static const atUint32 AMMO_COUNT_OFFSET = 0x0A60;
static const atUint32 MAX_HP_OFFSET = 0x5302;
static const atUint32 SPAWN_HP_OFFSET = 0x5304;
static const atUint32 CURRENT_HP_OFFSET = 0x5306;
static const atUint32 ROOM_ID_OFFSET = 0x5309;
static const atUint32 CURRENT_LOCATION_OFFSET = 0x531C;
static const atUint32 CURRENT_AREA_OFFSET = 0x533C;
static const atUint32 CURRENT_LOCATION_COPY_OFFSET = 0x535C;
static const atUint32 CHECKSUM_OFFSET = 0x53BC;
static const atUint32 ISNEW_OFFSET = 0x53AD;
static const uint32_t NAME_OFFSET = 0x08D4;
static const uint32_t RUPEE_COUNT_OFFSET = 0x0A5E;
static const uint32_t AMMO_COUNT_OFFSET = 0x0A60;
static const uint32_t MAX_HP_OFFSET = 0x5302;
static const uint32_t SPAWN_HP_OFFSET = 0x5304;
static const uint32_t CURRENT_HP_OFFSET = 0x5306;
static const uint32_t ROOM_ID_OFFSET = 0x5309;
static const uint32_t CURRENT_LOCATION_OFFSET = 0x531C;
static const uint32_t CURRENT_AREA_OFFSET = 0x533C;
static const uint32_t CURRENT_LOCATION_COPY_OFFSET = 0x535C;
static const uint32_t CHECKSUM_OFFSET = 0x53BC;
static const uint32_t ISNEW_OFFSET = 0x53AD;
static const atUint32 SKIP_CHECKSUM_OFFSET = 0x20;
static const uint32_t SKIP_CHECKSUM_OFFSET = 0x20;
} // namespace priv
union AmmoValues {
struct {
atUint32 arrows : 7;
atUint32 bombs : 7;
atUint32 : 9;
atUint32 seeds : 7;
atUint32 : 2;
uint32_t arrows : 7;
uint32_t bombs : 7;
uint32_t : 9;
uint32_t seeds : 7;
uint32_t : 2;
};
atUint32 value;
uint32_t value;
};
SkywardSwordQuest::SkywardSwordQuest(std::unique_ptr<atUint8[]>&& data, atUint32 len)
SkywardSwordQuest::SkywardSwordQuest(std::unique_ptr<uint8_t[]>&& data, uint32_t len)
: ZQuestFile(ZQuestFile::SS, Endian::Big, std::move(data), len) {}
void SkywardSwordQuest::setSkipData(std::unique_ptr<atUint8[]>&& data) { m_skipData = std::move(data); }
void SkywardSwordQuest::setSkipData(std::unique_ptr<uint8_t[]>&& data) { m_skipData = std::move(data); }
atUint8* SkywardSwordQuest::skipData() const { return m_skipData.get(); }
uint8_t* SkywardSwordQuest::skipData() const { return m_skipData.get(); }
void SkywardSwordQuest::setPlayerName(const std::string& name) {
if (name.length() > 8)
atDebug("WARNING: name cannot be greater than 8 characters, automatically truncating");
const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(name.c_str());
for (atUint32 i = 0; i < 8; i++) {
atUint16& c = *(atUint16*)(m_data.get() + priv::NAME_OFFSET + (i * 2));
for (uint32_t i = 0; i < 8; i++) {
uint16_t& c = *(uint16_t*)(m_data.get() + priv::NAME_OFFSET + (i * 2));
if (!*buf) {
c = 0;
@ -61,7 +61,7 @@ void SkywardSwordQuest::setPlayerName(const std::string& name) {
return;
}
buf += len;
c = atUint16(wc);
c = uint16_t(wc);
utility::BigUint16(c);
}
}
@ -69,8 +69,8 @@ void SkywardSwordQuest::setPlayerName(const std::string& name) {
std::string SkywardSwordQuest::playerName() const {
std::string val;
for (atUint32 i = 0; i < 8; i++) {
atUint16 c = *(atUint16*)(m_data.get() + priv::NAME_OFFSET + (i * 2));
for (uint32_t i = 0; i < 8; i++) {
uint16_t c = *(uint16_t*)(m_data.get() + priv::NAME_OFFSET + (i * 2));
if (c == 0)
break;
@ -85,18 +85,18 @@ std::string SkywardSwordQuest::playerName() const {
return val;
}
void SkywardSwordQuest::setRupeeCount(atUint16 value) {
atUint16& tmp = *(atUint16*)(m_data.get() + priv::RUPEE_COUNT_OFFSET);
void SkywardSwordQuest::setRupeeCount(uint16_t value) {
uint16_t& tmp = *(uint16_t*)(m_data.get() + priv::RUPEE_COUNT_OFFSET);
tmp = value;
utility::BigUint16(tmp);
}
atUint16 SkywardSwordQuest::rupeeCount() {
atUint16 ret = *(atUint16*)(m_data.get() + priv::RUPEE_COUNT_OFFSET);
uint16_t SkywardSwordQuest::rupeeCount() {
uint16_t ret = *(uint16_t*)(m_data.get() + priv::RUPEE_COUNT_OFFSET);
return utility::BigUint16(ret);
}
void SkywardSwordQuest::setAmmoCount(SkywardSwordQuest::AmmoType type, atUint32 count) {
void SkywardSwordQuest::setAmmoCount(SkywardSwordQuest::AmmoType type, uint32_t count) {
AmmoValues& values = *(AmmoValues*)(m_data.get() + priv::AMMO_COUNT_OFFSET);
utility::BigUint32(values.value);
@ -117,7 +117,7 @@ void SkywardSwordQuest::setAmmoCount(SkywardSwordQuest::AmmoType type, atUint32
utility::BigUint32(values.value);
}
atUint32 SkywardSwordQuest::ammoCount(AmmoType type) {
uint32_t SkywardSwordQuest::ammoCount(AmmoType type) {
AmmoValues values = *(AmmoValues*)(m_data.get() + priv::AMMO_COUNT_OFFSET);
utility::BigUint32(values.value);
@ -136,34 +136,34 @@ atUint32 SkywardSwordQuest::ammoCount(AmmoType type) {
}
}
void SkywardSwordQuest::setMaxHP(atUint16 val) {
*(atUint16*)(m_data.get() + priv::MAX_HP_OFFSET) = utility::BigUint16(val);
void SkywardSwordQuest::setMaxHP(uint16_t val) {
*(uint16_t*)(m_data.get() + priv::MAX_HP_OFFSET) = utility::BigUint16(val);
}
atUint16 SkywardSwordQuest::maxHP() {
atUint16 ret = *(atUint16*)(m_data.get() + priv::MAX_HP_OFFSET);
uint16_t SkywardSwordQuest::maxHP() {
uint16_t ret = *(uint16_t*)(m_data.get() + priv::MAX_HP_OFFSET);
return utility::BigUint16(ret);
}
float SkywardSwordQuest::maxHearts() { return (maxHP() / 4.f); }
void SkywardSwordQuest::setSpawnHP(atUint16 val) {
*(atUint16*)(m_data.get() + priv::SPAWN_HP_OFFSET) = utility::BigUint16(val);
void SkywardSwordQuest::setSpawnHP(uint16_t val) {
*(uint16_t*)(m_data.get() + priv::SPAWN_HP_OFFSET) = utility::BigUint16(val);
}
atUint16 SkywardSwordQuest::spawnHP() {
atUint16 ret = *(atUint16*)(m_data.get() + priv::SPAWN_HP_OFFSET);
uint16_t SkywardSwordQuest::spawnHP() {
uint16_t ret = *(uint16_t*)(m_data.get() + priv::SPAWN_HP_OFFSET);
return utility::BigUint16(ret);
}
float SkywardSwordQuest::spawnHearts() { return (spawnHP() / 4.f); }
void SkywardSwordQuest::setCurrentHP(atUint16 val) {
*(atUint16*)(m_data.get() + priv::CURRENT_HP_OFFSET) = utility::BigUint16(val);
void SkywardSwordQuest::setCurrentHP(uint16_t val) {
*(uint16_t*)(m_data.get() + priv::CURRENT_HP_OFFSET) = utility::BigUint16(val);
}
atUint16 SkywardSwordQuest::currentHP() {
atUint16 ret = *(atUint16*)(m_data.get() + priv::CURRENT_HP_OFFSET);
uint16_t SkywardSwordQuest::currentHP() {
uint16_t ret = *(uint16_t*)(m_data.get() + priv::CURRENT_HP_OFFSET);
return utility::BigUint16(ret);
}
@ -179,28 +179,28 @@ std::string SkywardSwordQuest::currentLocationCopy() {
return std::string((char*)m_data.get() + priv::CURRENT_LOCATION_COPY_OFFSET);
}
atUint32 SkywardSwordQuest::slotChecksum() {
atUint32 ret = *(atUint32*)(m_data.get() + priv::CHECKSUM_OFFSET);
uint32_t SkywardSwordQuest::slotChecksum() {
uint32_t ret = *(uint32_t*)(m_data.get() + priv::CHECKSUM_OFFSET);
utility::BigUint32(ret);
return ret;
}
atUint32 SkywardSwordQuest::skipChecksum() {
atUint32 ret = *(atUint32*)(m_skipData.get() + priv::SKIP_CHECKSUM_OFFSET);
uint32_t SkywardSwordQuest::skipChecksum() {
uint32_t ret = *(uint32_t*)(m_skipData.get() + priv::SKIP_CHECKSUM_OFFSET);
utility::BigUint32(ret);
return ret;
}
void SkywardSwordQuest::fixChecksums() {
atUint32 checksum = checksums::crc32(m_data.get(), priv::CHECKSUM_OFFSET);
uint32_t checksum = checksums::crc32(m_data.get(), priv::CHECKSUM_OFFSET);
utility::BigUint32(checksum);
*(atUint32*)(m_data.get() + priv::CHECKSUM_OFFSET) = checksum;
*(uint32_t*)(m_data.get() + priv::CHECKSUM_OFFSET) = checksum;
checksum = checksums::crc32(m_skipData.get(), priv::SKIP_CHECKSUM_OFFSET);
utility::BigUint32(checksum);
*(atUint32*)(m_skipData.get() + priv::SKIP_CHECKSUM_OFFSET) = checksum;
*(uint32_t*)(m_skipData.get() + priv::SKIP_CHECKSUM_OFFSET) = checksum;
}
void SkywardSwordQuest::setNew(bool isNew) { *(bool*)(m_data.get() + priv::ISNEW_OFFSET) = isNew; }

View File

@ -55,16 +55,16 @@ void Sprite::setStateIds(std::vector<int> ids) {
std::vector<int> Sprite::stateIds() const { return m_stateIds; }
atUint32 Sprite::stateCount() const { return (atUint32)m_stateIds.size(); }
uint32_t Sprite::stateCount() const { return (uint32_t)m_stateIds.size(); }
void Sprite::setCurrentState(const atUint32 id) {
void Sprite::setCurrentState(const uint32_t id) {
if (id >= m_stateIds.size())
return;
m_currentState = id;
}
atUint32 Sprite::currentState() const { return m_currentState; }
uint32_t Sprite::currentState() const { return m_currentState; }
bool Sprite::addFrame(SpriteFrame* part) {
if (m_frames.size() > 65536)
@ -89,7 +89,7 @@ bool Sprite::removeFrame(SpriteFrame* frame) {
return false;
}
void Sprite::setFrame(atUint32 id) {
void Sprite::setFrame(uint32_t id) {
if (id > m_frames.size())
return;
}
@ -110,14 +110,14 @@ void Sprite::setFrames(std::vector<SpriteFrame*> frames) {
m_frames = frames;
}
atUint32 Sprite::frameCount() const { return (atUint32)m_frames.size(); }
uint32_t Sprite::frameCount() const { return (uint32_t)m_frames.size(); }
std::vector<SpriteFrame*> Sprite::frames() const { return m_frames; }
SpriteFile* Sprite::container() const { return m_root; }
void Sprite::setCurrentFrame(SpriteFrame* frame) {
atUint32 id = 0;
uint32_t id = 0;
for (SpriteFrame* tmpFrame : m_frames) {
if (tmpFrame == frame) {
@ -129,7 +129,7 @@ void Sprite::setCurrentFrame(SpriteFrame* frame) {
}
}
void Sprite::setCurrentFrame(atUint32 id) {
void Sprite::setCurrentFrame(uint32_t id) {
if (id >= m_frames.size())
return;
@ -142,7 +142,7 @@ void Sprite::advanceFrame() {
m_currentFrame++;
if (m_currentFrame >= m_frames.size())
m_currentFrame = (atUint32)m_frames.size() - 1;
m_currentFrame = (uint32_t)m_frames.size() - 1;
}
void Sprite::retreatFrame() {

View File

@ -4,17 +4,17 @@
#include <iostream>
namespace athena::Sakura {
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_t SpriteFile::Major = 1;
const uint32_t SpriteFile::Minor = 0;
const uint32_t SpriteFile::Revision = 2;
const uint32_t SpriteFile::Build = 0;
const uint32_t SpriteFile::Version = Major | (Minor << 8) | (Revision << 16) | (Build << 24);
const atUint32 SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24);
const uint32_t SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24);
SpriteFile::SpriteFile() {}
SpriteFile::SpriteFile(atUint32 width, atUint32 height, float originX, float originY)
SpriteFile::SpriteFile(uint32_t width, uint32_t height, float originX, float originY)
: m_size(width, height), m_origin(originX, originY) {}
SpriteFile::SpriteFile(const Vector2Di& size, const Vector2Df& origin) : m_size(size), m_origin(origin) {}
@ -28,15 +28,15 @@ SpriteFile::~SpriteFile() {
m_sprites.clear();
}
void SpriteFile::setSize(atUint32 width, atUint32 height) { setSize(Vector2Di(width, height)); }
void SpriteFile::setSize(uint32_t width, uint32_t height) { setSize(Vector2Di(width, height)); }
void SpriteFile::setSize(const Vector2Di& size) { m_size = size; }
Vector2Di SpriteFile::size() const { return m_size; }
atUint32 SpriteFile::width() const { return m_size.x; }
uint32_t SpriteFile::width() const { return m_size.x; }
atUint32 SpriteFile::height() const { return m_size.y; }
uint32_t SpriteFile::height() const { return m_size.y; }
void SpriteFile::setOrigin(const float x, const float y) { setOrigin(Vector2Df(x, y)); }
@ -65,7 +65,7 @@ void SpriteFile::removeTexture(int id) {
delete tex;
}
STexture* SpriteFile::texture(atUint32 id) {
STexture* SpriteFile::texture(uint32_t id) {
if (id >= m_textures.size())
return NULL;
@ -74,7 +74,7 @@ STexture* SpriteFile::texture(atUint32 id) {
std::vector<STexture*> SpriteFile::textures() const { return m_textures; }
atUint32 SpriteFile::textureCount() const { return (atUint32)m_textures.size(); }
uint32_t SpriteFile::textureCount() const { return (uint32_t)m_textures.size(); }
void SpriteFile::addSprite(Sprite* sprite) {
std::string name(sprite->name());
@ -125,7 +125,7 @@ Sprite* SpriteFile::sprite(const std::string& name) {
std::unordered_map<std::string, Sprite*> SpriteFile::sprites() const { return m_sprites; }
atUint32 SpriteFile::spriteCount() const { return (atUint32)m_sprites.size(); }
uint32_t SpriteFile::spriteCount() const { return (uint32_t)m_sprites.size(); }
void SpriteFile::setTextures(std::vector<STexture*> textures) {
if (textures.size() == 0)

View File

@ -6,21 +6,21 @@
#include "athena/Utility.hpp"
namespace athena::io {
SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {}
SpriteFileReader::SpriteFileReader(uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {}
SpriteFileReader::SpriteFileReader(const std::string& filepath) : MemoryCopyReader(filepath) {}
Sakura::SpriteFile* SpriteFileReader::readFile() {
Sakura::SpriteFile* ret = NULL;
atUint32 magic = readUint32();
uint32_t magic = readUint32();
if (magic != Sakura::SpriteFile::Magic) {
atError("Not a valid Sakura Sprite container");
return nullptr;
}
atUint32 version = readUint32();
uint32_t version = readUint32();
// TODO: Make this more verbose
if (version != Sakura::SpriteFile::Version) {
@ -33,14 +33,14 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
// Such as the texture count, it's dimensions, and it's origin.
// After that we have the number of sprites contained in this
// sprite container.
atUint16 textureCount =
uint16_t textureCount =
readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
// This is probably overkill, but it's better safe than sorry.
atUint32 width = readUint32();
atUint32 height = readUint32();
uint32_t width = readUint32();
uint32_t height = readUint32();
float originX = readFloat();
float originY = readFloat();
atUint16 spriteCount = readUint16();
uint16_t spriteCount = readUint16();
// Lets go ahead and create or new container.
ret = new Sakura::SpriteFile(width, height, originX, originY);
@ -50,7 +50,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
// to migrate this code to Big Endian based systems, such as the wii
// which require data to be 32 byte aligned, or it causes some issues.
// It's also convenient to have this, for later expansion.
atUint32 reserved = readUint32();
uint32_t reserved = readUint32();
// Next we have to load the textures
// If we tried to add them one at a time to the sprite container
@ -63,7 +63,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
QList<Sakura::STexture*> textures;
#endif
for (atUint16 i = 0; i < textureCount; i++) {
for (uint16_t i = 0; i < textureCount; i++) {
Sakura::STexture* texture = new Sakura::STexture;
texture->Filepath = readString();
texture->Preload = readBool();
@ -84,7 +84,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
QMap<QString, Sakura::Sprite*> sprites;
#endif
for (atUint16 i = 0; i < spriteCount; i++) {
for (uint16_t i = 0; i < spriteCount; i++) {
Sakura::Sprite* sprite = new Sakura::Sprite(ret);
#ifndef ATHENA_USE_QT
std::string name = readString();
@ -92,8 +92,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
QString name = QString::fromStdString(readString());
#endif
sprite->setName(name);
atUint16 frameCount = readUint16();
atUint16 stateCount = readUint16();
uint16_t frameCount = readUint16();
uint16_t stateCount = readUint16();
// Each state id corresponds to a texture held in the parent class
std::vector<int> stateIds;
@ -116,10 +116,10 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
QList<Sakura::SpriteFrame*> frames;
#endif
for (atUint32 k = 0; k < frameCount; k++) {
for (uint32_t k = 0; k < frameCount; k++) {
Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite);
frame->setFrameTime(readFloat());
atUint16 partCount = readUint16();
uint16_t partCount = readUint16();
#ifndef ATHENA_USE_QT
std::vector<Sakura::SpritePart*> parts;
@ -127,7 +127,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
QList<Sakura::SpritePart*> parts;
#endif
for (atUint8 j = 0; j < partCount; j++) {
for (uint8_t j = 0; j < partCount; j++) {
Sakura::SpritePart* part = new Sakura::SpritePart(frame);
#ifndef ATHENA_USE_QT
std::string name = readString();
@ -143,8 +143,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile() {
float texXOff = readFloat();
float texYOff = readFloat();
part->setTextureOffset(texXOff, texYOff);
atUint32 width = readUint32();
atUint32 height = readUint32();
uint32_t width = readUint32();
uint32_t height = readUint32();
part->setSize(width, height);
bool flippedH = readBool();
part->setFlippedHorizontally(flippedH);

View File

@ -5,7 +5,7 @@
#include "athena/SpriteFrame.hpp"
namespace athena::io {
SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length) : MemoryCopyWriter(data, length) {}
SpriteFileWriter::SpriteFileWriter(uint8_t* data, uint64_t length) : MemoryCopyWriter(data, length) {}
SpriteFileWriter::SpriteFileWriter(std::string_view filepath) : MemoryCopyWriter(filepath) {}

View File

@ -14,7 +14,7 @@ void SpriteFrame::setParts(std::vector<SpritePart*> parts) { m_parts = parts; }
std::vector<SpritePart*> SpriteFrame::parts() const { return m_parts; }
atUint32 SpriteFrame::partCount() const { return (atUint32)m_parts.size(); }
uint32_t SpriteFrame::partCount() const { return (uint32_t)m_parts.size(); }
float SpriteFrame::frameTime() const { return m_frameTime; }

View File

@ -34,7 +34,7 @@ void SpritePart::setTextureOffset(const Vector2Df& offset) { m_textureOffset = o
Vector2Df SpritePart::textureOffset() const { return m_textureOffset; }
void SpritePart::setSize(atUint32 width, atUint32 height) { setSize(Vector2Di(width, height)); }
void SpritePart::setSize(uint32_t width, uint32_t height) { setSize(Vector2Di(width, height)); }
void SpritePart::setSize(const Vector2Di& size) { m_size = size; }

View File

@ -20,16 +20,16 @@
namespace athena::utility {
void fillRandom(atUint8* rndArea, atUint64 count) {
atUint8* buf = rndArea;
for (atUint64 i = 0; i < count / 4; i++) {
*(atUint32*)(buf) = rand();
void fillRandom(uint8_t* rndArea, uint64_t count) {
uint8_t* buf = rndArea;
for (uint64_t i = 0; i < count / 4; i++) {
*(uint32_t*)(buf) = rand();
buf += 4;
}
atUint64 rem = count % 4;
uint64_t rem = count % 4;
if (rem) {
for (atUint64 j = 0; j < rem; j++) {
for (uint64_t j = 0; j < rem; j++) {
*buf = rand();
buf++;
}
@ -113,14 +113,14 @@ int countChar(std::string_view str, const char chr, int* lastOccur) {
return ret;
}
atUint64 fileSize(std::string_view filename) {
uint64_t fileSize(std::string_view filename) {
atStat64_t st;
atStat64(filename.data(), &st);
return st.st_size;
}
#ifdef _WIN32
atUint64 fileSize(std::wstring_view filename) {
uint64_t fileSize(std::wstring_view filename) {
atStat64_t st;
_wstati64(filename.data(), &st);
return st.st_size;
@ -151,12 +151,12 @@ std::string& trim(std::string& s) {
return s;
}
atUint64 rand64() {
uint64_t rand64() {
// Combine 4 parts of low 16-bit of each rand()
atUint64 r0 = (atUint64)rand() << 48;
atUint64 r1 = (atUint64)rand() << 48 >> 16;
atUint64 r2 = (atUint64)rand() << 48 >> 32;
atUint64 r3 = (atUint64)rand() << 48 >> 48;
uint64_t r0 = (uint64_t)rand() << 48;
uint64_t r1 = (uint64_t)rand() << 48 >> 16;
uint64_t r2 = (uint64_t)rand() << 48 >> 32;
uint64_t r3 = (uint64_t)rand() << 48 >> 48;
return r0 | r1 | r2 | r3;
}

View File

@ -6,7 +6,7 @@
namespace athena::io {
void VectorWriter::seek(atInt64 position, SeekOrigin origin) {
void VectorWriter::seek(int64_t position, SeekOrigin origin) {
switch (origin) {
case SeekOrigin::Begin:
if (position < 0) {
@ -15,14 +15,14 @@ void VectorWriter::seek(atInt64 position, SeekOrigin origin) {
return;
}
if ((atUint64)position > m_data.size())
if ((uint64_t)position > m_data.size())
m_data.resize(position);
m_position = position;
break;
case SeekOrigin::Current:
if ((((atInt64)m_position + position) < 0)) {
if ((((int64_t)m_position + position) < 0)) {
atError("Position outside stream bounds");
setError();
return;
@ -35,13 +35,13 @@ void VectorWriter::seek(atInt64 position, SeekOrigin origin) {
break;
case SeekOrigin::End:
if (((atInt64)m_data.size() - position) < 0) {
if (((int64_t)m_data.size() - position) < 0) {
atError("Position outside stream bounds");
setError();
return;
}
if ((atUint64)position > m_data.size()) {
if ((uint64_t)position > m_data.size()) {
atError("data exceeds vector size");
setError();
return;
@ -52,7 +52,7 @@ void VectorWriter::seek(atInt64 position, SeekOrigin origin) {
}
}
void VectorWriter::writeUBytes(const atUint8* data, atUint64 length) {
void VectorWriter::writeUBytes(const uint8_t* data, uint64_t length) {
if (!data) {
atError("data cannnot be NULL");
setError();
@ -61,7 +61,7 @@ void VectorWriter::writeUBytes(const atUint8* data, atUint64 length) {
if (m_position < m_data.size()) {
size_t delta = std::min(m_data.size() - m_position, length);
memmove(reinterpret_cast<atInt8*>(&m_data[m_position]), data, delta);
memmove(reinterpret_cast<int8_t*>(&m_data[m_position]), data, delta);
data += delta;
length -= delta;
m_position += delta;
@ -70,7 +70,7 @@ void VectorWriter::writeUBytes(const atUint8* data, atUint64 length) {
if (length != 0) {
size_t insertPos = m_data.size();
m_data.resize(insertPos + length);
memmove(reinterpret_cast<atInt8*>(&m_data[insertPos]), data, length);
memmove(reinterpret_cast<int8_t*>(&m_data[insertPos]), data, length);
m_position += length;
}
}

View File

@ -8,7 +8,7 @@ namespace athena {
WiiBanner::WiiBanner() : m_gameId(0), m_banner(NULL), m_flags(0), m_bannerSize(0) {}
WiiBanner::WiiBanner(atUint32 gameId, const std::u16string& title, const std::u16string& subtitle, WiiImage* banner,
WiiBanner::WiiBanner(uint32_t gameId, const std::u16string& title, const std::u16string& subtitle, WiiImage* banner,
std::vector<WiiImage*> icons)
: m_gameId(gameId)
, m_banner(banner)
@ -23,9 +23,9 @@ WiiBanner::~WiiBanner() {
m_icons.clear();
}
void WiiBanner::setGameID(atUint64 id) { m_gameId = id; }
void WiiBanner::setGameID(uint64_t id) { m_gameId = id; }
atUint64 WiiBanner::gameID() const { return m_gameId; }
uint64_t WiiBanner::gameID() const { return m_gameId; }
void WiiBanner::setTitle(const std::u16string& title) { m_title = title; }
const std::u16string& WiiBanner::title() const { return m_title; }
@ -36,14 +36,14 @@ const std::u16string& WiiBanner::subtitle() const { return m_subtitle; }
void WiiBanner::addIcon(WiiImage* icon) { m_icons.push_back(icon); }
void WiiBanner::setIcon(atUint32 id, WiiImage* icon) {
void WiiBanner::setIcon(uint32_t id, WiiImage* icon) {
if (m_icons[id] != NULL) {
delete m_icons[id];
m_icons[id] = icon;
}
}
WiiImage* WiiBanner::getIcon(atUint32 id) const {
WiiImage* WiiBanner::getIcon(uint32_t id) const {
if (!m_icons[id])
return NULL;
@ -55,20 +55,20 @@ void WiiBanner::setBannerImage(WiiImage* banner) { m_banner = banner; }
WiiImage* WiiBanner::bannerImage() const { return m_banner; }
void WiiBanner::setAnimationSpeed(atUint16 animSpeed) { m_animSpeed = animSpeed; }
void WiiBanner::setAnimationSpeed(uint16_t animSpeed) { m_animSpeed = animSpeed; }
atUint16 WiiBanner::animationSpeed() const { return m_animSpeed; }
uint16_t WiiBanner::animationSpeed() const { return m_animSpeed; }
void WiiBanner::setPermissions(atUint8 permissions) { m_permissions = permissions; }
void WiiBanner::setPermissions(uint8_t permissions) { m_permissions = permissions; }
atUint8 WiiBanner::permissions() const { return m_permissions; }
uint8_t WiiBanner::permissions() const { return m_permissions; }
void WiiBanner::setBannerSize(atUint32 size) { m_bannerSize = size; }
void WiiBanner::setBannerSize(uint32_t size) { m_bannerSize = size; }
atUint32 WiiBanner::bannerSize() const { return m_bannerSize; }
uint32_t WiiBanner::bannerSize() const { return m_bannerSize; }
void WiiBanner::setFlags(atUint32 flags) { m_flags = flags; }
void WiiBanner::setFlags(uint32_t flags) { m_flags = flags; }
atUint32 WiiBanner::flags() const { return m_flags; }
uint32_t WiiBanner::flags() const { return m_flags; }
} // namespace athena

View File

@ -25,13 +25,13 @@ WiiFile::WiiFile(const std::string& filename)
, m_fileData(NULL)
, m_parent(NULL) {}
WiiFile::WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length)
WiiFile::WiiFile(const std::string& filename, uint8_t permissions, const uint8_t* data, uint32_t length)
: m_permissions(permissions)
, m_attributes(0)
, m_type(WiiFile::File)
, m_filename(filename)
, m_fileLen(length)
, m_fileData((atUint8*)data) {}
, m_fileData((uint8_t*)data) {}
WiiFile::~WiiFile() {
if (m_fileData)
@ -45,28 +45,28 @@ void WiiFile::setFilename(const std::string& filename) { m_filename = filename;
std::string WiiFile::filename() const { return m_filename; }
void WiiFile::setPermissions(const atUint8 permissions) { m_permissions = (atUint8)permissions; }
void WiiFile::setPermissions(const uint8_t permissions) { m_permissions = (uint8_t)permissions; }
atUint8 WiiFile::permissions() const { return m_permissions; }
uint8_t WiiFile::permissions() const { return m_permissions; }
void WiiFile::setData(const atUint8* data) {
void WiiFile::setData(const uint8_t* data) {
if (m_fileData) {
delete[] m_fileData;
m_fileData = NULL;
}
m_fileData = (atUint8*)data;
m_fileData = (uint8_t*)data;
}
atUint8* WiiFile::data() const { return m_fileData; }
uint8_t* WiiFile::data() const { return m_fileData; }
void WiiFile::setLength(const int len) { m_fileLen = (int)len; }
int WiiFile::length() const { return m_fileLen; }
void WiiFile::setAttributes(const atUint8 attr) { m_attributes = attr; }
void WiiFile::setAttributes(const uint8_t attr) { m_attributes = attr; }
atUint8 WiiFile::attributes() const { return m_attributes; }
uint8_t WiiFile::attributes() const { return m_attributes; }
void WiiFile::setType(WiiFile::Type type) { m_type = type; }
@ -88,14 +88,14 @@ void WiiFile::addChild(WiiFile* file) {
// Lets figure out it's place
std::string tmpName(file->filename());
// Since we only support *NIX paths this is simple
atUint32 depth = athena::utility::countChar(tmpName, '/');
uint32_t depth = athena::utility::countChar(tmpName, '/');
bool owned = false;
while ((depth--) > 0) {
// add them from the beginning of the path up
tmpName = tmpName.substr(0, tmpName.find('/'));
for (atUint32 i = 0; i < m_children.size(); i++) {
for (uint32_t i = 0; i < m_children.size(); i++) {
if (m_children[i]->filename() == tmpName) {
std::string newName = file->filename();
newName = newName.substr(newName.rfind("/") + 1, newName.size() - newName.rfind("/"));
@ -154,7 +154,7 @@ void WiiFile::setParent(WiiFile* parent) {
m_parent->addChild(this);
}
atUint32 WiiFile::fileCount() {
uint32_t WiiFile::fileCount() {
size_t ret = m_children.size();
for (WiiFile* f : m_children) {
@ -164,7 +164,7 @@ atUint32 WiiFile::fileCount() {
ret += f->fileCount();
}
return (atUint32)ret;
return (uint32_t)ret;
}
std::vector<WiiFile*> WiiFile::allChildren() {

View File

@ -5,22 +5,22 @@
namespace athena {
WiiImage::WiiImage(atUint32 width, atUint32 height, std::unique_ptr<atUint8[]>&& data)
WiiImage::WiiImage(uint32_t width, uint32_t height, std::unique_ptr<uint8_t[]>&& data)
: m_width(width), m_height(height), m_data(std::move(data)) {}
atUint8* WiiImage::data() { return m_data.get(); }
uint8_t* WiiImage::data() { return m_data.get(); }
atUint32 WiiImage::width() const { return m_width; }
uint32_t WiiImage::width() const { return m_width; }
atUint32 WiiImage::height() const { return m_height; }
uint32_t WiiImage::height() const { return m_height; }
atUint8* WiiImage::toRGBA() {
atUint32 x, y;
atUint32 x1, y1;
atUint32 iv;
atUint8* bitmapdata = NULL;
uint8_t* WiiImage::toRGBA() {
uint32_t x, y;
uint32_t x1, y1;
uint32_t iv;
uint8_t* bitmapdata = NULL;
bitmapdata = new atUint8[m_width * m_height * 4];
bitmapdata = new uint8_t[m_width * m_height * 4];
if (bitmapdata == NULL)
return NULL;
@ -29,27 +29,27 @@ atUint8* WiiImage::toRGBA() {
for (x1 = 0; x1 < m_width; x1 += 4) {
for (y = y1; y < (y1 + 4); y++) {
for (x = x1; x < (x1 + 4); x++) {
atUint16 oldpixel = *(atUint16*)(m_data.get() + ((iv++) * 2));
uint16_t oldpixel = *(uint16_t*)(m_data.get() + ((iv++) * 2));
// if((x >= m_width) || (y >= m_height))
// continue;
oldpixel = utility::swapU16(oldpixel);
if (oldpixel & (1 << 15)) {
// RGB5
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;
uint8_t b = (((oldpixel >> 10) & 0x1F) * 255) / 31;
uint8_t g = (((oldpixel >> 5) & 0x1F) * 255) / 31;
uint8_t r = (((oldpixel >> 0) & 0x1F) * 255) / 31;
uint8_t a = 255;
uint8_t rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
(*(uint32_t**)&bitmapdata)[x + (y * m_width)] = rgba;
} else {
// RGB4A3
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;
uint8_t a = (((oldpixel >> 12) & 0x7) * 255) / 7;
uint8_t b = (((oldpixel >> 8) & 0xF) * 255) / 15;
uint8_t g = (((oldpixel >> 4) & 0xF) * 255) / 15;
uint8_t r = (((oldpixel >> 0) & 0xF) * 255) / 15;
uint32_t rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
(*(uint32_t**)&bitmapdata)[x + (y * m_width)] = rgba;
}
}
}

View File

@ -47,7 +47,7 @@ WiiFile* WiiSave::file(const std::string& filepath) {
return m_root->child(cleanPath);
}
atUint32 WiiSave::fileCount() const { return m_root->fileCount(); }
uint32_t WiiSave::fileCount() const { return m_root->fileCount(); }
WiiFile* WiiSave::root() { return m_root; }

View File

@ -17,7 +17,7 @@ namespace athena {
namespace io {
WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {
WiiSaveReader::WiiSaveReader(const uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {
setEndian(Endian::Big);
}
@ -39,14 +39,14 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave() {
}
ret->setBanner(banner);
atUint32 bkVer = readUint32();
uint32_t bkVer = readUint32();
if (bkVer != 0x00000070) {
atError("Invalid BacKup header size");
return nullptr;
}
atUint32 bkMagic = readUint32();
uint32_t bkMagic = readUint32();
if (bkMagic != 0x426B0001) {
atError("Invalid BacKup header magic");
@ -54,12 +54,12 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave() {
}
/*atUint32 ngId =*/readUint32();
atUint32 numFiles = readUint32();
uint32_t numFiles = readUint32();
/*int fileSize =*/readUint32();
seek(8); // skip unknown data;
atUint32 totalSize = readUint32();
uint32_t totalSize = readUint32();
seek(64); // Unknown (Most likely padding)
seek(8);
seek(6);
@ -68,7 +68,7 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave() {
std::vector<WiiFile*> files;
for (atUint32 i = 0; i < numFiles; ++i) {
for (uint32_t i = 0; i < numFiles; ++i) {
WiiFile* file = readFile();
if (file)
@ -82,18 +82,18 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave() {
}
WiiBanner* WiiSaveReader::readBanner() {
atUint8* dec = new atUint8[0xF0C0];
uint8_t* dec = new uint8_t[0xF0C0];
memset(dec, 0, 0xF0C0);
std::unique_ptr<atUint8[]> buf = readUBytes(0xF0C0);
atUint8* oldData = data();
atUint64 oldPos = position();
atUint64 oldLen = length();
atUint64 gameId;
atUint32 bannerSize;
atUint8 permissions;
atUint8 md5[16];
atUint8 md5Calc[16];
atUint8 tmpIV[16];
std::unique_ptr<uint8_t[]> buf = readUBytes(0xF0C0);
uint8_t* oldData = data();
uint64_t oldPos = position();
uint64_t oldLen = length();
uint64_t gameId;
uint32_t bannerSize;
uint8_t permissions;
uint8_t md5[16];
uint8_t md5Calc[16];
uint8_t tmpIV[16];
memcpy(tmpIV, SD_IV, 16);
std::cout << "Decrypting: banner.bin...";
@ -210,24 +210,24 @@ WiiBanner* WiiSaveReader::readBanner() {
return banner;
}
WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height) {
std::unique_ptr<atUint8[]> image = readUBytes(width * height * 2);
WiiImage* WiiSaveReader::readImage(uint32_t width, uint32_t height) {
std::unique_ptr<uint8_t[]> image = readUBytes(width * height * 2);
if (!utility::isEmpty((atInt8*)image.get(), width * height * 2))
if (!utility::isEmpty((int8_t*)image.get(), width * height * 2))
return new WiiImage(width, height, std::move(image));
return NULL;
}
WiiFile* WiiSaveReader::readFile() {
atUint32 fileLen;
atUint8 permissions;
atUint8 attributes;
atUint8 type;
uint32_t fileLen;
uint8_t permissions;
uint8_t attributes;
uint8_t type;
std::string name;
WiiFile* ret;
atUint32 magic = readUint32();
uint32_t magic = readUint32();
if (magic != 0x03adf17e) {
std::cerr << "Not a valid File entry header: 0x" << std::hex << magic << std::endl;
@ -243,17 +243,17 @@ WiiFile* WiiSaveReader::readFile() {
ret->setPermissions(permissions);
ret->setAttributes(attributes);
ret->setType((WiiFile::Type)type);
std::unique_ptr<atUint8[]> iv = readUBytes(0x10);
std::unique_ptr<uint8_t[]> iv = readUBytes(0x10);
seek(0x20);
if (type == WiiFile::File) {
// Read file data
int roundedLen = (fileLen + 63) & ~63;
std::unique_ptr<atUint8[]> filedata = readUBytes(roundedLen);
std::unique_ptr<uint8_t[]> filedata = readUBytes(roundedLen);
// Decrypt file
std::cout << "Decrypting: " << ret->filename() << "...";
atUint8* decData = new atUint8[roundedLen];
uint8_t* decData = new uint8_t[roundedLen];
std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY);
aes->decrypt(iv.get(), filedata.get(), decData, roundedLen);
@ -265,19 +265,19 @@ WiiFile* WiiSaveReader::readFile() {
return ret;
}
void WiiSaveReader::readCerts(atUint32 totalSize) {
void WiiSaveReader::readCerts(uint32_t totalSize) {
std::cout << "Reading certs..." << std::endl;
atUint32 dataSize = totalSize - 0x340;
std::unique_ptr<atUint8[]> sig = readUBytes(0x40);
std::unique_ptr<atUint8[]> ngCert = readUBytes(0x180);
std::unique_ptr<atUint8[]> apCert = readUBytes(0x180);
uint32_t dataSize = totalSize - 0x340;
std::unique_ptr<uint8_t[]> sig = readUBytes(0x40);
std::unique_ptr<uint8_t[]> ngCert = readUBytes(0x180);
std::unique_ptr<uint8_t[]> apCert = readUBytes(0x180);
seek(0xF0C0, SeekOrigin::Begin);
std::unique_ptr<atUint8[]> data = readUBytes(dataSize);
atUint8* hash;
std::unique_ptr<uint8_t[]> data = readUBytes(dataSize);
uint8_t* hash;
std::cout << "validating..." << std::endl;
hash = getSha1(data.get(), dataSize);
atUint8* hash2 = getSha1(hash, 20);
uint8_t* hash2 = getSha1(hash, 20);
bool ngValid = false;
bool apValid = false;
ecc::checkEC(ngCert.get(), apCert.get(), sig.get(), hash2, apValid, ngValid);

View File

@ -27,8 +27,8 @@ namespace io {
WiiSaveWriter::WiiSaveWriter(const std::string& filename) : MemoryCopyWriter(filename) { setEndian(Endian::Big); }
bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig,
atUint32 ngKeyId, const std::string& filepath) {
bool WiiSaveWriter::writeSave(WiiSave* save, uint8_t* macAddress, uint32_t ngId, uint8_t* ngPriv, uint8_t* ngSig,
uint32_t ngKeyId, const std::string& filepath) {
if (!save) {
atError("save cannot be NULL");
return false;
@ -48,16 +48,16 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
writeUint32(0); // totalSize
seek(64);
writeUint64(save->banner()->gameID());
writeBytes((atInt8*)macAddress, 6);
writeBytes((int8_t*)macAddress, 6);
seek(2); // unknown;
seek(0x10); // padding;
atUint32 totalSize = 0;
uint32_t totalSize = 0;
for (WiiFile* file : save->allFiles()) {
totalSize += writeFile(file);
}
atUint64 pos = position();
uint64_t pos = position();
// Write size data
seek(0xF0C0 + 0x10, SeekOrigin::Begin);
writeUint32(totalSize);
@ -75,10 +75,10 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
void WiiSaveWriter::writeBanner(WiiBanner* banner) {
setEndian(Endian::Big);
writeInt64(banner->gameID());
writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size());
writeByte((atInt8)banner->permissions());
writeInt32((0x60a0 + 0x1200) * (uint32_t)banner->icons().size());
writeByte((int8_t)banner->permissions());
seek(1);
writeBytes((atInt8*)MD5_BLANKER, 16);
writeBytes((int8_t*)MD5_BLANKER, 16);
seek(2);
writeInt32(0x5749424E); // WIBN
writeInt32(banner->flags());
@ -100,42 +100,42 @@ void WiiSaveWriter::writeBanner(WiiBanner* banner) {
seek(0x00C0, SeekOrigin::Begin);
WiiImage* bannerImage = banner->bannerImage();
writeBytes((atInt8*)bannerImage->data(), bannerImage->width() * bannerImage->height() * 2);
writeBytes((int8_t*)bannerImage->data(), bannerImage->width() * bannerImage->height() * 2);
// For empty icons
atUint8* tmpIcon = new atUint8[48 * 48 * 2];
uint8_t* tmpIcon = new uint8_t[48 * 48 * 2];
memset(tmpIcon, 0, 48 * 48 * 2);
for (atUint32 i = 0; i < 8; ++i) {
for (uint32_t i = 0; i < 8; ++i) {
if (i < banner->icons().size()) {
writeImage(banner->icons()[i]);
} else {
writeBytes((atInt8*)tmpIcon, 48 * 48 * 2);
writeBytes((int8_t*)tmpIcon, 48 * 48 * 2);
}
}
delete[] tmpIcon; // delete tmp buffer;
atUint8* hash = new atUint8[0x10];
MD5Hash::MD5(hash, (atUint8*)data(), 0xF0C0);
uint8_t* hash = new uint8_t[0x10];
MD5Hash::MD5(hash, (uint8_t*)data(), 0xF0C0);
seek(0x0E, SeekOrigin::Begin);
writeBytes((atInt8*)hash, 0x10);
writeBytes((int8_t*)hash, 0x10);
std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY);
atUint8 data[0xF0C0];
uint8_t data[0xF0C0];
memcpy(data, this->data(), 0xF0C0);
atUint8 tmpIV[26];
uint8_t tmpIV[26];
memcpy(tmpIV, SD_IV, 16);
aes->encrypt(tmpIV, data, data, 0xF0C0);
seek(0, SeekOrigin::Begin);
writeBytes((atInt8*)data, 0xF0C0);
writeBytes((int8_t*)data, 0xF0C0);
seek(0xF0C0, SeekOrigin::Begin);
}
atUint32 WiiSaveWriter::writeFile(WiiFile* file) {
atUint32 ret = 0x80;
uint32_t WiiSaveWriter::writeFile(WiiFile* file) {
uint32_t ret = 0x80;
// Write the File magic
writeUint32(0x03ADF17E);
@ -144,28 +144,28 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file) {
writeByte(file->attributes());
writeByte(file->type());
atUint8 name[0x45];
uint8_t name[0x45];
utility::fillRandom(name, 0x45);
memcpy(name, file->fullpath().c_str(), file->fullpath().size());
name[file->fullpath().size()] = '\0';
writeBytes((atInt8*)name, 0x45);
atUint8 iv[16];
writeBytes((int8_t*)name, 0x45);
uint8_t iv[16];
utility::fillRandom(iv, 0x10);
writeBytes((atInt8*)iv, 0x10);
atUint8 crap[0x20];
writeBytes((int8_t*)iv, 0x10);
uint8_t crap[0x20];
utility::fillRandom(crap, 0x20);
writeBytes((atInt8*)crap, 0x20);
writeBytes((int8_t*)crap, 0x20);
if (file->type() == WiiFile::File) {
int roundedSize = (file->length() + 63) & ~63;
atUint8* data = new atUint8[roundedSize];
uint8_t* data = new uint8_t[roundedSize];
memset(data, 0, roundedSize);
std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY);
aes->encrypt(iv, file->data(), data, roundedSize);
writeBytes((atInt8*)data, roundedSize);
writeBytes((int8_t*)data, roundedSize);
ret += roundedSize;
delete[] data;
}
@ -174,21 +174,21 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file) {
}
void WiiSaveWriter::writeImage(WiiImage* image) {
atInt8* data = (atInt8*)image->data();
int8_t* data = (int8_t*)image->data();
writeBytes(data, image->width() * image->height() * 2);
}
void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId) {
atUint8 sig[0x40];
atUint8 ngCert[0x180];
atUint8 apCert[0x180];
atUint8* hash;
atUint8 apPriv[30];
atUint8 apSig[60];
void WiiSaveWriter::writeCerts(uint32_t filesSize, uint32_t ngId, uint8_t* ngPriv, uint8_t* ngSig, uint32_t ngKeyId) {
uint8_t sig[0x40];
uint8_t ngCert[0x180];
uint8_t apCert[0x180];
uint8_t* hash;
uint8_t apPriv[30];
uint8_t apSig[60];
char signer[64];
char name[64];
atUint8* buf;
atUint32 dataSize;
uint8_t* buf;
uint32_t dataSize;
sprintf(signer, "Root-CA00000001-MS00000002");
sprintf(name, "NG%08x", ngId);
@ -209,12 +209,12 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
delete[] hash;
dataSize = filesSize + 0x80;
buf = new atUint8[dataSize];
atUint8* rawData = data();
buf = new uint8_t[dataSize];
uint8_t* rawData = data();
memcpy(buf, rawData + 0xF0C0, dataSize);
hash = getSha1(buf, dataSize);
atUint8* hash2 = getSha1(hash, 20);
uint8_t* hash2 = getSha1(hash, 20);
delete[] hash;
delete[] buf;
@ -224,12 +224,12 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
if (!utility::isSystemBigEndian())
stuff = utility::swap32(stuff);
*(atUint32*)(sig + 60) = stuff;
*(uint32_t*)(sig + 60) = stuff;
delete[] hash2;
writeBytes((atInt8*)sig, 0x40);
writeBytes((atInt8*)ngCert, 0x180);
writeBytes((atInt8*)apCert, 0x180);
writeBytes((int8_t*)sig, 0x40);
writeBytes((int8_t*)ngCert, 0x180);
writeBytes((int8_t*)apCert, 0x180);
}
} // namespace io

View File

@ -27,17 +27,17 @@ void initGameStrings() {
GameStrings.push_back("A Link Between Worlds");
}
const atUint32 ZQuestFile::Major = 2;
const atUint32 ZQuestFile::Minor = 0;
const atUint32 ZQuestFile::Revision = 0;
const uint32_t ZQuestFile::Major = 2;
const uint32_t ZQuestFile::Minor = 0;
const uint32_t ZQuestFile::Revision = 0;
const atUint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
const uint32_t ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
const atUint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
const uint32_t ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
ZQuestFile::ZQuestFile() : m_game(NoGame), m_endian(Endian::Little), m_length(0) { initGameStrings(); }
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, std::unique_ptr<atUint8[]>&& data, atUint32 length,
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, std::unique_ptr<uint8_t[]>&& data, uint32_t length,
const std::string& gameString)
: m_game(game), m_gameString(gameString), m_endian(endian), m_data(std::move(data)), m_length(length) {
initGameStrings();
@ -61,14 +61,14 @@ void ZQuestFile::setEndian(Endian endian) { m_endian = endian; }
Endian ZQuestFile::endian() const { return m_endian; }
void ZQuestFile::setData(std::unique_ptr<atUint8[]>&& data, atUint32 length) {
void ZQuestFile::setData(std::unique_ptr<uint8_t[]>&& data, uint32_t length) {
m_data = std::move(data);
m_length = length;
}
atUint8* ZQuestFile::data() const { return m_data.get(); }
uint8_t* ZQuestFile::data() const { return m_data.get(); }
atUint32 ZQuestFile::length() const { return m_length; }
uint32_t ZQuestFile::length() const { return m_length; }
void ZQuestFile::setGameString(const std::string& gameString) { m_gameString = gameString; }

View File

@ -9,16 +9,16 @@
namespace athena::io {
ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length) : MemoryCopyReader(data, length) {}
ZQuestFileReader::ZQuestFileReader(uint8_t* data, uint64_t length) : MemoryCopyReader(data, length) {}
ZQuestFileReader::ZQuestFileReader(const std::string& filename) : MemoryCopyReader(filename) {}
ZQuestFile* ZQuestFileReader::read() {
atUint32 magic, version, compressedLen, uncompressedLen;
uint32_t magic, version, compressedLen, uncompressedLen;
ZQuestFile::Game game = ZQuestFile::NoGame;
std::string gameString;
atUint16 BOM;
atUint32 checksum = 0;
uint16_t BOM;
uint32_t checksum = 0;
magic = readUint32();
@ -56,7 +56,7 @@ ZQuestFile* ZQuestFileReader::read() {
seek(0x0A);
}
std::unique_ptr<atUint8[]> data = readUBytes(compressedLen); // compressedLen is always the total file size
std::unique_ptr<uint8_t[]> data = readUBytes(compressedLen); // compressedLen is always the total file size
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0)) {
if (checksum != athena::checksums::crc32(data.get(), compressedLen)) {
@ -70,8 +70,8 @@ ZQuestFile* ZQuestFileReader::read() {
}
if (compressedLen != uncompressedLen) {
atUint8* dst = new atUint8[uncompressedLen];
atUint32 dstLen = io::Compression::decompressZlib(data.get(), compressedLen, dst, uncompressedLen);
uint8_t* dst = new uint8_t[uncompressedLen];
uint32_t dstLen = io::Compression::decompressZlib(data.get(), compressedLen, dst, uncompressedLen);
if (dstLen != uncompressedLen) {
delete[] dst;

View File

@ -5,7 +5,7 @@
namespace athena::io {
ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length) : MemoryCopyWriter(data, length) {}
ZQuestFileWriter::ZQuestFileWriter(uint8_t* data, uint64_t length) : MemoryCopyWriter(data, length) {}
ZQuestFileWriter::ZQuestFileWriter(const std::string& filename) : MemoryCopyWriter(filename) {}
@ -17,12 +17,12 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) {
writeUint32(ZQuestFile::Magic);
writeUint32(ZQuestFile::Version);
atUint8* questData = quest->data();
atUint32 compLen;
uint8_t* questData = quest->data();
uint32_t compLen;
if (compress) {
atUint8* compData =
new atUint8[quest->length() + 0x40]; // add 20 bytes because sometimes the file grows with compression
uint8_t* compData =
new uint8_t[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);
@ -44,7 +44,7 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress) {
}
writeUint32(quest->length());
writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
writeBytes((int8_t*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
writeUint16(quest->endian() == Endian::Big ? 0xFFFE : 0xFEFF);
writeUint32(athena::checksums::crc32(questData, compLen));
writeUBytes(questData, compLen);

View File

@ -5,21 +5,21 @@
namespace bignum {
void subModulus(atUint8* a, const atUint8* N, atUint32 n) {
atUint8 c = 0;
void subModulus(uint8_t* a, const uint8_t* N, uint32_t n) {
uint8_t c = 0;
for (atUint32 i = n - 1; i < n; i--) {
atUint32 dig = N[i] + c;
for (uint32_t i = n - 1; i < n; i--) {
uint32_t dig = N[i] + c;
c = (a[i] < dig);
a[i] -= dig;
}
}
void add(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n) {
atUint8 c = 0;
void add(uint8_t* d, uint8_t* a, const uint8_t* b, const uint8_t* N, uint32_t n) {
uint8_t c = 0;
for (atUint32 i = n - 1; i < n; i--) {
atUint32 dig = a[i] + b[i] + c;
for (uint32_t i = n - 1; i < n; i--) {
uint32_t dig = a[i] + b[i] + c;
c = (dig >= 0x100);
d[i] = dig;
}
@ -31,11 +31,11 @@ void add(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n)
subModulus(d, N, n);
}
void mul(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n) {
void mul(uint8_t* d, uint8_t* a, const uint8_t* b, const uint8_t* N, uint32_t n) {
memset(d, 0, n);
for (atUint32 i = 0; i < n; i++) {
for (atUint8 mask = 0x80; mask != 0; mask >>= 1) {
for (uint32_t i = 0; i < n; i++) {
for (uint8_t mask = 0x80; mask != 0; mask >>= 1) {
add(d, d, d, N, n);
if ((a[i] & mask) != 0)
@ -44,13 +44,13 @@ void mul(atUint8* d, atUint8* a, const atUint8* b, const atUint8* N, atUint32 n)
}
}
void exp(atUint8* d, const atUint8* a, const atUint8* N, atUint32 n, atUint8* e, atUint32 en) {
atUint8 t[512];
void exp(uint8_t* d, const uint8_t* a, const uint8_t* N, uint32_t n, uint8_t* e, uint32_t en) {
uint8_t t[512];
memset(d, 0, n);
d[n - 1] = 1;
for (atUint32 i = 0; i < en; i++) {
for (atUint8 mask = 0x80; mask != 0; mask >>= 1) {
for (uint32_t i = 0; i < en; i++) {
for (uint8_t mask = 0x80; mask != 0; mask >>= 1) {
mul(t, d, d, N, n);
if ((e[i] & mask) != 0)
@ -61,8 +61,8 @@ void exp(atUint8* d, const atUint8* a, const atUint8* N, atUint32 n, atUint8* e,
}
}
void inv(atUint8* d, atUint8* a, const atUint8* N, atUint32 n) {
atUint8 t[512], s[512];
void inv(uint8_t* d, uint8_t* a, const uint8_t* N, uint32_t n) {
uint8_t t[512], s[512];
memcpy(t, N, n);
memset(s, 0, n);
@ -71,8 +71,8 @@ void inv(atUint8* d, atUint8* a, const atUint8* N, atUint32 n) {
exp(d, a, N, n, t, n);
}
int compare(const atUint8* a, const atUint8* b, atUint32 n) {
for (atUint32 i = 0; i < n; i++) {
int compare(const uint8_t* a, const uint8_t* b, uint32_t n) {
for (uint32_t i = 0; i < n; i++) {
if (a[i] < b[i])
return -1;

View File

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

View File

@ -334,15 +334,15 @@ void SHA1PadMessage(SHA1Context* context) {
SHA1ProcessMessageBlock(context);
}
atUint8* getSha1(atUint8* stuff, atUint32 stuff_size) {
uint8_t* getSha1(uint8_t* stuff, uint32_t stuff_size) {
SHA1Context sha;
SHA1Reset(&sha);
SHA1Input(&sha, (const atUint8*)stuff, stuff_size);
SHA1Input(&sha, (const uint8_t*)stuff, stuff_size);
if (!SHA1Result(&sha))
return 0;
atUint8* ret = new atUint8[20];
uint8_t* ret = new uint8_t[20];
memset(ret, 0, 20);
for (int i = 0; i < 5; i++) {