diff --git a/DataSpec/DNAMP1/AFSM.hpp b/DataSpec/DNAMP1/AFSM.hpp new file mode 100644 index 000000000..07071a065 --- /dev/null +++ b/DataSpec/DNAMP1/AFSM.hpp @@ -0,0 +1,175 @@ +#ifndef _RETRO_AFSM_HPP_ +#define _RETRO_AFSM_HPP_ + +#include +#include "../DNACommon/DNACommon.hpp" +#include "DNAMP1.hpp" + +namespace Retro +{ +namespace DNAMP1 +{ +struct AFSM : public BigYAML +{ + DECL_YAML + Value stateCount; + Vector, DNA_COUNT(stateCount)> stateNames; + Value triggerCount; + + struct State : public BigYAML + { + DECL_YAML + Value transitionCount; + struct Transition : public BigYAML + { + Delete _d; + Value triggerCount; + + struct Trigger : public BigYAML + { + Delete _d; + bool first = false; + String<-1> name; + Value parameter; + Value targetState; + void read(Athena::io::IStreamReader& __dna_reader) + { + /* name */ + name = __dna_reader.readString(-1); + /* parameter */ + parameter = __dna_reader.readFloatBig(); + if (first) + { + /* targetState */ + targetState = __dna_reader.readUint32Big(); + } + } + + void write(Athena::io::IStreamWriter& __dna_writer) const + { + /* name */ + __dna_writer.writeString(name, -1); + /* parameter */ + __dna_writer.writeFloatBig(parameter); + if (first) + { + /* targetState */ + __dna_writer.writeUint32Big(targetState); + } + } + + void read(Athena::io::YAMLDocReader& __dna_docin) + { + /* name */ + name = __dna_docin.readString("name"); + /* parameter */ + parameter = __dna_docin.readFloat("parameter"); + if (first) + { + /* targetState */ + targetState = __dna_docin.readUint32("targetState"); + } + } + + void write(Athena::io::YAMLDocWriter& __dna_docout) const + { + /* name */ + __dna_docout.writeString("name", name); + /* parameter */ + __dna_docout.writeFloat("parameter", parameter); + if (first) + { + /* targetState */ + __dna_docout.writeUint32("targetState", targetState); + } + } + + static const char* DNAType() + { + return "Retro::DNAMP1::AFSM::Transition::Trigger"; + } + + size_t binarySize(size_t __isz) const + { + __isz += name.size() + 1; + return __isz + (first ? 8 : 4); + } + }; + + Vector triggers; + + void read(Athena::io::IStreamReader& __dna_reader) + { + /* triggerCount */ + triggerCount = __dna_reader.readUint32Big(); + int i = 0; + /* triggers */ + __dna_reader.enumerate(triggers, triggerCount, + [&](Athena::io::IStreamReader& in, Trigger& tr){ + tr.first = i == 0; + tr.read(in); + i++; + }); + } + + void write(Athena::io::IStreamWriter& __dna_writer) const + { + /* triggerCount */ + __dna_writer.writeInt32Big(triggerCount); + /* triggers */ + __dna_writer.enumerate(triggers); + } + + void read(Athena::io::YAMLDocReader& __dna_docin) + { + /* triggerCount */ + triggerCount = __dna_docin.readUint32("triggerCount"); + int i = 0; + /* triggers */ + __dna_docin.enumerate("triggers", triggers, triggerCount, + [&](Athena::io::YAMLDocReader& in, Trigger& tr){ + tr.first = i == 0; + tr.read(in); + i++; + }); + } + + void write(Athena::io::YAMLDocWriter& __dna_docout) const + { + /* triggerCount */ + __dna_docout.writeUint32("triggerCount", triggerCount); + /* triggers */ + __dna_docout.enumerate("triggers", triggers); + } + + static const char* DNAType() + { + return "Retro::DNAMP1::AFSM::Transition"; + } + + size_t binarySize(size_t __isz) const + { + __isz = __EnumerateSize(__isz, triggers); + return __isz + 4; + } + }; + + Vector transitions; + }; + + Vector states; + + static bool Extract(PAKEntryReadStream& rs, const HECL::ProjectPath& outPath) + { + AFSM afsm; + afsm.read(rs); + FILE* fp = HECL::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); + afsm.toYAMLFile(fp); + fclose(fp); + return true; + } +}; +} +} + +#endif // _RETRO_AFSM_HPP_ diff --git a/DataSpec/DNAMP1/CMakeLists.txt b/DataSpec/DNAMP1/CMakeLists.txt index 0ecc0cf9e..ea89c972c 100644 --- a/DataSpec/DNAMP1/CMakeLists.txt +++ b/DataSpec/DNAMP1/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(ScriptObjects) make_dnalist(liblist PAK MLVL + AFSM ANCS ANIM CINF diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index 9a1db6a3f..381129c67 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -8,6 +8,7 @@ #include "../DNACommon/TXTR.hpp" #include "../DNACommon/PART.hpp" #include "CMDL.hpp" +#include "AFSM.hpp" #include "ANCS.hpp" #include "MREA.hpp" #include "MAPA.hpp" @@ -270,6 +271,8 @@ ResExtractor PAKBridge::LookupExtractor(const PAK::Entry& entry) return {SCAN::Extract, nullptr, {_S(".yaml")}, 0, SCAN::Name}; case SBIG('TXTR'): return {TXTR::Extract, nullptr, {_S(".png")}}; + case SBIG('AFSM'): + return {AFSM::Extract, nullptr, {_S(".yaml")}}; case SBIG('FRME'): return {nullptr, FRME::Extract, {_S(".blend")}, 2}; case SBIG('CMDL'):