diff options
| author | Lywx <kiritodev01@gmail.com> | 2024-03-20 21:17:11 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-20 21:17:11 -0600 |
| commit | f0c70f855a892ca7dc21cee4b4037dad983adb8f (patch) | |
| tree | f15cc271b00166476a2e7b780e50d911770a7316 | |
| parent | 8465919ab7aba6cfde7d25ad1731673e5da01642 (diff) | |
Auto pad and overlap detection (#47)
* Fully implemented pad and overlap detection
* Cleaned code, fixed pad generation and added alignment
* Added debug size on pads
62 files changed, 405 insertions, 407 deletions
diff --git a/TemplateFactory.cpp b/TemplateFactory.cpp index 60e03fc..811231b 100644 --- a/TemplateFactory.cpp +++ b/TemplateFactory.cpp @@ -6,29 +6,29 @@ #include "utils/TorchUtils.h" TypeData::TypeData(uint32_t data): mData(data) { - + } -void TypeHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult TypeHeaderExporter::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; + return std::nullopt; } write << "extern Type " << symbol << ";\n"; // write << "extern Type " << symbol << "[];\n"; } -void TypeCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult TypeCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto data = std::static_pointer_cast<TypeData>(raw); - + } -void TypeBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult TypeBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { } diff --git a/TemplateFactory.h b/TemplateFactory.h index 34bb960..16bcf00 100644 --- a/TemplateFactory.h +++ b/TemplateFactory.h @@ -12,23 +12,20 @@ public: }; class TypeHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TypeBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TypeCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TypeFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, TypeCodeExporter) @@ -36,6 +33,5 @@ public: REGISTER(Binary, TypeBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; // } diff --git a/src/Companion.cpp b/src/Companion.cpp index 7784fe7..96d6773 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -48,6 +48,8 @@ namespace fs = std::filesystem; static const std::string regular = "[%Y-%m-%d %H:%M:%S.%e] [%l] %v"; static const std::string line = "[%Y-%m-%d %H:%M:%S.%e] [%l] > %v"; +#define ABS(x) ((x) < 0 ? -(x) : (x)) + void Companion::Init(const ExportType type) { spdlog::set_level(spdlog::level::debug); @@ -137,7 +139,7 @@ void Companion::ParseEnums(std::string& header) { enumIndex++; this->gEnums[enumName][enumIndex] = line; } - + } } @@ -210,6 +212,8 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar spdlog::set_pattern(line); } + ExportResult endptr = std::nullopt; + switch (this->gConfig.exporterType) { case ExportType::Binary: { if(binary == nullptr) { @@ -246,29 +250,58 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar file.close(); break; } - default: { - exporter->get()->Export(stream, result.value(), name, node, &name); - - if(this->gConfig.exporterType == ExportType::Code) { - if(node["pad"]){ - auto filename = this->gCurrentDirectory.filename().string(); - auto pad = GetSafeNode<uint32_t>(node, "pad"); - stream << "char pad_" << filename << "_" << std::to_string(gCurrentPad++) << "[] = {\n" << tab; - for(int i = 0; i < pad; i++){ - stream << "0x00, "; - } - stream << "\n};\n\n"; - } + case ExportType::Code: { + endptr = exporter->get()->Export(stream, result.value(), name, node, &name); + if (this->IsDebug() && endptr.has_value() && endptr->index() == 0) { + stream << "// 0x" << std::hex << std::uppercase << std::get<0>(endptr.value()) << "\n\n"; } - + break; + } + default: { + endptr = exporter->get()->Export(stream, result.value(), name, node, &name); break; } } SPDLOG_INFO("Processed {}", name); + WriteEntry entry; if(node["offset"]) { - this->gWriteMap[this->gCurrentFile][type].emplace_back(node["offset"].as<uint32_t>(), stream.str()); + auto alignment = GetSafeNode<uint32_t>(node, "alignment", impl->GetAlignment()); + if(!endptr.has_value()) { + entry = { + node["offset"].as<uint32_t>(), + alignment, + stream.str(), + std::nullopt + }; + } else { + switch (endptr->index()) { + case 0: + entry = { + node["offset"].as<uint32_t>(), + alignment, + stream.str(), + std::get<size_t>(endptr.value()) + }; + break; + case 1: { + const auto oentry = std::get<OffsetEntry>(endptr.value()); + entry = { + oentry.start, + alignment, + stream.str(), + oentry.end + }; + break; + } + default: + SPDLOG_ERROR("Invalid endptr index {}", endptr->index()); + SPDLOG_ERROR("Type of endptr: {}", typeid(endptr).name()); + throw std::runtime_error("We should never reach this point"); + } + } } + this->gWriteMap[this->gCurrentFile][type].push_back(entry); } void Companion::ParseModdingConfig() { @@ -355,6 +388,8 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) { const auto offset = GetSafeNode<uint32_t>(vram, "offset"); this->gCurrentVram = { addr, offset }; } + + this->gEnablePadGen = GetSafeNode<bool>(node, "autopads", true); } void Companion::Process() { @@ -699,44 +734,83 @@ void Companion::Process() { std::ostringstream stream; + std::vector<WriteEntry> entries; + if(std::holds_alternative<std::string>(this->gWriteOrder)) { auto sort = std::get<std::string>(this->gWriteOrder); - std::vector<std::pair<uint32_t, std::string>> outbuf; - for (const auto& [type, buffer] : this->gWriteMap[this->gCurrentFile]) { - outbuf.insert(outbuf.end(), buffer.begin(), buffer.end()); + for (const auto& [type, raw] : this->gWriteMap[this->gCurrentFile]) { + entries.insert(entries.end(), raw.begin(), raw.end()); } - this->gWriteMap.clear(); if(sort == "OFFSET") { - std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) { - return std::get<uint32_t>(a) < std::get<uint32_t>(b); + std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) { + return a.addr < b.addr; }); } else if(sort == "ROFFSET") { - std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) { - return std::get<uint32_t>(a) > std::get<uint32_t>(b); + std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) { + return a.addr > b.addr; }); } else if(sort != "LINEAR") { throw std::runtime_error("Invalid write order"); } - - for (auto& [symbol, buffer] : outbuf) { - stream << buffer; - } - outbuf.clear(); } else { for (const auto& type : std::get<std::vector<std::string>>(this->gWriteOrder)) { - std::vector<std::pair<uint32_t, std::string>> outbuf = this->gWriteMap[this->gCurrentFile][type]; + entries = this->gWriteMap[this->gCurrentFile][type]; - std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) { - return std::get<uint32_t>(a) > std::get<uint32_t>(b); + std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) { + return a.addr > b.addr; }); + } + } - for (auto& [symbol, buffer] : outbuf) { - stream << buffer; + for (size_t i = 0; i < entries.size(); i++) { + const auto result = entries[i]; + stream << result.buffer; + + if(i < entries.size() - 1 && this->gConfig.exporterType == ExportType::Code){ + auto endptr = result.endptr; + if(!endptr.has_value()){ + continue; + } + +#define ASSET_PTR(x) IS_SEGMENTED(x) ? SEGMENT_OFFSET(x) : x + + uint32_t startptr = ASSET_PTR(result.endptr.value()); + uint32_t end = ASSET_PTR(entries[i + 1].addr); + + uint32_t alignment = entries[i + 1].alignment; + int32_t gap = end - startptr; + + if(gap < 0x10 && gap >= alignment && end % 0x10 == 0 && this->gEnablePadGen) { + SPDLOG_WARN("Gap detected between 0x{:X} and 0x{:X} with size 0x{:X} on file {}", startptr, end, gap, this->gCurrentFile); + SPDLOG_WARN("Creating pad of 0x{:X} bytes", gap); + const auto padfile = this->gCurrentDirectory.filename().string(); + if(this->IsDebug()){ + stream << "// 0x" << std::hex << startptr << "\n"; + } + stream << "char pad_" << padfile << "_" << std::to_string(gCurrentPad++) << "[] = {\n" << tab; + auto gapSize = gap & ~3; + for(size_t j = 0; j < gapSize; j++){ + stream << "0x00, "; + } + stream << "\n};\n"; + if(this->IsDebug()){ + stream << "// 0x" << std::hex << end << "\n\n"; + } else { + stream << "\n"; + } + } else if(gap > 0x10) { + stream << "\n// WARNING: Gap detected between 0x" << std::hex << startptr << " and 0x" << end << " with size 0x" << gap << " on file " << this->gCurrentFile << "\n"; + } + + if(gap < 0) { + SPDLOG_WARN("Overlap detected between 0x{:X} and 0x{:X}", startptr, end); } } } + this->gWriteMap.clear(); + std::string buffer = stream.str(); if(buffer.empty()) { @@ -1002,7 +1076,7 @@ std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) { std::string output; std::string typeId = ConvertType(type); int index; - + if(symbol != "") { output = symbol; } else if(Decompressor::IsSegmented(offset)){ diff --git a/src/Companion.h b/src/Companion.h index 7e38fea..abe8ce9 100644 --- a/src/Companion.h +++ b/src/Companion.h @@ -51,6 +51,13 @@ struct VRAMEntry { uint32_t offset; }; +struct WriteEntry { + uint32_t addr; + uint32_t alignment; + std::string buffer; + std::optional<uint32_t> endptr; +}; + struct GBIConfig { GBIVersion version = GBIVersion::f3d; GBIMinorVersion subversion = GBIMinorVersion::None; @@ -123,6 +130,7 @@ private: // Temporal Variables std::string gCurrentFile; std::string gFileHeader; + bool gEnablePadGen = false; uint32_t gCurrentPad = 0; uint32_t gCurrentFileOffset; uint32_t gCurrentSegmentNumber; @@ -132,8 +140,8 @@ private: std::variant<std::vector<std::string>, std::string> gWriteOrder; std::unordered_map<std::string, std::shared_ptr<BaseFactory>> gFactories; std::unordered_map<std::string, std::string> gModdedAssetPaths; + std::unordered_map<std::string, std::map<std::string, std::vector<WriteEntry>>> gWriteMap; std::unordered_map<std::string, std::map<std::string, std::pair<YAML::Node, bool>>> gAssetDependencies; - std::unordered_map<std::string, std::map<std::string, std::vector<std::pair<uint32_t, std::string>>>> gWriteMap; std::unordered_map<std::string, std::unordered_map<uint32_t, std::tuple<std::string, YAML::Node>>> gAddrMap; void ParseEnums(std::string& file); diff --git a/src/factories/AudioHeaderFactory.h b/src/factories/AudioHeaderFactory.h index 4726068..5372eb5 100644 --- a/src/factories/AudioHeaderFactory.h +++ b/src/factories/AudioHeaderFactory.h @@ -5,11 +5,7 @@ class AudioHeaderFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return {}; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/BankFactory.cpp b/src/factories/BankFactory.cpp index 5c057d7..0155ae7 100644 --- a/src/factories/BankFactory.cpp +++ b/src/factories/BankFactory.cpp @@ -1,7 +1,7 @@ #include "BankFactory.h" #include "Companion.h" -void BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto bank = std::static_pointer_cast<BankData>(raw); @@ -84,6 +84,7 @@ void BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> BankFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) { diff --git a/src/factories/BankFactory.h b/src/factories/BankFactory.h index 4699c92..cb69955 100644 --- a/src/factories/BankFactory.h +++ b/src/factories/BankFactory.h @@ -14,19 +14,15 @@ public: }; class BankBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class BankFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, BankBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/BaseFactory.h b/src/factories/BaseFactory.h index 05d3d77..ae8c9a1 100644 --- a/src/factories/BaseFactory.h +++ b/src/factories/BaseFactory.h @@ -4,6 +4,7 @@ #include "n64/Cartridge.h" #include <cstdint> #include <iostream> +#include <any> #include <memory> #include <vector> #include <string> @@ -23,6 +24,13 @@ #define tab "\t" #define fourSpaceTab " " +struct OffsetEntry { + uint32_t start; + uint32_t end; +}; + +typedef std::optional<std::variant<size_t, OffsetEntry>> ExportResult; + enum class ExportType { Header, Code, @@ -67,14 +75,16 @@ public: class BaseExporter { public: - virtual void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) = 0; + virtual ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) = 0; static void WriteHeader(LUS::BinaryWriter& write, LUS::ResourceType resType, int32_t version); }; class BaseFactory { public: virtual std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) = 0; - virtual std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) = 0; + virtual std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) { + return std::nullopt; + } std::optional<std::shared_ptr<BaseExporter>> GetExporter(ExportType type) { auto exporters = this->GetExporters(); if (exporters.find(type) != exporters.end()) { @@ -82,7 +92,12 @@ public: } return std::nullopt; } - virtual bool SupportModdedAssets() = 0; + virtual bool SupportModdedAssets() { + return false; + } + virtual uint32_t GetAlignment() { + return 4; + }; private: virtual std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() = 0; };
\ No newline at end of file diff --git a/src/factories/BlobFactory.cpp b/src/factories/BlobFactory.cpp index 0539641..db902c1 100644 --- a/src/factories/BlobFactory.cpp +++ b/src/factories/BlobFactory.cpp @@ -3,7 +3,7 @@ #include "utils/Decompressor.h" #include <iomanip> -void BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer; @@ -31,19 +31,13 @@ void BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> write << "\n};\n"; if (Companion::Instance->IsDebug()) { - const auto sz = data.size(); - - write << "// size: 0x" << std::hex << std::uppercase << sz << "\n"; - if (IS_SEGMENTED(offset)) { - offset = SEGMENT_OFFSET(offset); - } - write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n"; + write << "// size: 0x" << std::hex << std::uppercase << data.size() << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + data.size(); } -void BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer; @@ -51,6 +45,7 @@ void BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData writer.Write((uint32_t) data.size()); writer.Write((char*) data.data(), data.size()); writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> BlobFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/BlobFactory.h b/src/factories/BlobFactory.h index 9dd1c0d..83d018e 100644 --- a/src/factories/BlobFactory.h +++ b/src/factories/BlobFactory.h @@ -3,24 +3,20 @@ #include "BaseFactory.h" #include "../types/RawBuffer.h" class BlobBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class BlobCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class BlobFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, BlobBinaryExporter) REGISTER(Code, BlobCodeExporter) }; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index c001049..8f55f3e 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -64,18 +64,19 @@ void GFXDSetGBIVersion(){ } } -void DListHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult DListHeaderExporter::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; + return std::nullopt; } write << "extern Gfx " << symbol << "[];\n"; + return std::nullopt; } -void DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { const auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs; const auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -125,18 +126,13 @@ void DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> write << std::string(out); write << "};\n"; + const auto sz = (sizeof(uint32_t) * cmds.size()); if (Companion::Instance->IsDebug()) { - const auto sz = (sizeof(uint32_t) * cmds.size()); - write << "// count: " << std::to_string(sz / 8) << " Gfx\n"; - if (IS_SEGMENTED(offset)) { - offset = SEGMENT_OFFSET(offset); - } - write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + sz; } void DebugDisplayList(uint32_t w0, uint32_t w1){ @@ -181,7 +177,7 @@ std::optional<std::tuple<std::string, YAML::Node>> SearchVtx(uint32_t ptr){ return std::nullopt; } -void DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs; auto writer = LUS::BinaryWriter(); diff --git a/src/factories/DisplayListFactory.h b/src/factories/DisplayListFactory.h index 1bdc87e..71a7e42 100644 --- a/src/factories/DisplayListFactory.h +++ b/src/factories/DisplayListFactory.h @@ -12,23 +12,20 @@ public: }; class DListHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class DListBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class DListCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class DListFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Header, DListHeaderExporter) @@ -36,5 +33,7 @@ public: REGISTER(Code, DListCodeExporter) }; } - bool SupportModdedAssets() override { return false; } + uint32_t GetAlignment() override { + return 8; + }; }; diff --git a/src/factories/LightsFactory.cpp b/src/factories/LightsFactory.cpp index a14e12f..a26a17a 100644 --- a/src/factories/LightsFactory.cpp +++ b/src/factories/LightsFactory.cpp @@ -4,18 +4,19 @@ #include "spdlog/spdlog.h" #include "Companion.h" -void LightsHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult LightsHeaderExporter::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; + return std::nullopt; } write << "extern Lights1 " << symbol << ";\n"; + return std::nullopt; } -void LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto light = std::static_pointer_cast<LightsData>(raw)->mLights; auto symbol = GetSafeNode(node, "symbol", entryName); @@ -44,9 +45,10 @@ void LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData write << r2 << ", " << g2 << ", " << b2 << ", " << x << ", " << y << ", " << z << "\n"; write << ");\n\n"; + return std::nullopt; } -void LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto light = std::static_pointer_cast<LightsData>(raw)->mLights; auto writer = LUS::BinaryWriter(); auto size = sizeof(light.l) / sizeof(LightRaw); @@ -65,6 +67,7 @@ void LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedDa } writer.Finish(write); writer.Close(); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> LightsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/LightsFactory.h b/src/factories/LightsFactory.h index a063ddf..8771434 100644 --- a/src/factories/LightsFactory.h +++ b/src/factories/LightsFactory.h @@ -42,23 +42,20 @@ public: }; class LightsHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class LightsBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class LightsCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class LightsFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, LightsCodeExporter) @@ -66,5 +63,4 @@ public: REGISTER(Binary, LightsBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/SampleFactory.cpp b/src/factories/SampleFactory.cpp index f367a1e..ec88060 100644 --- a/src/factories/SampleFactory.cpp +++ b/src/factories/SampleFactory.cpp @@ -1,6 +1,6 @@ #include "SampleFactory.h" -void SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto sample = std::static_pointer_cast<SampleData>(raw)->mSample; @@ -30,6 +30,7 @@ void SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedDa writer.Write(sample.name); writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SampleFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) { diff --git a/src/factories/SampleFactory.h b/src/factories/SampleFactory.h index 19f26ee..7e647fd 100644 --- a/src/factories/SampleFactory.h +++ b/src/factories/SampleFactory.h @@ -13,19 +13,15 @@ public: }; class SampleBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SampleFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, SampleBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/SequenceFactory.cpp b/src/factories/SequenceFactory.cpp index 17b1ac6..3a6254a 100644 --- a/src/factories/SequenceFactory.cpp +++ b/src/factories/SequenceFactory.cpp @@ -1,6 +1,6 @@ #include "SequenceFactory.h" -void SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); const auto sequence = std::static_pointer_cast<SequenceData>(raw); @@ -13,6 +13,7 @@ void SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsed writer.Write( sequence->mSize); writer.Write(reinterpret_cast<char*>(sequence->mBuffer.data()), sequence->mSize); writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SequenceFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) { diff --git a/src/factories/SequenceFactory.h b/src/factories/SequenceFactory.h index 40f19c8..7eb4192 100644 --- a/src/factories/SequenceFactory.h +++ b/src/factories/SequenceFactory.h @@ -15,19 +15,15 @@ public: }; class SequenceBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SequenceFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, SequenceBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } };
\ No newline at end of file diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index 9202b94..cdaef37 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -79,14 +79,14 @@ std::vector<uint8_t> alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t return result; } -void TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult TextureHeaderExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto data = std::static_pointer_cast<TextureData>(raw)->mBuffer; if(Companion::Instance->IsOTRMode()){ write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; - return; + return std::nullopt; } const auto searchTable = Companion::Instance->SearchTable(offset); @@ -95,16 +95,17 @@ void TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedD const auto [name, start, end, mode] = searchTable.value(); if(start != offset){ - return; + return std::nullopt; } write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << name << "[][" << data.size() << "];\n"; } else { write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[];\n"; } + return std::nullopt; } -void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { auto texture = std::static_pointer_cast<TextureData>(raw); auto data = texture->mBuffer; auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -169,27 +170,21 @@ void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedDat } write << "// 0x" << std::hex << std::uppercase << offset << "\n"; } - + write << GetSafeNode<std::string>(node, "ctype", "static const u8") << " " << symbol << "[] = {\n"; write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n"; write << "};\n"; + const auto sz = data.size(); if (Companion::Instance->IsDebug()) { - const auto sz = data.size(); - write << "// size: 0x" << std::hex << std::uppercase << sz << "\n"; - if (IS_SEGMENTED(offset)) { - offset = SEGMENT_OFFSET(offset); - } - write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n"; } - - write << "\n"; } + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + data.size(); } -void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { auto writer = LUS::BinaryWriter(); auto texture = std::static_pointer_cast<TextureData>(raw); auto data = texture->mBuffer; @@ -203,9 +198,10 @@ void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedD writer.Write((uint32_t) data.size()); writer.Write((char*) data.data(), data.size()); writer.Finish(write); + return std::nullopt; } -void TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { +ExportResult TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { auto texture = std::static_pointer_cast<TextureData>(data); auto format = texture->mFormat; uint8_t* raw = new uint8_t[CalculateTextureSize(format.type, texture->mWidth, texture->mHeight) * 2]; @@ -258,6 +254,7 @@ void TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedD } write.write(reinterpret_cast<char*>(raw), size); + return std::nullopt; } diff --git a/src/factories/TextureFactory.h b/src/factories/TextureFactory.h index e2e61e2..e2698d8 100644 --- a/src/factories/TextureFactory.h +++ b/src/factories/TextureFactory.h @@ -33,19 +33,19 @@ public: }; class TextureHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TextureCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TextureBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TextureModdingExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TextureFactory : public BaseFactory { diff --git a/src/factories/Vec3fFactory.cpp b/src/factories/Vec3fFactory.cpp index e6dbf2b..41b7bfb 100644 --- a/src/factories/Vec3fFactory.cpp +++ b/src/factories/Vec3fFactory.cpp @@ -16,15 +16,16 @@ Vec3fData::Vec3fData(std::vector<Vec3f> vecs): mVecs(vecs) { } } -void Vec3fHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult Vec3fHeaderExporter::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; + return std::nullopt; } write << "extern Vec3f " << symbol << "[];\n"; + return std::nullopt; } @@ -32,7 +33,7 @@ int GetPrecision(Vec3f v) { return std::max(std::max(GetPrecision(v.x), GetPrecision(v.y)), GetPrecision(v.z)); } -void Vec3fCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult Vec3fCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto vecData = std::static_pointer_cast<Vec3fData>(raw); @@ -41,7 +42,7 @@ void Vec3fCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> if(IS_SEGMENTED(off)) { off = SEGMENT_OFFSET(off); - } + } if (Companion::Instance->IsDebug()) { write << "// 0x" << std::uppercase << std::hex << off << "\n"; } @@ -58,16 +59,16 @@ void Vec3fCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> } write << "\n};\n"; + if (Companion::Instance->IsDebug()) { write << "// Count: " << vecData->mVecs.size() << " Vec3fs\n"; - write << "// 0x" << std::uppercase << std::hex << off + vecData->mVecs.size() * sizeof(Vec3f) << "\n"; } - write << "\n"; - -} -void Vec3fBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return (IS_SEGMENTED(off) ? SEGMENT_OFFSET(off) : off) + vecData->mVecs.size() * sizeof(Vec3f); +} +ExportResult Vec3fBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> Vec3fFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/Vec3fFactory.h b/src/factories/Vec3fFactory.h index 9d9dd4a..2832f77 100644 --- a/src/factories/Vec3fFactory.h +++ b/src/factories/Vec3fFactory.h @@ -13,23 +13,20 @@ public: }; class Vec3fHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class Vec3fBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class Vec3fCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class Vec3fFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, Vec3fCodeExporter) @@ -37,5 +34,4 @@ public: REGISTER(Binary, Vec3fBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; diff --git a/src/factories/VtxFactory.cpp b/src/factories/VtxFactory.cpp index 301dd48..ee26fe7 100644 --- a/src/factories/VtxFactory.cpp +++ b/src/factories/VtxFactory.cpp @@ -7,18 +7,19 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define COL(c) std::dec << std::setfill(' ') << std::setw(3) << c -void VtxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult VtxHeaderExporter::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; + return std::nullopt; } write << "extern Vtx " << symbol << "[];\n"; + return std::nullopt; } -void VtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult VtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto vtx = std::static_pointer_cast<VtxData>(raw)->mVtxs; const auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -65,13 +66,12 @@ void VtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> r if (Companion::Instance->IsDebug()) { write << "// count: " << std::to_string(vtx.size()) << " Vtxs\n"; - write << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(VtxRaw) * vtx.size())) << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + vtx.size() * sizeof(VtxRaw); } -void VtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult VtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto vtx = std::static_pointer_cast<VtxData>(raw); auto writer = LUS::BinaryWriter(); @@ -91,6 +91,7 @@ void VtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> VtxFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/VtxFactory.h b/src/factories/VtxFactory.h index 3ab1f52..75bd906 100644 --- a/src/factories/VtxFactory.h +++ b/src/factories/VtxFactory.h @@ -17,23 +17,20 @@ public: }; class VtxHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class VtxBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class VtxCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class VtxFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, VtxCodeExporter) @@ -41,5 +38,7 @@ public: REGISTER(Binary, VtxBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } + uint32_t GetAlignment() override { + return 8; + }; };
\ No newline at end of file diff --git a/src/factories/mk64/CourseVtx.cpp b/src/factories/mk64/CourseVtx.cpp index 5570616..524ae6b 100644 --- a/src/factories/mk64/CourseVtx.cpp +++ b/src/factories/mk64/CourseVtx.cpp @@ -6,18 +6,19 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define COL(c) "0x" << std::hex << std::setw(2) << std::setfill('0') << c -void MK64::CourseVtxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult MK64::CourseVtxHeaderExporter::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; + return std::nullopt; } write << "extern CourseVtx " << symbol << "[];\n"; + return std::nullopt; } -void MK64::CourseVtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::CourseVtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto vtx = std::static_pointer_cast<CourseVtxData>(raw)->mVtxs; const auto symbol = GetSafeNode(node, "symbol", entryName); const auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -56,9 +57,10 @@ void MK64::CourseVtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IP } write << "};\n\n"; + return std::nullopt; } -void MK64::CourseVtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::CourseVtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto vtx = std::static_pointer_cast<CourseVtxData>(raw); auto writer = LUS::BinaryWriter(); @@ -77,6 +79,7 @@ void MK64::CourseVtxBinaryExporter::Export(std::ostream &write, std::shared_ptr< } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> MK64::CourseVtxFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/mk64/CourseVtx.h b/src/factories/mk64/CourseVtx.h index f08ca77..8241769 100644 --- a/src/factories/mk64/CourseVtx.h +++ b/src/factories/mk64/CourseVtx.h @@ -18,15 +18,15 @@ namespace MK64 { }; class CourseVtxHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class CourseVtxBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class CourseVtxCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class CourseVtxFactory : public BaseFactory { diff --git a/src/factories/mk64/SpawnData.cpp b/src/factories/mk64/SpawnData.cpp index 401c8ff..5397537 100644 --- a/src/factories/mk64/SpawnData.cpp +++ b/src/factories/mk64/SpawnData.cpp @@ -6,18 +6,19 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define COL(c) "0x" << std::hex << std::setw(2) << std::setfill('0') << c -void MK64::SpawnDataHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult MK64::SpawnDataHeaderExporter::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; + return std::nullopt; } write << "extern ActorSpawnData " << symbol << "[];\n"; + return std::nullopt; } -void MK64::SpawnDataCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::SpawnDataCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto spawns = std::static_pointer_cast<SpawnDataData>(raw)->mSpawns; const auto symbol = GetSafeNode(node, "symbol", entryName); const auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -42,15 +43,12 @@ void MK64::SpawnDataCodeExporter::Export(std::ostream &write, std::shared_ptr<IP // { x, y, z, id }, write << "{" << NUM(x) << ", " << NUM(y) << ", " << NUM(z) << ", " << NUM(id) << " },\n"; } + write << "};\n"; - if (Companion::Instance->IsDebug()) { - write << fourSpaceTab << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(MK64::ActorSpawnData) * spawns.size())) << "\n"; - } - - write << "};\n\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + (sizeof(MK64::ActorSpawnData) * spawns.size()); } -void MK64::SpawnDataBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::SpawnDataBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto spawns = std::static_pointer_cast<SpawnDataData>(raw)->mSpawns; auto writer = LUS::BinaryWriter(); @@ -64,6 +62,7 @@ void MK64::SpawnDataBinaryExporter::Export(std::ostream &write, std::shared_ptr< } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> MK64::SpawnDataFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/mk64/SpawnData.h b/src/factories/mk64/SpawnData.h index 3e5b9d4..168208d 100644 --- a/src/factories/mk64/SpawnData.h +++ b/src/factories/mk64/SpawnData.h @@ -19,15 +19,15 @@ namespace MK64 { }; class SpawnDataHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SpawnDataBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SpawnDataCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SpawnDataFactory : public BaseFactory { diff --git a/src/factories/mk64/TrackSections.cpp b/src/factories/mk64/TrackSections.cpp index 6707950..1c1319e 100644 --- a/src/factories/mk64/TrackSections.cpp +++ b/src/factories/mk64/TrackSections.cpp @@ -6,18 +6,19 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define COL(c) "0x" << std::hex << std::setw(2) << std::setfill('0') << c -void MK64::TrackSectionsHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult MK64::TrackSectionsHeaderExporter::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; + return std::nullopt; } write << "extern TrackSections " << symbol << "[];\n"; + return std::nullopt; } -void MK64::TrackSectionsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::TrackSectionsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto sections = std::static_pointer_cast<TrackSectionsData>(raw)->mSecs; const auto symbol = GetSafeNode(node, "symbol", entryName); const auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -43,15 +44,12 @@ void MK64::TrackSectionsCodeExporter::Export(std::ostream &write, std::shared_pt // { addr, surface, section, flags }, write << "{" << NUM(addr) << ", " << NUM(surf) << ", " << NUM(sect) << ", " << NUM(flags) << "},\n"; } + write << "};\n"; - if (Companion::Instance->IsDebug()) { - write << fourSpaceTab << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(TrackSections) * sections.size())) << "\n"; - } - - write << "};\n\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + (sizeof(MK64::TrackSections) * sections.size()); } -void MK64::TrackSectionsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::TrackSectionsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto sections = std::static_pointer_cast<TrackSectionsData>(raw); auto writer = LUS::BinaryWriter(); @@ -65,6 +63,7 @@ void MK64::TrackSectionsBinaryExporter::Export(std::ostream &write, std::shared_ } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> MK64::TrackSectionsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/mk64/TrackSections.h b/src/factories/mk64/TrackSections.h index 32c7b9b..839661c 100644 --- a/src/factories/mk64/TrackSections.h +++ b/src/factories/mk64/TrackSections.h @@ -19,15 +19,15 @@ namespace MK64 { }; class TrackSectionsHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TrackSectionsBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TrackSectionsCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TrackSectionsFactory : public BaseFactory { diff --git a/src/factories/mk64/Waypoints.cpp b/src/factories/mk64/Waypoints.cpp index 9149fb6..81e6b36 100644 --- a/src/factories/mk64/Waypoints.cpp +++ b/src/factories/mk64/Waypoints.cpp @@ -6,18 +6,19 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define COL(c) "0x" << std::hex << std::setw(2) << std::setfill('0') << c -void MK64::WaypointHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult MK64::WaypointHeaderExporter::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; + return std::nullopt; } write << "extern TrackWaypoint " << symbol << "[];\n"; + return std::nullopt; } -void MK64::WaypointCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::WaypointCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto waypoints = std::static_pointer_cast<WaypointData>(raw)->mWaypoints; auto symbol = GetSafeNode(node, "symbol", entryName); @@ -39,9 +40,10 @@ void MK64::WaypointCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa write << "{" << NUM(x) << ", " << NUM(y) << ", " << NUM(z) << ", " << NUM(seg) << " },\n"; } write << "};\n\n"; + return std::nullopt; } -void MK64::WaypointBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult MK64::WaypointBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto waypoints = std::static_pointer_cast<WaypointData>(raw)->mWaypoints; auto writer = LUS::BinaryWriter(); @@ -55,6 +57,7 @@ void MK64::WaypointBinaryExporter::Export(std::ostream &write, std::shared_ptr<I } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> MK64::WaypointsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/mk64/Waypoints.h b/src/factories/mk64/Waypoints.h index ff60b70..6e70803 100644 --- a/src/factories/mk64/Waypoints.h +++ b/src/factories/mk64/Waypoints.h @@ -19,15 +19,15 @@ namespace MK64 { }; class WaypointHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class WaypointBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class WaypointCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class WaypointsFactory : public BaseFactory { diff --git a/src/factories/sf64/AnimFactory.cpp b/src/factories/sf64/AnimFactory.cpp index 1d12860..7e5eeb2 100644 --- a/src/factories/sf64/AnimFactory.cpp +++ b/src/factories/sf64/AnimFactory.cpp @@ -13,7 +13,7 @@ SF64::AnimData::AnimData(int16_t frameCount, int16_t limbCount, uint32_t dataOff SPDLOG_ERROR("SF64:ANIM error: Data and Key offsets overlap"); } if(mJointKeys.size() != limbCount + 1) { - SPDLOG_ERROR("SF64:ANIM error: Joint Key count does not match Limb count"); + SPDLOG_ERROR("SF64:ANIM error: Joint Key count does not match Limb count"); } if(frameData.size() > 0 && frameData[0] != 0){ SPDLOG_INFO("SF64:ANIM alert: Found non-zero frame data on first frame"); @@ -23,18 +23,19 @@ SF64::AnimData::AnimData(int16_t frameCount, int16_t limbCount, uint32_t dataOff } } -void SF64::AnimHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::AnimHeaderExporter::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; + return std::nullopt; } write << "extern Animation " << symbol << ";\n"; + return std::nullopt; } -void SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto anim = std::static_pointer_cast<SF64::AnimData>(raw); const auto symbol = GetSafeNode(node, "symbol", entryName); const auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -94,19 +95,14 @@ void SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsed write << "Animation " << symbol << " = {\n"; write << fourSpaceTab << anim->mFrameCount << ", " << anim->mLimbCount << ", " << dataName << ", " << keyName << ",\n"; write << "};\n"; - - if (Companion::Instance->IsDebug()) { - int off = offset + 0xC; - if(IS_SEGMENTED(off)) { - off = SEGMENT_OFFSET(off); - } - write << "// 0x" << std::uppercase << std::hex << off << "\n"; - } - write<< "\n"; + return OffsetEntry { + anim->mDataOffset, + (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + 0xC + }; } -void SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto anim = std::static_pointer_cast<SF64::AnimData>(raw); auto writer = LUS::BinaryWriter(); @@ -125,6 +121,7 @@ void SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_ptr<IPars writer.Write(data); } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::AnimFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sf64/AnimFactory.h b/src/factories/sf64/AnimFactory.h index 0fd4d37..be05515 100644 --- a/src/factories/sf64/AnimFactory.h +++ b/src/factories/sf64/AnimFactory.h @@ -21,23 +21,20 @@ public: }; class AnimHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class AnimBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class AnimCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class AnimFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, AnimCodeExporter) @@ -45,6 +42,5 @@ public: REGISTER(Binary, AnimBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/ColPolyFactory.cpp b/src/factories/sf64/ColPolyFactory.cpp index b2c6c45..9f8bb50 100644 --- a/src/factories/sf64/ColPolyFactory.cpp +++ b/src/factories/sf64/ColPolyFactory.cpp @@ -10,21 +10,22 @@ #define NUM(x, w) std::dec << std::setfill(' ') << std::setw(w) << x SF64::ColPolyData::ColPolyData(std::vector<SF64::CollisionPoly> polys, std::vector<Vec3s> mesh): mPolys(polys), mMesh(mesh) { - + } -void SF64::ColPolyHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::ColPolyHeaderExporter::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; + return std::nullopt; } write << "extern CollisionPoly " << symbol << "[];\n"; + return std::nullopt; } -void SF64::ColPolyCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::ColPolyCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto colpolys = std::static_pointer_cast<SF64::ColPolyData>(raw); @@ -32,7 +33,7 @@ void SF64::ColPolyCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar int i; if(IS_SEGMENTED(off)) { off = SEGMENT_OFFSET(off); - } + } if (Companion::Instance->IsDebug()) { write << "// 0x" << std::uppercase << std::hex << off << "\n"; } @@ -105,15 +106,13 @@ void SF64::ColPolyCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar if (Companion::Instance->IsDebug()) { write << "// Mesh vertex count: " << colpolys->mMesh.size() << "\n"; - write << "// 0x" << std::uppercase << std::hex << off + colpolys->mMesh.size() * sizeof(Vec3s) << "\n"; } - write << "\n"; - + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + colpolys->mMesh.size() * sizeof(Vec3s); } -void SF64::ColPolyBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - +ExportResult SF64::ColPolyBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::ColPolyFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sf64/ColPolyFactory.h b/src/factories/sf64/ColPolyFactory.h index fd43f62..5d795ee 100644 --- a/src/factories/sf64/ColPolyFactory.h +++ b/src/factories/sf64/ColPolyFactory.h @@ -22,23 +22,20 @@ public: }; class ColPolyHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ColPolyBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ColPolyCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ColPolyFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, ColPolyCodeExporter) @@ -46,6 +43,5 @@ public: REGISTER(Binary, ColPolyBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/EnvSettingsFactory.cpp b/src/factories/sf64/EnvSettingsFactory.cpp index 8ed654a..aeda5cb 100644 --- a/src/factories/sf64/EnvSettingsFactory.cpp +++ b/src/factories/sf64/EnvSettingsFactory.cpp @@ -6,28 +6,29 @@ #include "utils/TorchUtils.h" SF64::EnvSettingsData::EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f unk_20, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB): mType(type), mUnk_04(unk_04), mBgColor(bgColor), mSeqId(seqId), mFogR(fogR), mFogG(fogG), mFogB(fogB), mFogN(fogN), mFogF(fogF), mUnk_20(unk_20), mLightR(lightR), mLightG(lightG), mLightB(lightB), mAmbR(ambR), mAmbG(ambG), mAmbB(ambB) { - + } -void SF64::EnvSettingsHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::EnvSettingsHeaderExporter::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; + return std::nullopt; } write << "extern EnvSettings " << symbol << ";\n"; + return std::nullopt; } -void SF64::EnvSettingsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::EnvSettingsCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto env = std::static_pointer_cast<SF64::EnvSettingsData>(raw); auto off = offset; if(IS_SEGMENTED(off)) { off = SEGMENT_OFFSET(off); - } + } if (Companion::Instance->IsDebug()) { write << "// 0x" << std::uppercase << std::hex << off << "\n"; } @@ -54,14 +55,12 @@ void SF64::EnvSettingsCodeExporter::Export(std::ostream &write, std::shared_ptr< write << env->mAmbG << ", "; write << env->mAmbB << ",\n"; write << "};\n"; - if (Companion::Instance->IsDebug()) { - write << "// 0x" << std::uppercase << std::hex << off + sizeof(EnvSettingsData) << "\n"; - } - write << "\n"; -} -void SF64::EnvSettingsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + sizeof(EnvSettingsData); +} +ExportResult SF64::EnvSettingsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::EnvSettingsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sf64/EnvSettingsFactory.h b/src/factories/sf64/EnvSettingsFactory.h index 59cd78f..156886e 100644 --- a/src/factories/sf64/EnvSettingsFactory.h +++ b/src/factories/sf64/EnvSettingsFactory.h @@ -28,23 +28,20 @@ public: }; class EnvSettingsHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class EnvSettingsBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class EnvSettingsCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class EnvSettingsFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, EnvSettingsCodeExporter) @@ -52,6 +49,5 @@ public: REGISTER(Binary, EnvSettingsBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/HitboxFactory.cpp b/src/factories/sf64/HitboxFactory.cpp index 69d5ef1..be453a0 100644 --- a/src/factories/sf64/HitboxFactory.cpp +++ b/src/factories/sf64/HitboxFactory.cpp @@ -8,21 +8,22 @@ #define FLOAT(x, w) std::dec << std::setfill(' ') << (((int) x == x) ? "" : " ") << std::setw(w - 2) << x << (((int) x == x) ? ".0f" : "f") SF64::HitboxData::HitboxData(std::vector<float> data, std::vector<int> types): mData(data), mTypes(types) { - + } -void SF64::HitboxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::HitboxHeaderExporter::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; + return std::nullopt; } write << "extern f32 " << symbol << "[];\n"; + return std::nullopt; } -void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::HitboxCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto hitbox = std::static_pointer_cast<SF64::HitboxData>(raw); @@ -30,10 +31,10 @@ void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars auto count = hitbox->mData[index++]; auto hasType2 = false; auto off = offset; - + if(IS_SEGMENTED(off)) { off = SEGMENT_OFFSET(off); - } + } for(int type : hitbox->mTypes) { if(type == 2) { hasType2 = true; @@ -45,7 +46,7 @@ void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars } write << "f32 " << symbol << "[] = {\n"; write << fourSpaceTab << count << ",\n"; - + for(int i = 0; i < (int)count; i++) { if(hitbox->mTypes[i] == 4) { write << fourSpaceTab << "HITBOX_TYPE_4, "; @@ -76,13 +77,11 @@ void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars write << "\n"; } write << "};\n"; - if (Companion::Instance->IsDebug()) { - write << "// 0x" << std::uppercase << std::hex << off + sizeof(float) * index << "\n"; - } - write << "\n"; + + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + sizeof(float) * index; } -void SF64::HitboxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::HitboxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto hitbox = std::static_pointer_cast<SF64::HitboxData>(raw); auto writer = LUS::BinaryWriter(); @@ -91,6 +90,7 @@ void SF64::HitboxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IPa writer.Write(value); } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::HitboxFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sf64/HitboxFactory.h b/src/factories/sf64/HitboxFactory.h index 8c54c7e..69d20bf 100644 --- a/src/factories/sf64/HitboxFactory.h +++ b/src/factories/sf64/HitboxFactory.h @@ -13,23 +13,20 @@ public: }; class HitboxHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class HitboxBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class HitboxCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class HitboxFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, HitboxCodeExporter) @@ -37,6 +34,5 @@ public: REGISTER(Binary, HitboxBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/MessageFactory.cpp b/src/factories/sf64/MessageFactory.cpp index 38ad859..9aa2c5b 100644 --- a/src/factories/sf64/MessageFactory.cpp +++ b/src/factories/sf64/MessageFactory.cpp @@ -49,15 +49,16 @@ std::unordered_map<std::string, std::string> ASCIITable = { { "CLN", ":" }, { "PIP", "| " } }; -void SF64::MessageHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::MessageHeaderExporter::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; + return std::nullopt; } write << "extern u16 " << symbol << "[];\n"; + return std::nullopt; } void TextToStream(std::ostream& stream, int charCode) { @@ -73,7 +74,7 @@ void TextToStream(std::ostream& stream, int charCode) { } } -void SF64::MessageCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::MessageCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto message = std::static_pointer_cast<MessageData>(raw)->mMessage; const auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -129,13 +130,12 @@ void SF64::MessageCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar if (Companion::Instance->IsDebug()) { write << "// count: " << std::to_string(message.size()) << " chars\n"; - write << "// 0x" << std::hex << std::uppercase << (offset + (message.size() * sizeof(uint16_t))) << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + message.size() * sizeof(uint16_t); } -void SF64::MessageBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::MessageBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); const auto data = std::static_pointer_cast<MessageData>(raw); diff --git a/src/factories/sf64/MessageFactory.h b/src/factories/sf64/MessageFactory.h index 7565cc4..f59ae91 100644 --- a/src/factories/sf64/MessageFactory.h +++ b/src/factories/sf64/MessageFactory.h @@ -12,23 +12,20 @@ public: }; class MessageCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, MessageCodeExporter) @@ -36,6 +33,5 @@ public: REGISTER(Binary, MessageBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sf64/MessageLookupFactory.cpp b/src/factories/sf64/MessageLookupFactory.cpp index 2272c2d..5e8c38a 100644 --- a/src/factories/sf64/MessageLookupFactory.cpp +++ b/src/factories/sf64/MessageLookupFactory.cpp @@ -4,18 +4,18 @@ #include "spdlog/spdlog.h" #include "Companion.h" -void SF64::MessageLookupHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::MessageLookupHeaderExporter::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; + return std::nullopt; } write << "extern MsgLookup " << symbol << "[];\n"; } -void SF64::MessageLookupCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::MessageLookupCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto table = std::static_pointer_cast<MessageTable>(raw)->mTable; const auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -51,15 +51,10 @@ void SF64::MessageLookupCodeExporter::Export(std::ostream &write, std::shared_pt } write << "\n};\n"; - - if (Companion::Instance->IsDebug()) { - write << "// 0x" << std::hex << std::uppercase << (offset + (table.size() * sizeof(uint16_t))) << "\n"; - } - - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + table.size() * sizeof(uint16_t); } -void SF64::MessageLookupBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::MessageLookupBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); const auto data = std::static_pointer_cast<MessageTable>(raw); diff --git a/src/factories/sf64/MessageLookupFactory.h b/src/factories/sf64/MessageLookupFactory.h index 8413aec..1c2c884 100644 --- a/src/factories/sf64/MessageLookupFactory.h +++ b/src/factories/sf64/MessageLookupFactory.h @@ -17,23 +17,20 @@ public: }; class MessageLookupCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageLookupHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageLookupBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class MessageLookupFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, MessageLookupCodeExporter) @@ -41,6 +38,5 @@ public: REGISTER(Binary, MessageLookupBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sf64/ObjInitFactory.cpp b/src/factories/sf64/ObjInitFactory.cpp index a2e42eb..3e6694e 100644 --- a/src/factories/sf64/ObjInitFactory.cpp +++ b/src/factories/sf64/ObjInitFactory.cpp @@ -5,18 +5,18 @@ #define NUM(x, w) std::dec << std::setfill(' ') << std::setw(w) << x #define FLOAT(x, w) std::dec << std::setfill(' ') << std::setw(w) << std::fixed << std::setprecision(1) << x << "f" -void SF64::ObjInitHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::ObjInitHeaderExporter::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; + return std::nullopt; } write << "extern ObjectInit " << symbol << "[];\n"; } -void SF64::ObjInitCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::ObjInitCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto symbol = GetSafeNode(node, "symbol", entryName); auto offset = GetSafeNode<uint32_t>(node, "offset"); auto objs = std::static_pointer_cast<ObjInitData>(raw)->mObjInit; @@ -43,13 +43,12 @@ void SF64::ObjInitCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar if (Companion::Instance->IsDebug()) { write << "// count: " << std::to_string(objs.size()) << " ObjectInits\n"; - write << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(ObjectInit) * objs.size())) << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + sizeof(ObjectInit) * objs.size(); } -void SF64::ObjInitBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::ObjInitBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto data = std::static_pointer_cast<ObjInitData>(raw)->mObjInit; diff --git a/src/factories/sf64/ObjInitFactory.h b/src/factories/sf64/ObjInitFactory.h index 2abfab5..55b0171 100644 --- a/src/factories/sf64/ObjInitFactory.h +++ b/src/factories/sf64/ObjInitFactory.h @@ -22,23 +22,20 @@ public: }; class ObjInitHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ObjInitBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ObjInitCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ObjInitFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Header, ObjInitHeaderExporter) @@ -46,6 +43,5 @@ public: REGISTER(Code, ObjInitCodeExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp index 6385836..03c1c6d 100644 --- a/src/factories/sf64/ScriptFactory.cpp +++ b/src/factories/sf64/ScriptFactory.cpp @@ -9,15 +9,16 @@ SF64::ScriptData::ScriptData(std::vector<uint32_t> ptrs, std::vector<uint16_t> c } -void SF64::ScriptHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::ScriptHeaderExporter::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; + return std::nullopt; } write << "extern u16* " << symbol << "[];\n"; + return std::nullopt; } std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { @@ -32,7 +33,7 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { return cmd.str(); } -void SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::ScriptCodeExporter::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); auto offset = GetSafeNode<uint32_t>(node, "offset"); auto script = std::static_pointer_cast<SF64::ScriptData>(raw); @@ -92,14 +93,16 @@ void SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars if (Companion::Instance->IsDebug()) { write << "// count: " << script->mPtrs.size() << " events\n"; - write << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(uint32_t) * script->mPtrs.size())) << "\n"; } - write << "\n"; + return OffsetEntry { + script->mCmdsStart, + static_cast<uint32_t>((IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + script->mPtrs.size() * sizeof(uint32_t)) + }; } -void SF64::ScriptBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - +ExportResult SF64::ScriptBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::ScriptFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sf64/ScriptFactory.h b/src/factories/sf64/ScriptFactory.h index 24eaf71..aa3e22d 100644 --- a/src/factories/sf64/ScriptFactory.h +++ b/src/factories/sf64/ScriptFactory.h @@ -16,23 +16,20 @@ public: }; class ScriptHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ScriptBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ScriptCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class ScriptFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, ScriptCodeExporter) @@ -40,6 +37,5 @@ public: REGISTER(Binary, ScriptBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/SkeletonFactory.cpp b/src/factories/sf64/SkeletonFactory.cpp index fdcae26..3701abe 100644 --- a/src/factories/sf64/SkeletonFactory.cpp +++ b/src/factories/sf64/SkeletonFactory.cpp @@ -10,21 +10,22 @@ #define FLOAT(x, w, p) std::dec << std::setfill(' ') << std::setw(w) << std::fixed << std::setprecision(p) << x SF64::LimbData::LimbData(uint32_t addr, uint32_t dList, Vec3f trans, Vec3s rot, uint32_t sibling, uint32_t child, int index): mAddr(addr), mDList(dList), mTrans(trans), mRot(rot), mSibling(sibling), mChild(child), mIndex(index) { - + } -void SF64::SkeletonHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::SkeletonHeaderExporter::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; + return std::nullopt; } write << "extern Limb* " << symbol << "[];\n"; + return std::nullopt; } -void SF64::SkeletonCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::SkeletonCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto skeleton = std::static_pointer_cast<SF64::SkeletonData>(raw); @@ -84,20 +85,19 @@ void SF64::SkeletonCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa } } write << "\n};\n"; + if (Companion::Instance->IsDebug()) { - int sz = (skeleton->mSkeleton.size() * 0x24) + 4; - int off = limbs[0].mAddr;; - if (IS_SEGMENTED(off)) { - off = SEGMENT_OFFSET(off); - } write << "// Limbs: " << std::dec << skeleton->mSkeleton.size() << "\n"; - write << "// 0x" << std::hex << std::uppercase << (off + sz) << "\n"; } - write << "\n"; -} -void SF64::SkeletonBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return OffsetEntry { + limbs[0].mAddr, + (IS_SEGMENTED(limbs[0].mAddr) ? SEGMENT_OFFSET(limbs[0].mAddr) : limbs[0].mAddr) + skeleton->mSkeleton.size() * 0x24 + 4 + }; +} +ExportResult SF64::SkeletonBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::SkeletonFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { @@ -108,7 +108,6 @@ std::optional<std::shared_ptr<IParsedData>> SF64::SkeletonFactory::parse(std::ve reader.SetEndianness(LUS::Endianness::Big); auto limbAddr = reader.ReadUInt32(); auto limbIndex = 0; - while(limbAddr != 0) { YAML::Node limbNode; diff --git a/src/factories/sf64/SkeletonFactory.h b/src/factories/sf64/SkeletonFactory.h index f949793..c35e04b 100644 --- a/src/factories/sf64/SkeletonFactory.h +++ b/src/factories/sf64/SkeletonFactory.h @@ -26,23 +26,20 @@ public: }; class SkeletonHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SkeletonBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SkeletonCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class SkeletonFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, SkeletonCodeExporter) @@ -50,6 +47,5 @@ public: REGISTER(Binary, SkeletonBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sf64/TriangleFactory.cpp b/src/factories/sf64/TriangleFactory.cpp index 0d933b2..ad3a1ae 100644 --- a/src/factories/sf64/TriangleFactory.cpp +++ b/src/factories/sf64/TriangleFactory.cpp @@ -14,18 +14,19 @@ SF64::TriangleData::TriangleData(std::vector<Vec3s> tris, std::vector<YAML::Node> meshNodes): mTris(tris), mMeshNodes(meshNodes) { } -void SF64::TriangleHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { +ExportResult SF64::TriangleHeaderExporter::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; + return std::nullopt; } write << "extern Triangle " << symbol << "[];\n"; + return std::nullopt; } -void SF64::TriangleCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SF64::TriangleCodeExporter::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); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto triData = std::static_pointer_cast<SF64::TriangleData>(raw); @@ -35,7 +36,7 @@ void SF64::TriangleCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa int i; if(IS_SEGMENTED(off)) { off = SEGMENT_OFFSET(off); - } + } if (Companion::Instance->IsDebug()) { write << "// 0x" << std::uppercase << std::hex << STRIP_SEGMENT(offset) << "\n"; } @@ -54,14 +55,13 @@ void SF64::TriangleCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa if (Companion::Instance->IsDebug()) { write << "// Triangle count: " << triData->mTris.size() << "\n"; - write << "// 0x" << std::uppercase << std::hex << off + triData->mTris.size() * sizeof(Vec3s) << "\n"; } - write << "\n"; + return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + triData->mTris.size() * sizeof(Vec3s); } -void SF64::TriangleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - +ExportResult SF64::TriangleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SF64::TriangleFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { @@ -111,7 +111,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::TriangleFactory::parse(std::ve meshNode["type"] = "VEC3F"; meshNode["count"] = meshSize; meshNode["offset"] = meshOffset; - + meshNode = Companion::Instance->AddAsset(meshNode).value(); meshNodes.push_back(meshNode); meshOffset += meshSize * sizeof(Vec3f); diff --git a/src/factories/sf64/TriangleFactory.h b/src/factories/sf64/TriangleFactory.h index 5be4f3e..57acac4 100644 --- a/src/factories/sf64/TriangleFactory.h +++ b/src/factories/sf64/TriangleFactory.h @@ -14,23 +14,20 @@ public: }; class TriangleHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TriangleBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TriangleCodeExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TriangleFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Code, TriangleCodeExporter) @@ -38,6 +35,5 @@ public: REGISTER(Binary, TriangleBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sm64/AnimationFactory.cpp b/src/factories/sm64/AnimationFactory.cpp index 368de1f..1b4070d 100644 --- a/src/factories/sm64/AnimationFactory.cpp +++ b/src/factories/sm64/AnimationFactory.cpp @@ -1,7 +1,7 @@ #include "AnimationFactory.h" #include "spdlog/spdlog.h" -void SM64::AnimationBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SM64::AnimationBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); const auto anim = std::static_pointer_cast<AnimationData>(raw); @@ -25,6 +25,7 @@ void SM64::AnimationBinaryExporter::Export(std::ostream &write, std::shared_ptr< } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sm64/AnimationFactory.h b/src/factories/sm64/AnimationFactory.h index 9658c50..3917516 100644 --- a/src/factories/sm64/AnimationFactory.h +++ b/src/factories/sm64/AnimationFactory.h @@ -19,18 +19,14 @@ public: }; class AnimationBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class AnimationFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, AnimationBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sm64/DialogFactory.cpp b/src/factories/sm64/DialogFactory.cpp index 8cfdcd0..5ffa4db 100644 --- a/src/factories/sm64/DialogFactory.cpp +++ b/src/factories/sm64/DialogFactory.cpp @@ -2,7 +2,7 @@ #include "spdlog/spdlog.h" #include "utils/Decompressor.h" -void SM64::DialogBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SM64::DialogBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto dialog = std::static_pointer_cast<DialogData>(raw); @@ -15,6 +15,7 @@ void SM64::DialogBinaryExporter::Export(std::ostream &write, std::shared_ptr<IPa writer.Write((uint32_t) dialog->mText.size()); writer.Write((char*) dialog->mText.data(), dialog->mText.size()); writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SM64::DialogFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sm64/DialogFactory.h b/src/factories/sm64/DialogFactory.h index dc456f9..ba6579d 100644 --- a/src/factories/sm64/DialogFactory.h +++ b/src/factories/sm64/DialogFactory.h @@ -15,18 +15,14 @@ public: }; class DialogBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class DialogFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, DialogBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sm64/DictionaryFactory.cpp b/src/factories/sm64/DictionaryFactory.cpp index 2b723ef..63d9f3d 100644 --- a/src/factories/sm64/DictionaryFactory.cpp +++ b/src/factories/sm64/DictionaryFactory.cpp @@ -1,6 +1,6 @@ #include "DictionaryFactory.h" -void SM64::DictionaryBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SM64::DictionaryBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); const auto data = std::static_pointer_cast<DictionaryData>(raw); @@ -13,6 +13,7 @@ void SM64::DictionaryBinaryExporter::Export(std::ostream &write, std::shared_ptr writer.Write(reinterpret_cast<char*>(value.data()), value.size()); } writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SM64::DictionaryFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) { diff --git a/src/factories/sm64/DictionaryFactory.h b/src/factories/sm64/DictionaryFactory.h index 4e94aec..0a817d9 100644 --- a/src/factories/sm64/DictionaryFactory.h +++ b/src/factories/sm64/DictionaryFactory.h @@ -12,18 +12,14 @@ public: }; class DictionaryBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class DictionaryFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, DictionaryBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; }
\ No newline at end of file diff --git a/src/factories/sm64/GeoLayoutFactory.cpp b/src/factories/sm64/GeoLayoutFactory.cpp index f0d4788..f8bbc02 100644 --- a/src/factories/sm64/GeoLayoutFactory.cpp +++ b/src/factories/sm64/GeoLayoutFactory.cpp @@ -87,7 +87,7 @@ uint64_t RegisterOrLoadDisplayList(uint32_t ptr) { return 0; } -void SM64::GeoBinaryExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { +ExportResult SM64::GeoBinaryExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { const auto layout = std::static_pointer_cast<GeoLayout>(data).get(); auto writer = LUS::BinaryWriter(); @@ -187,8 +187,8 @@ void SM64::GeoBinaryExporter::Export(std::ostream&write, std::shared_ptr<IParsed output.Close(); } -void SM64::GeoHeaderExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { - +ExportResult SM64::GeoHeaderExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sm64/GeoLayoutFactory.h b/src/factories/sm64/GeoLayoutFactory.h index 0b743af..e769b64 100644 --- a/src/factories/sm64/GeoLayoutFactory.h +++ b/src/factories/sm64/GeoLayoutFactory.h @@ -22,25 +22,21 @@ public: }; class GeoHeaderExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class GeoBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class GeoLayoutFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Header, GeoHeaderExporter) REGISTER(Binary, GeoBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; } diff --git a/src/factories/sm64/TextFactory.cpp b/src/factories/sm64/TextFactory.cpp index 303cdac..c0f9bff 100644 --- a/src/factories/sm64/TextFactory.cpp +++ b/src/factories/sm64/TextFactory.cpp @@ -1,7 +1,7 @@ #include "TextFactory.h" #include "utils/Decompressor.h" -void SM64::TextBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { +ExportResult SM64::TextBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer; @@ -9,6 +9,7 @@ void SM64::TextBinaryExporter::Export(std::ostream &write, std::shared_ptr<IPars writer.Write((uint32_t) data.size()); writer.Write((char*) data.data(), data.size()); writer.Finish(write); + return std::nullopt; } std::optional<std::shared_ptr<IParsedData>> SM64::TextFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { diff --git a/src/factories/sm64/TextFactory.h b/src/factories/sm64/TextFactory.h index 3813587..e7840ac 100644 --- a/src/factories/sm64/TextFactory.h +++ b/src/factories/sm64/TextFactory.h @@ -5,18 +5,14 @@ namespace SM64 { class TextBinaryExporter : public BaseExporter { - void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; + ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; class TextFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; - std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { - return std::nullopt; - } inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { REGISTER(Binary, TextBinaryExporter) }; } - bool SupportModdedAssets() override { return false; } }; };
\ No newline at end of file |
