diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2024-03-23 01:57:53 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-23 01:57:53 -0600 |
| commit | cd7dd6f59a9b0ffb867fcd7b80a6c05def701088 (patch) | |
| tree | 8c07c17342f850dbad89dd77f215f179572e6db6 /src/factories/mk64/DrivingBehaviour.cpp | |
| parent | 5c6fa9c1f6ad4b07426a6f360ccf2d54b0c94cb8 (diff) | |
Add Mtx, float, and mk64 Factories (#43)
* Create MtxFactory.cpp
* Add mtx factory
* Implement mtx output
* Changed implementation
* Update comment
* Finish Mtx factory
* Add float factory
* Add runtime error for untested code
* Add DrivingBehaviour factory & fix bug
* Remove limit
* Add mk64 graphics
* Changes
* fix
* Update
* Improve error checking
Diffstat (limited to 'src/factories/mk64/DrivingBehaviour.cpp')
| -rw-r--r-- | src/factories/mk64/DrivingBehaviour.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/factories/mk64/DrivingBehaviour.cpp b/src/factories/mk64/DrivingBehaviour.cpp new file mode 100644 index 0000000..76e355a --- /dev/null +++ b/src/factories/mk64/DrivingBehaviour.cpp @@ -0,0 +1,98 @@ +#include "DrivingBehaviour.h" +#include "spdlog/spdlog.h" + +#include "Companion.h" +#include "utils/Decompressor.h" + +#define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x +#define COL(c) std::dec << std::setfill(' ') << std::setw(3) << c + +ExportResult MK64::DrivingBehaviourHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { + const auto symbol = GetSafeNode(node, "symbol", entryName); + + if(Companion::Instance->IsOTRMode()){ + write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + return std::nullopt; + } + + write << "extern DrivingBehaviour " << symbol << "[];\n"; + return std::nullopt; +} + +ExportResult MK64::DrivingBehaviourCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto bhv = std::static_pointer_cast<DrivingData>(raw); + const auto symbol = GetSafeNode(node, "symbol", entryName); + auto offset = GetSafeNode<uint32_t>(node, "offset"); + + if (IS_SEGMENTED(offset)) { + offset = SEGMENT_OFFSET(offset); + } + + if (Companion::Instance->IsDebug()) { + if (IS_SEGMENTED(offset)) { + offset = SEGMENT_OFFSET(offset); + } + write << "// 0x" << std::hex << std::uppercase << offset << "\n"; + } + + write << "DrivingBehaviour " << symbol << "[] = {\n"; + + + for(auto b : bhv->mBhvs) { + auto w1 = b.waypoint1; + auto w2 = b.waypoint2; + auto id = b.bhv; + + // { w1, w2, bhvId} + write << fourSpaceTab << "{" << NUM(w1) << ", " << NUM(w2) << ", " << NUM(id) << "},\n"; + } + + write << "};\n"; + + if (Companion::Instance->IsDebug()) { + write << "// count: " << std::to_string(bhv->mBhvs.size()) << " Entries\n"; + write << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(BhvRaw) * bhv->mBhvs.size())) << "\n"; + } + + write << "\n"; + return offset + bhv->mBhvs.size() * sizeof(BhvRaw); +} + +ExportResult MK64::DrivingBehaviourBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto bhv = std::static_pointer_cast<DrivingData>(raw); + auto writer = LUS::BinaryWriter(); + + WriteHeader(writer, LUS::ResourceType::DrivingBehaviour, 0); + writer.Write((uint32_t) bhv->mBhvs.size()); + for(auto b : bhv->mBhvs) { + writer.Write(b.waypoint1); + writer.Write(b.waypoint2); + writer.Write(b.bhv); + } + + writer.Finish(write); + return std::nullopt; +} + +std::optional<std::shared_ptr<IParsedData>> MK64::DrivingBehaviourFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { + auto [_, segment] = Decompressor::AutoDecode(node, buffer); + LUS::BinaryReader reader(segment.data, segment.size); + + reader.SetEndianness(LUS::Endianness::Big); + std::vector<BhvRaw> behaviours; + + while(1) { + auto w1 = reader.ReadInt16(); + auto w2 = reader.ReadInt16(); + auto id = reader.ReadInt32(); + + behaviours.push_back( BhvRaw( {w1, w2, id} ) ); + + // Magic number for ending of array + if ((w1 == -1) && (w2 == -1)) { + break; + } + } + + return std::make_shared<DrivingData>(behaviours); +}
\ No newline at end of file |
