diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-06-09 00:50:45 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2024-06-09 00:50:45 -0600 |
| commit | 0153dd0329549e66c2373cfe4b96063a3790d35a (patch) | |
| tree | 26b01b3b56c126a6b7553f5f520653b62242b52b | |
| parent | 521452cb6aea6034859546dffb0bc18d3880d4db (diff) | |
Fixed GeoLayout Processing
| -rw-r--r-- | src/Companion.cpp | 12 | ||||
| -rw-r--r-- | src/factories/DisplayListFactory.cpp | 4 | ||||
| -rw-r--r-- | src/factories/sm64/GeoLayoutFactory.cpp | 66 | ||||
| -rw-r--r-- | src/factories/sm64/GeoLayoutFactory.h | 2 |
4 files changed, 76 insertions, 8 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index 5776ae5..a797ee4 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -922,13 +922,19 @@ void Companion::ProcessFile(YAML::Node root) { fs::path entryPath = this->gCurrentFile; std::string symbol = entryPath.stem().string(); std::transform(symbol.begin(), symbol.end(), symbol.begin(), toupper); - file << "#ifndef " << symbol << "_H" << std::endl; - file << "#define " << symbol << "_H" << std::endl << std::endl; + if(this->IsOTRMode()){ + file << "#pragma once\n\n"; + } else { + file << "#ifndef " << symbol << "_H" << std::endl; + file << "#define " << symbol << "_H" << std::endl << std::endl; + } if(!this->gFileHeader.empty()) { file << this->gFileHeader << std::endl; } file << buffer; - file << std::endl << "#endif" << std::endl; + if(!this->IsOTRMode()){ + file << std::endl << "#endif" << std::endl; + } } else { if(!this->gFileHeader.empty()) { file << this->gFileHeader << std::endl; diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index 4258996..088ff1d 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -312,6 +312,8 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP } if(opcode == GBI(G_MOVEMEM)) { + // TODO: Fix this opcode + continue; auto ptr = w1; auto dec = Companion::Instance->GetNodeByAddr(ptr); @@ -320,7 +322,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP switch (gbi) { case GBIVersion::f3d: - index = C0(0, 8); + index = C0(16, 8); offset = 0; break; default: diff --git a/src/factories/sm64/GeoLayoutFactory.cpp b/src/factories/sm64/GeoLayoutFactory.cpp index 73eed8e..58150bf 100644 --- a/src/factories/sm64/GeoLayoutFactory.cpp +++ b/src/factories/sm64/GeoLayoutFactory.cpp @@ -6,6 +6,11 @@ #include "geo/GeoUtils.h" #include "utils/TorchUtils.h" +#include <regex> + +std::unordered_map<uint32_t, std::string> gFunctionMap; +static std::regex pattern(R"(0x([0-9a-fA-F]+)\s{16}([^\s]+))"); + uint64_t RegisterAutoGen(uint32_t ptr, std::string type) { if (ptr != 0) { @@ -13,16 +18,48 @@ uint64_t RegisterAutoGen(uint32_t ptr, std::string type) { node["type"] = type; node["offset"] = ptr; Companion::Instance->AddAsset(node); + } else { + SPDLOG_WARN("RegisterAutoGen: ptr is 0 type: {}", type); } return ptr; } +void StoreFunc(uint32_t vram) { + return; + + if(!gFunctionMap.contains(vram)) { + return; + } + + auto name = gFunctionMap[vram]; + SPDLOG_INFO("Found Function: 0x{:X} Name: {}", vram, name); + + std::ofstream outfile; + outfile.open("map.txt", std::ios_base::app); + outfile << "{ 0x" << std::hex << vram << ", " << name << " },\n"; + + gFunctionMap.erase(vram); +} + +SM64::GeoLayoutFactory::GeoLayoutFactory() { + // std::ifstream file("/Users/lywx/Downloads/sm64.jp.map"); + // std::string str; + // while (std::getline(file, str)) { + // if(str.find('=') != std::string::npos) { + // continue; + // } + + // std::smatch match; + // if (std::regex_search(str, match, pattern)) { + // gFunctionMap[std::stoul(match[1].str(), nullptr, 16)] = match[2].str(); + // } + // } +} + ExportResult SM64::GeoCodeExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { const auto cmds = std::static_pointer_cast<GeoLayout>(data)->commands; const auto symbol = GetSafeNode(node, "symbol", entryName); - auto offset = GetSafeNode<uint32_t>(node, "offset"); - size_t size = 0; uint32_t indentCount = 1; uint32_t cmdCount = 0; @@ -258,6 +295,15 @@ ExportResult SM64::GeoBinaryExporter::Export(std::ostream&write, std::shared_ptr } ExportResult SM64::GeoHeaderExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) { + const auto symbol = GetSafeNode(node, "symbol", entryName); + + if(Companion::Instance->IsOTRMode()){ + write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + return std::nullopt; + } + + write << "extern GeoLayout " << symbol << "[];\n"; + return std::nullopt; } @@ -297,8 +343,10 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v cmd += 0x08 << CMD_SIZE_SHIFT; break; } - case GeoOpcode::Return: + case GeoOpcode::Return: { processing = false; + break; + } case GeoOpcode::OpenNode: case GeoOpcode::CloseNode: { cmd += 0x04 << CMD_SIZE_SHIFT; @@ -359,6 +407,8 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v auto ptr = cur_geo_cmd_u32(0x08); arguments.emplace_back(ptr); + StoreFunc(ptr); + cmd += 0x04 << CMD_SIZE_SHIFT; } @@ -393,6 +443,8 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v arguments.emplace_back(cs); arguments.emplace_back(ptr); + StoreFunc(ptr); + cmd += 0x08 << CMD_SIZE_SHIFT; break; } @@ -412,6 +464,8 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v arguments.emplace_back(focus); arguments.emplace_back(ptr); + StoreFunc(ptr); + cmd += 0x14 << CMD_SIZE_SHIFT; break; } @@ -547,7 +601,7 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v arguments.emplace_back(param); arguments.emplace_back(ptr); - SPDLOG_INFO("Found ASM: 0x{:X}", ptr); + StoreFunc(ptr); cmd += 0x08 << CMD_SIZE_SHIFT; break; @@ -559,6 +613,8 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v arguments.emplace_back(bg); arguments.emplace_back(ptr); + StoreFunc(ptr); + cmd += 0x08 << CMD_SIZE_SHIFT; break; } @@ -578,6 +634,8 @@ std::optional<std::shared_ptr<IParsedData>> SM64::GeoLayoutFactory::parse(std::v auto ptr = cur_geo_cmd_u32(0x08); auto player = cur_geo_cmd_u8(0x01); + StoreFunc(ptr); + arguments.emplace_back(ptr); arguments.emplace_back(player); diff --git a/src/factories/sm64/GeoLayoutFactory.h b/src/factories/sm64/GeoLayoutFactory.h index 2cc7120..7f41a95 100644 --- a/src/factories/sm64/GeoLayoutFactory.h +++ b/src/factories/sm64/GeoLayoutFactory.h @@ -39,6 +39,8 @@ class GeoBinaryExporter : public BaseExporter { class GeoLayoutFactory : public BaseFactory { public: + GeoLayoutFactory(); + std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { |
