athena/src/athena/ZQuestFile.cpp

84 lines
2.7 KiB
C++
Raw Permalink Normal View History

2016-03-04 13:00:12 -10:00
#include "athena/ZQuestFile.hpp"
2017-12-28 21:55:42 -10:00
#include <cstring>
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
namespace athena {
std::vector<std::string> GameStrings;
2018-12-07 19:18:17 -10:00
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-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
const uint32_t ZQuestFile::Major = 2;
const uint32_t ZQuestFile::Minor = 0;
const uint32_t ZQuestFile::Revision = 0;
2013-07-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
const uint32_t ZQuestFile::Version = Major | (Minor << 8) | (Revision << 16);
2013-07-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
const uint32_t ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQuestFile::Major) << 24);
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
ZQuestFile::ZQuestFile() : m_game(NoGame), m_endian(Endian::Little), m_length(0) { initGameStrings(); }
2013-07-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
ZQuestFile::ZQuestFile(ZQuestFile::Game game, Endian endian, std::unique_ptr<uint8_t[]>&& data, uint32_t length,
2018-12-07 19:18:17 -10:00
const std::string& gameString)
: m_game(game), m_gameString(gameString), m_endian(endian), m_data(std::move(data)), m_length(length) {
initGameStrings();
2015-05-18 20:24:56 -07:00
2018-12-07 19:18:17 -10:00
if (gameString.empty() && (m_game < GameStrings.size() - 1))
m_gameString = GameStrings[m_game];
2013-07-20 20:51:26 -07:00
}
2018-12-07 19:18:17 -10:00
void ZQuestFile::setGame(ZQuestFile::Game game) {
m_game = game;
2015-05-18 20:24:56 -07:00
2018-12-07 19:18:17 -10:00
if (m_game > GameStrings.size() - 1)
return;
2018-12-07 19:18:17 -10:00
m_gameString = GameStrings[m_game];
2013-07-20 20:51:26 -07:00
}
2018-12-07 19:18:17 -10:00
ZQuestFile::Game ZQuestFile::game() const { return m_game; }
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
void ZQuestFile::setEndian(Endian endian) { m_endian = endian; }
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
Endian ZQuestFile::endian() const { return m_endian; }
2013-07-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
void ZQuestFile::setData(std::unique_ptr<uint8_t[]>&& data, uint32_t length) {
2018-12-07 19:18:17 -10:00
m_data = std::move(data);
m_length = length;
2013-07-20 20:51:26 -07:00
}
2025-04-26 09:34:02 -07:00
uint8_t* ZQuestFile::data() const { return m_data.get(); }
2013-07-20 20:51:26 -07:00
2025-04-26 09:34:02 -07:00
uint32_t ZQuestFile::length() const { return m_length; }
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
void ZQuestFile::setGameString(const std::string& gameString) { m_gameString = gameString; }
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
std::string ZQuestFile::gameString() const { return m_gameString; }
2013-07-20 20:51:26 -07:00
2018-12-07 19:18:17 -10:00
const std::vector<std::string> ZQuestFile::gameStringList() {
if (GameStrings.size() <= 0)
initGameStrings();
2015-05-18 20:24:56 -07:00
2018-12-07 19:18:17 -10:00
return GameStrings;
2013-07-20 20:51:26 -07:00
}
2018-12-07 19:18:17 -10:00
} // namespace athena