This commit is contained in:
Jack Andersen 2016-03-09 10:04:02 -10:00
commit f2ebc3c5da
8 changed files with 1250 additions and 2 deletions

View File

@ -18,8 +18,9 @@ add_library(DNACommon
ANIM.hpp ANIM.cpp
PART.hpp PART.cpp
SWHC.hpp
ELSC.hpp
ELSC.hpp ELSC.cpp
ParticleCommon.cpp
FONT.hpp FONT.cpp
DeafBabe.hpp
BabeDead.hpp
Tweaks/ITweakGame.hpp

483
DataSpec/DNACommon/ELSC.cpp Normal file
View File

@ -0,0 +1,483 @@
#include "ELSC.hpp"
namespace DataSpec
{
namespace DNAParticle
{
template <class IDType>
void ELSM<IDType>::read(athena::io::YAMLDocReader& r)
{
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;
}
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;
}
}
}
template <class IDType>
void ELSM<IDType>::write(athena::io::YAMLDocWriter& w) const
{
if (x0_LIFE)
{
w.enterSubRecord("LIFE");
x0_LIFE.write(w);
w.leaveSubRecord();
}
if (x4_SLIF)
{
w.enterSubRecord("SLIF");
x4_SLIF.write(w);
w.leaveSubRecord();
}
if (x8_GRAT)
{
w.enterSubRecord("GRAT");
x8_GRAT.write(w);
w.leaveSubRecord();
}
if (xc_SCNT)
{
w.enterSubRecord("SCNT");
xc_SCNT.write(w);
w.leaveSubRecord();
}
if (x10_SSEG)
{
w.enterSubRecord("SSEG");
x10_SSEG.write(w);
w.leaveSubRecord();
}
if (x14_COLR)
{
w.enterSubRecord("COLR");
x14_COLR.write(w);
w.leaveSubRecord();
}
if (x18_IEMT)
{
w.enterSubRecord("IEMT");
x18_IEMT.write(w);
w.leaveSubRecord();
}
if (x1c_FEMT)
{
w.enterSubRecord("FEMT");
x1c_FEMT.write(w);
w.leaveSubRecord();
}
if (x20_AMPL)
{
w.enterSubRecord("AMPL");
x20_AMPL.write(w);
w.leaveSubRecord();
}
if (x24_AMPD)
{
w.enterSubRecord("AMPD");
x24_AMPD.write(w);
w.leaveSubRecord();
}
if (x28_LWD1)
{
w.enterSubRecord("LWD1");
x28_LWD1.write(w);
w.leaveSubRecord();
}
if (x2c_LWD2)
{
w.enterSubRecord("LWD2");
x2c_LWD2.write(w);
w.leaveSubRecord();
}
if (x30_LWD3)
{
w.enterSubRecord("LWD3");
x30_LWD3.write(w);
w.leaveSubRecord();
}
if (x34_LCL1)
{
w.enterSubRecord("LCL1");
x34_LCL1.write(w);
w.leaveSubRecord();
}
if (x38_LCL2)
{
w.enterSubRecord("LCL2");
x38_LCL2.write(w);
w.leaveSubRecord();
}
if (x3c_LCL3)
{
w.enterSubRecord("LCL3");
x3c_LCL3.write(w);
w.leaveSubRecord();
}
if (x40_SSWH)
{
w.enterSubRecord("SSWH");
x40_SSWH.write(w);
w.leaveSubRecord();
}
if (x50_GPSM)
{
w.enterSubRecord("GPSM");
x50_GPSM.write(w);
w.leaveSubRecord();
}
if (x60_EPSM)
{
w.enterSubRecord("EPSM");
x60_EPSM.write(w);
w.leaveSubRecord();
}
if (x70_ZERY)
{
w.enterSubRecord("ZERY");
x70_ZERY.write(w);
w.leaveSubRecord();
}
}
template <class IDType>
size_t ELSM<IDType>::binarySize(size_t __isz) const
{
__isz += 4;
if (x0_LIFE)
__isz = x0_LIFE.binarySize(__isz + 4);
if (x4_SLIF)
__isz = x4_SLIF.binarySize(__isz + 4);
if (x8_GRAT)
__isz = x8_GRAT.binarySize(__isz + 4);
if (xc_SCNT)
__isz = xc_SCNT.binarySize(__isz + 4);
if (x10_SSEG)
__isz = x10_SSEG.binarySize(__isz + 4);
if (x14_COLR)
__isz = x14_COLR.binarySize(__isz + 4);
if (x18_IEMT)
__isz = x18_IEMT.binarySize(__isz + 4);
if (x1c_FEMT)
__isz = x1c_FEMT.binarySize(__isz + 4);
if (x20_AMPL)
__isz = x20_AMPL.binarySize(__isz + 4);
if (x24_AMPD)
__isz = x24_AMPD.binarySize(__isz + 4);
if (x28_LWD1)
__isz = x28_LWD1.binarySize(__isz + 4);
if (x2c_LWD2)
__isz = x2c_LWD2.binarySize(__isz + 4);
if (x30_LWD3)
__isz = x30_LWD3.binarySize(__isz + 4);
if (x34_LCL1)
__isz = x34_LCL1.binarySize(__isz + 4);
if (x38_LCL2)
__isz = x38_LCL2.binarySize(__isz + 4);
if (x3c_LCL3)
__isz = x3c_LCL3.binarySize(__isz + 4);
if (x40_SSWH)
__isz = x40_SSWH.binarySize(__isz + 4);
if (x50_GPSM)
__isz = x50_GPSM.binarySize(__isz + 4);
if (x60_EPSM)
__isz = x60_EPSM.binarySize(__isz + 4);
if (x70_ZERY)
__isz = x70_ZERY.binarySize(__isz + 4);
return __isz;
}
template <class IDType>
void ELSM<IDType>::read(athena::io::IStreamReader& r)
{
uint32_t clsId;
r.readBytesToBuf(&clsId, 4);
if (clsId != SBIG('ELSM'))
{
LogModule.report(logvisor::Warning, "non ELSM provided to ELSM parser");
return;
}
r.readBytesToBuf(&clsId, 4);
while (clsId != SBIG('_END'))
{
switch(clsId)
{
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:
LogModule.report(logvisor::Fatal, "Unknown ELSM class %.4s @%" PRIi64, &clsId, r.position());
break;
}
r.readBytesToBuf(&clsId, 4);
}
}
template <class IDType>
void ELSM<IDType>::write(athena::io::IStreamWriter& w) const
{
w.writeBytes((atInt8*)"ELSM", 4);
if (x0_LIFE)
{
w.writeBytes((atInt8*)"LIFE", 4);
x0_LIFE.write(w);
}
if (x4_SLIF)
{
w.writeBytes((atInt8*)"SLIF", 4);
x4_SLIF.write(w);
}
if (x8_GRAT)
{
w.writeBytes((atInt8*)"GRAT", 4);
x8_GRAT.write(w);
}
if (xc_SCNT)
{
w.writeBytes((atInt8*)"SCNT", 4);
xc_SCNT.write(w);
}
if (x10_SSEG)
{
w.writeBytes((atInt8*)"SSEG", 4);
x10_SSEG.write(w);
}
if (x14_COLR)
{
w.writeBytes((atInt8*)"COLR", 4);
x14_COLR.write(w);
}
if (x18_IEMT)
{
w.writeBytes((atInt8*)"IEMT", 4);
x18_IEMT.write(w);
}
if (x1c_FEMT)
{
w.writeBytes((atInt8*)"FEMT", 4);
x1c_FEMT.write(w);
}
if (x20_AMPL)
{
w.writeBytes((atInt8*)"AMPL", 4);
x20_AMPL.write(w);
}
if (x24_AMPD)
{
w.writeBytes((atInt8*)"AMPD", 4);
x24_AMPD.write(w);
}
if (x28_LWD1)
{
w.writeBytes((atInt8*)"LWD1", 4);
x28_LWD1.write(w);
}
if (x2c_LWD2)
{
w.writeBytes((atInt8*)"LWD2", 4);
x2c_LWD2.write(w);
}
if (x30_LWD3)
{
w.writeBytes((atInt8*)"LWD3", 4);
x30_LWD3.write(w);
}
if (x34_LCL1)
{
w.writeBytes((atInt8*)"LCL1", 4);
x34_LCL1.write(w);
}
if (x38_LCL2)
{
w.writeBytes((atInt8*)"LCL2", 4);
x38_LCL2.write(w);
}
if (x3c_LCL3)
{
w.writeBytes((atInt8*)"LCL3", 4);
x3c_LCL3.write(w);
}
if (x40_SSWH)
{
w.writeBytes((atInt8*)"SSWH", 4);
x40_SSWH.write(w);
}
if (x50_GPSM)
{
w.writeBytes((atInt8*)"GPSM", 4);
x50_GPSM.write(w);
}
if (x60_EPSM)
{
w.writeBytes((atInt8*)"EPSM", 4);
x60_EPSM.write(w);
}
if (x70_ZERY)
{
w.writeBytes((atInt8*)"ZERY", 4);
x70_ZERY.write(w);
}
}
template struct ELSM<UniqueID32>;
template struct ELSM<UniqueID64>;
template <class IDType>
bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w"));
if (fp)
{
ELSM<IDType> elsm;
elsm.read(rs);
elsm.toYAMLFile(fp);
fclose(fp);
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.writeBytes((atInt8*)"\xff", 1);
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);
}
}

View File

@ -2,5 +2,52 @@
#define __COMMON_ELSC_HPP__
#include "ParticleCommon.hpp"
#include "PAK.hpp"
#include "athena/FileWriter.hpp"
namespace DataSpec
{
namespace DNAParticle
{
template <class IDType>
struct ELSM : BigYAML
{
static const char* DNAType() { return "urde::ELSM"; }
const char* DNATypeV() const { return DNAType(); }
IntElementFactory x0_LIFE;
IntElementFactory x4_SLIF;
RealElementFactory x8_GRAT;
IntElementFactory xc_SCNT;
IntElementFactory x10_SSEG;
ColorElementFactory x14_COLR;
EmitterElementFactory x18_IEMT;
EmitterElementFactory x1c_FEMT;
RealElementFactory x20_AMPL;
RealElementFactory x24_AMPD;
RealElementFactory x28_LWD1;
RealElementFactory x2c_LWD2;
RealElementFactory x30_LWD3;
ColorElementFactory x34_LCL1;
ColorElementFactory x38_LCL2;
ColorElementFactory x3c_LCL3;
ChildResourceFactory<IDType> x40_SSWH;
ChildResourceFactory<IDType> x50_GPSM;
ChildResourceFactory<IDType> x60_EPSM;
BoolHelper x70_ZERY;
void read(athena::io::YAMLDocReader& r);
void write(athena::io::YAMLDocWriter& w) const;
size_t binarySize(size_t __isz) const;
void read(athena::io::IStreamReader& r);
void write(athena::io::IStreamWriter& w) const;
};
template <class IDType>
bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template <class IDType>
bool WriteELSM(const ELSM<IDType>& elsm, const hecl::ProjectPath& outPath);
}
}
#endif // __COMMON_ELSC_HPP__

582
DataSpec/DNACommon/FONT.cpp Normal file
View File

@ -0,0 +1,582 @@
#include "FONT.hpp"
namespace DataSpec
{
namespace DNAFont
{
logvisor::Module LogModule("urde::DNAFont");
void GlyphRect::read(athena::io::IStreamReader& __dna_reader)
{
/* left */
left = __dna_reader.readFloatBig();
/* top */
top = __dna_reader.readFloatBig();
/* right */
right = __dna_reader.readFloatBig();
/* bottom */
bottom = __dna_reader.readFloatBig();
}
void GlyphRect::write(athena::io::IStreamWriter& __dna_writer) const
{
/* left */
__dna_writer.writeFloatBig(left);
/* top */
__dna_writer.writeFloatBig(top);
/* right */
__dna_writer.writeFloatBig(right);
/* bottom */
__dna_writer.writeFloatBig(bottom);
}
void GlyphRect::read(athena::io::YAMLDocReader& __dna_docin)
{
/* left */
left = __dna_docin.readFloat("left");
/* top */
top = __dna_docin.readFloat("top");
/* right */
right = __dna_docin.readFloat("right");
/* bottom */
bottom = __dna_docin.readFloat("bottom");
}
void GlyphRect::write(athena::io::YAMLDocWriter& __dna_docout) const
{
/* left */
__dna_docout.writeFloat("left", left);
/* top */
__dna_docout.writeFloat("top", top);
/* right */
__dna_docout.writeFloat("right", right);
/* bottom */
__dna_docout.writeFloat("bottom", bottom);
}
const char* GlyphRect::DNAType()
{
return "GlyphRect";
}
size_t GlyphRect::binarySize(size_t __isz) const
{
return __isz + 16;
}
template <class IDType>
void FONT<IDType>::read(athena::io::IStreamReader& __dna_reader)
{
/* magic */
atUint32 magic;
__dna_reader.readBytesToBuf(&magic, 4);
if (magic != SBIG('FONT'))
{
LogModule.report(logvisor::Fatal, "Invalid FONT magic '%s'", &magic);
return;
}
/* version */
version = __dna_reader.readUint32Big();
/* unknown1 */
unknown1 = __dna_reader.readUint32Big();
/* lineHeight */
lineHeight = __dna_reader.readInt32Big();
/* verticalOffset */
verticalOffset = __dna_reader.readInt32Big();
/* lineMargin */
lineMargin = __dna_reader.readInt32Big();
/* unknown2 */
unknown2 = __dna_reader.readBool();
/* unknown3 */
unknown3 = __dna_reader.readBool();
/* unknown4 */
unknown4 = __dna_reader.readUint32Big();
/* fontSize */
fontSize = __dna_reader.readUint32Big();
/* name */
name = __dna_reader.readString(-1);
/* textureId */
textureId.read(__dna_reader);
/* textureFormat */
textureFormat = __dna_reader.readUint32Big();
/* glyphCount */
glyphCount = __dna_reader.readUint32Big();
/* glyphs */
for (atUint32 i = 0; i < glyphCount; i++)
{
if (version < 4)
glyphs.emplace_back(new GlyphMP1);
else
glyphs.emplace_back(new GlyphMP2);
glyphs.back()->read(__dna_reader);
}
/* kerningInfoCount */
kerningInfoCount = __dna_reader.readUint32Big();
/* kerningInfo */
__dna_reader.enumerate(kerningInfo, kerningInfoCount);
}
template <class IDType>
void FONT<IDType>::write(athena::io::IStreamWriter& __dna_writer) const
{
/* magic */
__dna_writer.writeBytes((atInt8*)"FONT", 4);
/* version */
__dna_writer.writeUint32Big(version);
/* unknown1 */
__dna_writer.writeUint32Big(unknown1);
/* lineHeight */
__dna_writer.writeInt32Big(lineHeight);
/* verticalOffset */
__dna_writer.writeInt32Big(verticalOffset);
/* lineMargin */
__dna_writer.writeInt32Big(lineMargin);
/* unknown2 */
__dna_writer.writeBool(unknown2);
/* unknown3 */
__dna_writer.writeBool(unknown3);
/* unknown4 */
__dna_writer.writeUint32Big(unknown4);
/* fontSize */
__dna_writer.writeUint32Big(fontSize);
/* name */
__dna_writer.writeString(name, -1);
/* textureId */
textureId.write(__dna_writer);
/* textureFormat */
__dna_writer.writeUint32Big(textureFormat);
/* glyphCount */
__dna_writer.writeUint32Big(glyphCount);
/* glyphs */
for (const std::unique_ptr<IGlyph>& glyph : glyphs)
glyph->write(__dna_writer);
/* kerningInfoCount */
__dna_writer.writeUint32Big(kerningInfoCount);
/* kerningInfo */
__dna_writer.enumerate(kerningInfo);
}
template <class IDType>
void FONT<IDType>::read(athena::io::YAMLDocReader& __dna_docin)
{
/* version */
version = __dna_docin.readUint32("version");
/* unknown1 */
unknown1 = __dna_docin.readUint32("unknown1");
/* lineHeight */
lineHeight = __dna_docin.readInt32("lineHeight");
/* verticalOffset */
verticalOffset = __dna_docin.readInt32("verticalOffset");
/* lineMargin */
lineMargin = __dna_docin.readInt32("lineMargin");
/* unknown2 */
unknown2 = __dna_docin.readBool("unknown2");
/* unknown3 */
unknown3 = __dna_docin.readBool("unknown3");
/* unknown4 */
unknown4 = __dna_docin.readUint32("unknown4");
/* fontSize */
fontSize = __dna_docin.readUint32("fontSize");
/* name */
name = __dna_docin.readString("name");
/* textureId */
__dna_docin.enumerate("textureId", textureId);
/* textureFormat */
textureFormat = __dna_docin.readUint32("textureFormat");
/* glyphCount */
/* glyphs */
size_t count;
__dna_docin.enterSubVector("glyphs", count);
glyphCount = count;
for (atUint32 i = 0; i < glyphCount; i++)
{
if (version < 4)
glyphs.emplace_back(new GlyphMP1);
else
glyphs.emplace_back(new GlyphMP2);
__dna_docin.enterSubRecord(nullptr);
glyphs.back()->read(__dna_docin);
__dna_docin.leaveSubRecord();
}
__dna_docin.leaveSubVector();
/* kerningInfoCount squelched */
/* kerningInfo */
kerningInfoCount = __dna_docin.enumerate("kerningInfo", kerningInfo);
}
template <class IDType>
void FONT<IDType>::write(athena::io::YAMLDocWriter& __dna_docout) const
{
/* version */
__dna_docout.writeUint32("version", version);
/* unknown1 */
__dna_docout.writeUint32("unknown1", unknown1);
/* lineHeight */
__dna_docout.writeInt32("lineHeight", lineHeight);
/* verticalOffset */
__dna_docout.writeInt32("verticalOffset", verticalOffset);
/* lineMargin */
__dna_docout.writeInt32("lineMargin", lineMargin);
/* unknown2 */
__dna_docout.writeBool("unknown2", unknown2);
/* unknown3 */
__dna_docout.writeBool("unknown3", unknown3);
/* unknown4 */
__dna_docout.writeUint32("unknown4", unknown4);
/* fontSize */
__dna_docout.writeUint32("fontSize", fontSize);
/* name */
__dna_docout.writeString("name", name);
/* textureId */
__dna_docout.enumerate("textureId", textureId);
/* textureFormat */
__dna_docout.writeUint32("textureFormat", textureFormat);
/* glyphCount squelched */
/* glyphs */
__dna_docout.enterSubVector("glyphs");
for (const std::unique_ptr<IGlyph>& glyph : glyphs)
{
__dna_docout.enterSubRecord(nullptr);
glyph->write(__dna_docout);
__dna_docout.leaveSubRecord();
}
__dna_docout.leaveSubVector();
/* kerningInfoCount squelched */
/* kerningInfo */
__dna_docout.enumerate("kerningInfo", kerningInfo);
}
template <class IDType>
const char* FONT<IDType>::DNAType()
{
return "FONT";
}
template <class IDType>
size_t FONT<IDType>::binarySize(size_t __isz) const
{
__isz += name.size() + 1;
__isz = textureId.binarySize(__isz);
for (const std::unique_ptr<IGlyph>& glyph : glyphs)
__isz = glyph->binarySize(__isz);
__isz = __EnumerateSize(__isz, kerningInfo);
return __isz + 46;
}
void IGlyph::read(athena::io::IStreamReader& __dna_reader)
{
/* m_character */
m_character = __dna_reader.readUint16Big();
/* m_glyphRect */
m_glyphRect.read(__dna_reader);
}
void IGlyph::write(athena::io::IStreamWriter& __dna_writer) const
{
/* m_character */
__dna_writer.writeUint16Big(m_character);
/* m_glyphRect */
m_glyphRect.write(__dna_writer);
}
void IGlyph::read(athena::io::YAMLDocReader& __dna_docin)
{
/* m_character */
m_character = __dna_docin.readUint16("m_character");
/* m_glyphRect */
__dna_docin.enumerate("m_glyphRect", m_glyphRect);
}
void IGlyph::write(athena::io::YAMLDocWriter& __dna_docout) const
{
/* m_character */
__dna_docout.writeUint16("m_character", m_character);
/* m_glyphRect */
__dna_docout.enumerate("m_glyphRect", m_glyphRect);
}
const char* IGlyph::DNAType()
{
return "FONT::IGlyph";
}
size_t IGlyph::binarySize(size_t __isz) const
{
__isz = m_glyphRect.binarySize(__isz);
return __isz + 2;
}
void GlyphMP1::read(athena::io::IStreamReader& __dna_reader)
{
IGlyph::read(__dna_reader);
/* m_leftPadding */
m_leftPadding = __dna_reader.readInt32Big();
/* m_advance */
m_advance = __dna_reader.readInt32Big();
/* m_rightPadding */
m_rightPadding = __dna_reader.readInt32Big();
/* m_width */
m_width = __dna_reader.readInt32Big();
/* m_height */
m_height = __dna_reader.readInt32Big();
/* m_baseline */
m_baseline = __dna_reader.readInt32Big();
/* m_kerningIndex */
m_kerningIndex = __dna_reader.readInt32Big();
}
void GlyphMP1::write(athena::io::IStreamWriter& __dna_writer) const
{
IGlyph::write(__dna_writer);
/* m_leftPadding */
__dna_writer.writeInt32Big(m_leftPadding);
/* m_advance */
__dna_writer.writeInt32Big(m_advance);
/* m_rightPadding */
__dna_writer.writeInt32Big(m_rightPadding);
/* m_width */
__dna_writer.writeInt32Big(m_width);
/* m_height */
__dna_writer.writeInt32Big(m_height);
/* m_baseline */
__dna_writer.writeInt32Big(m_baseline);
/* m_kerningIndex */
__dna_writer.writeInt32Big(m_kerningIndex);
}
void GlyphMP1::read(athena::io::YAMLDocReader& __dna_docin)
{
IGlyph::read(__dna_docin);
/* m_leftPadding */
m_leftPadding = __dna_docin.readInt32("m_leftPadding");
/* m_advance */
m_advance = __dna_docin.readInt32("m_advance");
/* m_rightPadding */
m_rightPadding = __dna_docin.readInt32("m_rightPadding");
/* m_width */
m_width = __dna_docin.readInt32("m_width");
/* m_height */
m_height = __dna_docin.readInt32("m_height");
/* m_baseline */
m_baseline = __dna_docin.readInt32("m_baseline");
/* m_kerningIndex */
m_kerningIndex = __dna_docin.readInt32("m_kerningIndex");
}
void GlyphMP1::write(athena::io::YAMLDocWriter& __dna_docout) const
{
IGlyph::write(__dna_docout);
/* m_leftPadding */
__dna_docout.writeInt32("m_leftPadding", m_leftPadding);
/* m_advance */
__dna_docout.writeInt32("m_advance", m_advance);
/* m_rightPadding */
__dna_docout.writeInt32("m_rightPadding", m_rightPadding);
/* m_width */
__dna_docout.writeInt32("m_width", m_width);
/* m_height */
__dna_docout.writeInt32("m_height", m_height);
/* m_baseline */
__dna_docout.writeInt32("m_baseline", m_baseline);
/* m_kerningIndex */
__dna_docout.writeInt32("m_kerningIndex", m_kerningIndex);
}
const char* GlyphMP1::DNAType()
{
return "GlyphMP1";
}
size_t GlyphMP1::binarySize(size_t __isz) const
{
__isz = IGlyph::binarySize(__isz);
return __isz + 28;
}
void GlyphMP2::read(athena::io::IStreamReader& __dna_reader)
{
IGlyph::read(__dna_reader);
/* m_layer */
m_layer = __dna_reader.readByte();
/* m_leftPadding */
m_leftPadding = __dna_reader.readByte();
/* m_advance */
m_advance = __dna_reader.readByte();
/* m_rightPadding */
m_rightPadding = __dna_reader.readByte();
/* m_width */
m_width = __dna_reader.readByte();
/* m_height */
m_height = __dna_reader.readByte();
/* m_baseline */
m_baseline = __dna_reader.readByte();
/* m_kerningIndex */
m_kerningIndex = __dna_reader.readInt16Big();
}
void GlyphMP2::write(athena::io::IStreamWriter& __dna_writer) const
{
IGlyph::write(__dna_writer);
/* m_layer */
__dna_writer.writeByte(m_layer);
/* m_leftPadding */
__dna_writer.writeByte(m_leftPadding);
/* m_advance */
__dna_writer.writeByte(m_advance);
/* m_rightPadding */
__dna_writer.writeByte(m_rightPadding);
/* m_width */
__dna_writer.writeByte(m_width);
/* m_height */
__dna_writer.writeByte(m_height);
/* m_baseline */
__dna_writer.writeByte(m_baseline);
/* m_kerningIndex */
__dna_writer.writeInt16Big(m_kerningIndex);
}
void GlyphMP2::read(athena::io::YAMLDocReader& __dna_docin)
{
IGlyph::read(__dna_docin);
/* m_layer */
m_layer = __dna_docin.readByte("m_layer");
/* m_leftPadding */
m_leftPadding = __dna_docin.readByte("m_leftPadding");
/* m_advance */
m_advance = __dna_docin.readByte("m_advance");
/* m_rightPadding */
m_rightPadding = __dna_docin.readByte("m_rightPadding");
/* m_width */
m_width = __dna_docin.readByte("m_width");
/* m_height */
m_height = __dna_docin.readByte("m_height");
/* m_baseline */
m_baseline = __dna_docin.readByte("m_baseline");
/* m_kerningIndex */
m_kerningIndex = __dna_docin.readInt16("m_kerningIndex");
}
void GlyphMP2::write(athena::io::YAMLDocWriter& __dna_docout) const
{
IGlyph::write(__dna_docout);
/* m_layer */
__dna_docout.writeByte("m_layer", m_layer);
/* m_leftPadding */
__dna_docout.writeByte("m_leftPadding", m_leftPadding);
/* m_advance */
__dna_docout.writeByte("m_advance", m_advance);
/* m_rightPadding */
__dna_docout.writeByte("m_rightPadding", m_rightPadding);
/* m_width */
__dna_docout.writeByte("m_width", m_width);
/* m_height */
__dna_docout.writeByte("m_height", m_height);
/* m_baseline */
__dna_docout.writeByte("m_baseline", m_baseline);
/* m_kerningIndex */
__dna_docout.writeInt16("m_kerningIndex", m_kerningIndex);
}
const char* GlyphMP2::DNAType()
{
return "GlyphMP2";
}
size_t GlyphMP2::binarySize(size_t __isz) const
{
__isz = IGlyph::binarySize(__isz);
return __isz + 9;
}
void KerningInfo::read(athena::io::IStreamReader& __dna_reader)
{
/* thisChar */
thisChar = __dna_reader.readUint16Big();
/* nextChar */
nextChar = __dna_reader.readUint16Big();
/* adjust */
adjust = __dna_reader.readInt32Big();
}
void KerningInfo::write(athena::io::IStreamWriter& __dna_writer) const
{
/* thisChar */
__dna_writer.writeUint16Big(thisChar);
/* nextChar */
__dna_writer.writeUint16Big(nextChar);
/* adjust */
__dna_writer.writeInt32Big(adjust);
}
void KerningInfo::read(athena::io::YAMLDocReader& __dna_docin)
{
/* thisChar */
thisChar = __dna_docin.readUint16("thisChar");
/* nextChar */
nextChar = __dna_docin.readUint16("nextChar");
/* adjust */
adjust = __dna_docin.readInt32("adjust");
}
void KerningInfo::write(athena::io::YAMLDocWriter& __dna_docout) const
{
/* thisChar */
__dna_docout.writeUint16("thisChar", thisChar);
/* nextChar */
__dna_docout.writeUint16("nextChar", nextChar);
/* adjust */
__dna_docout.writeInt32("adjust", adjust);
}
const char* KerningInfo::DNAType()
{
return "KerningInfo";
}
size_t KerningInfo::binarySize(size_t __isz) const
{
return __isz + 8;
}
template struct FONT<UniqueID32>;
template struct FONT<UniqueID64>;
template <class IDType>
bool ExtractFONT(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w"));
if (fp)
{
FONT<IDType> font;
font.read(rs);
font.toYAMLFile(fp);
fclose(fp);
return true;
}
return false;
}
template bool ExtractFONT<UniqueID32>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template bool ExtractFONT<UniqueID64>(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template <class IDType>
bool WriteFONT(const FONT<IDType>& font, const hecl::ProjectPath& outPath)
{
athena::io::FileWriter w(outPath.getAbsolutePath(), true, false);
if (w.hasError())
return false;
font.write(w);
int64_t rem = w.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
w.writeBytes((atInt8*)"\xff", 1);
return true;
}
template bool WriteFONT<UniqueID32>(const FONT<UniqueID32>& font, const hecl::ProjectPath& outPath);
template bool WriteFONT<UniqueID64>(const FONT<UniqueID64>& font, const hecl::ProjectPath& outPath);
}
}

123
DataSpec/DNACommon/FONT.hpp Normal file
View File

@ -0,0 +1,123 @@
#ifndef __COMMON_FONT_HPP__
#define __COMMON_FONT_HPP__
#include "PAK.hpp"
#include "athena/FileWriter.hpp"
namespace DataSpec
{
namespace DNAFont
{
struct GlyphRect : BigYAML
{
DECL_YAML
Value<float> left;
Value<float> top;
Value<float> right;
Value<float> bottom;
};
struct IGlyph : BigYAML
{
DECL_YAML
Value<atUint16> m_character;
GlyphRect m_glyphRect;
atUint16 character() const { return m_character; }
float left() const { return m_glyphRect.left; }
float top() const { return m_glyphRect.top; }
float right() const { return m_glyphRect.right; }
float bottom() const { return m_glyphRect.bottom; }
GlyphRect rect() const { return m_glyphRect; }
virtual int layer() { return 0; }
virtual atInt32 leftPadding() const=0;
virtual atInt32 advance() const =0;
virtual atInt32 rightPadding() const=0;
virtual atInt32 width() const=0;
virtual atInt32 height() const=0;
virtual atInt32 baseline() const=0;
virtual atInt32 kerningIndex() const =0;
};
struct GlyphMP1 : IGlyph
{
DECL_YAML
Value<atInt32> m_leftPadding;
Value<atInt32> m_advance;
Value<atInt32> m_rightPadding;
Value<atInt32> m_width;
Value<atInt32> m_height;
Value<atInt32> m_baseline;
Value<atInt32> m_kerningIndex;
atInt32 leftPadding() const { return m_leftPadding; }
atInt32 advance() const { return m_advance; }
atInt32 rightPadding() const { return m_rightPadding; }
atInt32 width() const { return m_width; }
atInt32 height() const { return m_height; }
atInt32 baseline() const { return m_baseline; }
atInt32 kerningIndex() const { return m_kerningIndex; }
};
struct GlyphMP2 : IGlyph
{
DECL_YAML
Value<atInt8> m_layer;
Value<atInt8> m_leftPadding;
Value<atInt8> m_advance;
Value<atInt8> m_rightPadding;
Value<atInt8> m_width;
Value<atInt8> m_height;
Value<atInt8> m_baseline;
Value<atInt16> m_kerningIndex;
atInt32 layer() const { return m_layer; }
atInt32 leftPadding() const { return m_leftPadding; }
atInt32 advance() const { return m_advance; }
atInt32 rightPadding() const { return m_rightPadding; }
atInt32 width() const { return m_width; }
atInt32 height() const { return m_height; }
atInt32 baseline() const { return m_baseline; }
atInt32 kerningIndex() const { return m_kerningIndex; }
};
struct KerningInfo : BigYAML
{
DECL_YAML
Value<atUint16> thisChar;
Value<atUint16> nextChar;
Value<atInt32> adjust;
};
template <class IDType>
struct FONT : BigYAML
{
DECL_YAML
Value<atUint32> version;
Value<atUint32> unknown1;
Value<atInt32> lineHeight;
Value<atInt32> verticalOffset;
Value<atInt32> lineMargin;
Value<bool> unknown2;
Value<bool> unknown3;
Value<atUint32> unknown4;
Value<atUint32> fontSize; // in points
String<-1> name;
IDType textureId;
Value<atUint32> textureFormat;
Value<atUint32> glyphCount;
std::vector<std::unique_ptr<IGlyph>> glyphs;
Value<atUint32> kerningInfoCount;
Vector<KerningInfo, DNA_COUNT(kerningInfoCount)> kerningInfo;
};
template <class IDType>
bool ExtractFONT(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath);
template <class IDType>
bool WriteFONT(const FONT<IDType>& font, const hecl::ProjectPath& outPath);
}
}
#endif // __COMMON_FONT_HPP__

View File

@ -7,6 +7,8 @@
#include "MLVL.hpp"
#include "../DNACommon/TXTR.hpp"
#include "../DNACommon/PART.hpp"
#include "../DNACommon/ELSC.hpp"
#include "../DNACommon/FONT.hpp"
#include "CMDL.hpp"
#include "AFSM.hpp"
#include "ANCS.hpp"
@ -287,7 +289,11 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK::Entry& entry)
case SBIG('MAPA'):
return {nullptr, MAPA::Extract, {_S(".blend")}, 4};
case SBIG('PART'):
return {DNAParticle::ExtractGPSM<UniqueID32>, nullptr, {_S(".yaml")}};
return {DNAParticle::ExtractGPSM<UniqueID32>, nullptr, {_S(".gpsm.yaml")}};
case SBIG('ELSC'):
return {DNAParticle::ExtractELSM<UniqueID32>, nullptr, {_S(".elsm.yaml")}};
case SBIG('FONT'):
return {DNAFont::ExtractFONT<UniqueID32>, nullptr, {_S(".yaml")}};
}
return {};
}

View File

@ -8,6 +8,7 @@
#include "MAPA.hpp"
#include "AFSM.hpp"
#include "../DNACommon/TXTR.hpp"
#include "../DNACommon/FONT.hpp"
namespace DataSpec
{
@ -229,6 +230,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const DNAMP1::PAK::Entry& ent
return {nullptr, MREA::Extract, {_S(".blend")}, 4};
case SBIG('MAPA'):
return {nullptr, MAPA::Extract, {_S(".blend")}, 4};
case SBIG('FONT'):
return {DNAFont::ExtractFONT<UniqueID32>, nullptr, {_S(".yaml")}};
}
return {};
}

View File

@ -9,6 +9,7 @@
#include "MREA.hpp"
#include "MAPA.hpp"
#include "../DNACommon/TXTR.hpp"
#include "../DNACommon/FONT.hpp"
namespace DataSpec
{
@ -237,6 +238,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK::Entry& entry)
return {nullptr, MREA::Extract, {_S(".blend")}, 4};
case SBIG('MAPA'):
return {nullptr, MAPA::Extract, {_S(".blend")}, 4};
case SBIG('FONT'):
return {DNAFont::ExtractFONT<UniqueID64>, nullptr, {_S(".yaml")}};
}
return {};
}