2016-04-11 05:13:16 +00:00
|
|
|
#include <athena/Global.hpp>
|
|
|
|
#include <athena/IStreamReader.hpp>
|
|
|
|
#include <athena/IStreamWriter.hpp>
|
|
|
|
|
|
|
|
#include "FSM2.hpp"
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
namespace DataSpec::DNAFSM2
|
2016-04-11 05:13:16 +00:00
|
|
|
{
|
|
|
|
logvisor::Module LogDNAFSM2("urde::DNAFSM2");
|
|
|
|
|
|
|
|
template <class IDType>
|
2018-02-22 07:24:51 +00:00
|
|
|
template <class Op>
|
|
|
|
void FSM2<IDType>::Enumerate(typename Op::StreamT& s)
|
2016-04-11 05:13:16 +00:00
|
|
|
{
|
2018-02-22 07:24:51 +00:00
|
|
|
Do<Op>({"header"}, header, s);
|
2016-04-11 05:13:16 +00:00
|
|
|
if (header.magic != SBIG('FSM2'))
|
|
|
|
{
|
|
|
|
LogDNAFSM2.report(logvisor::Fatal, "Invalid FSM2 magic '%.4s' expected 'FSM2'", header.magic.toString().c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header.version == 1)
|
|
|
|
{
|
2018-02-22 07:24:51 +00:00
|
|
|
if (!detail)
|
|
|
|
detail.reset(new FSMV1);
|
|
|
|
Do<Op>({"detail"}, static_cast<FSMV1&>(*detail), s);
|
2016-04-11 05:13:16 +00:00
|
|
|
}
|
2018-02-22 07:24:51 +00:00
|
|
|
else if (header.version == 2)
|
2016-04-11 05:13:16 +00:00
|
|
|
{
|
2018-02-22 07:24:51 +00:00
|
|
|
if (!detail)
|
|
|
|
detail.reset(new FSMV2);
|
|
|
|
Do<Op>({"detail"}, static_cast<FSMV2&>(*detail), s);
|
2016-04-11 05:13:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogDNAFSM2.report(logvisor::Fatal, "Invalid FSM2 version '%i'", header.version);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 07:24:51 +00:00
|
|
|
AT_SPECIALIZE_DNA(FSM2<UniqueID32>)
|
|
|
|
AT_SPECIALIZE_DNA(FSM2<UniqueID64>)
|
2016-04-11 05:13:16 +00:00
|
|
|
|
2018-02-22 07:24:51 +00:00
|
|
|
template <>
|
|
|
|
const char* FSM2<UniqueID32>::DNAType() { return "urde::FSM2<UniqueID32>"; }
|
2016-04-11 05:13:16 +00:00
|
|
|
|
2018-02-22 07:24:51 +00:00
|
|
|
template <>
|
|
|
|
const char* FSM2<UniqueID64>::DNAType() { return "urde::FSM2<UniqueID64>"; }
|
2016-04-11 05:13:16 +00:00
|
|
|
|
|
|
|
template struct FSM2<UniqueID32>;
|
|
|
|
template struct FSM2<UniqueID64>;
|
|
|
|
|
|
|
|
template <class IDType>
|
|
|
|
bool ExtractFSM2(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
|
|
|
|
{
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileWriter writer(outPath.getAbsolutePath());
|
|
|
|
if (writer.isOpen())
|
2016-04-11 05:13:16 +00:00
|
|
|
{
|
|
|
|
FSM2<IDType> fsm2;
|
|
|
|
fsm2.read(rs);
|
2018-02-22 07:24:51 +00:00
|
|
|
athena::io::ToYAMLStream(fsm2, writer);
|
2016-04-11 05:13:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
template bool ExtractFSM2<UniqueID32>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
|
|
|
|
template bool ExtractFSM2<UniqueID64>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
|
|
|
|
|
|
|
|
template <class IDType>
|
|
|
|
bool WriteFSM2(const FSM2<IDType>& fsm2, const hecl::ProjectPath& outPath)
|
|
|
|
{
|
|
|
|
athena::io::FileWriter w(outPath.getAbsolutePath(), true, false);
|
|
|
|
if (w.hasError())
|
|
|
|
return false;
|
|
|
|
fsm2.write(w);
|
|
|
|
int64_t rem = w.position() % 32;
|
|
|
|
if (rem)
|
|
|
|
for (int64_t i=0 ; i<32-rem ; ++i)
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeUByte(0xff);
|
2016-04-11 05:13:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
template bool WriteFSM2<UniqueID32>(const FSM2<UniqueID32>& fsm2, const hecl::ProjectPath& outPath);
|
|
|
|
template bool WriteFSM2<UniqueID64>(const FSM2<UniqueID64>& fsm2, const hecl::ProjectPath& outPath);
|
|
|
|
|
|
|
|
}
|