metaforce/DataSpec/DNACommon/ELSC.cpp

503 lines
12 KiB
C++
Raw Normal View History

2016-03-08 20:49:44 -08:00
#include "ELSC.hpp"
2017-12-29 00:08:12 -08:00
namespace DataSpec::DNAParticle
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
2016-03-08 20:49:44 -08:00
template <class IDType>
2018-02-21 23:24:51 -08:00
void ELSM<IDType>::_read(athena::io::IStreamReader& r)
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
uint32_t clsId;
r.readBytesToBuf(&clsId, 4);
if (clsId != SBIG('ELSM'))
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
LogModule.report(logvisor::Warning, "non ELSM provided to ELSM parser");
return;
}
r.readBytesToBuf(&clsId, 4);
while (clsId != SBIG('_END'))
{
switch(clsId)
2016-03-08 20:49:44 -08:00
{
case SBIG('LIFE'):
x0_LIFE.read(r);
break;
case SBIG('SLIF'):
x4_SLIF.read(r);
break;
case SBIG('GRAT'):
x8_GRAT.read(r);
break;
case SBIG('SCNT'):
xc_SCNT.read(r);
break;
case SBIG('SSEG'):
x10_SSEG.read(r);
break;
case SBIG('COLR'):
x14_COLR.read(r);
break;
case SBIG('IEMT'):
x18_IEMT.read(r);
break;
case SBIG('FEMT'):
x1c_FEMT.read(r);
break;
case SBIG('AMPL'):
x20_AMPL.read(r);
break;
case SBIG('AMPD'):
x24_AMPD.read(r);
break;
case SBIG('LWD1'):
x28_LWD1.read(r);
break;
case SBIG('LWD2'):
x2c_LWD2.read(r);
break;
case SBIG('LWD3'):
x30_LWD3.read(r);
break;
case SBIG('LCL1'):
x34_LCL1.read(r);
break;
case SBIG('LCL2'):
x38_LCL2.read(r);
break;
case SBIG('LCL3'):
x3c_LCL3.read(r);
break;
case SBIG('SSWH'):
x40_SSWH.read(r);
break;
case SBIG('GPSM'):
x50_GPSM.read(r);
break;
case SBIG('EPSM'):
x60_EPSM.read(r);
break;
case SBIG('ZERY'):
x70_ZERY.read(r);
break;
2018-02-21 23:24:51 -08:00
default:
LogModule.report(logvisor::Fatal, "Unknown ELSM class %.4s @%" PRIi64, &clsId, r.position());
break;
2016-03-08 20:49:44 -08:00
}
2018-02-21 23:24:51 -08:00
r.readBytesToBuf(&clsId, 4);
2016-03-08 20:49:44 -08:00
}
}
template <class IDType>
2018-02-21 23:24:51 -08:00
void ELSM<IDType>::_write(athena::io::IStreamWriter& w) const
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
w.writeBytes((atInt8*)"ELSM", 4);
2016-03-08 20:49:44 -08:00
if (x0_LIFE)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LIFE", 4);
x0_LIFE.write(w);
}
2016-03-08 20:49:44 -08:00
if (x4_SLIF)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"SLIF", 4);
x4_SLIF.write(w);
}
2016-03-08 20:49:44 -08:00
if (x8_GRAT)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"GRAT", 4);
x8_GRAT.write(w);
}
2016-03-08 20:49:44 -08:00
if (xc_SCNT)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"SCNT", 4);
xc_SCNT.write(w);
}
2016-03-08 20:49:44 -08:00
if (x10_SSEG)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"SSEG", 4);
x10_SSEG.write(w);
}
2016-03-08 20:49:44 -08:00
if (x14_COLR)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"COLR", 4);
x14_COLR.write(w);
}
2016-03-08 20:49:44 -08:00
if (x18_IEMT)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"IEMT", 4);
x18_IEMT.write(w);
}
2016-03-08 20:49:44 -08:00
if (x1c_FEMT)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"FEMT", 4);
x1c_FEMT.write(w);
}
2016-03-08 20:49:44 -08:00
if (x20_AMPL)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"AMPL", 4);
x20_AMPL.write(w);
}
2016-03-08 20:49:44 -08:00
if (x24_AMPD)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"AMPD", 4);
x24_AMPD.write(w);
}
2016-03-08 20:49:44 -08:00
if (x28_LWD1)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LWD1", 4);
x28_LWD1.write(w);
}
2016-03-08 20:49:44 -08:00
if (x2c_LWD2)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LWD2", 4);
x2c_LWD2.write(w);
}
2016-03-08 20:49:44 -08:00
if (x30_LWD3)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LWD3", 4);
x30_LWD3.write(w);
}
2016-03-08 20:49:44 -08:00
if (x34_LCL1)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LCL1", 4);
x34_LCL1.write(w);
}
2016-03-08 20:49:44 -08:00
if (x38_LCL2)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LCL2", 4);
x38_LCL2.write(w);
}
2016-03-08 20:49:44 -08:00
if (x3c_LCL3)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"LCL3", 4);
x3c_LCL3.write(w);
}
2016-03-08 20:49:44 -08:00
if (x40_SSWH)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"SSWH", 4);
x40_SSWH.write(w);
}
2016-03-08 20:49:44 -08:00
if (x50_GPSM)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"GPSM", 4);
x50_GPSM.write(w);
}
2016-03-08 20:49:44 -08:00
if (x60_EPSM)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"EPSM", 4);
x60_EPSM.write(w);
}
2016-03-08 20:49:44 -08:00
if (x70_ZERY)
2018-02-21 23:24:51 -08:00
{
w.writeBytes((atInt8*)"ZERY", 4);
x70_ZERY.write(w);
}
w.writeBytes("_END", 4);
2016-03-08 20:49:44 -08:00
}
template <class IDType>
2018-02-21 23:24:51 -08:00
void ELSM<IDType>::_binarySize(size_t& s) const
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
s += 4;
2016-03-08 20:49:44 -08:00
if (x0_LIFE)
2018-02-21 23:24:51 -08:00
{
s += 4;
x0_LIFE.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x4_SLIF)
2018-02-21 23:24:51 -08:00
{
s += 4;
x4_SLIF.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x8_GRAT)
2018-02-21 23:24:51 -08:00
{
s += 4;
x8_GRAT.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (xc_SCNT)
2018-02-21 23:24:51 -08:00
{
s += 4;
xc_SCNT.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x10_SSEG)
2018-02-21 23:24:51 -08:00
{
s += 4;
x10_SSEG.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x14_COLR)
2018-02-21 23:24:51 -08:00
{
s += 4;
x14_COLR.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x18_IEMT)
2018-02-21 23:24:51 -08:00
{
s += 4;
x18_IEMT.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x1c_FEMT)
2018-02-21 23:24:51 -08:00
{
s += 4;
x1c_FEMT.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x20_AMPL)
2018-02-21 23:24:51 -08:00
{
s += 4;
x20_AMPL.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x24_AMPD)
2018-02-21 23:24:51 -08:00
{
s += 4;
x24_AMPD.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x28_LWD1)
2018-02-21 23:24:51 -08:00
{
s += 4;
x28_LWD1.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x2c_LWD2)
2018-02-21 23:24:51 -08:00
{
s += 4;
x2c_LWD2.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x30_LWD3)
2018-02-21 23:24:51 -08:00
{
s += 4;
x30_LWD3.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x34_LCL1)
2018-02-21 23:24:51 -08:00
{
s += 4;
x34_LCL1.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x38_LCL2)
2018-02-21 23:24:51 -08:00
{
s += 4;
x38_LCL2.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x3c_LCL3)
2018-02-21 23:24:51 -08:00
{
s += 4;
x3c_LCL3.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x40_SSWH)
2018-02-21 23:24:51 -08:00
{
s += 4;
x40_SSWH.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x50_GPSM)
2018-02-21 23:24:51 -08:00
{
s += 4;
x50_GPSM.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x60_EPSM)
2018-02-21 23:24:51 -08:00
{
s += 4;
x60_EPSM.binarySize(s);
}
2016-03-08 20:49:44 -08:00
if (x70_ZERY)
2018-02-21 23:24:51 -08:00
{
s += 4;
x70_ZERY.binarySize(s);
}
2016-03-08 20:49:44 -08:00
}
template <class IDType>
2018-02-21 23:24:51 -08:00
void ELSM<IDType>::_read(athena::io::YAMLDocReader& r)
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
for (const auto& elem : r.getCurNode()->m_mapChildren)
2016-03-08 20:49:44 -08:00
{
2018-02-21 23:24:51 -08:00
if (elem.first.size() < 4)
{
LogModule.report(logvisor::Warning, "short FourCC in element '%s'", elem.first.c_str());
continue;
}
2018-10-20 21:14:00 -07:00
if (auto rec = r.enterSubRecord(elem.first.c_str()))
2016-03-08 20:49:44 -08:00
{
2018-10-20 21:14:00 -07:00
switch (*reinterpret_cast<const uint32_t*>(elem.first.data()))
{
case SBIG('LIFE'):
x0_LIFE.read(r);
break;
case SBIG('SLIF'):
x4_SLIF.read(r);
break;
case SBIG('GRAT'):
x8_GRAT.read(r);
break;
case SBIG('SCNT'):
xc_SCNT.read(r);
break;
case SBIG('SSEG'):
x10_SSEG.read(r);
break;
case SBIG('COLR'):
x14_COLR.read(r);
break;
case SBIG('IEMT'):
x18_IEMT.read(r);
break;
case SBIG('FEMT'):
x1c_FEMT.read(r);
break;
case SBIG('AMPL'):
x20_AMPL.read(r);
break;
case SBIG('AMPD'):
x24_AMPD.read(r);
break;
case SBIG('LWD1'):
x28_LWD1.read(r);
break;
case SBIG('LWD2'):
x2c_LWD2.read(r);
break;
case SBIG('LWD3'):
x30_LWD3.read(r);
break;
case SBIG('LCL1'):
x34_LCL1.read(r);
break;
case SBIG('LCL2'):
x38_LCL2.read(r);
break;
case SBIG('LCL3'):
x3c_LCL3.read(r);
break;
case SBIG('SSWH'):
x40_SSWH.read(r);
break;
case SBIG('GPSM'):
x50_GPSM.read(r);
break;
case SBIG('EPSM'):
x60_EPSM.read(r);
break;
case SBIG('ZERY'):
x70_ZERY.read(r);
break;
default:
break;
}
2016-03-08 20:49:44 -08:00
}
}
}
template <class IDType>
2018-02-21 23:24:51 -08:00
void ELSM<IDType>::_write(athena::io::YAMLDocWriter& w) const
2016-03-08 20:49:44 -08:00
{
if (x0_LIFE)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LIFE"))
x0_LIFE.write(w);
2016-03-08 20:49:44 -08:00
if (x4_SLIF)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("SLIF"))
x4_SLIF.write(w);
2016-03-08 20:49:44 -08:00
if (x8_GRAT)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("GRAT"))
x8_GRAT.write(w);
2016-03-08 20:49:44 -08:00
if (xc_SCNT)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("SCNT"))
xc_SCNT.write(w);
2016-03-08 20:49:44 -08:00
if (x10_SSEG)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("SSEG"))
x10_SSEG.write(w);
2016-03-08 20:49:44 -08:00
if (x14_COLR)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("COLR"))
x14_COLR.write(w);
2016-03-08 20:49:44 -08:00
if (x18_IEMT)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("IEMT"))
x18_IEMT.write(w);
2016-03-08 20:49:44 -08:00
if (x1c_FEMT)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("FEMT"))
x1c_FEMT.write(w);
2016-03-08 20:49:44 -08:00
if (x20_AMPL)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("AMPL"))
x20_AMPL.write(w);
2016-03-08 20:49:44 -08:00
if (x24_AMPD)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("AMPD"))
x24_AMPD.write(w);
2016-03-08 20:49:44 -08:00
if (x28_LWD1)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LWD1"))
x28_LWD1.write(w);
2016-03-08 20:49:44 -08:00
if (x2c_LWD2)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LWD2"))
x2c_LWD2.write(w);
2016-03-08 20:49:44 -08:00
if (x30_LWD3)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LWD3"))
x30_LWD3.write(w);
2016-03-08 20:49:44 -08:00
if (x34_LCL1)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LCL1"))
x34_LCL1.write(w);
2016-03-08 20:49:44 -08:00
if (x38_LCL2)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LCL2"))
x38_LCL2.write(w);
2016-03-08 20:49:44 -08:00
if (x3c_LCL3)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("LCL3"))
x3c_LCL3.write(w);
2016-03-08 20:49:44 -08:00
if (x40_SSWH)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("SSWH"))
x40_SSWH.write(w);
2016-03-08 20:49:44 -08:00
if (x50_GPSM)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("GPSM"))
x50_GPSM.write(w);
2016-03-08 20:49:44 -08:00
if (x60_EPSM)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("EPSM"))
x60_EPSM.write(w);
2016-03-08 20:49:44 -08:00
if (x70_ZERY)
2018-02-21 23:24:51 -08:00
if (auto rec = w.enterSubRecord("ZERY"))
x70_ZERY.write(w);
2016-03-08 20:49:44 -08:00
}
2018-02-21 23:24:51 -08:00
AT_SUBSPECIALIZE_DNA_YAML(ELSM<UniqueID32>)
AT_SUBSPECIALIZE_DNA_YAML(ELSM<UniqueID64>)
template <>
const char* ELSM<UniqueID32>::DNAType() { return "urde::ELSM<UniqueID32>"; }
template <>
const char* ELSM<UniqueID64>::DNAType() { return "urde::ELSM<UniqueID64>"; }
2016-10-02 15:41:36 -07:00
template <class IDType>
void ELSM<IDType>::gatherDependencies(std::vector<hecl::ProjectPath>& pathsOut) const
{
g_curSpec->flattenDependencies(x40_SSWH.id, pathsOut);
g_curSpec->flattenDependencies(x50_GPSM.id, pathsOut);
g_curSpec->flattenDependencies(x60_EPSM.id, pathsOut);
}
2016-03-08 20:49:44 -08:00
template struct ELSM<UniqueID32>;
template struct ELSM<UniqueID64>;
template <class IDType>
bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{
2016-08-21 20:47:48 -07:00
athena::io::FileWriter writer(outPath.getAbsolutePath());
if (writer.isOpen())
2016-03-08 20:49:44 -08:00
{
ELSM<IDType> elsm;
elsm.read(rs);
2018-02-21 23:24:51 -08:00
athena::io::ToYAMLStream(elsm, writer);
2016-03-08 20:49:44 -08:00
return true;
}
return false;
}
template bool ExtractELSM<UniqueID32>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template bool ExtractELSM<UniqueID64>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template <class IDType>
bool WriteELSM(const ELSM<IDType>& elsm, const hecl::ProjectPath& outPath)
{
athena::io::FileWriter w(outPath.getAbsolutePath(), true, false);
if (w.hasError())
return false;
elsm.write(w);
int64_t rem = w.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
w.writeUByte(0xff);
2016-03-08 20:49:44 -08:00
return true;
}
template bool WriteELSM<UniqueID32>(const ELSM<UniqueID32>& gpsm, const hecl::ProjectPath& outPath);
template bool WriteELSM<UniqueID64>(const ELSM<UniqueID64>& gpsm, const hecl::ProjectPath& outPath);
}