mirror of https://github.com/libAthena/athena.git
* Fixed some bugs
This commit is contained in:
parent
ebca406d71
commit
304baa45bb
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define __STRX(x) #x
|
||||||
|
#define __STR(x) __STRX(x)
|
||||||
|
#define __LINE_STRING__ __STR(__LINE__)
|
||||||
|
|
||||||
namespace zelda
|
namespace zelda
|
||||||
{
|
{
|
||||||
namespace error
|
namespace error
|
||||||
|
@ -53,4 +57,10 @@ protected:
|
||||||
|
|
||||||
} // error
|
} // error
|
||||||
} // zelda
|
} // zelda
|
||||||
|
#define THROW_EXCEPTION(msg) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
throw zelda::error::Exception(__LINE_STRING__ " " __FILE__ " " msg); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define INVALIDDATAEXCEPTION_HPP
|
#define INVALIDDATAEXCEPTION_HPP
|
||||||
|
|
||||||
#include "Exception.hpp"
|
#include "Exception.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace zelda
|
namespace zelda
|
||||||
{
|
{
|
||||||
|
@ -20,10 +21,17 @@ class InvalidDataException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline InvalidDataException(const std::string& error)
|
inline InvalidDataException(const std::string& error)
|
||||||
: Exception("InvalidDataException: " + error)
|
: Exception(error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define THROW_INVALID_DATA(msg) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
throw zelda::error::InvalidDataException(__LINE_STRING__ " " __FILE__ " " msg); \
|
||||||
|
} while(0)
|
||||||
#endif // INVALIDDATAEXCEPTION_HPP
|
#endif // INVALIDDATAEXCEPTION_HPP
|
||||||
|
|
|
@ -24,6 +24,8 @@ SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
|
||||||
SkywardSwordFile* SkywardSwordFileReader::read()
|
SkywardSwordFile* SkywardSwordFileReader::read()
|
||||||
{
|
{
|
||||||
SkywardSwordFile* file = NULL;
|
SkywardSwordFile* file = NULL;
|
||||||
|
try
|
||||||
|
{
|
||||||
if (base::length() != 0xFBE0)
|
if (base::length() != 0xFBE0)
|
||||||
throw zelda::error::InvalidOperationException("SSFileReader::read -> File not the expected size of 0xFBE0");
|
throw zelda::error::InvalidOperationException("SSFileReader::read -> File not the expected size of 0xFBE0");
|
||||||
|
|
||||||
|
@ -51,6 +53,13 @@ SkywardSwordFile* SkywardSwordFileReader::read()
|
||||||
base::seek(pos, base::Beginning);
|
base::seek(pos, base::Beginning);
|
||||||
file->addQuest(q);
|
file->addQuest(q);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
delete file;
|
||||||
|
file = NULL;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ SpriteFileReader::SpriteFileReader(const std::string& filepath)
|
||||||
|
|
||||||
Sakura::SpriteFile* SpriteFileReader::readFile()
|
Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
{
|
{
|
||||||
|
Sakura::SpriteFile* ret = NULL;
|
||||||
|
try
|
||||||
|
{
|
||||||
Uint32 magic = base::readUInt32();
|
Uint32 magic = base::readUInt32();
|
||||||
|
|
||||||
if (magic != Sakura::SpriteFile::Magic)
|
if (magic != Sakura::SpriteFile::Magic)
|
||||||
|
@ -48,7 +51,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
Uint16 spriteCount = base::readUInt16();
|
Uint16 spriteCount = base::readUInt16();
|
||||||
|
|
||||||
// Lets go ahead and create or new container.
|
// Lets go ahead and create or new container.
|
||||||
Sakura::SpriteFile* ret = new Sakura::SpriteFile(width, height, originX, originY);
|
ret = new Sakura::SpriteFile(width, height, originX, originY);
|
||||||
|
|
||||||
// The next four bytes are reserved to keep the header 32 byte aligned.
|
// The next four bytes are reserved to keep the header 32 byte aligned.
|
||||||
// This isn't necessary for most systems, but it's eventually planned
|
// This isn't necessary for most systems, but it's eventually planned
|
||||||
|
@ -141,6 +144,13 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->setSprites(sprites);
|
ret->setSprites(sprites);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
delete ret;
|
||||||
|
ret = NULL;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ WiiSaveReader::WiiSaveReader(const std::string& filename)
|
||||||
WiiSave* WiiSaveReader::readSave()
|
WiiSave* WiiSaveReader::readSave()
|
||||||
{
|
{
|
||||||
WiiSave* ret = new WiiSave;
|
WiiSave* ret = new WiiSave;
|
||||||
|
try
|
||||||
|
{
|
||||||
if (length() < 0xF0C0)
|
if (length() < 0xF0C0)
|
||||||
throw error::InvalidOperationException("WiiSaveReader::readSave -> Not a valid WiiSave");
|
throw error::InvalidOperationException("WiiSaveReader::readSave -> Not a valid WiiSave");
|
||||||
|
|
||||||
|
@ -98,6 +100,14 @@ WiiSave* WiiSaveReader::readSave()
|
||||||
ret->setFiles(files);
|
ret->setFiles(files);
|
||||||
|
|
||||||
readCerts(totalSize);
|
readCerts(totalSize);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
delete ret;
|
||||||
|
ret = NULL;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +164,7 @@ WiiBanner* WiiSaveReader::readBanner()
|
||||||
gameId = base::readUInt64();
|
gameId = base::readUInt64();
|
||||||
bannerSize = base::readUInt32();
|
bannerSize = base::readUInt32();
|
||||||
permissions = base::readByte();
|
permissions = base::readByte();
|
||||||
/* unk =*/ base::readByte();
|
/* unk =*/ base::readByte();
|
||||||
base::seek(0x10);
|
base::seek(0x10);
|
||||||
// skip padding
|
// skip padding
|
||||||
base::seek(2);
|
base::seek(2);
|
||||||
|
|
Loading…
Reference in New Issue