mirror of https://github.com/libAthena/athena.git
* Rename datatypes to prevent collision
This commit is contained in:
parent
cc71bec5d7
commit
5f74cdb9ed
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -59,7 +60,7 @@ public:
|
||||||
* \param val The new quest to assign to the given index
|
* \param val The new quest to assign to the given index
|
||||||
* \throw InvalidOperationException on index out of range
|
* \throw InvalidOperationException on index out of range
|
||||||
*/
|
*/
|
||||||
void setQuest(Uint32 id, ALTTPQuest* val);
|
void setQuest(atUint32 id, ALTTPQuest* val);
|
||||||
/*! \brief Returns the primary quest list
|
/*! \brief Returns the primary quest list
|
||||||
*
|
*
|
||||||
* \return The primary quest list
|
* \return The primary quest list
|
||||||
|
@ -73,13 +74,13 @@ public:
|
||||||
* \return ALTTPQuest*
|
* \return ALTTPQuest*
|
||||||
* \throw InvalidOperationException on index out of range
|
* \throw InvalidOperationException on index out of range
|
||||||
*/
|
*/
|
||||||
ALTTPQuest* quest(Uint32 id) const;
|
ALTTPQuest* quest(atUint32 id) const;
|
||||||
|
|
||||||
/*! \brief Returns the number of primary quests
|
/*! \brief Returns the number of primary quests
|
||||||
*
|
*
|
||||||
* \return The number of quests
|
* \return The number of quests
|
||||||
*/
|
*/
|
||||||
Uint32 questCount() const;
|
atUint32 questCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -89,3 +90,4 @@ private:
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // __ALTTP_FILE_HPP__
|
#endif // __ALTTP_FILE_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -44,7 +45,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
ALTTPFileReader(Uint8*, Uint64);
|
ALTTPFileReader(atUint8*, atUint64);
|
||||||
|
|
||||||
/*! \brief This constructor creates an instance from a file on disk.
|
/*! \brief This constructor creates an instance from a file on disk.
|
||||||
*
|
*
|
||||||
|
@ -66,3 +67,4 @@ private:
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // __ALTTP_FILE_READER_HPP__
|
#endif // __ALTTP_FILE_READER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
ALTTPFileWriter(Uint8*, Uint64);
|
ALTTPFileWriter(atUint8*, atUint64);
|
||||||
|
|
||||||
/*! \brief This constructor creates an instance from a file on disk.
|
/*! \brief This constructor creates an instance from a file on disk.
|
||||||
*
|
*
|
||||||
|
@ -61,10 +62,11 @@ private:
|
||||||
void writeRoomFlags(ALTTPRoomFlags*);
|
void writeRoomFlags(ALTTPRoomFlags*);
|
||||||
void writeOverworldEvent(ALTTPOverworldEvent*);
|
void writeOverworldEvent(ALTTPOverworldEvent*);
|
||||||
void writeDungeonItems(ALTTPDungeonItemFlags);
|
void writeDungeonItems(ALTTPDungeonItemFlags);
|
||||||
Uint16 calculateChecksum(Uint32 game);
|
atUint16 calculateChecksum(atUint32 game);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __ALTTP_FILE_WRITER_HPP__
|
#endif // __ALTTP_FILE_WRITER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -51,7 +52,7 @@ public:
|
||||||
* \param rf
|
* \param rf
|
||||||
* \param id
|
* \param id
|
||||||
*/
|
*/
|
||||||
void setRoomFlags(ALTTPRoomFlags* rf, Uint32 id);
|
void setRoomFlags(ALTTPRoomFlags* rf, atUint32 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief roomFlags
|
* \brief roomFlags
|
||||||
|
@ -64,7 +65,7 @@ public:
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
ALTTPRoomFlags* roomFlags(Uint32 id);
|
ALTTPRoomFlags* roomFlags(atUint32 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setOverworldEvents
|
* \brief setOverworldEvents
|
||||||
|
@ -77,7 +78,7 @@ public:
|
||||||
* \param ow
|
* \param ow
|
||||||
* \param id
|
* \param id
|
||||||
*/
|
*/
|
||||||
void setOverworldEvents(ALTTPOverworldEvent* ow, Uint32 id);
|
void setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief overworldEvents
|
* \brief overworldEvents
|
||||||
|
@ -90,7 +91,7 @@ public:
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
ALTTPOverworldEvent* overworldEvent(Uint32 id) const;
|
ALTTPOverworldEvent* overworldEvent(atUint32 id) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setInventory
|
* \brief setInventory
|
||||||
|
@ -108,25 +109,25 @@ public:
|
||||||
* \brief setRupeeMax
|
* \brief setRupeeMax
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setRupeeMax(Uint16 val);
|
void setRupeeMax(atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief rupeeMax
|
* \brief rupeeMax
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 rupeeMax() const;
|
atUint16 rupeeMax() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setRupeeCurrent
|
* \brief setRupeeCurrent
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setRupeeCurrent(Uint16 val);
|
void setRupeeCurrent(atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief rupeeCurrent
|
* \brief rupeeCurrent
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 rupeeCurrent() const;
|
atUint16 rupeeCurrent() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setCompasses
|
* \brief setCompasses
|
||||||
|
@ -168,109 +169,109 @@ public:
|
||||||
* \brief setWishingPond
|
* \brief setWishingPond
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setWishingPond(Uint16 val);
|
void setWishingPond(atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief wishingPond
|
* \brief wishingPond
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 wishingPond() const;
|
atUint16 wishingPond() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setHealthMax
|
* \brief setHealthMax
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setHealthMax(Uint8 val);
|
void setHealthMax(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief healthMax
|
* \brief healthMax
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 healthMax() const;
|
atUint8 healthMax() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setHealth
|
* \brief setHealth
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setHealth(Uint8 val);
|
void setHealth(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief health
|
* \brief health
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 health() const;
|
atUint8 health() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setMagicPower
|
* \brief setMagicPower
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setMagicPower(Uint8 val);
|
void setMagicPower(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief magicPower
|
* \brief magicPower
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 magicPower() const;
|
atUint8 magicPower() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setKeys
|
* \brief setKeys
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setKeys(Uint8 val);
|
void setKeys(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief keys
|
* \brief keys
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 keys() const;
|
atUint8 keys() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setBombUpgrades
|
* \brief setBombUpgrades
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setBombUpgrades(Uint8 val);
|
void setBombUpgrades(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief bombUpgrades
|
* \brief bombUpgrades
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 bombUpgrades() const;
|
atUint8 bombUpgrades() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setArrowUpgrades
|
* \brief setArrowUpgrades
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setArrowUpgrades(Uint8 val);
|
void setArrowUpgrades(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief arrowUpgrades
|
* \brief arrowUpgrades
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 arrowUpgrades() const;
|
atUint8 arrowUpgrades() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setHealthFiller
|
* \brief setHealthFiller
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setHealthFiller(Uint8 val);
|
void setHealthFiller(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief healthFiller
|
* \brief healthFiller
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 healthFiller() const;
|
atUint8 healthFiller() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setMagicFiller
|
* \brief setMagicFiller
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setMagicFiller(Uint8 val);
|
void setMagicFiller(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief magicFiller
|
* \brief magicFiller
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 magicFiller() const;
|
atUint8 magicFiller() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setPendants
|
* \brief setPendants
|
||||||
|
@ -288,37 +289,37 @@ public:
|
||||||
* \brief setBombFiller
|
* \brief setBombFiller
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setBombFiller(Uint8 val);
|
void setBombFiller(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief bombFiller
|
* \brief bombFiller
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 bombFiller() const;
|
atUint8 bombFiller() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setArrowFiller
|
* \brief setArrowFiller
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setArrowFiller(Uint8 val);
|
void setArrowFiller(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief arrowFiller
|
* \brief arrowFiller
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 arrowFiller() const;
|
atUint8 arrowFiller() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setArrows
|
* \brief setArrows
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setArrows(Uint8 val);
|
void setArrows(atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief arrows
|
* \brief arrows
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 arrows() const;
|
atUint8 arrows() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setAbilityFlags
|
* \brief setAbilityFlags
|
||||||
|
@ -360,27 +361,27 @@ public:
|
||||||
* \brief setDungeonKeys
|
* \brief setDungeonKeys
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setDungeonKeys(std::vector<Uint8> val);
|
void setDungeonKeys(std::vector<atUint8> val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setDungeonKeys
|
* \brief setDungeonKeys
|
||||||
* \param id
|
* \param id
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setDungeonKeys(Uint32 id, Uint8 val);
|
void setDungeonKeys(atUint32 id, atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief dungeonKeys
|
* \brief dungeonKeys
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 dungeonKeys(Uint32 id) const;
|
atUint8 dungeonKeys(atUint32 id) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief dungeonCount
|
* \brief dungeonCount
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 dungeonCount() const;
|
atUint32 dungeonCount() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setProgressIndicator
|
* \brief setProgressIndicator
|
||||||
|
@ -470,71 +471,71 @@ public:
|
||||||
* \brief setOldManFlags
|
* \brief setOldManFlags
|
||||||
* \param flags
|
* \param flags
|
||||||
*/
|
*/
|
||||||
void setOldManFlags(std::vector<Uint8> flags);
|
void setOldManFlags(std::vector<atUint8> flags);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setOldManFlag
|
* \brief setOldManFlag
|
||||||
* \param id
|
* \param id
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setOldManFlag(Uint32 id, Uint8 val);
|
void setOldManFlag(atUint32 id, atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief oldManFlag
|
* \brief oldManFlag
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 oldManFlag(Uint32 id);
|
atUint8 oldManFlag(atUint32 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief oldManFlagCount
|
* \brief oldManFlagCount
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 oldManFlagCount() const;
|
atUint32 oldManFlagCount() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setBombFlag
|
* \brief setBombFlag
|
||||||
* \param flag
|
* \param flag
|
||||||
*/
|
*/
|
||||||
void setBombFlag(Uint8 flag);
|
void setBombFlag(atUint8 flag);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief bombFlag
|
* \brief bombFlag
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 bombFlag() const;
|
atUint8 bombFlag() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setUnknown1
|
* \brief setUnknown1
|
||||||
* \param flags
|
* \param flags
|
||||||
*/
|
*/
|
||||||
void setUnknown1(std::vector<Uint8> flags);
|
void setUnknown1(std::vector<atUint8> flags);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setUnknown1
|
* \brief setUnknown1
|
||||||
* \param id
|
* \param id
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setUnknown1(Uint32 id, Uint8 val);
|
void setUnknown1(atUint32 id, atUint8 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief unknown1
|
* \brief unknown1
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 unknown1(Uint32 id);
|
atUint8 unknown1(atUint32 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief unknown1Count
|
* \brief unknown1Count
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 unknown1Count() const;
|
atUint32 unknown1Count() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setPlayerName
|
* \brief setPlayerName
|
||||||
* \param playerName
|
* \param playerName
|
||||||
*/
|
*/
|
||||||
void setPlayerName(std::vector<Uint16> playerName);
|
void setPlayerName(std::vector<atUint16> playerName);
|
||||||
/*!
|
/*!
|
||||||
* \brief setPlayerName
|
* \brief setPlayerName
|
||||||
* \param playerName
|
* \param playerName
|
||||||
|
@ -544,7 +545,7 @@ public:
|
||||||
* \brief playerName
|
* \brief playerName
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
std::vector<Uint16> playerName() const;
|
std::vector<atUint16> playerName() const;
|
||||||
/*!
|
/*!
|
||||||
* \brief playerNameToString
|
* \brief playerNameToString
|
||||||
* \return
|
* \return
|
||||||
|
@ -567,101 +568,101 @@ public:
|
||||||
* \brief setDungeonDeathTotals
|
* \brief setDungeonDeathTotals
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setDungeonDeathTotals(std::vector<Uint16> val);
|
void setDungeonDeathTotals(std::vector<atUint16> val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setDungeonDeathTotal
|
* \brief setDungeonDeathTotal
|
||||||
* \param id
|
* \param id
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setDungeonDeathTotal(Uint32 id, Uint16 val);
|
void setDungeonDeathTotal(atUint32 id, atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief dungeonDeathTotal
|
* \brief dungeonDeathTotal
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 dungeonDeathTotal(Uint32 id) const;
|
atUint16 dungeonDeathTotal(atUint32 id) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief dungeonDeathTotalCount
|
* \brief dungeonDeathTotalCount
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 dungeonDeathTotalCount() const;
|
atUint16 dungeonDeathTotalCount() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setUnknown2
|
* \brief setUnknown2
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setUnknown2(Uint16 val);
|
void setUnknown2(atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief unknown2
|
* \brief unknown2
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 unknown2() const;
|
atUint16 unknown2() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setDeathSaveCount
|
* \brief setDeathSaveCount
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setDeathSaveCount(Uint16 val);
|
void setDeathSaveCount(atUint16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief deathSaveCount
|
* \brief deathSaveCount
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 deathSaveCount() const;
|
atUint16 deathSaveCount() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setPostGameDeathCounter
|
* \brief setPostGameDeathCounter
|
||||||
* \param val
|
* \param val
|
||||||
*/
|
*/
|
||||||
void setPostGameDeathCounter(Int16 val);
|
void setPostGameDeathCounter(atInt16 val);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief postGameDeathCounter
|
* \brief postGameDeathCounter
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Int16 postGameDeathCounter() const;
|
atInt16 postGameDeathCounter() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setChecksum
|
* \brief setChecksum
|
||||||
* \param checksum
|
* \param checksum
|
||||||
*/
|
*/
|
||||||
void setChecksum(Uint16 checksum);
|
void setChecksum(atUint16 checksum);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief checksum
|
* \brief checksum
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 checksum() const;
|
atUint16 checksum() const;
|
||||||
private:
|
private:
|
||||||
std::vector<ALTTPRoomFlags*> m_roomFlags;
|
std::vector<ALTTPRoomFlags*> m_roomFlags;
|
||||||
std::vector<ALTTPOverworldEvent*> m_overworldEvents;
|
std::vector<ALTTPOverworldEvent*> m_overworldEvents;
|
||||||
ALTTPInventory* m_inventory;
|
ALTTPInventory* m_inventory;
|
||||||
Uint16 m_rupeeMax;
|
atUint16 m_rupeeMax;
|
||||||
Uint16 m_rupeeCurrent;
|
atUint16 m_rupeeCurrent;
|
||||||
ALTTPDungeonItemFlags m_compasses;
|
ALTTPDungeonItemFlags m_compasses;
|
||||||
ALTTPDungeonItemFlags m_bigKeys;
|
ALTTPDungeonItemFlags m_bigKeys;
|
||||||
ALTTPDungeonItemFlags m_dungeonMaps;
|
ALTTPDungeonItemFlags m_dungeonMaps;
|
||||||
Uint16 m_wishingPond;
|
atUint16 m_wishingPond;
|
||||||
Uint8 m_healthMax;
|
atUint8 m_healthMax;
|
||||||
Uint8 m_health;
|
atUint8 m_health;
|
||||||
Uint8 m_magicPower;
|
atUint8 m_magicPower;
|
||||||
Uint8 m_keys;
|
atUint8 m_keys;
|
||||||
Uint8 m_bombUpgrades;
|
atUint8 m_bombUpgrades;
|
||||||
Uint8 m_arrowUpgrades;
|
atUint8 m_arrowUpgrades;
|
||||||
Uint8 m_heartFiller;
|
atUint8 m_heartFiller;
|
||||||
Uint8 m_magicFiller;
|
atUint8 m_magicFiller;
|
||||||
ALTTPPendants m_pendants;
|
ALTTPPendants m_pendants;
|
||||||
Uint8 m_bombFiller;
|
atUint8 m_bombFiller;
|
||||||
Uint8 m_arrowFiller;
|
atUint8 m_arrowFiller;
|
||||||
Uint8 m_arrows;
|
atUint8 m_arrows;
|
||||||
ALTTPAbilities m_abilityFlags;
|
ALTTPAbilities m_abilityFlags;
|
||||||
ALTTPCrystals m_crystals;
|
ALTTPCrystals m_crystals;
|
||||||
ALTTPMagicUsage m_magicUsage;
|
ALTTPMagicUsage m_magicUsage;
|
||||||
std::vector<Uint8> m_dungeonKeys;
|
std::vector<atUint8> m_dungeonKeys;
|
||||||
ALTTPProgressIndicator m_progressIndicator;
|
ALTTPProgressIndicator m_progressIndicator;
|
||||||
ALTTPProgressFlags1 m_progressFlags1;
|
ALTTPProgressFlags1 m_progressFlags1;
|
||||||
ALTTPMapIcon m_mapIcon;
|
ALTTPMapIcon m_mapIcon;
|
||||||
|
@ -669,18 +670,19 @@ private:
|
||||||
ALTTPProgressFlags2 m_progressFlags2;
|
ALTTPProgressFlags2 m_progressFlags2;
|
||||||
ALTTPLightDarkWorldIndicator m_lightDarkWorldIndicator;
|
ALTTPLightDarkWorldIndicator m_lightDarkWorldIndicator;
|
||||||
ALTTPTagAlong m_tagAlong;
|
ALTTPTagAlong m_tagAlong;
|
||||||
std::vector<Uint8> m_oldManFlags;
|
std::vector<atUint8> m_oldManFlags;
|
||||||
Uint8 m_bombFlag;
|
atUint8 m_bombFlag;
|
||||||
std::vector<Uint8> m_unknown1;
|
std::vector<atUint8> m_unknown1;
|
||||||
std::vector<Uint16> m_playerName;
|
std::vector<atUint16> m_playerName;
|
||||||
Uint16 m_valid;
|
atUint16 m_valid;
|
||||||
std::vector<Uint16> m_dungeonDeathTotals;
|
std::vector<atUint16> m_dungeonDeathTotals;
|
||||||
Uint16 m_unknown2;
|
atUint16 m_unknown2;
|
||||||
Uint16 m_deathSaveCount;
|
atUint16 m_deathSaveCount;
|
||||||
Int16 m_postGameDeathCounter;
|
atInt16 m_postGameDeathCounter;
|
||||||
Uint16 m_checksum;
|
atUint16 m_checksum;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __ALTTP_QUEST_HPP__
|
#endif // __ALTTP_QUEST_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
BinaryReader(const Uint8* data, Uint64 length);
|
BinaryReader(const atUint8* data, atUint64 length);
|
||||||
|
|
||||||
/*! \brief This constructor creates an instance from a file on disk.
|
/*! \brief This constructor creates an instance from a file on disk.
|
||||||
*
|
*
|
||||||
|
@ -85,7 +85,7 @@ public:
|
||||||
* \param position where in the buffer to seek
|
* \param position where in the buffer to seek
|
||||||
* \param origin The Origin to seek \sa SeekOrigin
|
* \param origin The Origin to seek \sa SeekOrigin
|
||||||
*/
|
*/
|
||||||
void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current);
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Returns whether or not the stream is at the end.
|
/*! \brief Returns whether or not the stream is at the end.
|
||||||
|
@ -98,13 +98,13 @@ public:
|
||||||
*
|
*
|
||||||
* \return Int64 The current position in the stream.
|
* \return Int64 The current position in the stream.
|
||||||
*/
|
*/
|
||||||
Uint64 position() const;
|
atUint64 position() const;
|
||||||
|
|
||||||
/*! \brief Returns whether or not the stream is at the end.
|
/*! \brief Returns whether or not the stream is at the end.
|
||||||
*
|
*
|
||||||
* \return bool True if at end; False otherwise.
|
* \return bool True if at end; False otherwise.
|
||||||
*/
|
*/
|
||||||
Uint64 length() const;
|
atUint64 length() const;
|
||||||
|
|
||||||
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
|
/*! \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
|
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
|
||||||
|
@ -115,7 +115,7 @@ public:
|
||||||
* \param length The length of the new buffer.
|
* \param length The length of the new buffer.
|
||||||
* \throw IOException
|
* \throw IOException
|
||||||
*/
|
*/
|
||||||
void setData(const Uint8* data, Uint64 length);
|
void setData(const atUint8* data, atUint64 length);
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Returns a copy of the current buffer.<br />
|
/*! \brief Returns a copy of the current buffer.<br />
|
||||||
|
@ -125,7 +125,7 @@ public:
|
||||||
* as Stream now owns the address, this is done to keep memory usage down.
|
* as Stream now owns the address, this is done to keep memory usage down.
|
||||||
* \return Uint8* The copy of the buffer.
|
* \return Uint8* The copy of the buffer.
|
||||||
*/
|
*/
|
||||||
Uint8* data() const;
|
atUint8* data() const;
|
||||||
|
|
||||||
/*! \brief Sets the target file
|
/*! \brief Sets the target file
|
||||||
*
|
*
|
||||||
|
@ -155,25 +155,25 @@ public:
|
||||||
*
|
*
|
||||||
* \return Int8 The value at the current position
|
* \return Int8 The value at the current position
|
||||||
*/
|
*/
|
||||||
Int8 readByte();
|
atInt8 readByte();
|
||||||
|
|
||||||
/*! \brief Reads a byte at the current position and advances the current position
|
/*! \brief Reads a byte at the current position and advances the current position
|
||||||
*
|
*
|
||||||
* \return Uint8 The value at the current position
|
* \return Uint8 The value at the current position
|
||||||
*/
|
*/
|
||||||
Uint8 readUByte();
|
atUint8 readUByte();
|
||||||
|
|
||||||
/*! \brief Reads a byte at the current position and advances the current position.
|
/*! \brief Reads a byte at the current position and advances the current position.
|
||||||
*
|
*
|
||||||
* \return Uint8* The buffer at the current position from the given length.
|
* \return Uint8* The buffer at the current position from the given length.
|
||||||
*/
|
*/
|
||||||
Int8* readBytes(Int64 length);
|
atInt8* readBytes(atInt64 length);
|
||||||
|
|
||||||
/*! \brief Reads a byte at the current position and advances the current position.
|
/*! \brief Reads a byte at the current position and advances the current position.
|
||||||
*
|
*
|
||||||
* \return Int8* The buffer at the current position from the given length.
|
* \return Int8* The buffer at the current position from the given length.
|
||||||
*/
|
*/
|
||||||
Uint8* readUBytes(Int64 length);
|
atUint8* readUBytes(atInt64 length);
|
||||||
|
|
||||||
/*! \brief Reads a Int16 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Int16 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -183,7 +183,7 @@ public:
|
||||||
* \return Int16 The value at the current address
|
* \return Int16 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Int16 readInt16();
|
atInt16 readInt16();
|
||||||
|
|
||||||
/*! \brief Reads a Uint16 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Uint16 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -193,7 +193,7 @@ public:
|
||||||
* \return Uint16 The value at the current address
|
* \return Uint16 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Uint16 readUint16();
|
atUint16 readUint16();
|
||||||
|
|
||||||
/*! \brief Reads a Int32 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Int32 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -203,7 +203,7 @@ public:
|
||||||
* \return Int32 The value at the current address
|
* \return Int32 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Int32 readInt32();
|
atInt32 readInt32();
|
||||||
|
|
||||||
/*! \brief Reads a Uint32 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Uint32 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -213,7 +213,7 @@ public:
|
||||||
* \return Uint32 The value at the current address
|
* \return Uint32 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Uint32 readUint32();
|
atUint32 readUint32();
|
||||||
|
|
||||||
/*! \brief Reads a Int64 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Int64 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -223,7 +223,7 @@ public:
|
||||||
* \return Int64 The value at the current address
|
* \return Int64 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Int64 readInt64();
|
atInt64 readInt64();
|
||||||
|
|
||||||
/*! \brief Reads a Uint64 and swaps to proper endianness depending on platform
|
/*! \brief Reads a Uint64 and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -233,7 +233,7 @@ public:
|
||||||
* \return Uint64 The value at the current address
|
* \return Uint64 The value at the current address
|
||||||
* \throw IOException when address is out of range
|
* \throw IOException when address is out of range
|
||||||
*/
|
*/
|
||||||
Uint64 readUint64();
|
atUint64 readUint64();
|
||||||
|
|
||||||
/*! \brief Reads a float and swaps to proper endianness depending on platform
|
/*! \brief Reads a float and swaps to proper endianness depending on platform
|
||||||
* and Stream settings, and advances the current position
|
* and Stream settings, and advances the current position
|
||||||
|
@ -279,11 +279,11 @@ public:
|
||||||
void setProgressCallback(std::function<void(int)> cb);
|
void setProgressCallback(std::function<void(int)> cb);
|
||||||
protected:
|
protected:
|
||||||
void loadData();
|
void loadData();
|
||||||
Uint8* m_data;
|
atUint8* m_data;
|
||||||
Uint64 m_length;
|
atUint64 m_length;
|
||||||
std::string m_filepath; //!< Path to the target file
|
std::string m_filepath; //!< Path to the target file
|
||||||
Uint64 m_position;
|
atUint64 m_position;
|
||||||
Uint64 m_bitPosition;
|
atUint64 m_bitPosition;
|
||||||
Endian m_endian;
|
Endian m_endian;
|
||||||
std::function<void(int)> m_progressCallback;
|
std::function<void(int)> m_progressCallback;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
BinaryWriter(Uint8* data, Uint64 length);
|
BinaryWriter(atUint8* data, atUint64 length);
|
||||||
|
|
||||||
/*! \brief This constructor creates an instance from a file on disk.
|
/*! \brief This constructor creates an instance from a file on disk.
|
||||||
*
|
*
|
||||||
|
@ -86,7 +86,7 @@ public:
|
||||||
* \param position where in the buffer to seek
|
* \param position where in the buffer to seek
|
||||||
* \param origin The Origin to seek \sa SeekOrigin
|
* \param origin The Origin to seek \sa SeekOrigin
|
||||||
*/
|
*/
|
||||||
void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current);
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Returns whether or not the stream is at the end.
|
/*! \brief Returns whether or not the stream is at the end.
|
||||||
|
@ -100,13 +100,13 @@ public:
|
||||||
*
|
*
|
||||||
* \return Int64 The current position in the stream.
|
* \return Int64 The current position in the stream.
|
||||||
*/
|
*/
|
||||||
Uint64 position() const;
|
atUint64 position() const;
|
||||||
|
|
||||||
/*! \brief Returns whether or not the stream is at the end.
|
/*! \brief Returns whether or not the stream is at the end.
|
||||||
*
|
*
|
||||||
* \return bool True if at end; False otherwise.
|
* \return bool True if at end; False otherwise.
|
||||||
*/
|
*/
|
||||||
Uint64 length() const;
|
atUint64 length() const;
|
||||||
|
|
||||||
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
|
/*! \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
|
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
|
||||||
|
@ -117,7 +117,7 @@ public:
|
||||||
* \param length The length of the new buffer.
|
* \param length The length of the new buffer.
|
||||||
* \throw IOException
|
* \throw IOException
|
||||||
*/
|
*/
|
||||||
void setData(const Uint8* data, Uint64 length);
|
void setData(const atUint8* data, atUint64 length);
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Returns a copy of the current buffer.<br />
|
/*! \brief Returns a copy of the current buffer.<br />
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
* as Stream now owns the address, this is done to keep memory usage down.
|
* as Stream now owns the address, this is done to keep memory usage down.
|
||||||
* \return Uint8* The copy of the buffer.
|
* \return Uint8* The copy of the buffer.
|
||||||
*/
|
*/
|
||||||
Uint8* data() const;
|
atUint8* data() const;
|
||||||
|
|
||||||
/*! \brief Sets the target file
|
/*! \brief Sets the target file
|
||||||
*
|
*
|
||||||
|
@ -161,13 +161,13 @@ public:
|
||||||
/*! \brief Writes a byte at the current position and advances the position by one byte.
|
/*! \brief Writes a byte at the current position and advances the position by one byte.
|
||||||
* \param byte The value to write
|
* \param byte The value to write
|
||||||
*/
|
*/
|
||||||
void writeUByte(Uint8 val);
|
void writeUByte(atUint8 val);
|
||||||
|
|
||||||
/*! \brief Writes a byte at the current position and advances the position by one byte.
|
/*! \brief Writes a byte at the current position and advances the position by one byte.
|
||||||
* \param byte The value to write
|
* \param byte The value to write
|
||||||
* \throw IOException
|
* \throw IOException
|
||||||
*/
|
*/
|
||||||
void writeByte(Int8 val);
|
void writeByte(atInt8 val);
|
||||||
|
|
||||||
/*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length
|
/*! \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.
|
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
|
||||||
|
@ -175,7 +175,7 @@ public:
|
||||||
* \param data The buffer to write
|
* \param data The buffer to write
|
||||||
* \param length The amount to write
|
* \param length The amount to write
|
||||||
*/
|
*/
|
||||||
void writeUBytes(Uint8* data, Uint64 len);
|
void writeUBytes(atUint8* data, atUint64 len);
|
||||||
|
|
||||||
/*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length
|
/*! \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.
|
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
|
||||||
|
@ -183,7 +183,7 @@ public:
|
||||||
* \param data The buffer to write
|
* \param data The buffer to write
|
||||||
* \param length The amount to write
|
* \param length The amount to write
|
||||||
*/
|
*/
|
||||||
void writeBytes(Int8* data, Uint64 len);
|
void writeBytes(atInt8* data, atUint64 len);
|
||||||
|
|
||||||
/*! \brief Writes an Int16 to the buffer and advances the buffer.
|
/*! \brief Writes an Int16 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -191,7 +191,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt16(Int16 val);
|
void writeInt16(atInt16 val);
|
||||||
|
|
||||||
/*! \brief Writes an Uint16 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint16 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings
|
* It also swaps the bytes depending on the platform and Stream settings
|
||||||
|
@ -199,7 +199,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUint16(Uint16);
|
void writeUint16(atUint16);
|
||||||
|
|
||||||
/*! \brief Writes an Int32 to the buffer and advances the buffer.
|
/*! \brief Writes an Int32 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -207,7 +207,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt32(Int32);
|
void writeInt32(atInt32);
|
||||||
|
|
||||||
/*! \brief Writes an Uint32 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint32 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -215,7 +215,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUint32(Uint32);
|
void writeUint32(atUint32);
|
||||||
|
|
||||||
/*! \brief Writes an Int64 to the buffer and advances the buffer.
|
/*! \brief Writes an Int64 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -223,7 +223,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt64(Int64);
|
void writeInt64(atInt64);
|
||||||
|
|
||||||
/*! \brief Writes an Uint64 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint64 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -231,7 +231,7 @@ public:
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUint64(Uint64);
|
void writeUint64(atUint64);
|
||||||
|
|
||||||
/*! \brief Writes an float to the buffer and advances the buffer.
|
/*! \brief Writes an float to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
|
@ -272,21 +272,21 @@ public:
|
||||||
*/
|
*/
|
||||||
void writeString(const std::string& str);
|
void writeString(const std::string& str);
|
||||||
|
|
||||||
void fill(Uint8 val, Uint64 length);
|
void fill(atUint8 val, atUint64 length);
|
||||||
void fill(Int8 val, Uint64 length);
|
void fill(atInt8 val, atUint64 length);
|
||||||
|
|
||||||
void setProgressCallback(std::function<void(int)> cb);
|
void setProgressCallback(std::function<void(int)> cb);
|
||||||
protected:
|
protected:
|
||||||
void loadData();
|
void loadData();
|
||||||
Uint8* m_data;
|
atUint8* m_data;
|
||||||
Uint64 m_length;
|
atUint64 m_length;
|
||||||
std::string m_filepath; //!< Path to the target file
|
std::string m_filepath; //!< Path to the target file
|
||||||
Uint64 m_position;
|
atUint64 m_position;
|
||||||
Uint64 m_bitPosition;
|
atUint64 m_bitPosition;
|
||||||
Endian m_endian;
|
Endian m_endian;
|
||||||
std::function<void(int)> m_progressCallback;
|
std::function<void(int)> m_progressCallback;
|
||||||
private:
|
private:
|
||||||
void resize(Uint64 newSize);
|
void resize(atUint64 newSize);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace Checksums
|
namespace Checksums
|
||||||
{
|
{
|
||||||
Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed = 0xFFFFFFFF);
|
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed = 0xFFFFFFFF);
|
||||||
Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed = 0xFFFF, Uint16 final = 0);
|
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0);
|
||||||
Uint16 crc16(const Uint8* data, Uint64 length);
|
atUint16 crc16(const atUint8* data, atUint64 length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // CHECKSUMS_HPP
|
#endif // CHECKSUMS_HPP
|
||||||
|
|
|
@ -25,15 +25,15 @@ namespace io
|
||||||
namespace Compression
|
namespace Compression
|
||||||
{
|
{
|
||||||
// Zlib compression
|
// Zlib compression
|
||||||
Int32 decompressZlib(Uint8* src, Uint32 srcLen, Uint8* dst, Uint32 dstLen);
|
atInt32 decompressZlib(atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
|
||||||
Int32 compressZlib(const Uint8* src, Uint32 srcLen, Uint8* dst, Uint32 dstLen);
|
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
|
||||||
|
|
||||||
// lzo compression
|
// lzo compression
|
||||||
Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize);
|
atInt32 decompressLZO(atUint8* source, atInt32 sourceSize, atUint8* dest, atInt32& dstSize);
|
||||||
|
|
||||||
// Yaz0 encoding
|
// Yaz0 encoding
|
||||||
Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize);
|
atUint32 yaz0Decode(atUint8* src, atUint8* dst, atUint32 uncompressedSize);
|
||||||
Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data);
|
atUint32 yaz0Encode(atUint8* src, atUint32 srcSize, atUint8* data);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,24 +39,24 @@ public:
|
||||||
void close();
|
void close();
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
bool save();
|
bool save();
|
||||||
void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current);
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
||||||
bool atEnd() const;
|
bool atEnd() const;
|
||||||
Uint64 position() const;
|
atUint64 position() const;
|
||||||
Uint64 length() const;
|
atUint64 length() const;
|
||||||
|
|
||||||
|
|
||||||
void seekBit(int);
|
void seekBit(int);
|
||||||
bool readBit();
|
bool readBit();
|
||||||
Uint8 readUByte();
|
atUint8 readUByte();
|
||||||
Int8 readByte();
|
atInt8 readByte();
|
||||||
Uint8* readUBytes(Uint64 len);
|
atUint8* readUBytes(atUint64 len);
|
||||||
Int8* readBytes(Uint64 len);
|
atInt8* readBytes(atUint64 len);
|
||||||
Uint16 readUint16();
|
atUint16 readUint16();
|
||||||
Int16 readInt16();
|
atInt16 readInt16();
|
||||||
Uint32 readUint32();
|
atUint32 readUint32();
|
||||||
Int32 readInt32();
|
atInt32 readInt32();
|
||||||
Uint64 readUint64();
|
atUint64 readUint64();
|
||||||
Int64 readInt64();
|
atInt64 readInt64();
|
||||||
double readDouble();
|
double readDouble();
|
||||||
float readFloat();
|
float readFloat();
|
||||||
bool readBool();
|
bool readBool();
|
||||||
|
@ -66,8 +66,8 @@ private:
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
FILE* m_fileHandle;
|
FILE* m_fileHandle;
|
||||||
Endian m_endian;
|
Endian m_endian;
|
||||||
Uint8 m_currentByte;
|
atUint8 m_currentByte;
|
||||||
Uint8 m_bitShift;
|
atUint8 m_bitShift;
|
||||||
bool m_bitValid;
|
bool m_bitValid;
|
||||||
};
|
};
|
||||||
} // io
|
} // io
|
||||||
|
|
|
@ -36,23 +36,23 @@ public:
|
||||||
void close();
|
void close();
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
bool save();
|
bool save();
|
||||||
void seek(Int64 pos, SeekOrigin origin = SeekOrigin::Current);
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
||||||
bool atEnd() const;
|
bool atEnd() const;
|
||||||
Uint64 position() const;
|
atUint64 position() const;
|
||||||
Uint64 length() const;
|
atUint64 length() const;
|
||||||
|
|
||||||
void writeBit (bool val);
|
void writeBit (bool val);
|
||||||
void seekBit (int bit);
|
void seekBit (int bit);
|
||||||
void writeUByte (Uint8 val);
|
void writeUByte (atUint8 val);
|
||||||
void writeByte (Int8 val);
|
void writeByte (atInt8 val);
|
||||||
void writeUBytes(Uint8* data, Uint64 len);
|
void writeUBytes(atUint8* data, atUint64 len);
|
||||||
void writeBytes (Int8* data, Uint64 len);
|
void writeBytes (atInt8* data, atUint64 len);
|
||||||
void writeUint16(Uint16 val);
|
void writeUint16(atUint16 val);
|
||||||
void writeInt16 (Int16 val);
|
void writeInt16 (atInt16 val);
|
||||||
void writeUint32(Uint32 val);
|
void writeUint32(atUint32 val);
|
||||||
void writeInt32 (Int32 val);
|
void writeInt32 (atInt32 val);
|
||||||
void writeUint64(Uint64 val);
|
void writeUint64(atUint64 val);
|
||||||
void writeInt64 (Int64 val);
|
void writeInt64 (atInt64 val);
|
||||||
void writeDouble(double val);
|
void writeDouble(double val);
|
||||||
void writeFloat (float val);
|
void writeFloat (float val);
|
||||||
void writeBool (bool val);
|
void writeBool (bool val);
|
||||||
|
@ -62,9 +62,9 @@ private:
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
FILE* m_fileHandle;
|
FILE* m_fileHandle;
|
||||||
Endian m_endian;
|
Endian m_endian;
|
||||||
Uint8 m_currentByte;
|
atUint8 m_currentByte;
|
||||||
Uint8 m_bytePosition;
|
atUint8 m_bytePosition;
|
||||||
Uint8 m_bitShift;
|
atUint8 m_bitShift;
|
||||||
bool m_bitValid;
|
bool m_bitValid;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
MCFileReader(Uint8*, Uint64);
|
MCFileReader(atUint8*, atUint64);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief This constructor creates an instance from a file on disk.
|
* \brief This constructor creates an instance from a file on disk.
|
||||||
|
@ -64,3 +65,4 @@ public:
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __MCFILEREADER_HPP__
|
#endif // __MCFILEREADER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -44,7 +45,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
MCFileWriter(Uint8*, Uint64);
|
MCFileWriter(atUint8*, atUint64);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief This constructor creates an instance from a file on disk.
|
* \brief This constructor creates an instance from a file on disk.
|
||||||
|
@ -61,9 +62,9 @@ public:
|
||||||
void writeFile(MCFile* file);
|
void writeFile(MCFile* file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Uint16 calculateSlotChecksum(Uint32 game);
|
atUint16 calculateSlotChecksum(atUint32 game);
|
||||||
Uint16 calculateChecksum(Uint8* data, Uint32 length);
|
atUint16 calculateChecksum(atUint8* data, atUint32 length);
|
||||||
Uint8* reverse(Uint8* data, Uint32 length);
|
atUint8* reverse(atUint8* data, atUint32 length);
|
||||||
void unscramble();
|
void unscramble();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,3 +72,4 @@ private:
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __MCFILEWRITER_HPP__
|
#endif // __MCFILEWRITER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -47,7 +48,7 @@ public:
|
||||||
~SkywardSwordFile();
|
~SkywardSwordFile();
|
||||||
|
|
||||||
void addQuest(SkywardSwordQuest* q);
|
void addQuest(SkywardSwordQuest* q);
|
||||||
SkywardSwordQuest* quest(Uint32 id);
|
SkywardSwordQuest* quest(atUint32 id);
|
||||||
std::vector<SkywardSwordQuest*> questList() const;
|
std::vector<SkywardSwordQuest*> questList() const;
|
||||||
|
|
||||||
void setRegion(Region region);
|
void setRegion(Region region);
|
||||||
|
@ -56,8 +57,9 @@ private:
|
||||||
Region m_region;
|
Region m_region;
|
||||||
// A vector is a bit overkill
|
// A vector is a bit overkill
|
||||||
std::vector<SkywardSwordQuest*> m_quests;
|
std::vector<SkywardSwordQuest*> m_quests;
|
||||||
Uint32 m_numQuests;
|
atUint32 m_numQuests;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // __SSFILE_HPP__
|
#endif // __SSFILE_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -28,7 +29,7 @@ class SkywardSwordFileReader : public BinaryReader
|
||||||
BINARYREADER_BASE();
|
BINARYREADER_BASE();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SkywardSwordFileReader(Uint8* data, Uint64 length);
|
SkywardSwordFileReader(atUint8* data, atUint64 length);
|
||||||
SkywardSwordFileReader(const std::string& filename);
|
SkywardSwordFileReader(const std::string& filename);
|
||||||
|
|
||||||
SkywardSwordFile* read();
|
SkywardSwordFile* read();
|
||||||
|
@ -37,3 +38,4 @@ public:
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __SSFILEREADER_HPP__
|
#endif // __SSFILEREADER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -30,7 +31,7 @@ class SkywardSwordFileWriter : public BinaryWriter
|
||||||
// Why does this fuck up my formatting in Qt Creator?
|
// Why does this fuck up my formatting in Qt Creator?
|
||||||
BINARYWRITER_BASE
|
BINARYWRITER_BASE
|
||||||
public:
|
public:
|
||||||
SkywardSwordFileWriter(Uint8* data, Uint64 len);
|
SkywardSwordFileWriter(atUint8* data, atUint64 len);
|
||||||
SkywardSwordFileWriter(const std::string& filename);
|
SkywardSwordFileWriter(const std::string& filename);
|
||||||
|
|
||||||
void write(SkywardSwordFile* file);
|
void write(SkywardSwordFile* file);
|
||||||
|
@ -38,3 +39,4 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // __SSFILEWRITER_HPP__
|
#endif // __SSFILEWRITER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -26,19 +27,20 @@ namespace Athena
|
||||||
class SkywardSwordQuest : public ZQuestFile
|
class SkywardSwordQuest : public ZQuestFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SkywardSwordQuest(Uint8* data, Uint32 len);
|
SkywardSwordQuest(atUint8* data, atUint32 len);
|
||||||
|
|
||||||
// TODO: Is len really needed?
|
// TODO: Is len really needed?
|
||||||
void setSkipData(const Uint8* data, Uint32 len = 0x24);
|
void setSkipData(const atUint8* data, atUint32 len = 0x24);
|
||||||
Uint8* skipData() const;
|
atUint8* skipData() const;
|
||||||
|
|
||||||
Uint32 skipLength() const;
|
atUint32 skipLength() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Uint8* m_skipData;
|
atUint8* m_skipData;
|
||||||
Uint32 m_skipLength;
|
atUint32 m_skipLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // SSQUEST_HPP
|
#endif // SSQUEST_HPP
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -78,20 +78,20 @@ public:
|
||||||
#else
|
#else
|
||||||
QList<int> stateIds() const;
|
QList<int> stateIds() const;
|
||||||
#endif
|
#endif
|
||||||
Uint32 stateCount() const;
|
atUint32 stateCount() const;
|
||||||
void setCurrentState(Uint32 id);
|
void setCurrentState(atUint32 id);
|
||||||
Uint32 currentState() const;
|
atUint32 currentState() const;
|
||||||
|
|
||||||
bool addFrame(SpriteFrame* Frame);
|
bool addFrame(SpriteFrame* Frame);
|
||||||
bool removeFrame(SpriteFrame* Frame);
|
bool removeFrame(SpriteFrame* Frame);
|
||||||
SpriteFrame* Frame(Uint32 id);
|
SpriteFrame* Frame(atUint32 id);
|
||||||
void setFrame(Uint32 id);
|
void setFrame(atUint32 id);
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
void setFrames(std::vector<SpriteFrame*> frames);
|
void setFrames(std::vector<SpriteFrame*> frames);
|
||||||
#else
|
#else
|
||||||
void setFrames(QList<SpriteFrame*> frames);
|
void setFrames(QList<SpriteFrame*> frames);
|
||||||
#endif
|
#endif
|
||||||
Uint32 frameCount() const;
|
atUint32 frameCount() const;
|
||||||
|
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
std::vector<SpriteFrame*> frames() const;
|
std::vector<SpriteFrame*> frames() const;
|
||||||
|
@ -102,7 +102,7 @@ public:
|
||||||
SpriteFile* container() const;
|
SpriteFile* container() const;
|
||||||
|
|
||||||
void setCurrentFrame(SpriteFrame* frame);
|
void setCurrentFrame(SpriteFrame* frame);
|
||||||
void setCurrentFrame(Uint32 id);
|
void setCurrentFrame(atUint32 id);
|
||||||
SpriteFrame* currentFrame() const;
|
SpriteFrame* currentFrame() const;
|
||||||
|
|
||||||
void advanceFrame();
|
void advanceFrame();
|
||||||
|
@ -129,8 +129,8 @@ private:
|
||||||
QList<int> m_stateIds;
|
QList<int> m_stateIds;
|
||||||
QList<SpriteFrame*> m_frames;
|
QList<SpriteFrame*> m_frames;
|
||||||
#endif
|
#endif
|
||||||
Uint32 m_currentState;
|
atUint32 m_currentState;
|
||||||
Uint32 m_currentFrame;
|
atUint32 m_currentFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,32 +53,32 @@ public:
|
||||||
/*!
|
/*!
|
||||||
* \brief Major
|
* \brief Major
|
||||||
*/
|
*/
|
||||||
static const Uint32 Major;
|
static const atUint32 Major;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Minor
|
* \brief Minor
|
||||||
*/
|
*/
|
||||||
static const Uint32 Minor;
|
static const atUint32 Minor;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Revision
|
* \brief Revision
|
||||||
*/
|
*/
|
||||||
static const Uint32 Revision;
|
static const atUint32 Revision;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Patch
|
* \brief Patch
|
||||||
*/
|
*/
|
||||||
static const Uint32 Build;
|
static const atUint32 Build;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Version
|
* \brief Version
|
||||||
*/
|
*/
|
||||||
static const Uint32 Version;
|
static const atUint32 Version;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Magic
|
* \brief Magic
|
||||||
*/
|
*/
|
||||||
static const Uint32 Magic;
|
static const atUint32 Magic;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief SSprite
|
* \brief SSprite
|
||||||
|
@ -92,7 +92,7 @@ public:
|
||||||
* \param originX
|
* \param originX
|
||||||
* \param originY
|
* \param originY
|
||||||
*/
|
*/
|
||||||
SpriteFile(Uint32 width, Uint32 height, float originX, float originY);
|
SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief SSpriteFile
|
* \brief SSpriteFile
|
||||||
|
@ -118,7 +118,7 @@ public slots:
|
||||||
* \param width
|
* \param width
|
||||||
* \param height
|
* \param height
|
||||||
*/
|
*/
|
||||||
void setSize(Uint32 width, Uint32 height);
|
void setSize(atUint32 width, atUint32 height);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setSize
|
* \brief setSize
|
||||||
|
@ -144,13 +144,13 @@ public slots:
|
||||||
* \brief width
|
* \brief width
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 width() const;
|
atUint32 width() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief height
|
* \brief height
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 height() const;
|
atUint32 height() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setOrigin
|
* \brief setOrigin
|
||||||
|
@ -209,14 +209,14 @@ public slots:
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
STexture* texture(Uint32 id);
|
STexture* texture(atUint32 id);
|
||||||
|
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
std::vector<STexture*> textures() const;
|
std::vector<STexture*> textures() const;
|
||||||
#else
|
#else
|
||||||
QList<STexture*> textures() const;
|
QList<STexture*> textures() const;
|
||||||
#endif
|
#endif
|
||||||
Uint32 textureCount() const;
|
atUint32 textureCount() const;
|
||||||
/*!
|
/*!
|
||||||
* \brief setTextures
|
* \brief setTextures
|
||||||
* \param textures
|
* \param textures
|
||||||
|
@ -250,7 +250,7 @@ public slots:
|
||||||
QMap<QString, Sprite*> sprites() const;
|
QMap<QString, Sprite*> sprites() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Uint32 spriteCount() const;
|
atUint32 spriteCount() const;
|
||||||
|
|
||||||
#ifdef ATHENA_USE_QT
|
#ifdef ATHENA_USE_QT
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -32,7 +32,7 @@ class SpriteFileReader : public BinaryReader
|
||||||
{
|
{
|
||||||
BINARYREADER_BASE();
|
BINARYREADER_BASE();
|
||||||
public:
|
public:
|
||||||
SpriteFileReader(Uint8* data, Uint64 length);
|
SpriteFileReader(atUint8* data, atUint64 length);
|
||||||
SpriteFileReader(const std::string& filepath);
|
SpriteFileReader(const std::string& filepath);
|
||||||
|
|
||||||
Sakura::SpriteFile* readFile();
|
Sakura::SpriteFile* readFile();
|
||||||
|
|
|
@ -32,7 +32,7 @@ class SpriteFileWriter : public BinaryWriter
|
||||||
{
|
{
|
||||||
BINARYWRITER_BASE;
|
BINARYWRITER_BASE;
|
||||||
public:
|
public:
|
||||||
SpriteFileWriter(Uint8* data, Uint64 length);
|
SpriteFileWriter(atUint8* data, atUint64 length);
|
||||||
|
|
||||||
SpriteFileWriter(const std::string& filepath);
|
SpriteFileWriter(const std::string& filepath);
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
QList<SpritePart*> parts() const;
|
QList<SpritePart*> parts() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Uint32 partCount() const;
|
atUint32 partCount() const;
|
||||||
|
|
||||||
void setRoot(Sprite* root);
|
void setRoot(Sprite* root);
|
||||||
Sprite* root() const;
|
Sprite* root() const;
|
||||||
|
|
|
@ -125,7 +125,7 @@ public:
|
||||||
* \param width
|
* \param width
|
||||||
* \param height
|
* \param height
|
||||||
*/
|
*/
|
||||||
void setSize(Uint32 width, Uint32 height);
|
void setSize(atUint32 width, atUint32 height);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setSize
|
* \brief setSize
|
||||||
|
@ -203,7 +203,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
bool m_flippedH;
|
bool m_flippedH;
|
||||||
bool m_flippedV;
|
bool m_flippedV;
|
||||||
Uint32 m_frameIndex;
|
atUint32 m_frameIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,24 +34,24 @@ public:
|
||||||
virtual bool isBigEndian() const= 0;
|
virtual bool isBigEndian() const= 0;
|
||||||
virtual bool isLittleEndian()const= 0;
|
virtual bool isLittleEndian()const= 0;
|
||||||
virtual bool isOpen() const= 0;
|
virtual bool isOpen() const= 0;
|
||||||
virtual void seek(Int64, SeekOrigin)=0;
|
virtual void seek(atInt64, SeekOrigin)=0;
|
||||||
virtual bool atEnd() const= 0;
|
virtual bool atEnd() const= 0;
|
||||||
virtual Uint64 position() const= 0;
|
virtual atUint64 position() const= 0;
|
||||||
virtual Uint64 length() const= 0;
|
virtual atUint64 length() const= 0;
|
||||||
protected:
|
protected:
|
||||||
virtual void seekBit (int){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void seekBit (int){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
// Reading
|
// Reading
|
||||||
virtual bool readBit() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual bool readBit() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Uint8 readUByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atUint8 readUByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Int8 readByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atInt8 readByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Uint8* readUBytes(Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atUint8* readUBytes(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Int8* readBytes(Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atInt8* readBytes(atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Uint16 readUint16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atUint16 readUint16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Int16 readInt16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atInt16 readInt16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Uint32 readUint32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atUint32 readUint32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Int32 readInt32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atInt32 readInt32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Uint64 readUint64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atUint64 readUint64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual Int64 readInt64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual atInt64 readInt64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual double readDouble() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual double readDouble() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual float readFloat() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual float readFloat() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual bool readBool() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual bool readBool() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
|
@ -59,23 +59,23 @@ protected:
|
||||||
virtual std::string readString() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual std::string readString() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
// Writing
|
// Writing
|
||||||
virtual void writeBit (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeBit (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUByte (Uint8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUByte (atUint8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeByte (Int8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeByte (atInt8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUBytes(Uint8*, Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUBytes(atUint8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeBytes (Int8*, Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeBytes (atInt8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUint16(Uint16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUint16(atUint16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeInt16 (Int16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeInt16 (atInt16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUint32(Uint32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUint32(atUint32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeInt32 (Int32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeInt32 (atInt32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUint64(Uint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUint64(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeInt64 (Int64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeInt64 (atInt64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeDouble(double){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeDouble(double){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeFloat (float){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeFloat (float){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeBool (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeBool (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeString(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeString(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void writeUnicode(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void writeUnicode(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void fill(Uint8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void fill(atUint8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
virtual void fill(Int8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
virtual void fill(atInt8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // STREAM_HPP
|
#endif // STREAM_HPP
|
||||||
|
|
|
@ -19,42 +19,42 @@
|
||||||
|
|
||||||
// 8 bits integer types
|
// 8 bits integer types
|
||||||
#if UCHAR_MAX == 0xFF
|
#if UCHAR_MAX == 0xFF
|
||||||
typedef signed char Int8;
|
typedef signed char atInt8;
|
||||||
typedef unsigned char Uint8;
|
typedef unsigned char atUint8;
|
||||||
#else
|
#else
|
||||||
#error No 8 bits integer type for this platform
|
#error No 8 bits integer type for this platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 16 bits integer types
|
// 16 bits integer types
|
||||||
#if USHRT_MAX == 0xFFFF
|
#if USHRT_MAX == 0xFFFF
|
||||||
typedef signed short Int16;
|
typedef signed short atInt16;
|
||||||
typedef unsigned short Uint16;
|
typedef unsigned short atUint16;
|
||||||
#elif UINT_MAX == 0xFFFF
|
#elif UINT_MAX == 0xFFFF
|
||||||
typedef signed int Int16;
|
typedef signed int atInt16;
|
||||||
typedef unsigned int Uint16;
|
typedef unsigned int atUint16;
|
||||||
#elif ULONG_MAX == 0xFFFF
|
#elif ULONG_MAX == 0xFFFF
|
||||||
typedef signed long Int16;
|
typedef signed long atInt16;
|
||||||
typedef unsigned long Uint16;
|
typedef unsigned long atUint16;
|
||||||
#else
|
#else
|
||||||
#error No 16 bits integer type for this platform
|
#error No 16 bits integer type for this platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 32 bits integer types
|
// 32 bits integer types
|
||||||
#if USHRT_MAX == 0xFFFFFFFF
|
#if USHRT_MAX == 0xFFFFFFFF
|
||||||
typedef signed short Int32;
|
typedef signed short atInt32;
|
||||||
typedef unsigned short Uint32;
|
typedef unsigned short atUint32;
|
||||||
#elif UINT_MAX == 0xFFFFFFFF
|
#elif UINT_MAX == 0xFFFFFFFF
|
||||||
typedef signed int Int32;
|
typedef signed int atInt32;
|
||||||
typedef unsigned int Uint32;
|
typedef unsigned int atUint32;
|
||||||
#elif ULONG_MAX == 0xFFFFFFFF
|
#elif ULONG_MAX == 0xFFFFFFFF
|
||||||
typedef signed long Int32;
|
typedef signed long atInt32;
|
||||||
typedef unsigned long Uint32;
|
typedef unsigned long atUint32;
|
||||||
#else
|
#else
|
||||||
#error No 32 bits integer type for this platform
|
#error No 32 bits integer type for this platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef signed long long Int64;
|
typedef signed long long atInt64;
|
||||||
typedef unsigned long long Uint64;
|
typedef unsigned long long atUint64;
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -26,21 +26,21 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
bool isEmpty(Int8*, Uint32);
|
bool isEmpty(atInt8*, atUint32);
|
||||||
|
|
||||||
Uint16 swapU16(Uint16 val );
|
atUint16 swapU16(atUint16 val );
|
||||||
Int16 swap16 (Int16 val );
|
atInt16 swap16 (atInt16 val );
|
||||||
Uint32 swapU32(Uint32 val);
|
atUint32 swapU32(atUint32 val);
|
||||||
Int32 swap32 (Int32 val );
|
atInt32 swap32 (atInt32 val );
|
||||||
Uint64 swapU64(Uint64 val);
|
atUint64 swapU64(atUint64 val);
|
||||||
Int64 swap64 (Int64 val);
|
atInt64 swap64 (atInt64 val);
|
||||||
|
|
||||||
float swapFloat(float val);
|
float swapFloat(float val);
|
||||||
double swapDouble(double val);
|
double swapDouble(double val);
|
||||||
|
|
||||||
bool isSystemBigEndian();
|
bool isSystemBigEndian();
|
||||||
|
|
||||||
void fillRandom(Uint8 * rndArea, Uint8 count);
|
void fillRandom(atUint8 * rndArea, atUint8 count);
|
||||||
|
|
||||||
std::vector<std::string> split(const std::string &s, char delim);
|
std::vector<std::string> split(const std::string &s, char delim);
|
||||||
std::string join(const std::vector<std::string>& elems, const std::string& delims);
|
std::string join(const std::vector<std::string>& elems, const std::string& delims);
|
||||||
|
@ -52,7 +52,7 @@ bool parseBool(const std::string& boolean, bool* valid = NULL);
|
||||||
|
|
||||||
int countChar(const std::string& str, const char chr, int* lastOccur = NULL);
|
int countChar(const std::string& str, const char chr, int* lastOccur = NULL);
|
||||||
|
|
||||||
Uint64 fileSize(FILE* f);
|
atUint64 fileSize(FILE* f);
|
||||||
} // utility
|
} // utility
|
||||||
} // Athena
|
} // Athena
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -51,20 +52,20 @@ public:
|
||||||
* \param m_banner
|
* \param m_banner
|
||||||
* \param icons
|
* \param icons
|
||||||
*/
|
*/
|
||||||
WiiBanner(Uint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector<WiiImage*> icons);
|
WiiBanner(atUint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector<WiiImage*> icons);
|
||||||
virtual ~WiiBanner();
|
virtual ~WiiBanner();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setGameID
|
* \brief setGameID
|
||||||
* \param id
|
* \param id
|
||||||
*/
|
*/
|
||||||
void setGameID(Uint64 id);
|
void setGameID(atUint64 id);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief gameID
|
* \brief gameID
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint64 gameID() const;
|
atUint64 gameID() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setBannerImage
|
* \brief setBannerImage
|
||||||
|
@ -82,13 +83,13 @@ public:
|
||||||
* \brief setBannerSize
|
* \brief setBannerSize
|
||||||
* \param size
|
* \param size
|
||||||
*/
|
*/
|
||||||
void setBannerSize(Uint32 size);
|
void setBannerSize(atUint32 size);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief bannerSize
|
* \brief bannerSize
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 bannerSize() const;
|
atUint32 bannerSize() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setTitle
|
* \brief setTitle
|
||||||
|
@ -125,14 +126,14 @@ public:
|
||||||
* \param id
|
* \param id
|
||||||
* \param icon
|
* \param icon
|
||||||
*/
|
*/
|
||||||
void setIcon(Uint32 id, WiiImage* icon);
|
void setIcon(atUint32 id, WiiImage* icon);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief getIcon
|
* \brief getIcon
|
||||||
* \param id
|
* \param id
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
WiiImage* getIcon(Uint32 id) const;
|
WiiImage* getIcon(atUint32 id) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief icons
|
* \brief icons
|
||||||
|
@ -144,45 +145,45 @@ public:
|
||||||
* \brief setAnimationSpeed
|
* \brief setAnimationSpeed
|
||||||
* \param animSpeed
|
* \param animSpeed
|
||||||
*/
|
*/
|
||||||
void setAnimationSpeed(Uint16 animSpeed);
|
void setAnimationSpeed(atUint16 animSpeed);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief animationSpeed
|
* \brief animationSpeed
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint16 animationSpeed() const;
|
atUint16 animationSpeed() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setPermissions
|
* \brief setPermissions
|
||||||
* \param permissions
|
* \param permissions
|
||||||
*/
|
*/
|
||||||
void setPermissions(Uint8 permissions);
|
void setPermissions(atUint8 permissions);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief permissions
|
* \brief permissions
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 permissions() const;
|
atUint8 permissions() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setFlags
|
* \brief setFlags
|
||||||
* \param flags
|
* \param flags
|
||||||
*/
|
*/
|
||||||
void setFlags(Uint32 flags);
|
void setFlags(atUint32 flags);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief flags
|
* \brief flags
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 flags() const;
|
atUint32 flags() const;
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
Uint64 m_gameId;
|
atUint64 m_gameId;
|
||||||
WiiImage* m_banner;
|
WiiImage* m_banner;
|
||||||
Uint32 m_animSpeed;
|
atUint32 m_animSpeed;
|
||||||
Uint8 m_permissions;
|
atUint8 m_permissions;
|
||||||
Uint32 m_flags;
|
atUint32 m_flags;
|
||||||
Uint32 m_bannerSize;
|
atUint32 m_bannerSize;
|
||||||
std::vector<WiiImage*> m_icons;
|
std::vector<WiiImage*> m_icons;
|
||||||
std::string m_title;
|
std::string m_title;
|
||||||
std::string m_subtitle;
|
std::string m_subtitle;
|
||||||
|
@ -190,3 +191,4 @@ private:
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // WIIBANNER_H
|
#endif // WIIBANNER_H
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -23,9 +24,9 @@
|
||||||
namespace Athena
|
namespace Athena
|
||||||
{
|
{
|
||||||
|
|
||||||
const Uint8 SD_KEY [16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
|
const atUint8 SD_KEY [16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
|
||||||
const Uint8 SD_IV [16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
|
const atUint8 SD_IV [16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
|
||||||
const Uint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
|
const atUint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
|
||||||
|
|
||||||
/*! \class WiiFile
|
/*! \class WiiFile
|
||||||
* \brief Wii file container class
|
* \brief Wii file container class
|
||||||
|
@ -79,7 +80,7 @@ public:
|
||||||
* \param data
|
* \param data
|
||||||
* \param length
|
* \param length
|
||||||
*/
|
*/
|
||||||
WiiFile(const std::string& filename, Uint8 permissions, const Uint8* data, Uint32 length);
|
WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length);
|
||||||
virtual ~WiiFile();
|
virtual ~WiiFile();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -98,12 +99,12 @@ public:
|
||||||
* \brief setData
|
* \brief setData
|
||||||
* \param data
|
* \param data
|
||||||
*/
|
*/
|
||||||
void setData(const Uint8* data);
|
void setData(const atUint8* data);
|
||||||
/*!
|
/*!
|
||||||
* \brief data
|
* \brief data
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8* data() const;
|
atUint8* data() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setLength
|
* \brief setLength
|
||||||
|
@ -121,25 +122,25 @@ public:
|
||||||
* \brief setPermissions
|
* \brief setPermissions
|
||||||
* \param permissions
|
* \param permissions
|
||||||
*/
|
*/
|
||||||
void setPermissions(const Uint8 permissions);
|
void setPermissions(const atUint8 permissions);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief permissions
|
* \brief permissions
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 permissions() const;
|
atUint8 permissions() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setAttributes
|
* \brief setAttributes
|
||||||
* \param attr
|
* \param attr
|
||||||
*/
|
*/
|
||||||
void setAttributes(const Uint8 attr);
|
void setAttributes(const atUint8 attr);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief attributes
|
* \brief attributes
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8 attributes() const;
|
atUint8 attributes() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setType
|
* \brief setType
|
||||||
|
@ -167,13 +168,14 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
Uint8 m_permissions;
|
atUint8 m_permissions;
|
||||||
Uint8 m_attributes;
|
atUint8 m_attributes;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
int m_fileLen;
|
int m_fileLen;
|
||||||
Uint8* m_fileData;
|
atUint8* m_fileData;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // WIIFILE_H
|
#endif // WIIFILE_H
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -37,7 +38,7 @@ public:
|
||||||
* \param height
|
* \param height
|
||||||
* \param data
|
* \param data
|
||||||
*/
|
*/
|
||||||
WiiImage(Uint32 width, Uint32 height, Uint8* data);
|
WiiImage(atUint32 width, atUint32 height, atUint8* data);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief ~WiiImage
|
* \brief ~WiiImage
|
||||||
|
@ -48,50 +49,51 @@ public:
|
||||||
* \brief setWidth
|
* \brief setWidth
|
||||||
* \param width
|
* \param width
|
||||||
*/
|
*/
|
||||||
void setWidth(const Uint32 width);
|
void setWidth(const atUint32 width);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief width
|
* \brief width
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 width() const;
|
atUint32 width() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setHeight
|
* \brief setHeight
|
||||||
* \param height
|
* \param height
|
||||||
*/
|
*/
|
||||||
void setHeight(const Uint32 height);
|
void setHeight(const atUint32 height);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief height
|
* \brief height
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 height() const;
|
atUint32 height() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief setData
|
* \brief setData
|
||||||
* \param data
|
* \param data
|
||||||
*/
|
*/
|
||||||
void setData(const Uint8* data);
|
void setData(const atUint8* data);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief data
|
* \brief data
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8* data();
|
atUint8* data();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief toRGBA
|
* \brief toRGBA
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8* toRGBA();
|
atUint8* toRGBA();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Uint32 m_width;
|
atUint32 m_width;
|
||||||
Uint32 m_height;
|
atUint32 m_height;
|
||||||
Uint8* m_data;
|
atUint8* m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // WIIIMAGE_HPP
|
#endif // WIIIMAGE_HPP
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -45,7 +46,7 @@ public:
|
||||||
* \param data The existing buffer
|
* \param data The existing buffer
|
||||||
* \param length The length of the existing buffer
|
* \param length The length of the existing buffer
|
||||||
*/
|
*/
|
||||||
WiiSaveReader(const Uint8*, Uint64);
|
WiiSaveReader(const atUint8*, atUint64);
|
||||||
|
|
||||||
/*! \brief This constructor creates an instance from a file on disk.
|
/*! \brief This constructor creates an instance from a file on disk.
|
||||||
*
|
*
|
||||||
|
@ -61,10 +62,11 @@ public:
|
||||||
private:
|
private:
|
||||||
WiiBanner* readBanner();
|
WiiBanner* readBanner();
|
||||||
WiiFile* readFile();
|
WiiFile* readFile();
|
||||||
WiiImage* readImage(Uint32 width, Uint32 height);
|
WiiImage* readImage(atUint32 width, atUint32 height);
|
||||||
void readCerts(Uint32 totalSize);
|
void readCerts(atUint32 totalSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // __WII_SAVE_READER_HPP__
|
#endif // __WII_SAVE_READER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -56,15 +57,16 @@ public:
|
||||||
* \param filepath
|
* \param filepath
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
bool writeSave(WiiSave* save, Uint8* macAddress, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId, const std::string& filepath = "");
|
bool writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId, const std::string& filepath = "");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeBanner(WiiBanner* banner);
|
void writeBanner(WiiBanner* banner);
|
||||||
Uint32 writeFile(WiiFile* file);
|
atUint32 writeFile(WiiFile* file);
|
||||||
void writeImage(WiiImage* image);
|
void writeImage(WiiImage* image);
|
||||||
void writeCerts(Uint32 filesSize, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId);
|
void writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // __WII_SAVE_WRITER_HPP__
|
#endif // __WII_SAVE_WRITER_HPP__
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
#ifndef ZQUEST_HPP
|
#ifndef ZQUEST_HPP
|
||||||
#define ZQUEST_HPP
|
#define ZQUEST_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "Athena/Global.hpp"
|
#include "Athena/Global.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -34,24 +36,24 @@ public:
|
||||||
/*!
|
/*!
|
||||||
* \brief The current major version of the ZQuest format
|
* \brief The current major version of the ZQuest format
|
||||||
*/
|
*/
|
||||||
static const Uint32 Major;
|
static const atUint32 Major;
|
||||||
/*!
|
/*!
|
||||||
* \brief The current minor version of the ZQuest format
|
* \brief The current minor version of the ZQuest format
|
||||||
*/
|
*/
|
||||||
static const Uint32 Minor;
|
static const atUint32 Minor;
|
||||||
/*!
|
/*!
|
||||||
* \brief The current revision of the ZQuest format
|
* \brief The current revision of the ZQuest format
|
||||||
*/
|
*/
|
||||||
static const Uint32 Revision;
|
static const atUint32 Revision;
|
||||||
/*!
|
/*!
|
||||||
* \brief The current version of the ZQuest format
|
* \brief The current version of the ZQuest format
|
||||||
*/
|
*/
|
||||||
static const Uint32 Version;
|
static const atUint32 Version;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The magic number used to identify the file e.g. "ZQS1"
|
* \brief The magic number used to identify the file e.g. "ZQS1"
|
||||||
*/
|
*/
|
||||||
static const Uint32 Magic;
|
static const atUint32 Magic;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \enum Game
|
* \enum Game
|
||||||
|
@ -96,7 +98,7 @@ public:
|
||||||
* \param data
|
* \param data
|
||||||
* \param length
|
* \param length
|
||||||
*/
|
*/
|
||||||
ZQuestFile(Game game, Endian endian, Uint8* data, Uint32 length, const std::string& gameString = std::string());
|
ZQuestFile(Game game, Endian endian, atUint8* data, atUint32 length, const std::string& gameString = std::string());
|
||||||
~ZQuestFile();
|
~ZQuestFile();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -128,19 +130,19 @@ public:
|
||||||
* \param data The data to assign
|
* \param data The data to assign
|
||||||
* \param length The length of the data
|
* \param length The length of the data
|
||||||
*/
|
*/
|
||||||
void setData(Uint8* data, Uint32 length);
|
void setData(atUint8* data, atUint32 length);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief data
|
* \brief data
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint8* data() const;
|
atUint8* data() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief length
|
* \brief length
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
Uint32 length() const;
|
atUint32 length() const;
|
||||||
|
|
||||||
void setGameString(const std::string& gameString);
|
void setGameString(const std::string& gameString);
|
||||||
/*!
|
/*!
|
||||||
|
@ -154,11 +156,12 @@ private:
|
||||||
Game m_game;
|
Game m_game;
|
||||||
std::string m_gameString;
|
std::string m_gameString;
|
||||||
Endian m_endian;
|
Endian m_endian;
|
||||||
Uint8* m_data;
|
atUint8* m_data;
|
||||||
Uint32 m_length;
|
atUint32 m_length;
|
||||||
|
|
||||||
// Game strings support
|
// Game strings support
|
||||||
};
|
};
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // ZQUEST_HPP
|
#endif // ZQUEST_HPP
|
||||||
|
#endif // ATHENA_NO_ZQUEST
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -38,7 +39,7 @@ public:
|
||||||
* \param data
|
* \param data
|
||||||
* \param length
|
* \param length
|
||||||
*/
|
*/
|
||||||
ZQuestFileReader(Uint8* data, Uint64 length);
|
ZQuestFileReader(atUint8* data, atUint64 length);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief ZQuestFileReader
|
* \brief ZQuestFileReader
|
||||||
|
@ -57,3 +58,5 @@ public:
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
#endif // __ZQUESTFILEREADER_HPP__
|
#endif // __ZQUESTFILEREADER_HPP__
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_ZQUEST
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -38,7 +39,7 @@ public:
|
||||||
* \param data
|
* \param data
|
||||||
* \param length
|
* \param length
|
||||||
*/
|
*/
|
||||||
ZQuestFileWriter(Uint8* data, Uint64 length);
|
ZQuestFileWriter(atUint8* data, atUint64 length);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief ZQuestFileWriter
|
* \brief ZQuestFileWriter
|
||||||
|
@ -57,3 +58,5 @@ public:
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
#endif // __ZQUESTFILEWRITER_HPP__
|
#endif // __ZQUESTFILEWRITER_HPP__
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_ZQUEST
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void aes_encrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len);
|
void aes_encrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len);
|
||||||
void aes_decrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len);
|
void aes_decrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len);
|
||||||
void aes_set_key(const Uint8 *key );
|
void aes_set_key(const atUint8 *key );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
12
include/bn.h
12
include/bn.h
|
@ -4,12 +4,12 @@
|
||||||
#ifndef __DOXYGEN_IGNORE__
|
#ifndef __DOXYGEN_IGNORE__
|
||||||
|
|
||||||
#include "Athena/Types.hpp"
|
#include "Athena/Types.hpp"
|
||||||
int bn_compare(Uint8 *a, Uint8 *b, Uint32 n);
|
int bn_compare(atUint8 *a, atUint8 *b, atUint32 n);
|
||||||
void bn_sub_modulus(Uint8 *a, Uint8 *N, Uint32 n);
|
void bn_sub_modulus(atUint8 *a, atUint8 *N, atUint32 n);
|
||||||
void bn_add(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n);
|
void bn_add(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n);
|
||||||
void bn_mul(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n);
|
void bn_mul(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n);
|
||||||
void bn_exp(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n, Uint8 *e, Uint32 en);
|
void bn_exp(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n, atUint8 *e, atUint32 en);
|
||||||
void bn_inv(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n);
|
void bn_inv(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n);
|
||||||
|
|
||||||
#endif // __DOXYGEN_IGNORE__
|
#endif // __DOXYGEN_IGNORE__
|
||||||
#endif // BN_H
|
#endif // BN_H
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#define EC_H
|
#define EC_H
|
||||||
#include "Athena/Types.hpp"
|
#include "Athena/Types.hpp"
|
||||||
|
|
||||||
bool check_ec ( Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash );
|
bool check_ec ( atUint8 *ng, atUint8 *ap, atUint8 *sig, atUint8 *sig_hash );
|
||||||
void make_ec_cert ( Uint8 *cert, Uint8 *sig, char *signer, char *name, Uint8 *priv, Uint32 key_id );
|
void make_ec_cert ( atUint8 *cert, atUint8 *sig, char *signer, char *name, atUint8 *priv, atUint32 key_id );
|
||||||
void generate_ecdsa( Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash );
|
void generate_ecdsa( atUint8 *R, atUint8 *S, atUint8 *k, atUint8 *hash );
|
||||||
|
|
||||||
#endif // EC_H
|
#endif // EC_H
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ typedef unsigned char uint8_t;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int lzo1x_decode(Uint8 *out, Int32 *outlen, Uint8 *in, Int32 *inlen);
|
int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ void SHA1Input( SHA1Context *,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Uint8* getSha1( Uint8 * stuff, Uint32 stuff_size );
|
atUint8* getSha1( atUint8 * stuff, atUint32 stuff_size );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -29,7 +30,7 @@ ALTTPFile::ALTTPFile(std::vector<ALTTPQuest*> quests, std::vector<ALTTPQuest*> b
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPFile::setQuest(Uint32 id, ALTTPQuest* val)
|
void ALTTPFile::setQuest(atUint32 id, ALTTPQuest* val)
|
||||||
{
|
{
|
||||||
if (id > m_quests.size())
|
if (id > m_quests.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -41,7 +42,7 @@ std::vector<ALTTPQuest*> ALTTPFile::questList() const
|
||||||
{
|
{
|
||||||
return m_quests;
|
return m_quests;
|
||||||
}
|
}
|
||||||
ALTTPQuest* ALTTPFile::quest(Uint32 id) const
|
ALTTPQuest* ALTTPFile::quest(atUint32 id) const
|
||||||
{
|
{
|
||||||
if (id > m_quests.size())
|
if (id > m_quests.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -49,8 +50,10 @@ ALTTPQuest* ALTTPFile::quest(Uint32 id) const
|
||||||
return m_quests[id];
|
return m_quests[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 ALTTPFile::questCount() const
|
atUint32 ALTTPFile::questCount() const
|
||||||
{
|
{
|
||||||
return m_quests.size();
|
return m_quests.size();
|
||||||
}
|
}
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -23,7 +24,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
ALTTPFileReader::ALTTPFileReader(Uint8* data, Uint64 length)
|
ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -38,17 +39,17 @@ ALTTPFile* ALTTPFileReader::readFile()
|
||||||
std::vector<ALTTPQuest*> quests;
|
std::vector<ALTTPQuest*> quests;
|
||||||
std::vector<ALTTPQuest*> backup;
|
std::vector<ALTTPQuest*> backup;
|
||||||
|
|
||||||
for (Uint32 i = 0; i < 6; i++)
|
for (atUint32 i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
// Temporary values to use for each save
|
// Temporary values to use for each save
|
||||||
ALTTPQuest* quest = new ALTTPQuest();
|
ALTTPQuest* quest = new ALTTPQuest();
|
||||||
std::vector<ALTTPRoomFlags*> roomFlags;
|
std::vector<ALTTPRoomFlags*> roomFlags;
|
||||||
std::vector<ALTTPOverworldEvent*> owEvents;
|
std::vector<ALTTPOverworldEvent*> owEvents;
|
||||||
std::vector<Uint8> dungeonKeys;
|
std::vector<atUint8> dungeonKeys;
|
||||||
std::vector<Uint8> oldmanFlags;
|
std::vector<atUint8> oldmanFlags;
|
||||||
std::vector<Uint8> unknown1;
|
std::vector<atUint8> unknown1;
|
||||||
std::vector<Uint16> playerName;
|
std::vector<atUint16> playerName;
|
||||||
std::vector<Uint16> dungeonDeaths;
|
std::vector<atUint16> dungeonDeaths;
|
||||||
|
|
||||||
int j = 0x140;
|
int j = 0x140;
|
||||||
while ((j--) > 0)
|
while ((j--) > 0)
|
||||||
|
@ -233,3 +234,5 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -24,7 +25,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
ALTTPFileWriter::ALTTPFileWriter(Uint8* data, Uint64 length)
|
ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ ALTTPFileWriter::ALTTPFileWriter(const std::string& filename)
|
||||||
void ALTTPFileWriter::writeFile(ALTTPFile* file)
|
void ALTTPFileWriter::writeFile(ALTTPFile* file)
|
||||||
{
|
{
|
||||||
ALTTPQuest* quest = NULL;
|
ALTTPQuest* quest = NULL;
|
||||||
for (Uint32 i = 0; i < 6; i++)
|
for (atUint32 i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if (i < 3)
|
if (i < 3)
|
||||||
quest = file->quest(i);
|
quest = file->quest(i);
|
||||||
|
@ -54,7 +55,7 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
|
||||||
writeOverworldEvent(quest->overworldEvent(j));
|
writeOverworldEvent(quest->overworldEvent(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
base::writeBytes((Int8*)quest->inventory(), sizeof(ALTTPInventory));
|
base::writeBytes((atInt8*)quest->inventory(), sizeof(ALTTPInventory));
|
||||||
base::writeUint16(quest->rupeeMax());
|
base::writeUint16(quest->rupeeMax());
|
||||||
base::writeUint16(quest->rupeeCurrent());
|
base::writeUint16(quest->rupeeCurrent());
|
||||||
writeDungeonItems(quest->compasses());
|
writeDungeonItems(quest->compasses());
|
||||||
|
@ -87,23 +88,23 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
|
||||||
base::writeBit(abilities.Read);
|
base::writeBit(abilities.Read);
|
||||||
base::writeBit(abilities.Unknown2);
|
base::writeBit(abilities.Unknown2);
|
||||||
ALTTPCrystals crystals = quest->crystals();
|
ALTTPCrystals crystals = quest->crystals();
|
||||||
base::writeBytes((Int8*)&crystals, sizeof(ALTTPCrystals));
|
base::writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals));
|
||||||
ALTTPMagicUsage magicUsage = quest->magicUsage();
|
ALTTPMagicUsage magicUsage = quest->magicUsage();
|
||||||
base::writeBytes((Int8*)&magicUsage, sizeof(ALTTPMagicUsage));
|
base::writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage));
|
||||||
|
|
||||||
for (int j = 0; j < 0x010; j++)
|
for (int j = 0; j < 0x010; j++)
|
||||||
base::writeByte(quest->dungeonKeys(j));
|
base::writeByte(quest->dungeonKeys(j));
|
||||||
|
|
||||||
base::seek(0x039);
|
base::seek(0x039);
|
||||||
base::writeByte((Int8)quest->progressIndicator());
|
base::writeByte((atInt8)quest->progressIndicator());
|
||||||
ALTTPProgressFlags1 progress1 = quest->progressFlags1();
|
ALTTPProgressFlags1 progress1 = quest->progressFlags1();
|
||||||
base::writeBytes((Int8*)&progress1, sizeof(ALTTPProgressFlags1));
|
base::writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1));
|
||||||
base::writeByte(quest->mapIcon());
|
base::writeByte(quest->mapIcon());
|
||||||
base::writeByte(quest->startLocation());
|
base::writeByte(quest->startLocation());
|
||||||
ALTTPProgressFlags2 progress2 = quest->progressFlags2();
|
ALTTPProgressFlags2 progress2 = quest->progressFlags2();
|
||||||
base::writeBytes((Int8*)&progress2, sizeof(ALTTPProgressFlags2));
|
base::writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2));
|
||||||
ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator();
|
ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator();
|
||||||
base::writeBytes((Int8*)&indicator, 1);
|
base::writeBytes((atInt8*)&indicator, 1);
|
||||||
base::seek(1);
|
base::seek(1);
|
||||||
base::writeByte(quest->tagAlong());
|
base::writeByte(quest->tagAlong());
|
||||||
|
|
||||||
|
@ -184,7 +185,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
|
||||||
base::writeBit(flags.SewerPassage);
|
base::writeBit(flags.SewerPassage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game)
|
atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* ALTTP's checksum is very basic
|
* ALTTP's checksum is very basic
|
||||||
|
@ -202,10 +203,10 @@ Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// First we start at 0
|
// First we start at 0
|
||||||
Uint16 sum = 0;
|
atUint16 sum = 0;
|
||||||
for (Uint32 i = 0; i < 0x4FE; i += 2)
|
for (atUint32 i = 0; i < 0x4FE; i += 2)
|
||||||
// Add each word one by one
|
// Add each word one by one
|
||||||
sum += *(Uint16*)(m_data + (i + (0x500 * game)));
|
sum += *(atUint16*)(m_data + (i + (0x500 * game)));
|
||||||
|
|
||||||
// Subtract it from 0x5a5a to get our true checksum
|
// Subtract it from 0x5a5a to get our true checksum
|
||||||
return (0x5a5a - sum);
|
return (0x5a5a - sum);
|
||||||
|
@ -220,3 +221,4 @@ Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game)
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -38,7 +39,7 @@ void ALTTPQuest::setRoomFlags(std::vector<ALTTPRoomFlags*> rf)
|
||||||
m_roomFlags = rf;
|
m_roomFlags = rf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, Uint32 id)
|
void ALTTPQuest::setRoomFlags(ALTTPRoomFlags* rf, atUint32 id)
|
||||||
{
|
{
|
||||||
m_roomFlags[id] = rf;
|
m_roomFlags[id] = rf;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +49,7 @@ std::vector<ALTTPRoomFlags*> ALTTPQuest::roomFlags()
|
||||||
return m_roomFlags;
|
return m_roomFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALTTPRoomFlags* ALTTPQuest::roomFlags(Uint32 id)
|
ALTTPRoomFlags* ALTTPQuest::roomFlags(atUint32 id)
|
||||||
{
|
{
|
||||||
return m_roomFlags[id];
|
return m_roomFlags[id];
|
||||||
}
|
}
|
||||||
|
@ -58,7 +59,7 @@ void ALTTPQuest::setOverworldEvents(std::vector<ALTTPOverworldEvent*> ow)
|
||||||
m_overworldEvents = ow;
|
m_overworldEvents = ow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, Uint32 id)
|
void ALTTPQuest::setOverworldEvents(ALTTPOverworldEvent* ow, atUint32 id)
|
||||||
{
|
{
|
||||||
m_overworldEvents[id] = ow;
|
m_overworldEvents[id] = ow;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +69,7 @@ std::vector<ALTTPOverworldEvent*> ALTTPQuest::overworldEvents() const
|
||||||
return m_overworldEvents;
|
return m_overworldEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALTTPOverworldEvent* ALTTPQuest::overworldEvent(Uint32 id) const
|
ALTTPOverworldEvent* ALTTPQuest::overworldEvent(atUint32 id) const
|
||||||
{
|
{
|
||||||
if (id > m_overworldEvents.size() - 1)
|
if (id > m_overworldEvents.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -85,22 +86,22 @@ ALTTPInventory* ALTTPQuest::inventory() const
|
||||||
return m_inventory;
|
return m_inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setRupeeMax(Uint16 val)
|
void ALTTPQuest::setRupeeMax(atUint16 val)
|
||||||
{
|
{
|
||||||
m_rupeeMax = val;
|
m_rupeeMax = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::rupeeMax() const
|
atUint16 ALTTPQuest::rupeeMax() const
|
||||||
{
|
{
|
||||||
return m_rupeeMax;
|
return m_rupeeMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setRupeeCurrent(Uint16 val)
|
void ALTTPQuest::setRupeeCurrent(atUint16 val)
|
||||||
{
|
{
|
||||||
m_rupeeCurrent = val;
|
m_rupeeCurrent = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::rupeeCurrent() const
|
atUint16 ALTTPQuest::rupeeCurrent() const
|
||||||
{
|
{
|
||||||
return m_rupeeCurrent;
|
return m_rupeeCurrent;
|
||||||
}
|
}
|
||||||
|
@ -135,91 +136,91 @@ ALTTPDungeonItemFlags ALTTPQuest::dungeonMaps() const
|
||||||
return m_dungeonMaps;
|
return m_dungeonMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setWishingPond(Uint16 val)
|
void ALTTPQuest::setWishingPond(atUint16 val)
|
||||||
{
|
{
|
||||||
m_wishingPond = val;
|
m_wishingPond = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::wishingPond() const
|
atUint16 ALTTPQuest::wishingPond() const
|
||||||
{
|
{
|
||||||
return m_wishingPond;
|
return m_wishingPond;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setHealthMax(Uint8 val)
|
void ALTTPQuest::setHealthMax(atUint8 val)
|
||||||
{
|
{
|
||||||
m_healthMax = val;
|
m_healthMax = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::healthMax() const
|
atUint8 ALTTPQuest::healthMax() const
|
||||||
{
|
{
|
||||||
return m_healthMax;
|
return m_healthMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setHealth(Uint8 val)
|
void ALTTPQuest::setHealth(atUint8 val)
|
||||||
{
|
{
|
||||||
m_health = val;
|
m_health = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::health() const
|
atUint8 ALTTPQuest::health() const
|
||||||
{
|
{
|
||||||
return m_health;
|
return m_health;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setMagicPower(Uint8 val)
|
void ALTTPQuest::setMagicPower(atUint8 val)
|
||||||
{
|
{
|
||||||
m_magicPower = val;
|
m_magicPower = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::magicPower() const
|
atUint8 ALTTPQuest::magicPower() const
|
||||||
{
|
{
|
||||||
return m_magicPower;
|
return m_magicPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setKeys(Uint8 val)
|
void ALTTPQuest::setKeys(atUint8 val)
|
||||||
{
|
{
|
||||||
m_keys = val;
|
m_keys = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::keys() const
|
atUint8 ALTTPQuest::keys() const
|
||||||
{
|
{
|
||||||
return m_keys;
|
return m_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setBombUpgrades(Uint8 val)
|
void ALTTPQuest::setBombUpgrades(atUint8 val)
|
||||||
{
|
{
|
||||||
m_bombUpgrades = val;
|
m_bombUpgrades = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::bombUpgrades() const
|
atUint8 ALTTPQuest::bombUpgrades() const
|
||||||
{
|
{
|
||||||
return m_bombUpgrades;
|
return m_bombUpgrades;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setArrowUpgrades(Uint8 val)
|
void ALTTPQuest::setArrowUpgrades(atUint8 val)
|
||||||
{
|
{
|
||||||
m_arrowUpgrades = val;
|
m_arrowUpgrades = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::arrowUpgrades() const
|
atUint8 ALTTPQuest::arrowUpgrades() const
|
||||||
{
|
{
|
||||||
return m_arrowUpgrades;
|
return m_arrowUpgrades;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setHealthFiller(Uint8 val)
|
void ALTTPQuest::setHealthFiller(atUint8 val)
|
||||||
{
|
{
|
||||||
m_heartFiller = val;
|
m_heartFiller = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::healthFiller() const
|
atUint8 ALTTPQuest::healthFiller() const
|
||||||
{
|
{
|
||||||
return m_heartFiller;
|
return m_heartFiller;
|
||||||
}
|
}
|
||||||
void ALTTPQuest::setMagicFiller(Uint8 val)
|
void ALTTPQuest::setMagicFiller(atUint8 val)
|
||||||
{
|
{
|
||||||
m_heartFiller = val;
|
m_heartFiller = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::magicFiller() const
|
atUint8 ALTTPQuest::magicFiller() const
|
||||||
{
|
{
|
||||||
return m_heartFiller;
|
return m_heartFiller;
|
||||||
}
|
}
|
||||||
|
@ -234,31 +235,31 @@ ALTTPPendants ALTTPQuest::pendants() const
|
||||||
return m_pendants;
|
return m_pendants;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setBombFiller(Uint8 val)
|
void ALTTPQuest::setBombFiller(atUint8 val)
|
||||||
{
|
{
|
||||||
m_bombFiller = val;
|
m_bombFiller = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::bombFiller() const
|
atUint8 ALTTPQuest::bombFiller() const
|
||||||
{
|
{
|
||||||
return m_bombFiller;
|
return m_bombFiller;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setArrowFiller(Uint8 val)
|
void ALTTPQuest::setArrowFiller(atUint8 val)
|
||||||
{
|
{
|
||||||
m_arrowFiller = val;
|
m_arrowFiller = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::arrowFiller() const
|
atUint8 ALTTPQuest::arrowFiller() const
|
||||||
{
|
{
|
||||||
return m_arrowFiller;
|
return m_arrowFiller;
|
||||||
}
|
}
|
||||||
void ALTTPQuest::setArrows(Uint8 val)
|
void ALTTPQuest::setArrows(atUint8 val)
|
||||||
{
|
{
|
||||||
m_arrows = val;
|
m_arrows = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::arrows() const
|
atUint8 ALTTPQuest::arrows() const
|
||||||
{
|
{
|
||||||
return m_arrows;
|
return m_arrows;
|
||||||
}
|
}
|
||||||
|
@ -293,12 +294,12 @@ ALTTPMagicUsage ALTTPQuest::magicUsage() const
|
||||||
return m_magicUsage;
|
return m_magicUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setDungeonKeys(std::vector<Uint8> val)
|
void ALTTPQuest::setDungeonKeys(std::vector<atUint8> val)
|
||||||
{
|
{
|
||||||
m_dungeonKeys = val;
|
m_dungeonKeys = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setDungeonKeys(Uint32 id, Uint8 val)
|
void ALTTPQuest::setDungeonKeys(atUint32 id, atUint8 val)
|
||||||
{
|
{
|
||||||
if (id > m_dungeonKeys.size() - 1)
|
if (id > m_dungeonKeys.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -306,7 +307,7 @@ void ALTTPQuest::setDungeonKeys(Uint32 id, Uint8 val)
|
||||||
m_dungeonKeys[id] = val;
|
m_dungeonKeys[id] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::dungeonKeys(Uint32 id) const
|
atUint8 ALTTPQuest::dungeonKeys(atUint32 id) const
|
||||||
{
|
{
|
||||||
if (id > m_dungeonKeys.size() - 1)
|
if (id > m_dungeonKeys.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -314,7 +315,7 @@ Uint8 ALTTPQuest::dungeonKeys(Uint32 id) const
|
||||||
return m_dungeonKeys[id];
|
return m_dungeonKeys[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 ALTTPQuest::dungeonCount() const
|
atUint32 ALTTPQuest::dungeonCount() const
|
||||||
{
|
{
|
||||||
return m_dungeonKeys.size();
|
return m_dungeonKeys.size();
|
||||||
}
|
}
|
||||||
|
@ -390,12 +391,12 @@ ALTTPTagAlong ALTTPQuest::tagAlong() const
|
||||||
return m_tagAlong;
|
return m_tagAlong;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setOldManFlags(std::vector<Uint8> flags)
|
void ALTTPQuest::setOldManFlags(std::vector<atUint8> flags)
|
||||||
{
|
{
|
||||||
m_oldManFlags = flags;
|
m_oldManFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setOldManFlag(Uint32 id, Uint8 val)
|
void ALTTPQuest::setOldManFlag(atUint32 id, atUint8 val)
|
||||||
{
|
{
|
||||||
if (id > m_oldManFlags.size() - 1)
|
if (id > m_oldManFlags.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -403,7 +404,7 @@ void ALTTPQuest::setOldManFlag(Uint32 id, Uint8 val)
|
||||||
m_oldManFlags[id] = val;
|
m_oldManFlags[id] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::oldManFlag(Uint32 id)
|
atUint8 ALTTPQuest::oldManFlag(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id > m_oldManFlags.size() - 1)
|
if (id > m_oldManFlags.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -411,27 +412,27 @@ Uint8 ALTTPQuest::oldManFlag(Uint32 id)
|
||||||
return m_oldManFlags[id];
|
return m_oldManFlags[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 ALTTPQuest::oldManFlagCount() const
|
atUint32 ALTTPQuest::oldManFlagCount() const
|
||||||
{
|
{
|
||||||
return m_oldManFlags.size();
|
return m_oldManFlags.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setBombFlag(Uint8 flag)
|
void ALTTPQuest::setBombFlag(atUint8 flag)
|
||||||
{
|
{
|
||||||
m_bombFlag = flag;
|
m_bombFlag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::bombFlag() const
|
atUint8 ALTTPQuest::bombFlag() const
|
||||||
{
|
{
|
||||||
return m_bombFlag;
|
return m_bombFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setUnknown1(std::vector<Uint8> flags)
|
void ALTTPQuest::setUnknown1(std::vector<atUint8> flags)
|
||||||
{
|
{
|
||||||
m_unknown1 = flags;
|
m_unknown1 = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setUnknown1(Uint32 id, Uint8 val)
|
void ALTTPQuest::setUnknown1(atUint32 id, atUint8 val)
|
||||||
{
|
{
|
||||||
if (id > m_unknown1.size())
|
if (id > m_unknown1.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -439,7 +440,7 @@ void ALTTPQuest::setUnknown1(Uint32 id, Uint8 val)
|
||||||
m_unknown1[id] = val;
|
m_unknown1[id] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ALTTPQuest::unknown1(Uint32 id)
|
atUint8 ALTTPQuest::unknown1(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id > m_unknown1.size())
|
if (id > m_unknown1.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -447,12 +448,12 @@ Uint8 ALTTPQuest::unknown1(Uint32 id)
|
||||||
return m_unknown1[id];
|
return m_unknown1[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 ALTTPQuest::unknown1Count() const
|
atUint32 ALTTPQuest::unknown1Count() const
|
||||||
{
|
{
|
||||||
return m_unknown1.size();
|
return m_unknown1.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setPlayerName(std::vector<Uint16> playerName)
|
void ALTTPQuest::setPlayerName(std::vector<atUint16> playerName)
|
||||||
{
|
{
|
||||||
m_playerName = playerName;
|
m_playerName = playerName;
|
||||||
}
|
}
|
||||||
|
@ -464,30 +465,30 @@ void ALTTPQuest::setPlayerName(const std::string& playerName)
|
||||||
|
|
||||||
m_playerName.clear();
|
m_playerName.clear();
|
||||||
|
|
||||||
for (Uint32 i = 0; i < 6; i++)
|
for (atUint32 i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if (i > playerName.size() - 1)
|
if (i > playerName.size() - 1)
|
||||||
{
|
{
|
||||||
m_playerName.push_back((Uint16)0xA9);
|
m_playerName.push_back((atUint16)0xA9);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char c = playerName[i];
|
char c = playerName[i];
|
||||||
if (c >= 'A' && c <= 'P' && c != 'I')
|
if (c >= 'A' && c <= 'P' && c != 'I')
|
||||||
{
|
{
|
||||||
|
|
||||||
m_playerName.push_back((Uint16)(c - 'A'));
|
m_playerName.push_back((atUint16)(c - 'A'));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= 'Q' && c <= 'Z')
|
if (c >= 'Q' && c <= 'Z')
|
||||||
{
|
{
|
||||||
std::cout << std::hex << (Uint16)((c - 'Q') + 0x20) << std::endl;
|
std::cout << std::hex << (atUint16)((c - 'Q') + 0x20) << std::endl;
|
||||||
m_playerName.push_back((Uint16)((c - 'Q') + 0x20));
|
m_playerName.push_back((atUint16)((c - 'Q') + 0x20));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= 'a' && c <= 'f')
|
if (c >= 'a' && c <= 'f')
|
||||||
{
|
{
|
||||||
std::cout << std::hex << (Uint16)((c - 'a') + 0x2A) << std::endl;
|
std::cout << std::hex << (atUint16)((c - 'a') + 0x2A) << std::endl;
|
||||||
m_playerName.push_back((Uint16)((c - 'a') + 0x2A));
|
m_playerName.push_back((atUint16)((c - 'a') + 0x2A));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= 'g' && c <= 'v')
|
if (c >= 'g' && c <= 'v')
|
||||||
|
@ -502,22 +503,22 @@ void ALTTPQuest::setPlayerName(const std::string& playerName)
|
||||||
m_playerName.push_back(0x44);
|
m_playerName.push_back(0x44);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m_playerName.push_back((Uint16)((c - 'g') + 0x40));
|
m_playerName.push_back((atUint16)((c - 'g') + 0x40));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= 'w' && c <= 'z')
|
if (c >= 'w' && c <= 'z')
|
||||||
{
|
{
|
||||||
m_playerName.push_back((Uint16)((c - 'w') + 0x60));
|
m_playerName.push_back((atUint16)((c - 'w') + 0x60));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
m_playerName.push_back((Uint16)((c - '0') + 0x64));
|
m_playerName.push_back((atUint16)((c - '0') + 0x64));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '-' || c == '.')
|
if (c == '-' || c == '.')
|
||||||
{
|
{
|
||||||
m_playerName.push_back((Uint16)(c - '-') + 0x80);
|
m_playerName.push_back((atUint16)(c - '-') + 0x80);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,7 +534,7 @@ void ALTTPQuest::setPlayerName(const std::string& playerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Uint16> ALTTPQuest::playerName() const
|
std::vector<atUint16> ALTTPQuest::playerName() const
|
||||||
{
|
{
|
||||||
return m_playerName;
|
return m_playerName;
|
||||||
}
|
}
|
||||||
|
@ -541,11 +542,11 @@ std::vector<Uint16> ALTTPQuest::playerName() const
|
||||||
std::string ALTTPQuest::playerNameToString() const
|
std::string ALTTPQuest::playerNameToString() const
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
std::vector<Uint16>::const_iterator iter = m_playerName.begin();
|
std::vector<atUint16>::const_iterator iter = m_playerName.begin();
|
||||||
|
|
||||||
for (; iter != m_playerName.end(); ++iter)
|
for (; iter != m_playerName.end(); ++iter)
|
||||||
{
|
{
|
||||||
Int16 c = *iter;
|
atInt16 c = *iter;
|
||||||
|
|
||||||
if (c >= 0x00 && c <= 0x0F)
|
if (c >= 0x00 && c <= 0x0F)
|
||||||
{
|
{
|
||||||
|
@ -615,12 +616,12 @@ bool ALTTPQuest::valid()
|
||||||
return m_valid;
|
return m_valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setDungeonDeathTotals(std::vector<Uint16> val)
|
void ALTTPQuest::setDungeonDeathTotals(std::vector<atUint16> val)
|
||||||
{
|
{
|
||||||
m_dungeonDeathTotals = val;
|
m_dungeonDeathTotals = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setDungeonDeathTotal(Uint32 id, Uint16 val)
|
void ALTTPQuest::setDungeonDeathTotal(atUint32 id, atUint16 val)
|
||||||
{
|
{
|
||||||
if (id > m_dungeonDeathTotals.size())
|
if (id > m_dungeonDeathTotals.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -628,7 +629,7 @@ void ALTTPQuest::setDungeonDeathTotal(Uint32 id, Uint16 val)
|
||||||
m_dungeonDeathTotals[id] = val;
|
m_dungeonDeathTotals[id] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::dungeonDeathTotal(Uint32 id) const
|
atUint16 ALTTPQuest::dungeonDeathTotal(atUint32 id) const
|
||||||
{
|
{
|
||||||
if (id > m_dungeonDeathTotals.size())
|
if (id > m_dungeonDeathTotals.size())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -636,48 +637,49 @@ Uint16 ALTTPQuest::dungeonDeathTotal(Uint32 id) const
|
||||||
return m_dungeonDeathTotals[id];
|
return m_dungeonDeathTotals[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::dungeonDeathTotalCount() const
|
atUint16 ALTTPQuest::dungeonDeathTotalCount() const
|
||||||
{
|
{
|
||||||
return m_dungeonDeathTotals.size();
|
return m_dungeonDeathTotals.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setUnknown2(Uint16 val)
|
void ALTTPQuest::setUnknown2(atUint16 val)
|
||||||
{
|
{
|
||||||
m_unknown2 = val;
|
m_unknown2 = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::unknown2() const
|
atUint16 ALTTPQuest::unknown2() const
|
||||||
{
|
{
|
||||||
return m_unknown2;
|
return m_unknown2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setDeathSaveCount(Uint16 val)
|
void ALTTPQuest::setDeathSaveCount(atUint16 val)
|
||||||
{
|
{
|
||||||
m_deathSaveCount = val;
|
m_deathSaveCount = val;
|
||||||
}
|
}
|
||||||
Uint16 ALTTPQuest::deathSaveCount() const
|
atUint16 ALTTPQuest::deathSaveCount() const
|
||||||
{
|
{
|
||||||
return m_deathSaveCount;
|
return m_deathSaveCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setPostGameDeathCounter(Int16 val)
|
void ALTTPQuest::setPostGameDeathCounter(atInt16 val)
|
||||||
{
|
{
|
||||||
m_postGameDeathCounter = val;
|
m_postGameDeathCounter = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int16 ALTTPQuest::postGameDeathCounter() const
|
atInt16 ALTTPQuest::postGameDeathCounter() const
|
||||||
{
|
{
|
||||||
return m_postGameDeathCounter;
|
return m_postGameDeathCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALTTPQuest::setChecksum(Uint16 checksum)
|
void ALTTPQuest::setChecksum(atUint16 checksum)
|
||||||
{
|
{
|
||||||
m_checksum = checksum;
|
m_checksum = checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 ALTTPQuest::checksum() const
|
atUint16 ALTTPQuest::checksum() const
|
||||||
{
|
{
|
||||||
return m_checksum;
|
return m_checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
BinaryReader::BinaryReader(const Uint8* data, Uint64 length)
|
BinaryReader::BinaryReader(const atUint8* data, atUint64 length)
|
||||||
: m_length(length),
|
: m_length(length),
|
||||||
m_position(0),
|
m_position(0),
|
||||||
m_bitPosition(0),
|
m_bitPosition(0),
|
||||||
|
@ -46,7 +46,7 @@ BinaryReader::BinaryReader(const Uint8* data, Uint64 length)
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("length cannot be 0");
|
THROW_INVALID_OPERATION_EXCEPTION("length cannot be 0");
|
||||||
|
|
||||||
m_data = new Uint8[m_length];
|
m_data = new atUint8[m_length];
|
||||||
memcpy(m_data, data, m_length);
|
memcpy(m_data, data, m_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,22 +93,22 @@ bool BinaryReader::isOpen() const
|
||||||
return m_data != nullptr;
|
return m_data != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryReader::seek(Int64 position, SeekOrigin origin)
|
void BinaryReader::seek(atInt64 position, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
switch (origin)
|
switch (origin)
|
||||||
{
|
{
|
||||||
case SeekOrigin::Begin:
|
case SeekOrigin::Begin:
|
||||||
if ((position < 0 || (Int64)position > (Int64)m_length))
|
if ((position < 0 || (atInt64)position > (atInt64)m_length))
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
||||||
m_position = position;
|
m_position = position;
|
||||||
break;
|
break;
|
||||||
case SeekOrigin::Current:
|
case SeekOrigin::Current:
|
||||||
if ((((Int64)m_position + position) < 0 || (m_position + position) > m_length))
|
if ((((atInt64)m_position + position) < 0 || (m_position + position) > m_length))
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
||||||
m_position += position;
|
m_position += position;
|
||||||
break;
|
break;
|
||||||
case SeekOrigin::End:
|
case SeekOrigin::End:
|
||||||
if ((((Int64)m_length - position < 0) || (m_length - position) > m_length))
|
if ((((atInt64)m_length - position < 0) || (m_length - position) > m_length))
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", position);
|
||||||
m_position = m_length - position;
|
m_position = m_length - position;
|
||||||
break;
|
break;
|
||||||
|
@ -120,30 +120,30 @@ bool BinaryReader::atEnd() const
|
||||||
return m_position >= m_length;
|
return m_position >= m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 BinaryReader::position() const
|
atUint64 BinaryReader::position() const
|
||||||
{
|
{
|
||||||
return m_position;
|
return m_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 BinaryReader::length() const
|
atUint64 BinaryReader::length() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryReader::setData(const Uint8* data, Uint64 length)
|
void BinaryReader::setData(const atUint8* data, atUint64 length)
|
||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data)
|
||||||
delete[] m_data;
|
delete[] m_data;
|
||||||
|
|
||||||
m_data = (Uint8*)data;
|
m_data = (atUint8*)data;
|
||||||
m_length = length;
|
m_length = length;
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* BinaryReader::data() const
|
atUint8* BinaryReader::data() const
|
||||||
{
|
{
|
||||||
Uint8* ret = new Uint8[m_length];
|
atUint8* ret = new atUint8[m_length];
|
||||||
memset(ret, 0, m_length);
|
memset(ret, 0, m_length);
|
||||||
memcpy(ret, m_data, m_length);
|
memcpy(ret, m_data, m_length);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -177,19 +177,19 @@ bool BinaryReader::readBit()
|
||||||
if (m_position > m_length)
|
if (m_position > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
|
||||||
bool ret = (*(Uint8*)(m_data + m_position) & (1 << m_bitPosition));
|
bool ret = (*(atUint8*)(m_data + m_position) & (1 << m_bitPosition));
|
||||||
|
|
||||||
m_bitPosition++;
|
m_bitPosition++;
|
||||||
if (m_bitPosition > 7)
|
if (m_bitPosition > 7)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8 BinaryReader::readByte()
|
atInt8 BinaryReader::readByte()
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -197,15 +197,15 @@ Int8 BinaryReader::readByte()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + 1 > m_length)
|
if (m_position + 1 > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
|
||||||
return *(Int8*)(m_data + m_position++);
|
return *(atInt8*)(m_data + m_position++);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 BinaryReader::readUByte()
|
atUint8 BinaryReader::readUByte()
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -216,20 +216,20 @@ Uint8 BinaryReader::readUByte()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + 1 > m_length)
|
if (m_position + 1 > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
|
||||||
return *(Uint8*)(m_data + m_position++);
|
return *(atUint8*)(m_data + m_position++);
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8* BinaryReader::readBytes(Int64 length)
|
atInt8* BinaryReader::readBytes(atInt64 length)
|
||||||
{
|
{
|
||||||
return (Int8*)readUBytes(length);
|
return (atInt8*)readUBytes(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* BinaryReader::readUBytes(Int64 length)
|
atUint8* BinaryReader::readUBytes(atInt64 length)
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -237,21 +237,21 @@ Uint8* BinaryReader::readUBytes(Int64 length)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + length > m_length)
|
if (m_position + length > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
|
||||||
Uint8* ret;
|
atUint8* ret;
|
||||||
ret = new Uint8[length];
|
ret = new atUint8[length];
|
||||||
|
|
||||||
memcpy(ret, (const Uint8*)(m_data + m_position), length);
|
memcpy(ret, (const atUint8*)(m_data + m_position), length);
|
||||||
m_position += length;
|
m_position += length;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int16 BinaryReader::readInt16()
|
atInt16 BinaryReader::readInt16()
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -259,25 +259,25 @@ Int16 BinaryReader::readInt16()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int16) > m_length)
|
if (m_position + sizeof(atInt16) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
Int16 ret = *(Int16*)(m_data + m_position);
|
atInt16 ret = *(atInt16*)(m_data + m_position);
|
||||||
m_position += sizeof(Int16);
|
m_position += sizeof(atInt16);
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
ret = utility::swap16(ret);
|
ret = utility::swap16(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 BinaryReader::readUint16()
|
atUint16 BinaryReader::readUint16()
|
||||||
{
|
{
|
||||||
return readInt16();
|
return readInt16();
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 BinaryReader::readInt32()
|
atInt32 BinaryReader::readInt32()
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -285,12 +285,12 @@ Int32 BinaryReader::readInt32()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int32) > m_length)
|
if (m_position + sizeof(atInt32) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
Int32 ret = *(Int32*)(m_data + m_position);
|
atInt32 ret = *(atInt32*)(m_data + m_position);
|
||||||
m_position += 4;
|
m_position += 4;
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
|
@ -298,12 +298,12 @@ Int32 BinaryReader::readInt32()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 BinaryReader::readUint32()
|
atUint32 BinaryReader::readUint32()
|
||||||
{
|
{
|
||||||
return readInt32();
|
return readInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
Int64 BinaryReader::readInt64()
|
atInt64 BinaryReader::readInt64()
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
loadData();
|
loadData();
|
||||||
|
@ -311,12 +311,12 @@ Int64 BinaryReader::readInt64()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + sizeof(Int64) > m_length)
|
if (m_position + sizeof(atInt64) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
|
||||||
Int64 ret = *(Int64*)(m_data + m_position);
|
atInt64 ret = *(atInt64*)(m_data + m_position);
|
||||||
m_position += 8;
|
m_position += 8;
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
|
@ -324,7 +324,7 @@ Int64 BinaryReader::readInt64()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 BinaryReader::readUint64()
|
atUint64 BinaryReader::readUint64()
|
||||||
{
|
{
|
||||||
return readUint64();
|
return readUint64();
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ float BinaryReader::readFloat()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + sizeof(float) > m_length)
|
if (m_position + sizeof(float) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
@ -358,7 +358,7 @@ double BinaryReader::readDouble()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + sizeof(double) > m_length)
|
if (m_position + sizeof(double) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
@ -380,7 +380,7 @@ bool BinaryReader::readBool()
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + sizeof(bool) > m_length)
|
if (m_position + sizeof(bool) > m_length)
|
||||||
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
|
||||||
|
@ -396,7 +396,7 @@ std::string BinaryReader::readUnicode()
|
||||||
loadData();
|
loadData();
|
||||||
std::string ret;
|
std::string ret;
|
||||||
std::vector<short> tmp;
|
std::vector<short> tmp;
|
||||||
Uint16 chr = readUint16();
|
atUint16 chr = readUint16();
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if (!chr)
|
if (!chr)
|
||||||
|
@ -412,7 +412,7 @@ std::string BinaryReader::readUnicode()
|
||||||
std::string BinaryReader::readString()
|
std::string BinaryReader::readString()
|
||||||
{
|
{
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
Uint8 chr = readByte();
|
atUint8 chr = readByte();
|
||||||
|
|
||||||
while (chr != 0)
|
while (chr != 0)
|
||||||
{
|
{
|
||||||
|
@ -431,7 +431,7 @@ void BinaryReader::setProgressCallback(std::function<void (int)> cb)
|
||||||
void BinaryReader::loadData()
|
void BinaryReader::loadData()
|
||||||
{
|
{
|
||||||
FILE* in;
|
FILE* in;
|
||||||
Uint32 length;
|
atUint32 length;
|
||||||
in = fopen(m_filepath.c_str(), "rb");
|
in = fopen(m_filepath.c_str(), "rb");
|
||||||
|
|
||||||
if (!in)
|
if (!in)
|
||||||
|
@ -443,17 +443,17 @@ void BinaryReader::loadData()
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
m_data = (Uint8*)memalign(32, length);
|
m_data = (Uint8*)memalign(32, length);
|
||||||
#else
|
#else
|
||||||
m_data = new Uint8[length];
|
m_data = new atUint8[length];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Uint32 done = 0;
|
atUint32 done = 0;
|
||||||
Uint32 blocksize = BLOCKSZ;
|
atUint32 blocksize = BLOCKSZ;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (blocksize > length - done)
|
if (blocksize > length - done)
|
||||||
blocksize = length - done;
|
blocksize = length - done;
|
||||||
|
|
||||||
Int32 ret = fread(m_data + done, 1, blocksize, in);
|
atInt32 ret = fread(m_data + done, 1, blocksize, in);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
THROW_IO_EXCEPTION("Error reading data from disk");
|
THROW_IO_EXCEPTION("Error reading data from disk");
|
||||||
|
|
|
@ -34,8 +34,8 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
BinaryWriter::BinaryWriter(Uint8* data, Uint64 length)
|
BinaryWriter::BinaryWriter(atUint8* data, atUint64 length)
|
||||||
: m_data((Uint8*)data),
|
: m_data((atUint8*)data),
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_position(0),
|
m_position(0),
|
||||||
m_bitPosition(0),
|
m_bitPosition(0),
|
||||||
|
@ -54,7 +54,7 @@ BinaryWriter::BinaryWriter(const std::string& filename, std::function<void(int)>
|
||||||
m_length = 0x10;
|
m_length = 0x10;
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_data = new Uint8[m_length];
|
m_data = new atUint8[m_length];
|
||||||
|
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
THROW_IO_EXCEPTION("Could not allocate memory!");
|
THROW_IO_EXCEPTION("Could not allocate memory!");
|
||||||
|
@ -95,7 +95,7 @@ bool BinaryWriter::isOpen() const
|
||||||
return m_data != nullptr;
|
return m_data != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::seek(Int64 position, SeekOrigin origin)
|
void BinaryWriter::seek(atInt64 position, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
switch (origin)
|
switch (origin)
|
||||||
{
|
{
|
||||||
|
@ -103,12 +103,12 @@ void BinaryWriter::seek(Int64 position, SeekOrigin origin)
|
||||||
if (position < 0)
|
if (position < 0)
|
||||||
THROW_IO_EXCEPTION("Position outside stream bounds");
|
THROW_IO_EXCEPTION("Position outside stream bounds");
|
||||||
|
|
||||||
if ((Uint64)position > m_length)
|
if ((atUint64)position > m_length)
|
||||||
resize(position);
|
resize(position);
|
||||||
m_position = position;
|
m_position = position;
|
||||||
break;
|
break;
|
||||||
case SeekOrigin::Current:
|
case SeekOrigin::Current:
|
||||||
if ((((Int64)m_position + position) < 0))
|
if ((((atInt64)m_position + position) < 0))
|
||||||
THROW_IO_EXCEPTION("Position outside stream bounds");
|
THROW_IO_EXCEPTION("Position outside stream bounds");
|
||||||
|
|
||||||
if (m_position + position > m_length)
|
if (m_position + position > m_length)
|
||||||
|
@ -117,10 +117,10 @@ void BinaryWriter::seek(Int64 position, SeekOrigin origin)
|
||||||
m_position += position;
|
m_position += position;
|
||||||
break;
|
break;
|
||||||
case SeekOrigin::End:
|
case SeekOrigin::End:
|
||||||
if (((Int64)m_length - position) < 0)
|
if (((atInt64)m_length - position) < 0)
|
||||||
THROW_IO_EXCEPTION("Position outside stream bounds");
|
THROW_IO_EXCEPTION("Position outside stream bounds");
|
||||||
|
|
||||||
if ((Uint64)position > m_length)
|
if ((atUint64)position > m_length)
|
||||||
resize(position);
|
resize(position);
|
||||||
m_position = m_length - position;
|
m_position = m_length - position;
|
||||||
break;
|
break;
|
||||||
|
@ -132,12 +132,12 @@ bool BinaryWriter::atEnd() const
|
||||||
return m_position >= m_length;
|
return m_position >= m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 BinaryWriter::position() const
|
atUint64 BinaryWriter::position() const
|
||||||
{
|
{
|
||||||
return m_position;
|
return m_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 BinaryWriter::length() const
|
atUint64 BinaryWriter::length() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
@ -152,20 +152,20 @@ std::string BinaryWriter::filepath() const
|
||||||
return m_filepath;
|
return m_filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::setData(const Uint8* data, Uint64 length)
|
void BinaryWriter::setData(const atUint8* data, atUint64 length)
|
||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data)
|
||||||
delete[] m_data;
|
delete[] m_data;
|
||||||
|
|
||||||
m_data = (Uint8*)data;
|
m_data = (atUint8*)data;
|
||||||
m_length = length;
|
m_length = length;
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* BinaryWriter::data() const
|
atUint8* BinaryWriter::data() const
|
||||||
{
|
{
|
||||||
Uint8* ret = new Uint8[m_length];
|
atUint8* ret = new atUint8[m_length];
|
||||||
memset(ret, 0, m_length);
|
memset(ret, 0, m_length);
|
||||||
memcpy(ret, m_data, m_length);
|
memcpy(ret, m_data, m_length);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -184,14 +184,14 @@ void BinaryWriter::save(const std::string& filename)
|
||||||
if (!out)
|
if (!out)
|
||||||
THROW_FILE_NOT_FOUND_EXCEPTION(m_filepath);
|
THROW_FILE_NOT_FOUND_EXCEPTION(m_filepath);
|
||||||
|
|
||||||
Uint32 done = 0;
|
atUint32 done = 0;
|
||||||
Uint32 blocksize = BLOCKSZ;
|
atUint32 blocksize = BLOCKSZ;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (blocksize > m_length - done)
|
if (blocksize > m_length - done)
|
||||||
blocksize = m_length - done;
|
blocksize = m_length - done;
|
||||||
|
|
||||||
Int32 ret = fwrite(m_data + done, 1, blocksize, out);
|
atInt32 ret = fwrite(m_data + done, 1, blocksize, out);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
THROW_IO_EXCEPTION("Error writing data to disk");
|
THROW_IO_EXCEPTION("Error writing data to disk");
|
||||||
|
@ -217,22 +217,22 @@ void BinaryWriter::writeBit(bool val)
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
|
||||||
if (m_position + sizeof(Uint8) > m_length)
|
if (m_position + sizeof(atUint8) > m_length)
|
||||||
resize(m_position + sizeof(Uint8));
|
resize(m_position + sizeof(atUint8));
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
*(Uint8*)(m_data + m_position) |= (1 << m_bitPosition);
|
*(atUint8*)(m_data + m_position) |= (1 << m_bitPosition);
|
||||||
else
|
else
|
||||||
*(Uint8*)(m_data + m_position) &= ~(1 << m_bitPosition);
|
*(atUint8*)(m_data + m_position) &= ~(1 << m_bitPosition);
|
||||||
m_bitPosition++;
|
m_bitPosition++;
|
||||||
if (m_bitPosition > 7)
|
if (m_bitPosition > 7)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUByte(Uint8 val)
|
void BinaryWriter::writeUByte(atUint8 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -240,17 +240,17 @@ void BinaryWriter::writeUByte(Uint8 val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
if (m_position + 1 > m_length)
|
if (m_position + 1 > m_length)
|
||||||
resize(m_position + 1);
|
resize(m_position + 1);
|
||||||
|
|
||||||
*(Uint8*)(m_data + m_position) = val;
|
*(atUint8*)(m_data + m_position) = val;
|
||||||
|
|
||||||
m_position++;
|
m_position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeByte(Int8 val)
|
void BinaryWriter::writeByte(atInt8 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -258,7 +258,7 @@ void BinaryWriter::writeByte(Int8 val)
|
||||||
writeUByte(val);
|
writeUByte(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUBytes(Uint8* data, Uint64 length)
|
void BinaryWriter::writeUBytes(atUint8* data, atUint64 length)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -266,7 +266,7 @@ void BinaryWriter::writeUBytes(Uint8* data, Uint64 length)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
|
@ -274,20 +274,20 @@ void BinaryWriter::writeUBytes(Uint8* data, Uint64 length)
|
||||||
if (m_position + length > m_length)
|
if (m_position + length > m_length)
|
||||||
resize(m_position + length);
|
resize(m_position + length);
|
||||||
|
|
||||||
memcpy((Int8*)(m_data + m_position), data, length);
|
memcpy((atInt8*)(m_data + m_position), data, length);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeBytes(Int8* data, Uint64 length)
|
void BinaryWriter::writeBytes(atInt8* data, atUint64 length)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
|
||||||
writeUBytes((Uint8*)data, length);
|
writeUBytes((atUint8*)data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeInt16(Int16 val)
|
void BinaryWriter::writeInt16(atInt16 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -295,20 +295,20 @@ void BinaryWriter::writeInt16(Int16 val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int16) > m_length)
|
if (m_position + sizeof(atInt16) > m_length)
|
||||||
resize(m_position + sizeof(Int16));
|
resize(m_position + sizeof(atInt16));
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swap16(val);
|
val = utility::swap16(val);
|
||||||
|
|
||||||
*(Int16*)(m_data + m_position) = val;
|
*(atInt16*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(Int16);
|
m_position += sizeof(atInt16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUint16(Uint16 val)
|
void BinaryWriter::writeUint16(atUint16 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -316,7 +316,7 @@ void BinaryWriter::writeUint16(Uint16 val)
|
||||||
writeInt16(val);
|
writeInt16(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeInt32(Int32 val)
|
void BinaryWriter::writeInt32(atInt32 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -324,20 +324,20 @@ void BinaryWriter::writeInt32(Int32 val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int32) > m_length)
|
if (m_position + sizeof(atInt32) > m_length)
|
||||||
resize(m_position + sizeof(Int32));
|
resize(m_position + sizeof(atInt32));
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swap32(val);
|
val = utility::swap32(val);
|
||||||
|
|
||||||
*(Int32*)(m_data + m_position) = val;
|
*(atInt32*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(Int32);
|
m_position += sizeof(atInt32);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUint32(Uint32 val)
|
void BinaryWriter::writeUint32(atUint32 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -345,41 +345,41 @@ void BinaryWriter::writeUint32(Uint32 val)
|
||||||
writeInt32(val);
|
writeInt32(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeInt64(Int64 val)
|
void BinaryWriter::writeInt64(atInt64 val)
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int64) > m_length)
|
if (m_position + sizeof(atInt64) > m_length)
|
||||||
resize(m_position + sizeof(Int64));
|
resize(m_position + sizeof(atInt64));
|
||||||
|
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swap64(val);
|
val = utility::swap64(val);
|
||||||
|
|
||||||
*(Int64*)(m_data + m_position) = val;
|
*(atInt64*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(Int64);
|
m_position += sizeof(atInt64);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUint64(Uint64 val)
|
void BinaryWriter::writeUint64(atUint64 val)
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Uint64) > m_length)
|
if (m_position + sizeof(atUint64) > m_length)
|
||||||
resize(m_position + sizeof(Uint64));
|
resize(m_position + sizeof(atUint64));
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU64(val);
|
val = utility::swapU64(val);
|
||||||
|
|
||||||
*(Uint64*)(m_data + m_position) = val;
|
*(atUint64*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(Uint64);
|
m_position += sizeof(atUint64);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeFloat(float val)
|
void BinaryWriter::writeFloat(float val)
|
||||||
|
@ -387,7 +387,7 @@ void BinaryWriter::writeFloat(float val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(float) > m_length)
|
if (m_position + sizeof(float) > m_length)
|
||||||
|
@ -405,7 +405,7 @@ void BinaryWriter::writeDouble(double val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(double) > m_length)
|
if (m_position + sizeof(double) > m_length)
|
||||||
|
@ -423,7 +423,7 @@ void BinaryWriter::writeBool(bool val)
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(atUint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(bool) > m_length)
|
if (m_position + sizeof(bool) > m_length)
|
||||||
|
@ -441,7 +441,7 @@ void BinaryWriter::writeUnicode(const std::string& str)
|
||||||
|
|
||||||
utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp));
|
utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp));
|
||||||
|
|
||||||
for (Uint16 chr : tmp)
|
for (atUint16 chr : tmp)
|
||||||
{
|
{
|
||||||
if (chr != 0xFEFF)
|
if (chr != 0xFEFF)
|
||||||
writeInt16(chr);
|
writeInt16(chr);
|
||||||
|
@ -451,7 +451,7 @@ void BinaryWriter::writeUnicode(const std::string& str)
|
||||||
|
|
||||||
void BinaryWriter::writeString(const std::string& str)
|
void BinaryWriter::writeString(const std::string& str)
|
||||||
{
|
{
|
||||||
for (Uint8 c : str)
|
for (atUint8 c : str)
|
||||||
{
|
{
|
||||||
writeUByte(c);
|
writeUByte(c);
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
|
@ -460,15 +460,15 @@ void BinaryWriter::writeString(const std::string& str)
|
||||||
writeUByte(0);
|
writeUByte(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::fill(Uint8 val, Uint64 length)
|
void BinaryWriter::fill(atUint8 val, atUint64 length)
|
||||||
{
|
{
|
||||||
while ((length--) > 0)
|
while ((length--) > 0)
|
||||||
writeUByte(val);
|
writeUByte(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::fill(Int8 val, Uint64 length)
|
void BinaryWriter::fill(atInt8 val, atUint64 length)
|
||||||
{
|
{
|
||||||
fill((Uint8)val, length);
|
fill((atUint8)val, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::setProgressCallback(std::function<void (int)> cb)
|
void BinaryWriter::setProgressCallback(std::function<void (int)> cb)
|
||||||
|
@ -476,7 +476,7 @@ void BinaryWriter::setProgressCallback(std::function<void (int)> cb)
|
||||||
m_progressCallback = cb;
|
m_progressCallback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::resize(Uint64 newSize)
|
void BinaryWriter::resize(atUint64 newSize)
|
||||||
{
|
{
|
||||||
if (newSize < m_length)
|
if (newSize < m_length)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("Stream::resize() -> New size cannot be less to the old size.");
|
THROW_INVALID_OPERATION_EXCEPTION("Stream::resize() -> New size cannot be less to the old size.");
|
||||||
|
@ -485,7 +485,7 @@ void BinaryWriter::resize(Uint64 newSize)
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
Uint8* newArray = (Uint8*)memalign(32, newSize);
|
Uint8* newArray = (Uint8*)memalign(32, newSize);
|
||||||
#else
|
#else
|
||||||
Uint8* newArray = new Uint8[newSize];
|
atUint8* newArray = new atUint8[newSize];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(newArray, 0, newSize);
|
memset(newArray, 0, newSize);
|
||||||
|
|
|
@ -23,9 +23,9 @@ namespace Athena
|
||||||
namespace Checksums
|
namespace Checksums
|
||||||
{
|
{
|
||||||
|
|
||||||
Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed)
|
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed)
|
||||||
{
|
{
|
||||||
static const Uint32 crc32Table[256] =
|
static const atUint32 crc32Table[256] =
|
||||||
{
|
{
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
||||||
|
@ -64,7 +64,7 @@ Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed)
|
||||||
if (!data)
|
if (!data)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Uint32 checksum = seed;
|
atUint32 checksum = seed;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
while (length--)
|
while (length--)
|
||||||
|
@ -73,9 +73,9 @@ Uint32 crc32(const Uint8* data, Uint64 length, Uint32 seed)
|
||||||
return checksum ^ seed;
|
return checksum ^ seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final)
|
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed, atUint16 final)
|
||||||
{
|
{
|
||||||
static const Uint16 crc16CCITTTable [256] =
|
static const atUint16 crc16CCITTTable [256] =
|
||||||
{
|
{
|
||||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108,
|
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108,
|
||||||
0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
|
0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
|
||||||
|
@ -108,7 +108,7 @@ Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final)
|
||||||
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||||
};
|
};
|
||||||
|
|
||||||
Uint16 checksum = seed;
|
atUint16 checksum = seed;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
while (length--)
|
while (length--)
|
||||||
|
@ -117,9 +117,9 @@ Uint16 crc16CCITT(const Uint8* data, Uint64 length, Uint16 seed, Uint16 final)
|
||||||
return checksum ^ final;
|
return checksum ^ final;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 crc16(const Uint8* data, Uint64 length)
|
atUint16 crc16(const atUint8* data, atUint64 length)
|
||||||
{
|
{
|
||||||
static const Uint16 crc16Table[256] =
|
static const atUint16 crc16Table[256] =
|
||||||
{
|
{
|
||||||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
||||||
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
||||||
|
@ -155,8 +155,8 @@ Uint16 crc16(const Uint8* data, Uint64 length)
|
||||||
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
|
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
|
||||||
};
|
};
|
||||||
|
|
||||||
Int32 pos = 0;
|
atInt32 pos = 0;
|
||||||
Uint16 checksum = 0;
|
atUint16 checksum = 0;
|
||||||
while (length--)
|
while (length--)
|
||||||
checksum = (crc16Table[(checksum ^ data[pos++]) & 0xFF] ^ (checksum >> 8));
|
checksum = (crc16Table[(checksum ^ data[pos++]) & 0xFF] ^ (checksum >> 8));
|
||||||
return checksum;
|
return checksum;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace io
|
||||||
namespace Compression
|
namespace Compression
|
||||||
{
|
{
|
||||||
|
|
||||||
Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen)
|
atInt32 decompressZlib(atUint8 *src, atUint32 srcLen, atUint8* dst, atUint32 dstLen)
|
||||||
{
|
{
|
||||||
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
strm.total_in = strm.avail_in = srcLen;
|
strm.total_in = strm.avail_in = srcLen;
|
||||||
|
@ -38,8 +38,8 @@ Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen)
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
|
|
||||||
Int32 err = -1;
|
atInt32 err = -1;
|
||||||
Int32 ret = -1;
|
atInt32 ret = -1;
|
||||||
|
|
||||||
err = inflateInit(&strm); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
|
err = inflateInit(&strm); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
|
||||||
if (err == Z_OK)
|
if (err == Z_OK)
|
||||||
|
@ -64,7 +64,7 @@ Int32 decompressZlib(Uint8 *src, Uint32 srcLen, Uint8* dst, Uint32 dstLen)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen)
|
atInt32 compressZlib(const atUint8 *src, atUint32 srcLen, atUint8 *dst, atUint32 dstLen)
|
||||||
{
|
{
|
||||||
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
strm.total_in = strm.avail_in = srcLen;
|
strm.total_in = strm.avail_in = srcLen;
|
||||||
|
@ -76,8 +76,8 @@ Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen)
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
|
|
||||||
Int32 err = -1;
|
atInt32 err = -1;
|
||||||
Int32 ret = -1;
|
atInt32 ret = -1;
|
||||||
|
|
||||||
err = deflateInit(&strm, Z_BEST_COMPRESSION);
|
err = deflateInit(&strm, Z_BEST_COMPRESSION);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ Int32 compressZlib(const Uint8 *src, Uint32 srcLen, Uint8 *dst, Uint32 dstLen)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize)
|
atInt32 decompressLZO(atUint8* source, atInt32 sourceSize, atUint8* dest, atInt32& dstSize)
|
||||||
{
|
{
|
||||||
int size = dstSize;
|
int size = dstSize;
|
||||||
int result = lzo1x_decode(dest, &size, source, &sourceSize);
|
int result = lzo1x_decode(dest, &size, source, &sourceSize);
|
||||||
|
@ -114,12 +114,12 @@ Int32 decompressLZO(Uint8* source, Int32 sourceSize, Uint8* dest, Int32& dstSize
|
||||||
//src points to the yaz0 source data (to the "real" source data, not at the header!)
|
//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
|
//dst points to a buffer uncompressedSize bytes large (you get uncompressedSize from
|
||||||
//the second 4 bytes in the Yaz0 header).
|
//the second 4 bytes in the Yaz0 header).
|
||||||
Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize)
|
atUint32 yaz0Decode(atUint8* src, atUint8* dst, atUint32 uncompressedSize)
|
||||||
{
|
{
|
||||||
Uint32 srcPlace = 0, dstPlace = 0; //current read/write positions
|
atUint32 srcPlace = 0, dstPlace = 0; //current read/write positions
|
||||||
|
|
||||||
Int32 validBitCount = 0; //number of valid bits left in "code" byte
|
atInt32 validBitCount = 0; //number of valid bits left in "code" byte
|
||||||
Uint8 currCodeByte;
|
atUint8 currCodeByte;
|
||||||
while(dstPlace < uncompressedSize)
|
while(dstPlace < uncompressedSize)
|
||||||
{
|
{
|
||||||
//read new "code" byte if the current one is used up
|
//read new "code" byte if the current one is used up
|
||||||
|
@ -140,14 +140,14 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//RLE part
|
//RLE part
|
||||||
Uint8 byte1 = src[srcPlace];
|
atUint8 byte1 = src[srcPlace];
|
||||||
Uint8 byte2 = src[srcPlace + 1];
|
atUint8 byte2 = src[srcPlace + 1];
|
||||||
srcPlace += 2;
|
srcPlace += 2;
|
||||||
|
|
||||||
Uint32 dist = ((byte1 & 0xF) << 8) | byte2;
|
atUint32 dist = ((byte1 & 0xF) << 8) | byte2;
|
||||||
Uint32 copySource = dstPlace - (dist + 1);
|
atUint32 copySource = dstPlace - (dist + 1);
|
||||||
|
|
||||||
Uint32 numBytes = byte1 >> 4;
|
atUint32 numBytes = byte1 >> 4;
|
||||||
if(numBytes == 0)
|
if(numBytes == 0)
|
||||||
{
|
{
|
||||||
numBytes = src[srcPlace] + 0x12;
|
numBytes = src[srcPlace] + 0x12;
|
||||||
|
@ -157,7 +157,7 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize)
|
||||||
numBytes += 2;
|
numBytes += 2;
|
||||||
|
|
||||||
//copy run
|
//copy run
|
||||||
for(Uint32 i = 0; i < numBytes; ++i)
|
for(atUint32 i = 0; i < numBytes; ++i)
|
||||||
{
|
{
|
||||||
dst[dstPlace] = dst[copySource];
|
dst[dstPlace] = dst[copySource];
|
||||||
copySource++;
|
copySource++;
|
||||||
|
@ -176,26 +176,26 @@ Uint32 yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize)
|
||||||
// Yaz0 encode
|
// Yaz0 encode
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Uint32 srcPos, dstPos;
|
atUint32 srcPos, dstPos;
|
||||||
} yaz0_Ret;
|
} yaz0_Ret;
|
||||||
|
|
||||||
Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos);
|
atUint32 simpleEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos);
|
||||||
Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos);
|
atUint32 nintendoEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos);
|
||||||
|
|
||||||
Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data)
|
atUint32 yaz0Encode(atUint8* src, atUint32 srcSize, atUint8* data)
|
||||||
{
|
{
|
||||||
yaz0_Ret r = { 0, 0 };
|
yaz0_Ret r = { 0, 0 };
|
||||||
Int32 pos = 0;
|
atInt32 pos = 0;
|
||||||
Uint8 dst[24]; // 8 codes * 3 bytes maximum
|
atUint8 dst[24]; // 8 codes * 3 bytes maximum
|
||||||
Uint32 dstSize = 0;
|
atUint32 dstSize = 0;
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
Uint32 validBitCount = 0; //number of valid bits left in "code" byte
|
atUint32 validBitCount = 0; //number of valid bits left in "code" byte
|
||||||
Uint8 currCodeByte = 0;
|
atUint8 currCodeByte = 0;
|
||||||
while(r.srcPos < srcSize)
|
while(r.srcPos < srcSize)
|
||||||
{
|
{
|
||||||
Uint32 numBytes;
|
atUint32 numBytes;
|
||||||
Uint32 matchPos;
|
atUint32 matchPos;
|
||||||
numBytes = nintendoEnc(src, srcSize, r.srcPos, &matchPos);
|
numBytes = nintendoEnc(src, srcSize, r.srcPos, &matchPos);
|
||||||
if (numBytes < 3)
|
if (numBytes < 3)
|
||||||
{
|
{
|
||||||
|
@ -209,8 +209,8 @@ Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//RLE part
|
//RLE part
|
||||||
Uint32 dist = r.srcPos - matchPos - 1;
|
atUint32 dist = r.srcPos - matchPos - 1;
|
||||||
Uint8 byte1, byte2, byte3;
|
atUint8 byte1, byte2, byte3;
|
||||||
|
|
||||||
if (numBytes >= 0x12) // 3 byte encoding
|
if (numBytes >= 0x12) // 3 byte encoding
|
||||||
{
|
{
|
||||||
|
@ -265,12 +265,12 @@ Uint32 yaz0Encode(Uint8* src, Uint32 srcSize, Uint8* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// a lookahead encoding scheme for ngc Yaz0
|
// a lookahead encoding scheme for ngc Yaz0
|
||||||
Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos)
|
atUint32 nintendoEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos)
|
||||||
{
|
{
|
||||||
Uint32 numBytes = 1;
|
atUint32 numBytes = 1;
|
||||||
static Uint32 numBytes1;
|
static atUint32 numBytes1;
|
||||||
static Uint32 matchPos;
|
static atUint32 matchPos;
|
||||||
static Int32 prevFlag = 0;
|
static atInt32 prevFlag = 0;
|
||||||
|
|
||||||
// if prevFlag is set, it means that the previous position was determined by look-ahead try.
|
// 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.
|
// so just use it. this is not the best optimization, but nintendo's choice for speed.
|
||||||
|
@ -297,11 +297,11 @@ Uint32 nintendoEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// simple and straight encoding scheme for Yaz0
|
// simple and straight encoding scheme for Yaz0
|
||||||
Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos)
|
atUint32 simpleEnc(atUint8* src, atInt32 size, atInt32 pos, atUint32 *pMatchPos)
|
||||||
{
|
{
|
||||||
int startPos = pos - 0x1000, j, i;
|
int startPos = pos - 0x1000, j, i;
|
||||||
Uint32 numBytes = 1;
|
atUint32 numBytes = 1;
|
||||||
Uint32 matchPos = 0;
|
atUint32 matchPos = 0;
|
||||||
|
|
||||||
if (startPos < 0)
|
if (startPos < 0)
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
|
@ -312,7 +312,7 @@ Uint32 simpleEnc(Uint8* src, Int32 size, Int32 pos, Uint32 *pMatchPos)
|
||||||
if (src[i+j] != src[j+pos])
|
if (src[i+j] != src[j+pos])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((Uint32)j > numBytes)
|
if ((atUint32)j > numBytes)
|
||||||
{
|
{
|
||||||
numBytes = j;
|
numBytes = j;
|
||||||
matchPos = i;
|
matchPos = i;
|
||||||
|
|
|
@ -92,7 +92,7 @@ bool FileReader::isOpen() const
|
||||||
return m_fileHandle != NULL;
|
return m_fileHandle != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileReader::seek(Int64 pos, SeekOrigin origin)
|
void FileReader::seek(atInt64 pos, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
|
THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
|
||||||
|
@ -106,7 +106,7 @@ bool FileReader::atEnd() const
|
||||||
return feof(m_fileHandle) != 0;
|
return feof(m_fileHandle) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 FileReader::position() const
|
atUint64 FileReader::position() const
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open");
|
||||||
|
@ -114,7 +114,7 @@ Uint64 FileReader::position() const
|
||||||
return ftello64(m_fileHandle);
|
return ftello64(m_fileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 FileReader::length() const
|
atUint64 FileReader::length() const
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open");
|
||||||
|
@ -141,14 +141,14 @@ bool FileReader::readBit()
|
||||||
if (!m_bitValid)
|
if (!m_bitValid)
|
||||||
{
|
{
|
||||||
int size = fread(&m_currentByte, 1, 1, m_fileHandle);
|
int size = fread(&m_currentByte, 1, 1, m_fileHandle);
|
||||||
if (size != sizeof(Uint8))
|
if (size != sizeof(atUint8))
|
||||||
THROW_IO_EXCEPTION("Error reading from file.");
|
THROW_IO_EXCEPTION("Error reading from file.");
|
||||||
|
|
||||||
m_bitShift = 0;
|
m_bitShift = 0;
|
||||||
m_bitValid = true;
|
m_bitValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 flag = (1 << m_bitShift);
|
atUint8 flag = (1 << m_bitShift);
|
||||||
m_bitShift++;
|
m_bitShift++;
|
||||||
if (m_bitShift > 7)
|
if (m_bitShift > 7)
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
@ -156,49 +156,49 @@ bool FileReader::readBit()
|
||||||
return ((m_currentByte & flag) == flag);
|
return ((m_currentByte & flag) == flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 FileReader::readUByte()
|
atUint8 FileReader::readUByte()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
Uint8 val = 0;
|
atUint8 val = 0;
|
||||||
fread(&val, 1, 1, m_fileHandle);
|
fread(&val, 1, 1, m_fileHandle);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8 FileReader::readByte()
|
atInt8 FileReader::readByte()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
return (Int8)readUByte();
|
return (atInt8)readUByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* FileReader::readUBytes(Uint64 len)
|
atUint8* FileReader::readUBytes(atUint64 len)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
Uint8* val = new Uint8[len];
|
atUint8* val = new atUint8[len];
|
||||||
fread(val, 1, len, m_fileHandle);
|
fread(val, 1, len, m_fileHandle);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8* FileReader::readBytes(Uint64 len)
|
atInt8* FileReader::readBytes(atUint64 len)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
return (Int8*)readUBytes(len);
|
return (atInt8*)readUBytes(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 FileReader::readUint16()
|
atUint16 FileReader::readUint16()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
Uint16 val;
|
atUint16 val;
|
||||||
fread(&val, 1, sizeof(Uint16), m_fileHandle);
|
fread(&val, 1, sizeof(atUint16), m_fileHandle);
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU16(val);
|
val = utility::swapU16(val);
|
||||||
|
@ -206,22 +206,22 @@ Uint16 FileReader::readUint16()
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int16 FileReader::readInt16()
|
atInt16 FileReader::readInt16()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
return (Int16)readUint16();
|
return (atInt16)readUint16();
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 FileReader::readUint32()
|
atUint32 FileReader::readUint32()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
Uint32 val;
|
atUint32 val;
|
||||||
fread(&val, 1, sizeof(Uint32), m_fileHandle);
|
fread(&val, 1, sizeof(atUint32), m_fileHandle);
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU32(val);
|
val = utility::swapU32(val);
|
||||||
|
@ -229,22 +229,22 @@ Uint32 FileReader::readUint32()
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 FileReader::readInt32()
|
atInt32 FileReader::readInt32()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
return (Int32)readUint32();
|
return (atInt32)readUint32();
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 FileReader::readUint64()
|
atUint64 FileReader::readUint64()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
Uint64 val;
|
atUint64 val;
|
||||||
fread(&val, 1, sizeof(Uint64), m_fileHandle);
|
fread(&val, 1, sizeof(atUint64), m_fileHandle);
|
||||||
|
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU64(val);
|
val = utility::swapU64(val);
|
||||||
|
@ -252,12 +252,12 @@ Uint64 FileReader::readUint64()
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int64 FileReader::readInt64()
|
atInt64 FileReader::readInt64()
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
|
||||||
|
|
||||||
return (Int64)readUint64();
|
return (atInt64)readUint64();
|
||||||
}
|
}
|
||||||
|
|
||||||
double FileReader::readDouble()
|
double FileReader::readDouble()
|
||||||
|
@ -301,7 +301,7 @@ bool FileReader::readBool()
|
||||||
std::string FileReader::readString()
|
std::string FileReader::readString()
|
||||||
{
|
{
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
Uint8 chr = readByte();
|
atUint8 chr = readByte();
|
||||||
|
|
||||||
while (chr != 0)
|
while (chr != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,7 +91,7 @@ bool FileWriter::save()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::seek(Int64 pos, SeekOrigin origin)
|
void FileWriter::seek(atInt64 pos, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
||||||
THROW_IO_EXCEPTION("Unable to seek in file");
|
THROW_IO_EXCEPTION("Unable to seek in file");
|
||||||
|
@ -102,12 +102,12 @@ bool FileWriter::atEnd() const
|
||||||
return feof(m_fileHandle) != 0;
|
return feof(m_fileHandle) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 FileWriter::position() const
|
atUint64 FileWriter::position() const
|
||||||
{
|
{
|
||||||
return ftello64(m_fileHandle);
|
return ftello64(m_fileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 FileWriter::length() const
|
atUint64 FileWriter::length() const
|
||||||
{
|
{
|
||||||
return utility::fileSize(m_fileHandle);
|
return utility::fileSize(m_fileHandle);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ void FileWriter::writeBit(bool val)
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
fseeko64(m_fileHandle, m_bytePosition, (int)SeekOrigin::Begin);
|
fseeko64(m_fileHandle, m_bytePosition, (int)SeekOrigin::Begin);
|
||||||
if (fwrite(&m_currentByte, 1, 1, m_fileHandle) != sizeof(Int8))
|
if (fwrite(&m_currentByte, 1, 1, m_fileHandle) != sizeof(atInt8))
|
||||||
THROW_IO_EXCEPTION("Unable to data to file");
|
THROW_IO_EXCEPTION("Unable to data to file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,23 +146,23 @@ void FileWriter::seekBit(int bit)
|
||||||
m_bitValid = true;
|
m_bitValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeUByte(Uint8 val)
|
void FileWriter::writeUByte(atUint8 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint8), m_fileHandle) != sizeof(Uint8))
|
if (fwrite(&val, 1, sizeof(atUint8), m_fileHandle) != sizeof(atUint8))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeByte(Int8 val)
|
void FileWriter::writeByte(atInt8 val)
|
||||||
{
|
{
|
||||||
writeUByte(val);
|
writeUByte(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeUBytes(Uint8* data, Uint64 len)
|
void FileWriter::writeUBytes(atUint8* data, atUint64 len)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -173,12 +173,12 @@ void FileWriter::writeUBytes(Uint8* data, Uint64 len)
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeBytes(Int8* data, Uint64 len)
|
void FileWriter::writeBytes(atInt8* data, atUint64 len)
|
||||||
{
|
{
|
||||||
writeUBytes((Uint8*)data, len);
|
writeUBytes((atUint8*)data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeUint16(Uint16 val)
|
void FileWriter::writeUint16(atUint16 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -188,16 +188,16 @@ void FileWriter::writeUint16(Uint16 val)
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU16(val);
|
val = utility::swapU16(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint16), m_fileHandle) != sizeof(Uint16))
|
if (fwrite(&val, 1, sizeof(atUint16), m_fileHandle) != sizeof(atUint16))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeInt16(Int16 val)
|
void FileWriter::writeInt16(atInt16 val)
|
||||||
{
|
{
|
||||||
writeUint16(val);
|
writeUint16(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeUint32(Uint32 val)
|
void FileWriter::writeUint32(atUint32 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -207,16 +207,16 @@ void FileWriter::writeUint32(Uint32 val)
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU32(val);
|
val = utility::swapU32(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint32), m_fileHandle) != sizeof(Uint32))
|
if (fwrite(&val, 1, sizeof(atUint32), m_fileHandle) != sizeof(atUint32))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeInt32(Int32 val)
|
void FileWriter::writeInt32(atInt32 val)
|
||||||
{
|
{
|
||||||
writeUint32(val);
|
writeUint32(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeUint64(Uint64 val)
|
void FileWriter::writeUint64(atUint64 val)
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||||
|
@ -226,11 +226,11 @@ void FileWriter::writeUint64(Uint64 val)
|
||||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
val = utility::swapU64(val);
|
val = utility::swapU64(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint64), m_fileHandle) != sizeof(Uint64))
|
if (fwrite(&val, 1, sizeof(atUint64), m_fileHandle) != sizeof(atUint64))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWriter::writeInt64(Int64 val)
|
void FileWriter::writeInt64(atInt64 val)
|
||||||
{
|
{
|
||||||
writeUint64(val);
|
writeUint64(val);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ void FileWriter::writeUnicode(const std::string& str)
|
||||||
|
|
||||||
utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp));
|
utf8::utf8to16(tmpStr.begin(), tmpStr.end(), back_inserter(tmp));
|
||||||
|
|
||||||
for (Uint16 chr : tmp)
|
for (atUint16 chr : tmp)
|
||||||
{
|
{
|
||||||
if (chr != 0xFEFF)
|
if (chr != 0xFEFF)
|
||||||
writeInt16(chr);
|
writeInt16(chr);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -21,7 +22,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
MCFileReader::MCFileReader(Uint8* data, Uint64 length)
|
MCFileReader::MCFileReader(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -33,3 +34,4 @@ MCFileReader::MCFileReader(const std::string& filename)
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -20,7 +21,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
MCFileWriter::MCFileWriter(Uint8* data, Uint64 length)
|
MCFileWriter::MCFileWriter(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -33,13 +34,13 @@ MCFileWriter::MCFileWriter(const std::string& filename)
|
||||||
// TODO: Check the implementation, it seems to work fine, however it's not exactly correct,
|
// 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
|
// 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.
|
// need to figure out what it's doing and whether it's relevant to the checksum.
|
||||||
Uint16 MCFileWriter::calculateSlotChecksum(Uint32 game)
|
atUint16 MCFileWriter::calculateSlotChecksum(atUint32 game)
|
||||||
{
|
{
|
||||||
Uint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4);
|
atUint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4);
|
||||||
Uint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500);
|
atUint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500);
|
||||||
|
|
||||||
first = (first + second) & 0xFFFF;
|
first = (first + second) & 0xFFFF;
|
||||||
Uint16 result = first << 16;
|
atUint16 result = first << 16;
|
||||||
second = ~first&0xFFFF;
|
second = ~first&0xFFFF;
|
||||||
second += 1;
|
second += 1;
|
||||||
result += second;
|
result += second;
|
||||||
|
@ -47,14 +48,14 @@ Uint16 MCFileWriter::calculateSlotChecksum(Uint32 game)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 MCFileWriter::calculateChecksum(Uint8 *data, Uint32 length)
|
atUint16 MCFileWriter::calculateChecksum(atUint8 *data, atUint32 length)
|
||||||
{
|
{
|
||||||
Uint16 sum = 0;
|
atUint16 sum = 0;
|
||||||
int i = length;
|
int i = length;
|
||||||
|
|
||||||
for (Uint32 j = 0; j < length; j += 2)
|
for (atUint32 j = 0; j < length; j += 2)
|
||||||
{
|
{
|
||||||
sum += *(Uint16*)(data + j) ^ i;
|
sum += *(atUint16*)(data + j) ^ i;
|
||||||
i -= 2;
|
i -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,10 +65,10 @@ Uint16 MCFileWriter::calculateChecksum(Uint8 *data, Uint32 length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rewrite this to be more optimized, the current solution takes quite a few cycles
|
// TODO: Rewrite this to be more optimized, the current solution takes quite a few cycles
|
||||||
Uint8* MCFileWriter::reverse(Uint8* data, Uint32 length)
|
atUint8* MCFileWriter::reverse(atUint8* data, atUint32 length)
|
||||||
{
|
{
|
||||||
Uint32 a = 0;
|
atUint32 a = 0;
|
||||||
Uint32 swap;
|
atUint32 swap;
|
||||||
|
|
||||||
for (;a<--length; a++)
|
for (;a<--length; a++)
|
||||||
{
|
{
|
||||||
|
@ -86,14 +87,15 @@ void MCFileWriter::unscramble()
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Uint32 i = 0; i < m_length; i += 4)
|
for (atUint32 i = 0; i < m_length; i += 4)
|
||||||
{
|
{
|
||||||
Uint32 block1 = *(Uint32*)reverse((m_data + i), 4);
|
atUint32 block1 = *(atUint32*)reverse((m_data + i), 4);
|
||||||
Uint32 block2 = *(Uint32*)reverse((m_data + i + 4), 4);
|
atUint32 block2 = *(atUint32*)reverse((m_data + i + 4), 4);
|
||||||
*(Uint32*)(m_data + i) = block2;
|
*(atUint32*)(m_data + i) = block2;
|
||||||
*(Uint32*)(m_data + i + 4) = block1;
|
*(atUint32*)(m_data + i + 4) = block1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -44,7 +45,7 @@ void SkywardSwordFile::addQuest(Athena::SkywardSwordQuest *q)
|
||||||
m_quests.push_back(q);
|
m_quests.push_back(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkywardSwordQuest *SkywardSwordFile::quest(Uint32 id)
|
SkywardSwordQuest *SkywardSwordFile::quest(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id > m_quests.size() - 1)
|
if (id > m_quests.size() - 1)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
THROW_INVALID_OPERATION_EXCEPTION("index out of range");
|
||||||
|
@ -69,3 +70,4 @@ Region SkywardSwordFile::region() const
|
||||||
|
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -25,7 +26,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
SkywardSwordFileReader::SkywardSwordFileReader(Uint8* data, Uint64 length)
|
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
base::setEndian(Endian::BigEndian);
|
base::setEndian(Endian::BigEndian);
|
||||||
|
@ -45,13 +46,13 @@ SkywardSwordFile* SkywardSwordFileReader::read()
|
||||||
if (base::length() != 0xFBE0)
|
if (base::length() != 0xFBE0)
|
||||||
THROW_INVALID_DATA_EXCEPTION("File not the expected size of 0xFBE0");
|
THROW_INVALID_DATA_EXCEPTION("File not the expected size of 0xFBE0");
|
||||||
|
|
||||||
Uint32 magic = base::readUint32();
|
atUint32 magic = base::readUint32();
|
||||||
|
|
||||||
if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic)
|
if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic)
|
||||||
THROW_INVALID_DATA_EXCEPTION("Not a valid Skyward Sword save file");
|
THROW_INVALID_DATA_EXCEPTION("Not a valid Skyward Sword save file");
|
||||||
|
|
||||||
base::seek(0x01C, SeekOrigin::Begin);
|
base::seek(0x01C, SeekOrigin::Begin);
|
||||||
Uint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1)
|
atUint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1)
|
||||||
|
|
||||||
if (headerSize != 0x1D)
|
if (headerSize != 0x1D)
|
||||||
THROW_INVALID_DATA_EXCEPTION("Invalid header size, Corrupted data?");
|
THROW_INVALID_DATA_EXCEPTION("Invalid header size, Corrupted data?");
|
||||||
|
@ -61,8 +62,8 @@ SkywardSwordFile* SkywardSwordFileReader::read()
|
||||||
file->setRegion((magic == SkywardSwordFile::USMagic ? Region::NTSC: (magic == SkywardSwordFile::JAMagic ? Region::NTSCJ: Region::PAL)));
|
file->setRegion((magic == SkywardSwordFile::USMagic ? Region::NTSC: (magic == SkywardSwordFile::JAMagic ? Region::NTSCJ: Region::PAL)));
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
SkywardSwordQuest* q = new SkywardSwordQuest((Uint8*)base::readBytes(0x53C0), 0x53C0);
|
SkywardSwordQuest* q = new SkywardSwordQuest((atUint8*)base::readBytes(0x53C0), 0x53C0);
|
||||||
Uint64 pos = base::position();
|
atUint64 pos = base::position();
|
||||||
// seek to the skip data for this particular quest
|
// seek to the skip data for this particular quest
|
||||||
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
|
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
|
||||||
q->setSkipData(base::readUBytes(0x24));
|
q->setSkipData(base::readUBytes(0x24));
|
||||||
|
@ -82,3 +83,4 @@ SkywardSwordFile* SkywardSwordFileReader::read()
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -24,7 +25,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
SkywardSwordFileWriter::SkywardSwordFileWriter(Uint8 *data, Uint64 len)
|
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8 *data, atUint64 len)
|
||||||
: base(data, len)
|
: base(data, len)
|
||||||
{
|
{
|
||||||
base::setEndian(Endian::BigEndian);
|
base::setEndian(Endian::BigEndian);
|
||||||
|
@ -41,7 +42,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file)
|
||||||
if (!file)
|
if (!file)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("file cannot be NULL");
|
THROW_INVALID_OPERATION_EXCEPTION("file cannot be NULL");
|
||||||
|
|
||||||
Uint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic :
|
atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic :
|
||||||
(file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic));
|
(file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic));
|
||||||
|
|
||||||
base::writeUint32(magic);
|
base::writeUint32(magic);
|
||||||
|
@ -58,7 +59,7 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file)
|
||||||
THROW_INVALID_DATA_EXCEPTION("q->skipData() not 0x24 bytes in length");
|
THROW_INVALID_DATA_EXCEPTION("q->skipData() not 0x24 bytes in length");
|
||||||
// Write the save data
|
// Write the save data
|
||||||
base::writeUBytes(q->data(), q->length());
|
base::writeUBytes(q->data(), q->length());
|
||||||
Uint64 pos = base::position();
|
atUint64 pos = base::position();
|
||||||
// Write the slots skip data
|
// Write the slots skip data
|
||||||
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
|
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
|
||||||
base::writeUBytes(q->skipData(), q->skipLength());
|
base::writeUBytes(q->skipData(), q->skipLength());
|
||||||
|
@ -73,3 +74,4 @@ void SkywardSwordFileWriter::write(SkywardSwordFile *file)
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -17,14 +18,14 @@
|
||||||
|
|
||||||
namespace Athena
|
namespace Athena
|
||||||
{
|
{
|
||||||
SkywardSwordQuest::SkywardSwordQuest(Uint8 *data, Uint32 len)
|
SkywardSwordQuest::SkywardSwordQuest(atUint8 *data, atUint32 len)
|
||||||
: ZQuestFile(ZQuestFile::SS, Endian::BigEndian, data, len),
|
: ZQuestFile(ZQuestFile::SS, Endian::BigEndian, data, len),
|
||||||
m_skipData(nullptr),
|
m_skipData(nullptr),
|
||||||
m_skipLength(0)
|
m_skipLength(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkywardSwordQuest::setSkipData(const Uint8 *data, Uint32 len)
|
void SkywardSwordQuest::setSkipData(const atUint8 *data, atUint32 len)
|
||||||
{
|
{
|
||||||
if (m_skipData)
|
if (m_skipData)
|
||||||
{
|
{
|
||||||
|
@ -32,18 +33,19 @@ void SkywardSwordQuest::setSkipData(const Uint8 *data, Uint32 len)
|
||||||
m_skipData = nullptr;
|
m_skipData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_skipData = (Uint8*)data;
|
m_skipData = (atUint8*)data;
|
||||||
m_skipLength = len;
|
m_skipLength = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 *SkywardSwordQuest::skipData() const
|
atUint8 *SkywardSwordQuest::skipData() const
|
||||||
{
|
{
|
||||||
return m_skipData;
|
return m_skipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SkywardSwordQuest::skipLength() const
|
atUint32 SkywardSwordQuest::skipLength() const
|
||||||
{
|
{
|
||||||
return m_skipLength;
|
return m_skipLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -146,12 +146,12 @@ QList<int> Sprite::stateIds() const
|
||||||
return m_stateIds;
|
return m_stateIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 Sprite::stateCount() const
|
atUint32 Sprite::stateCount() const
|
||||||
{
|
{
|
||||||
return m_stateIds.size();
|
return m_stateIds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::setCurrentState(const Uint32 id)
|
void Sprite::setCurrentState(const atUint32 id)
|
||||||
{
|
{
|
||||||
if (id >= m_stateIds.size())
|
if (id >= m_stateIds.size())
|
||||||
return;
|
return;
|
||||||
|
@ -162,7 +162,7 @@ void Sprite::setCurrentState(const Uint32 id)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 Sprite::currentState() const
|
atUint32 Sprite::currentState() const
|
||||||
{
|
{
|
||||||
return m_currentState;
|
return m_currentState;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ bool Sprite::removeFrame(SpriteFrame* frame)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::setFrame(Uint32 id)
|
void Sprite::setFrame(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id > m_frames.size())
|
if (id > m_frames.size())
|
||||||
return;
|
return;
|
||||||
|
@ -228,7 +228,7 @@ void Sprite::setFrames(QList<SpriteFrame*> frames)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Uint32 Sprite::frameCount() const
|
atUint32 Sprite::frameCount() const
|
||||||
{
|
{
|
||||||
return m_frames.size();
|
return m_frames.size();
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ SpriteFile* Sprite::container() const
|
||||||
|
|
||||||
void Sprite::setCurrentFrame(SpriteFrame* frame)
|
void Sprite::setCurrentFrame(SpriteFrame* frame)
|
||||||
{
|
{
|
||||||
Uint32 id = 0;
|
atUint32 id = 0;
|
||||||
for (SpriteFrame* tmpFrame : m_frames)
|
for (SpriteFrame* tmpFrame : m_frames)
|
||||||
{
|
{
|
||||||
if (tmpFrame == frame)
|
if (tmpFrame == frame)
|
||||||
|
@ -261,7 +261,7 @@ void Sprite::setCurrentFrame(SpriteFrame* frame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::setCurrentFrame(Uint32 id)
|
void Sprite::setCurrentFrame(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id >= m_frames.size())
|
if (id >= m_frames.size())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,20 +22,20 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace Sakura
|
namespace Sakura
|
||||||
{
|
{
|
||||||
const Uint32 SpriteFile::Major = 1;
|
const atUint32 SpriteFile::Major = 1;
|
||||||
const Uint32 SpriteFile::Minor = 0;
|
const atUint32 SpriteFile::Minor = 0;
|
||||||
const Uint32 SpriteFile::Revision = 2;
|
const atUint32 SpriteFile::Revision = 2;
|
||||||
const Uint32 SpriteFile::Build = 0;
|
const atUint32 SpriteFile::Build = 0;
|
||||||
const Uint32 SpriteFile::Version = Major | (Minor << 8) | (Revision << 16) | (Build << 24);
|
const atUint32 SpriteFile::Version = Major | (Minor << 8) | (Revision << 16) | (Build << 24);
|
||||||
|
|
||||||
const Uint32 SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24);
|
const atUint32 SpriteFile::Magic = 'S' | ('P' << 8) | ('R' << 16) | ('S' << 24);
|
||||||
|
|
||||||
|
|
||||||
SpriteFile::SpriteFile()
|
SpriteFile::SpriteFile()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteFile::SpriteFile(Uint32 width, Uint32 height, float originX, float originY)
|
SpriteFile::SpriteFile(atUint32 width, atUint32 height, float originX, float originY)
|
||||||
: m_size(width, height),
|
: m_size(width, height),
|
||||||
m_origin(originX, originY)
|
m_origin(originX, originY)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ SpriteFile::~SpriteFile()
|
||||||
m_sprites.clear();
|
m_sprites.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFile::setSize(Uint32 width, Uint32 height)
|
void SpriteFile::setSize(atUint32 width, atUint32 height)
|
||||||
{
|
{
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
setSize(Vector2Di(width, height));
|
setSize(Vector2Di(width, height));
|
||||||
|
@ -93,7 +93,7 @@ QSize SpriteFile::size() const
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SpriteFile::width() const
|
atUint32 SpriteFile::width() const
|
||||||
{
|
{
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
return m_size.x;
|
return m_size.x;
|
||||||
|
@ -102,7 +102,7 @@ Uint32 SpriteFile::width() const
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SpriteFile::height() const
|
atUint32 SpriteFile::height() const
|
||||||
{
|
{
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
return m_size.y;
|
return m_size.y;
|
||||||
|
@ -179,7 +179,7 @@ void SpriteFile::removeTexture(int id)
|
||||||
delete tex;
|
delete tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
STexture* SpriteFile::texture(Uint32 id)
|
STexture* SpriteFile::texture(atUint32 id)
|
||||||
{
|
{
|
||||||
if (id >= m_textures.size())
|
if (id >= m_textures.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -196,7 +196,7 @@ QList<STexture*> SpriteFile::textures() const
|
||||||
return m_textures;
|
return m_textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SpriteFile::textureCount() const
|
atUint32 SpriteFile::textureCount() const
|
||||||
{
|
{
|
||||||
return m_textures.size();
|
return m_textures.size();
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ QMap<QString, Sprite*> SpriteFile::sprites() const
|
||||||
return m_sprites;
|
return m_sprites;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SpriteFile::spriteCount() const
|
atUint32 SpriteFile::spriteCount() const
|
||||||
{
|
{
|
||||||
return m_sprites.size();
|
return m_sprites.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
SpriteFileReader::SpriteFileReader(Uint8* data, Uint64 length)
|
SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
Sakura::SpriteFile* ret = NULL;
|
Sakura::SpriteFile* ret = NULL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Uint32 magic = base::readUint32();
|
atUint32 magic = base::readUint32();
|
||||||
|
|
||||||
if (magic != Sakura::SpriteFile::Magic)
|
if (magic != Sakura::SpriteFile::Magic)
|
||||||
THROW_INVALID_DATA_EXCEPTION("Not a valid Sakura Sprite container");
|
THROW_INVALID_DATA_EXCEPTION("Not a valid Sakura Sprite container");
|
||||||
|
|
||||||
Uint32 version = base::readUint32();
|
atUint32 version = base::readUint32();
|
||||||
|
|
||||||
// TODO: Make this more verbose
|
// TODO: Make this more verbose
|
||||||
if (version != Sakura::SpriteFile::Version)
|
if (version != Sakura::SpriteFile::Version)
|
||||||
|
@ -59,13 +59,13 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
// Such as the texture count, it's dimensions, and it's origin.
|
// Such as the texture count, it's dimensions, and it's origin.
|
||||||
// After that we have the number of sprites contained in this
|
// After that we have the number of sprites contained in this
|
||||||
// sprite container.
|
// sprite container.
|
||||||
Uint16 textureCount = base::readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
|
atUint16 textureCount = base::readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
|
||||||
// This is probably overkill, but it's better safe than sorry.
|
// This is probably overkill, but it's better safe than sorry.
|
||||||
Uint32 width = base::readUint32();
|
atUint32 width = base::readUint32();
|
||||||
Uint32 height = base::readUint32();
|
atUint32 height = base::readUint32();
|
||||||
float originX = base::readFloat();
|
float originX = base::readFloat();
|
||||||
float originY = base::readFloat();
|
float originY = base::readFloat();
|
||||||
Uint16 spriteCount = base::readUint16();
|
atUint16 spriteCount = base::readUint16();
|
||||||
|
|
||||||
// Lets go ahead and create or new container.
|
// Lets go ahead and create or new container.
|
||||||
ret = new Sakura::SpriteFile(width, height, originX, originY);
|
ret = new Sakura::SpriteFile(width, height, originX, originY);
|
||||||
|
@ -75,7 +75,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
// to migrate this code to Big Endian based systems, such as the wii
|
// to migrate this code to Big Endian based systems, such as the wii
|
||||||
// which require data to be 32 byte aligned, or it causes some issues.
|
// which require data to be 32 byte aligned, or it causes some issues.
|
||||||
// It's also convenient to have this, for later expansion.
|
// It's also convenient to have this, for later expansion.
|
||||||
Uint32 reserved = base::readUint32();
|
atUint32 reserved = base::readUint32();
|
||||||
UNUSED(reserved);
|
UNUSED(reserved);
|
||||||
|
|
||||||
// Next we have to load the textures
|
// Next we have to load the textures
|
||||||
|
@ -89,7 +89,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
QList<Sakura::STexture*> textures;
|
QList<Sakura::STexture*> textures;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (Uint16 i = 0; i < textureCount; i++)
|
for (atUint16 i = 0; i < textureCount; i++)
|
||||||
{
|
{
|
||||||
Sakura::STexture* texture = new Sakura::STexture;
|
Sakura::STexture* texture = new Sakura::STexture;
|
||||||
texture->Filepath = base::readString();
|
texture->Filepath = base::readString();
|
||||||
|
@ -111,7 +111,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
QMap<QString, Sakura::Sprite*> sprites;
|
QMap<QString, Sakura::Sprite*> sprites;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (Uint16 i = 0; i < spriteCount; i++)
|
for (atUint16 i = 0; i < spriteCount; i++)
|
||||||
{
|
{
|
||||||
Sakura::Sprite* sprite = new Sakura::Sprite(ret);
|
Sakura::Sprite* sprite = new Sakura::Sprite(ret);
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
|
@ -120,8 +120,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
QString name = QString::fromStdString(base::readString());
|
QString name = QString::fromStdString(base::readString());
|
||||||
#endif
|
#endif
|
||||||
sprite->setName(name);
|
sprite->setName(name);
|
||||||
Uint16 frameCount = base::readUint16();
|
atUint16 frameCount = base::readUint16();
|
||||||
Uint16 stateCount = base::readUint16();
|
atUint16 stateCount = base::readUint16();
|
||||||
|
|
||||||
// Each state id corresponds to a texture held in the parent class
|
// Each state id corresponds to a texture held in the parent class
|
||||||
std::vector<int> stateIds;
|
std::vector<int> stateIds;
|
||||||
|
@ -144,11 +144,11 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
QList<Sakura::SpriteFrame*> frames;
|
QList<Sakura::SpriteFrame*> frames;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (Uint32 k = 0; k < frameCount; k++)
|
for (atUint32 k = 0; k < frameCount; k++)
|
||||||
{
|
{
|
||||||
Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite);
|
Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite);
|
||||||
frame->setFrameTime(base::readFloat());
|
frame->setFrameTime(base::readFloat());
|
||||||
Uint16 partCount = base::readUint16();
|
atUint16 partCount = base::readUint16();
|
||||||
|
|
||||||
|
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
|
@ -156,7 +156,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
#else
|
#else
|
||||||
QList<Sakura::SpritePart*> parts;
|
QList<Sakura::SpritePart*> parts;
|
||||||
#endif
|
#endif
|
||||||
for (Uint8 j = 0; j < partCount; j++)
|
for (atUint8 j = 0; j < partCount; j++)
|
||||||
{
|
{
|
||||||
Sakura::SpritePart* part = new Sakura::SpritePart(frame);
|
Sakura::SpritePart* part = new Sakura::SpritePart(frame);
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
|
@ -173,8 +173,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
float texXOff = base::readFloat();
|
float texXOff = base::readFloat();
|
||||||
float texYOff = base::readFloat();
|
float texYOff = base::readFloat();
|
||||||
part->setTextureOffset(texXOff, texYOff);
|
part->setTextureOffset(texXOff, texYOff);
|
||||||
Uint32 width = base::readUint32();
|
atUint32 width = base::readUint32();
|
||||||
Uint32 height = base::readUint32();
|
atUint32 height = base::readUint32();
|
||||||
part->setSize(width, height);
|
part->setSize(width, height);
|
||||||
bool flippedH = base::readBool();
|
bool flippedH = base::readBool();
|
||||||
part->setFlippedHorizontally(flippedH);
|
part->setFlippedHorizontally(flippedH);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
SpriteFileWriter::SpriteFileWriter(Uint8 *data, Uint64 length)
|
SpriteFileWriter::SpriteFileWriter(atUint8 *data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ QList<SpritePart*> SpriteFrame::parts() const
|
||||||
return m_parts;
|
return m_parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SpriteFrame::partCount() const
|
atUint32 SpriteFrame::partCount() const
|
||||||
{
|
{
|
||||||
return m_parts.size();
|
return m_parts.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ QPoint SpritePart::textureOffset() const
|
||||||
return m_textureOffset;
|
return m_textureOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpritePart::setSize(Uint32 width, Uint32 height)
|
void SpritePart::setSize(atUint32 width, atUint32 height)
|
||||||
{
|
{
|
||||||
#ifndef ATHENA_USE_QT
|
#ifndef ATHENA_USE_QT
|
||||||
setSize(Vector2Di(width, height));
|
setSize(Vector2Di(width, height));
|
||||||
|
|
|
@ -27,59 +27,59 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
bool isEmpty(Int8* buf, Uint32 size)
|
bool isEmpty(atInt8* buf, atUint32 size)
|
||||||
{
|
{
|
||||||
return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
|
return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 swapU16(Uint16 val )
|
atUint16 swapU16(atUint16 val )
|
||||||
{
|
{
|
||||||
return (Uint16)swap16(val);
|
return (atUint16)swap16(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Int16 swap16(Int16 val )
|
atInt16 swap16(atInt16 val )
|
||||||
{
|
{
|
||||||
return (val = (val << 8) | ((val >> 8) & 0xFF));
|
return (val = (val << 8) | ((val >> 8) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 swapU32(Uint32 val)
|
atUint32 swapU32(atUint32 val)
|
||||||
{
|
{
|
||||||
return (Uint32)swap32(val);
|
return (atUint32)swap32(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int swap32(Int32 val )
|
int swap32(atInt32 val )
|
||||||
{
|
{
|
||||||
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
|
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
|
||||||
val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
|
val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 swapU64(Uint64 val)
|
atUint64 swapU64(atUint64 val)
|
||||||
{
|
{
|
||||||
return (Uint64)swap64(val);
|
return (atUint64)swap64(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Int64 swap64(Int64 val)
|
atInt64 swap64(atInt64 val)
|
||||||
{
|
{
|
||||||
return (val = ((Int64)((((Int64)(val) & 0xFF00000000000000ULL) >> 56) |
|
return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) |
|
||||||
(((Int64)(val) & 0x00FF000000000000ULL) >> 40) |
|
(((atInt64)(val) & 0x00FF000000000000ULL) >> 40) |
|
||||||
(((Int64)(val) & 0x0000FF0000000000ULL) >> 24) |
|
(((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) |
|
||||||
(((Int64)(val) & 0x000000FF00000000ULL) >> 8) |
|
(((atInt64)(val) & 0x000000FF00000000ULL) >> 8) |
|
||||||
(((Int64)(val) & 0x00000000FF000000ULL) << 8) |
|
(((atInt64)(val) & 0x00000000FF000000ULL) << 8) |
|
||||||
(((Int64)(val) & 0x0000000000FF0000ULL) << 24) |
|
(((atInt64)(val) & 0x0000000000FF0000ULL) << 24) |
|
||||||
(((Int64)(val) & 0x000000000000FF00ULL) << 40) |
|
(((atInt64)(val) & 0x000000000000FF00ULL) << 40) |
|
||||||
(((Int64)(val) & 0x00000000000000FFULL) << 56))));
|
(((atInt64)(val) & 0x00000000000000FFULL) << 56))));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSystemBigEndian()
|
bool isSystemBigEndian()
|
||||||
{
|
{
|
||||||
Uint8* test = (Uint8*)"\xFE\xFF";
|
atUint8* test = (atUint8*)"\xFE\xFF";
|
||||||
return (*(Uint16*)test == 0xFEFF);
|
return (*(atUint16*)test == 0xFEFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillRandom(Uint8 * rndArea, Uint8 count)
|
void fillRandom(atUint8 * rndArea, atUint8 count)
|
||||||
{
|
{
|
||||||
for(Uint16 i = 0; i < count; i++)
|
for(atUint16 i = 0; i < count; i++)
|
||||||
rndArea[i]=rand();
|
rndArea[i]=rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ double swapDouble(double val)
|
||||||
retFloat[6] = convFloat[1];
|
retFloat[6] = convFloat[1];
|
||||||
retFloat[7] = convFloat[0];
|
retFloat[7] = convFloat[0];
|
||||||
|
|
||||||
return (double)((Uint64)retVal);
|
return (double)((atUint64)retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -228,11 +228,11 @@ int countChar(const std::string& str, const char chr, int* lastOccur)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 fileSize(FILE* f)
|
atUint64 fileSize(FILE* f)
|
||||||
{
|
{
|
||||||
Uint64 oldPos = ftello64(f);
|
atUint64 oldPos = ftello64(f);
|
||||||
fseeko64(f, 0, SEEK_END);
|
fseeko64(f, 0, SEEK_END);
|
||||||
Uint64 size = ftello64(f);
|
atUint64 size = ftello64(f);
|
||||||
fseeko64(f, oldPos, SEEK_SET);
|
fseeko64(f, oldPos, SEEK_SET);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -32,7 +33,7 @@ WiiBanner::WiiBanner() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WiiBanner::WiiBanner(Uint32 gameId, const std::string& title,
|
WiiBanner::WiiBanner(atUint32 gameId, const std::string& title,
|
||||||
const std::string& subtitle, WiiImage* banner, std::vector<WiiImage*> icons) :
|
const std::string& subtitle, WiiImage* banner, std::vector<WiiImage*> icons) :
|
||||||
m_gameId(gameId),
|
m_gameId(gameId),
|
||||||
m_banner(banner),
|
m_banner(banner),
|
||||||
|
@ -50,12 +51,12 @@ WiiBanner::~WiiBanner()
|
||||||
m_icons.clear();
|
m_icons.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setGameID(Uint64 id)
|
void WiiBanner::setGameID(atUint64 id)
|
||||||
{
|
{
|
||||||
m_gameId = id;
|
m_gameId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 WiiBanner::gameID() const
|
atUint64 WiiBanner::gameID() const
|
||||||
{
|
{
|
||||||
return m_gameId;
|
return m_gameId;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ void WiiBanner::addIcon(WiiImage* icon)
|
||||||
m_icons.push_back(icon);
|
m_icons.push_back(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setIcon(Uint32 id, WiiImage* icon)
|
void WiiBanner::setIcon(atUint32 id, WiiImage* icon)
|
||||||
{
|
{
|
||||||
if (m_icons[id] != NULL)
|
if (m_icons[id] != NULL)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +94,7 @@ void WiiBanner::setIcon(Uint32 id, WiiImage* icon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WiiImage* WiiBanner::getIcon(Uint32 id) const
|
WiiImage* WiiBanner::getIcon(atUint32 id) const
|
||||||
{
|
{
|
||||||
if (!m_icons[id])
|
if (!m_icons[id])
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -115,44 +116,45 @@ WiiImage* WiiBanner::bannerImage() const
|
||||||
return m_banner;
|
return m_banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setAnimationSpeed(Uint16 animSpeed)
|
void WiiBanner::setAnimationSpeed(atUint16 animSpeed)
|
||||||
{
|
{
|
||||||
m_animSpeed = animSpeed;
|
m_animSpeed = animSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 WiiBanner::animationSpeed() const
|
atUint16 WiiBanner::animationSpeed() const
|
||||||
{
|
{
|
||||||
return m_animSpeed;
|
return m_animSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setPermissions(Uint8 permissions)
|
void WiiBanner::setPermissions(atUint8 permissions)
|
||||||
{
|
{
|
||||||
m_permissions = permissions;
|
m_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 WiiBanner::permissions() const
|
atUint8 WiiBanner::permissions() const
|
||||||
{
|
{
|
||||||
return m_permissions;
|
return m_permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setBannerSize(Uint32 size)
|
void WiiBanner::setBannerSize(atUint32 size)
|
||||||
{
|
{
|
||||||
m_bannerSize = size;
|
m_bannerSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 WiiBanner::bannerSize() const
|
atUint32 WiiBanner::bannerSize() const
|
||||||
{
|
{
|
||||||
return m_bannerSize;
|
return m_bannerSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiBanner::setFlags(Uint32 flags)
|
void WiiBanner::setFlags(atUint32 flags)
|
||||||
{
|
{
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 WiiBanner::flags() const
|
atUint32 WiiBanner::flags() const
|
||||||
{
|
{
|
||||||
return m_flags;
|
return m_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -41,13 +42,13 @@ WiiFile::WiiFile(const std::string& filename) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WiiFile::WiiFile(const std::string& filename, Uint8 permissions, const Uint8* data, Uint32 length) :
|
WiiFile::WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length) :
|
||||||
m_permissions(permissions),
|
m_permissions(permissions),
|
||||||
m_attributes(0),
|
m_attributes(0),
|
||||||
m_type(WiiFile::File),
|
m_type(WiiFile::File),
|
||||||
m_filename(filename),
|
m_filename(filename),
|
||||||
m_fileLen(length),
|
m_fileLen(length),
|
||||||
m_fileData((Uint8*)data)
|
m_fileData((atUint8*)data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,27 +69,27 @@ std::string WiiFile::filename() const
|
||||||
return m_filename;
|
return m_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiFile::setPermissions(const Uint8 permissions)
|
void WiiFile::setPermissions(const atUint8 permissions)
|
||||||
{
|
{
|
||||||
m_permissions = (Uint8)permissions;
|
m_permissions = (atUint8)permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 WiiFile::permissions() const
|
atUint8 WiiFile::permissions() const
|
||||||
{
|
{
|
||||||
return m_permissions;
|
return m_permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiFile::setData(const Uint8* data)
|
void WiiFile::setData(const atUint8* data)
|
||||||
{
|
{
|
||||||
if (m_fileData)
|
if (m_fileData)
|
||||||
{
|
{
|
||||||
delete[] m_fileData;
|
delete[] m_fileData;
|
||||||
m_fileData = NULL;
|
m_fileData = NULL;
|
||||||
}
|
}
|
||||||
m_fileData = (Uint8*)data;
|
m_fileData = (atUint8*)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* WiiFile::data() const
|
atUint8* WiiFile::data() const
|
||||||
{
|
{
|
||||||
return m_fileData;
|
return m_fileData;
|
||||||
}
|
}
|
||||||
|
@ -103,12 +104,12 @@ int WiiFile::length() const
|
||||||
return m_fileLen;
|
return m_fileLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiFile::setAttributes(const Uint8 attr)
|
void WiiFile::setAttributes(const atUint8 attr)
|
||||||
{
|
{
|
||||||
m_attributes = attr;
|
m_attributes = attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 WiiFile::attributes() const
|
atUint8 WiiFile::attributes() const
|
||||||
{
|
{
|
||||||
return m_attributes;
|
return m_attributes;
|
||||||
}
|
}
|
||||||
|
@ -134,3 +135,4 @@ bool WiiFile::isFile() const
|
||||||
}
|
}
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
namespace Athena
|
namespace Athena
|
||||||
{
|
{
|
||||||
|
|
||||||
WiiImage::WiiImage(Uint32 width, Uint32 height, Uint8* data) :
|
WiiImage::WiiImage(atUint32 width, atUint32 height, atUint8* data) :
|
||||||
m_width(width),
|
m_width(width),
|
||||||
m_height(height),
|
m_height(height),
|
||||||
m_data(data)
|
m_data(data)
|
||||||
|
@ -35,29 +36,29 @@ WiiImage::~WiiImage()
|
||||||
m_data = NULL;
|
m_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* WiiImage::data()
|
atUint8* WiiImage::data()
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 WiiImage::width() const
|
atUint32 WiiImage::width() const
|
||||||
{
|
{
|
||||||
return m_width;
|
return m_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 WiiImage::height() const
|
atUint32 WiiImage::height() const
|
||||||
{
|
{
|
||||||
return m_height;
|
return m_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 *WiiImage::toRGBA()
|
atUint8 *WiiImage::toRGBA()
|
||||||
{
|
{
|
||||||
Uint32 x, y;
|
atUint32 x, y;
|
||||||
Uint32 x1, y1;
|
atUint32 x1, y1;
|
||||||
Uint32 iv;
|
atUint32 iv;
|
||||||
Uint8* bitmapdata = NULL;
|
atUint8* bitmapdata = NULL;
|
||||||
|
|
||||||
bitmapdata = new Uint8[m_width * m_height * 4];
|
bitmapdata = new atUint8[m_width * m_height * 4];
|
||||||
if(bitmapdata == NULL)
|
if(bitmapdata == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -69,29 +70,29 @@ Uint8 *WiiImage::toRGBA()
|
||||||
{
|
{
|
||||||
for(x = x1; x < (x1 + 4); x++)
|
for(x = x1; x < (x1 + 4); x++)
|
||||||
{
|
{
|
||||||
Uint16 oldpixel = *(Uint16*)(m_data + ((iv++) * 2));
|
atUint16 oldpixel = *(atUint16*)(m_data + ((iv++) * 2));
|
||||||
//if((x >= m_width) || (y >= m_height))
|
//if((x >= m_width) || (y >= m_height))
|
||||||
// continue;
|
// continue;
|
||||||
oldpixel = utility::swapU16(oldpixel);
|
oldpixel = utility::swapU16(oldpixel);
|
||||||
if(oldpixel & (1 << 15))
|
if(oldpixel & (1 << 15))
|
||||||
{
|
{
|
||||||
// RGB5
|
// RGB5
|
||||||
Uint8 b = (((oldpixel >> 10) & 0x1F) * 255) / 31;
|
atUint8 b = (((oldpixel >> 10) & 0x1F) * 255) / 31;
|
||||||
Uint8 g = (((oldpixel >> 5) & 0x1F) * 255) / 31;
|
atUint8 g = (((oldpixel >> 5) & 0x1F) * 255) / 31;
|
||||||
Uint8 r = (((oldpixel >> 0) & 0x1F) * 255) / 31;
|
atUint8 r = (((oldpixel >> 0) & 0x1F) * 255) / 31;
|
||||||
Uint8 a = 255;
|
atUint8 a = 255;
|
||||||
Uint8 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
|
atUint8 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
|
||||||
(*(Uint32**)&bitmapdata)[x + (y * m_width)] = rgba;
|
(*(atUint32**)&bitmapdata)[x + (y * m_width)] = rgba;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// RGB4A3
|
// RGB4A3
|
||||||
Uint8 a = (((oldpixel >> 12) & 0x7) * 255) / 7;
|
atUint8 a = (((oldpixel >> 12) & 0x7) * 255) / 7;
|
||||||
Uint8 b = (((oldpixel >> 8) & 0xF) * 255) / 15;
|
atUint8 b = (((oldpixel >> 8) & 0xF) * 255) / 15;
|
||||||
Uint8 g = (((oldpixel >> 4) & 0xF) * 255) / 15;
|
atUint8 g = (((oldpixel >> 4) & 0xF) * 255) / 15;
|
||||||
Uint8 r = (((oldpixel >> 0) & 0xF) * 255) / 15;
|
atUint8 r = (((oldpixel >> 0) & 0xF) * 255) / 15;
|
||||||
Uint32 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
|
atUint32 rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24);
|
||||||
(*(Uint32**)&bitmapdata)[x + (y * m_width)] = rgba;
|
(*(atUint32**)&bitmapdata)[x + (y * m_width)] = rgba;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,3 +102,4 @@ Uint8 *WiiImage::toRGBA()
|
||||||
}
|
}
|
||||||
|
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -36,7 +37,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
WiiSaveReader::WiiSaveReader(const Uint8* data, Uint64 length)
|
WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
setEndian(Endian::BigEndian);
|
setEndian(Endian::BigEndian);
|
||||||
|
@ -61,25 +62,25 @@ WiiSave* WiiSaveReader::readSave()
|
||||||
THROW_INVALID_DATA_EXCEPTION("Invalid banner");
|
THROW_INVALID_DATA_EXCEPTION("Invalid banner");
|
||||||
|
|
||||||
ret->setBanner(banner);
|
ret->setBanner(banner);
|
||||||
Uint32 bkVer = base::readUint32();
|
atUint32 bkVer = base::readUint32();
|
||||||
|
|
||||||
if (bkVer != 0x00000070)
|
if (bkVer != 0x00000070)
|
||||||
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header size");
|
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header size");
|
||||||
|
|
||||||
Uint32 bkMagic = base::readUint32();
|
atUint32 bkMagic = base::readUint32();
|
||||||
bkMagic = bkMagic;
|
bkMagic = bkMagic;
|
||||||
if (bkMagic != 0x426B0001)
|
if (bkMagic != 0x426B0001)
|
||||||
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header magic");
|
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header magic");
|
||||||
|
|
||||||
Uint32 ngId = base::readUint32();
|
atUint32 ngId = base::readUint32();
|
||||||
ngId = ngId;
|
ngId = ngId;
|
||||||
|
|
||||||
Uint32 numFiles = base::readUint32();
|
atUint32 numFiles = base::readUint32();
|
||||||
|
|
||||||
/*int fileSize =*/ base::readUint32();
|
/*int fileSize =*/ base::readUint32();
|
||||||
base::seek(8); // skip unknown data;
|
base::seek(8); // skip unknown data;
|
||||||
|
|
||||||
Uint32 totalSize = base::readUint32();
|
atUint32 totalSize = base::readUint32();
|
||||||
base::seek(64); // Unknown (Most likely padding)
|
base::seek(64); // Unknown (Most likely padding)
|
||||||
base::seek(8);
|
base::seek(8);
|
||||||
base::seek(6);
|
base::seek(6);
|
||||||
|
@ -87,7 +88,7 @@ WiiSave* WiiSaveReader::readSave()
|
||||||
base::seek(0x10);
|
base::seek(0x10);
|
||||||
|
|
||||||
std::unordered_map<std::string, WiiFile*> files;
|
std::unordered_map<std::string, WiiFile*> files;
|
||||||
for (Uint32 i = 0; i < numFiles; ++i)
|
for (atUint32 i = 0; i < numFiles; ++i)
|
||||||
{
|
{
|
||||||
WiiFile* file = readFile();
|
WiiFile* file = readFile();
|
||||||
if (file)
|
if (file)
|
||||||
|
@ -110,18 +111,18 @@ WiiSave* WiiSaveReader::readSave()
|
||||||
|
|
||||||
WiiBanner* WiiSaveReader::readBanner()
|
WiiBanner* WiiSaveReader::readBanner()
|
||||||
{
|
{
|
||||||
Uint8* dec = new Uint8[0xF0C0];
|
atUint8* dec = new atUint8[0xF0C0];
|
||||||
memset(dec, 0, 0xF0C0);
|
memset(dec, 0, 0xF0C0);
|
||||||
Uint8* data = (Uint8*)base::readBytes(0xF0C0);
|
atUint8* data = (atUint8*)base::readBytes(0xF0C0);
|
||||||
Uint8* oldData = base::data();
|
atUint8* oldData = base::data();
|
||||||
Uint64 oldPos = base::position();
|
atUint64 oldPos = base::position();
|
||||||
Uint64 oldLen = base::length();
|
atUint64 oldLen = base::length();
|
||||||
Uint64 gameId;
|
atUint64 gameId;
|
||||||
Uint32 bannerSize;
|
atUint32 bannerSize;
|
||||||
Uint8 permissions;
|
atUint8 permissions;
|
||||||
Uint8 md5[16];
|
atUint8 md5[16];
|
||||||
Uint8 md5Calc[16];
|
atUint8 md5Calc[16];
|
||||||
Uint8 tmpIV[26];
|
atUint8 tmpIV[26];
|
||||||
memcpy(tmpIV, SD_IV, 16);
|
memcpy(tmpIV, SD_IV, 16);
|
||||||
|
|
||||||
std::cout << "Decrypting: banner.bin...";
|
std::cout << "Decrypting: banner.bin...";
|
||||||
|
@ -232,11 +233,11 @@ WiiBanner* WiiSaveReader::readBanner()
|
||||||
return banner;
|
return banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
WiiImage* WiiSaveReader::readImage(Uint32 width, Uint32 height)
|
WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height)
|
||||||
{
|
{
|
||||||
Uint8* image = (Uint8*)base::readBytes(width*height*2);
|
atUint8* image = (atUint8*)base::readBytes(width*height*2);
|
||||||
|
|
||||||
if (!utility::isEmpty((Int8*)image, width*height*2))
|
if (!utility::isEmpty((atInt8*)image, width*height*2))
|
||||||
return new WiiImage(width, height, image);
|
return new WiiImage(width, height, image);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -245,15 +246,15 @@ WiiImage* WiiSaveReader::readImage(Uint32 width, Uint32 height)
|
||||||
|
|
||||||
WiiFile* WiiSaveReader::readFile()
|
WiiFile* WiiSaveReader::readFile()
|
||||||
{
|
{
|
||||||
Uint32 fileLen;
|
atUint32 fileLen;
|
||||||
Uint8 permissions;
|
atUint8 permissions;
|
||||||
Uint8 attributes;
|
atUint8 attributes;
|
||||||
Uint8 type;
|
atUint8 type;
|
||||||
std::string name;
|
std::string name;
|
||||||
Uint8* filedata;
|
atUint8* filedata;
|
||||||
WiiFile* ret;
|
WiiFile* ret;
|
||||||
|
|
||||||
Uint32 magic = base::readUint32();
|
atUint32 magic = base::readUint32();
|
||||||
if (magic != 0x03adf17e)
|
if (magic != 0x03adf17e)
|
||||||
{
|
{
|
||||||
std::cerr << "Not a valid File entry header: 0x" << std::hex << magic << std::endl;
|
std::cerr << "Not a valid File entry header: 0x" << std::hex << magic << std::endl;
|
||||||
|
@ -269,18 +270,18 @@ WiiFile* WiiSaveReader::readFile()
|
||||||
ret->setPermissions(permissions);
|
ret->setPermissions(permissions);
|
||||||
ret->setAttributes(attributes);
|
ret->setAttributes(attributes);
|
||||||
ret->setType((WiiFile::Type)type);
|
ret->setType((WiiFile::Type)type);
|
||||||
Uint8* iv = (Uint8*)base::readBytes(0x10);
|
atUint8* iv = (atUint8*)base::readBytes(0x10);
|
||||||
base::seek(0x20);
|
base::seek(0x20);
|
||||||
|
|
||||||
if (type == WiiFile::File)
|
if (type == WiiFile::File)
|
||||||
{
|
{
|
||||||
// Read file data
|
// Read file data
|
||||||
int roundedLen = (fileLen + 63) & ~63;
|
int roundedLen = (fileLen + 63) & ~63;
|
||||||
filedata = (Uint8*)base::readBytes(roundedLen);
|
filedata = (atUint8*)base::readBytes(roundedLen);
|
||||||
|
|
||||||
// Decrypt file
|
// Decrypt file
|
||||||
std::cout << "Decrypting: " << ret->filename() << "...";
|
std::cout << "Decrypting: " << ret->filename() << "...";
|
||||||
Uint8* decData = new Uint8[roundedLen];
|
atUint8* decData = new atUint8[roundedLen];
|
||||||
aes_set_key(SD_KEY);
|
aes_set_key(SD_KEY);
|
||||||
aes_decrypt(iv, filedata, decData, roundedLen);
|
aes_decrypt(iv, filedata, decData, roundedLen);
|
||||||
delete filedata;
|
delete filedata;
|
||||||
|
@ -293,19 +294,19 @@ WiiFile* WiiSaveReader::readFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WiiSaveReader::readCerts(Uint32 totalSize)
|
void WiiSaveReader::readCerts(atUint32 totalSize)
|
||||||
{
|
{
|
||||||
std::cout << "Reading certs..." << std::endl;
|
std::cout << "Reading certs..." << std::endl;
|
||||||
Uint32 dataSize = totalSize - 0x340;
|
atUint32 dataSize = totalSize - 0x340;
|
||||||
Uint8* sig = (Uint8*)base::readBytes(0x40);
|
atUint8* sig = (atUint8*)base::readBytes(0x40);
|
||||||
Uint8* ngCert = (Uint8*)base::readBytes(0x180);
|
atUint8* ngCert = (atUint8*)base::readBytes(0x180);
|
||||||
Uint8* apCert = (Uint8*)base::readBytes(0x180);
|
atUint8* apCert = (atUint8*)base::readBytes(0x180);
|
||||||
base::seek(0xF0C0, SeekOrigin::Begin);
|
base::seek(0xF0C0, SeekOrigin::Begin);
|
||||||
Uint8* data = (Uint8*)base::readBytes(dataSize);
|
atUint8* data = (atUint8*)base::readBytes(dataSize);
|
||||||
Uint8* hash;
|
atUint8* hash;
|
||||||
|
|
||||||
hash = getSha1(data, dataSize);
|
hash = getSha1(data, dataSize);
|
||||||
Uint8* hash2 = getSha1(hash, 20);
|
atUint8* hash2 = getSha1(hash, 20);
|
||||||
|
|
||||||
std::cout << "validating..." << std::endl;
|
std::cout << "validating..." << std::endl;
|
||||||
std::cout << (check_ec(ngCert, apCert, sig, hash2) ? "ok" : "invalid") << "...";
|
std::cout << (check_ec(ngCert, apCert, sig, hash2) ? "ok" : "invalid") << "...";
|
||||||
|
@ -314,3 +315,4 @@ void WiiSaveReader::readCerts(Uint32 totalSize)
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_SAVES
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -51,7 +52,7 @@ WiiSaveWriter::WiiSaveWriter(const std::string &filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WiiSaveWriter::writeSave(WiiSave *save, Uint8 *macAddress, Uint32 ngId, Uint8 *ngPriv, Uint8 *ngSig, Uint32 ngKeyId,const std::string &filepath)
|
bool WiiSaveWriter::writeSave(WiiSave *save, atUint8 *macAddress, atUint32 ngId, atUint8 *ngPriv, atUint8 *ngSig, atUint32 ngKeyId,const std::string &filepath)
|
||||||
{
|
{
|
||||||
if (!save)
|
if (!save)
|
||||||
THROW_INVALID_OPERATION_EXCEPTION("save cannot be NULL");
|
THROW_INVALID_OPERATION_EXCEPTION("save cannot be NULL");
|
||||||
|
@ -69,10 +70,10 @@ bool WiiSaveWriter::writeSave(WiiSave *save, Uint8 *macAddress, Uint32 ngId, Uin
|
||||||
base::writeUint32(0); // totalSize
|
base::writeUint32(0); // totalSize
|
||||||
base::seek(64);
|
base::seek(64);
|
||||||
base::writeUint64(save->banner()->gameID());
|
base::writeUint64(save->banner()->gameID());
|
||||||
base::writeBytes((Int8*)macAddress, 6);
|
base::writeBytes((atInt8*)macAddress, 6);
|
||||||
base::seek(2); // unknown;
|
base::seek(2); // unknown;
|
||||||
base::seek(0x10); // padding;
|
base::seek(0x10); // padding;
|
||||||
Uint32 totalSize = 0;
|
atUint32 totalSize = 0;
|
||||||
for (std::unordered_map<std::string, WiiFile*>::const_iterator iter = save->fileList().begin(); iter != save->fileList().end(); ++iter)
|
for (std::unordered_map<std::string, WiiFile*>::const_iterator iter = save->fileList().begin(); iter != save->fileList().end(); ++iter)
|
||||||
{
|
{
|
||||||
totalSize += writeFile(iter->second);
|
totalSize += writeFile(iter->second);
|
||||||
|
@ -97,9 +98,9 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner)
|
||||||
base::setEndian(Endian::BigEndian);
|
base::setEndian(Endian::BigEndian);
|
||||||
base::writeInt64(banner->gameID());
|
base::writeInt64(banner->gameID());
|
||||||
base::writeInt32((0x60a0+0x1200)*banner->icons().size());
|
base::writeInt32((0x60a0+0x1200)*banner->icons().size());
|
||||||
base::writeByte((Int8)banner->permissions());
|
base::writeByte((atInt8)banner->permissions());
|
||||||
base::seek(1);
|
base::seek(1);
|
||||||
base::writeBytes((Int8*)MD5_BLANKER, 16);
|
base::writeBytes((atInt8*)MD5_BLANKER, 16);
|
||||||
base::seek(2);
|
base::seek(2);
|
||||||
base::writeInt32(0x5749424E); // WIBN
|
base::writeInt32(0x5749424E); // WIBN
|
||||||
base::writeInt32(banner->flags());
|
base::writeInt32(banner->flags());
|
||||||
|
@ -117,12 +118,12 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner)
|
||||||
base::seek(0x00C0, SeekOrigin::Begin);
|
base::seek(0x00C0, SeekOrigin::Begin);
|
||||||
|
|
||||||
WiiImage* bannerImage = banner->bannerImage();
|
WiiImage* bannerImage = banner->bannerImage();
|
||||||
base::writeBytes((Int8*)bannerImage->data(), bannerImage->width()*bannerImage->height()*2);
|
base::writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height()*2);
|
||||||
|
|
||||||
// For empty icons
|
// For empty icons
|
||||||
Uint8* tmpIcon = new Uint8[48*48*2];
|
atUint8* tmpIcon = new atUint8[48*48*2];
|
||||||
memset(tmpIcon, 0, 48*48*2);
|
memset(tmpIcon, 0, 48*48*2);
|
||||||
for (Uint32 i = 0; i < 8; ++i)
|
for (atUint32 i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if (i < banner->icons().size())
|
if (i < banner->icons().size())
|
||||||
{
|
{
|
||||||
|
@ -130,32 +131,32 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
base::writeBytes((Int8*)tmpIcon, 48*48*2);
|
base::writeBytes((atInt8*)tmpIcon, 48*48*2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] tmpIcon; // delete tmp buffer;
|
delete[] tmpIcon; // delete tmp buffer;
|
||||||
|
|
||||||
Uint8* hash = new Uint8[0x10];
|
atUint8* hash = new atUint8[0x10];
|
||||||
MD5Hash::MD5(hash, (Uint8*)base::data(), 0xF0C0);
|
MD5Hash::MD5(hash, (atUint8*)base::data(), 0xF0C0);
|
||||||
base::seek(0x0E, SeekOrigin::Begin);
|
base::seek(0x0E, SeekOrigin::Begin);
|
||||||
base::writeBytes((Int8*)hash, 0x10);
|
base::writeBytes((atInt8*)hash, 0x10);
|
||||||
|
|
||||||
aes_set_key(SD_KEY);
|
aes_set_key(SD_KEY);
|
||||||
Uint8 data[0xF0C0];
|
atUint8 data[0xF0C0];
|
||||||
memcpy(data, base::data(), 0xF0C0);
|
memcpy(data, base::data(), 0xF0C0);
|
||||||
Uint8 tmpIV[26];
|
atUint8 tmpIV[26];
|
||||||
memcpy(tmpIV, SD_IV, 16);
|
memcpy(tmpIV, SD_IV, 16);
|
||||||
aes_encrypt(tmpIV, data, data, 0xF0C0);
|
aes_encrypt(tmpIV, data, data, 0xF0C0);
|
||||||
|
|
||||||
base::seek(0, SeekOrigin::Begin);
|
base::seek(0, SeekOrigin::Begin);
|
||||||
base::writeBytes((Int8*)data, 0xF0C0);
|
base::writeBytes((atInt8*)data, 0xF0C0);
|
||||||
base::seek(0xF0C0, SeekOrigin::Begin);
|
base::seek(0xF0C0, SeekOrigin::Begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 WiiSaveWriter::writeFile(WiiFile *file)
|
atUint32 WiiSaveWriter::writeFile(WiiFile *file)
|
||||||
{
|
{
|
||||||
Uint32 ret = 0x80;
|
atUint32 ret = 0x80;
|
||||||
|
|
||||||
// Write the File magic
|
// Write the File magic
|
||||||
base::writeUint32(0x03ADF17E);
|
base::writeUint32(0x03ADF17E);
|
||||||
|
@ -164,28 +165,28 @@ Uint32 WiiSaveWriter::writeFile(WiiFile *file)
|
||||||
base::writeByte(file->attributes());
|
base::writeByte(file->attributes());
|
||||||
base::writeByte(file->type());
|
base::writeByte(file->type());
|
||||||
|
|
||||||
Uint8 name[0x45];
|
atUint8 name[0x45];
|
||||||
utility::fillRandom(name, 0x45);
|
utility::fillRandom(name, 0x45);
|
||||||
memcpy(name, file->filename().c_str(), file->filename().size());
|
memcpy(name, file->filename().c_str(), file->filename().size());
|
||||||
name[file->filename().size()] = '\0';
|
name[file->filename().size()] = '\0';
|
||||||
base::writeBytes((Int8*)name, 0x45);
|
base::writeBytes((atInt8*)name, 0x45);
|
||||||
Uint8 iv[16];
|
atUint8 iv[16];
|
||||||
utility::fillRandom(iv, 0x10);
|
utility::fillRandom(iv, 0x10);
|
||||||
base::writeBytes((Int8*)iv, 0x10);
|
base::writeBytes((atInt8*)iv, 0x10);
|
||||||
Uint8 crap[0x20];
|
atUint8 crap[0x20];
|
||||||
utility::fillRandom(crap, 0x20);
|
utility::fillRandom(crap, 0x20);
|
||||||
base::writeBytes((Int8*)crap, 0x20);
|
base::writeBytes((atInt8*)crap, 0x20);
|
||||||
|
|
||||||
if (file->type() == WiiFile::File)
|
if (file->type() == WiiFile::File)
|
||||||
{
|
{
|
||||||
int roundedSize = (file->length() + 63) & ~63;
|
int roundedSize = (file->length() + 63) & ~63;
|
||||||
Uint8* data = new Uint8[roundedSize];
|
atUint8* data = new atUint8[roundedSize];
|
||||||
memset(data, 0, roundedSize);
|
memset(data, 0, roundedSize);
|
||||||
|
|
||||||
aes_set_key(SD_KEY);
|
aes_set_key(SD_KEY);
|
||||||
aes_encrypt(iv, file->data(), data, roundedSize);
|
aes_encrypt(iv, file->data(), data, roundedSize);
|
||||||
|
|
||||||
base::writeBytes((Int8*)data, roundedSize);
|
base::writeBytes((atInt8*)data, roundedSize);
|
||||||
ret += roundedSize;
|
ret += roundedSize;
|
||||||
delete[] data;
|
delete[] data;
|
||||||
}
|
}
|
||||||
|
@ -196,22 +197,22 @@ Uint32 WiiSaveWriter::writeFile(WiiFile *file)
|
||||||
|
|
||||||
void WiiSaveWriter::writeImage(WiiImage* image)
|
void WiiSaveWriter::writeImage(WiiImage* image)
|
||||||
{
|
{
|
||||||
Int8* data = (Int8*)image->data();
|
atInt8* data = (atInt8*)image->data();
|
||||||
base::writeBytes(data, image->width() * image->height() * 2);
|
base::writeBytes(data, image->width() * image->height() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uint8 *ngSig, Uint32 ngKeyId)
|
void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8 *ngPriv, atUint8 *ngSig, atUint32 ngKeyId)
|
||||||
{
|
{
|
||||||
Uint8 sig[0x40];
|
atUint8 sig[0x40];
|
||||||
Uint8 ngCert[0x180];
|
atUint8 ngCert[0x180];
|
||||||
Uint8 apCert[0x180];
|
atUint8 apCert[0x180];
|
||||||
Uint8* hash;
|
atUint8* hash;
|
||||||
Uint8 apPriv[30];
|
atUint8 apPriv[30];
|
||||||
Uint8 apSig[60];
|
atUint8 apSig[60];
|
||||||
char signer[64];
|
char signer[64];
|
||||||
char name[64];
|
char name[64];
|
||||||
Uint8* data;
|
atUint8* data;
|
||||||
Uint32 dataSize;
|
atUint32 dataSize;
|
||||||
|
|
||||||
sprintf(signer, "Root-CA00000001-MS00000002");
|
sprintf(signer, "Root-CA00000001-MS00000002");
|
||||||
sprintf(name, "NG%08x", ngId);
|
sprintf(name, "NG%08x", ngId);
|
||||||
|
@ -232,12 +233,12 @@ void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uin
|
||||||
delete[] hash;
|
delete[] hash;
|
||||||
|
|
||||||
dataSize = filesSize + 0x80;
|
dataSize = filesSize + 0x80;
|
||||||
data = new Uint8[dataSize];
|
data = new atUint8[dataSize];
|
||||||
Uint8* rawData = base::data();
|
atUint8* rawData = base::data();
|
||||||
memcpy(data, rawData + 0xF0C0, dataSize);
|
memcpy(data, rawData + 0xF0C0, dataSize);
|
||||||
|
|
||||||
hash = getSha1(data, dataSize);
|
hash = getSha1(data, dataSize);
|
||||||
Uint8* hash2 = getSha1(hash, 20);
|
atUint8* hash2 = getSha1(hash, 20);
|
||||||
delete[] hash;
|
delete[] hash;
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
|
||||||
|
@ -246,13 +247,14 @@ void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uin
|
||||||
if (!utility::isSystemBigEndian())
|
if (!utility::isSystemBigEndian())
|
||||||
stuff = utility::swap32(stuff);
|
stuff = utility::swap32(stuff);
|
||||||
|
|
||||||
*(Uint32*)(sig+60) = stuff;
|
*(atUint32*)(sig+60) = stuff;
|
||||||
delete[] hash2;
|
delete[] hash2;
|
||||||
|
|
||||||
base::writeBytes((Int8*)sig, 0x40);
|
base::writeBytes((atInt8*)sig, 0x40);
|
||||||
base::writeBytes((Int8*)ngCert, 0x180);
|
base::writeBytes((atInt8*)ngCert, 0x180);
|
||||||
base::writeBytes((Int8*)apCert, 0x180);
|
base::writeBytes((atInt8*)apCert, 0x180);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#endif // ATHENA_NO_SAVES
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
#include "Athena/ZQuestFile.hpp"
|
#include "Athena/ZQuestFile.hpp"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace Athena
|
namespace Athena
|
||||||
|
@ -43,13 +45,13 @@ void initGameStrings()
|
||||||
GameStrings.push_back("A Link Between Worlds");
|
GameStrings.push_back("A Link Between Worlds");
|
||||||
}
|
}
|
||||||
|
|
||||||
const Uint32 ZQuestFile::Major = 2;
|
const atUint32 ZQuestFile::Major = 2;
|
||||||
const Uint32 ZQuestFile::Minor = 0;
|
const atUint32 ZQuestFile::Minor = 0;
|
||||||
const Uint32 ZQuestFile::Revision = 0;
|
const atUint32 ZQuestFile::Revision = 0;
|
||||||
|
|
||||||
const Uint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
|
const atUint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
|
||||||
|
|
||||||
const Uint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
|
const atUint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
|
||||||
|
|
||||||
ZQuestFile::ZQuestFile()
|
ZQuestFile::ZQuestFile()
|
||||||
: m_game(NoGame),
|
: m_game(NoGame),
|
||||||
|
@ -60,7 +62,7 @@ ZQuestFile::ZQuestFile()
|
||||||
initGameStrings();
|
initGameStrings();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, Uint8* data, Uint32 length, const std::string& gameString)
|
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, atUint8* data, atUint32 length, const std::string& gameString)
|
||||||
: m_game(game),
|
: m_game(game),
|
||||||
m_gameString(gameString),
|
m_gameString(gameString),
|
||||||
m_endian(endian),
|
m_endian(endian),
|
||||||
|
@ -103,14 +105,14 @@ Endian ZQuestFile::endian() const
|
||||||
return m_endian;
|
return m_endian;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZQuestFile::setData(Uint8* data, Uint32 length)
|
void ZQuestFile::setData(atUint8* data, atUint32 length)
|
||||||
{
|
{
|
||||||
// ensure we're not overwritting our data without freeing first
|
// ensure we're not overwritting our data without freeing first
|
||||||
// or assigning unnecessisarily
|
// or assigning unnecessisarily
|
||||||
if (!m_data || m_data != data)
|
if (!m_data || m_data != data)
|
||||||
{
|
{
|
||||||
delete[] m_data;
|
delete[] m_data;
|
||||||
m_data = new Uint8[length];
|
m_data = new atUint8[length];
|
||||||
// Why is this memcpy needed?
|
// Why is this memcpy needed?
|
||||||
// I get SIGABRT without it, need to research
|
// I get SIGABRT without it, need to research
|
||||||
memcpy(m_data, data, length);
|
memcpy(m_data, data, length);
|
||||||
|
@ -118,13 +120,13 @@ void ZQuestFile::setData(Uint8* data, Uint32 length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* ZQuestFile::data() const
|
atUint8* ZQuestFile::data() const
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Uint32 ZQuestFile::length() const
|
atUint32 ZQuestFile::length() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
@ -146,3 +148,5 @@ const std::vector<std::string> ZQuestFile::gameStringList()
|
||||||
return GameStrings;
|
return GameStrings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_ZQUEST
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
#include "Athena/InvalidDataException.hpp"
|
#include "Athena/InvalidDataException.hpp"
|
||||||
#include "Athena/Checksums.hpp"
|
#include "Athena/Checksums.hpp"
|
||||||
#include "Athena/Utility.hpp"
|
#include "Athena/Utility.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
ZQuestFileReader::ZQuestFileReader(Uint8 *data, Uint64 length)
|
ZQuestFileReader::ZQuestFileReader(atUint8 *data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -40,12 +42,12 @@ ZQuestFileReader::ZQuestFileReader(const std::string &filename)
|
||||||
|
|
||||||
ZQuestFile *ZQuestFileReader::read()
|
ZQuestFile *ZQuestFileReader::read()
|
||||||
{
|
{
|
||||||
Uint32 magic, version, compressedLen, uncompressedLen;
|
atUint32 magic, version, compressedLen, uncompressedLen;
|
||||||
ZQuestFile::Game game = ZQuestFile::NoGame;
|
ZQuestFile::Game game = ZQuestFile::NoGame;
|
||||||
std::string gameString;
|
std::string gameString;
|
||||||
Uint16 BOM;
|
atUint16 BOM;
|
||||||
Uint32 checksum;
|
atUint32 checksum;
|
||||||
Uint8* data;
|
atUint8* data;
|
||||||
|
|
||||||
magic = base::readUint32();
|
magic = base::readUint32();
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ ZQuestFile *ZQuestFileReader::read()
|
||||||
base::seek(0x0A);
|
base::seek(0x0A);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (Uint8*)base::readBytes(compressedLen); // compressedLen is always the total file size
|
data = (atUint8*)base::readBytes(compressedLen); // compressedLen is always the total file size
|
||||||
|
|
||||||
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
|
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
|
||||||
{
|
{
|
||||||
|
@ -101,8 +103,8 @@ ZQuestFile *ZQuestFileReader::read()
|
||||||
|
|
||||||
if (compressedLen != uncompressedLen)
|
if (compressedLen != uncompressedLen)
|
||||||
{
|
{
|
||||||
Uint8* dst = new Uint8[uncompressedLen];
|
atUint8* dst = new atUint8[uncompressedLen];
|
||||||
Uint32 dstLen = io::Compression::decompressZlib(data, compressedLen, dst, uncompressedLen);
|
atUint32 dstLen = io::Compression::decompressZlib(data, compressedLen, dst, uncompressedLen);
|
||||||
|
|
||||||
if (dstLen != uncompressedLen)
|
if (dstLen != uncompressedLen)
|
||||||
{
|
{
|
||||||
|
@ -121,3 +123,5 @@ ZQuestFile *ZQuestFileReader::read()
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef ATHENA_NO_ZQUEST
|
||||||
// This file is part of libAthena.
|
// This file is part of libAthena.
|
||||||
//
|
//
|
||||||
// libAthena is free software: you can redistribute it and/or modify
|
// libAthena is free software: you can redistribute it and/or modify
|
||||||
|
@ -24,7 +25,7 @@ namespace Athena
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
ZQuestFileWriter::ZQuestFileWriter(Uint8* data, Uint64 length)
|
ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length)
|
||||||
: base(data, length)
|
: base(data, length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -41,11 +42,11 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
|
||||||
|
|
||||||
base::writeUint32(ZQuestFile::Magic);
|
base::writeUint32(ZQuestFile::Magic);
|
||||||
base::writeUint32(ZQuestFile::Version);
|
base::writeUint32(ZQuestFile::Version);
|
||||||
Uint8* questData = quest->data();
|
atUint8* questData = quest->data();
|
||||||
Uint32 compLen;
|
atUint32 compLen;
|
||||||
if (compress)
|
if (compress)
|
||||||
{
|
{
|
||||||
Uint8* compData = new Uint8[quest->length() + 0x40]; // add 20 bytes because sometimes the file grows with compression
|
atUint8* compData = new atUint8[quest->length() + 0x40]; // add 20 bytes because sometimes the file grows with compression
|
||||||
compLen = quest->length() + 0x40;
|
compLen = quest->length() + 0x40;
|
||||||
compLen = io::Compression::compressZlib(questData, quest->length(), compData, compLen);
|
compLen = io::Compression::compressZlib(questData, quest->length(), compData, compLen);
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
|
||||||
}
|
}
|
||||||
|
|
||||||
base::writeUint32(quest->length());
|
base::writeUint32(quest->length());
|
||||||
base::writeBytes((Int8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
|
base::writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
|
||||||
base::writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
|
base::writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
|
||||||
base::writeUint32(Athena::Checksums::crc32(questData, compLen));
|
base::writeUint32(Athena::Checksums::crc32(questData, compLen));
|
||||||
base::writeUBytes(questData, compLen);
|
base::writeUBytes(questData, compLen);
|
||||||
|
@ -88,3 +89,5 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
|
||||||
|
|
||||||
} // io
|
} // io
|
||||||
} // zelda
|
} // zelda
|
||||||
|
|
||||||
|
#endif // ATHENA_NO_ZQUEST
|
||||||
|
|
124
src/aes.c
124
src/aes.c
|
@ -25,38 +25,38 @@
|
||||||
|
|
||||||
/* Fixed Data */
|
/* Fixed Data */
|
||||||
|
|
||||||
static Uint8 InCo[4]={0xB,0xD,0x9,0xE}; /* Inverse Coefficients */
|
static atUint8 InCo[4]={0xB,0xD,0x9,0xE}; /* Inverse Coefficients */
|
||||||
|
|
||||||
static Uint8 fbsub[256];
|
static atUint8 fbsub[256];
|
||||||
static Uint8 rbsub[256];
|
static atUint8 rbsub[256];
|
||||||
static Uint8 ptab[256],ltab[256];
|
static atUint8 ptab[256],ltab[256];
|
||||||
static Uint32 ftable[256];
|
static atUint32 ftable[256];
|
||||||
static Uint32 rtable[256];
|
static atUint32 rtable[256];
|
||||||
static Uint32 rco[30];
|
static atUint32 rco[30];
|
||||||
|
|
||||||
/* Parameter-dependent data */
|
/* Parameter-dependent data */
|
||||||
|
|
||||||
int Nk,Nb,Nr;
|
int Nk,Nb,Nr;
|
||||||
Uint8 fi[24],ri[24];
|
atUint8 fi[24],ri[24];
|
||||||
Uint32 fkey[120];
|
atUint32 fkey[120];
|
||||||
Uint32 rkey[120];
|
atUint32 rkey[120];
|
||||||
|
|
||||||
static Uint32 pack(const Uint8 *b)
|
static atUint32 pack(const atUint8 *b)
|
||||||
{ /* pack bytes into a 32-bit Word */
|
{ /* pack bytes into a 32-bit Word */
|
||||||
return ((Uint32)b[3]<<24)|((Uint32)b[2]<<16)|((Uint32)b[1]<<8)|(Uint32)b[0];
|
return ((atUint32)b[3]<<24)|((atUint32)b[2]<<16)|((atUint32)b[1]<<8)|(atUint32)b[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unpack(Uint32 a,Uint8 *b)
|
static void unpack(atUint32 a,atUint8 *b)
|
||||||
{ /* unpack bytes from a word */
|
{ /* unpack bytes from a word */
|
||||||
b[0]=(Uint8)a;
|
b[0]=(atUint8)a;
|
||||||
b[1]=(Uint8)(a>>8);
|
b[1]=(atUint8)(a>>8);
|
||||||
b[2]=(Uint8)(a>>16);
|
b[2]=(atUint8)(a>>16);
|
||||||
b[3]=(Uint8)(a>>24);
|
b[3]=(atUint8)(a>>24);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 xtime(Uint8 a)
|
static atUint8 xtime(atUint8 a)
|
||||||
{
|
{
|
||||||
Uint8 b;
|
atUint8 b;
|
||||||
if (a&0x80) b=0x1B;
|
if (a&0x80) b=0x1B;
|
||||||
else b=0;
|
else b=0;
|
||||||
a<<=1;
|
a<<=1;
|
||||||
|
@ -64,15 +64,15 @@ static Uint8 xtime(Uint8 a)
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 bmul(Uint8 x,Uint8 y)
|
static atUint8 bmul(atUint8 x,atUint8 y)
|
||||||
{ /* x.y= AntiLog(Log(x) + Log(y)) */
|
{ /* x.y= AntiLog(Log(x) + Log(y)) */
|
||||||
if (x && y) return ptab[(ltab[x]+ltab[y])%255];
|
if (x && y) return ptab[(ltab[x]+ltab[y])%255];
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint32 SubByte(Uint32 a)
|
static atUint32 SubByte(atUint32 a)
|
||||||
{
|
{
|
||||||
Uint8 b[4];
|
atUint8 b[4];
|
||||||
unpack(a,b);
|
unpack(a,b);
|
||||||
b[0]=fbsub[b[0]];
|
b[0]=fbsub[b[0]];
|
||||||
b[1]=fbsub[b[1]];
|
b[1]=fbsub[b[1]];
|
||||||
|
@ -81,18 +81,18 @@ static Uint32 SubByte(Uint32 a)
|
||||||
return pack(b);
|
return pack(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 product(Uint32 x,Uint32 y)
|
static atUint8 product(atUint32 x,atUint32 y)
|
||||||
{ /* dot product of two 4-byte arrays */
|
{ /* dot product of two 4-byte arrays */
|
||||||
Uint8 xb[4],yb[4];
|
atUint8 xb[4],yb[4];
|
||||||
unpack(x,xb);
|
unpack(x,xb);
|
||||||
unpack(y,yb);
|
unpack(y,yb);
|
||||||
return bmul(xb[0],yb[0])^bmul(xb[1],yb[1])^bmul(xb[2],yb[2])^bmul(xb[3],yb[3]);
|
return bmul(xb[0],yb[0])^bmul(xb[1],yb[1])^bmul(xb[2],yb[2])^bmul(xb[3],yb[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint32 InvMixCol(Uint32 x)
|
static atUint32 InvMixCol(atUint32 x)
|
||||||
{ /* matrix Multiplication */
|
{ /* matrix Multiplication */
|
||||||
Uint32 y,m;
|
atUint32 y,m;
|
||||||
Uint8 b[4];
|
atUint8 b[4];
|
||||||
|
|
||||||
m=pack(InCo);
|
m=pack(InCo);
|
||||||
b[3]=product(m,x);
|
b[3]=product(m,x);
|
||||||
|
@ -106,9 +106,9 @@ static Uint32 InvMixCol(Uint32 x)
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 ByteSub(Uint8 x)
|
atUint8 ByteSub(atUint8 x)
|
||||||
{
|
{
|
||||||
Uint8 y=ptab[255-ltab[x]]; /* multiplicative inverse */
|
atUint8 y=ptab[255-ltab[x]]; /* multiplicative inverse */
|
||||||
x=y; x=ROTL(x);
|
x=y; x=ROTL(x);
|
||||||
y^=x; x=ROTL(x);
|
y^=x; x=ROTL(x);
|
||||||
y^=x; x=ROTL(x);
|
y^=x; x=ROTL(x);
|
||||||
|
@ -120,7 +120,7 @@ Uint8 ByteSub(Uint8 x)
|
||||||
void gentables(void)
|
void gentables(void)
|
||||||
{ /* generate tables */
|
{ /* generate tables */
|
||||||
int i;
|
int i;
|
||||||
Uint8 y,b[4];
|
atUint8 y,b[4];
|
||||||
|
|
||||||
/* use 3 as primitive root to generate power and log tables */
|
/* use 3 as primitive root to generate power and log tables */
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ void gentables(void)
|
||||||
rbsub[0x63]=0;
|
rbsub[0x63]=0;
|
||||||
for (i=1;i<256;i++)
|
for (i=1;i<256;i++)
|
||||||
{
|
{
|
||||||
y=ByteSub((Uint8)i);
|
y=ByteSub((atUint8)i);
|
||||||
fbsub[i]=y; rbsub[y]=i;
|
fbsub[i]=y; rbsub[y]=i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,14 +164,14 @@ void gentables(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gkey(int nb,int nk, const Uint8 *key)
|
void gkey(int nb,int nk, const atUint8 *key)
|
||||||
{ /* blocksize=32*nb bits. Key=32*nk bits */
|
{ /* blocksize=32*nb bits. Key=32*nk bits */
|
||||||
/* currently nb,bk = 4, 6 or 8 */
|
/* currently nb,bk = 4, 6 or 8 */
|
||||||
/* key comes as 4*Nk bytes */
|
/* key comes as 4*Nk bytes */
|
||||||
/* Key Scheduler. Create expanded encryption key */
|
/* Key Scheduler. Create expanded encryption key */
|
||||||
int i,j,k,m,N;
|
int i,j,k,m,N;
|
||||||
int C1,C2,C3;
|
int C1,C2,C3;
|
||||||
Uint32 CipherKey[8];
|
atUint32 CipherKey[8];
|
||||||
|
|
||||||
Nb=nb; Nk=nk;
|
Nb=nb; Nk=nk;
|
||||||
|
|
||||||
|
@ -236,10 +236,10 @@ void gkey(int nb,int nk, const Uint8 *key)
|
||||||
* Instead of just one ftable[], I could have 4, the other *
|
* Instead of just one ftable[], I could have 4, the other *
|
||||||
* 3 pre-rotated to save the ROTL8, ROTL16 and ROTL24 overhead */
|
* 3 pre-rotated to save the ROTL8, ROTL16 and ROTL24 overhead */
|
||||||
|
|
||||||
void encrypt(Uint8 *buff)
|
void encrypt(atUint8 *buff)
|
||||||
{
|
{
|
||||||
int i,j,k,m;
|
int i,j,k,m;
|
||||||
Uint32 a[8],b[8],*x,*y,*t;
|
atUint32 a[8],b[8],*x,*y,*t;
|
||||||
|
|
||||||
for (i=j=0;i<Nb;i++,j+=4)
|
for (i=j=0;i<Nb;i++,j+=4)
|
||||||
{
|
{
|
||||||
|
@ -259,10 +259,10 @@ void encrypt(Uint8 *buff)
|
||||||
for (m=j=0;j<Nb;j++,m+=3)
|
for (m=j=0;j<Nb;j++,m+=3)
|
||||||
{ /* deal with each 32-bit element of the State */
|
{ /* deal with each 32-bit element of the State */
|
||||||
/* This is the time-critical bit */
|
/* This is the time-critical bit */
|
||||||
y[j]=fkey[k++]^ftable[(Uint8)x[j]]^
|
y[j]=fkey[k++]^ftable[(atUint8)x[j]]^
|
||||||
ROTL8(ftable[(Uint8)(x[fi[m]]>>8)])^
|
ROTL8(ftable[(atUint8)(x[fi[m]]>>8)])^
|
||||||
ROTL16(ftable[(Uint8)(x[fi[m+1]]>>16)])^
|
ROTL16(ftable[(atUint8)(x[fi[m+1]]>>16)])^
|
||||||
ROTL24(ftable[(Uint8)(x[fi[m+2]]>>24)]);
|
ROTL24(ftable[(atUint8)(x[fi[m+2]]>>24)]);
|
||||||
}
|
}
|
||||||
t=x; x=y; y=t; /* swap pointers */
|
t=x; x=y; y=t; /* swap pointers */
|
||||||
}
|
}
|
||||||
|
@ -270,23 +270,23 @@ void encrypt(Uint8 *buff)
|
||||||
/* Last Round - unroll if possible */
|
/* Last Round - unroll if possible */
|
||||||
for (m=j=0;j<Nb;j++,m+=3)
|
for (m=j=0;j<Nb;j++,m+=3)
|
||||||
{
|
{
|
||||||
y[j]=fkey[k++]^(Uint32)fbsub[(Uint8)x[j]]^
|
y[j]=fkey[k++]^(atUint32)fbsub[(atUint8)x[j]]^
|
||||||
ROTL8((Uint32)fbsub[(Uint8)(x[fi[m]]>>8)])^
|
ROTL8((atUint32)fbsub[(atUint8)(x[fi[m]]>>8)])^
|
||||||
ROTL16((Uint32)fbsub[(Uint8)(x[fi[m+1]]>>16)])^
|
ROTL16((atUint32)fbsub[(atUint8)(x[fi[m+1]]>>16)])^
|
||||||
ROTL24((Uint32)fbsub[(Uint8)(x[fi[m+2]]>>24)]);
|
ROTL24((atUint32)fbsub[(atUint8)(x[fi[m+2]]>>24)]);
|
||||||
}
|
}
|
||||||
for (i=j=0;i<Nb;i++,j+=4)
|
for (i=j=0;i<Nb;i++,j+=4)
|
||||||
{
|
{
|
||||||
unpack(y[i],(Uint8 *)&buff[j]);
|
unpack(y[i],(atUint8 *)&buff[j]);
|
||||||
x[i]=y[i]=0; /* clean up stack */
|
x[i]=y[i]=0; /* clean up stack */
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void decrypt(Uint8 *buff)
|
void decrypt(atUint8 *buff)
|
||||||
{
|
{
|
||||||
int i,j,k,m;
|
int i,j,k,m;
|
||||||
Uint32 a[8],b[8],*x,*y,*t;
|
atUint32 a[8],b[8],*x,*y,*t;
|
||||||
|
|
||||||
for (i=j=0;i<Nb;i++,j+=4)
|
for (i=j=0;i<Nb;i++,j+=4)
|
||||||
{
|
{
|
||||||
|
@ -305,10 +305,10 @@ void decrypt(Uint8 *buff)
|
||||||
|
|
||||||
for (m=j=0;j<Nb;j++,m+=3)
|
for (m=j=0;j<Nb;j++,m+=3)
|
||||||
{ /* This is the time-critical bit */
|
{ /* This is the time-critical bit */
|
||||||
y[j]=rkey[k++]^rtable[(Uint8)x[j]]^
|
y[j]=rkey[k++]^rtable[(atUint8)x[j]]^
|
||||||
ROTL8(rtable[(Uint8)(x[ri[m]]>>8)])^
|
ROTL8(rtable[(atUint8)(x[ri[m]]>>8)])^
|
||||||
ROTL16(rtable[(Uint8)(x[ri[m+1]]>>16)])^
|
ROTL16(rtable[(atUint8)(x[ri[m+1]]>>16)])^
|
||||||
ROTL24(rtable[(Uint8)(x[ri[m+2]]>>24)]);
|
ROTL24(rtable[(atUint8)(x[ri[m+2]]>>24)]);
|
||||||
}
|
}
|
||||||
t=x; x=y; y=t; /* swap pointers */
|
t=x; x=y; y=t; /* swap pointers */
|
||||||
}
|
}
|
||||||
|
@ -316,28 +316,28 @@ void decrypt(Uint8 *buff)
|
||||||
/* Last Round - unroll if possible */
|
/* Last Round - unroll if possible */
|
||||||
for (m=j=0;j<Nb;j++,m+=3)
|
for (m=j=0;j<Nb;j++,m+=3)
|
||||||
{
|
{
|
||||||
y[j]=rkey[k++]^(Uint32)rbsub[(Uint8)x[j]]^
|
y[j]=rkey[k++]^(atUint32)rbsub[(atUint8)x[j]]^
|
||||||
ROTL8((Uint32)rbsub[(Uint8)(x[ri[m]]>>8)])^
|
ROTL8((atUint32)rbsub[(atUint8)(x[ri[m]]>>8)])^
|
||||||
ROTL16((Uint32)rbsub[(Uint8)(x[ri[m+1]]>>16)])^
|
ROTL16((atUint32)rbsub[(atUint8)(x[ri[m+1]]>>16)])^
|
||||||
ROTL24((Uint32)rbsub[(Uint8)(x[ri[m+2]]>>24)]);
|
ROTL24((atUint32)rbsub[(atUint8)(x[ri[m+2]]>>24)]);
|
||||||
}
|
}
|
||||||
for (i=j=0;i<Nb;i++,j+=4)
|
for (i=j=0;i<Nb;i++,j+=4)
|
||||||
{
|
{
|
||||||
unpack(y[i],(Uint8 *)&buff[j]);
|
unpack(y[i],(atUint8 *)&buff[j]);
|
||||||
x[i]=y[i]=0; /* clean up stack */
|
x[i]=y[i]=0; /* clean up stack */
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aes_set_key(const Uint8 *key) {
|
void aes_set_key(const atUint8 *key) {
|
||||||
gentables();
|
gentables();
|
||||||
gkey(4, 4, key);
|
gkey(4, 4, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CBC mode decryption
|
// CBC mode decryption
|
||||||
void aes_decrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len) {
|
void aes_decrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len) {
|
||||||
Uint8 block[16];
|
atUint8 block[16];
|
||||||
Uint8* ctext_ptr;
|
atUint8* ctext_ptr;
|
||||||
unsigned int blockno = 0, i;
|
unsigned int blockno = 0, i;
|
||||||
|
|
||||||
//fprintf( stderr,"aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len );
|
//fprintf( stderr,"aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len );
|
||||||
|
@ -355,7 +355,7 @@ void aes_decrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len) {
|
||||||
memcpy(block, inbuf + blockno * sizeof(block), fraction);
|
memcpy(block, inbuf + blockno * sizeof(block), fraction);
|
||||||
decrypt(block);
|
decrypt(block);
|
||||||
if (blockno == 0) ctext_ptr = iv;
|
if (blockno == 0) ctext_ptr = iv;
|
||||||
else ctext_ptr = (Uint8*)(inbuf + (blockno-1) * sizeof(block));
|
else ctext_ptr = (atUint8*)(inbuf + (blockno-1) * sizeof(block));
|
||||||
|
|
||||||
for(i=0; i < fraction; i++)
|
for(i=0; i < fraction; i++)
|
||||||
outbuf[blockno * sizeof(block) + i] =
|
outbuf[blockno * sizeof(block) + i] =
|
||||||
|
@ -366,8 +366,8 @@ void aes_decrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CBC mode encryption
|
// CBC mode encryption
|
||||||
void aes_encrypt(Uint8 *iv, const Uint8 *inbuf, Uint8 *outbuf, Uint64 len) {
|
void aes_encrypt(atUint8 *iv, const atUint8 *inbuf, atUint8 *outbuf, atUint64 len) {
|
||||||
Uint8 block[16];
|
atUint8 block[16];
|
||||||
unsigned int blockno = 0, i;
|
unsigned int blockno = 0, i;
|
||||||
|
|
||||||
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
|
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
|
||||||
|
|
42
src/bn.cpp
42
src/bn.cpp
|
@ -7,19 +7,19 @@
|
||||||
|
|
||||||
#include "bn.h"
|
#include "bn.h"
|
||||||
|
|
||||||
static void bn_zero(Uint8 *d, Uint32 n)
|
static void bn_zero(atUint8 *d, atUint32 n)
|
||||||
{
|
{
|
||||||
memset(d, 0, n);
|
memset(d, 0, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bn_copy(Uint8 *d, Uint8 *a, Uint32 n)
|
static void bn_copy(atUint8 *d, atUint8 *a, atUint32 n)
|
||||||
{
|
{
|
||||||
memcpy(d, a, n);
|
memcpy(d, a, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bn_compare(Uint8 *a, Uint8 *b, Uint32 n)
|
int bn_compare(atUint8 *a, atUint8 *b, atUint32 n)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (a[i] < b[i])
|
if (a[i] < b[i])
|
||||||
|
@ -31,11 +31,11 @@ int bn_compare(Uint8 *a, Uint8 *b, Uint32 n)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bn_sub_modulus(Uint8 *a, Uint8 *N, Uint32 n)
|
void bn_sub_modulus(atUint8 *a, atUint8 *N, atUint32 n)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint32 dig;
|
atUint32 dig;
|
||||||
Uint8 c;
|
atUint8 c;
|
||||||
|
|
||||||
c = 0;
|
c = 0;
|
||||||
for (i = n - 1; i < n; i--) {
|
for (i = n - 1; i < n; i--) {
|
||||||
|
@ -45,11 +45,11 @@ void bn_sub_modulus(Uint8 *a, Uint8 *N, Uint32 n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bn_add(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n)
|
void bn_add(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint32 dig;
|
atUint32 dig;
|
||||||
Uint8 c;
|
atUint8 c;
|
||||||
|
|
||||||
c = 0;
|
c = 0;
|
||||||
for (i = n - 1; i < n; i--) {
|
for (i = n - 1; i < n; i--) {
|
||||||
|
@ -65,10 +65,10 @@ void bn_add(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n)
|
||||||
bn_sub_modulus(d, N, n);
|
bn_sub_modulus(d, N, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bn_mul(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n)
|
void bn_mul(atUint8 *d, atUint8 *a, atUint8 *b, atUint8 *N, atUint32 n)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint8 mask;
|
atUint8 mask;
|
||||||
|
|
||||||
bn_zero(d, n);
|
bn_zero(d, n);
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ void bn_mul(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bn_exp(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n, Uint8 *e, Uint32 en)
|
void bn_exp(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n, atUint8 *e, atUint32 en)
|
||||||
{
|
{
|
||||||
Uint8 t[512];
|
atUint8 t[512];
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint8 mask;
|
atUint8 mask;
|
||||||
|
|
||||||
bn_zero(d, n);
|
bn_zero(d, n);
|
||||||
d[n-1] = 1;
|
d[n-1] = 1;
|
||||||
|
@ -99,9 +99,9 @@ void bn_exp(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n, Uint8 *e, Uint32 en)
|
||||||
}
|
}
|
||||||
|
|
||||||
// only for prime N -- stupid but lazy, see if I care
|
// only for prime N -- stupid but lazy, see if I care
|
||||||
void bn_inv(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n)
|
void bn_inv(atUint8 *d, atUint8 *a, atUint8 *N, atUint32 n)
|
||||||
{
|
{
|
||||||
Uint8 t[512], s[512];
|
atUint8 t[512], s[512];
|
||||||
|
|
||||||
bn_copy(t, N, n);
|
bn_copy(t, N, n);
|
||||||
bn_zero(s, n);
|
bn_zero(s, n);
|
||||||
|
|
120
src/ec.cpp
120
src/ec.cpp
|
@ -19,11 +19,11 @@
|
||||||
0x3b, 0x33, 0x3b, 0x20, 0xe9, 0xce, 0x42, 0x81, 0xfe, 0x11, 0x5f, 0x7d, 0x8f, 0x90, 0xad };
|
0x3b, 0x33, 0x3b, 0x20, 0xe9, 0xce, 0x42, 0x81, 0xfe, 0x11, 0x5f, 0x7d, 0x8f, 0x90, 0xad };
|
||||||
*/
|
*/
|
||||||
// order of the addition group of points
|
// order of the addition group of points
|
||||||
static Uint8 ec_N[30] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
static atUint8 ec_N[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 };
|
0x13, 0xe9, 0x74, 0xe7, 0x2f, 0x8a, 0x69, 0x22, 0x03, 0x1d, 0x26, 0x03, 0xcf, 0xe0, 0xd7 };
|
||||||
|
|
||||||
// base point
|
// base point
|
||||||
static Uint8 ec_G[60] = { 0x00, 0xfa, 0xc9, 0xdf, 0xcb, 0xac, 0x83, 0x13, 0xbb, 0x21, 0x39, 0xf1, 0xbb, 0x75, 0x5f,
|
static atUint8 ec_G[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,
|
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,
|
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 };
|
0x8a, 0x0b, 0xef, 0xf8, 0x67, 0xa7, 0xca, 0x36, 0x71, 0x6f, 0x7e, 0x01, 0xf8, 0x10, 0x52 };
|
||||||
|
@ -40,19 +40,19 @@ static void elt_print(char *name, u8 *a)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
static void elt_copy(Uint8 *d, Uint8 *a)
|
static void elt_copy(atUint8 *d, atUint8 *a)
|
||||||
{
|
{
|
||||||
memcpy(d, a, 30);
|
memcpy(d, a, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_zero(Uint8 *d)
|
static void elt_zero(atUint8 *d)
|
||||||
{
|
{
|
||||||
memset(d, 0, 30);
|
memset(d, 0, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int elt_is_zero(Uint8 *d)
|
static int elt_is_zero(atUint8 *d)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
for (i = 0; i < 30; i++)
|
for (i = 0; i < 30; i++)
|
||||||
if (d[i] != 0)
|
if (d[i] != 0)
|
||||||
|
@ -61,18 +61,18 @@ static int elt_is_zero(Uint8 *d)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_add(Uint8 *d, Uint8 *a, Uint8 *b)
|
static void elt_add(atUint8 *d, atUint8 *a, atUint8 *b)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
for (i = 0; i < 30; i++)
|
for (i = 0; i < 30; i++)
|
||||||
d[i] = a[i] ^ b[i];
|
d[i] = a[i] ^ b[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_mul_x(Uint8 *d, Uint8 *a)
|
static void elt_mul_x(atUint8 *d, atUint8 *a)
|
||||||
{
|
{
|
||||||
Uint8 carry, x, y;
|
atUint8 carry, x, y;
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
carry = a[0] & 1;
|
carry = a[0] & 1;
|
||||||
|
|
||||||
|
@ -87,10 +87,10 @@ static void elt_mul_x(Uint8 *d, Uint8 *a)
|
||||||
d[20] ^= carry << 2;
|
d[20] ^= carry << 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_mul(Uint8 *d, Uint8 *a, Uint8 *b)
|
static void elt_mul(atUint8 *d, atUint8 *a, atUint8 *b)
|
||||||
{
|
{
|
||||||
Uint32 i, n;
|
atUint32 i, n;
|
||||||
Uint8 mask;
|
atUint8 mask;
|
||||||
|
|
||||||
elt_zero(d);
|
elt_zero(d);
|
||||||
|
|
||||||
|
@ -110,11 +110,11 @@ static void elt_mul(Uint8 *d, Uint8 *a, Uint8 *b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Uint8 square[16] = { 0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15, 0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55 };
|
static const atUint8 square[16] = { 0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15, 0x40, 0x41, 0x44, 0x45, 0x50, 0x51, 0x54, 0x55 };
|
||||||
|
|
||||||
static void elt_square_to_wide(Uint8 *d, Uint8 *a)
|
static void elt_square_to_wide(atUint8 *d, atUint8 *a)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
|
|
||||||
for (i = 0; i < 30; i++) {
|
for (i = 0; i < 30; i++) {
|
||||||
d[2*i] = square[a[i] >> 4];
|
d[2*i] = square[a[i] >> 4];
|
||||||
|
@ -122,10 +122,10 @@ static void elt_square_to_wide(Uint8 *d, Uint8 *a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wide_reduce(Uint8 *d)
|
static void wide_reduce(atUint8 *d)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint8 x;
|
atUint8 x;
|
||||||
|
|
||||||
for (i = 0; i < 30; i++) {
|
for (i = 0; i < 30; i++) {
|
||||||
x = d[i];
|
x = d[i];
|
||||||
|
@ -147,9 +147,9 @@ static void wide_reduce(Uint8 *d)
|
||||||
d[30] &= 1;
|
d[30] &= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_square(Uint8 *d, Uint8 *a)
|
static void elt_square(atUint8 *d, atUint8 *a)
|
||||||
{
|
{
|
||||||
Uint8 wide[60];
|
atUint8 wide[60];
|
||||||
|
|
||||||
elt_square_to_wide(wide, a);
|
elt_square_to_wide(wide, a);
|
||||||
wide_reduce(wide);
|
wide_reduce(wide);
|
||||||
|
@ -157,9 +157,9 @@ static void elt_square(Uint8 *d, Uint8 *a)
|
||||||
elt_copy(d, wide + 30);
|
elt_copy(d, wide + 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void itoh_tsujii(Uint8 *d, Uint8 *a, Uint8 *b, Uint32 j)
|
static void itoh_tsujii(atUint8 *d, atUint8 *a, atUint8 *b, atUint32 j)
|
||||||
{
|
{
|
||||||
Uint8 t[30];
|
atUint8 t[30];
|
||||||
|
|
||||||
elt_copy(t, a);
|
elt_copy(t, a);
|
||||||
while (j--) {
|
while (j--) {
|
||||||
|
@ -170,10 +170,10 @@ static void itoh_tsujii(Uint8 *d, Uint8 *a, Uint8 *b, Uint32 j)
|
||||||
elt_mul(d, t, b);
|
elt_mul(d, t, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void elt_inv(Uint8 *d, Uint8 *a)
|
static void elt_inv(atUint8 *d, atUint8 *a)
|
||||||
{
|
{
|
||||||
Uint8 t[30];
|
atUint8 t[30];
|
||||||
Uint8 s[30];
|
atUint8 s[30];
|
||||||
|
|
||||||
itoh_tsujii(t, a, a, 1);
|
itoh_tsujii(t, a, a, 1);
|
||||||
itoh_tsujii(s, t, a, 1);
|
itoh_tsujii(s, t, a, 1);
|
||||||
|
@ -212,15 +212,15 @@ static int point_is_on_curve(u8 *p)
|
||||||
return elt_is_zero(s);
|
return elt_is_zero(s);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
static int point_is_zero(Uint8 *p)
|
static int point_is_zero(atUint8 *p)
|
||||||
{
|
{
|
||||||
return elt_is_zero(p) && elt_is_zero(p + 30);
|
return elt_is_zero(p) && elt_is_zero(p + 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void point_double(Uint8 *r, Uint8 *p)
|
static void point_double(atUint8 *r, atUint8 *p)
|
||||||
{
|
{
|
||||||
Uint8 s[30], t[30];
|
atUint8 s[30], t[30];
|
||||||
Uint8 *px, *py, *rx, *ry;
|
atUint8 *px, *py, *rx, *ry;
|
||||||
|
|
||||||
px = p;
|
px = p;
|
||||||
py = p + 30;
|
py = p + 30;
|
||||||
|
@ -249,10 +249,10 @@ static void point_double(Uint8 *r, Uint8 *p)
|
||||||
elt_add(ry, ry, t);
|
elt_add(ry, ry, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void point_add(Uint8 *r, Uint8 *p, Uint8 *q)
|
static void point_add(atUint8 *r, atUint8 *p, atUint8 *q)
|
||||||
{
|
{
|
||||||
Uint8 s[30], t[30], u[30];
|
atUint8 s[30], t[30], u[30];
|
||||||
Uint8 *px, *py, *qx, *qy, *rx, *ry;
|
atUint8 *px, *py, *qx, *qy, *rx, *ry;
|
||||||
|
|
||||||
px = p;
|
px = p;
|
||||||
py = p + 30;
|
py = p + 30;
|
||||||
|
@ -302,10 +302,10 @@ static void point_add(Uint8 *r, Uint8 *p, Uint8 *q)
|
||||||
elt_add(ry, s, rx);
|
elt_add(ry, s, rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void point_mul(Uint8 *d, Uint8 *a, Uint8 *b) // a is bignum
|
static void point_mul(atUint8 *d, atUint8 *a, atUint8 *b) // a is bignum
|
||||||
{
|
{
|
||||||
Uint32 i;
|
atUint32 i;
|
||||||
Uint8 mask;
|
atUint8 mask;
|
||||||
|
|
||||||
elt_zero(d);
|
elt_zero(d);
|
||||||
elt_zero(d + 30);
|
elt_zero(d + 30);
|
||||||
|
@ -318,13 +318,13 @@ static void point_mul(Uint8 *d, Uint8 *a, Uint8 *b) // a is bignum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_ecdsa(Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash)
|
void generate_ecdsa(atUint8 *R, atUint8 *S, atUint8 *k, atUint8 *hash)
|
||||||
{
|
{
|
||||||
Uint8 e[30];
|
atUint8 e[30];
|
||||||
Uint8 kk[30];
|
atUint8 kk[30];
|
||||||
Uint8 m[30];
|
atUint8 m[30];
|
||||||
Uint8 minv[30];
|
atUint8 minv[30];
|
||||||
Uint8 mG[60];
|
atUint8 mG[60];
|
||||||
//FILE *fp;
|
//FILE *fp;
|
||||||
|
|
||||||
elt_zero(e);
|
elt_zero(e);
|
||||||
|
@ -351,12 +351,12 @@ void generate_ecdsa(Uint8 *R, Uint8 *S, Uint8 *k, Uint8 *hash)
|
||||||
bn_mul(S, minv, kk, ec_N, 30);
|
bn_mul(S, minv, kk, ec_N, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_ecdsa(Uint8 *Q, Uint8 *R, Uint8 *S, Uint8 *hash)
|
bool check_ecdsa(atUint8 *Q, atUint8 *R, atUint8 *S, atUint8 *hash)
|
||||||
{
|
{
|
||||||
Uint8 Sinv[30];
|
atUint8 Sinv[30];
|
||||||
Uint8 e[30];
|
atUint8 e[30];
|
||||||
Uint8 w1[30], w2[30];
|
atUint8 w1[30], w2[30];
|
||||||
Uint8 r1[60], r2[60];
|
atUint8 r1[60], r2[60];
|
||||||
|
|
||||||
bn_inv(Sinv, S, ec_N, 30);
|
bn_inv(Sinv, S, ec_N, 30);
|
||||||
|
|
||||||
|
@ -377,16 +377,16 @@ bool check_ecdsa(Uint8 *Q, Uint8 *R, Uint8 *S, Uint8 *hash)
|
||||||
return (bn_compare(r1, R, 30) == 0);
|
return (bn_compare(r1, R, 30) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ec_priv_to_pub(Uint8 *k, Uint8 *Q)
|
void ec_priv_to_pub(atUint8 *k, atUint8 *Q)
|
||||||
{
|
{
|
||||||
point_mul(Q, k, ec_G);
|
point_mul(Q, k, ec_G);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_ec(Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash)
|
bool check_ec(atUint8 *ng, atUint8 *ap, atUint8 *sig, atUint8 *sig_hash)
|
||||||
{
|
{
|
||||||
Uint8* ap_hash;
|
atUint8* ap_hash;
|
||||||
Uint8 *ng_Q, *ap_R, *ap_S;
|
atUint8 *ng_Q, *ap_R, *ap_S;
|
||||||
Uint8 *ap_Q, *sig_R, *sig_S;
|
atUint8 *ap_Q, *sig_R, *sig_S;
|
||||||
|
|
||||||
ng_Q = ng + 0x0108;
|
ng_Q = ng + 0x0108;
|
||||||
ap_R = ap + 0x04;
|
ap_R = ap + 0x04;
|
||||||
|
@ -402,21 +402,21 @@ bool check_ec(Uint8 *ng, Uint8 *ap, Uint8 *sig, Uint8 *sig_hash)
|
||||||
&& check_ecdsa(ap_Q, sig_R, sig_S, sig_hash);
|
&& check_ecdsa(ap_Q, sig_R, sig_S, sig_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_ec_cert(Uint8 *cert, Uint8 *sig, char *signer, char *name, Uint8 *priv, Uint32 key_id )
|
void make_ec_cert(atUint8 *cert, atUint8 *sig, char *signer, char *name, atUint8 *priv, atUint32 key_id )
|
||||||
{
|
{
|
||||||
memset(cert, 0, 0x180);
|
memset(cert, 0, 0x180);
|
||||||
*(Uint32*)(cert) = 0x10002;
|
*(atUint32*)(cert) = 0x10002;
|
||||||
if (!Athena::utility::isSystemBigEndian())
|
if (!Athena::utility::isSystemBigEndian())
|
||||||
*(Uint32*)(cert) = Athena::utility::swapU32(*(Uint32*)(cert));
|
*(atUint32*)(cert) = Athena::utility::swapU32(*(atUint32*)(cert));
|
||||||
memcpy((char*)cert + 4, sig, 60);
|
memcpy((char*)cert + 4, sig, 60);
|
||||||
strcpy((char*)cert + 0x80, signer);
|
strcpy((char*)cert + 0x80, signer);
|
||||||
*(Uint32*)(cert + 0xc0) = 2;
|
*(atUint32*)(cert + 0xc0) = 2;
|
||||||
if (!Athena::utility::isSystemBigEndian())
|
if (!Athena::utility::isSystemBigEndian())
|
||||||
*(Uint32*)(cert + 0xc0) = Athena::utility::swapU32(*(Uint32*)(cert + 0xc0));
|
*(atUint32*)(cert + 0xc0) = Athena::utility::swapU32(*(atUint32*)(cert + 0xc0));
|
||||||
strcpy((char*)cert + 0xc4, name);
|
strcpy((char*)cert + 0xc4, name);
|
||||||
*(Uint32*)(cert + 0x104) = key_id;
|
*(atUint32*)(cert + 0x104) = key_id;
|
||||||
if (!Athena::utility::isSystemBigEndian())
|
if (!Athena::utility::isSystemBigEndian())
|
||||||
*(Uint32*)(cert + 0x104) = Athena::utility::swapU32(*(Uint32*)(cert + 0x104));
|
*(atUint32*)(cert + 0x104) = Athena::utility::swapU32(*(atUint32*)(cert + 0x104));
|
||||||
|
|
||||||
ec_priv_to_pub(priv, cert + 0x108);
|
ec_priv_to_pub(priv, cert + 0x108);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
//! define if we may read up to 4 bytes beyond the input buffer
|
//! define if we may read up to 4 bytes beyond the input buffer
|
||||||
//#define INBUF_PADDED 1
|
//#define INBUF_PADDED 1
|
||||||
typedef struct LZOContext {
|
typedef struct LZOContext {
|
||||||
Uint8 *in, *in_end;
|
atUint8 *in, *in_end;
|
||||||
Uint8 *out_start, *out, *out_end;
|
atUint8 *out_start, *out, *out_end;
|
||||||
int error;
|
int error;
|
||||||
} LZOContext;
|
} LZOContext;
|
||||||
|
|
||||||
|
@ -166,9 +166,9 @@ static void copy_backptr(LZOContext *c, int back, int cnt) {
|
||||||
* make sure all buffers are appropriately padded, in must provide
|
* make sure all buffers are appropriately padded, in must provide
|
||||||
* LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
|
* LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
|
||||||
*/
|
*/
|
||||||
int lzo1x_decode(Uint8 *out, Int32 *outlen, Uint8 *in, Int32 *inlen) {
|
int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen) {
|
||||||
enum {COPY, BACKPTR} state = COPY;
|
enum {COPY, BACKPTR} state = COPY;
|
||||||
Int32 x;
|
atInt32 x;
|
||||||
LZOContext c;
|
LZOContext c;
|
||||||
c.in = in;
|
c.in = in;
|
||||||
c.in_end = in + *inlen;
|
c.in_end = in + *inlen;
|
||||||
|
|
|
@ -372,15 +372,15 @@ void SHA1PadMessage(SHA1Context *context)
|
||||||
SHA1ProcessMessageBlock(context);
|
SHA1ProcessMessageBlock(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8* getSha1( Uint8 * stuff, Uint32 stuff_size )
|
atUint8* getSha1( atUint8 * stuff, atUint32 stuff_size )
|
||||||
{
|
{
|
||||||
SHA1Context sha;
|
SHA1Context sha;
|
||||||
SHA1Reset( &sha );
|
SHA1Reset( &sha );
|
||||||
SHA1Input( &sha, (const Uint8*)stuff, stuff_size );
|
SHA1Input( &sha, (const atUint8*)stuff, stuff_size );
|
||||||
if( !SHA1Result( &sha ) )
|
if( !SHA1Result( &sha ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Uint8* ret = new Uint8[20];
|
atUint8* ret = new atUint8[20];
|
||||||
memset(ret, 0, 20);
|
memset(ret, 0, 20);
|
||||||
|
|
||||||
for( int i = 0; i < 5 ; i++ )
|
for( int i = 0; i < 5 ; i++ )
|
||||||
|
|
Loading…
Reference in New Issue