Remove GPL remnants, and naive `base` typedef

This commit is contained in:
Phillip Stephens 2017-01-03 03:15:07 -08:00
parent ba92629900
commit e5715bbf8f
25 changed files with 294 additions and 375 deletions

View File

@ -156,6 +156,9 @@ add_library(athena-zelda EXCLUDE_FROM_ALL
include/athena/SkywardSwordFileReader.hpp
include/athena/SkywardSwordFileWriter.hpp
include/athena/SkywardSwordQuest.hpp
include/athena/ZQuestFile.hpp
include/athena/ZQuestFileReader.hpp
include/athena/ZQuestFileWriter.hpp
)
# Icon

View File

@ -21,8 +21,6 @@ namespace io
*/
class ALTTPFileReader : protected MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
/*! \brief This constructor takes an existing buffer to read from.
*

View File

@ -20,8 +20,6 @@ namespace io
*/
class ALTTPFileWriter : protected MemoryCopyWriter
{
MEMORYCOPYWRITER_BASE();
public:
/*! \brief This constructor takes an existing buffer to write to.
*

View File

@ -20,7 +20,6 @@ namespace io
*/
class MCFileReader : public MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
/*!
* \brief This constructor takes an existing buffer to read from.

View File

@ -21,7 +21,6 @@ namespace io
*/
class MCFileWriter : protected MemoryCopyWriter
{
MEMORYCOPYWRITER_BASE();
public:
/*!
* \brief This constructor takes an existing buffer to write to.

View File

@ -121,18 +121,5 @@ protected:
} // io
} // Athena
#ifndef MEMORYREADER_BASE
#define MEMORYREADER_BASE() \
private: \
typedef athena::io::MemoryReader base
#endif // MEMORYREADER_BASE
#ifndef MEMORYCOPYREADER_BASE
#define MEMORYCOPYREADER_BASE() \
private: \
typedef athena::io::MemoryCopyReader base
#endif // MEMORYCOPYREADER_BASE
#endif // MEMORYREADER_HPP

View File

@ -161,16 +161,4 @@ private:
}
}
#ifndef MEMORYWRITER_BASE
#define MEMORYWRITER_BASE() \
private: \
typedef athena::io::MemoryWriter base
#endif // BINARYWRITER_BASE
#ifndef MEMORYCOPYWRITER_BASE
#define MEMORYCOPYWRITER_BASE() \
private: \
typedef athena::io::MemoryCopyWriter base
#endif // BINARYWRITER_BASE
#endif // MEMORYWRITER_HPP

View File

@ -10,7 +10,6 @@ namespace io
{
class SkywardSwordFileReader : public MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
SkywardSwordFileReader(atUint8* data, atUint64 length);

View File

@ -12,7 +12,6 @@ namespace io
class SkywardSwordFileWriter : public MemoryCopyWriter
{
MEMORYCOPYWRITER_BASE();
public:
SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(const std::string& filename);

View File

@ -15,7 +15,6 @@ namespace io
class SpriteFileReader : public MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(const std::string& filepath);

View File

@ -23,7 +23,6 @@ namespace io
*/
class WiiSaveReader : public MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
/*! \brief This constructor takes an existing buffer to read from.
*

View File

@ -22,7 +22,6 @@ namespace io
*/
class WiiSaveWriter : protected MemoryCopyWriter
{
MEMORYCOPYWRITER_BASE();
public:
/*! \brief This constructor creates an instance from a file on disk.
*

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena 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.
//
// libAthena 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 libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef ZQUEST_HPP
#define ZQUEST_HPP

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena 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.
//
// libAthena 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 libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ZQUESTFILEREADER_HPP__
#define __ZQUESTFILEREADER_HPP__
@ -31,7 +16,6 @@ namespace io
*/
class ZQuestFileReader : protected MemoryCopyReader
{
MEMORYCOPYREADER_BASE();
public:
/*!

View File

@ -1,19 +1,4 @@
#ifndef ATHENA_NO_ZQUEST
// This file is part of libAthena.
//
// libAthena 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.
//
// libAthena 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 libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ZQUESTFILEWRITER_HPP__
#define __ZQUESTFILEWRITER_HPP__
@ -31,8 +16,6 @@ namespace io
*/
class ZQuestFileWriter : protected MemoryCopyWriter
{
MEMORYCOPYWRITER_BASE();
public:
/*!
* \brief ZQuestFileWriter

View File

@ -52,22 +52,22 @@ ALTTPFile* ALTTPFileReader::readFile()
quest->setOverworldEvents(owEvents);
quest->setInventory(*(ALTTPInventory*)base::readBytes(sizeof(ALTTPInventory)).get());
quest->setRupeeMax(base::readUint16());
quest->setRupeeCurrent(base::readUint16());
quest->setInventory(*(ALTTPInventory*)readBytes(sizeof(ALTTPInventory)).get());
quest->setRupeeMax(readUint16());
quest->setRupeeCurrent(readUint16());
quest->setCompasses(readDungeonFlags());
quest->setBigKeys(readDungeonFlags());
quest->setDungeonMaps(readDungeonFlags());
quest->setWishingPond(base::readUint16());
quest->setHealthMax(base::readByte());
quest->setHealth(base::readByte());
quest->setMagicPower(base::readByte());
quest->setKeys(base::readByte());
quest->setBombUpgrades(base::readByte());
quest->setArrowUpgrades(base::readByte());
quest->setHealthFiller(base::readByte());
quest->setMagicFiller(base::readByte());
atUint8 pendantsByte = base::readUByte();
quest->setWishingPond(readUint16());
quest->setHealthMax(readByte());
quest->setHealth(readByte());
quest->setMagicPower(readByte());
quest->setKeys(readByte());
quest->setBombUpgrades(readByte());
quest->setArrowUpgrades(readByte());
quest->setHealthFiller(readByte());
quest->setMagicFiller(readByte());
atUint8 pendantsByte = readUByte();
ALTTPPendants pendants;
pendants.Courage = pendantsByte & 1;
pendants.Wisdom = (pendantsByte >> 1) & 1;
@ -78,11 +78,11 @@ ALTTPFile* ALTTPFileReader::readFile()
pendants.Unused4 = false;
pendants.Unused5 = false;
quest->setPendants(pendants);
quest->setBombFiller(base::readByte());
quest->setArrowFiller(base::readByte());
quest->setArrows(base::readByte());
base::seek(1);
atUint8 abilitiesByte = base::readUByte();
quest->setBombFiller(readByte());
quest->setArrowFiller(readByte());
quest->setArrows(readByte());
seek(1);
atUint8 abilitiesByte = readUByte();
ALTTPAbilities abilities;
abilities.Nothing = abilitiesByte & 1;
abilities.Swim = (abilitiesByte >> 1) & 1;
@ -93,42 +93,42 @@ ALTTPFile* ALTTPFileReader::readFile()
abilities.Read = (abilitiesByte >> 6) & 1;
abilities.Unknown2 = (abilitiesByte >> 7) & 1;
quest->setAbilityFlags(abilities);
quest->setCrystals(*(ALTTPCrystals*)base::readBytes(sizeof(ALTTPCrystals)).get());
quest->setMagicUsage(*(ALTTPMagicUsage*)base::readBytes(sizeof(ALTTPMagicUsage)).get());
quest->setCrystals(*(ALTTPCrystals*)readBytes(sizeof(ALTTPCrystals)).get());
quest->setMagicUsage(*(ALTTPMagicUsage*)readBytes(sizeof(ALTTPMagicUsage)).get());
j = 0x10;
while ((j--) > 0)
{
dungeonKeys.push_back(base::readByte());
dungeonKeys.push_back(readByte());
}
quest->setDungeonKeys(dungeonKeys);
base::seek(0x039);
quest->setProgressIndicator((ALTTPProgressIndicator)base::readByte());
quest->setProgressFlags1(*(ALTTPProgressFlags1*)base::readBytes(sizeof(ALTTPProgressFlags1)).get());
quest->setMapIcon((ALTTPMapIcon)base::readByte());
quest->setStartLocation((ALTTPStartLocation)base::readByte());
quest->setProgressFlags2(*(ALTTPProgressFlags2*)base::readBytes(sizeof(ALTTPProgressFlags2)).get());
quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)base::readBytes(1).get());
base::seek(1);
quest->setTagAlong((ALTTPTagAlong)base::readByte());
seek(0x039);
quest->setProgressIndicator((ALTTPProgressIndicator)readByte());
quest->setProgressFlags1(*(ALTTPProgressFlags1*)readBytes(sizeof(ALTTPProgressFlags1)).get());
quest->setMapIcon((ALTTPMapIcon)readByte());
quest->setStartLocation((ALTTPStartLocation)readByte());
quest->setProgressFlags2(*(ALTTPProgressFlags2*)readBytes(sizeof(ALTTPProgressFlags2)).get());
quest->setLightDarkWorldIndicator(*(ALTTPLightDarkWorldIndicator*)readBytes(1).get());
seek(1);
quest->setTagAlong((ALTTPTagAlong)readByte());
j = 6;
while ((j--) > 0)
{
oldmanFlags.push_back(base::readByte());
oldmanFlags.push_back(readByte());
}
quest->setOldManFlags(oldmanFlags);
quest->setBombFlag(base::readByte());
quest->setBombFlag(readByte());
j = 5;
while ((j--) > 0)
{
unknown1.push_back(base::readByte());
unknown1.push_back(readByte());
}
quest->setUnknown1(unknown1);
@ -137,28 +137,28 @@ ALTTPFile* ALTTPFileReader::readFile()
while ((j--) > 0)
{
playerName.push_back(base::readUint16());
playerName.push_back(readUint16());
}
quest->setPlayerName(playerName);
quest->setValid((base::readUint16() == 0x55AA));
quest->setValid((readUint16() == 0x55AA));
j = 0x0D;
while ((j--) > 0)
{
dungeonDeaths.push_back(base::readUint16());
dungeonDeaths.push_back(readUint16());
}
quest->setDungeonDeathTotals(dungeonDeaths);
quest->setUnknown2(base::readUint16());
quest->setDeathSaveCount(base::readUint16());
quest->setPostGameDeathCounter(base::readInt16());
quest->setUnknown2(readUint16());
quest->setDeathSaveCount(readUint16());
quest->setPostGameDeathCounter(readInt16());
base::seek(0xF7);
seek(0xF7);
quest->setChecksum(base::readUint16());
quest->setChecksum(readUint16());
if (i < 3)
quests.push_back(quest);
@ -172,7 +172,7 @@ ALTTPFile* ALTTPFileReader::readFile()
ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
{
ALTTPRoomFlags* flags = new ALTTPRoomFlags;
atUint8 flagsByte = base::readUByte();
atUint8 flagsByte = readUByte();
flags->Chest1 = flagsByte & 1;
flags->Chest2 = (flagsByte >> 1) & 1;
flags->Chest3 = (flagsByte >> 2) & 1;
@ -181,7 +181,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
flags->Quadrant2 = (flagsByte >> 5) & 1;
flags->Quadrant3 = (flagsByte >> 6) & 1;
flags->Quadrant4 = (flagsByte >> 7) & 1;
flagsByte = base::readUByte();
flagsByte = readUByte();
flags->Door1 = flagsByte & 1;
flags->Door2 = (flagsByte >> 1) & 1;
flags->Door3 = (flagsByte >> 2) & 1;
@ -197,7 +197,7 @@ ALTTPRoomFlags* ALTTPFileReader::readRoomFlags()
ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent()
{
ALTTPOverworldEvent* event = new ALTTPOverworldEvent;
atUint8 flagsByte = base::readUByte();
atUint8 flagsByte = readUByte();
event->Unused1 = flagsByte & 1;
event->HeartPiece = (flagsByte >> 1) & 1;
event->Overlay = (flagsByte >> 2) & 1;
@ -212,7 +212,7 @@ ALTTPOverworldEvent* ALTTPFileReader::readOverworldEvent()
ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
{
ALTTPDungeonItemFlags flags;
atUint8 flagsByte = base::readUByte();
atUint8 flagsByte = readUByte();
flags.Unused1 = flagsByte & 1;
flags.Unused2 = (flagsByte >> 1) & 1;
flags.GanonsTower = (flagsByte >> 2) & 1;
@ -221,7 +221,7 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
flags.TowerOfHera = (flagsByte >> 5) & 1;
flags.IcePalace = (flagsByte >> 6) & 1;
flags.SkullWoods = (flagsByte >> 7) & 1;
flagsByte = base::readUByte();
flagsByte = readUByte();
flags.MiseryMire = flagsByte & 1;
flags.DarkPalace = (flagsByte >> 1) & 1;
flags.SwampPalace = (flagsByte >> 2) & 1;

View File

@ -40,31 +40,31 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
writeOverworldEvent(quest->overworldEvent(j));
}
base::writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory));
base::writeUint16(quest->rupeeMax());
base::writeUint16(quest->rupeeCurrent());
writeBytes((atInt8*)&quest->inventory(), sizeof(ALTTPInventory));
writeUint16(quest->rupeeMax());
writeUint16(quest->rupeeCurrent());
writeDungeonItems(quest->compasses());
writeDungeonItems(quest->bigKeys());
writeDungeonItems(quest->dungeonMaps());
base::writeUint16(quest->wishingPond());
base::writeByte(quest->healthMax());
base::writeByte(quest->health());
base::writeByte(quest->magicPower());
base::writeByte(quest->keys());
base::writeByte(quest->bombUpgrades());
base::writeByte(quest->arrowUpgrades());
base::writeByte(quest->healthFiller());
base::writeByte(quest->magicFiller());
writeUint16(quest->wishingPond());
writeByte(quest->healthMax());
writeByte(quest->health());
writeByte(quest->magicPower());
writeByte(quest->keys());
writeByte(quest->bombUpgrades());
writeByte(quest->arrowUpgrades());
writeByte(quest->healthFiller());
writeByte(quest->magicFiller());
ALTTPPendants pendants = quest->pendants();
atUint8 pendantsByte = 0;
pendantsByte |= pendants.Courage;
pendantsByte |= pendants.Wisdom << 1;
pendantsByte |= pendants.Power << 2;
base::writeUByte(pendantsByte);
base::writeByte(quest->bombFiller());
base::writeByte(quest->arrowFiller());
base::writeByte(quest->arrows());
base::seek(1);
writeUByte(pendantsByte);
writeByte(quest->bombFiller());
writeByte(quest->arrowFiller());
writeByte(quest->arrows());
seek(1);
ALTTPAbilities abilities = quest->abilityFlags();
atUint8 abilitiesByte = 0;
abilitiesByte |= abilities.Nothing;
@ -75,51 +75,51 @@ void ALTTPFileWriter::writeFile(ALTTPFile* file)
abilitiesByte |= abilities.Talk << 5;
abilitiesByte |= abilities.Read << 6;
abilitiesByte |= abilities.Unknown2 << 7;
base::writeUByte(abilitiesByte);
writeUByte(abilitiesByte);
ALTTPCrystals crystals = quest->crystals();
base::writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals));
writeBytes((atInt8*)&crystals, sizeof(ALTTPCrystals));
ALTTPMagicUsage magicUsage = quest->magicUsage();
base::writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage));
writeBytes((atInt8*)&magicUsage, sizeof(ALTTPMagicUsage));
for (int j = 0; j < 0x010; j++)
base::writeByte(quest->dungeonKeys(j));
writeByte(quest->dungeonKeys(j));
base::seek(0x039);
base::writeByte((atInt8)quest->progressIndicator());
seek(0x039);
writeByte((atInt8)quest->progressIndicator());
ALTTPProgressFlags1 progress1 = quest->progressFlags1();
base::writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1));
base::writeByte(quest->mapIcon());
base::writeByte(quest->startLocation());
writeBytes((atInt8*)&progress1, sizeof(ALTTPProgressFlags1));
writeByte(quest->mapIcon());
writeByte(quest->startLocation());
ALTTPProgressFlags2 progress2 = quest->progressFlags2();
base::writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2));
writeBytes((atInt8*)&progress2, sizeof(ALTTPProgressFlags2));
ALTTPLightDarkWorldIndicator indicator = quest->lightDarkWorldIndicator();
base::writeBytes((atInt8*)&indicator, 1);
base::seek(1);
base::writeByte(quest->tagAlong());
writeBytes((atInt8*)&indicator, 1);
seek(1);
writeByte(quest->tagAlong());
for (int j = 0; j < 6; j++)
base::writeByte(quest->oldManFlag(j));
writeByte(quest->oldManFlag(j));
base::writeByte(quest->bombFlag());
writeByte(quest->bombFlag());
for (int j = 0; j < 5; j++)
base::writeByte(quest->unknown1(j));
writeByte(quest->unknown1(j));
for (int j = 0; j < 6; j++)
base::writeUint16(quest->playerName()[j]);
writeUint16(quest->playerName()[j]);
base::writeUint16((quest->valid() == true ? 0x55AA : 0));
writeUint16((quest->valid() == true ? 0x55AA : 0));
for (int j = 0; j < 0x0D; j++)
base::writeUint16(quest->dungeonDeathTotal(j));
writeUint16(quest->dungeonDeathTotal(j));
base::writeUint16(quest->unknown2());
base::writeUint16(quest->deathSaveCount());
base::writeUint16(quest->postGameDeathCounter());
writeUint16(quest->unknown2());
writeUint16(quest->deathSaveCount());
writeUint16(quest->postGameDeathCounter());
base::seek(0xF7);
base::writeUint16(calculateChecksum(i));
seek(0xF7);
writeUint16(calculateChecksum(i));
}
}
@ -134,7 +134,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags)
flagsByte |= flags->Quadrant2 << 5;
flagsByte |= flags->Quadrant3 << 6;
flagsByte |= flags->Quadrant4 << 7;
base::writeUByte(flagsByte);
writeUByte(flagsByte);
flagsByte = 0;
flagsByte |= flags->Door1;
flagsByte |= flags->Door2 << 1;
@ -144,7 +144,7 @@ void ALTTPFileWriter::writeRoomFlags(ALTTPRoomFlags* flags)
flagsByte |= flags->Key << 5;
flagsByte |= flags->KeyOrChest << 6;
flagsByte |= flags->ChestOrTile << 7;
base::writeUByte(flagsByte);
writeUByte(flagsByte);
}
void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event)
@ -158,7 +158,7 @@ void ALTTPFileWriter::writeOverworldEvent(ALTTPOverworldEvent* event)
flagsByte |= event->Unused4 << 5;
flagsByte |= event->Set << 6;
flagsByte |= event->Unused5 << 7;
base::writeUByte(flagsByte);
writeUByte(flagsByte);
}
void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
@ -172,7 +172,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
flagsByte |= flags.IcePalace << 5;
flagsByte |= flags.SkullWoods << 6;
flagsByte |= flags.MiseryMire << 7;
base::writeUByte(flagsByte);
writeUByte(flagsByte);
flagsByte = 0;
flagsByte |= flags.DarkPalace;
flagsByte |= flags.SwampPalace << 1;
@ -181,7 +181,7 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
flagsByte |= flags.EasternPalace << 4;
flagsByte |= flags.HyruleCastle << 5;
flagsByte |= flags.SewerPassage << 6;
base::writeUByte(flagsByte);
writeUByte(flagsByte);
}
atUint16 ALTTPFileWriter::calculateChecksum(atUint32 game)

View File

@ -19,11 +19,11 @@ MCFileReader::MCFileReader(const std::string& filename)
MCFile* MCFileReader::readFile()
{
bool isScrambled = base::readUint32() != SCRAMBLE_VALUE;
base::m_position = 0;
bool isScrambled = readUint32() != SCRAMBLE_VALUE;
m_position = 0;
if (isScrambled)
MCFile::unscramble(base::m_dataCopy.get(), base::m_length);
MCFile::unscramble(m_dataCopy.get(), m_length);
return nullptr;
}

View File

@ -11,26 +11,26 @@ namespace io
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length)
: base(data, length)
{
base::setEndian(Endian::BigEndian);
setEndian(Endian::BigEndian);
}
SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
: base(filename)
{
base::setEndian(Endian::BigEndian);
setEndian(Endian::BigEndian);
}
SkywardSwordFile* SkywardSwordFileReader::read()
{
SkywardSwordFile* file = NULL;
if (base::length() != 0xFBE0)
if (length() != 0xFBE0)
{
atError("File not the expected size of 0xFBE0");
return nullptr;
}
atUint32 magic = base::readUint32();
atUint32 magic = readUint32();
if (magic != SkywardSwordFile::USMagic && magic != SkywardSwordFile::JAMagic && magic != SkywardSwordFile::EUMagic)
{
@ -38,8 +38,8 @@ SkywardSwordFile* SkywardSwordFileReader::read()
return nullptr;
}
base::seek(0x01C, SeekOrigin::Begin);
atUint32 headerSize = base::readUint32(); // Seems to be (headerSize - 1)
seek(0x01C, SeekOrigin::Begin);
atUint32 headerSize = readUint32(); // Seems to be (headerSize - 1)
if (headerSize != 0x1D)
{
@ -53,12 +53,12 @@ SkywardSwordFile* SkywardSwordFileReader::read()
for (int i = 0; i < 3; i++)
{
SkywardSwordQuest* q = new SkywardSwordQuest(base::readUBytes(0x53C0), 0x53C0);
atUint64 pos = base::position();
SkywardSwordQuest* q = new SkywardSwordQuest(readUBytes(0x53C0), 0x53C0);
atUint64 pos = position();
// seek to the skip data for this particular quest
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
q->setSkipData(base::readUBytes(0x24));
base::seek(pos, SeekOrigin::Begin);
seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
q->setSkipData(readUBytes(0x24));
seek(pos, SeekOrigin::Begin);
file->addQuest(q);
}

View File

@ -10,13 +10,13 @@ namespace io
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len)
: base(data, len)
{
base::setEndian(Endian::BigEndian);
setEndian(Endian::BigEndian);
}
SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename)
: base(filename)
{
base::setEndian(Endian::BigEndian);
setEndian(Endian::BigEndian);
}
void SkywardSwordFileWriter::write(SkywardSwordFile* file)
@ -30,9 +30,9 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file)
atUint32 magic = (file->region() == Region::NTSC ? SkywardSwordFile::USMagic :
(file->region() == Region::NTSCJ ? SkywardSwordFile::JAMagic : SkywardSwordFile::EUMagic));
base::writeUint32(magic);
base::seek(0x1C, SeekOrigin::Begin);
base::writeUint32(0x1D);
writeUint32(magic);
seek(0x1C, SeekOrigin::Begin);
writeUint32(0x1D);
std::vector<SkywardSwordQuest*> quests = file->questList();
int i = 0;
@ -48,17 +48,17 @@ void SkywardSwordFileWriter::write(SkywardSwordFile* file)
// Update the checksums
q->fixChecksums();
// Write the save data
base::writeUBytes(q->data(), q->length());
atUint64 pos = base::position();
writeUBytes(q->data(), q->length());
atUint64 pos = position();
// Write the slots skip data
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
base::writeUBytes(q->skipData(), 0x24);
base::seek(pos, SeekOrigin::Begin);
seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
writeUBytes(q->skipData(), 0x24);
seek(pos, SeekOrigin::Begin);
i++;
}
// write those padding bytes
base::seek(0xFBE0, SeekOrigin::Begin);
seek(0xFBE0, SeekOrigin::Begin);
save();
}

View File

@ -24,7 +24,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{
Sakura::SpriteFile* ret = NULL;
atUint32 magic = base::readUint32();
atUint32 magic = readUint32();
if (magic != Sakura::SpriteFile::Magic)
{
@ -32,7 +32,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
return nullptr;
}
atUint32 version = base::readUint32();
atUint32 version = readUint32();
// TODO: Make this more verbose
if (version != Sakura::SpriteFile::Version)
@ -46,13 +46,13 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
// Such as the texture count, it's dimensions, and it's origin.
// After that we have the number of sprites contained in this
// sprite container.
atUint16 textureCount = base::readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
atUint16 textureCount = readUint16(); // Having it as a Uint16 gives us the ability to have up to 65536 different states
// This is probably overkill, but it's better safe than sorry.
atUint32 width = base::readUint32();
atUint32 height = base::readUint32();
float originX = base::readFloat();
float originY = base::readFloat();
atUint16 spriteCount = base::readUint16();
atUint32 width = readUint32();
atUint32 height = readUint32();
float originX = readFloat();
float originY = readFloat();
atUint16 spriteCount = readUint16();
// Lets go ahead and create or new container.
ret = new Sakura::SpriteFile(width, height, originX, originY);
@ -62,7 +62,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
// to migrate this code to Big Endian based systems, such as the wii
// which require data to be 32 byte aligned, or it causes some issues.
// It's also convenient to have this, for later expansion.
atUint32 reserved = base::readUint32();
atUint32 reserved = readUint32();
UNUSED(reserved);
// Next we have to load the textures
@ -79,8 +79,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
for (atUint16 i = 0; i < textureCount; i++)
{
Sakura::STexture* texture = new Sakura::STexture;
texture->Filepath = base::readString();
texture->Preload = base::readBool();
texture->Filepath = readString();
texture->Preload = readBool();
textures.push_back(texture);
}
@ -102,19 +102,19 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{
Sakura::Sprite* sprite = new Sakura::Sprite(ret);
#ifndef ATHENA_USE_QT
std::string name = base::readString();
std::string name = readString();
#else
QString name = QString::fromStdString(base::readString());
QString name = QString::fromStdString(readString());
#endif
sprite->setName(name);
atUint16 frameCount = base::readUint16();
atUint16 stateCount = base::readUint16();
atUint16 frameCount = readUint16();
atUint16 stateCount = readUint16();
// Each state id corresponds to a texture held in the parent class
std::vector<int> stateIds;
for (int j = 0; j < stateCount; j++)
stateIds.push_back(base::readUint16());
stateIds.push_back(readUint16());
sprite->setStateIds(stateIds);
@ -135,8 +135,8 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
for (atUint32 k = 0; k < frameCount; k++)
{
Sakura::SpriteFrame* frame = new Sakura::SpriteFrame(sprite);
frame->setFrameTime(base::readFloat());
atUint16 partCount = base::readUint16();
frame->setFrameTime(readFloat());
atUint16 partCount = readUint16();
#ifndef ATHENA_USE_QT
@ -149,25 +149,25 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
{
Sakura::SpritePart* part = new Sakura::SpritePart(frame);
#ifndef ATHENA_USE_QT
std::string name = base::readString();
std::string name = readString();
#else
QString name = QString::fromStdString(base::readString());
QString name = QString::fromStdString(readString());
#endif
part->setName(name);
part->setCollision(base::readBool());
part->setCollision(readBool());
float xOff = base::readFloat();
float yOff = base::readFloat();
float xOff = readFloat();
float yOff = readFloat();
part->setOffset(xOff, yOff);
float texXOff = base::readFloat();
float texYOff = base::readFloat();
float texXOff = readFloat();
float texYOff = readFloat();
part->setTextureOffset(texXOff, texYOff);
atUint32 width = base::readUint32();
atUint32 height = base::readUint32();
atUint32 width = readUint32();
atUint32 height = readUint32();
part->setSize(width, height);
bool flippedH = base::readBool();
bool flippedH = readBool();
part->setFlippedHorizontally(flippedH);
bool flippedV = base::readBool();
bool flippedV = readBool();
part->setFlippedVertically(flippedV);
parts.push_back(part);

View File

@ -20,13 +20,13 @@ namespace io
{
WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length)
: base(data, length)
: MemoryCopyReader(data, length)
{
setEndian(Endian::BigEndian);
}
WiiSaveReader::WiiSaveReader(const std::string& filename)
: base(filename)
: MemoryCopyReader(filename)
{
setEndian(Endian::BigEndian);
}
@ -50,7 +50,7 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
}
ret->setBanner(banner);
atUint32 bkVer = base::readUint32();
atUint32 bkVer = readUint32();
if (bkVer != 0x00000070)
{
@ -58,7 +58,7 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
return nullptr;
}
atUint32 bkMagic = base::readUint32();
atUint32 bkMagic = readUint32();
if (bkMagic != 0x426B0001)
{
@ -66,18 +66,18 @@ std::unique_ptr<WiiSave> WiiSaveReader::readSave()
return nullptr;
}
/*atUint32 ngId =*/ base::readUint32();
atUint32 numFiles = base::readUint32();
/*atUint32 ngId =*/ readUint32();
atUint32 numFiles = readUint32();
/*int fileSize =*/ base::readUint32();
base::seek(8); // skip unknown data;
/*int fileSize =*/ readUint32();
seek(8); // skip unknown data;
atUint32 totalSize = base::readUint32();
base::seek(64); // Unknown (Most likely padding)
base::seek(8);
base::seek(6);
base::seek(2);
base::seek(0x10);
atUint32 totalSize = readUint32();
seek(64); // Unknown (Most likely padding)
seek(8);
seek(6);
seek(2);
seek(0x10);
std::vector<WiiFile*> files;
@ -99,10 +99,10 @@ WiiBanner* WiiSaveReader::readBanner()
{
atUint8* dec = new atUint8[0xF0C0];
memset(dec, 0, 0xF0C0);
std::unique_ptr<atUint8[]> data = base::readUBytes(0xF0C0);
atUint8* oldData = base::data();
atUint64 oldPos = base::position();
atUint64 oldLen = base::length();
std::unique_ptr<atUint8[]> buf = readUBytes(0xF0C0);
atUint8* oldData = data();
atUint64 oldPos = position();
atUint64 oldLen = length();
atUint64 gameId;
atUint32 bannerSize;
atUint8 permissions;
@ -114,7 +114,7 @@ WiiBanner* WiiSaveReader::readBanner()
std::cout << "Decrypting: banner.bin...";
std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY);
aes->decrypt(tmpIV, data.get(), dec, 0xF0C0);
aes->decrypt(tmpIV, buf.get(), dec, 0xF0C0);
std::cout << "done" << std::endl;
memset(md5, 0, 16);
@ -144,22 +144,22 @@ WiiBanner* WiiSaveReader::readBanner()
std::cerr << std::hex << (int)(md5Calc[i]);
std::cerr << std::endl;
base::setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin);
setData(oldData, oldLen);
seek(oldPos, SeekOrigin::Begin);
atError("MD5 Mismatch");
return nullptr;
}
// Set the binary reader buffer;
base::setData(dec, 0xF0C0);
setData(dec, 0xF0C0);
// Start reading the header
gameId = base::readUint64();
bannerSize = base::readUint32();
permissions = base::readByte();
/* unk =*/ base::readByte();
base::seek(0x10);
gameId = readUint64();
bannerSize = readUint32();
permissions = readByte();
/* unk =*/ readByte();
seek(0x10);
// skip padding
base::seek(2);
seek(2);
int magic;
int flags;
@ -167,31 +167,31 @@ WiiBanner* WiiSaveReader::readBanner()
std::string gameTitle;
std::string subTitle;
magic = base::readUint32();
magic = readUint32();
// Ensure that the header magic is valid.
if (magic != 0x5749424E)
{
// Make sure to reset m_reader values back to the old ones.
base::setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin);
setData(oldData, oldLen);
seek(oldPos, SeekOrigin::Begin);
atError("Invalid Header Magic");
return nullptr;
}
flags = base::readUint32();
animSpeed = base::readUint16();
base::seek(22);
flags = readUint32();
animSpeed = readUint16();
seek(22);
gameTitle = base::readWStringAsString();
gameTitle = readWStringAsString();
if (base::position() != 0x0080)
base::seek(0x0080, SeekOrigin::Begin);
if (position() != 0x0080)
seek(0x0080, SeekOrigin::Begin);
subTitle = base::readWStringAsString();
subTitle = readWStringAsString();
if (base::position() != 0x00C0)
base::seek(0x00C0, SeekOrigin::Begin);
if (position() != 0x00C0)
seek(0x00C0, SeekOrigin::Begin);
WiiBanner* banner = new WiiBanner;
banner->setGameID(gameId);
@ -227,14 +227,14 @@ WiiBanner* WiiSaveReader::readBanner()
}
}
base::setData(oldData, oldLen);
base::seek(oldPos, SeekOrigin::Begin);
setData(oldData, oldLen);
seek(oldPos, SeekOrigin::Begin);
return banner;
}
WiiImage* WiiSaveReader::readImage(atUint32 width, atUint32 height)
{
std::unique_ptr<atUint8[]> image = base::readUBytes(width * height * 2);
std::unique_ptr<atUint8[]> image = readUBytes(width * height * 2);
if (!utility::isEmpty((atInt8*)image.get(), width * height * 2))
return new WiiImage(width, height, std::move(image));
@ -252,7 +252,7 @@ WiiFile* WiiSaveReader::readFile()
std::string name;
WiiFile* ret;
atUint32 magic = base::readUint32();
atUint32 magic = readUint32();
if (magic != 0x03adf17e)
{
@ -260,23 +260,23 @@ WiiFile* WiiSaveReader::readFile()
return NULL;
}
fileLen = base::readUint32();
permissions = base::readByte();
attributes = base::readByte();
type = (WiiFile::Type)base::readByte();
name = std::string((const char*)base::readBytes(0x45).get());
fileLen = readUint32();
permissions = readByte();
attributes = readByte();
type = (WiiFile::Type)readByte();
name = std::string((const char*)readBytes(0x45).get());
ret = new WiiFile(std::string(name));
ret->setPermissions(permissions);
ret->setAttributes(attributes);
ret->setType((WiiFile::Type)type);
std::unique_ptr<atUint8[]> iv = base::readUBytes(0x10);
base::seek(0x20);
std::unique_ptr<atUint8[]> iv = readUBytes(0x10);
seek(0x20);
if (type == WiiFile::File)
{
// Read file data
int roundedLen = (fileLen + 63) & ~63;
std::unique_ptr<atUint8[]> filedata = base::readUBytes(roundedLen);
std::unique_ptr<atUint8[]> filedata = readUBytes(roundedLen);
// Decrypt file
std::cout << "Decrypting: " << ret->filename() << "...";
@ -296,11 +296,11 @@ void WiiSaveReader::readCerts(atUint32 totalSize)
{
std::cout << "Reading certs..." << std::endl;
atUint32 dataSize = totalSize - 0x340;
std::unique_ptr<atUint8[]> sig = base::readUBytes(0x40);
std::unique_ptr<atUint8[]> ngCert = base::readUBytes(0x180);
std::unique_ptr<atUint8[]> apCert = base::readUBytes(0x180);
base::seek(0xF0C0, SeekOrigin::Begin);
std::unique_ptr<atUint8[]> data = base::readUBytes(dataSize);
std::unique_ptr<atUint8[]> sig = readUBytes(0x40);
std::unique_ptr<atUint8[]> ngCert = readUBytes(0x180);
std::unique_ptr<atUint8[]> apCert = readUBytes(0x180);
seek(0xF0C0, SeekOrigin::Begin);
std::unique_ptr<atUint8[]> data = readUBytes(dataSize);
atUint8* hash;
std::cout << "validating..." << std::endl;

View File

@ -28,9 +28,9 @@ namespace io
{
WiiSaveWriter::WiiSaveWriter(const std::string& filename)
: base(filename)
: MemoryCopyWriter(filename)
{
base::setEndian(Endian::BigEndian);
setEndian(Endian::BigEndian);
}
@ -47,18 +47,18 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
writeBanner(save->banner());
base::writeUint32(0x70);
base::writeUint32(0x426B0001);
base::writeUint32(ngId); // NG-ID
base::writeUint32(save->fileCount());
base::writeUint32(0); // Size of files;
base::seek(8);
base::writeUint32(0); // totalSize
base::seek(64);
base::writeUint64(save->banner()->gameID());
base::writeBytes((atInt8*)macAddress, 6);
base::seek(2); // unknown;
base::seek(0x10); // padding;
writeUint32(0x70);
writeUint32(0x426B0001);
writeUint32(ngId); // NG-ID
writeUint32(save->fileCount());
writeUint32(0); // Size of files;
seek(8);
writeUint32(0); // totalSize
seek(64);
writeUint64(save->banner()->gameID());
writeBytes((atInt8*)macAddress, 6);
seek(2); // unknown;
seek(0x10); // padding;
atUint32 totalSize = 0;
for (WiiFile* file : save->allFiles())
@ -66,47 +66,47 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
totalSize += writeFile(file);
}
atUint64 pos = base::position();
atUint64 pos = position();
// Write size data
base::seek(0xF0C0 + 0x10, SeekOrigin::Begin);
base::writeUint32(totalSize);
base::seek(0xF0C0 + 0x1C, SeekOrigin::Begin);
base::writeUint32(totalSize + 0x3c0);
base::seek(pos, SeekOrigin::Begin);
seek(0xF0C0 + 0x10, SeekOrigin::Begin);
writeUint32(totalSize);
seek(0xF0C0 + 0x1C, SeekOrigin::Begin);
writeUint32(totalSize + 0x3c0);
seek(pos, SeekOrigin::Begin);
writeCerts(totalSize, ngId, ngPriv, ngSig, ngKeyId);
base::save();
this->save();
return true;
}
void WiiSaveWriter::writeBanner(WiiBanner* banner)
{
base::setEndian(Endian::BigEndian);
base::writeInt64(banner->gameID());
base::writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size());
base::writeByte((atInt8)banner->permissions());
base::seek(1);
base::writeBytes((atInt8*)MD5_BLANKER, 16);
base::seek(2);
base::writeInt32(0x5749424E); // WIBN
base::writeInt32(banner->flags());
base::writeInt16(banner->animationSpeed());
base::seek(22);
setEndian(Endian::BigEndian);
writeInt64(banner->gameID());
writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size());
writeByte((atInt8)banner->permissions());
seek(1);
writeBytes((atInt8*)MD5_BLANKER, 16);
seek(2);
writeInt32(0x5749424E); // WIBN
writeInt32(banner->flags());
writeInt16(banner->animationSpeed());
seek(22);
base::writeStringAsWString(banner->title());
writeStringAsWString(banner->title());
if (base::position() != 0x0080)
base::seek(0x0080, SeekOrigin::Begin);
if (position() != 0x0080)
seek(0x0080, SeekOrigin::Begin);
base::writeStringAsWString(banner->subtitle());
writeStringAsWString(banner->subtitle());
if (base::position() != 0x00C0)
base::seek(0x00C0, SeekOrigin::Begin);
if (position() != 0x00C0)
seek(0x00C0, SeekOrigin::Begin);
WiiImage* bannerImage = banner->bannerImage();
base::writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height() * 2);
writeBytes((atInt8*)bannerImage->data(), bannerImage->width()*bannerImage->height() * 2);
// For empty icons
atUint8* tmpIcon = new atUint8[48 * 48 * 2];
@ -120,28 +120,28 @@ void WiiSaveWriter::writeBanner(WiiBanner* banner)
}
else
{
base::writeBytes((atInt8*)tmpIcon, 48 * 48 * 2);
writeBytes((atInt8*)tmpIcon, 48 * 48 * 2);
}
}
delete[] tmpIcon; // delete tmp buffer;
atUint8* hash = new atUint8[0x10];
MD5Hash::MD5(hash, (atUint8*)base::data(), 0xF0C0);
base::seek(0x0E, SeekOrigin::Begin);
base::writeBytes((atInt8*)hash, 0x10);
MD5Hash::MD5(hash, (atUint8*)data(), 0xF0C0);
seek(0x0E, SeekOrigin::Begin);
writeBytes((atInt8*)hash, 0x10);
std::unique_ptr<IAES> aes = NewAES();
aes->setKey(SD_KEY);
atUint8 data[0xF0C0];
memcpy(data, base::data(), 0xF0C0);
memcpy(data, this->data(), 0xF0C0);
atUint8 tmpIV[26];
memcpy(tmpIV, SD_IV, 16);
aes->encrypt(tmpIV, data, data, 0xF0C0);
base::seek(0, SeekOrigin::Begin);
base::writeBytes((atInt8*)data, 0xF0C0);
base::seek(0xF0C0, SeekOrigin::Begin);
seek(0, SeekOrigin::Begin);
writeBytes((atInt8*)data, 0xF0C0);
seek(0xF0C0, SeekOrigin::Begin);
}
atUint32 WiiSaveWriter::writeFile(WiiFile* file)
@ -149,23 +149,23 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
atUint32 ret = 0x80;
// Write the File magic
base::writeUint32(0x03ADF17E);
base::writeUint32(file->length());
base::writeByte(file->permissions());
base::writeByte(file->attributes());
base::writeByte(file->type());
writeUint32(0x03ADF17E);
writeUint32(file->length());
writeByte(file->permissions());
writeByte(file->attributes());
writeByte(file->type());
atUint8 name[0x45];
utility::fillRandom(name, 0x45);
memcpy(name, file->fullpath().c_str(), file->fullpath().size());
name[file->fullpath().size()] = '\0';
base::writeBytes((atInt8*)name, 0x45);
writeBytes((atInt8*)name, 0x45);
atUint8 iv[16];
utility::fillRandom(iv, 0x10);
base::writeBytes((atInt8*)iv, 0x10);
writeBytes((atInt8*)iv, 0x10);
atUint8 crap[0x20];
utility::fillRandom(crap, 0x20);
base::writeBytes((atInt8*)crap, 0x20);
writeBytes((atInt8*)crap, 0x20);
if (file->type() == WiiFile::File)
{
@ -177,7 +177,7 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
aes->setKey(SD_KEY);
aes->encrypt(iv, file->data(), data, roundedSize);
base::writeBytes((atInt8*)data, roundedSize);
writeBytes((atInt8*)data, roundedSize);
ret += roundedSize;
delete[] data;
}
@ -189,7 +189,7 @@ atUint32 WiiSaveWriter::writeFile(WiiFile* file)
void WiiSaveWriter::writeImage(WiiImage* image)
{
atInt8* data = (atInt8*)image->data();
base::writeBytes(data, image->width() * image->height() * 2);
writeBytes(data, image->width() * image->height() * 2);
}
void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPriv, atUint8* ngSig, atUint32 ngKeyId)
@ -202,7 +202,7 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
atUint8 apSig[60];
char signer[64];
char name[64];
atUint8* data;
atUint8* buf;
atUint32 dataSize;
sprintf(signer, "Root-CA00000001-MS00000002");
@ -224,14 +224,14 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
delete[] hash;
dataSize = filesSize + 0x80;
data = new atUint8[dataSize];
atUint8* rawData = base::data();
memcpy(data, rawData + 0xF0C0, dataSize);
buf = new atUint8[dataSize];
atUint8* rawData = data();
memcpy(buf, rawData + 0xF0C0, dataSize);
hash = getSha1(data, dataSize);
hash = getSha1(buf, dataSize);
atUint8* hash2 = getSha1(hash, 20);
delete[] hash;
delete[] data;
delete[] buf;
ecc::createECDSA(sig, sig + 30, apPriv, hash2);
int stuff = 0x2f536969;
@ -242,9 +242,9 @@ void WiiSaveWriter::writeCerts(atUint32 filesSize, atUint32 ngId, atUint8* ngPri
*(atUint32*)(sig + 60) = stuff;
delete[] hash2;
base::writeBytes((atInt8*)sig, 0x40);
base::writeBytes((atInt8*)ngCert, 0x180);
base::writeBytes((atInt8*)apCert, 0x180);
writeBytes((atInt8*)sig, 0x40);
writeBytes((atInt8*)ngCert, 0x180);
writeBytes((atInt8*)apCert, 0x180);
}
} // io

View File

@ -30,7 +30,7 @@ ZQuestFile* ZQuestFileReader::read()
atUint16 BOM;
atUint32 checksum = 0;
magic = base::readUint32();
magic = readUint32();
if ((magic & 0x00FFFFFF) != (ZQuestFile::Magic & 0x00FFFFFF))
{
@ -38,7 +38,7 @@ ZQuestFile* ZQuestFileReader::read()
return nullptr;
}
version = base::readUint32();
version = readUint32();
if (version > ZQuestFile::Version)
{
@ -46,12 +46,12 @@ ZQuestFile* ZQuestFileReader::read()
return nullptr;
}
compressedLen = base::readUint32();
uncompressedLen = base::readUint32();
compressedLen = readUint32();
uncompressedLen = readUint32();
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
{
gameString = std::string((const char*)base::readBytes(0x0A).get(), 0x0A);
gameString = std::string((const char*)readBytes(0x0A).get(), 0x0A);
for (size_t i = 0; i < ZQuestFile::gameStringList().size(); i++)
{
@ -63,17 +63,17 @@ ZQuestFile* ZQuestFileReader::read()
}
}
BOM = base::readUint16();
checksum = base::readUint32();
BOM = readUint16();
checksum = readUint32();
}
else
{
game = (ZQuestFile::Game)base::readUint32();
BOM = base::readUint16();
base::seek(0x0A);
game = (ZQuestFile::Game)readUint32();
BOM = readUint16();
seek(0x0A);
}
std::unique_ptr<atUint8[]> data = base::readUBytes(compressedLen); // compressedLen is always the total file size
std::unique_ptr<atUint8[]> data = readUBytes(compressedLen); // compressedLen is always the total file size
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
{

View File

@ -26,8 +26,8 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
return;
}
base::writeUint32(ZQuestFile::Magic);
base::writeUint32(ZQuestFile::Version);
writeUint32(ZQuestFile::Magic);
writeUint32(ZQuestFile::Version);
atUint8* questData = quest->data();
atUint32 compLen;
@ -44,28 +44,28 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
// Delete the compressed data since we won't be using it
delete[] compData;
compData = NULL;
base::writeUint32(quest->length());
writeUint32(quest->length());
}
else
{
// Don't do delete on data
questData = compData;
base::writeUint32(compLen);
writeUint32(compLen);
}
}
else
{
compLen = quest->length();
base::writeUint32(quest->length());
writeUint32(quest->length());
}
base::writeUint32(quest->length());
base::writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
base::writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
base::writeUint32(athena::Checksums::crc32(questData, compLen));
base::writeUBytes(questData, compLen);
writeUint32(quest->length());
writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
writeUint32(athena::Checksums::crc32(questData, compLen));
writeUBytes(questData, compLen);
base::save();
save();
// Delete compressed data to prevent memory leaks
if (questData != quest->data())