New code style refactor

This commit is contained in:
Jack Andersen
2018-12-07 19:18:17 -10:00
parent e1b29fda7a
commit 7243c687a8
123 changed files with 15125 additions and 18399 deletions

View File

@@ -5,54 +5,51 @@
#include <wiiuse/wpad.h>
#endif
static void *xfb = nullptr;
static void* xfb = nullptr;
static GXRModeObj* rmode = nullptr;
#endif
#include <athena/MemoryReader.hpp>
int main()
{
int main() {
#if GEKKO
VIDEO_Init();
VIDEO_Init();
#if HW_RVL
WPAD_Init();
WPAD_Init();
#endif
PAD_Init();
PAD_Init();
rmode = VIDEO_GetPreferredMode(nullptr);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
rmode = VIDEO_GetPreferredMode(nullptr);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
CON_EnableGecko(CARD_SLOTB, true);
CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
CON_EnableGecko(CARD_SLOTB, true);
VIDEO_Configure(rmode);
VIDEO_SetBlack(false);
VIDEO_Configure(rmode);
VIDEO_SetBlack(false);
VIDEO_Flush();
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
athena::io::MemoryCopyReader test("sd:/test.dat");
while(true)
{
athena::io::MemoryCopyReader test("sd:/test.dat");
while (true) {
#if HW_RVL
WPAD_ScanPads();
WPAD_ScanPads();
#endif
PAD_ScanPads();
if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
break;
PAD_ScanPads();
if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
break;
#if HW_RVL
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
break;
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
break;
#endif
VIDEO_WaitVSync();
}
VIDEO_WaitVSync();
}
#endif
return 0;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,22 +3,21 @@
#define EXPECTED_BYTES 281
int main(int argc, const char** argv)
{
TESTFile<atUint32, 2> file = {};
file.arrCount[0] = 2;
file.array.push_back(42);
file.array.push_back(64);
size_t binSize = 0;
file.binarySize(binSize);
athena::io::MemoryCopyWriter w(nullptr, binSize);
atInt64 pos = w.position();
file.write(w);
bool pass = !w.hasError() && w.position() - pos == binSize && binSize == EXPECTED_BYTES;
if (pass)
printf("[PASS] %" PRISize " bytes written\n", size_t(w.position() - pos));
else
printf("[FAIL] %" PRISize " bytes written; %" PRISize " bytes sized; %d bytes expected\n",
size_t(w.position() - pos), binSize, EXPECTED_BYTES);
return pass ? 0 : 1;
int main(int argc, const char** argv) {
TESTFile<atUint32, 2> file = {};
file.arrCount[0] = 2;
file.array.push_back(42);
file.array.push_back(64);
size_t binSize = 0;
file.binarySize(binSize);
athena::io::MemoryCopyWriter w(nullptr, binSize);
atInt64 pos = w.position();
file.write(w);
bool pass = !w.hasError() && w.position() - pos == binSize && binSize == EXPECTED_BYTES;
if (pass)
printf("[PASS] %" PRISize " bytes written\n", size_t(w.position() - pos));
else
printf("[FAIL] %" PRISize " bytes written; %" PRISize " bytes sized; %d bytes expected\n",
size_t(w.position() - pos), binSize, EXPECTED_BYTES);
return pass ? 0 : 1;
}

View File

@@ -3,87 +3,71 @@
using namespace athena;
typedef io::DNA<Big> BigDNA;
enum ETest : atUint8
{
ZERO,
ONE,
TWO,
THREE
};
enum ETest : atUint8 { ZERO, ONE, TWO, THREE };
template <ETest EVal>
struct AT_SPECIALIZE_PARMS(ETest::ZERO, ETest::ONE, ETest::TWO, ETest::THREE)
TESTSubFile : public BigDNA
{
AT_DECL_DNA
Value<ETest> varE = EVal;
Value<atUint32> sub1;
Value<atUint32> sub2;
struct AT_SPECIALIZE_PARMS(ETest::ZERO, ETest::ONE, ETest::TWO, ETest::THREE) TESTSubFile : public BigDNA {
AT_DECL_DNA
Value<ETest> varE = EVal;
Value<atUint32> sub1;
Value<atUint32> sub2;
};
struct TESTSubClassFile : public TESTSubFile<ETest::ONE>
{
AT_DECL_DNA
Value<atUint32> sub3;
Value<atUint16> sub4;
struct TESTSubClassFile : public TESTSubFile<ETest::ONE> {
AT_DECL_DNA
Value<atUint32> sub3;
Value<atUint16> sub4;
};
struct TESTSubSubClassFile : public TESTSubClassFile
{
AT_DECL_DNA
Value<atUint32> sub5;
Value<atUint32> sub6;
struct TESTSubSubClassFile : public TESTSubClassFile {
AT_DECL_DNA
Value<atUint32> sub5;
Value<atUint32> sub6;
};
template <class Var32Tp, int Var32Val>
struct AT_SPECIALIZE_PARMS(atUint16, 42, atUint32, 87, atUint32, 2)
TESTFile : public BigDNA
{
struct AT_SPECIALIZE_PARMS(atUint16, 42, atUint32, 87, atUint32, 2) TESTFile : public BigDNA {
AT_DECL_DNA
Value<bool> varBool;
AT_OVERRIDE_RCRC32(12345678) Value<Var32Tp> x4_var32 = Var32Val;
AT_OVERRIDE_RCRC32(deadbabe) Value<atUint16> x8_var16;
Value<atVec3f> vec3;
Value<atVec4f> vec4;
struct TESTNestedSubFile : public BigDNA {
AT_DECL_DNA
Value<bool> varBool;
AT_OVERRIDE_RCRC32(12345678) Value<Var32Tp> x4_var32 = Var32Val;
AT_OVERRIDE_RCRC32(deadbabe) Value<atUint16> x8_var16;
Value<atVec3f> vec3;
Value<atVec4f> vec4;
Value<atUint32> nestSub1;
Value<atUint32> nestSub2;
} nestedSubFile;
struct TESTNestedSubFile : public BigDNA
{
AT_DECL_DNA
Value<atUint32> nestSub1;
Value<atUint32> nestSub2;
} nestedSubFile;
using TESTSubFileUsing = TESTSubFile<ETest::TWO>;
TESTSubFileUsing subFile;
using TESTSubFileUsing = TESTSubFile<ETest::TWO>;
TESTSubFileUsing subFile;
Align<4> align;
Align<4> align;
template <class NestedTp, int NestedVal>
struct AT_SPECIALIZE_PARMS(atInt32, 36, atInt64, 96) TESTTemplateSubFile : public BigDNA {
AT_DECL_DNA
Value<NestedTp> explSub1 = NestedVal;
Value<Var32Tp> explSub2 = Var32Val;
};
Value<TESTTemplateSubFile<atInt32, 36>> nestedTemplate1;
Value<TESTTemplateSubFile<atInt64, 96>> nestedTemplate2;
template <class NestedTp, int NestedVal>
struct AT_SPECIALIZE_PARMS(atInt32, 36, atInt64, 96)
TESTTemplateSubFile : public BigDNA
{
AT_DECL_DNA
Value<NestedTp> explSub1 = NestedVal;
Value<Var32Tp> explSub2 = Var32Val;
};
Value<TESTTemplateSubFile<atInt32, 36>> nestedTemplate1;
Value<TESTTemplateSubFile<atInt64, 96>> nestedTemplate2;
Value<atUint32, Little> arrCount[2];
Vector<atUint32, AT_DNA_COUNT(arrCount[0])> array;
Value<atUint32, Little> arrCount[2];
Vector<atUint32, AT_DNA_COUNT(arrCount[0])> array;
Value<atUint32> arrAltCount;
Vector<atUint32, AT_DNA_COUNT(arrAltCount)> arrayAlt;
Value<atUint32> arrAltCount;
Vector<atUint32, AT_DNA_COUNT(arrAltCount)> arrayAlt;
Seek<21, Current> seek;
Seek<21, Current> seek;
Value<atUint32> arrCount2;
Vector<TESTSubFile<ETest::ZERO>, AT_DNA_COUNT(arrCount[1] + arrCount2)> array2;
Value<atUint32> arrCount2;
Vector<TESTSubFile<ETest::ZERO>, AT_DNA_COUNT(arrCount[1] + arrCount2)> array2;
Value<atUint32> bufSz;
Buffer<AT_DNA_COUNT(bufSz)> buf;
Value<atUint32> bufSz;
Buffer<AT_DNA_COUNT(bufSz)> buf;
String<32> str;
WString<64> wstr;
String<32> str;
WString<64> wstr;
};

View File

@@ -3,40 +3,38 @@
#include <string>
#include "LZ77/LZLookupTable.hpp"
class LZBase
{
class LZBase {
public:
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3, atInt32 blockSize = 8);
virtual ~LZBase() {}
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3,
atInt32 blockSize = 8);
virtual ~LZBase() {}
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
private:
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr,
atUint8* startLBPtr);
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr, atUint8* startLBPtr);
protected:
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;
atInt32 m_minMatch;//Minimum number of bytes that have to matched to go through with compression
atInt32 m_blockSize;
atUint32 m_minOffset;
LZLookupTable m_lookupTable;
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;
atInt32 m_minMatch; // Minimum number of bytes that have to matched to go through with compression
atInt32 m_blockSize;
atUint32 m_minOffset;
LZLookupTable m_lookupTable;
};

View File

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

View File

@@ -2,11 +2,10 @@
#include "LZBase.hpp"
class LZType10 : public LZBase
{
class LZType10 : public LZBase {
public:
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3, atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen);
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen);
};

View File

@@ -1,14 +1,11 @@
#pragma once
#include "LZBase.hpp"
class LZType11 : public LZBase
{
class LZType11 : public LZBase {
public:
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3, atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength);
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength);
};

View File

@@ -4,19 +4,16 @@
#include <cstdlib>
#include <memory>
namespace athena
{
namespace athena {
class IAES
{
class IAES {
public:
virtual ~IAES() {}
virtual void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
virtual void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
virtual void setKey(const uint8_t* key)=0;
virtual ~IAES() {}
virtual void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len) = 0;
virtual void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len) = 0;
virtual void setKey(const uint8_t* key) = 0;
};
std::unique_ptr<IAES> NewAES();
}
} // namespace athena

View File

@@ -2,92 +2,56 @@
#include "Types.hpp"
namespace athena
{
namespace athena {
enum BowType : char
{
BowNone,
BowArrows,
BowSilverArrows
enum BowType : char { BowNone, BowArrows, BowSilverArrows };
enum BoomerangType : char { BoomerangNone, BoomerangBlue, BoomerangRed };
enum MagicType : char { MagicNone, MagicMushroom, MagicPowder };
enum ArmorType : char { GreenJerkin, BlueMail, RedMail };
enum BottleType : char {
BottleNone,
BottleMushroom, // No Use
BottleEmpty,
BottleRedPotion,
BottleBluePotion,
BottleFairy,
BottleBee,
BottleGoodBee
};
enum BoomerangType : char
{
BoomerangNone,
BoomerangBlue,
BoomerangRed
enum ALTTPStartLocation { LinksHouse = 0x00, Sanctuary = 0x01, Any = 0x05 };
enum ALTTPProgressIndicator { LinkInBed, InCastleWithSword, CompletedFirstDungeon, BeatenAghanim };
enum ALTTPMapIcon {
Nothing = 0x00, //?
CrossInKakariko = 0x01, //?
CrossAtFirstDungeon = 0x02, //
Pendant = 0x03,
MasterSword = 0x04,
AganhimCastle = 0x05,
Crystal1 = 0x06,
AllCrystals = 0x07,
AganhimGanonTower = 0x08
};
enum MagicType : char
{
MagicNone,
MagicMushroom,
MagicPowder
enum ALTTPTagAlong {
Noone,
Zelda,
Unknown1,
Oldman,
ZeldaMessage,
Blind,
DwarfFrog,
DwarfLW,
Kiki,
Unknown2,
TheifsChest,
AfterBoss
};
enum ArmorType : char
{
GreenJerkin,
BlueMail,
RedMail
};
enum BottleType : char
{
BottleNone,
BottleMushroom, // No Use
BottleEmpty,
BottleRedPotion,
BottleBluePotion,
BottleFairy,
BottleBee,
BottleGoodBee
};
enum ALTTPStartLocation
{
LinksHouse = 0x00,
Sanctuary = 0x01,
Any = 0x05
};
enum ALTTPProgressIndicator
{
LinkInBed,
InCastleWithSword,
CompletedFirstDungeon,
BeatenAghanim
};
enum ALTTPMapIcon
{
Nothing = 0x00, //?
CrossInKakariko = 0x01, //?
CrossAtFirstDungeon = 0x02, //
Pendant = 0x03,
MasterSword = 0x04,
AganhimCastle = 0x05,
Crystal1 = 0x06,
AllCrystals = 0x07,
AganhimGanonTower = 0x08
};
enum ALTTPTagAlong
{
Noone,
Zelda,
Unknown1,
Oldman,
ZeldaMessage,
Blind,
DwarfFrog,
DwarfLW,
Kiki,
Unknown2,
TheifsChest,
AfterBoss
};
} // zelda
} // namespace athena

View File

@@ -3,8 +3,7 @@
#include "athena/Global.hpp"
#include <vector>
namespace athena
{
namespace athena {
class ALTTPQuest;
@@ -14,61 +13,58 @@ class ALTTPQuest;
* Contains all relevant data for an A Link to the Past
* SRM file.
*/
class ALTTPFile
{
class ALTTPFile {
public:
/*! \brief Quest Iterator
*
* An Iterator typedef for iterating through the Quest lists
*/
typedef std::vector<ALTTPQuest*>::iterator QuestIter;
/*! \brief Quest Iterator
*
* An Iterator typedef for iterating through the Quest lists
*/
typedef std::vector<ALTTPQuest*>::iterator QuestIter;
/*! \brief Default constructor
*
*
*/
ALTTPFile();
/*! \brief Default constructor
*
*
*/
ALTTPFile();
/*! \brief Constructor
*
* \param questList The primary quest list
* \param backupList The backup quest list
*/
ALTTPFile(std::vector<ALTTPQuest*> questList, std::vector<ALTTPQuest*> backupList);
/*! \brief Constructor
*
* \param questList The primary quest list
* \param backupList The backup quest list
*/
ALTTPFile(std::vector<ALTTPQuest*> questList, std::vector<ALTTPQuest*> backupList);
/*! \brief Sets a quest at the given index
*
* \param id Index to the given quest
* \param val The new quest to assign to the given index
* \throw InvalidOperationException on index out of range
*/
void setQuest(atUint32 id, ALTTPQuest* val);
/*! \brief Returns the primary quest list
*
* \return The primary quest list
*/
std::vector<ALTTPQuest*> questList() const;
/*! \brief Sets a quest at the given index
*
* \param id Index to the given quest
* \param val The new quest to assign to the given index
* \throw InvalidOperationException on index out of range
*/
void setQuest(atUint32 id, ALTTPQuest* val);
/*! \brief Returns the primary quest list
*
* \return The primary quest list
*/
std::vector<ALTTPQuest*> questList() const;
/*! \brief Returns a quest at the given index
*
* Returns a quest at the given index
*
* \return ALTTPQuest*
* \throw InvalidOperationException on index out of range
*/
ALTTPQuest* quest(atUint32 id) const;
/*! \brief Returns a quest at the given index
*
* Returns a quest at the given index
*
* \return ALTTPQuest*
* \throw InvalidOperationException on index out of range
*/
ALTTPQuest* quest(atUint32 id) const;
/*! \brief Returns the number of primary quests
*
* \return The number of quests
*/
atUint32 questCount() const;
/*! \brief Returns the number of primary quests
*
* \return The number of quests
*/
atUint32 questCount() const;
private:
std::vector<ALTTPQuest*> m_quests;
std::vector<ALTTPQuest*> m_backup;
std::vector<ALTTPQuest*> m_quests;
std::vector<ALTTPQuest*> m_backup;
};
} // zelda
} // namespace athena

View File

@@ -5,12 +5,10 @@
#include "athena/MemoryReader.hpp"
#include "athena/ALTTPQuest.hpp"
namespace athena
{
namespace athena {
class ALTTPFile;
namespace io
{
namespace io {
/*! \class ALTTPFileReader
* \brief A Link to the Past save data reader class
*
@@ -18,32 +16,32 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class ALTTPFileReader : protected MemoryCopyReader
{
class ALTTPFileReader : protected MemoryCopyReader {
public:
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(atUint8*, atUint64);
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(atUint8*, atUint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileReader(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileReader(const std::string&);
/*! \brief Reads the SRAM data from the buffer
*
* \return ALTTPFile* SRAM data
*/
ALTTPFile* readFile();
/*! \brief Reads the SRAM data from the buffer
*
* \return ALTTPFile* SRAM data
*/
ALTTPFile* readFile();
private:
ALTTPRoomFlags* readRoomFlags();
ALTTPOverworldEvent* readOverworldEvent();
ALTTPDungeonItemFlags readDungeonFlags();
ALTTPRoomFlags* readRoomFlags();
ALTTPOverworldEvent* readOverworldEvent();
ALTTPDungeonItemFlags readDungeonFlags();
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -4,12 +4,10 @@
#include "athena/MemoryWriter.hpp"
#include "athena/ALTTPQuest.hpp"
namespace athena
{
namespace athena {
class ALTTPFile;
namespace io
{
namespace io {
/*! \class ALTTPFileWriter
* \brief A Link to the Past save data writer class
*
@@ -17,35 +15,33 @@ namespace io
* all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader
*/
class ALTTPFileWriter : protected MemoryCopyWriter
{
class ALTTPFileWriter : protected MemoryCopyWriter {
public:
/*! \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(atUint8*, atUint64);
/*! \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(atUint8*, atUint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileWriter(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileWriter(const std::string&);
/*! \brief Writes the given SRAM data to a file on disk
*
* \param file SRAM data to right
*/
void writeFile(ALTTPFile* file);
/*! \brief Writes the given SRAM data to a file on disk
*
* \param file SRAM data to right
*/
void writeFile(ALTTPFile* file);
private:
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
void writeDungeonItems(ALTTPDungeonItemFlags);
atUint16 calculateChecksum(atUint32 game);
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
void writeDungeonItems(ALTTPDungeonItemFlags);
atUint16 calculateChecksum(atUint32 game);
};
} // io
} // zelda
} // namespace io
} // namespace athena

File diff suppressed because it is too large Load Diff

View File

@@ -3,196 +3,176 @@
#include <string>
#include "athena/Types.hpp"
namespace athena
{
namespace athena {
struct ALTTPRoomFlags
{
bool Chest1: 1;
bool Chest2: 1;
bool Chest3: 1;
bool Chest4: 1;
bool Quadrant1: 1;
bool Quadrant2: 1;
bool Quadrant3: 1;
bool Quadrant4: 1;
bool Door1: 1;
bool Door2: 1;
bool Door3: 1;
bool Door4: 1;
bool BossBattleWon: 1;
bool Key: 1;
bool KeyOrChest: 1;
bool ChestOrTile: 1;
struct ALTTPRoomFlags {
bool Chest1 : 1;
bool Chest2 : 1;
bool Chest3 : 1;
bool Chest4 : 1;
bool Quadrant1 : 1;
bool Quadrant2 : 1;
bool Quadrant3 : 1;
bool Quadrant4 : 1;
bool Door1 : 1;
bool Door2 : 1;
bool Door3 : 1;
bool Door4 : 1;
bool BossBattleWon : 1;
bool Key : 1;
bool KeyOrChest : 1;
bool ChestOrTile : 1;
};
struct ALTTPOverworldEvent
{
bool Unused1: 1;
bool HeartPiece: 1;
bool Overlay: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Set: 1;
bool Unused5: 1;
struct ALTTPOverworldEvent {
bool Unused1 : 1;
bool HeartPiece : 1;
bool Overlay : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Set : 1;
bool Unused5 : 1;
};
struct ALTTPInventory
{
char Bow;
char Boomerang;
bool Hookshot;
char Bombs; // Bomb count
char Magic;
bool FireRod;
bool IceRod;
bool Bombos;
bool Ether;
bool Quake;
bool Torch;
bool Hammer;
char Flute;
bool BugNet;
bool Book;
bool Bottles;
bool Somaria;
bool Byrna;
bool MagicCape;
char MagicMirror;
char Gloves;
char Boots;
bool Flippers;
bool MoonPearl;
char Unused; //?
char Sword;
char Shield;
char Armor;
char BottleTypes[4];
struct ALTTPInventory {
char Bow;
char Boomerang;
bool Hookshot;
char Bombs; // Bomb count
char Magic;
bool FireRod;
bool IceRod;
bool Bombos;
bool Ether;
bool Quake;
bool Torch;
bool Hammer;
char Flute;
bool BugNet;
bool Book;
bool Bottles;
bool Somaria;
bool Byrna;
bool MagicCape;
char MagicMirror;
char Gloves;
char Boots;
bool Flippers;
bool MoonPearl;
char Unused; //?
char Sword;
char Shield;
char Armor;
char BottleTypes[4];
};
/*! \struct ALTTPLightDarkWorldIndicator
*/
struct ALTTPLightDarkWorldIndicator
{
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
bool Unused6: 1;
bool IsDarkWorld: 1;
bool Unused7: 1;
struct ALTTPLightDarkWorldIndicator {
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
bool Unused6 : 1;
bool IsDarkWorld : 1;
bool Unused7 : 1;
};
struct ALTTPDungeonItemFlags
{
union
{
struct
{
bool Unused1: 1;
bool Unused2: 1;
bool GanonsTower: 1;
bool TurtleRock: 1;
bool GargoylesDomain: 1;
bool TowerOfHera: 1;
bool IcePalace: 1;
bool SkullWoods: 1;
};
atUint8 flags1;
struct ALTTPDungeonItemFlags {
union {
struct {
bool Unused1 : 1;
bool Unused2 : 1;
bool GanonsTower : 1;
bool TurtleRock : 1;
bool GargoylesDomain : 1;
bool TowerOfHera : 1;
bool IcePalace : 1;
bool SkullWoods : 1;
};
atUint8 flags1;
};
union
{
struct
{
bool MiseryMire: 1;
bool DarkPalace: 1;
bool SwampPalace: 1;
bool HyruleCastle2: 1; // unused in orignal game
bool DesertPalace: 1;
bool EasternPalace: 1;
bool HyruleCastle: 1; // unused exist in original game
bool SewerPassage: 1; // unused exist in original game
};
atUint8 flags2;
union {
struct {
bool MiseryMire : 1;
bool DarkPalace : 1;
bool SwampPalace : 1;
bool HyruleCastle2 : 1; // unused in orignal game
bool DesertPalace : 1;
bool EasternPalace : 1;
bool HyruleCastle : 1; // unused exist in original game
bool SewerPassage : 1; // unused exist in original game
};
atUint8 flags2;
};
};
struct ALTTPPendants
{
bool Courage: 1;
bool Wisdom: 1;
bool Power: 1;
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
struct ALTTPPendants {
bool Courage : 1;
bool Wisdom : 1;
bool Power : 1;
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
};
struct ALTTPAbilities
{
bool Nothing: 1; //?
bool Swim: 1;
bool Dash: 1;
bool Pull: 1;
bool Unknown1: 1; //---
bool Talk: 1;
bool Read: 1;
bool Unknown2: 1; //---
struct ALTTPAbilities {
bool Nothing : 1; //?
bool Swim : 1;
bool Dash : 1;
bool Pull : 1;
bool Unknown1 : 1; //---
bool Talk : 1;
bool Read : 1;
bool Unknown2 : 1; //---
};
struct ALTTPCrystals
{
bool MiseryMire: 1;
bool DarkPalace: 1;
bool IcePalace: 1;
bool TurtleRock: 1;
bool SwampPalace: 1;
bool GargoyleDomain: 1;
bool SkullWoods: 1;
struct ALTTPCrystals {
bool MiseryMire : 1;
bool DarkPalace : 1;
bool IcePalace : 1;
bool TurtleRock : 1;
bool SwampPalace : 1;
bool GargoyleDomain : 1;
bool SkullWoods : 1;
};
struct ALTTPMagicUsage
{
bool Normal: 1;
bool Half: 1;
bool Quarter: 1;
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
struct ALTTPMagicUsage {
bool Normal : 1;
bool Half : 1;
bool Quarter : 1;
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
};
struct ALTTPProgressFlags1
{
bool UncleSecretPassage: 1;
bool DyingPriest: 1; //?
bool ZeldaSanctuary: 1; //?
bool Unused1: 1;
bool UncleLeftHouse: 1;
bool BookOfMudora: 1; //? Math says it's a guess need to investigate
bool DwarfPartner: 1; //?
bool Unused2: 1;
struct ALTTPProgressFlags1 {
bool UncleSecretPassage : 1;
bool DyingPriest : 1; //?
bool ZeldaSanctuary : 1; //?
bool Unused1 : 1;
bool UncleLeftHouse : 1;
bool BookOfMudora : 1; //? Math says it's a guess need to investigate
bool DwarfPartner : 1; //?
bool Unused2 : 1;
};
struct ALTTPProgressFlags2
{
bool BottleFromBum: 1;
bool BottleFromSalesMen: 1;
bool Unused1: 1; //?
bool FluteBoy: 1;
bool ThiefsChest: 1;
bool SavedSmithPartner: 1;
bool Unused2: 1; //?
bool SmithsHaveSword: 1;
struct ALTTPProgressFlags2 {
bool BottleFromBum : 1;
bool BottleFromSalesMen : 1;
bool Unused1 : 1; //?
bool FluteBoy : 1;
bool ThiefsChest : 1;
bool SavedSmithPartner : 1;
bool Unused2 : 1; //?
bool SmithsHaveSword : 1;
};
}
} // namespace athena

View File

@@ -2,10 +2,10 @@
#include "athena/Global.hpp"
namespace athena::checksums
{
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF, atUint64 final = 0xFFFFFFFFFFFFFFFF);
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF,
atUint64 final = 0xFFFFFFFFFFFFFFFF);
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed = 0xFFFFFFFF, atUint32 final = 0xFFFFFFFF);
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0);
atUint16 crc16(const atUint8* data, atUint64 length, atUint16 seed = 0, atUint16 final = 0);
}
} // namespace athena::checksums

View File

@@ -2,196 +2,161 @@
#include <cstdint>
namespace athena::checksums::literals
{
namespace athena::checksums::literals {
constexpr uint32_t crc32_table[] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
constexpr uint32_t crc32_table[] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4,
0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074,
0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525,
0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76,
0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6,
0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7,
0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330,
0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
template <uint32_t CRC, char... Chars>
struct Crc32Impl {};
template <uint32_t CRC, char Head, char... Tail>
struct Crc32Impl<CRC, Head, Tail...> {
static constexpr uint32_t value =
Crc32Impl<crc32_table[static_cast<unsigned char>(CRC) ^ static_cast<unsigned char>(Head)] ^ (CRC >> 8),
Tail...>::value;
};
template<uint32_t CRC, char ...Chars> struct Crc32Impl {
template <uint32_t CRC>
struct Crc32Impl<CRC> {
static constexpr uint32_t value = CRC ^ 0xFFFFFFFF;
};
template<uint32_t CRC, char Head, char ...Tail> struct Crc32Impl<CRC, Head, Tail...> {
static constexpr uint32_t value = Crc32Impl<
crc32_table[static_cast<unsigned char>(CRC) ^ static_cast<unsigned char>(Head)]
^ (CRC >> 8), Tail...>::value;
};
template <char... Chars>
using Crc32 = Crc32Impl<0xFFFFFFFF, Chars...>;
template<uint32_t CRC> struct Crc32Impl<CRC> {
static constexpr uint32_t value = CRC ^ 0xFFFFFFFF;
};
template<char ...Chars> using Crc32 = Crc32Impl<0xFFFFFFFF, Chars...>;
constexpr uint32_t crc32_rec(uint32_t crc, const char *s) {
return *s == 0 ? crc ^ 0xFFFFFFFF :
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
static_cast<unsigned char>(*s)]
^ (crc >> 8), s + 1);
constexpr uint32_t crc32_rec(uint32_t crc, const char* s) {
return *s == 0 ? crc ^ 0xFFFFFFFF
: crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^ static_cast<unsigned char>(*s)] ^ (crc >> 8),
s + 1);
}
constexpr uint32_t operator "" _crc32(const char *s, size_t len) {
return crc32_rec(0xFFFFFFFF, s);
constexpr uint32_t operator"" _crc32(const char* s, size_t len) { return crc32_rec(0xFFFFFFFF, s); }
static_assert("Hello"_crc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value, "CRC32 values don't match");
static_assert("0"_crc32 == Crc32<'0'>::value, "CRC32 values don't match");
constexpr uint32_t rcrc32_rec(uint32_t crc, const char* s) {
return *s == 0 ? crc
: crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^ static_cast<unsigned char>(*s)] ^ (crc >> 8),
s + 1);
}
static_assert("Hello"_crc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value,
"CRC32 values don't match");
static_assert("0"_crc32 == Crc32<'0'>::value,
"CRC32 values don't match");
constexpr uint32_t operator"" _rcrc32(const char* s, size_t len) { return rcrc32_rec(0xFFFFFFFF, s); }
static_assert("Hello"_rcrc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value, "CRC32 values don't match");
static_assert("0"_rcrc32 == Crc32<'0'>::value, "CRC32 values don't match");
constexpr uint32_t rcrc32_rec(uint32_t crc, const char *s) {
return *s == 0 ? crc :
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
static_cast<unsigned char>(*s)]
^ (crc >> 8), s + 1);
}
constexpr uint64_t crc64_table[] = {
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF,
0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D,
0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847,
0x1C4488F3E8F96ED4, 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A,
0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, 0xF45BB4758C645C51,
0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D,
0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8,
0x0B6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF,
0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, 0xAA478900B1228E31, 0xE8B768EB18C8B8A2,
0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8,
0x2465CD79455E395B, 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A,
0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, 0xDA050215EA6C212F,
0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63,
0x16D7A787B7FAA0D6, 0x5427466C1E109645, 0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7,
0x8F72ECA30CD7A324, 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F,
0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED,
0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87,
0xA07CF2199274CA14, 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144,
0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, 0x84193F60D72AF34F,
0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903,
0x48CB9AF28ABC72B6, 0x0A3B7B1923564425, 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238,
0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F,
0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E,
0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534,
0x78D8A1B9894EC3A7, 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6,
0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, 0x90C79D3FEDD3F122,
0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E,
0x5C1538ADB04570DB, 0x1EE5D94619AF4648, 0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA,
0xC5B073890B687329, 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC,
0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E,
0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754,
0x26C49CCCB40811C7, 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149,
0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, 0xCEDBA04AD0952342,
0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E,
0x020905D88D03A2BB, 0x40F9E43324E99428, 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4,
0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083,
0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, 0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E,
0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4,
0xC4E0DB53F3C36767, 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206,
0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, 0xE085162AB69D5E3C,
0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470,
0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4,
0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C,
0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9, 0x14DEA25F3AF9026D, 0x562E43B4931334FE,
0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394,
0x9AFCE626CE85B507};
constexpr uint32_t operator "" _rcrc32(const char *s, size_t len) {
return rcrc32_rec(0xFFFFFFFF, s);
}
template <uint64_t CRC, char... Chars>
struct Crc64Impl {};
static_assert("Hello"_rcrc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value,
"CRC32 values don't match");
static_assert("0"_rcrc32 == Crc32<'0'>::value,
"CRC32 values don't match");
constexpr uint64_t crc64_table[] =
{
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5,
0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A,
0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B,
0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4,
0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A,
0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285,
0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4,
0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B,
0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B,
0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5,
0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A,
0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584,
0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B,
0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A,
0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5,
0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A,
0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645,
0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324,
0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75,
0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA,
0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB,
0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14,
0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144,
0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B,
0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA,
0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425,
0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB,
0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15,
0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA,
0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78,
0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7,
0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6,
0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19,
0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97,
0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648,
0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329,
0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6,
0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879,
0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18,
0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7,
0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149,
0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96,
0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7,
0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428,
0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57,
0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9,
0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36,
0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8,
0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767,
0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206,
0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9,
0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589,
0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956,
0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37,
0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066,
0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9,
0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8,
0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507
template <uint64_t CRC, char Head, char... Tail>
struct Crc64Impl<CRC, Head, Tail...> {
static constexpr uint64_t value =
Crc64Impl<crc64_table[static_cast<unsigned char>(CRC >> 56) ^ static_cast<unsigned char>(Head)] ^ (CRC << 8),
Tail...>::value;
};
template<uint64_t CRC, char ...Chars> struct Crc64Impl {
template <uint64_t CRC>
struct Crc64Impl<CRC> {
static constexpr uint64_t value = CRC ^ 0xFFFFFFFFFFFFFFFF;
};
template<uint64_t CRC, char Head, char ...Tail> struct Crc64Impl<CRC, Head, Tail...> {
static constexpr uint64_t value = Crc64Impl<
crc64_table[static_cast<unsigned char>(CRC >> 56) ^ static_cast<unsigned char>(Head)]
^ (CRC << 8), Tail...>::value;
};
template <char... Chars>
using Crc64 = Crc64Impl<0xFFFFFFFFFFFFFFFF, Chars...>;
template<uint64_t CRC> struct Crc64Impl<CRC> {
static constexpr uint64_t value = CRC ^ 0xFFFFFFFFFFFFFFFF;
};
template<char ...Chars> using Crc64 = Crc64Impl<0xFFFFFFFFFFFFFFFF, Chars...>;
constexpr uint64_t crc64_rec(uint64_t crc, const char *s) {
return *s == 0 ? crc ^ 0xFFFFFFFFFFFFFFFF :
crc64_rec(crc64_table[static_cast<unsigned char>(crc >> 56) ^
static_cast<unsigned char>(*s)]
^ (crc << 8), s + 1);
constexpr uint64_t crc64_rec(uint64_t crc, const char* s) {
return *s == 0 ? crc ^ 0xFFFFFFFFFFFFFFFF
: crc64_rec(crc64_table[static_cast<unsigned char>(crc >> 56) ^ static_cast<unsigned char>(*s)] ^
(crc << 8),
s + 1);
}
constexpr uint64_t operator "" _crc64(const char *s, size_t len) {
return crc64_rec(0xFFFFFFFFFFFFFFFF, s);
}
static_assert("Hello"_crc64 == Crc64<'H', 'e', 'l', 'l', 'o'>::value,
"CRC64 values don't match");
static_assert("0"_crc64 == Crc64<'0'>::value,
"CRC64 values don't match");
}
constexpr uint64_t operator"" _crc64(const char* s, size_t len) { return crc64_rec(0xFFFFFFFFFFFFFFFF, s); }
static_assert("Hello"_crc64 == Crc64<'H', 'e', 'l', 'l', 'o'>::value, "CRC64 values don't match");
static_assert("0"_crc64 == Crc64<'0'>::value, "CRC64 values don't match");
} // namespace athena::checksums::literals

View File

@@ -2,8 +2,7 @@
#include "athena/Global.hpp"
namespace athena::io::Compression
{
namespace athena::io::Compression {
// Zlib compression
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
@@ -17,4 +16,4 @@ atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data);
atUint32 decompressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst);
atUint32 compressLZ77(const atUint8* src, atUint32 srcLen, atUint8** dst, bool extended = false);
}
} // namespace athena::io::Compression

View File

@@ -13,8 +13,7 @@
#include <vector>
#include <memory>
namespace athena::io
{
namespace athena::io {
/**
* @brief Base DNA class used against 'atdna'
@@ -26,81 +25,80 @@ namespace athena::io
* a streamed medium
*/
template <Endian DNAE>
struct DNA
{
/**
* @brief Designated byte-order used for serializing fields
*/
static constexpr Endian DNAEndian = DNAE;
struct DNA {
/**
* @brief Designated byte-order used for serializing fields
*/
static constexpr Endian DNAEndian = DNAE;
/**
* @brief Template type signaling atdna to capture the value where it's used
* @tparam T The type of the value. Can be any numeric type or atVec* type
* @tparam VE Endianness of the value
*/
template <typename T, Endian VE = DNAE>
using Value = T;
/**
* @brief Template type signaling atdna to capture the value where it's used
* @tparam T The type of the value. Can be any numeric type or atVec* type
* @tparam VE Endianness of the value
*/
template <typename T, Endian VE = DNAE>
using Value = T;
/**
* @brief Template type wrapping std::vector and signaling atdna to manipulate it where it's used
* @tparam T The type of contained elements. Can be any numeric type, atVec* type, or another DNA subclass
* @tparam cntVar C++ expression wrapped in DNA_COUNT macro to determine number of elements for vector
* @tparam VE Endianness of the contained values
*/
template <typename T, size_t cntVar, Endian VE = DNAE>
using Vector = std::vector<T>;
/**
* @brief Template type wrapping std::vector and signaling atdna to manipulate it where it's used
* @tparam T The type of contained elements. Can be any numeric type, atVec* type, or another DNA subclass
* @tparam cntVar C++ expression wrapped in DNA_COUNT macro to determine number of elements for vector
* @tparam VE Endianness of the contained values
*/
template <typename T, size_t cntVar, Endian VE = DNAE>
using Vector = std::vector<T>;
/**
* @brief Template type wrapping std::unique_ptr<atUint8[]> and signaling atdna to read a
* raw byte-buffer where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of bytes for buffer
*/
template <size_t sizeVar>
using Buffer = std::unique_ptr<atUint8[]>;
/**
* @brief Template type wrapping std::unique_ptr<atUint8[]> and signaling atdna to read a
* raw byte-buffer where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of bytes for buffer
*/
template <size_t sizeVar>
using Buffer = std::unique_ptr<atUint8[]>;
/**
* @brief Template type wrapping std::string and signaling atdna to read string data where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of characters for string
* -1 literal indicates null-terminated string
*/
template <atInt32 sizeVar = -1>
using String = std::string;
/**
* @brief Template type wrapping std::string and signaling atdna to read string data where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of characters for string
* -1 literal indicates null-terminated string
*/
template <atInt32 sizeVar = -1>
using String = std::string;
/**
* @brief Template type wrapping std::wstring and signaling atdna to read wstring data where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of characters for wstring
* -1 literal indicates null-terminated wstring
*/
template <atInt32 sizeVar = -1, Endian VE = DNAE>
using WString = std::wstring;
/**
* @brief Template type wrapping std::wstring and signaling atdna to read wstring data where it's used
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of characters for wstring
* -1 literal indicates null-terminated wstring
*/
template <atInt32 sizeVar = -1, Endian VE = DNAE>
using WString = std::wstring;
/**
* @brief Meta Template signaling atdna to insert a stream seek where it's used
* @tparam offset C++ expression wrapped in DNA_COUNT macro to determine number of bytes to seek
* @tparam direction SeekOrigin to seek relative to
*/
template <off_t offset, SeekOrigin direction>
struct Seek {};
/**
* @brief Meta Template signaling atdna to insert a stream seek where it's used
* @tparam offset C++ expression wrapped in DNA_COUNT macro to determine number of bytes to seek
* @tparam direction SeekOrigin to seek relative to
*/
template <off_t offset, SeekOrigin direction>
struct Seek {};
/**
* @brief Meta Template signaling atdna to insert an aligning stream seek where it's used
* @tparam align Number of bytes to align to
*/
template <size_t align>
struct Align {};
/**
* @brief Meta Template signaling atdna to insert an aligning stream seek where it's used
* @tparam align Number of bytes to align to
*/
template <size_t align>
struct Align {};
/**
* @brief Meta Template preventing atdna from emitting read/write implementations
*/
struct Delete {};
/**
* @brief Meta Template preventing atdna from emitting read/write implementations
*/
struct Delete {};
/* Bring fundamental operations into DNA subclasses for easier per-op overrides */
using Read = athena::io::Read<PropType::None>;
using Write = athena::io::Write<PropType::None>;
using BinarySize = athena::io::BinarySize<PropType::None>;
using PropCount = athena::io::PropCount<PropType::None>;
using ReadYaml = athena::io::ReadYaml<PropType::None>;
using WriteYaml = athena::io::WriteYaml<PropType::None>;
/* Bring fundamental operations into DNA subclasses for easier per-op overrides */
using Read = athena::io::Read<PropType::None>;
using Write = athena::io::Write<PropType::None>;
using BinarySize = athena::io::BinarySize<PropType::None>;
using PropCount = athena::io::PropCount<PropType::None>;
using ReadYaml = athena::io::ReadYaml<PropType::None>;
using WriteYaml = athena::io::WriteYaml<PropType::None>;
};
/**
@@ -120,24 +118,22 @@ struct DNA
* { (Do stuff with `r`) }
*/
template <Endian DNAE>
struct DNAV : DNA<DNAE>
{
virtual ~DNAV() = default;
virtual void read(athena::io::IStreamReader& r) = 0;
virtual void write(athena::io::IStreamWriter& w) const = 0;
virtual void binarySize(size_t& s) const = 0;
virtual const char* DNATypeV() const = 0;
struct DNAV : DNA<DNAE> {
virtual ~DNAV() = default;
virtual void read(athena::io::IStreamReader& r) = 0;
virtual void write(athena::io::IStreamWriter& w) const = 0;
virtual void binarySize(size_t& s) const = 0;
virtual const char* DNATypeV() const = 0;
};
template <Endian DNAE>
struct DNAVYaml : DNAV<DNAE>
{
virtual ~DNAVYaml() = default;
virtual void read(athena::io::IStreamReader& r) = 0;
virtual void write(athena::io::IStreamWriter& w) const = 0;
virtual void binarySize(size_t& s) const = 0;
virtual void read(athena::io::YAMLDocReader& r) = 0;
virtual void write(athena::io::YAMLDocWriter& w) const = 0;
struct DNAVYaml : DNAV<DNAE> {
virtual ~DNAVYaml() = default;
virtual void read(athena::io::IStreamReader& r) = 0;
virtual void write(athena::io::IStreamWriter& w) const = 0;
virtual void binarySize(size_t& s) const = 0;
virtual void read(athena::io::YAMLDocReader& r) = 0;
virtual void write(athena::io::YAMLDocWriter& w) const = 0;
};
/** Macro to supply count variable to atdna and mute it for other compilers */
@@ -147,6 +143,4 @@ struct DNAVYaml : DNAV<DNAE>
#define AT_DNA_COUNT(cnt) 0
#endif
}
} // namespace athena::io

File diff suppressed because it is too large Load Diff

View File

@@ -6,132 +6,116 @@
#include "FileReader.hpp"
#include "FileWriter.hpp"
namespace athena::io
{
namespace athena::io {
template <class T>
static inline const char* __GetDNAName(const T& dna,
typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0)
{
return dna.DNATypeV();
static inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0) {
return dna.DNATypeV();
}
template <class T>
static inline const char* __GetDNAName(const T& dna,
typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0)
{
return dna.DNAType();
static inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0) {
return dna.DNAType();
}
template <class T>
static inline std::string ToYAMLString(const T& dna)
{
YAMLDocWriter docWriter(__GetDNAName(dna));
static inline std::string ToYAMLString(const T& dna) {
YAMLDocWriter docWriter(__GetDNAName(dna));
std::string res;
yaml_emitter_set_output(docWriter.getEmitter(), (yaml_write_handler_t*)YAMLStdStringWriter, &res);
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
std::string res;
yaml_emitter_set_output(docWriter.getEmitter(), (yaml_write_handler_t*)YAMLStdStringWriter, &res);
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
dna.write(docWriter);
if (!docWriter.finish(nullptr))
return std::string();
dna.write(docWriter);
if (!docWriter.finish(nullptr))
return std::string();
return res;
return res;
}
template <class T>
static inline bool FromYAMLString(T& dna, std::string_view str)
{
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
if (!docReader.parse(nullptr))
return false;
dna.read(docReader);
return true;
static inline bool FromYAMLString(T& dna, std::string_view str) {
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
if (!docReader.parse(nullptr))
return false;
dna.read(docReader);
return true;
}
template<class DNASubtype>
static inline bool ValidateFromYAMLString(std::string_view str)
{
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
bool retval = docReader.ValidateClassType(DNASubtype::DNAType());
return retval;
template <class DNASubtype>
static inline bool ValidateFromYAMLString(std::string_view str) {
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
bool retval = docReader.ValidateClassType(DNASubtype::DNAType());
return retval;
}
template <class T>
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout)
{
YAMLDocWriter docWriter(__GetDNAName(dna));
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
YAMLDocWriter docWriter(__GetDNAName(dna));
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
dna.write(docWriter);
return docWriter.finish(&fout);
dna.write(docWriter);
return docWriter.finish(&fout);
}
template <class T>
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
void(T::*fn)(YAMLDocWriter& out)const)
{
YAMLDocWriter docWriter(__GetDNAName(dna));
void (T::*fn)(YAMLDocWriter& out) const) {
YAMLDocWriter docWriter(__GetDNAName(dna));
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
(dna.*fn)(docWriter);
return docWriter.finish(&fout);
(dna.*fn)(docWriter);
return docWriter.finish(&fout);
}
template <class T>
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin)
{
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
dna.read(docReader);
return true;
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
dna.read(docReader);
return true;
}
template <class T>
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin,
void(T::*fn)(YAMLDocReader& in))
{
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
(dna.*fn)(docReader);
return true;
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)(YAMLDocReader& in)) {
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
(dna.*fn)(docReader);
return true;
}
template <class T, typename NameT>
static inline bool MergeToYAMLFile(const T& dna, const NameT& filename)
{
athena::io::FileReader r(filename);
YAMLDocWriter docWriter(__GetDNAName(dna), r.isOpen() ? &r : nullptr);
r.close();
static inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
athena::io::FileReader r(filename);
YAMLDocWriter docWriter(__GetDNAName(dna), r.isOpen() ? &r : nullptr);
r.close();
dna.write(docWriter);
athena::io::FileWriter w(filename);
if (!w.isOpen())
return false;
return docWriter.finish(&w);
dna.write(docWriter);
athena::io::FileWriter w(filename);
if (!w.isOpen())
return false;
return docWriter.finish(&w);
}
template <class DNASubtype>
static inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin)
{
YAMLDocReader reader;
atUint64 pos = fin.position();
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);
bool retval = reader.ValidateClassType(DNASubtype::DNAType());
fin.seek(pos, athena::Begin);
return retval;
}
static inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin) {
YAMLDocReader reader;
atUint64 pos = fin.position();
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);
bool retval = reader.ValidateClassType(DNASubtype::DNAType());
fin.seek(pos, athena::Begin);
return retval;
}
} // namespace athena::io

View File

@@ -8,30 +8,26 @@
typedef int mode_t;
#endif
namespace athena
{
class Dir
{
namespace athena {
class Dir {
public:
explicit Dir(std::string_view path);
explicit Dir(std::string_view path);
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view path)
{ return Dir(path).absolutePath(); }
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view path) { return Dir(path).absolutePath(); }
bool isDir() const;
static bool isDir(std::string_view dir)
{ return Dir(dir).isDir(); }
bool isDir() const;
static bool isDir(std::string_view dir) { return Dir(dir).isDir(); }
std::vector<FileInfo> files() const;
std::vector<FileInfo> files() const;
bool cd(std::string_view path);
bool rm(std::string_view path);
bool touch();
static bool mkdir(std::string_view dir, mode_t mode = 0755);
static bool mkpath(std::string_view path, mode_t mode = 0755);
bool cd(std::string_view path);
bool rm(std::string_view path);
bool touch();
static bool mkdir(std::string_view dir, mode_t mode = 0755);
static bool mkpath(std::string_view path, mode_t mode = 0755);
private:
std::string m_path;
std::string m_path;
};
}
} // namespace athena

View File

@@ -4,54 +4,41 @@
#include "athena/Global.hpp"
namespace athena
{
class FileInfo
{
namespace athena {
class FileInfo {
public:
explicit FileInfo(std::string_view path = {});
explicit FileInfo(std::string_view path = {});
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view lnk)
{ return FileInfo(lnk).absolutePath(); }
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view lnk) { return FileInfo(lnk).absolutePath(); }
std::string absoluteFilePath() const;
static inline std::string absoluteFilePath(std::string_view path)
{ return FileInfo(path).absoluteFilePath(); }
std::string absoluteFilePath() const;
static inline std::string absoluteFilePath(std::string_view path) { return FileInfo(path).absoluteFilePath(); }
std::string filename() const;
static inline std::string filename(std::string_view path)
{ return FileInfo(path).filename(); }
std::string filename() const;
static inline std::string filename(std::string_view path) { return FileInfo(path).filename(); }
std::string path() const { return m_path; }
static inline std::string path(std::string_view path)
{ return FileInfo(path).path(); }
std::string path() const { return m_path; }
static inline std::string path(std::string_view path) { return FileInfo(path).path(); }
std::string extension() const;
static inline std::string extension(std::string_view path)
{ return FileInfo(path).extension(); }
std::string extension() const;
static inline std::string extension(std::string_view path) { return FileInfo(path).extension(); }
atUint64 size() const;
static inline atUint64 size(std::string_view path)
{ return FileInfo(path).size(); }
atUint64 size() const;
static inline atUint64 size(std::string_view path) { return FileInfo(path).size(); }
bool exists() const;
static inline bool exists(std::string_view path)
{ return FileInfo(path).exists(); }
bool exists() const;
static inline bool exists(std::string_view path) { return FileInfo(path).exists(); }
bool isLink() const;
static inline bool isLink(std::string_view lnk)
{ return FileInfo(lnk).isLink(); }
bool isFile() const;
static inline bool isFile(std::string_view path)
{ return FileInfo(path).isFile(); }
bool isLink() const;
static inline bool isLink(std::string_view lnk) { return FileInfo(lnk).isLink(); }
bool isFile() const;
static inline bool isFile(std::string_view path) { return FileInfo(path).isFile(); }
bool touch() const;
static inline bool touch(std::string_view path)
{ return FileInfo(path).touch(); }
bool touch() const;
static inline bool touch(std::string_view path) { return FileInfo(path).touch(); }
private:
std::string m_path;
std::string m_path;
};
}
} // namespace athena

View File

@@ -13,71 +13,66 @@
#include <memory>
#include "athena/IStreamReader.hpp"
namespace athena::io
{
class FileReader : public IStreamReader
{
namespace athena::io {
class FileReader : public IStreamReader {
public:
FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr=true);
FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr=true);
virtual ~FileReader();
FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
virtual ~FileReader();
inline std::string filename() const
{
inline std::string filename() const {
#if _WIN32
return utility::wideToUtf8(m_filename);
return utility::wideToUtf8(m_filename);
#else
return m_filename;
return m_filename;
#endif
}
}
inline std::wstring wfilename() const
{
inline std::wstring wfilename() const {
#if _WIN32
return m_filename;
return m_filename;
#else
return utility::utf8ToWide(m_filename);
return utility::utf8ToWide(m_filename);
#endif
}
}
void open();
void close();
inline bool isOpen() const
{return m_fileHandle != 0;}
bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
atUint64 readUBytesToBuf(void* buf, atUint64 len);
void open();
void close();
inline bool isOpen() const { return m_fileHandle != 0; }
bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
atUint64 readUBytesToBuf(void* buf, atUint64 len);
void setCacheSize(const atInt32 blockSize);
void setCacheSize(const atInt32 blockSize);
#if _WIN32
using HandleType = HANDLE;
using HandleType = HANDLE;
#else
using HandleType = FILE*;
using HandleType = FILE*;
#endif
HandleType _fileHandle() {return m_fileHandle;}
HandleType _fileHandle() { return m_fileHandle; }
protected:
#if _WIN32
std::wstring m_filename;
std::wstring m_filename;
#else
std::string m_filename;
std::string m_filename;
#endif
HandleType m_fileHandle;
std::unique_ptr<atUint8[]> m_cacheData;
atInt32 m_blockSize;
atInt32 m_curBlock;
atUint64 m_offset;
bool m_globalErr;
HandleType m_fileHandle;
std::unique_ptr<atUint8[]> m_cacheData;
atInt32 m_blockSize;
atInt32 m_curBlock;
atUint64 m_offset;
bool m_globalErr;
};
} // Athena
} // namespace athena::io
#ifndef FILEREADER_BASE
#define FILEREADER_BASE() \
private: \
typedef athena::io::FileReader base
#define FILEREADER_BASE() \
private: \
typedef athena::io::FileReader base
#endif // FILEREADER_BASE

View File

@@ -10,112 +10,107 @@
#endif
#include "athena/IStreamWriter.hpp"
namespace athena::io
{
class FileWriter : public IStreamWriter
{
namespace athena::io {
class FileWriter : public IStreamWriter {
public:
FileWriter(std::string_view filename, bool overwrite = true, bool globalErr=true);
FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr=true);
virtual ~FileWriter();
FileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true);
FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true);
virtual ~FileWriter();
inline std::string filename() const
{
inline std::string filename() const {
#if _WIN32
return utility::wideToUtf8(m_filename);
return utility::wideToUtf8(m_filename);
#else
return m_filename;
return m_filename;
#endif
}
inline std::wstring wfilename() const
{
}
inline std::wstring wfilename() const {
#if _WIN32
return m_filename;
return m_filename;
#else
return utility::utf8ToWide(m_filename);
return utility::utf8ToWide(m_filename);
#endif
}
}
void open(bool overwrite = true);
void close();
inline bool isOpen() const
{return m_fileHandle != 0;}
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
void writeUBytes(const atUint8* data, atUint64 len);
void open(bool overwrite = true);
void close();
inline bool isOpen() const { return m_fileHandle != 0; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
void writeUBytes(const atUint8* data, atUint64 len);
#if _WIN32
using HandleType = HANDLE;
using HandleType = HANDLE;
#else
using HandleType = FILE*;
using HandleType = FILE*;
#endif
HandleType _fileHandle() {return m_fileHandle;}
HandleType _fileHandle() { return m_fileHandle; }
private:
#if _WIN32
std::wstring m_filename;
std::wstring m_filename;
#else
std::string m_filename;
std::string m_filename;
#endif
HandleType m_fileHandle;
bool m_globalErr;
HandleType m_fileHandle;
bool m_globalErr;
};
class TransactionalFileWriter : public IStreamWriter
{
class TransactionalFileWriter : public IStreamWriter {
#if _WIN32
std::wstring m_filename;
std::wstring m_filename;
#else
std::string m_filename;
std::string m_filename;
#endif
bool m_overwrite, m_globalErr;
std::vector<uint8_t> m_deferredBuffer;
atUint64 m_position = 0;
bool m_overwrite, m_globalErr;
std::vector<uint8_t> m_deferredBuffer;
atUint64 m_position = 0;
public:
TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr=true)
: m_overwrite(overwrite), m_globalErr(globalErr)
{
TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
m_filename = utility::utf8ToWide(filename);
m_filename = utility::utf8ToWide(filename);
#else
m_filename = filename;
m_filename = filename;
#endif
}
TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr=true)
: m_overwrite(overwrite), m_globalErr(globalErr)
{
}
TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
m_filename = filename;
m_filename = filename;
#else
m_filename = utility::wideToUtf8(filename);
m_filename = utility::wideToUtf8(filename);
#endif
}
void flush() {
if (m_deferredBuffer.size()) {
FileWriter w(m_filename, m_overwrite, m_globalErr);
w.writeUBytes(m_deferredBuffer.data(), m_deferredBuffer.size());
cancel();
}
}
void flush()
{
if (m_deferredBuffer.size())
{
FileWriter w(m_filename, m_overwrite, m_globalErr);
w.writeUBytes(m_deferredBuffer.data(), m_deferredBuffer.size());
cancel();
}
}
void cancel() {
m_deferredBuffer.clear();
m_position = 0;
}
void cancel() { m_deferredBuffer.clear(); m_position = 0; }
inline atUint64 position() const { return m_position; }
inline atUint64 length() const { return m_deferredBuffer.size(); }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void writeUBytes(const atUint8* data, atUint64 len);
inline atUint64 position() const { return m_position; }
inline atUint64 length() const { return m_deferredBuffer.size(); }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void writeUBytes(const atUint8* data, atUint64 len);
~TransactionalFileWriter() { flush(); }
~TransactionalFileWriter() { flush(); }
};
} // Athena
} // namespace athena::io
#ifndef FILEWRITER_BASE
#define FILEWRITER_BASE() \
private: \
typedef athena::io::FileWriter base;
#define FILEWRITER_BASE() \
private: \
typedef athena::io::FileWriter base;
#endif // FILEWRITER_BASE

View File

@@ -82,80 +82,57 @@ typedef struct stat64 atStat64_t;
#ifndef ENABLE_BITWISE_ENUM
#define ENABLE_BITWISE_ENUM(type) \
constexpr type operator|(type a, type b) \
{ \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) | static_cast<T>(b)); \
} \
constexpr type operator&(type a, type b) \
{ \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) & static_cast<T>(b)); \
} \
inline type& operator|=(type& a, const type& b) \
{ \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) | static_cast<T>(b)); \
return a; \
} \
inline type& operator&=(type& a, const type& b) \
{ \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) & static_cast<T>(b)); \
return a; \
} \
inline type operator~(const type& key) \
{ \
using T = std::underlying_type_t<type>; \
return type(~static_cast<T>(key)); \
}
constexpr type operator|(type a, type b) { \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) | static_cast<T>(b)); \
} \
constexpr type operator&(type a, type b) { \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) & static_cast<T>(b)); \
} \
inline type& operator|=(type& a, const type& b) { \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) | static_cast<T>(b)); \
return a; \
} \
inline type& operator&=(type& a, const type& b) { \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) & static_cast<T>(b)); \
return a; \
} \
inline type operator~(const type& key) { \
using T = std::underlying_type_t<type>; \
return type(~static_cast<T>(key)); \
}
#endif
namespace athena
{
namespace error
{
enum class Level
{
Message,
Warning,
Error,
Fatal
};
namespace athena {
namespace error {
enum class Level { Message, Warning, Error, Fatal };
}
enum SeekOrigin
{
Begin,
Current,
End
};
enum SeekOrigin { Begin, Current, End };
enum Endian
{
Little,
Big
};
enum Endian { Little, Big };
namespace io
{
namespace io {
template <Endian DNAE>
struct DNA;
template <Endian DNAE>
struct DNAV;
template <class T>
using __IsDNARecord = typename std::disjunction<std::is_base_of<DNA<Endian::Big>, T>,
std::is_base_of<DNA<Endian::Little>, T>>;
using __IsDNARecord =
typename std::disjunction<std::is_base_of<DNA<Endian::Big>, T>, std::is_base_of<DNA<Endian::Little>, T>>;
template <class T>
inline constexpr bool __IsDNARecord_v = __IsDNARecord<T>::value;
template <class T>
using __IsDNAVRecord = typename std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>,
std::is_base_of<DNAV<Endian::Little>, T>>;
using __IsDNAVRecord =
typename std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>, std::is_base_of<DNAV<Endian::Little>, T>>;
template <class T>
inline constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
}
} // Athena
} // namespace io
} // namespace athena
typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line,
const char* fmt, ...);
@@ -173,91 +150,80 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#ifdef _MSC_VER
#ifndef NDEBUG
#define atDebug(fmt, ...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#else
#define atDebug(fmt, ...)
#endif
#define atMessage(fmt, ...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atWarning(fmt, ...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atError(fmt, ...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atFatal(fmt, ...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#elif defined(__GNUC__)
#ifndef NDEBUG
#define atDebug(fmt...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#else // _MSC_VER
#define atDebug(fmt, ...)
#endif // NDEBUG
#define atMessage(fmt...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atWarning(fmt...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atError(fmt...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atFatal(fmt...) \
do \
{ \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
do { \
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#endif // defined(__GNUC__)

View File

@@ -2,31 +2,30 @@
#include "Global.hpp"
namespace athena::io
{
namespace athena::io {
std::ostream& operator<<(std::ostream& os, Endian& endian);
class IStream
{
class IStream {
public:
virtual ~IStream() = default;
virtual ~IStream() = default;
void setEndian(Endian endian) { m_endian = endian; }
Endian endian() const { return m_endian; }
bool isBigEndian() const { return (m_endian == Endian::Big); }
bool isLittleEndian() const { return (m_endian == Endian::Little); }
virtual void seek(atInt64, SeekOrigin) = 0;
virtual bool atEnd() const = 0;
virtual atUint64 position() const = 0;
virtual atUint64 length() const = 0;
bool hasError() const { return m_hasError; }
void setEndian(Endian endian) { m_endian = endian; }
Endian endian() const { return m_endian; }
bool isBigEndian() const { return (m_endian == Endian::Big); }
bool isLittleEndian() const { return (m_endian == Endian::Little); }
virtual void seek(atInt64, SeekOrigin) = 0;
virtual bool atEnd() const = 0;
virtual atUint64 position() const = 0;
virtual atUint64 length() const = 0;
bool hasError() const { return m_hasError; }
protected:
void setError() { m_hasError = true; }
bool m_hasError = false;
void setError() { m_hasError = true; }
bool m_hasError = false;
#if __BYTE_ORDER == __BIG_ENDIAN
Endian m_endian = Big;
Endian m_endian = Big;
#else
Endian m_endian = Little;
Endian m_endian = Little;
#endif
};
}
} // namespace athena::io

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,7 @@
#include "athena/Global.hpp"
namespace athena
{
namespace athena {
class MCSlot;
/*! \class MCFile
@@ -12,23 +11,18 @@ class MCSlot;
* Contains all relevant data for a The Minish Cap save,
* file.
*/
class MCFile
{
class MCFile {
public:
static const char VERSION_EU_JP[33];
static const char VERSION_US[33];
enum SlotType
{
New = 0x54494E49,
Valid = 0x4D435A33,
Deleted = 0x466C6544
};
static const char VERSION_EU_JP[33];
static const char VERSION_US[33];
enum SlotType { New = 0x54494E49, Valid = 0x4D435A33, Deleted = 0x466C6544 };
MCFile();
MCFile();
static atUint8* unscramble(atUint8* data, atUint64 length);
static atUint8* unscramble(atUint8* data, atUint64 length);
private:
MCSlot* m_slots[3];
MCSlot* m_slots[3];
};
} // zelda
} // namespace athena

View File

@@ -2,13 +2,11 @@
#include "athena/MemoryReader.hpp"
namespace athena
{
namespace athena {
class MCFile;
namespace io
{
namespace io {
/*! \class MCFileReader
* \brief The Minish Cap Save save data reader class
@@ -17,32 +15,30 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class MCFileReader : public MemoryCopyReader
{
class MCFileReader : public MemoryCopyReader {
public:
/*!
* \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileReader(atUint8*, atUint64);
/*!
* \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileReader(atUint8*, atUint64);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileReader(const std::string&);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileReader(const std::string&);
/*!
* \brief Reads the save data from the buffer
*
* \return MCFile* SRAM data
*/
MCFile* readFile();
/*!
* \brief Reads the save data from the buffer
*
* \return MCFile* SRAM data
*/
MCFile* readFile();
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -3,13 +3,11 @@
#include "athena/Types.hpp"
#include "athena/MemoryWriter.hpp"
namespace athena
{
namespace athena {
class MCFile;
namespace io
{
namespace io {
/*! \class MCFileWriter
* \brief The Minish Cap Save save data writer class
@@ -18,36 +16,35 @@ namespace io
* all work is done using a memory buffer, and not written directly from the disk.
* \sa BinaryWriter
*/
class MCFileWriter : protected MemoryCopyWriter
{
class MCFileWriter : protected MemoryCopyWriter {
public:
/*!
* \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileWriter(atUint8*, atUint64);
/*!
* \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileWriter(atUint8*, atUint64);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileWriter(const std::string&);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileWriter(const std::string&);
/*!
* \brief Writes the given save data to a file on disk
*
* \param file Save data to write
*/
void writeFile(MCFile* file);
/*!
* \brief Writes the given save data to a file on disk
*
* \param file Save data to write
*/
void writeFile(MCFile* file);
static atUint16 calculateChecksum(atUint8* data, atUint32 length);
static atUint16 calculateChecksum(atUint8* data, atUint32 length);
private:
atUint16 calculateSlotChecksum(atUint32 game);
atUint16 calculateSlotChecksum(atUint32 game);
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -3,13 +3,10 @@
#include "athena/Global.hpp"
#include "athena/ZQuestFile.hpp"
namespace athena
{
class MCSlot : public ZQuestFile
{
namespace athena {
class MCSlot : public ZQuestFile {
public:
MCSlot(std::unique_ptr<atUint8[]>&& data, atUint32 length);
MCSlot(std::unique_ptr<atUint8[]>&& data, atUint32 length);
};
} // Athena
} // namespace athena

View File

@@ -5,8 +5,7 @@
#include <functional>
#include "athena/IStreamReader.hpp"
namespace athena::io
{
namespace athena::io {
/*! \class MemoryReader
* \brief A Stream class for reading data from a memory position
*
@@ -15,106 +14,97 @@ namespace athena::io
* this allows for fast, flexible code as well as the ability to quickly modify data
* \sa Stream
*/
class MemoryReader : public IStreamReader
{
class MemoryReader : public IStreamReader {
protected:
MemoryReader() = default;
MemoryReader() = default;
public:
virtual ~MemoryReader();
virtual ~MemoryReader();
/*! \brief This constructor references an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
* \param takeOwnership Memory will be freed with the reader if set
*/
MemoryReader(const void* data, atUint64 length, bool takeOwnership=false, bool globalErr=true);
/*! \brief This constructor references an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
* \param takeOwnership Memory will be freed with the reader if set
*/
MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* \param position where in the buffer to seek
* \param origin The Origin to seek \sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* \param position where in the buffer to seek
* \param origin The Origin to seek \sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! \brief Returns the current position in the stream.
*
* \return Int64 The current position in the stream.
*/
inline atUint64 position() const
{return m_position;}
/*! \brief Returns the current position in the stream.
*
* \return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
/*! \brief Returns whether or not the stream is at the end.
*
* \return bool True if at end; False otherwise.
*/
inline atUint64 length() const
{return m_length;}
/*! \brief Returns whether or not the stream is at the end.
*
* \return bool True if at end; False otherwise.
*/
inline atUint64 length() const { return m_length; }
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
* if that was not the intent.<br />
* Once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* \param data The new buffer.
* \param length The length of the new buffer.
* \param takeOwnership Memory will be freed with the reader if set
* \throw IOException
*/
void setData(const atUint8* data, atUint64 length, bool takeOwnership = false);
/*! \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
* if that was not the intent.<br />
* Once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* \param data The new buffer.
* \param length The length of the new buffer.
* \param takeOwnership Memory will be freed with the reader if set
* \throw IOException
*/
void setData(const atUint8* data, atUint64 length, bool takeOwnership=false);
/*! \brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
* directly edit the buffer and use setData to set the new information.<br />
* However once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* \return Uint8* The copy of the buffer.
*/
atUint8* data() const;
/*! \brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
* directly edit the buffer and use setData to set the new information.<br />
* However once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* \return Uint8* The copy of the buffer.
*/
atUint8* data() const;
/*! \brief Reads a specified number of bytes to user-allocated buffer
* \param buf User-allocated buffer pointer
* \param len Length to read
* \return Number of bytes read
*/
atUint64 readUBytesToBuf(void* buf, atUint64 len);
/*! \brief Reads a specified number of bytes to user-allocated buffer
* \param buf User-allocated buffer pointer
* \param len Length to read
* \return Number of bytes read
*/
atUint64 readUBytesToBuf(void* buf, atUint64 len);
protected:
const void* m_data = nullptr;
atUint64 m_length = 0;
atUint64 m_position = 0;
bool m_owns = false;
bool m_globalErr = true;
const void* m_data = nullptr;
atUint64 m_length = 0;
atUint64 m_position = 0;
bool m_owns = false;
bool m_globalErr = true;
};
class MemoryCopyReader : public MemoryReader
{
class MemoryCopyReader : public MemoryReader {
public:
/*! \brief This constructor copies an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MemoryCopyReader(const void* data, atUint64 length);
/*! \brief This constructor copies an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MemoryCopyReader(const void* data, atUint64 length);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MemoryCopyReader(const std::string& filename)
: m_filepath(filename)
{loadData();}
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); }
void setData(const atUint8* data, atUint64 length);
void setData(const atUint8* data, atUint64 length);
protected:
void loadData();
std::unique_ptr<atUint8[]> m_dataCopy;
std::string m_filepath; //!< Path to the target file
void loadData();
std::unique_ptr<atUint8[]> m_dataCopy;
std::string m_filepath; //!< Path to the target file
};
} // Athena
} // namespace athena::io

View File

@@ -5,8 +5,7 @@
#include <functional>
#include "athena/IStreamWriter.hpp"
namespace athena::io
{
namespace athena::io {
/*! @class MemoryWriter
* @brief A Stream class for writing data to a memory position
@@ -16,144 +15,133 @@ namespace athena::io
* this allows for fast, flexible code as well as the ability to quickly modify data
* @sa Stream
*/
class MemoryWriter : public IStreamWriter
{
class MemoryWriter : public IStreamWriter {
public:
virtual ~MemoryWriter();
virtual ~MemoryWriter();
/*! @brief This constructor references an existing buffer to write to in-place.
*
* @param data The existing buffer
* @param length The length of the existing buffer
*/
explicit MemoryWriter(atUint8* data, atUint64 length, bool takeOwnership = false);
/*! @brief This constructor references an existing buffer to write to in-place.
*
* @param data The existing buffer
* @param length The length of the existing buffer
*/
explicit MemoryWriter(atUint8* data, atUint64 length, bool takeOwnership = false);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_length; }
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const
{return m_position;}
inline bool isOpen() const { return true; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const
{return m_length;}
/** @brief Sets the buffer to the given one, deleting the current one if it owns it.<br />
* @param data The new buffer.
* @param length The length of the new buffer.
* @param takeOwnership Whether the Stream now owns the buffer.
*/
void setData(atUint8* data, atUint64 length, bool takeOwnership = false);
inline bool isOpen() const {return true;}
/*! @brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
* directly edit the buffer and use setData to set the new information.<br />
* @return Uint8* The copy of the buffer.
*/
atUint8* data() const;
/** @brief Sets the buffer to the given one, deleting the current one if it owns it.<br />
* @param data The new buffer.
* @param length The length of the new buffer.
* @param takeOwnership Whether the Stream now owns the buffer.
*/
void setData(atUint8* data, atUint64 length, bool takeOwnership = false);
/*! @brief Sets the target file
*
* @param filepath The path to write to.
*/
inline void setFilepath(const std::string& filepath) { m_filepath = filepath; }
/*! @brief
* Returns the target file
*/
inline std::string filepath() const { return m_filepath; }
/*! @brief Returns a copy of the current buffer.<br />
* Changes to the copy do not affect the buffer so it's perfectly safe to
* directly edit the buffer and use setData to set the new information.<br />
* @return Uint8* The copy of the buffer.
*/
atUint8* data() const;
/*! @brief Saves the file to the specified file.
*
* @param filename If not empty, the filename to save to
*/
void save(std::string_view filename = {});
/*! @brief Sets the target file
*
* @param filepath The path to write to.
*/
inline void setFilepath(const std::string& filepath)
{m_filepath = filepath;}
/*! @brief
* Returns the target file
*/
inline std::string filepath() const
{return m_filepath;}
/*! @brief Saves the file to the specified file.
*
* @param filename If not empty, the filename to save to
*/
void save(std::string_view filename = {});
/*! @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.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
/*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
protected:
MemoryWriter() {}
atUint8* m_data;
atUint64 m_length;
atUint64 m_position;
bool m_bufferOwned;
std::string m_filepath; //!< Path to the target file
MemoryWriter() {}
atUint8* m_data;
atUint64 m_length;
atUint64 m_position;
bool m_bufferOwned;
std::string m_filepath; //!< Path to the target file
};
class MemoryCopyWriter : public MemoryWriter
{
class MemoryCopyWriter : public MemoryWriter {
public:
/*! @brief This constructor copies an existing buffer to write to.
*
* @param data The existing buffer
* @param length The length of the existing buffer
*/
explicit MemoryCopyWriter(atUint8* data = nullptr, atUint64 length = 0x10);
/*! @brief This constructor copies an existing buffer to write to.
*
* @param data The existing buffer
* @param length The length of the existing buffer
*/
explicit MemoryCopyWriter(atUint8* data=nullptr, atUint64 length=0x10);
/*! @brief This constructor creates an instance from a file on disk.
*
* @param filename The file to create the stream from
*/
MemoryCopyWriter(std::string_view filename);
/*! @brief This constructor creates an instance from a file on disk.
*
* @param filename The file to create the stream from
*/
MemoryCopyWriter(std::string_view filename);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @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
* if that was not the intent.<br />
* Once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* @param data The new buffer.
* @param length The length of the new buffer.
* @throw IOException
*/
void setData(const atUint8* data, atUint64 length);
/*! @brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
* if that was not the intent.<br />
* Once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* @param data The new buffer.
* @param length The length of the new buffer.
* @throw IOException
*/
void setData(const atUint8* data, atUint64 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.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
/*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
protected:
std::unique_ptr<atUint8[]> m_dataCopy;
std::unique_ptr<atUint8[]> m_dataCopy;
private:
void resize(atUint64 newSize);
void resize(atUint64 newSize);
};
}
} // namespace athena::io

View File

@@ -5,54 +5,51 @@
#include "athena/Stream.hpp"
#include <physfs.h>
namespace athena::io
{
class PHYSFSFileReader : public Stream
{
namespace athena::io {
class PHYSFSFileReader : public Stream {
public:
PHYSFSFileReader(const std::string& path);
PHYSFSFileReader(const std::string& path);
void setEndian(Endian);
Endian endian() const;
bool isBigEndian() const;
bool isLittleEndian() const;
atUint8* data();
void setEndian(Endian);
Endian endian() const;
bool isBigEndian() const;
bool isLittleEndian() const;
atUint8* data();
atUint64 length() const;
atUint64 length() const;
atUint64 position() const;
atUint64 position() const;
bool isOpen() const;
bool isOpen() const;
void seek(atInt64 position, SeekOrigin origin);
atInt8 readByte();
atUint8 readUByte();
atUint8* readUBytes(atUint64 length);
atInt8* readBytes(atUint64 length);
atUint16 readUint16();
atInt16 readInt16();
atUint32 readUint32();
atInt32 readInt32();
atUint64 readUint64();
atInt64 readInt64();
double readDouble();
float readFloat();
bool readBool();
void seek(atInt64 position, SeekOrigin origin);
atInt8 readByte();
atUint8 readUByte();
atUint8* readUBytes(atUint64 length);
atInt8* readBytes(atUint64 length);
atUint16 readUint16();
atInt16 readInt16();
atUint32 readUint32();
atInt32 readInt32();
atUint64 readUint64();
atInt64 readInt64();
double readDouble();
float readFloat();
bool readBool();
bool atEnd() const;
bool atEnd() const;
// TODO: Strings
// TODO: Strings
private:
Endian m_endian;
std::string m_path;
atUint64 m_length;
PHYSFS_File* m_handle;
Endian m_endian;
std::string m_path;
atUint64 m_length;
PHYSFS_File* m_handle;
};
}
} // namespace athena::io
#ifndef PHYSFSFILEREADER_BASE
#define PHYSFSFILEREADER_BASE() \
typedef athena::io::PHYSFSFileReader base
#define PHYSFSFILEREADER_BASE() typedef athena::io::PHYSFSFileReader base
#endif
#endif // PHYSFSSTREAM_HPP
#endif // ATHENA_ENABLE_PHYSFS

View File

@@ -2,29 +2,18 @@
#include "athena/Global.hpp"
namespace athena::Sakura
{
namespace athena::Sakura {
template <typename T>
class Vector2D
{
class Vector2D {
public:
T x;
T y;
T x;
T y;
Vector2D()
: x(0),
y(0)
{
}
Vector2D() : x(0), y(0) {}
Vector2D(T x, T y)
: x(x),
y(y)
{
}
Vector2D(T x, T y) : x(x), y(y) {}
};
typedef Vector2D<int> Vector2Di;
typedef Vector2D<float> Vector2Df;
} // Sakura
} // namespace athena::Sakura

View File

@@ -5,43 +5,31 @@
// standard lib
#include <vector>
namespace athena
{
namespace athena {
class SkywardSwordQuest;
enum class Region
{
NTSC,
NTSCJ,
PAL
};
enum class Region { NTSC, NTSCJ, PAL };
class SkywardSwordFile
{
class SkywardSwordFile {
public:
enum MagicNumbers
{
USMagic = 0x534F5545,
JAMagic = 0x534F554A,
EUMagic = 0x534F5550
};
enum MagicNumbers { USMagic = 0x534F5545, JAMagic = 0x534F554A, EUMagic = 0x534F5550 };
SkywardSwordFile();
SkywardSwordFile(std::vector<SkywardSwordQuest*> quests);
~SkywardSwordFile();
SkywardSwordFile();
SkywardSwordFile(std::vector<SkywardSwordQuest*> quests);
~SkywardSwordFile();
void addQuest(SkywardSwordQuest* q);
SkywardSwordQuest* quest(atUint32 id);
std::vector<SkywardSwordQuest*> questList() const;
void addQuest(SkywardSwordQuest* q);
SkywardSwordQuest* quest(atUint32 id);
std::vector<SkywardSwordQuest*> questList() const;
void setRegion(Region region);
Region region() const;
void setRegion(Region region);
Region region() const;
private:
Region m_region;
// A vector is a bit overkill
std::vector<SkywardSwordQuest*> m_quests;
atUint32 m_numQuests;
Region m_region;
// A vector is a bit overkill
std::vector<SkywardSwordQuest*> m_quests;
atUint32 m_numQuests;
};
}
} // namespace athena

View File

@@ -2,19 +2,15 @@
#include "athena/MemoryReader.hpp"
namespace athena
{
namespace athena {
class SkywardSwordFile;
namespace io
{
class SkywardSwordFileReader : public MemoryCopyReader
{
namespace io {
class SkywardSwordFileReader : public MemoryCopyReader {
public:
SkywardSwordFileReader(atUint8* data, atUint64 length);
SkywardSwordFileReader(const std::string& filename);
SkywardSwordFileReader(atUint8* data, atUint64 length);
SkywardSwordFileReader(const std::string& filename);
SkywardSwordFile* read();
SkywardSwordFile* read();
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -2,20 +2,17 @@
#include "athena/MemoryWriter.hpp"
namespace athena
{
namespace athena {
class SkywardSwordFile;
namespace io
{
namespace io {
class SkywardSwordFileWriter : public MemoryCopyWriter
{
class SkywardSwordFileWriter : public MemoryCopyWriter {
public:
SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(const std::string& filename);
SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(const std::string& filename);
void write(SkywardSwordFile* file);
void write(SkywardSwordFile* file);
};
}
}
} // namespace io
} // namespace athena

View File

@@ -4,55 +4,48 @@
#include "athena/Global.hpp"
#include "athena/ZQuestFile.hpp"
namespace athena
{
namespace athena {
// TODO: Handle game specific data
class SkywardSwordQuest : public ZQuestFile
{
class SkywardSwordQuest : public ZQuestFile {
public:
enum AmmoType
{
Arrows,
Bombs,
Seeds
};
enum AmmoType { Arrows, Bombs, Seeds };
SkywardSwordQuest(std::unique_ptr<atUint8[]>&& data, atUint32 len);
SkywardSwordQuest(std::unique_ptr<atUint8[]>&& data, atUint32 len);
void setPlayerName(const std::string& name);
std::string playerName() const;
void setPlayerName(const std::string& name);
std::string playerName() const;
void setRupeeCount(atUint16 value);
atUint16 rupeeCount();
void setAmmoCount(AmmoType type, atUint32 count);
atUint32 ammoCount(AmmoType type);
void setMaxHP(atUint16 val);
atUint16 maxHP();
float maxHearts();
void setSpawnHP(atUint16 val);
atUint16 spawnHP();
float spawnHearts();
void setCurrentHP(atUint16 val);
atUint16 currentHP();
float currentHearts();
std::string currentLocation();
std::string currentArea();
std::string currentLocationCopy();
void setRupeeCount(atUint16 value);
atUint16 rupeeCount();
void setAmmoCount(AmmoType type, atUint32 count);
atUint32 ammoCount(AmmoType type);
void setMaxHP(atUint16 val);
atUint16 maxHP();
float maxHearts();
void setSpawnHP(atUint16 val);
atUint16 spawnHP();
float spawnHearts();
void setCurrentHP(atUint16 val);
atUint16 currentHP();
float currentHearts();
std::string currentLocation();
std::string currentArea();
std::string currentLocationCopy();
void setSkipData(std::unique_ptr<atUint8[]>&& data);
atUint8* skipData() const;
void setSkipData(std::unique_ptr<atUint8[]>&& data);
atUint8* skipData() const;
atUint32 slotChecksum();
atUint32 skipChecksum();
void fixChecksums();
atUint32 slotChecksum();
atUint32 skipChecksum();
void fixChecksums();
void setNew(bool isNew);
bool isNew() const;
void setNew(bool isNew);
bool isNew() const;
private:
std::unique_ptr<atUint8[]> m_skipData;
std::unique_ptr<atUint8[]> m_skipData;
};
} // Athena
} // namespace athena
#endif // SSQUEST_HPP

View File

@@ -14,89 +14,71 @@ typedef UINT_PTR SOCKET;
struct sockaddr_in;
namespace athena::net
{
namespace athena::net {
/** IP address class derived from SFML */
class IPAddress
{
uint32_t m_address = 0;
bool m_valid = false;
class IPAddress {
uint32_t m_address = 0;
bool m_valid = false;
void resolve(const std::string& address);
void resolve(const std::string& address);
public:
IPAddress(const std::string& address)
{
resolve(address);
}
IPAddress(const std::string& address) { resolve(address); }
uint32_t toInteger() const;
operator bool() const { return m_valid; }
uint32_t toInteger() const;
operator bool() const { return m_valid; }
};
/** Server-oriented TCP socket class derived from SFML */
class Socket
{
class Socket {
#ifndef _WIN32
using SocketTp = int;
using SocketTp = int;
#else
using SocketTp = SOCKET;
using SocketTp = SOCKET;
#endif
SocketTp m_socket = -1;
bool m_isBlocking;
SocketTp m_socket = -1;
bool m_isBlocking;
bool openSocket();
void setRemoteSocket(int remSocket);
bool openSocket();
void setRemoteSocket(int remSocket);
public:
enum class EResult
{
OK,
Error,
Busy
};
enum class EResult { OK, Error, Busy };
#ifdef _WIN32
static EResult LastWSAError();
static EResult LastWSAError();
#endif
Socket(bool blocking)
: m_isBlocking(blocking) {}
~Socket() { close(); }
Socket(bool blocking) : m_isBlocking(blocking) {}
~Socket() { close(); }
Socket(const Socket& other) = delete;
Socket& operator=(const Socket& other) = delete;
Socket(Socket&& other)
: m_socket(other.m_socket), m_isBlocking(other.m_isBlocking)
{
other.m_socket = -1;
}
Socket& operator=(Socket&& other)
{
close();
m_socket = other.m_socket;
other.m_socket = -1;
m_isBlocking = other.m_isBlocking;
return *this;
}
Socket(const Socket& other) = delete;
Socket& operator=(const Socket& other) = delete;
Socket(Socket&& other) : m_socket(other.m_socket), m_isBlocking(other.m_isBlocking) { other.m_socket = -1; }
Socket& operator=(Socket&& other) {
close();
m_socket = other.m_socket;
other.m_socket = -1;
m_isBlocking = other.m_isBlocking;
return *this;
}
void setBlocking(bool blocking);
bool isOpen() const { return m_socket != -1; }
bool openAndListen(const IPAddress& address, uint32_t port);
EResult accept(Socket& remoteSocketOut, sockaddr_in& fromAddress);
EResult accept(Socket& remoteSocketOut);
EResult accept(Socket& remoteSocketOut, std::string& fromHostname);
void close();
EResult send(const void* buf, size_t len, size_t& transferred);
EResult send(const void* buf, size_t len);
EResult recv(void* buf, size_t len, size_t& transferred);
EResult recv(void* buf, size_t len);
void setBlocking(bool blocking);
bool isOpen() const { return m_socket != -1; }
bool openAndListen(const IPAddress& address, uint32_t port);
EResult accept(Socket& remoteSocketOut, sockaddr_in& fromAddress);
EResult accept(Socket& remoteSocketOut);
EResult accept(Socket& remoteSocketOut, std::string& fromHostname);
void close();
EResult send(const void* buf, size_t len, size_t& transferred);
EResult send(const void* buf, size_t len);
EResult recv(void* buf, size_t len, size_t& transferred);
EResult recv(void* buf, size_t len);
operator bool() const { return isOpen(); }
operator bool() const { return isOpen(); }
SocketTp GetInternalSocket() const { return m_socket; }
SocketTp GetInternalSocket() const { return m_socket; }
};
}
} // namespace athena::net

View File

@@ -4,67 +4,65 @@
#include <string>
#include "athena/SakuraGlobal.hpp"
namespace athena::Sakura
{
namespace athena::Sakura {
class SpriteFile;
class SpriteFrame;
class Sprite
{
class Sprite {
public:
Sprite(SpriteFile* root);
Sprite(SpriteFile* root, const std::string& name);
virtual ~Sprite();
Sprite(SpriteFile* root);
Sprite(SpriteFile* root, const std::string& name);
virtual ~Sprite();
virtual void setPosition(const float x, const float y);
virtual void setPosition(const Vector2Df& pos);
virtual Vector2Df position() const;
void setName(const std::string& name);
std::string name() const;
virtual void setPosition(const float x, const float y);
virtual void setPosition(const Vector2Df& pos);
virtual Vector2Df position() const;
void setName(const std::string& name);
std::string name() const;
void addStateId(int id);
void addStateId(int id);
/*!
* \brief Returns the texture id of a given state
* \param index The index of the id.
* \return return the state id if it exists, -1 otherwise
*/
int stateId(int index) const;
void setStateIds(std::vector<int> ids);
std::vector<int> stateIds() const;
atUint32 stateCount() const;
void setCurrentState(atUint32 id);
atUint32 currentState() const;
/*!
* \brief Returns the texture id of a given state
* \param index The index of the id.
* \return return the state id if it exists, -1 otherwise
*/
int stateId(int index) const;
void setStateIds(std::vector<int> ids);
std::vector<int> stateIds() const;
atUint32 stateCount() const;
void setCurrentState(atUint32 id);
atUint32 currentState() const;
bool addFrame(SpriteFrame* Frame);
bool removeFrame(SpriteFrame* Frame);
SpriteFrame* Frame(atUint32 id);
void setFrame(atUint32 id);
void setFrames(std::vector<SpriteFrame*> frames);
atUint32 frameCount() const;
bool addFrame(SpriteFrame* Frame);
bool removeFrame(SpriteFrame* Frame);
SpriteFrame* Frame(atUint32 id);
void setFrame(atUint32 id);
void setFrames(std::vector<SpriteFrame*> frames);
atUint32 frameCount() const;
std::vector<SpriteFrame*> frames() const;
std::vector<SpriteFrame*> frames() const;
SpriteFile* container() const;
SpriteFile* container() const;
void setCurrentFrame(SpriteFrame* frame);
void setCurrentFrame(atUint32 id);
SpriteFrame* currentFrame() const;
void setCurrentFrame(SpriteFrame* frame);
void setCurrentFrame(atUint32 id);
SpriteFrame* currentFrame() const;
void advanceFrame();
void retreatFrame();
void advanceFrame();
void retreatFrame();
void setRoot(SpriteFile* root);
SpriteFile* root() const;
void setRoot(SpriteFile* root);
SpriteFile* root() const;
private:
SpriteFile* m_root;
std::string m_name;
Vector2Df m_position;
std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<SpriteFrame*> m_frames;
atUint32 m_currentState;
atUint32 m_currentFrame;
SpriteFile* m_root;
std::string m_name;
Vector2Df m_position;
std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<SpriteFrame*> m_frames;
atUint32 m_currentState;
atUint32 m_currentFrame;
};
} // zelda
} // namespace athena::Sakura

View File

@@ -7,74 +7,71 @@
#include <string>
#include "athena/SakuraGlobal.hpp"
namespace athena::Sakura
{
struct STexture
{
std::string Filepath;
bool Preload;
namespace athena::Sakura {
struct STexture {
std::string Filepath;
bool Preload;
};
class Sprite;
class SpriteFile
{
class SpriteFile {
public:
/*!
* \brief Major
*/
static const atUint32 Major;
/*!
* \brief Major
*/
static const atUint32 Major;
/*!
* \brief Minor
*/
static const atUint32 Minor;
/*!
* \brief Minor
*/
static const atUint32 Minor;
/*!
* \brief Revision
*/
static const atUint32 Revision;
/*!
* \brief Revision
*/
static const atUint32 Revision;
/*!
* \brief Patch
*/
static const atUint32 Build;
/*!
* \brief Patch
*/
static const atUint32 Build;
/*!
* \brief Version
*/
static const atUint32 Version;
/*!
* \brief Version
*/
static const atUint32 Version;
/*!
* \brief Magic
*/
static const atUint32 Magic;
/*!
* \brief Magic
*/
static const atUint32 Magic;
/*!
* \brief SSprite
*/
SpriteFile();
/*!
* \brief SSprite
*/
SpriteFile();
/*!
* \brief SSpriteFile
* \param width
* \param height
* \param originX
* \param originY
*/
SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
/*!
* \brief SSpriteFile
* \param width
* \param height
* \param originX
* \param originY
*/
SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
/*!
* \brief SSpriteFile
* \param size
* \param origin
*/
/*!
* \brief SSpriteFile
* \param size
* \param origin
*/
#ifndef ATHENA_USE_QT
SpriteFile(const Vector2Di& size, const Vector2Df& origin);
SpriteFile(const Vector2Di& size, const Vector2Df& origin);
#else
SpriteFile(const QSize& size, const QPoint& origin);
SpriteFile(const QSize& size, const QPoint& origin);
#endif
~SpriteFile();
~SpriteFile();
#ifndef ATHENA_USE_QT
public:
@@ -82,113 +79,112 @@ public:
public slots:
#endif
/*!
* \brief setSize
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
/*!
* \brief setSize
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
/*!
* \brief setSize
* \param size
*/
void setSize(const Vector2Di& size);
/*!
* \brief setSize
* \param size
*/
void setSize(const Vector2Di& size);
/*!
* \brief size
* \return
*/
Vector2Di size() const;
/*!
* \brief size
* \return
*/
Vector2Di size() const;
/*!
* \brief width
* \return
*/
atUint32 width() const;
/*!
* \brief width
* \return
*/
atUint32 width() const;
/*!
* \brief height
* \return
*/
atUint32 height() const;
/*!
* \brief height
* \return
*/
atUint32 height() const;
/*!
* \brief setOrigin
* \param x
* \param y
*/
void setOrigin(const float x, const float y);
/*!
* \brief setOrigin
* \param x
* \param y
*/
void setOrigin(const float x, const float y);
/*!
* \brief setOrigin
* \param origin
*/
void setOrigin(const Vector2Df& origin);
/*!
* \brief setOrigin
* \param origin
*/
void setOrigin(const Vector2Df& origin);
/*!
* \brief origin
* \return
*/
Vector2Df origin() const;
/*!
* \brief origin
* \return
*/
Vector2Df origin() const;
/*!
* \brief originX
* \return
*/
float originX() const;
/*!
* \brief originX
* \return
*/
float originX() const;
/*!
* \brief originY
* \return
*/
float originY() const;
/*!
* \brief originY
* \return
*/
float originY() const;
/*!
* \brief addTexture
* \param texture
*/
bool addTexture(STexture* texture);
/*!
* \brief addTexture
* \param texture
*/
bool addTexture(STexture* texture);
/*!
* \brief removeTexture
* \param id
*/
void removeTexture(int id);
/*!
* \brief removeTexture
* \param id
*/
void removeTexture(int id);
/*!
* \brief texture
* \param id
* \return
*/
STexture* texture(atUint32 id);
std::vector<STexture*> textures() const;
/*!
* \brief texture
* \param id
* \return
*/
STexture* texture(atUint32 id);
std::vector<STexture*> textures() const;
atUint32 textureCount() const;
/*!
* \brief setTextures
* \param textures
*/
void setTextures(std::vector<STexture*> textures);
atUint32 textureCount() const;
/*!
* \brief setTextures
* \param textures
*/
void setTextures(std::vector<STexture*> textures);
void addSprite(Sprite* sprite);
void addSprite(Sprite* sprite);
void removeSprite(const std::string& name);
void removeSprite(Sprite* sprite);
void removeSprite(const std::string& name);
void removeSprite(Sprite* sprite);
void setSprites(std::unordered_map<std::string, Sprite*> sprites);
Sprite* sprite(const std::string& name);
std::unordered_map<std::string, Sprite*> sprites() const;
void setSprites(std::unordered_map<std::string, Sprite*> sprites);
Sprite* sprite(const std::string& name);
std::unordered_map<std::string, Sprite*> sprites() const;
atUint32 spriteCount() const;
atUint32 spriteCount() const;
private:
std::vector<STexture*> m_textures;
Vector2Di m_size;
Vector2Df m_origin;
std::unordered_map<std::string, Sprite*> m_sprites;
std::vector<STexture*> m_textures;
Vector2Di m_size;
Vector2Df m_origin;
std::unordered_map<std::string, Sprite*> m_sprites;
};
} // Zelda
} // namespace athena::Sakura
#endif // SSPRITE_HPP

View File

@@ -2,25 +2,19 @@
#include "athena/MemoryReader.hpp"
namespace athena::Sakura
{
namespace athena::Sakura {
class SpriteFile;
} // Sakura
} // namespace athena::Sakura
namespace athena
{
namespace io
{
namespace athena {
namespace io {
class SpriteFileReader : public MemoryCopyReader
{
class SpriteFileReader : public MemoryCopyReader {
public:
SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(const std::string& filepath);
SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(const std::string& filepath);
Sakura::SpriteFile* readFile();
Sakura::SpriteFile* readFile();
};
}
} // zelda
} // namespace io
} // namespace athena

View File

@@ -2,25 +2,21 @@
#include "athena/MemoryWriter.hpp"
namespace athena
{
namespace Sakura
{
namespace athena {
namespace Sakura {
class SpriteFile;
} // Sakura
} // namespace Sakura
namespace io
{
namespace io {
class SpriteFileWriter : public MemoryCopyWriter
{
class SpriteFileWriter : public MemoryCopyWriter {
public:
SpriteFileWriter(atUint8* data, atUint64 length);
SpriteFileWriter(atUint8* data, atUint64 length);
SpriteFileWriter(std::string_view filepath);
SpriteFileWriter(std::string_view filepath);
void writeFile(Sakura::SpriteFile* file);
void writeFile(Sakura::SpriteFile* file);
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -1,49 +1,45 @@
#pragma once
#include "athena/SakuraGlobal.hpp"
#include <vector>
namespace athena::Sakura
{
namespace athena::Sakura {
class Sprite;
class SpritePart;
class SpriteFrame
{
class SpriteFrame {
public:
/*!
* \brief SSpriteFrame
*/
SpriteFrame();
/*!
* \brief SSpriteFrame
*/
SpriteFrame();
SpriteFrame(Sprite* root);
/*!
* \brief setFrameTime
* \param frameTime
*/
void setFrameTime(float frameTime);
SpriteFrame(Sprite* root);
/*!
* \brief setFrameTime
* \param frameTime
*/
void setFrameTime(float frameTime);
/*!
* \brief frameTime
* \return
*/
float frameTime() const;
/*!
* \brief frameTime
* \return
*/
float frameTime() const;
void setParts(std::vector<SpritePart*> parts);
std::vector<SpritePart*> parts() const;
void setParts(std::vector<SpritePart*> parts);
std::vector<SpritePart*> parts() const;
atUint32 partCount() const;
atUint32 partCount() const;
void setRoot(Sprite* root);
Sprite* root() const;
void setRoot(Sprite* root);
Sprite* root() const;
private:
Sprite* m_root;
float m_frameTime;
std::vector<SpritePart*> m_parts;
Sprite* m_root;
float m_frameTime;
std::vector<SpritePart*> m_parts;
};
} // zelda
} // namespace athena::Sakura

View File

@@ -5,110 +5,106 @@
#include <string>
namespace athena::Sakura
{
namespace athena::Sakura {
class SpriteFrame;
class SpritePart
{
class SpritePart {
public:
SpritePart(SpriteFrame* root);
SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false);
virtual ~SpritePart();
SpritePart(SpriteFrame* root);
SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false);
virtual ~SpritePart();
void setName(const std::string& name);
std::string name() const;
void setCollision(bool col);
bool hasCollision() const;
void setName(const std::string& name);
std::string name() const;
void setCollision(bool col);
bool hasCollision() const;
/*!
* \brief setOffset
* \param x
* \param y
*/
void setOffset(float x, float y);
void setOffset(const Vector2Df& offset);
/*!
* \brief setOffset
* \param x
* \param y
*/
void setOffset(float x, float y);
void setOffset(const Vector2Df& offset);
/*!
* \brief offset
* \return
*/
Vector2Df offset() const;
/*!
* \brief offset
* \return
*/
Vector2Df offset() const;
/*!
* \brief setTextureOffset
* \param x
* \param y
*/
void setTextureOffset(float x, float y);
/*!
* \brief setTextureOffset
* \param x
* \param y
*/
void setTextureOffset(float x, float y);
/*!
* \brief setTextureOffset
* \param texOff
*/
void setTextureOffset(const Vector2Df& offset);
/*!
* \brief setTextureOffset
* \param texOff
*/
void setTextureOffset(const Vector2Df& offset);
/*!
* \brief textureOffset
* \return
*/
Vector2Df textureOffset() const;
/*!
* \brief setSize
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
/*!
* \brief textureOffset
* \return
*/
Vector2Df textureOffset() const;
/*!
* \brief setSize
* \param width
* \param height
*/
void setSize(atUint32 width, atUint32 height);
/*!
* \brief setSize
* \param size
*/
void setSize(const Vector2Di& size);
/*!
* \brief size
* \return
*/
Vector2Di size() const;
/*!
* \brief setSize
* \param size
*/
void setSize(const Vector2Di& size);
/*!
* \brief size
* \return
*/
Vector2Di size() const;
/*!
* \brief setFlippedHorizontally
* \param val
*/
void setFlippedHorizontally(const bool val);
/*!
* \brief setFlippedHorizontally
* \param val
*/
void setFlippedHorizontally(const bool val);
/*!
* \brief flippedHorizontally
* \return
*/
bool flippedHorizontally() const;
/*!
* \brief flippedHorizontally
* \return
*/
bool flippedHorizontally() const;
/*!
* \brief setFlippedVertically
* \param val
*/
void setFlippedVertically(const bool val);
/*!
* \brief setFlippedVertically
* \param val
*/
void setFlippedVertically(const bool val);
/*!
* \brief flippedVertically
* \return
*/
bool flippedVertically() const;
void setRoot(SpriteFrame* root);
SpriteFrame* root() const;
/*!
* \brief flippedVertically
* \return
*/
bool flippedVertically() const;
void setRoot(SpriteFrame* root);
SpriteFrame* root() const;
private:
SpriteFrame* m_root;
std::string m_name;
bool m_hasCollision;
Vector2Df m_offset;
Vector2Df m_textureOffset;
Vector2Di m_size;
bool m_flippedH;
bool m_flippedV;
atUint32 m_frameIndex;
SpriteFrame* m_root;
std::string m_name;
bool m_hasCollision;
Vector2Df m_offset;
Vector2Df m_textureOffset;
Vector2Di m_size;
bool m_flippedH;
bool m_flippedV;
atUint32 m_frameIndex;
};
}
} // namespace athena::Sakura

View File

@@ -13,23 +13,34 @@ using atUint64 = uint64_t;
// Vector types
#include "simd/simd.hpp"
typedef struct { athena::simd<float> simd; } atVec2f;
typedef struct { athena::simd<float> simd; } atVec3f;
typedef struct { athena::simd<float> simd; } atVec4f;
typedef struct { athena::simd<double> simd; } atVec2d;
typedef struct { athena::simd<double> simd; } atVec3d;
typedef struct { athena::simd<double> simd; } atVec4d;
typedef struct {
athena::simd<float> simd;
} atVec2f;
typedef struct {
athena::simd<float> simd;
} atVec3f;
typedef struct {
athena::simd<float> simd;
} atVec4f;
typedef struct {
athena::simd<double> simd;
} atVec2d;
typedef struct {
athena::simd<double> simd;
} atVec3d;
typedef struct {
athena::simd<double> simd;
} atVec4d;
#ifndef UNUSED
#define UNUSED(x) ((void)x)
#endif // UNUSED
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
#define DEPRECATED(func) func __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif

View File

@@ -9,190 +9,165 @@
#include "athena/Global.hpp"
#include "athena/Types.hpp"
namespace athena::utility
{
inline bool isEmpty(atInt8* buf, atUint32 size) {return !memcmp(buf, buf + 1, size - 1);}
namespace athena::utility {
inline bool isEmpty(atInt8* buf, atUint32 size) { return !memcmp(buf, buf + 1, size - 1); }
#if _WIN32
constexpr bool isSystemBigEndian() {return false;}
constexpr bool isSystemBigEndian() { return false; }
#else
constexpr bool isSystemBigEndian() {return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__;}
constexpr bool isSystemBigEndian() { return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; }
#endif
inline constexpr ::athena::Endian SystemEndian = isSystemBigEndian() ? Big : Little;
inline constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? Little : Big;
inline atInt16 swap16(atInt16 val)
{
inline atInt16 swap16(atInt16 val) {
#if __GNUC__
return __builtin_bswap16(val);
return __builtin_bswap16(val);
#elif _WIN32
return _byteswap_ushort(val);
return _byteswap_ushort(val);
#else
return (val = (val << 8) | ((val >> 8) & 0xFF));
return (val = (val << 8) | ((val >> 8) & 0xFF));
#endif
}
inline atUint16 swapU16(atUint16 val) {return (atUint16)swap16(val);}
inline atInt32 swap32(atInt32 val)
{
inline atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
inline atInt32 swap32(atInt32 val) {
#if __GNUC__
return __builtin_bswap32(val);
return __builtin_bswap32(val);
#elif _WIN32
return _byteswap_ulong(val);
return _byteswap_ulong(val);
#else
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
return val;
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
return val;
#endif
}
inline atUint32 swapU32(atUint32 val) {return (atUint32)swap32(val);}
inline atInt64 swap64(atInt64 val)
{
inline atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
inline atInt64 swap64(atInt64 val) {
#if __GNUC__
return __builtin_bswap64(val);
return __builtin_bswap64(val);
#elif _WIN32
return _byteswap_uint64(val);
return _byteswap_uint64(val);
#else
return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) |
(((atInt64)(val) & 0x00FF000000000000ULL) >> 40) |
(((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) |
(((atInt64)(val) & 0x000000FF00000000ULL) >> 8) |
(((atInt64)(val) & 0x00000000FF000000ULL) << 8) |
(((atInt64)(val) & 0x0000000000FF0000ULL) << 24) |
(((atInt64)(val) & 0x000000000000FF00ULL) << 40) |
(((atInt64)(val) & 0x00000000000000FFULL) << 56))));
return (val = ((atInt64)(
(((atInt64)(val)&0xFF00000000000000ULL) >> 56) | (((atInt64)(val)&0x00FF000000000000ULL) >> 40) |
(((atInt64)(val)&0x0000FF0000000000ULL) >> 24) | (((atInt64)(val)&0x000000FF00000000ULL) >> 8) |
(((atInt64)(val)&0x00000000FF000000ULL) << 8) | (((atInt64)(val)&0x0000000000FF0000ULL) << 24) |
(((atInt64)(val)&0x000000000000FF00ULL) << 40) | (((atInt64)(val)&0x00000000000000FFULL) << 56))));
#endif
}
inline atUint64 swapU64(atUint64 val) {return (atUint64)swap64(val);}
inline float swapFloat(float val)
{
atInt32 ival = swap32(*((atInt32*)(&val)));
return *((float*)(&ival));
inline atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
inline float swapFloat(float val) {
atInt32 ival = swap32(*((atInt32*)(&val)));
return *((float*)(&ival));
}
inline double swapDouble(double val)
{
atInt64 ival = swap64(*((atInt64*)(&val)));
return *((double*)(&ival));
inline double swapDouble(double val) {
atInt64 ival = swap64(*((atInt64*)(&val)));
return *((double*)(&ival));
}
inline atInt16 LittleInt16(atInt16& val)
{
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
inline atInt16 LittleInt16(atInt16& val) {
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
return val;
return val;
}
inline atUint16 LittleUint16(atUint16& val)
{
atInt16 ret = val;
LittleInt16(ret);
val = ret;
inline atUint16 LittleUint16(atUint16& val) {
atInt16 ret = val;
LittleInt16(ret);
val = ret;
return val;
return val;
}
inline atInt16 BigInt16(atInt16& val)
{
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
inline atInt16 BigInt16(atInt16& val) {
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap16(val);
return val;
return val;
}
inline atUint16 BigUint16(atUint16& val)
{
atInt16 ret = val;
BigInt16(ret);
val = ret;
inline atUint16 BigUint16(atUint16& val) {
atInt16 ret = val;
BigInt16(ret);
val = ret;
return val;
return val;
}
inline atInt32 LittleInt32(atInt32& val)
{
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
inline atInt32 LittleInt32(atInt32& val) {
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
return val;
return val;
}
inline atUint32 LittleUint32(atUint32& val)
{
atInt32 ret = val;
LittleInt32(ret);
val = ret;
inline atUint32 LittleUint32(atUint32& val) {
atInt32 ret = val;
LittleInt32(ret);
val = ret;
return val;
return val;
}
inline atInt32 BigInt32(atInt32& val)
{
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
inline atInt32 BigInt32(atInt32& val) {
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap32(val);
return val;
return val;
}
inline atUint32 BigUint32(atUint32& val)
{
atInt32 ret = val;
BigInt32(ret);
val = ret;
inline atUint32 BigUint32(atUint32& val) {
atInt32 ret = val;
BigInt32(ret);
val = ret;
return val;
return val;
}
inline atInt64 LittleInt64(atInt64& val)
{
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
inline atInt64 LittleInt64(atInt64& val) {
if (athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
return val;
return val;
}
inline atUint64 LittleUint64(atUint64& val)
{
atInt64 ret = val;
LittleInt64(ret);
val = ret;
inline atUint64 LittleUint64(atUint64& val) {
atInt64 ret = val;
LittleInt64(ret);
val = ret;
return val;
return val;
}
inline atInt64 BigInt64(atInt64& val)
{
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
inline atInt64 BigInt64(atInt64& val) {
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swap64(val);
return val;
return val;
}
inline atUint64 BigUint64(atUint64& val)
{
atInt64 ret = val;
BigInt64(ret);
val = ret;
inline atUint64 BigUint64(atUint64& val) {
atInt64 ret = val;
BigInt64(ret);
val = ret;
return val;
return val;
}
inline float LittleFloat(float val)
{
if (athena::utility::isSystemBigEndian())
val = athena::utility::swapFloat(val);
inline float LittleFloat(float val) {
if (athena::utility::isSystemBigEndian())
val = athena::utility::swapFloat(val);
return val;
return val;
}
inline float BigFloat(float val)
{
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swapFloat(val);
inline float BigFloat(float val) {
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swapFloat(val);
return val;
return val;
}
inline double LittleDouble(double val)
{
if (athena::utility::isSystemBigEndian())
val = athena::utility::swapDouble(val);
inline double LittleDouble(double val) {
if (athena::utility::isSystemBigEndian())
val = athena::utility::swapDouble(val);
return val;
return val;
}
inline double BigDouble(double val)
{
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swapDouble(val);
inline double BigDouble(double val) {
if (!athena::utility::isSystemBigEndian())
val = athena::utility::swapDouble(val);
return val;
return val;
}
void fillRandom(atUint8 * rndArea, atUint64 count);
void fillRandom(atUint8* rndArea, atUint64 count);
std::vector<std::string> split(std::string_view s, char delim);
atUint64 rand64();
std::string join(const std::vector<std::string>& elems, std::string_view delims);
@@ -221,5 +196,5 @@ std::string wideToUtf8(std::wstring_view src);
std::wstring utf8ToWide(std::string_view src);
} // Athena
} // namespace athena::utility
#endif

View File

@@ -6,8 +6,7 @@
#include <vector>
#include "athena/IStreamWriter.hpp"
namespace athena::io
{
namespace athena::io {
/*! @class VectorWriter
* @brief A Stream class for writing data to a STL vector
@@ -16,46 +15,44 @@ namespace athena::io
* all work is done using a std::vector, and not written directly to the disk
* @sa Stream
*/
class VectorWriter : public IStreamWriter
{
class VectorWriter : public IStreamWriter {
public:
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_data.size(); }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_data.size(); }
inline bool isOpen() const { return true; }
inline bool isOpen() const { return true; }
/*! @brief Obtains reference to underlying std::vector store */
const std::vector<uint8_t>& data() const { return m_data; }
/*! @brief Obtains reference to underlying std::vector store */
const std::vector<uint8_t>& data() const { return m_data; }
/*! @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.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
/*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
protected:
std::vector<uint8_t> m_data;
atUint64 m_position = 0;
std::vector<uint8_t> m_data;
atUint64 m_position = 0;
};
}
} // namespace athena::io

View File

@@ -4,172 +4,165 @@
#include <string>
#include "athena/Global.hpp"
namespace athena
{
namespace athena {
class WiiImage;
/*! \class WiiBanner
* \brief Wii banner container class
*
* Contains all relevant data for a Wii banner.
*/
class WiiBanner
{
class WiiBanner {
public:
enum
{
NoCopy = 0x00000001,
Bounce = 0x00000010,
NoCopyBounce = NoCopy | Bounce
};
enum { NoCopy = 0x00000001, Bounce = 0x00000010, NoCopyBounce = NoCopy | Bounce };
/*!
* \brief WiiBanner
*/
WiiBanner();
/*!
* \brief WiiBanner
* \param gameId
* \param title
* \param subtitle
* \param m_banner
* \param icons
*/
WiiBanner(atUint32 gameId, const std::u16string& title, const std::u16string& subtitle,
WiiImage* m_banner, std::vector<WiiImage*> icons);
virtual ~WiiBanner();
/*!
* \brief WiiBanner
*/
WiiBanner();
/*!
* \brief WiiBanner
* \param gameId
* \param title
* \param subtitle
* \param m_banner
* \param icons
*/
WiiBanner(atUint32 gameId, const std::u16string& title, const std::u16string& subtitle, WiiImage* m_banner,
std::vector<WiiImage*> icons);
virtual ~WiiBanner();
/*!
* \brief setGameID
* \param id
*/
void setGameID(atUint64 id);
/*!
* \brief setGameID
* \param id
*/
void setGameID(atUint64 id);
/*!
* \brief gameID
* \return
*/
atUint64 gameID() const;
/*!
* \brief gameID
* \return
*/
atUint64 gameID() const;
/*!
* \brief setBannerImage
* \param banner
*/
void setBannerImage(WiiImage* banner);
/*!
* \brief setBannerImage
* \param banner
*/
void setBannerImage(WiiImage* banner);
/*!
* \brief bannerImage
* \return
*/
WiiImage* bannerImage() const;
/*!
* \brief bannerImage
* \return
*/
WiiImage* bannerImage() const;
/*!
* \brief setBannerSize
* \param size
*/
void setBannerSize(atUint32 size);
/*!
* \brief setBannerSize
* \param size
*/
void setBannerSize(atUint32 size);
/*!
* \brief bannerSize
* \return
*/
atUint32 bannerSize() const;
/*!
* \brief bannerSize
* \return
*/
atUint32 bannerSize() const;
/*!
* \brief setTitle
* \param title
*/
void setTitle(const std::u16string& title);
/*!
* \brief setTitle
* \param title
*/
void setTitle(const std::u16string& title);
/*!
* \brief title
* \return
*/
const std::u16string& title() const;
/*!
* \brief title
* \return
*/
const std::u16string& title() const;
/*!
* \brief setSubtitle
* \param subtitle
*/
void setSubtitle(const std::u16string& subtitle);
/*!
* \brief setSubtitle
* \param subtitle
*/
void setSubtitle(const std::u16string& subtitle);
/*!
* \brief subtitle
* \return
*/
const std::u16string& subtitle() const;
/*!
* \brief subtitle
* \return
*/
const std::u16string& subtitle() const;
/*!
* \brief addIcon
* \param icon
*/
void addIcon(WiiImage* icon);
/*!
* \brief addIcon
* \param icon
*/
void addIcon(WiiImage* icon);
/*!
* \brief setIcon
* \param id
* \param icon
*/
void setIcon(atUint32 id, WiiImage* icon);
/*!
* \brief setIcon
* \param id
* \param icon
*/
void setIcon(atUint32 id, WiiImage* icon);
/*!
* \brief getIcon
* \param id
* \return
*/
WiiImage* getIcon(atUint32 id) const;
/*!
* \brief getIcon
* \param id
* \return
*/
WiiImage* getIcon(atUint32 id) const;
/*!
* \brief icons
* \return
*/
std::vector<WiiImage*> icons() const;
/*!
* \brief icons
* \return
*/
std::vector<WiiImage*> icons() const;
/*!
* \brief setAnimationSpeed
* \param animSpeed
*/
void setAnimationSpeed(atUint16 animSpeed);
/*!
* \brief setAnimationSpeed
* \param animSpeed
*/
void setAnimationSpeed(atUint16 animSpeed);
/*!
* \brief animationSpeed
* \return
*/
atUint16 animationSpeed() const;
/*!
* \brief animationSpeed
* \return
*/
atUint16 animationSpeed() const;
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(atUint8 permissions);
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(atUint8 permissions);
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
/*!
* \brief setFlags
* \param flags
*/
void setFlags(atUint32 flags);
/*!
* \brief setFlags
* \param flags
*/
void setFlags(atUint32 flags);
/*!
* \brief flags
* \return
*/
atUint32 flags() const;
/*!
* \brief flags
* \return
*/
atUint32 flags() const;
protected:
private:
atUint64 m_gameId;
WiiImage* m_banner;
atUint32 m_animSpeed;
atUint8 m_permissions;
atUint32 m_flags;
atUint32 m_bannerSize;
std::vector<WiiImage*> m_icons;
std::u16string m_title;
std::u16string m_subtitle;
atUint64 m_gameId;
WiiImage* m_banner;
atUint32 m_animSpeed;
atUint8 m_permissions;
atUint32 m_flags;
atUint32 m_bannerSize;
std::vector<WiiImage*> m_icons;
std::u16string m_title;
std::u16string m_subtitle;
};
} // zelda
} // namespace athena

View File

@@ -5,217 +5,213 @@
#include <vector>
#include "athena/Global.hpp"
namespace athena
{
namespace athena {
const atUint8 SD_KEY [16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
const atUint8 SD_IV [16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
const atUint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
const atUint8 SD_KEY[16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08,
0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
const atUint8 SD_IV[16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f,
0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
const atUint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17,
0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
/*! \class WiiFile
* \brief Wii file container class
*
* Contains all relevant data for a file in a data.bin file.
*/
class WiiFile
{
class WiiFile {
public:
/*! \enum Permission
* \brief The Wii uses a bastardized unix permissions system so these flags
* reflect the file's individual permissions.
*/
enum Permission {
OtherRead = 0x01,
OtherWrite = 0x02,
GroupRead = 0x04,
GroupWrite = 0x08,
OwnerRead = 0x10,
OwnerWrite = 0x20,
/*! \enum Permission
* \brief The Wii uses a bastardized unix permissions system so these flags
* reflect the file's individual permissions.
*/
enum Permission
{
OtherRead = 0x01,
OtherWrite = 0x02,
GroupRead = 0x04,
GroupWrite = 0x08,
OwnerRead = 0x10,
OwnerWrite = 0x20,
// Mask values;
OtherRW = (OtherRead | OtherWrite), //!< Mask to get the Other group permissions
GroupRW = (GroupRead | GroupWrite),
OwnerRW = (OwnerRead | OwnerWrite)
};
// Mask values;
OtherRW = (OtherRead | OtherWrite), //!< Mask to get the Other group permissions
GroupRW = (GroupRead | GroupWrite),
OwnerRW = (OwnerRead | OwnerWrite)
};
/*!
* \brief The Type enum
*/
enum Type { File = 0x01, Directory = 0x02 };
/*!
* \brief The Type enum
*/
enum Type
{
File = 0x01,
Directory = 0x02
};
WiiFile();
WiiFile();
/*!
* \brief WiiFile
* \param filename
*/
WiiFile(const std::string& filename);
/*!
* \brief WiiFile
* \param filename
*/
WiiFile(const std::string& filename);
/*!
* \brief WiiFile
* \param filename
* \param permissions
* \param data
* \param length
*/
WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length);
virtual ~WiiFile();
/*!
* \brief WiiFile
* \param filename
* \param permissions
* \param data
* \param length
*/
WiiFile(const std::string& filename, atUint8 permissions, const atUint8* data, atUint32 length);
virtual ~WiiFile();
/*!
* \brief setFilename
* \param filename
*/
void setFilename(const std::string& filename);
/*!
* \brief setFilename
* \param filename
*/
void setFilename(const std::string& filename);
/*!
* \brief filename
* \return
*/
std::string filename() const;
/*!
* \brief filename
* \return
*/
std::string filename() const;
/*!
* \brief setData
* \param data
*/
void setData(const atUint8* data);
/*!
* \brief data
* \return
*/
atUint8* data() const;
/*!
* \brief setData
* \param data
*/
void setData(const atUint8* data);
/*!
* \brief data
* \return
*/
atUint8* data() const;
/*!
* \brief setLength
* \param len
*/
void setLength(const int len);
/*!
* \brief setLength
* \param len
*/
void setLength(const int len);
/*!
* \brief length
* \return
*/
int length() const;
/*!
* \brief length
* \return
*/
int length() const;
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(const atUint8 permissions);
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(const atUint8 permissions);
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
/*!
* \brief permissions
* \return
*/
atUint8 permissions() const;
/*!
* \brief setAttributes
* \param attr
*/
void setAttributes(const atUint8 attr);
/*!
* \brief setAttributes
* \param attr
*/
void setAttributes(const atUint8 attr);
/*!
* \brief attributes
* \return
*/
atUint8 attributes() const;
/*!
* \brief attributes
* \return
*/
atUint8 attributes() const;
/*!
* \brief setType
* \param type
*/
void setType(Type type);
/*!
* \brief setType
* \param type
*/
void setType(Type type);
/*!
* \brief type
* \return
*/
Type type() const;
/*!
* \brief type
* \return
*/
Type type() const;
/*!
* \brief isDirectory
* \return
*/
bool isDirectory() const;
/*!
* \brief isDirectory
* \return
*/
bool isDirectory() const;
/*!
* \brief isFile
* \return
*/
bool isFile() const;
/*!
* \brief isFile
* \return
*/
bool isFile() const;
/*!
* \brief addChild
* \param file
*/
void addChild(WiiFile* file);
/*!
* \brief children
* \return
*/
std::vector<WiiFile*> children();
/*!
* \brief child
* \param name
* \return
*/
WiiFile* child(const std::string& name);
/*!
* \brief removeChild
* \param name
*/
void removeChild(const std::string& name);
/*!
* \brief removeChild
* \param file
*/
void removeChild(WiiFile* file);
/*!
* \brief addChild
* \param file
*/
void addChild(WiiFile* file);
/*!
* \brief children
* \return
*/
std::vector<WiiFile*> children();
/*!
* \brief child
* \param name
* \return
*/
WiiFile* child(const std::string& name);
/*!
* \brief removeChild
* \param name
*/
void removeChild(const std::string& name);
/*!
* \brief removeChild
* \param file
*/
void removeChild(WiiFile* file);
/*!
* \brief parent
* \return
*/
WiiFile* parent();
/*!
* \brief parent
* \return
*/
WiiFile* parent();
/*!
* \brief setParent
* \param parent
*/
void setParent(WiiFile* parent);
/*!
* \brief setParent
* \param parent
*/
void setParent(WiiFile* parent);
/*!
* \brief fileCount
* \return
*/
atUint32 fileCount();
/*!
* \brief fileCount
* \return
*/
atUint32 fileCount();
/*!
* \brief allChildren
* \return
*/
std::vector<WiiFile*> allChildren();
/*!
* \brief allChildren
* \return
*/
std::vector<WiiFile*> allChildren();
/*!
* \brief fullpath
* \return
*/
std::string fullpath();
/*!
* \brief fullpath
* \return
*/
std::string fullpath();
protected:
private:
atUint8 m_permissions;
atUint8 m_attributes;
Type m_type;
std::string m_filename;
int m_fileLen;
atUint8* m_fileData;
WiiFile* m_parent;
std::vector<WiiFile*> m_children;
atUint8 m_permissions;
atUint8 m_attributes;
Type m_type;
std::string m_filename;
int m_fileLen;
atUint8* m_fileData;
WiiFile* m_parent;
std::vector<WiiFile*> m_children;
};
} // zelda
} // namespace athena

View File

@@ -3,74 +3,71 @@
#include <memory>
#include "athena/Types.hpp"
namespace athena
{
namespace athena {
/*!
* \brief The WiiImage class
*/
class WiiImage
{
class WiiImage {
public:
/*!
* \brief WiiImage
*/
WiiImage();
/*!
* \brief WiiImage
* \param width
* \param height
* \param data
*/
WiiImage(atUint32 width, atUint32 height, std::unique_ptr<atUint8[]>&& data);
/*!
* \brief WiiImage
*/
WiiImage();
/*!
* \brief WiiImage
* \param width
* \param height
* \param data
*/
WiiImage(atUint32 width, atUint32 height, std::unique_ptr<atUint8[]>&& data);
/*!
* \brief setWidth
* \param width
*/
void setWidth(const atUint32 width);
/*!
* \brief setWidth
* \param width
*/
void setWidth(const atUint32 width);
/*!
* \brief width
* \return
*/
atUint32 width() const;
/*!
* \brief width
* \return
*/
atUint32 width() const;
/*!
* \brief setHeight
* \param height
*/
void setHeight(const atUint32 height);
/*!
* \brief setHeight
* \param height
*/
void setHeight(const atUint32 height);
/*!
* \brief height
* \return
*/
atUint32 height() const;
/*!
* \brief height
* \return
*/
atUint32 height() const;
/*!
* \brief setData
* \param data
*/
void setData(const atUint8* data);
/*!
* \brief setData
* \param data
*/
void setData(const atUint8* data);
/*!
* \brief data
* \return
*/
atUint8* data();
/*!
* \brief data
* \return
*/
atUint8* data();
/*!
* \brief toRGBA
* \return
*/
atUint8* toRGBA();
/*!
* \brief toRGBA
* \return
*/
atUint8* toRGBA();
private:
atUint32 m_width;
atUint32 m_height;
std::unique_ptr<atUint8[]> m_data;
atUint32 m_width;
atUint32 m_height;
std::unique_ptr<atUint8[]> m_data;
};
} // zelda
} // namespace athena

View File

@@ -5,8 +5,7 @@
#include <vector>
#include "athena/Global.hpp"
namespace athena
{
namespace athena {
class WiiFile;
class WiiBanner;
@@ -19,65 +18,61 @@ class BinaryWriter;
*
* Contains all relevant data for a Wii data.bin file.
*/
class WiiSave
{
class WiiSave {
public:
/*!
* \brief FileIterator
*/
typedef std::unordered_map<std::string, WiiFile*>::const_iterator FileIterator;
/*!
* \brief FileIterator
*/
typedef std::unordered_map<std::string, WiiFile*>::const_iterator FileIterator;
/*!
* \brief WiiSave
*/
WiiSave();
/*!
* \brief ~WiiSave
*/
virtual ~WiiSave();
/*!
* \brief WiiSave
*/
WiiSave();
/*!
* \brief ~WiiSave
*/
virtual ~WiiSave();
/*!
* \brief addFile
* \param filename
* \param file
*/
void addFile(WiiFile* file);
void setRoot(WiiFile* root);
/*!
* \brief file
* \param filename
* \return
*/
WiiFile* file(const std::string& filename);
/*!
* \brief addFile
* \param filename
* \param file
*/
void addFile(WiiFile* file);
void setRoot(WiiFile* root);
/*!
* \brief file
* \param filename
* \return
*/
WiiFile* file(const std::string& filename);
atUint32 fileCount() const;
/*!
* \brief fileList
* \return
*/
WiiFile* root();
atUint32 fileCount() const;
/*!
* \brief fileList
* \return
*/
WiiFile* root();
/*!
* \brief setBanner
* \param banner
*/
void setBanner(WiiBanner* banner);
/*!
* \brief setBanner
* \param banner
*/
void setBanner(WiiBanner* banner);
/*!
* \brief banner
* \return
*/
WiiBanner* banner() const;
/*!
* \brief banner
* \return
*/
WiiBanner* banner() const;
std::vector<WiiFile*> allFiles() const;
std::vector<WiiFile*> allFiles() const;
protected:
private:
WiiFile* m_root;
WiiBanner* m_banner;
WiiFile* m_root;
WiiBanner* m_banner;
};
} // zelda
} // namespace athena

View File

@@ -3,15 +3,13 @@
#include "athena/Global.hpp"
#include "athena/MemoryReader.hpp"
namespace athena
{
namespace athena {
class WiiSave;
class WiiBanner;
class WiiFile;
class WiiImage;
namespace io
{
namespace io {
/*! \class WiiSaveReader
* \brief Wii data.bin reader class
@@ -20,34 +18,34 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class WiiSaveReader : public MemoryCopyReader
{
class WiiSaveReader : public MemoryCopyReader {
public:
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
WiiSaveReader(const atUint8*, atUint64);
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
WiiSaveReader(const atUint8*, atUint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveReader(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveReader(const std::string&);
/*!
* \brief readSave
* \return
*/
std::unique_ptr<WiiSave> readSave();
/*!
* \brief readSave
* \return
*/
std::unique_ptr<WiiSave> readSave();
private:
WiiBanner* readBanner();
WiiFile* readFile();
WiiImage* readImage(atUint32 width, atUint32 height);
void readCerts(atUint32 totalSize);
WiiFile* buildTree(std::vector<WiiFile*> files);
WiiBanner* readBanner();
WiiFile* readFile();
WiiImage* readImage(atUint32 width, atUint32 height);
void readCerts(atUint32 totalSize);
WiiFile* buildTree(std::vector<WiiFile*> files);
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -2,15 +2,13 @@
#include "athena/MemoryWriter.hpp"
namespace athena
{
namespace athena {
class WiiSave;
class WiiBanner;
class WiiFile;
class WiiImage;
namespace io
{
namespace io {
/*! \class WiiSaveWriter
* \brief Wii data.bin writer class
@@ -19,34 +17,34 @@ namespace io
* all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader
*/
class WiiSaveWriter : protected MemoryCopyWriter
{
class WiiSaveWriter : protected MemoryCopyWriter {
public:
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveWriter(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveWriter(const std::string&);
/*!
* \brief writeSave
* \param save
* \param macAddress
* \param ngId
* \param ngPriv
* \param ngSig
* \param ngKeyId
* \param filepath
* \return
*/
bool writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId, const std::string& filepath = "");
/*!
* \brief writeSave
* \param save
* \param macAddress
* \param ngId
* \param ngPriv
* \param ngSig
* \param ngKeyId
* \param filepath
* \return
*/
bool writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId,
const std::string& filepath = "");
private:
void writeBanner(WiiBanner* banner);
atUint32 writeFile(WiiFile* file);
void writeImage(WiiImage* image);
void writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId);
void writeBanner(WiiBanner* banner);
atUint32 writeFile(WiiFile* file);
void writeImage(WiiImage* image);
void writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId);
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@@ -12,157 +12,147 @@
#include <functional>
#include "Global.hpp"
namespace athena::io
{
namespace athena::io {
class IStreamReader;
class IStreamWriter;
enum class YAMLNodeStyle
{
Any,
Flow,
Block
enum class YAMLNodeStyle { Any, Flow, Block };
struct YAMLNode {
yaml_node_type_t m_type;
std::string m_scalarString;
std::vector<std::unique_ptr<YAMLNode>> m_seqChildren;
std::vector<std::pair<std::string, std::unique_ptr<YAMLNode>>> m_mapChildren;
YAMLNodeStyle m_style = YAMLNodeStyle::Any;
YAMLNode(yaml_node_type_t type) : m_type(type) {}
inline const YAMLNode* findMapChild(std::string_view key) const {
for (const auto& item : m_mapChildren)
if (!item.first.compare(key))
return item.second.get();
return nullptr;
}
inline void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node) {
for (auto& item : m_mapChildren)
if (!item.first.compare(key)) {
item.second = std::move(node);
return;
}
m_mapChildren.emplace_back(key, std::move(node));
}
};
struct YAMLNode
{
yaml_node_type_t m_type;
std::string m_scalarString;
std::vector<std::unique_ptr<YAMLNode>> m_seqChildren;
std::vector<std::pair<std::string, std::unique_ptr<YAMLNode>>> m_mapChildren;
YAMLNodeStyle m_style = YAMLNodeStyle::Any;
YAMLNode(yaml_node_type_t type) : m_type(type) {}
inline const YAMLNode* findMapChild(std::string_view key) const
{
for (const auto& item : m_mapChildren)
if (!item.first.compare(key))
return item.second.get();
return nullptr;
}
inline void assignMapChild(std::string_view key, std::unique_ptr <YAMLNode>&& node)
{
for (auto& item : m_mapChildren)
if (!item.first.compare(key))
{
item.second = std::move(node);
return;
}
m_mapChildren.emplace_back(key, std::move(node));
}
};
template<typename RETURNTYPE>
template <typename RETURNTYPE>
RETURNTYPE NodeToVal(const YAMLNode* node);
template<>
template <>
bool NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(bool val);
std::unique_ptr<YAMLNode> ValToNode(bool val);
template<>
template <>
atInt8 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atInt8 val);
std::unique_ptr<YAMLNode> ValToNode(atInt8 val);
template<>
template <>
atUint8 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atUint8 val);
std::unique_ptr<YAMLNode> ValToNode(atUint8 val);
template<>
template <>
atInt16 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atInt16 val);
std::unique_ptr<YAMLNode> ValToNode(atInt16 val);
template<>
template <>
atUint16 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atUint16 val);
std::unique_ptr<YAMLNode> ValToNode(atUint16 val);
template<>
template <>
atInt32 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atInt32 val);
std::unique_ptr<YAMLNode> ValToNode(atInt32 val);
template<>
template <>
atUint32 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atUint32 val);
std::unique_ptr<YAMLNode> ValToNode(atUint32 val);
template<>
template <>
atInt64 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atInt64 val);
std::unique_ptr<YAMLNode> ValToNode(atInt64 val);
template<>
template <>
atUint64 NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(atUint64 val);
std::unique_ptr<YAMLNode> ValToNode(atUint64 val);
template<>
template <>
float NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(float val);
std::unique_ptr<YAMLNode> ValToNode(float val);
template<>
template <>
double NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(double val);
std::unique_ptr<YAMLNode> ValToNode(double val);
template<typename RETURNTYPE>
template <typename RETURNTYPE>
RETURNTYPE NodeToVec(const YAMLNode* node);
template<>
template <>
atVec2f NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec2f& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec2f& val);
template<>
template <>
atVec3f NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec3f& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec3f& val);
template<>
template <>
atVec4f NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec4f& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec4f& val);
template<>
template <>
atVec2d NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec2d& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec2d& val);
template<>
template <>
atVec3d NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec3d& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec3d& val);
template<>
template <>
atVec4d NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const atVec4d& val);
std::unique_ptr<YAMLNode> ValToNode(const atVec4d& val);
template<>
template <>
std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount);
std::unique_ptr<YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount);
template<>
template <>
std::string NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(std::string_view val);
std::unique_ptr<YAMLNode> ValToNode(std::string_view val);
template<>
template <>
std::wstring NodeToVal(const YAMLNode* node);
std::unique_ptr <YAMLNode> ValToNode(std::wstring_view val);
std::unique_ptr<YAMLNode> ValToNode(std::wstring_view val);
std::unique_ptr <YAMLNode> ValToNode(std::u16string_view val);
std::unique_ptr<YAMLNode> ValToNode(std::u16string_view val);
std::unique_ptr <YAMLNode> ValToNode(std::u32string_view val);
std::unique_ptr<YAMLNode> ValToNode(std::u32string_view val);
std::string base64_encode(const atUint8* bytes_to_encode, size_t in_len);
@@ -172,28 +162,22 @@ void HandleYAMLParserError(yaml_parser_t* parser);
void HandleYAMLEmitterError(yaml_emitter_t* emitter);
struct YAMLStdStringViewReaderState
{
std::string_view::const_iterator begin;
std::string_view::const_iterator end;
struct YAMLStdStringViewReaderState {
std::string_view::const_iterator begin;
std::string_view::const_iterator end;
YAMLStdStringViewReaderState(std::string_view str)
{
begin = str.begin();
end = str.end();
}
YAMLStdStringViewReaderState(std::string_view str) {
begin = str.begin();
end = str.end();
}
};
int YAMLStdStringReader(YAMLStdStringViewReaderState* str,
unsigned char* buffer, size_t size, size_t* size_read);
int YAMLStdStringReader(YAMLStdStringViewReaderState* str, unsigned char* buffer, size_t size, size_t* size_read);
int YAMLStdStringWriter(std::string* str, unsigned char* buffer, size_t size);
int YAMLAthenaReader(athena::io::IStreamReader* reader,
unsigned char* buffer, size_t size, size_t* size_read);
int YAMLAthenaReader(athena::io::IStreamReader* reader, unsigned char* buffer, size_t size, size_t* size_read);
int YAMLAthenaWriter(athena::io::IStreamWriter* writer,
unsigned char* buffer, size_t size);
}
int YAMLAthenaWriter(athena::io::IStreamWriter* writer, unsigned char* buffer, size_t size);
} // namespace athena::io

View File

@@ -2,168 +2,160 @@
#include "YAMLCommon.hpp"
namespace athena::io
{
namespace athena::io {
class YAMLDocReader
{
std::unique_ptr<YAMLNode> m_rootNode;
std::vector<YAMLNode*> m_subStack;
std::vector<int> m_seqTrackerStack;
yaml_parser_t m_parser;
std::unique_ptr<YAMLNode> ParseEvents(athena::io::IStreamReader* reader);
void _leaveSubRecord();
void _leaveSubVector();
class YAMLDocReader {
std::unique_ptr<YAMLNode> m_rootNode;
std::vector<YAMLNode*> m_subStack;
std::vector<int> m_seqTrackerStack;
yaml_parser_t m_parser;
std::unique_ptr<YAMLNode> ParseEvents(athena::io::IStreamReader* reader);
void _leaveSubRecord();
void _leaveSubVector();
public:
YAMLDocReader();
~YAMLDocReader();
YAMLDocReader();
~YAMLDocReader();
void reset();
void reset();
inline yaml_parser_t* getParser() { return &m_parser; }
inline yaml_parser_t* getParser() { return &m_parser; }
bool parse(athena::io::IStreamReader* reader);
bool parse(athena::io::IStreamReader* reader);
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
bool ValidateClassType(const char* expectedType);
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
bool ValidateClassType(const char* expectedType);
inline const YAMLNode* getRootNode() const { return m_rootNode.get(); }
inline const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
std::unique_ptr<YAMLNode> releaseRootNode() { return std::move(m_rootNode); }
inline const YAMLNode* getRootNode() const { return m_rootNode.get(); }
inline const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
std::unique_ptr<YAMLNode> releaseRootNode() { return std::move(m_rootNode); }
class RecordRAII
{
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
RecordRAII(YAMLDocReader* r) : m_r(r) {}
RecordRAII() = default;
public:
operator bool() const { return m_r != nullptr; }
void leave() { if (m_r) {m_r->_leaveSubRecord(); m_r = nullptr;} }
~RecordRAII() { if (m_r) m_r->_leaveSubRecord(); }
};
friend class RecordRAII;
class RecordRAII {
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
RecordRAII(YAMLDocReader* r) : m_r(r) {}
RecordRAII() = default;
RecordRAII enterSubRecord(const char* name);
template <class T>
void enumerate(const char* name, T& record,
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
{
if (auto rec = enterSubRecord(name))
record.read(*this);
public:
operator bool() const { return m_r != nullptr; }
void leave() {
if (m_r) {
m_r->_leaveSubRecord();
m_r = nullptr;
}
}
class VectorRAII
{
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
VectorRAII(YAMLDocReader* r) : m_r(r) {}
VectorRAII() = default;
public:
operator bool() const { return m_r != nullptr; }
~VectorRAII() { if (m_r) m_r->_leaveSubVector(); }
};
friend class VectorRAII;
VectorRAII enterSubVector(const char* name, size_t& countOut);
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value &&
!std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value &&
!std::is_same<T, atVec4f>::value>* = 0)
{
size_t countOut;
if (auto v = enterSubVector(name, countOut))
{
vector.clear();
vector.reserve(countOut);
for (size_t i=0 ; i<countOut ; ++i)
{
vector.emplace_back();
if (auto rec = enterSubRecord(nullptr))
vector.back().read(*this);
}
}
return countOut;
~RecordRAII() {
if (m_r)
m_r->_leaveSubRecord();
}
};
friend class RecordRAII;
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value ||
std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value ||
std::is_same<T, atVec4f>::value>* = 0)
{
size_t countOut;
if (auto v = enterSubVector(name, countOut))
{
vector.clear();
vector.reserve(countOut);
for (size_t i=0 ; i<countOut ; ++i)
vector.push_back(readVal<T>(name));
}
return countOut;
RecordRAII enterSubRecord(const char* name);
template <class T>
void enumerate(const char* name, T& record, typename std::enable_if_t<__IsDNARecord_v<T>>* = 0) {
if (auto rec = enterSubRecord(name))
record.read(*this);
}
class VectorRAII {
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
VectorRAII(YAMLDocReader* r) : m_r(r) {}
VectorRAII() = default;
public:
operator bool() const { return m_r != nullptr; }
~VectorRAII() {
if (m_r)
m_r->_leaveSubVector();
}
};
friend class VectorRAII;
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector,
std::function<void(YAMLDocReader&, T&)> readf)
{
size_t countOut;
if (auto v = enterSubVector(name, countOut))
{
vector.clear();
vector.reserve(countOut);
for (size_t i=0 ; i<countOut ; ++i)
{
vector.emplace_back();
if (auto rec = enterSubRecord(nullptr))
readf(*this, vector.back());
}
}
return countOut;
VectorRAII enterSubVector(const char* name, size_t& countOut);
template <class T>
size_t
enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value>* = 0) {
size_t countOut;
if (auto v = enterSubVector(name, countOut)) {
vector.clear();
vector.reserve(countOut);
for (size_t i = 0; i < countOut; ++i) {
vector.emplace_back();
if (auto rec = enterSubRecord(nullptr))
vector.back().read(*this);
}
}
return countOut;
}
bool hasVal(const char* name) const
{
if (m_subStack.size())
{
const YAMLNode* mnode = m_subStack.back();
if (mnode->m_type == YAML_MAPPING_NODE && name)
for (const auto& item : mnode->m_mapChildren)
if (!item.first.compare(name))
return true;
}
return false;
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>* = 0) {
size_t countOut;
if (auto v = enterSubVector(name, countOut)) {
vector.clear();
vector.reserve(countOut);
for (size_t i = 0; i < countOut; ++i)
vector.push_back(readVal<T>(name));
}
return countOut;
}
template <typename RETURNTYPE>
RETURNTYPE readVal(const char* name);
bool readBool(const char* name);
atInt8 readByte(const char* name);
atUint8 readUByte(const char* name);
atInt16 readInt16(const char* name);
atUint16 readUint16(const char* name);
atInt32 readInt32(const char* name);
atUint32 readUint32(const char* name);
atInt64 readInt64(const char* name);
atUint64 readUint64(const char* name);
float readFloat(const char* name);
double readDouble(const char* name);
atVec2f readVec2f(const char* name);
atVec3f readVec3f(const char* name);
atVec4f readVec4f(const char* name);
atVec2d readVec2d(const char* name);
atVec3d readVec3d(const char* name);
atVec4d readVec4d(const char* name);
std::unique_ptr<atUint8[]> readUBytes(const char* name);
std::string readString(const char* name);
std::wstring readWString(const char* name);
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector, std::function<void(YAMLDocReader&, T&)> readf) {
size_t countOut;
if (auto v = enterSubVector(name, countOut)) {
vector.clear();
vector.reserve(countOut);
for (size_t i = 0; i < countOut; ++i) {
vector.emplace_back();
if (auto rec = enterSubRecord(nullptr))
readf(*this, vector.back());
}
}
return countOut;
}
bool hasVal(const char* name) const {
if (m_subStack.size()) {
const YAMLNode* mnode = m_subStack.back();
if (mnode->m_type == YAML_MAPPING_NODE && name)
for (const auto& item : mnode->m_mapChildren)
if (!item.first.compare(name))
return true;
}
return false;
}
template <typename RETURNTYPE>
RETURNTYPE readVal(const char* name);
bool readBool(const char* name);
atInt8 readByte(const char* name);
atUint8 readUByte(const char* name);
atInt16 readInt16(const char* name);
atUint16 readUint16(const char* name);
atInt32 readInt32(const char* name);
atUint32 readUint32(const char* name);
atInt64 readInt64(const char* name);
atUint64 readUint64(const char* name);
float readFloat(const char* name);
double readDouble(const char* name);
atVec2f readVec2f(const char* name);
atVec3f readVec3f(const char* name);
atVec4f readVec4f(const char* name);
atVec2d readVec2d(const char* name);
atVec3d readVec3d(const char* name);
atVec4d readVec4d(const char* name);
std::unique_ptr<atUint8[]> readUBytes(const char* name);
std::string readString(const char* name);
std::wstring readWString(const char* name);
};
}
} // namespace athena::io

View File

@@ -2,133 +2,125 @@
#include "YAMLCommon.hpp"
namespace athena::io
{
namespace athena::io {
class YAMLDocWriter {
std::unique_ptr<YAMLNode> m_rootNode;
std::vector<YAMLNode*> m_subStack;
yaml_emitter_t m_emitter;
static bool RecursiveFinish(yaml_emitter_t* doc, const YAMLNode& node);
void _leaveSubRecord();
void _leaveSubVector();
class YAMLDocWriter
{
std::unique_ptr<YAMLNode> m_rootNode;
std::vector<YAMLNode*> m_subStack;
yaml_emitter_t m_emitter;
static bool RecursiveFinish(yaml_emitter_t* doc, const YAMLNode& node);
void _leaveSubRecord();
void _leaveSubVector();
public:
YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
~YAMLDocWriter();
YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
~YAMLDocWriter();
yaml_emitter_t* getEmitter() { return &m_emitter; }
yaml_emitter_t* getEmitter() { return &m_emitter; }
bool finish(athena::io::IStreamWriter* fout);
bool finish(athena::io::IStreamWriter* fout);
inline YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
inline YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
class RecordRAII
{
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
RecordRAII(YAMLDocWriter* w) : m_w(w) {}
RecordRAII() = default;
public:
operator bool() const { return m_w != nullptr; }
~RecordRAII() { if (m_w) m_w->_leaveSubRecord(); }
};
friend class RecordRAII;
class RecordRAII {
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
RecordRAII(YAMLDocWriter* w) : m_w(w) {}
RecordRAII() = default;
RecordRAII enterSubRecord(const char* name);
template <class T>
void enumerate(const char* name, T& record,
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
{
if (auto rec = enterSubRecord(name))
record.write(*this);
public:
operator bool() const { return m_w != nullptr; }
~RecordRAII() {
if (m_w)
m_w->_leaveSubRecord();
}
};
friend class RecordRAII;
class VectorRAII
{
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
VectorRAII(YAMLDocWriter* w) : m_w(w) {}
VectorRAII() = default;
public:
operator bool() const { return m_w != nullptr; }
~VectorRAII() { if (m_w) m_w->_leaveSubVector(); }
};
friend class VectorRAII;
RecordRAII enterSubRecord(const char* name);
VectorRAII enterSubVector(const char* name);
template <class T>
void enumerate(const char* name, T& record, typename std::enable_if_t<__IsDNARecord_v<T>>* = 0) {
if (auto rec = enterSubRecord(name))
record.write(*this);
}
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value &&
!std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value &&
!std::is_same<T, atVec4f>::value &&
!std::is_same<T, atVec2d>::value &&
!std::is_same<T, atVec3d>::value &&
!std::is_same<T, atVec4d>::value>* = 0)
{
if (auto v = enterSubVector(name))
for (const T& item : vector)
if (auto rec = enterSubRecord(nullptr))
item.write(*this);
class VectorRAII {
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
VectorRAII(YAMLDocWriter* w) : m_w(w) {}
VectorRAII() = default;
public:
operator bool() const { return m_w != nullptr; }
~VectorRAII() {
if (m_w)
m_w->_leaveSubVector();
}
};
friend class VectorRAII;
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value ||
std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value ||
std::is_same<T, atVec4f>::value ||
std::is_same<T, atVec2d>::value ||
std::is_same<T, atVec3d>::value ||
std::is_same<T, atVec4d>::value>* = 0)
{
if (auto v = enterSubVector(name))
for (T item : vector)
writeVal<T>(nullptr, item);
}
VectorRAII enterSubVector(const char* name);
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
std::function<void(YAMLDocWriter&, const T&)> writef)
{
if (auto v = enterSubVector(name))
for (const T& item : vector)
if (auto rec = enterSubRecord(nullptr))
writef(*this, item);
}
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value &&
!std::is_same<T, atVec2d>::value && !std::is_same<T, atVec3d>::value &&
!std::is_same<T, atVec4d>::value>* = 0) {
if (auto v = enterSubVector(name))
for (const T& item : vector)
if (auto rec = enterSubRecord(nullptr))
item.write(*this);
}
template <typename INTYPE>
void writeVal(const char* name, const INTYPE& val);
template <typename INTYPE>
void writeVal(const char* name, const INTYPE& val, size_t byteCount);
void writeBool(const char* name, const bool& val);
void writeByte(const char* name, const atInt8& val);
void writeUByte(const char* name, const atUint8& val);
void writeInt16(const char* name, const atInt16& val);
void writeUint16(const char* name, const atUint16& val);
void writeInt32(const char* name, const atInt32& val);
void writeUint32(const char* name, const atUint32& val);
void writeInt64(const char* name, const atInt64& val);
void writeUint64(const char* name, const atUint64& val);
void writeFloat(const char* name, const float& val);
void writeDouble(const char* name, const double& val);
void writeVec2f(const char* name, const atVec2f& val);
void writeVec3f(const char* name, const atVec3f& val);
void writeVec4f(const char* name, const atVec4f& val);
void writeVec2d(const char* name, const atVec2d& val);
void writeVec3d(const char* name, const atVec3d& val);
void writeVec4d(const char* name, const atVec4d& val);
void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
void writeString(const char* name, std::string_view val);
void writeWString(const char* name, std::wstring_view val);
void writeU16String(const char* name, std::u16string_view val);
void writeU32String(const char* name, std::u32string_view val);
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value ||
std::is_same<T, atVec2d>::value || std::is_same<T, atVec3d>::value ||
std::is_same<T, atVec4d>::value>* = 0) {
if (auto v = enterSubVector(name))
for (T item : vector)
writeVal<T>(nullptr, item);
}
void setStyle(YAMLNodeStyle s);
template <class T>
void enumerate(const char* name, const std::vector<T>& vector, std::function<void(YAMLDocWriter&, const T&)> writef) {
if (auto v = enterSubVector(name))
for (const T& item : vector)
if (auto rec = enterSubRecord(nullptr))
writef(*this, item);
}
template <typename INTYPE>
void writeVal(const char* name, const INTYPE& val);
template <typename INTYPE>
void writeVal(const char* name, const INTYPE& val, size_t byteCount);
void writeBool(const char* name, const bool& val);
void writeByte(const char* name, const atInt8& val);
void writeUByte(const char* name, const atUint8& val);
void writeInt16(const char* name, const atInt16& val);
void writeUint16(const char* name, const atUint16& val);
void writeInt32(const char* name, const atInt32& val);
void writeUint32(const char* name, const atUint32& val);
void writeInt64(const char* name, const atInt64& val);
void writeUint64(const char* name, const atUint64& val);
void writeFloat(const char* name, const float& val);
void writeDouble(const char* name, const double& val);
void writeVec2f(const char* name, const atVec2f& val);
void writeVec3f(const char* name, const atVec3f& val);
void writeVec4f(const char* name, const atVec4f& val);
void writeVec2d(const char* name, const atVec2d& val);
void writeVec3d(const char* name, const atVec3d& val);
void writeVec4d(const char* name, const atVec4d& val);
void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
void writeString(const char* name, std::string_view val);
void writeWString(const char* name, std::wstring_view val);
void writeU16String(const char* name, std::u16string_view val);
void writeU32String(const char* name, std::u32string_view val);
void setStyle(YAMLNodeStyle s);
};
}
} // namespace athena::io

View File

@@ -2,151 +2,148 @@
#ifndef ZQUEST_HPP
#define ZQUEST_HPP
#include "athena/Global.hpp"
#include <string>
#include <vector>
#include <memory>
#define ZQUEST_VERSION_CHECK(major, minor, revision) \
(major | (minor << 8) | (revision << 16))
#define ZQUEST_VERSION_CHECK(major, minor, revision) (major | (minor << 8) | (revision << 16))
namespace athena
{
namespace athena {
/*!
* \brief ZQuestFile is an export format for save data.
*/
class ZQuestFile
{
class ZQuestFile {
public:
/*!
* \brief The current major version of the ZQuest format
*/
static const atUint32 Major;
/*!
* \brief The current minor version of the ZQuest format
*/
static const atUint32 Minor;
/*!
* \brief The current revision of the ZQuest format
*/
static const atUint32 Revision;
/*!
* \brief The current version of the ZQuest format
*/
static const atUint32 Version;
/*!
* \brief The current major version of the ZQuest format
*/
static const atUint32 Major;
/*!
* \brief The current minor version of the ZQuest format
*/
static const atUint32 Minor;
/*!
* \brief The current revision of the ZQuest format
*/
static const atUint32 Revision;
/*!
* \brief The current version of the ZQuest format
*/
static const atUint32 Version;
/*!
* \brief The magic number used to identify the file e.g. "ZQS1"
*/
static const atUint32 Magic;
/*!
* \brief The magic number used to identify the file e.g. "ZQS1"
*/
static const atUint32 Magic;
/*!
* \enum Game
* \brief The list of games currently supported by ZQuest
*/
enum Game
{
NoGame, //!< None or Unsupported
LoZ, //!< Legend of Zelda
AoL, //!< Adventure of Link
ALttP, //!< A Link to the Past
LA, //!< Links Awakening
OoT, //!< Ocarin of Time
OoT3D, //!< Ocarina of Time 3D
MM, //!< Majora's Mask
OoS, //!< Oracle of Season
OoA, //!< Oracle of Ages
FS, //!< Four Swords
WW, //!< Wind Waker
FSA, //!< Four Swords Adventures
MC, //!< Minish Cap
TP, //!< Twilight Princess
PH, //!< Phantom Hourglass
ST, //!< Spirit Tracks
SS, //!< Skyward Sword
ALBW, //!< A Link Between Worlds
// Add more games here
/*!
* \enum Game
* \brief The list of games currently supported by ZQuest
*/
enum Game {
NoGame, //!< None or Unsupported
LoZ, //!< Legend of Zelda
AoL, //!< Adventure of Link
ALttP, //!< A Link to the Past
LA, //!< Links Awakening
OoT, //!< Ocarin of Time
OoT3D, //!< Ocarina of Time 3D
MM, //!< Majora's Mask
OoS, //!< Oracle of Season
OoA, //!< Oracle of Ages
FS, //!< Four Swords
WW, //!< Wind Waker
FSA, //!< Four Swords Adventures
MC, //!< Minish Cap
TP, //!< Twilight Princess
PH, //!< Phantom Hourglass
ST, //!< Spirit Tracks
SS, //!< Skyward Sword
ALBW, //!< A Link Between Worlds
// Add more games here
// This must always be last
GameCount //!< Total number of supported games
};
// This must always be last
GameCount //!< Total number of supported games
};
/*!
* \brief ZQuest
*/
ZQuestFile();
/*!
* \brief ZQuest
*/
ZQuestFile();
/*!