mirror of
https://github.com/libAthena/athena.git
synced 2025-12-12 14:46:12 +00:00
* Major rewrite
This commit is contained in:
75
src/Athena/SkywardSwordFileWriter.cpp
Normal file
75
src/Athena/SkywardSwordFileWriter.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// 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/>
|
||||
|
||||
#include "Athena/SkywardSwordFileWriter.hpp"
|
||||
#include "Athena/SkywardSwordFile.hpp"
|
||||
#include "Athena/SkywardSwordQuest.hpp"
|
||||
#include "Athena/InvalidOperationException.hpp"
|
||||
#include "Athena/InvalidDataException.hpp"
|
||||
|
||||
namespace Athena
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
SkywardSwordFileWriter::SkywardSwordFileWriter(Uint8 *data, Uint64 len)
|
||||
: base(data, len)
|
||||
{
|
||||
base::setEndian(Endian::BigEndian);
|
||||
}
|
||||
|
||||
SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string &filename)
|
||||
: base(filename)
|
||||
{
|
||||
base::setEndian(Endian::BigEndian);
|
||||
}
|
||||
|
||||
void SkywardSwordFileWriter::write(SkywardSwordFile *file)
|
||||
{
|
||||
if (!file)
|
||||
THROW_INVALID_OPERATION_EXCEPTION("file cannot be NULL");
|
||||
|
||||
Uint32 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);
|
||||
|
||||
std::vector<SkywardSwordQuest*> quests = file->questList();
|
||||
int i = 0;
|
||||
for (SkywardSwordQuest* q : quests)
|
||||
{
|
||||
if (q->length() != 0x53C0)
|
||||
THROW_INVALID_DATA_EXCEPTION("q->data() not 0x53C0 bytes in length");
|
||||
if (q->skipLength() != 0x24)
|
||||
THROW_INVALID_DATA_EXCEPTION("q->skipData() not 0x24 bytes in length");
|
||||
// Write the save data
|
||||
base::writeUBytes(q->data(), q->length());
|
||||
Uint64 pos = base::position();
|
||||
// Write the slots skip data
|
||||
base::seek(0xFB60 + (i * 0x24), SeekOrigin::Begin);
|
||||
base::writeUBytes(q->skipData(), q->skipLength());
|
||||
base::seek(pos, SeekOrigin::Begin);
|
||||
i++;
|
||||
}
|
||||
|
||||
// write those padding bytes
|
||||
base::seek(0xFBE0, SeekOrigin::Begin);
|
||||
save();
|
||||
}
|
||||
|
||||
} // io
|
||||
} // zelda
|
||||
Reference in New Issue
Block a user