ANCS fixes and cleanup

This commit is contained in:
Jack Andersen 2015-08-08 13:24:17 -10:00
parent e0bf3a7024
commit 2d18e95a91
11 changed files with 155 additions and 638 deletions

View File

@ -6,8 +6,6 @@
namespace Retro namespace Retro
{ {
HECL::Database::ASListType<std::string> ASTYPE_STRGLanguage("STRG", "Language", "string");
std::unique_ptr<ISTRG> LoadSTRG(Athena::io::IStreamReader& reader) std::unique_ptr<ISTRG> LoadSTRG(Athena::io::IStreamReader& reader)
{ {
reader.setEndian(Athena::BigEndian); reader.setEndian(Athena::BigEndian);

View File

@ -3,7 +3,6 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <angelscript.h>
#include <HECL/HECL.hpp> #include <HECL/HECL.hpp>
#include <HECL/Database.hpp> #include <HECL/Database.hpp>
#include <Athena/FileWriter.hpp> #include <Athena/FileWriter.hpp>
@ -20,14 +19,9 @@ struct ISTRG
virtual std::wstring getUTF16(const FourCC& lang, size_t idx) const=0; virtual std::wstring getUTF16(const FourCC& lang, size_t idx) const=0;
virtual HECL::SystemString getSystemString(const FourCC& lang, size_t idx) const=0; virtual HECL::SystemString getSystemString(const FourCC& lang, size_t idx) const=0;
virtual int32_t lookupIdx(const std::string& name) const=0; virtual int32_t lookupIdx(const std::string& name) const=0;
virtual bool readAngelScript(const AngelScript::asIScriptModule& in)=0;
virtual void writeAngelScript(std::ofstream& out) const=0;
}; };
std::unique_ptr<ISTRG> LoadSTRG(Athena::io::IStreamReader& reader); std::unique_ptr<ISTRG> LoadSTRG(Athena::io::IStreamReader& reader);
extern HECL::Database::ASListType<std::string> ASTYPE_STRGLanguage;
} }
#endif // __COMMON_STRG_HPP__ #endif // __COMMON_STRG_HPP__

View File

@ -10,7 +10,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::read(A
parmType = reader.readUint32(); parmType = reader.readUint32();
unk1 = reader.readUint32(); unk1 = reader.readUint32();
unk2 = reader.readFloat(); unk2 = reader.readFloat();
switch(DataType(parmType)) switch (DataType(parmType))
{ {
case DataType::DTInt32: case DataType::DTInt32:
parmVals[0].int32 = reader.readInt32(); parmVals[0].int32 = reader.readInt32();
@ -37,7 +37,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::write(
writer.writeUint32(parmType); writer.writeUint32(parmType);
writer.writeUint32(unk1); writer.writeUint32(unk1);
writer.writeFloat(unk2); writer.writeFloat(unk2);
switch(DataType(parmType)) switch (DataType(parmType))
{ {
case DataType::DTInt32: case DataType::DTInt32:
writer.writeInt32(parmVals[0].int32); writer.writeInt32(parmVals[0].int32);
@ -65,7 +65,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::fromYA
unk1 = reader.readUint32("unk1"); unk1 = reader.readUint32("unk1");
unk2 = reader.readFloat("unk2"); unk2 = reader.readFloat("unk2");
reader.enterSubVector("parmVals"); reader.enterSubVector("parmVals");
switch(DataType(parmType)) switch (DataType(parmType))
{ {
case DataType::DTInt32: case DataType::DTInt32:
parmVals[0].int32 = reader.readInt32(nullptr); parmVals[0].int32 = reader.readInt32(nullptr);
@ -95,7 +95,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::toYAML
writer.writeUint32("unk1", unk1); writer.writeUint32("unk1", unk1);
writer.writeFloat("unk2", unk2); writer.writeFloat("unk2", unk2);
writer.enterSubVector("parmVals"); writer.enterSubVector("parmVals");
switch(DataType(parmType)) switch (DataType(parmType))
{ {
case DataType::DTInt32: case DataType::DTInt32:
writer.writeInt32(nullptr, parmVals[0].int32); writer.writeInt32(nullptr, parmVals[0].int32);
@ -124,23 +124,18 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::read(Athena::io:
atUint32 parmInfoCount = reader.readUint32(); atUint32 parmInfoCount = reader.readUint32();
atUint32 animInfoCount = reader.readUint32(); atUint32 animInfoCount = reader.readUint32();
parmInfos.reserve(parmInfoCount); reader.enumerate(parmInfos, parmInfoCount);
for (int i=0 ; i<parmInfoCount ; ++i)
{
parmInfos.emplace_back();
parmInfos.back().read(reader);
}
animInfos.clear();
animInfos.reserve(animInfoCount); animInfos.reserve(animInfoCount);
for (int i=0 ; i<animInfoCount ; ++i) reader.enumerate<AnimInfo>(animInfos, animInfoCount,
[this, parmInfoCount](Athena::io::IStreamReader& reader, AnimInfo& ai)
{ {
animInfos.emplace_back();
AnimInfo& ai = animInfos.back();
ai.id = reader.readUint32(); ai.id = reader.readUint32();
ai.parmVals.reserve(parmInfoCount); ai.parmVals.reserve(parmInfoCount);
for (const ParmInfo& pi : parmInfos) for (const ParmInfo& pi : parmInfos)
{ {
switch(ParmInfo::DataType(pi.parmType)) switch (ParmInfo::DataType(pi.parmType))
{ {
case ParmInfo::DTInt32: case ParmInfo::DTInt32:
ai.parmVals.emplace_back(reader.readInt32()); ai.parmVals.emplace_back(reader.readInt32());
@ -158,7 +153,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::read(Athena::io:
default: break; default: break;
} }
} }
} });
} }
void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::write(Athena::io::IStreamWriter& writer) const void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::write(Athena::io::IStreamWriter& writer) const
@ -179,7 +174,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::write(Athena::io
ParmInfo::Parm pVal; ParmInfo::Parm pVal;
if (it != ai.parmVals.end()) if (it != ai.parmVals.end())
pVal = *it++; pVal = *it++;
switch(ParmInfo::DataType(pi.parmType)) switch (ParmInfo::DataType(pi.parmType))
{ {
case ParmInfo::DTInt32: case ParmInfo::DTInt32:
writer.writeInt32(pVal.int32); writer.writeInt32(pVal.int32);
@ -206,28 +201,17 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::fromYAML(Athena:
atUint32 parmInfoCount = reader.readUint32("parmInfoCount"); atUint32 parmInfoCount = reader.readUint32("parmInfoCount");
atUint32 animInfoCount = reader.readUint32("animInfoCount"); atUint32 animInfoCount = reader.readUint32("animInfoCount");
parmInfos.reserve(parmInfoCount); reader.enumerate("parmInfos", parmInfos, parmInfoCount);
reader.enterSubVector("parmInfos");
for (int i=0 ; i<parmInfoCount ; ++i)
{
parmInfos.emplace_back();
parmInfos.back().fromYAML(reader);
}
reader.leaveSubVector();
animInfos.reserve(animInfoCount); reader.enumerate<AnimInfo>("animInfos", animInfos, animInfoCount,
reader.enterSubVector("animInfos"); [this, parmInfoCount](Athena::io::YAMLDocReader& reader, AnimInfo& ai)
for (int i=0 ; i<animInfoCount ; ++i)
{ {
animInfos.emplace_back();
AnimInfo& ai = animInfos.back();
reader.enterSubRecord(nullptr);
ai.id = reader.readUint32("id"); ai.id = reader.readUint32("id");
ai.parmVals.reserve(parmInfoCount); ai.parmVals.reserve(parmInfoCount);
reader.enterSubVector("parmVals"); reader.enterSubVector("parmVals");
for (const ParmInfo& pi : parmInfos) for (const ParmInfo& pi : parmInfos)
{ {
switch(ParmInfo::DataType(pi.parmType)) switch (ParmInfo::DataType(pi.parmType))
{ {
case ParmInfo::DTInt32: case ParmInfo::DTInt32:
ai.parmVals.emplace_back(reader.readInt32(nullptr)); ai.parmVals.emplace_back(reader.readInt32(nullptr));
@ -246,9 +230,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::fromYAML(Athena:
} }
} }
reader.leaveSubVector(); reader.leaveSubVector();
reader.leaveSubRecord(); });
}
reader.leaveSubVector();
} }
void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::toYAML(Athena::io::YAMLDocWriter& writer) const void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::toYAML(Athena::io::YAMLDocWriter& writer) const
@ -257,19 +239,11 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::toYAML(Athena::i
writer.writeUint32("parmInfoCount", parmInfos.size()); writer.writeUint32("parmInfoCount", parmInfos.size());
writer.writeUint32("animInfoCount", animInfos.size()); writer.writeUint32("animInfoCount", animInfos.size());
writer.enterSubVector("parmInfos"); writer.enumerate("parmInfos", parmInfos);
for (const ParmInfo& pi : parmInfos)
{
writer.enterSubRecord(nullptr);
pi.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.enterSubVector("animInfos"); writer.enumerate<AnimInfo>("animInfos", animInfos,
for (const AnimInfo& ai : animInfos) [this](Athena::io::YAMLDocWriter& writer, const AnimInfo& ai)
{ {
writer.enterSubRecord("info");
writer.writeUint32("id", ai.id); writer.writeUint32("id", ai.id);
auto it = ai.parmVals.begin(); auto it = ai.parmVals.begin();
writer.enterSubVector("parms"); writer.enterSubVector("parms");
@ -278,7 +252,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::toYAML(Athena::i
ParmInfo::Parm pVal; ParmInfo::Parm pVal;
if (it != ai.parmVals.end()) if (it != ai.parmVals.end())
pVal = *it++; pVal = *it++;
switch(ParmInfo::DataType(pi.parmType)) switch (ParmInfo::DataType(pi.parmType))
{ {
case ParmInfo::DTInt32: case ParmInfo::DTInt32:
writer.writeInt32(nullptr, pVal.int32); writer.writeInt32(nullptr, pVal.int32);
@ -297,9 +271,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::toYAML(Athena::i
} }
} }
writer.leaveSubVector(); writer.leaveSubVector();
writer.leaveSubRecord(); });
}
writer.leaveSubVector();
} }
void ANCS::CharacterSet::CharacterInfo::read(Athena::io::IStreamReader& reader) void ANCS::CharacterSet::CharacterInfo::read(Athena::io::IStreamReader& reader)
@ -312,78 +284,45 @@ void ANCS::CharacterSet::CharacterInfo::read(Athena::io::IStreamReader& reader)
cinf.read(reader); cinf.read(reader);
atUint32 animationCount = reader.readUint32(); atUint32 animationCount = reader.readUint32();
animations.reserve(animationCount); reader.enumerate(animations, animationCount);
for (int i=0 ; i<animationCount ; ++i)
{
animations.emplace_back();
animations.back().read(reader);
}
pasDatabase.read(reader); pasDatabase.read(reader);
atUint32 partCount = reader.readUint32(); atUint32 partCount = reader.readUint32();
partResData.part.clear(); reader.enumerate(partResData.part, partCount);
partResData.part.reserve(partCount);
for (int i=0 ; i<partCount ; ++i)
{
partResData.part.emplace_back();
partResData.part.back().read(reader);
}
atUint32 swhcCount = reader.readUint32(); atUint32 swhcCount = reader.readUint32();
partResData.swhc.clear(); reader.enumerate(partResData.swhc, swhcCount);
partResData.swhc.reserve(swhcCount);
for (int i=0 ; i<swhcCount ; ++i)
{
partResData.swhc.emplace_back();
partResData.swhc.back().read(reader);
}
atUint32 unkCount = reader.readUint32(); atUint32 unkCount = reader.readUint32();
partResData.unk.clear(); reader.enumerate(partResData.unk, unkCount);
partResData.unk.reserve(unkCount);
for (int i=0 ; i<unkCount ; ++i)
{
partResData.unk.emplace_back();
partResData.unk.back().read(reader);
}
partResData.elsc.clear();
if (sectionCount > 5) if (sectionCount > 5)
{ {
atUint32 elscCount = reader.readUint32(); atUint32 elscCount = reader.readUint32();
partResData.elsc.clear(); reader.enumerate(partResData.elsc, elscCount);
partResData.elsc.reserve(elscCount);
for (int i=0 ; i<elscCount ; ++i)
{
partResData.elsc.emplace_back();
partResData.elsc.back().read(reader);
}
} }
unk1 = reader.readUint32(); unk1 = reader.readUint32();
if (sectionCount > 9)
{
unk2 = reader.readUint32();
unk3 = reader.readUint32();
}
animAABBs.clear(); animAABBs.clear();
if (sectionCount > 1) if (sectionCount > 1)
{ {
atUint32 aabbCount = reader.readUint32(); atUint32 aabbCount = reader.readUint32();
animAABBs.reserve(aabbCount); reader.enumerate(animAABBs, aabbCount);
for (int i=0 ; i<aabbCount ; ++i)
{
animAABBs.emplace_back();
animAABBs.back().read(reader);
}
} }
effects.clear(); effects.clear();
if (sectionCount > 2) if (sectionCount > 2)
{ {
atUint32 effectCount = reader.readUint32(); atUint32 effectCount = reader.readUint32();
effects.reserve(effectCount); reader.enumerate(effects, effectCount);
for (int i=0 ; i<effectCount ; ++i)
{
effects.emplace_back();
effects.back().read(reader);
}
} }
if (sectionCount > 3) if (sectionCount > 3)
@ -396,9 +335,7 @@ void ANCS::CharacterSet::CharacterInfo::read(Athena::io::IStreamReader& reader)
if (sectionCount > 4) if (sectionCount > 4)
{ {
atUint32 aidxCount = reader.readUint32(); atUint32 aidxCount = reader.readUint32();
animIdxs.reserve(aidxCount); reader.enumerate(animIdxs, aidxCount);
for (int i=0 ; i<aidxCount ; ++i)
animIdxs.emplace_back(reader.readUint32());
} }
} }
@ -407,7 +344,9 @@ void ANCS::CharacterSet::CharacterInfo::write(Athena::io::IStreamWriter& writer)
writer.writeUint32(idx); writer.writeUint32(idx);
atUint16 sectionCount; atUint16 sectionCount;
if (partResData.elsc.size()) if (unk2 || unk3)
sectionCount = 10;
else if (partResData.elsc.size())
sectionCount = 6; sectionCount = 6;
else if (animIdxs.size()) else if (animIdxs.size())
sectionCount = 5; sectionCount = 5;
@ -427,44 +366,42 @@ void ANCS::CharacterSet::CharacterInfo::write(Athena::io::IStreamWriter& writer)
cinf.write(writer); cinf.write(writer);
writer.writeUint32(animations.size()); writer.writeUint32(animations.size());
for (const Animation& anim : animations) writer.enumerate(animations);
anim.write(writer);
pasDatabase.write(writer); pasDatabase.write(writer);
writer.writeUint32(partResData.part.size()); writer.writeUint32(partResData.part.size());
for (const UniqueID32& id : partResData.part) writer.enumerate(partResData.part);
id.write(writer);
writer.writeUint32(partResData.swhc.size()); writer.writeUint32(partResData.swhc.size());
for (const UniqueID32& id : partResData.swhc) writer.enumerate(partResData.swhc);
id.write(writer);
writer.writeUint32(partResData.unk.size()); writer.writeUint32(partResData.unk.size());
for (const UniqueID32& id : partResData.unk) writer.enumerate(partResData.unk);
id.write(writer);
if (sectionCount > 5) if (sectionCount > 5)
{ {
writer.writeUint32(partResData.elsc.size()); writer.writeUint32(partResData.elsc.size());
for (const UniqueID32& id : partResData.elsc) writer.enumerate(partResData.elsc);
id.write(writer);
} }
writer.writeUint32(unk1); writer.writeUint32(unk1);
if (sectionCount > 9)
{
writer.writeUint32(unk2);
writer.writeUint32(unk3);
}
if (sectionCount > 1) if (sectionCount > 1)
{ {
writer.writeUint32(animAABBs.size()); writer.writeUint32(animAABBs.size());
for (const ActionAABB& aabb : animAABBs) writer.enumerate(animAABBs);
aabb.write(writer);
} }
if (sectionCount > 2) if (sectionCount > 2)
{ {
writer.writeUint32(effects.size()); writer.writeUint32(effects.size());
for (const Effect& effect : effects) writer.enumerate(effects);
effect.write(writer);
} }
if (sectionCount > 3) if (sectionCount > 3)
@ -486,140 +423,63 @@ void ANCS::CharacterSet::CharacterInfo::fromYAML(Athena::io::YAMLDocReader& read
idx = reader.readUint32("idx"); idx = reader.readUint32("idx");
atUint16 sectionCount = reader.readUint16("sectionCount"); atUint16 sectionCount = reader.readUint16("sectionCount");
name = reader.readString("name"); name = reader.readString("name");
reader.enterSubRecord("cmdl"); reader.enumerate("cmdl", cmdl);
cmdl.fromYAML(reader); reader.enumerate("cskr", cskr);
reader.leaveSubRecord(); reader.enumerate("cinf", cinf);
reader.enterSubRecord("cskr");
cskr.fromYAML(reader);
reader.leaveSubRecord();
reader.enterSubRecord("cinf");
cinf.fromYAML(reader);
reader.leaveSubRecord();
atUint32 animationCount = reader.readUint32("animationCount"); atUint32 animationCount = reader.readUint32("animationCount");
animations.reserve(animationCount); reader.enumerate("animations", animations, animationCount);
reader.enterSubVector("animations");
for (int i=0 ; i<animationCount ; ++i)
{
animations.emplace_back();
reader.enterSubRecord(nullptr);
animations.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
reader.enterSubRecord("pasDatabase"); reader.enumerate("pasDatabase", pasDatabase);
pasDatabase.fromYAML(reader);
reader.leaveSubRecord();
atUint32 partCount = reader.readUint32("partCount"); atUint32 partCount = reader.readUint32("partCount");
partResData.part.clear(); reader.enumerate("part", partResData.part, partCount);
partResData.part.reserve(partCount);
reader.enterSubVector("part");
for (int i=0 ; i<partCount ; ++i)
{
partResData.part.emplace_back();
reader.enterSubRecord(nullptr);
partResData.part.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
atUint32 swhcCount = reader.readUint32("swhcCount"); atUint32 swhcCount = reader.readUint32("swhcCount");
partResData.swhc.clear(); reader.enumerate("swhc", partResData.swhc, swhcCount);
partResData.swhc.reserve(swhcCount);
reader.enterSubVector("swhc");
for (int i=0 ; i<swhcCount ; ++i)
{
partResData.swhc.emplace_back();
reader.enterSubRecord(nullptr);
partResData.swhc.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
atUint32 unkCount = reader.readUint32("unkCount"); atUint32 unkCount = reader.readUint32("unkCount");
partResData.unk.clear(); reader.enumerate("unk", partResData.unk, unkCount);
partResData.unk.reserve(unkCount);
reader.enterSubVector("unk");
for (int i=0 ; i<unkCount ; ++i)
{
partResData.unk.emplace_back();
reader.enterSubRecord(nullptr);
partResData.unk.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
partResData.elsc.clear();
if (sectionCount > 5) if (sectionCount > 5)
{ {
atUint32 elscCount = reader.readUint32("elscCount"); atUint32 elscCount = reader.readUint32("elscCount");
partResData.elsc.clear(); reader.enumerate("elsc", partResData.elsc, elscCount);
partResData.elsc.reserve(elscCount);
reader.enterSubVector("elsc");
for (int i=0 ; i<elscCount ; ++i)
{
partResData.elsc.emplace_back();
reader.enterSubRecord(nullptr);
partResData.elsc.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
} }
unk1 = reader.readUint32("unk1"); unk1 = reader.readUint32("unk1");
if (sectionCount > 9)
{
unk2 = reader.readUint32("unk2");
unk3 = reader.readUint32("unk3");
}
animAABBs.clear(); animAABBs.clear();
if (sectionCount > 1) if (sectionCount > 1)
{ {
atUint32 aabbCount = reader.readUint32("animAABBCount"); atUint32 aabbCount = reader.readUint32("animAABBCount");
animAABBs.reserve(aabbCount); reader.enumerate("part", animAABBs, aabbCount);
reader.enterSubVector("animAABBs");
for (int i=0 ; i<aabbCount ; ++i)
{
animAABBs.emplace_back();
reader.enterSubRecord(nullptr);
animAABBs.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
} }
effects.clear(); effects.clear();
if (sectionCount > 2) if (sectionCount > 2)
{ {
atUint32 effectCount = reader.readUint32("effectCount"); atUint32 effectCount = reader.readUint32("effectCount");
effects.reserve(effectCount); reader.enumerate("effects", effects, effectCount);
reader.enterSubVector("effects");
for (int i=0 ; i<effectCount ; ++i)
{
effects.emplace_back();
reader.enterSubRecord(nullptr);
effects.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
} }
if (sectionCount > 3) if (sectionCount > 3)
{ {
reader.enterSubRecord("cmdlOverride"); reader.enumerate("cmdlOverride", cmdlOverride);
cmdlOverride.fromYAML(reader); reader.enumerate("cskrOverride", cskrOverride);
reader.leaveSubRecord();
reader.enterSubRecord("cskrOverride");
cskrOverride.fromYAML(reader);
reader.leaveSubRecord();
} }
animIdxs.clear(); animIdxs.clear();
if (sectionCount > 4) if (sectionCount > 4)
{ {
atUint32 animIdxCount = reader.readUint32("animIdxCount"); atUint32 animIdxCount = reader.readUint32("animIdxCount");
animIdxs.reserve(animIdxCount); reader.enumerate("animIdxs", animIdxs, animIdxCount);
reader.enterSubVector("animIdxs");
for (int i=0 ; i<animIdxCount ; ++i)
animIdxs.emplace_back(reader.readUint32(nullptr));
reader.leaveSubVector();
} }
} }
@ -628,7 +488,9 @@ void ANCS::CharacterSet::CharacterInfo::toYAML(Athena::io::YAMLDocWriter& writer
writer.writeUint32("idx", idx); writer.writeUint32("idx", idx);
atUint16 sectionCount; atUint16 sectionCount;
if (partResData.elsc.size()) if (unk2 || unk3)
sectionCount = 10;
else if (partResData.elsc.size())
sectionCount = 6; sectionCount = 6;
else if (animIdxs.size()) else if (animIdxs.size())
sectionCount = 5; sectionCount = 5;
@ -643,118 +505,59 @@ void ANCS::CharacterSet::CharacterInfo::toYAML(Athena::io::YAMLDocWriter& writer
writer.writeUint16("sectionCount", sectionCount); writer.writeUint16("sectionCount", sectionCount);
writer.writeString("name", name); writer.writeString("name", name);
writer.enterSubRecord("cmdl"); writer.enumerate("cmdl", cmdl);
cmdl.toYAML(writer); writer.enumerate("cskr", cskr);
writer.leaveSubRecord(); writer.enumerate("cinf", cinf);
writer.enterSubRecord("cskr");
cskr.toYAML(writer);
writer.leaveSubRecord();
writer.enterSubRecord("cinf");
cinf.toYAML(writer);
writer.leaveSubRecord();
writer.writeUint32("animationCount", animations.size()); writer.writeUint32("animationCount", animations.size());
writer.enterSubVector("animations"); writer.enumerate("animations", animations);
for (const Animation& anim : animations)
{
writer.enterSubRecord(nullptr);
anim.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.enterSubRecord("pasDatabase"); writer.enumerate("pasDatabase", pasDatabase);
pasDatabase.toYAML(writer);
writer.leaveSubRecord();
writer.writeUint32("partCount", partResData.part.size()); writer.writeUint32("partCount", partResData.part.size());
writer.enterSubVector("part"); writer.enumerate("part", partResData.part);
for (const UniqueID32& id : partResData.part)
{
writer.enterSubRecord(nullptr);
id.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.writeUint32("swhcCount", partResData.swhc.size()); writer.writeUint32("swhcCount", partResData.swhc.size());
writer.enterSubVector("swhc"); writer.enumerate("swhc", partResData.swhc);
for (const UniqueID32& id : partResData.swhc)
{
writer.enterSubRecord(nullptr);
id.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.writeUint32("unkCount", partResData.unk.size()); writer.writeUint32("unkCount", partResData.unk.size());
writer.enterSubVector("unk"); writer.enumerate("unk", partResData.unk);
for (const UniqueID32& id : partResData.unk)
{
writer.enterSubRecord(nullptr);
id.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
if (sectionCount > 5) if (sectionCount > 5)
{ {
writer.writeUint32("elscCount", partResData.elsc.size()); writer.writeUint32("elscCount", partResData.elsc.size());
writer.enterSubVector("elsc"); writer.enumerate("elsc", partResData.elsc);
for (const UniqueID32& id : partResData.elsc)
{
writer.enterSubRecord(nullptr);
id.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
} }
writer.writeUint32("unk1", unk1); writer.writeUint32("unk1", unk1);
if (sectionCount > 9)
{
writer.writeUint32("unk2", unk2);
writer.writeUint32("unk3", unk3);
}
if (sectionCount > 1) if (sectionCount > 1)
{ {
writer.writeUint32("animAABBCount", animAABBs.size()); writer.writeUint32("animAABBCount", animAABBs.size());
writer.enterSubVector("animAABBs"); writer.enumerate("animAABBs", animAABBs);
for (const ActionAABB& aabb : animAABBs)
{
writer.enterSubRecord(nullptr);
aabb.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
} }
if (sectionCount > 2) if (sectionCount > 2)
{ {
writer.writeUint32("effectCount", effects.size()); writer.writeUint32("effectCount", effects.size());
writer.enterSubVector("effects"); writer.enumerate("effects", effects);
for (const Effect& effect : effects)
{
writer.enterSubRecord(nullptr);
effect.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
} }
if (sectionCount > 3) if (sectionCount > 3)
{ {
writer.enterSubRecord("cmdlOverride"); writer.enumerate("cmdlOverride", cmdlOverride);
cmdlOverride.toYAML(writer); writer.enumerate("cskrOverride", cskrOverride);
writer.leaveSubRecord();
writer.enterSubRecord("cskrOverride");
cskrOverride.toYAML(writer);
writer.leaveSubRecord();
} }
if (sectionCount > 4) if (sectionCount > 4)
{ {
writer.writeUint32("animIdxCount", animIdxs.size()); writer.writeUint32("animIdxCount", animIdxs.size());
writer.enterSubVector("animIdxs"); writer.enumerate("animIdxs", animIdxs);
for (atUint32 idx : animIdxs)
writer.writeUint32(nullptr, idx);
writer.leaveSubVector();
} }
} }
@ -833,6 +636,14 @@ void ANCS::AnimationSet::MetaAnimFactory::fromYAML(Athena::io::YAMLDocReader& re
} }
void ANCS::AnimationSet::MetaAnimFactory::toYAML(Athena::io::YAMLDocWriter& writer) const
{
if (!m_anim)
return;
writer.writeString("type", m_anim->m_typeStr);
m_anim->toYAML(writer);
}
void ANCS::AnimationSet::MetaTransFactory::read(Athena::io::IStreamReader& reader) void ANCS::AnimationSet::MetaTransFactory::read(Athena::io::IStreamReader& reader)
{ {
IMetaTrans::Type type(IMetaTrans::Type(reader.readUint32())); IMetaTrans::Type type(IMetaTrans::Type(reader.readUint32()));
@ -905,67 +716,38 @@ void ANCS::AnimationSet::MetaTransFactory::toYAML(Athena::io::YAMLDocWriter& wri
m_trans->toYAML(writer); m_trans->toYAML(writer);
} }
void ANCS::AnimationSet::MetaAnimFactory::toYAML(Athena::io::YAMLDocWriter& writer) const
{
if (!m_anim)
return;
writer.writeString("type", m_anim->m_typeStr);
m_anim->toYAML(writer);
}
void ANCS::AnimationSet::read(Athena::io::IStreamReader& reader) void ANCS::AnimationSet::read(Athena::io::IStreamReader& reader)
{ {
atUint16 sectionCount = reader.readUint16(); atUint16 sectionCount = reader.readUint16();
atUint32 animationCount = reader.readUint32(); atUint32 animationCount = reader.readUint32();
animations.reserve(animationCount); reader.enumerate(animations, animationCount);
for (int i=0 ; i<animationCount ; ++i)
{
animations.emplace_back();
animations.back().read(reader);
}
atUint32 transitionCount = reader.readUint32(); atUint32 transitionCount = reader.readUint32();
transitions.reserve(transitionCount); reader.enumerate(transitions, transitionCount);
for (int i=0 ; i<transitionCount ; ++i) defaultTransition.read(reader);
{
transitions.emplace_back();
transitions.back().read(reader);
}
additiveAnims.clear();
if (sectionCount > 1) if (sectionCount > 1)
{ {
atUint32 additiveAnimCount = reader.readUint32(); atUint32 additiveAnimCount = reader.readUint32();
additiveAnims.reserve(additiveAnimCount); reader.enumerate(additiveAnims, additiveAnimCount);
for (int i=0 ; i<additiveAnimCount ; ++i)
{
additiveAnims.emplace_back();
additiveAnims.back().read(reader);
}
floatA = reader.readFloat(); floatA = reader.readFloat();
floatB = reader.readFloat(); floatB = reader.readFloat();
} }
halfTransitions.clear();
if (sectionCount > 2) if (sectionCount > 2)
{ {
atUint32 halfTransitionCount = reader.readUint32(); atUint32 halfTransitionCount = reader.readUint32();
halfTransitions.reserve(halfTransitionCount); reader.enumerate(halfTransitions, halfTransitionCount);
for (int i=0 ; i<halfTransitionCount ; ++i)
{
halfTransitions.emplace_back();
halfTransitions.back().read(reader);
}
} }
animResources.clear();
if (sectionCount > 3) if (sectionCount > 3)
{ {
atUint32 animResourcesCount = reader.readUint32(); atUint32 animResourcesCount = reader.readUint32();
animResources.reserve(animResourcesCount); reader.enumerate(animResources, animResourcesCount);
for (int i=0 ; i<animResourcesCount ; ++i)
{
animResources.emplace_back();
animResources.back().read(reader);
}
} }
} }
@ -984,18 +766,16 @@ void ANCS::AnimationSet::write(Athena::io::IStreamWriter& writer) const
writer.writeUint16(sectionCount); writer.writeUint16(sectionCount);
writer.writeUint32(animations.size()); writer.writeUint32(animations.size());
for (const auto& anim : animations) writer.enumerate(animations);
anim.write(writer);
writer.writeUint32(transitions.size()); writer.writeUint32(transitions.size());
for (const auto& trans : transitions) writer.enumerate(transitions);
trans.write(writer); defaultTransition.write(writer);
if (sectionCount > 1) if (sectionCount > 1)
{ {
writer.writeUint32(additiveAnims.size()); writer.writeUint32(additiveAnims.size());
for (const auto& aa : additiveAnims) writer.enumerate(additiveAnims);
aa.write(writer);
writer.writeFloat(floatA); writer.writeFloat(floatA);
writer.writeFloat(floatB); writer.writeFloat(floatB);
} }
@ -1003,15 +783,13 @@ void ANCS::AnimationSet::write(Athena::io::IStreamWriter& writer) const
if (sectionCount > 2) if (sectionCount > 2)
{ {
writer.writeUint32(halfTransitions.size()); writer.writeUint32(halfTransitions.size());
for (const auto& ht : halfTransitions) writer.enumerate(halfTransitions);
ht.write(writer);
} }
if (sectionCount > 3) if (sectionCount > 3)
{ {
writer.writeUint32(animResources.size()); writer.writeUint32(animResources.size());
for (const auto& ar : animResources) writer.enumerate(animResources);
ar.write(writer);
} }
} }
@ -1020,74 +798,33 @@ void ANCS::AnimationSet::fromYAML(Athena::io::YAMLDocReader& reader)
atUint16 sectionCount = reader.readUint16("sectionCount"); atUint16 sectionCount = reader.readUint16("sectionCount");
atUint32 animationCount = reader.readUint32("animationCount"); atUint32 animationCount = reader.readUint32("animationCount");
animations.reserve(animationCount); reader.enumerate("animations", animations, animationCount);
reader.enterSubVector("animations");
for (int i=0 ; i<animationCount ; ++i)
{
animations.emplace_back();
reader.enterSubRecord(nullptr);
animations.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
atUint32 transitionCount = reader.readUint32("transitionCount"); atUint32 transitionCount = reader.readUint32("transitionCount");
transitions.reserve(transitionCount); reader.enumerate("transitions", transitions, transitionCount);
reader.enterSubVector("transitions"); reader.enumerate("defaultTransition", defaultTransition);
for (int i=0 ; i<transitionCount ; ++i)
{
transitions.emplace_back();
reader.enterSubRecord(nullptr);
transitions.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
additiveAnims.clear();
if (sectionCount > 1) if (sectionCount > 1)
{ {
atUint32 additiveAnimCount = reader.readUint32("additiveAnimCount"); atUint32 additiveAnimCount = reader.readUint32("additiveAnimCount");
additiveAnims.reserve(additiveAnimCount); reader.enumerate("additiveAnims", additiveAnims, additiveAnimCount);
reader.enterSubVector("additiveAnims");
for (int i=0 ; i<additiveAnimCount ; ++i)
{
additiveAnims.emplace_back();
reader.enterSubRecord(nullptr);
additiveAnims.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
floatA = reader.readFloat("floatA"); floatA = reader.readFloat("floatA");
floatB = reader.readFloat("floatB"); floatB = reader.readFloat("floatB");
} }
halfTransitions.clear();
if (sectionCount > 2) if (sectionCount > 2)
{ {
atUint32 halfTransitionCount = reader.readUint32("halfTransitionCount"); atUint32 halfTransitionCount = reader.readUint32("halfTransitionCount");
halfTransitions.reserve(halfTransitionCount); reader.enumerate("halfTransitions", halfTransitions, halfTransitionCount);
reader.enterSubVector("halfTransitions");
for (int i=0 ; i<halfTransitionCount ; ++i)
{
halfTransitions.emplace_back();
reader.enterSubRecord(nullptr);
halfTransitions.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
} }
animResources.clear();
if (sectionCount > 3) if (sectionCount > 3)
{ {
atUint32 animResourcesCount = reader.readUint32("animResourcesCount"); atUint32 animResourcesCount = reader.readUint32("animResourcesCount");
animResources.reserve(animResourcesCount); reader.enumerate("animResources", animResources, animResourcesCount);
reader.enterSubVector("animResources");
for (int i=0 ; i<animResourcesCount ; ++i)
{
animResources.emplace_back();
reader.enterSubRecord(nullptr);
animResources.back().fromYAML(reader);
reader.leaveSubRecord();
}
reader.leaveSubVector();
} }
} }
@ -1106,36 +843,16 @@ void ANCS::AnimationSet::toYAML(Athena::io::YAMLDocWriter& writer) const
writer.writeUint16("sectionCount", sectionCount); writer.writeUint16("sectionCount", sectionCount);
writer.writeUint32("animationCount", animations.size()); writer.writeUint32("animationCount", animations.size());
writer.enterSubVector("animations"); writer.enumerate("animations", animations);
for (const auto& anim : animations)
{
writer.enterSubRecord(nullptr);
anim.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.writeUint32("transitionCount", transitions.size()); writer.writeUint32("transitionCount", transitions.size());
writer.enterSubVector("transitions"); writer.enumerate("transitions", transitions);
for (const auto& trans : transitions) writer.enumerate("defaultTransition", defaultTransition);
{
writer.enterSubRecord(nullptr);
trans.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
if (sectionCount > 1) if (sectionCount > 1)
{ {
writer.writeUint32("additiveAnimCount", additiveAnims.size()); writer.writeUint32("additiveAnimCount", additiveAnims.size());
writer.enterSubVector("additiveAnims"); writer.enumerate("additiveAnims", additiveAnims);
for (const auto& aa : additiveAnims)
{
writer.enterSubRecord(nullptr);
aa.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
writer.writeFloat("floatA", floatA); writer.writeFloat("floatA", floatA);
writer.writeFloat("floatB", floatB); writer.writeFloat("floatB", floatB);
} }
@ -1143,27 +860,13 @@ void ANCS::AnimationSet::toYAML(Athena::io::YAMLDocWriter& writer) const
if (sectionCount > 2) if (sectionCount > 2)
{ {
writer.writeUint32("halfTransitionCount", halfTransitions.size()); writer.writeUint32("halfTransitionCount", halfTransitions.size());
writer.enterSubVector("halfTransitions"); writer.enumerate("halfTransitions", halfTransitions);
for (const auto& ht : halfTransitions)
{
writer.enterSubRecord(nullptr);
ht.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
} }
if (sectionCount > 3) if (sectionCount > 3)
{ {
writer.writeUint32("animResourcesCount", animResources.size()); writer.writeUint32("animResourcesCount", animResources.size());
writer.enterSubVector("animResources"); writer.enumerate("animResources", animResources);
for (const auto& ar : animResources)
{
writer.enterSubRecord(nullptr);
ar.toYAML(writer);
writer.leaveSubRecord();
}
writer.leaveSubVector();
} }
} }

View File

@ -20,6 +20,7 @@ struct ANCS : BigYAML
Value<atUint32> characterCount; Value<atUint32> characterCount;
struct CharacterInfo : BigYAML struct CharacterInfo : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
atUint32 idx; atUint32 idx;
@ -45,11 +46,13 @@ struct ANCS : BigYAML
Value<atUint32> defaultState; Value<atUint32> defaultState;
struct AnimState : BigYAML struct AnimState : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
atUint32 id; atUint32 id;
struct ParmInfo : BigYAML struct ParmInfo : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
enum DataType enum DataType
{ {
@ -76,11 +79,6 @@ struct ANCS : BigYAML
atUint32 unk1; atUint32 unk1;
float unk2; float unk2;
Parm parmVals[2]; Parm parmVals[2];
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
}; };
std::vector<ParmInfo> parmInfos; std::vector<ParmInfo> parmInfos;
@ -90,12 +88,8 @@ struct ANCS : BigYAML
std::vector<ParmInfo::Parm> parmVals; std::vector<ParmInfo::Parm> parmVals;
}; };
std::vector<AnimInfo> animInfos; std::vector<AnimInfo> animInfos;
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
}; };
Vector<AnimState, DNA_COUNT(animStateCount)> animStates;
} pasDatabase; } pasDatabase;
struct ParticleResData struct ParticleResData
@ -106,7 +100,9 @@ struct ANCS : BigYAML
std::vector<UniqueID32> elsc; std::vector<UniqueID32> elsc;
} partResData; } partResData;
atUint32 unk1; atUint32 unk1 = 0;
atUint32 unk2 = 0;
atUint32 unk3 = 0;
struct ActionAABB : BigYAML struct ActionAABB : BigYAML
{ {
@ -140,17 +136,13 @@ struct ANCS : BigYAML
UniqueID32 cskrOverride; UniqueID32 cskrOverride;
std::vector<atUint32> animIdxs; std::vector<atUint32> animIdxs;
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
}; };
Vector<CharacterInfo, DNA_COUNT(characterCount)> characters;
} characterSet; } characterSet;
struct AnimationSet : BigYAML struct AnimationSet : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
struct IMetaAnim : BigYAML struct IMetaAnim : BigYAML
@ -174,12 +166,9 @@ struct ANCS : BigYAML
}; };
struct MetaAnimFactory : BigYAML struct MetaAnimFactory : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
std::unique_ptr<IMetaAnim> m_anim; std::unique_ptr<IMetaAnim> m_anim;
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
}; };
struct MetaAnimPrimitive : IMetaAnim struct MetaAnimPrimitive : IMetaAnim
{ {
@ -258,12 +247,9 @@ struct ANCS : BigYAML
}; };
struct MetaTransFactory : BigYAML struct MetaTransFactory : BigYAML
{ {
DECL_YAML
Delete expl; Delete expl;
std::unique_ptr<IMetaTrans> m_trans; std::unique_ptr<IMetaTrans> m_trans;
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
}; };
struct MetaTransMetaAnim : IMetaTrans struct MetaTransMetaAnim : IMetaTrans
{ {
@ -280,7 +266,6 @@ struct ANCS : BigYAML
Value<atUint8> unk2; Value<atUint8> unk2;
Value<atUint8> unk3; Value<atUint8> unk3;
Value<atUint32> unk4; Value<atUint32> unk4;
}; };
struct MetaTransPhaseTrans : IMetaTrans struct MetaTransPhaseTrans : IMetaTrans
{ {
@ -302,6 +287,7 @@ struct ANCS : BigYAML
MetaTransFactory metaTrans; MetaTransFactory metaTrans;
}; };
std::vector<Transition> transitions; std::vector<Transition> transitions;
MetaTransFactory defaultTransition;
struct AdditiveAnimationInfo : BigYAML struct AdditiveAnimationInfo : BigYAML
{ {
@ -330,12 +316,17 @@ struct ANCS : BigYAML
UniqueID32 evntId; UniqueID32 evntId;
}; };
std::vector<AnimationResources> animResources; std::vector<AnimationResources> animResources;
void read(Athena::io::IStreamReader& reader);
void write(Athena::io::IStreamWriter& writer) const;
void fromYAML(Athena::io::YAMLDocReader& reader);
void toYAML(Athena::io::YAMLDocWriter& writer) const;
} animationSet; } animationSet;
static bool Extract(const SpecBase&, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath)
{
ANCS ancs;
ancs.read(rs);
FILE* fp = HECL::Fopen(outPath.getAbsolutePath().c_str(), _S("wb"));
ancs.toYAMLFile(fp);
fclose(fp);
return true;
}
}; };
} }

View File

@ -6,6 +6,7 @@
#include "MLVL.hpp" #include "MLVL.hpp"
#include "../DNACommon/TXTR.hpp" #include "../DNACommon/TXTR.hpp"
#include "CMDL.hpp" #include "CMDL.hpp"
#include "ANCS.hpp"
namespace Retro namespace Retro
{ {
@ -181,6 +182,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK::Entry& entry)
return {TXTR::Extract, nullptr, ".png"}; return {TXTR::Extract, nullptr, ".png"};
case SBIG('CMDL'): case SBIG('CMDL'):
return {nullptr, CMDL::Extract, ".blend", 1}; return {nullptr, CMDL::Extract, ".blend", 1};
case SBIG('ANCS'):
return {ANCS::Extract, nullptr, ".yaml"};
case SBIG('MLVL'): case SBIG('MLVL'):
return {MLVL::Extract, nullptr, ".yaml"}; return {MLVL::Extract, nullptr, ".yaml"};
} }

View File

@ -174,73 +174,5 @@ void STRG::toYAML(Athena::io::YAMLDocWriter& writer) const
} }
} }
bool STRG::readAngelScript(const AngelScript::asIScriptModule& in)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
/* Validate pass */
for (AngelScript::asUINT i=0 ; i<in.GetGlobalVarCount() ; ++i)
{
const char* name;
int typeId;
if (in.GetGlobalVar(i, &name, 0, &typeId) < 0)
continue;
if (typeId == ASTYPE_STRGLanguage.getTypeID())
{
if (strlen(name) != 4)
{
Log.report(LogVisor::Error, "STRG language string '%s' from %s must be exactly 4 characters", name, in.GetName());
return false;
}
}
}
/* Read pass */
langs.clear();
for (AngelScript::asUINT i=0 ; i<in.GetGlobalVarCount() ; ++i)
{
const char* name;
int typeId;
if (in.GetGlobalVar(i, &name, 0, &typeId) < 0)
continue;
if (typeId == ASTYPE_STRGLanguage.getTypeID())
{
const std::vector<std::string*>& strsin = ASTYPE_STRGLanguage.vectorCast(in.GetAddressOfGlobalVar(i));
std::vector<std::wstring> strs;
for (const std::string* str : strsin)
strs.emplace_back(wconv.from_bytes(*str));
langs.emplace_back(FourCC(name), strs);
}
}
langMap.clear();
langMap.reserve(langs.size());
for (std::pair<FourCC, std::vector<std::wstring>>& item : langs)
langMap.emplace(item.first, &item.second);
return true;
}
void STRG::writeAngelScript(std::ofstream& out) const
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
{
out << "STRG::Language " << lang.first.toString() << "({";
bool comma = false;
unsigned idx = 0;
for (const std::wstring& str : lang.second)
{
if (comma)
out << ",";
out << "\n/* " << idx++ << " */ \"";
out << wconv.to_bytes(str);
out << "\"";
comma = true;
}
out << "\n});\n";
}
}
} }
} }

View File

@ -58,9 +58,6 @@ struct STRG : ISTRG, BigYAML
return HECL::SystemString(); return HECL::SystemString();
} }
bool readAngelScript(const AngelScript::asIScriptModule& in);
void writeAngelScript(std::ofstream& out) const;
static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath) static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath)
{ {
STRG strg; STRG strg;

View File

@ -139,43 +139,5 @@ void STRG::write(Athena::io::IStreamWriter& writer) const
} }
} }
bool STRG::readAngelScript(const AngelScript::asIScriptModule& in)
{
return false;
}
void STRG::writeAngelScript(std::ofstream& out) const
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
{
out << "STRG::Language " << lang.first.toString() << "({";
bool comma = false;
unsigned idx = 0;
for (const std::wstring& str : lang.second)
{
if (comma)
out << ",";
out << "\n/* " << idx++ << " */ \"";
out << wconv.to_bytes(str);
out << "\"";
comma = true;
}
out << "\n});\n";
}
out << "STRG::Names NAMES({";
bool comma = false;
for (const std::pair<std::string, int32_t>& name : names)
{
if (comma)
out << ",";
out << "\n ";
comma = true;
out << "{\"" << name.first << "\", " << name.second << "}";
}
out << "\n});\n";
}
} }
} }

View File

@ -63,27 +63,13 @@ struct STRG : ISTRG, BigDNA
return HECL::SystemString(); return HECL::SystemString();
} }
bool readAngelScript(const AngelScript::asIScriptModule& in);
void writeAngelScript(std::ofstream& out) const;
static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath) static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath)
{ {
STRG strg;
strg.read(rs);
std::ofstream strgOut(outPath.getAbsolutePath());
strg.writeAngelScript(strgOut);
return true; return true;
} }
static bool Cook(const HECL::ProjectPath& inPath, const HECL::ProjectPath& outPath) static bool Cook(const HECL::ProjectPath& inPath, const HECL::ProjectPath& outPath)
{ {
STRG strg;
HECL::Database::ASUniqueModule mod = HECL::Database::ASUniqueModule::CreateFromPath(inPath);
if (!mod)
return false;
strg.readAngelScript(mod);
Athena::io::FileWriter ws(outPath.getAbsolutePath());
strg.write(ws);
return true; return true;
} }
}; };

View File

@ -147,41 +147,5 @@ void STRG::write(Athena::io::IStreamWriter& writer) const
} }
} }
bool STRG::readAngelScript(const AngelScript::asIScriptModule& in)
{
return false;
}
void STRG::writeAngelScript(std::ofstream& out) const
{
for (const std::pair<FourCC, std::vector<std::string>>& lang : langs)
{
out << "STRG::Language " << lang.first.toString() << "({";
bool comma = false;
unsigned idx = 0;
for (const std::string& str : lang.second)
{
if (comma)
out << ",";
out << "\n/* " << idx++ << " */ \"";
out << str << "\"";
comma = true;
}
out << "\n});\n";
}
out << "STRG::Names NAMES({";
bool comma = false;
for (const std::pair<std::string, int32_t>& name : names)
{
if (comma)
out << ",";
out << "\n ";
comma = true;
out << "{\"" << name.first << "\", " << name.second << "}";
}
out << "\n});\n";
}
} }
} }

View File

@ -63,26 +63,13 @@ struct STRG : ISTRG, BigDNA
return HECL::SystemString(); return HECL::SystemString();
} }
bool readAngelScript(const AngelScript::asIScriptModule& in);
void writeAngelScript(std::ofstream& out) const;
static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath) static bool Extract(const SpecBase& dataspec, PAKEntryReadStream& rs, const HECL::ProjectPath& outPath)
{ {
std::unique_ptr<ISTRG> strg = LoadSTRG(rs);
std::ofstream strgOut(outPath.getAbsolutePath());
strg->writeAngelScript(strgOut);
return true; return true;
} }
static bool Cook(const HECL::ProjectPath& inPath, const HECL::ProjectPath& outPath) static bool Cook(const HECL::ProjectPath& inPath, const HECL::ProjectPath& outPath)
{ {
STRG strg;
HECL::Database::ASUniqueModule mod = HECL::Database::ASUniqueModule::CreateFromPath(inPath);
if (!mod)
return false;
strg.readAngelScript(mod);
Athena::io::FileWriter ws(outPath.getAbsolutePath());
strg.write(ws);
return true; return true;
} }
}; };