metaforce/DataSpec/DNACommon/SWHC.cpp

591 lines
14 KiB
C++
Raw Normal View History

2016-03-28 08:54:02 +00:00
#include "SWHC.hpp"
2017-12-29 08:08:12 +00:00
namespace DataSpec::DNAParticle
2016-03-28 08:54:02 +00:00
{
2018-02-22 07:24:51 +00:00
template <>
const char* SWSH<UniqueID32>::DNAType() { return "SWSH<UniqueID32>"; }
template <>
const char* SWSH<UniqueID64>::DNAType() { return "SWSH<UniqueID64>"; }
2016-03-28 08:54:02 +00:00
template <class IDType>
2018-02-22 07:24:51 +00:00
void SWSH<IDType>::_read(typename BigDNA::ReadYaml::StreamT& r)
2016-03-28 08:54:02 +00:00
{
for (const auto& elem : r.getCurNode()->m_mapChildren)
{
if (elem.first.size() < 4)
{
LogModule.report(logvisor::Warning, "short FourCC in element '%s'", elem.first.c_str());
continue;
}
2017-02-12 23:56:03 +00:00
if (auto rec = r.enterSubRecord(elem.first.c_str()))
2016-03-28 08:54:02 +00:00
{
2017-02-12 23:56:03 +00:00
switch(*reinterpret_cast<const uint32_t*>(elem.first.data()))
{
case SBIG('PSLT'):
x0_PSLT.read(r);
break;
case SBIG('TIME'):
x4_TIME.read(r);
break;
case SBIG('LRAD'):
x8_LRAD.read(r);
break;
case SBIG('RRAD'):
xc_RRAD.read(r);
break;
case SBIG('LENG'):
x10_LENG.read(r);
break;
case SBIG('COLR'):
x14_COLR.read(r);
break;
case SBIG('SIDE'):
x18_SIDE.read(r);
break;
case SBIG('IROT'):
x1c_IROT.read(r);
break;
case SBIG('ROTM'):
x20_ROTM.read(r);
break;
case SBIG('POFS'):
x24_POFS.read(r);
break;
case SBIG('IVEL'):
x28_IVEL.read(r);
break;
case SBIG('NPOS'):
x2c_NPOS.read(r);
break;
case SBIG('VELM'):
x30_VELM.read(r);
break;
case SBIG('VLM2'):
x34_VLM2.read(r);
break;
case SBIG('SPLN'):
x38_SPLN.read(r);
break;
case SBIG('TEXR'):
x3c_TEXR.read(r);
break;
case SBIG('TSPN'):
x40_TSPN.read(r);
break;
case SBIG('LLRD'):
x44_24_LLRD = r.readBool(nullptr);
break;
case SBIG('CROS'):
x44_25_CROS = r.readBool(nullptr);
break;
case SBIG('VLS1'):
x44_26_VLS1 = r.readBool(nullptr);
break;
case SBIG('VLS2'):
x44_27_VLS2 = r.readBool(nullptr);
break;
case SBIG('SROT'):
x44_28_SROT = r.readBool(nullptr);
break;
case SBIG('WIRE'):
x44_29_WIRE = r.readBool(nullptr);
break;
case SBIG('TEXW'):
x44_30_TEXW = r.readBool(nullptr);
break;
case SBIG('AALP'):
x44_31_AALP = r.readBool(nullptr);
break;
case SBIG('ZBUF'):
x45_24_ZBUF = r.readBool(nullptr);
break;
case SBIG('ORNT'):
x45_25_ORNT = r.readBool(nullptr);
break;
case SBIG('CRND'):
x45_26_CRND = r.readBool(nullptr);
break;
2018-10-21 04:14:00 +00:00
default:
break;
2017-02-12 23:56:03 +00:00
}
2016-03-28 08:54:02 +00:00
}
}
}
template <class IDType>
2018-02-22 07:24:51 +00:00
void SWSH<IDType>::_write(typename BigDNA::WriteYaml::StreamT& w) const
2016-03-28 08:54:02 +00:00
{
if (x0_PSLT)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("PSLT"))
x0_PSLT.write(w);
2016-03-28 08:54:02 +00:00
if (x4_TIME)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("TIME"))
x4_TIME.write(w);
2016-03-28 08:54:02 +00:00
if (x8_LRAD)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("LRAD"))
x8_LRAD.write(w);
2016-03-28 08:54:02 +00:00
if (xc_RRAD)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("RRAD"))
xc_RRAD.write(w);
2016-03-28 08:54:02 +00:00
if (x10_LENG)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("LENG"))
x10_LENG.write(w);
2016-03-28 08:54:02 +00:00
if (x14_COLR)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("COLR"))
x14_COLR.write(w);
2016-03-28 08:54:02 +00:00
if (x18_SIDE)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("SIDE"))
x18_SIDE.write(w);
2016-03-28 08:54:02 +00:00
if (x1c_IROT)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("IROT"))
x1c_IROT.write(w);
2016-03-28 08:54:02 +00:00
if (x20_ROTM)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("ROTM"))
x20_ROTM.write(w);
2016-03-28 08:54:02 +00:00
if (x24_POFS)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("POFS"))
x24_POFS.write(w);
2016-03-28 08:54:02 +00:00
if (x28_IVEL)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("IVEL"))
x28_IVEL.write(w);
2016-03-28 08:54:02 +00:00
if (x2c_NPOS)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("NPOS"))
x2c_NPOS.write(w);
2016-03-28 08:54:02 +00:00
if (x30_VELM)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("VELM"))
x30_VELM.write(w);
2016-03-28 08:54:02 +00:00
if (x34_VLM2)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("VLM2"))
x34_VLM2.write(w);
2016-03-28 08:54:02 +00:00
if (x38_SPLN)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("SPLN"))
x38_SPLN.write(w);
2016-03-28 08:54:02 +00:00
if (x3c_TEXR)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("TEXR"))
x3c_TEXR.write(w);
2016-03-28 08:54:02 +00:00
if (x40_TSPN)
2017-02-12 23:56:03 +00:00
if (auto rec = w.enterSubRecord("TSPN"))
x40_TSPN.write(w);
2016-03-28 08:54:02 +00:00
if (x44_24_LLRD)
w.writeBool("LLRD", true);
if (!x44_25_CROS)
w.writeBool("CROS", false);
if (x44_26_VLS1)
w.writeBool("VLS1", true);
if (x44_27_VLS2)
w.writeBool("VLS2", true);
if (x44_28_SROT)
w.writeBool("SROT", true);
if (x44_29_WIRE)
w.writeBool("WIRE", true);
if (x44_30_TEXW)
w.writeBool("TEXW", true);
if (x44_31_AALP)
w.writeBool("AALP", true);
if (x45_24_ZBUF)
w.writeBool("ZBUF", true);
if (x45_25_ORNT)
w.writeBool("ORNT", true);
if (x45_26_CRND)
w.writeBool("CRND", true);
}
template <class IDType>
2018-02-22 07:24:51 +00:00
void SWSH<IDType>::_binarySize(typename BigDNA::BinarySize::StreamT& s) const
2016-03-28 08:54:02 +00:00
{
2018-02-22 07:24:51 +00:00
s += 4;
2016-03-28 08:54:02 +00:00
if (x0_PSLT)
2018-02-22 07:24:51 +00:00
{
s += 4;
x0_PSLT.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x4_TIME)
2018-02-22 07:24:51 +00:00
{
s += 4;
x4_TIME.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x8_LRAD)
2018-02-22 07:24:51 +00:00
{
s += 4;
x8_LRAD.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (xc_RRAD)
2018-02-22 07:24:51 +00:00
{
s += 4;
xc_RRAD.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x10_LENG)
2018-02-22 07:24:51 +00:00
{
s += 4;
x10_LENG.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x14_COLR)
2018-02-22 07:24:51 +00:00
{
s += 4;
x14_COLR.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x18_SIDE)
2018-02-22 07:24:51 +00:00
{
s += 4;
x18_SIDE.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x1c_IROT)
2018-02-22 07:24:51 +00:00
{
s += 4;
x1c_IROT.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x20_ROTM)
2018-02-22 07:24:51 +00:00
{
s += 4;
x20_ROTM.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x24_POFS)
2018-02-22 07:24:51 +00:00
{
s += 4;
x24_POFS.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x28_IVEL)
2018-02-22 07:24:51 +00:00
{
s += 4;
x28_IVEL.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x2c_NPOS)
2018-02-22 07:24:51 +00:00
{
s += 4;
x2c_NPOS.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x30_VELM)
2018-02-22 07:24:51 +00:00
{
s += 4;
x30_VELM.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x34_VLM2)
2018-02-22 07:24:51 +00:00
{
s += 4;
x34_VLM2.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x38_SPLN)
2018-02-22 07:24:51 +00:00
{
s += 4;
x38_SPLN.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x3c_TEXR)
2018-02-22 07:24:51 +00:00
{
s += 4;
x3c_TEXR.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x40_TSPN)
2018-02-22 07:24:51 +00:00
{
s += 4;
x40_TSPN.binarySize(s);
}
2016-03-28 08:54:02 +00:00
if (x44_24_LLRD)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (!x44_25_CROS)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_26_VLS1)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_27_VLS2)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_28_SROT)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_29_WIRE)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_30_TEXW)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x44_31_AALP)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x45_24_ZBUF)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x45_25_ORNT)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
if (x45_26_CRND)
2018-02-22 07:24:51 +00:00
s += 9;
2016-03-28 08:54:02 +00:00
}
template <class IDType>
2018-02-22 07:24:51 +00:00
void SWSH<IDType>::_read(typename BigDNA::Read::StreamT& r)
2016-03-28 08:54:02 +00:00
{
uint32_t clsId;
r.readBytesToBuf(&clsId, 4);
if (clsId != SBIG('SWSH'))
{
LogModule.report(logvisor::Warning, "non SWSH provided to SWSH parser");
return;
}
r.readBytesToBuf(&clsId, 4);
while (clsId != SBIG('_END'))
{
switch(clsId)
{
case SBIG('PSLT'):
x0_PSLT.read(r);
break;
case SBIG('TIME'):
x4_TIME.read(r);
break;
case SBIG('LRAD'):
x8_LRAD.read(r);
break;
case SBIG('RRAD'):
xc_RRAD.read(r);
break;
case SBIG('LENG'):
x10_LENG.read(r);
break;
case SBIG('COLR'):
x14_COLR.read(r);
break;
case SBIG('SIDE'):
x18_SIDE.read(r);
break;
case SBIG('IROT'):
x1c_IROT.read(r);
break;
case SBIG('ROTM'):
x20_ROTM.read(r);
break;
case SBIG('POFS'):
x24_POFS.read(r);
break;
case SBIG('IVEL'):
x28_IVEL.read(r);
break;
case SBIG('NPOS'):
x2c_NPOS.read(r);
break;
case SBIG('VELM'):
x30_VELM.read(r);
break;
case SBIG('VLM2'):
x34_VLM2.read(r);
break;
case SBIG('SPLN'):
x38_SPLN.read(r);
break;
case SBIG('TEXR'):
x3c_TEXR.read(r);
break;
case SBIG('TSPN'):
x40_TSPN.read(r);
break;
case SBIG('LLRD'):
r.readUint32Big();
x44_24_LLRD = r.readBool();
break;
case SBIG('CROS'):
r.readUint32Big();
x44_25_CROS = r.readBool();
break;
case SBIG('VLS1'):
r.readUint32Big();
x44_26_VLS1 = r.readBool();
break;
case SBIG('VLS2'):
r.readUint32Big();
x44_27_VLS2 = r.readBool();
break;
case SBIG('SROT'):
r.readUint32Big();
x44_28_SROT = r.readBool();
break;
case SBIG('WIRE'):
r.readUint32Big();
x44_29_WIRE = r.readBool();
break;
case SBIG('TEXW'):
r.readUint32Big();
x44_30_TEXW = r.readBool();
break;
case SBIG('AALP'):
r.readUint32Big();
x44_31_AALP = r.readBool();
break;
case SBIG('ZBUF'):
r.readUint32Big();
x45_24_ZBUF = r.readBool();
break;
case SBIG('ORNT'):
r.readUint32Big();
x45_25_ORNT = r.readBool();
break;
case SBIG('CRND'):
r.readUint32Big();
x45_26_CRND = r.readBool();
break;
default:
LogModule.report(logvisor::Fatal, "Unknown SWSH class %.4s @%" PRIi64, &clsId, r.position());
break;
}
r.readBytesToBuf(&clsId, 4);
}
}
template <class IDType>
2018-02-22 07:24:51 +00:00
void SWSH<IDType>::_write(typename BigDNA::Write::StreamT& w) const
2016-03-28 08:54:02 +00:00
{
w.writeBytes((atInt8*)"SWSH", 4);
if (x0_PSLT)
{
w.writeBytes((atInt8*)"PSLT", 4);
x0_PSLT.write(w);
}
if (x4_TIME)
{
w.writeBytes((atInt8*)"TIME", 4);
x4_TIME.write(w);
}
if (x8_LRAD)
{
w.writeBytes((atInt8*)"LRAD", 4);
x8_LRAD.write(w);
}
if (xc_RRAD)
{
w.writeBytes((atInt8*)"RRAD", 4);
xc_RRAD.write(w);
}
if (x10_LENG)
{
w.writeBytes((atInt8*)"LENG", 4);
x10_LENG.write(w);
}
if (x14_COLR)
{
w.writeBytes((atInt8*)"COLR", 4);
x14_COLR.write(w);
}
if (x18_SIDE)
{
w.writeBytes((atInt8*)"SIDE", 4);
x18_SIDE.write(w);
}
if (x1c_IROT)
{
w.writeBytes((atInt8*)"IROT", 4);
x1c_IROT.write(w);
}
if (x20_ROTM)
{
w.writeBytes((atInt8*)"ROTM", 4);
x20_ROTM.write(w);
}
if (x24_POFS)
{
w.writeBytes((atInt8*)"POFS", 4);
x24_POFS.write(w);
}
if (x28_IVEL)
{
w.writeBytes((atInt8*)"IVEL", 4);
x28_IVEL.write(w);
}
if (x2c_NPOS)
{
w.writeBytes((atInt8*)"NPOS", 4);
x2c_NPOS.write(w);
}
if (x30_VELM)
{
w.writeBytes((atInt8*)"VELM", 4);
x30_VELM.write(w);
}
if (x34_VLM2)
{
w.writeBytes((atInt8*)"VLM2", 4);
x34_VLM2.write(w);
}
if (x38_SPLN)
{
w.writeBytes((atInt8*)"SPLN", 4);
x38_SPLN.write(w);
}
if (x3c_TEXR)
{
w.writeBytes((atInt8*)"TEXR", 4);
x3c_TEXR.write(w);
}
if (x40_TSPN)
{
w.writeBytes((atInt8*)"TSPN", 4);
x40_TSPN.write(w);
}
if (x44_24_LLRD)
w.writeBytes("LLRDCNST\x01", 9);
if (!x44_25_CROS)
w.writeBytes("CROSCNST\x00", 9);
if (x44_26_VLS1)
w.writeBytes("VLS1CNST\x01", 9);
if (x44_27_VLS2)
w.writeBytes("VLS2CNST\x01", 9);
if (x44_28_SROT)
w.writeBytes("SROTCNST\x01", 9);
if (x44_29_WIRE)
w.writeBytes("WIRECNST\x01", 9);
if (x44_30_TEXW)
w.writeBytes("TEXWCNST\x01", 9);
if (x44_31_AALP)
w.writeBytes("AALPCNST\x01", 9);
if (x45_24_ZBUF)
w.writeBytes("ZBUFCNST\x01", 9);
if (x45_25_ORNT)
w.writeBytes("ORNTCNST\x01", 9);
if (x45_26_CRND)
w.writeBytes("CRNDCNST\x01", 9);
2016-03-28 09:25:50 +00:00
w.writeBytes("_END", 4);
2016-03-28 08:54:02 +00:00
}
2018-02-22 07:24:51 +00:00
AT_SUBSPECIALIZE_DNA_YAML(SWSH<UniqueID32>)
AT_SUBSPECIALIZE_DNA_YAML(SWSH<UniqueID64>)
2016-10-02 22:41:36 +00:00
template <class IDType>
void SWSH<IDType>::gatherDependencies(std::vector<hecl::ProjectPath>& pathsOut) const
{
if (x3c_TEXR.m_elem)
x3c_TEXR.m_elem->gatherDependencies(pathsOut);
}
2016-03-28 08:54:02 +00:00
template struct SWSH<UniqueID32>;
template struct SWSH<UniqueID64>;
template <class IDType>
bool ExtractSWSH(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{
2016-08-22 03:47:48 +00:00
athena::io::FileWriter writer(outPath.getAbsolutePath());
if (writer.isOpen())
2016-03-28 08:54:02 +00:00
{
SWSH<IDType> swsh;
swsh.read(rs);
2018-02-22 07:24:51 +00:00
athena::io::ToYAMLStream(swsh, writer);
2016-03-28 08:54:02 +00:00
return true;
}
return false;
}
template bool ExtractSWSH<UniqueID32>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template bool ExtractSWSH<UniqueID64>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template <class IDType>
bool WriteSWSH(const SWSH<IDType>& swsh, const hecl::ProjectPath& outPath)
{
athena::io::FileWriter w(outPath.getAbsolutePath(), true, false);
if (w.hasError())
return false;
swsh.write(w);
int64_t rem = w.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
w.writeUByte(0xff);
2016-03-28 08:54:02 +00:00
return true;
}
template bool WriteSWSH<UniqueID32>(const SWSH<UniqueID32>& swsh, const hecl::ProjectPath& outPath);
template bool WriteSWSH<UniqueID64>(const SWSH<UniqueID64>& swsh, const hecl::ProjectPath& outPath);
}