2013-07-21 07:49:07 +00:00
|
|
|
// This file is part of libZelda.
|
|
|
|
//
|
|
|
|
// libZelda is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// libZelda is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
#include "ZQuestFile.hpp"
|
2013-07-27 06:39:03 +00:00
|
|
|
#include <string.h>
|
2013-07-21 03:51:26 +00:00
|
|
|
|
|
|
|
namespace zelda
|
|
|
|
{
|
2014-04-19 01:36:46 +00:00
|
|
|
std::vector<std::string> GameStrings;
|
|
|
|
void initGameStrings()
|
|
|
|
{
|
|
|
|
// Populate game strings
|
|
|
|
GameStrings.push_back("No Game");
|
|
|
|
GameStrings.push_back("Legend Of Zelda");
|
|
|
|
GameStrings.push_back("Adventure of Link");
|
|
|
|
GameStrings.push_back("A Link to the Past");
|
|
|
|
GameStrings.push_back("Links Awakening");
|
|
|
|
GameStrings.push_back("Ocarina of Time");
|
|
|
|
GameStrings.push_back("Ocarina of Time 3D");
|
|
|
|
GameStrings.push_back("Majora's Mask");
|
|
|
|
GameStrings.push_back("Oracle of Seasons");
|
|
|
|
GameStrings.push_back("Oracle of Ages");
|
|
|
|
GameStrings.push_back("For Swords");
|
|
|
|
GameStrings.push_back("Wind Waker");
|
|
|
|
GameStrings.push_back("Four Swords Adventures");
|
|
|
|
GameStrings.push_back("Minish Cap");
|
|
|
|
GameStrings.push_back("Twilight Princess");
|
|
|
|
GameStrings.push_back("Phantom Hourglass");
|
|
|
|
GameStrings.push_back("Spirit Tracks");
|
|
|
|
GameStrings.push_back("Skyward Sword");
|
|
|
|
GameStrings.push_back("A Link Between Worlds");
|
|
|
|
}
|
2013-07-21 03:51:26 +00:00
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
const Uint32 ZQuestFile::Major = 2;
|
2013-07-22 03:06:54 +00:00
|
|
|
const Uint32 ZQuestFile::Minor = 0;
|
|
|
|
const Uint32 ZQuestFile::Revision = 0;
|
2013-07-21 03:51:26 +00:00
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
const Uint32 ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
|
2013-07-21 03:51:26 +00:00
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
const Uint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
|
2013-07-21 03:51:26 +00:00
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
ZQuestFile::ZQuestFile()
|
2013-07-21 03:51:26 +00:00
|
|
|
: m_game(NoGame),
|
|
|
|
m_endian(LittleEndian),
|
|
|
|
m_data(NULL),
|
|
|
|
m_length(0)
|
|
|
|
{
|
|
|
|
initGameStrings();
|
|
|
|
}
|
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, Uint8* data, Uint32 length, const std::string& gameString)
|
2013-07-21 03:51:26 +00:00
|
|
|
: m_game(game),
|
2014-04-19 01:36:46 +00:00
|
|
|
m_gameString(gameString),
|
2013-07-21 03:51:26 +00:00
|
|
|
m_endian(endian),
|
|
|
|
m_data(data),
|
|
|
|
m_length(length)
|
|
|
|
{
|
|
|
|
initGameStrings();
|
2014-04-19 01:36:46 +00:00
|
|
|
if (gameString.empty() && (m_game < GameStrings.size() - 1))
|
|
|
|
m_gameString = GameStrings[m_game];
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
ZQuestFile::~ZQuestFile()
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
delete[] m_data;
|
|
|
|
m_data = NULL;
|
|
|
|
m_length = 0;
|
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
void ZQuestFile::setGame(ZQuestFile::Game game)
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
m_game = game;
|
2014-04-19 01:36:46 +00:00
|
|
|
if (m_game > GameStrings.size() - 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_gameString = GameStrings[m_game];
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
ZQuestFile::Game ZQuestFile::game() const
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
return m_game;
|
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
void ZQuestFile::setEndian(Endian endian)
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
m_endian = endian;
|
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
Endian ZQuestFile::endian() const
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
return m_endian;
|
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
void ZQuestFile::setData(Uint8* data, Uint32 length)
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
// ensure we're not overwritting our data without freeing first
|
|
|
|
// or assigning unnecessisarily
|
|
|
|
if (!m_data || m_data != data)
|
|
|
|
{
|
|
|
|
delete[] m_data;
|
2013-07-27 06:39:03 +00:00
|
|
|
m_data = new Uint8[length];
|
2013-07-28 01:42:11 +00:00
|
|
|
// Why is this memcpy needed?
|
|
|
|
// I get SIGABRT without it, need to research
|
2013-07-27 06:39:03 +00:00
|
|
|
memcpy(m_data, data, length);
|
2013-07-22 03:06:54 +00:00
|
|
|
m_length = length;
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
Uint8* ZQuestFile::data() const
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-22 03:06:54 +00:00
|
|
|
Uint32 ZQuestFile::length() const
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
void ZQuestFile::setGameString(const std::string& gameString)
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
2014-04-19 01:36:46 +00:00
|
|
|
m_gameString = gameString;
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
std::string ZQuestFile::gameString() const
|
2013-07-21 03:51:26 +00:00
|
|
|
{
|
2014-04-19 01:36:46 +00:00
|
|
|
return m_gameString;
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 01:36:46 +00:00
|
|
|
const std::vector<std::string> ZQuestFile::gameStringList()
|
|
|
|
{
|
|
|
|
if (GameStrings.size() <= 0)
|
|
|
|
initGameStrings();
|
|
|
|
return GameStrings;
|
|
|
|
}
|
2013-07-21 03:51:26 +00:00
|
|
|
}
|