From 3cfd85a93dc3180be89616f867163a757f3eec16 Mon Sep 17 00:00:00 2001 From: inspectredc Date: Thu, 28 Mar 2024 19:27:21 +0000 Subject: temp exporter format improvement and parser improvements --- src/factories/sm64/GeoLayoutFactory.cpp | 46 ++++++++++++++++++++++----------- src/factories/sm64/geo/GeoCommand.h | 4 +-- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/factories/sm64/GeoLayoutFactory.cpp b/src/factories/sm64/GeoLayoutFactory.cpp index 6f91c71..be67f47 100644 --- a/src/factories/sm64/GeoLayoutFactory.cpp +++ b/src/factories/sm64/GeoLayoutFactory.cpp @@ -59,61 +59,75 @@ ExportResult SM64::GeoCodeExporter::Export(std::ostream&write, std::shared_ptr(args.index())) { case GeoArgumentType::U8: { - write << static_cast(std::get(args)); + write << std::hex << "0x" << static_cast(std::get(args)); break; } case GeoArgumentType::S8: { - write << static_cast(std::get(args)); + write << std::hex << "0x" << static_cast(std::get(args)); break; } case GeoArgumentType::U16: { - write << std::get(args); + write << std::hex << "0x" << std::get(args); break; } case GeoArgumentType::S16: { - write << std::get(args); + write << std::dec << std::get(args); break; } case GeoArgumentType::U32: { - write << "0x" << std::hex << std::get(args); + write << std::hex << "0x" << std::get(args); break; } case GeoArgumentType::S32: { - write << std::get(args); + write << std::dec << std::get(args); break; } case GeoArgumentType::U64: { - write << "0x" << std::hex << std::get(args); + // write << std::hex << "0x" << std::get(args); + uint32_t ptr = std::get(args); + auto dec = Companion::Instance->GetNodeByAddr(ptr); + std::string symbol = "NULL"; + + if (dec.has_value()) { + auto node = std::get<1>(dec.value()); + symbol = GetSafeNode(node, "symbol"); + write << symbol; + } else if (ptr == 0) { + write << symbol; + } else { + SPDLOG_WARN("Cannot find node for ptr 0x{:X}", ptr); + write << std::hex << "0x" << ptr; + } break; } case GeoArgumentType::VEC2F: { const auto [x, y] = std::get(args); - write << x << ", " << y; + write << std::dec << x << ", " << y; break; } case GeoArgumentType::VEC3F: { const auto [x, y, z] = std::get(args); - write << x << ", " << y << ", " << z; + write << std::dec << x << ", " << y << ", " << z; break; } case GeoArgumentType::VEC3S: { const auto [x, y, z] = std::get(args); - write << x << ", " << y << ", " << z; + write << std::dec << x << ", " << y << ", " << z; break; } case GeoArgumentType::VEC3I: { const auto [x, y, z] = std::get(args); - write << x << ", " << y << ", " << z; + write << std::dec << x << ", " << y << ", " << z; break; } case GeoArgumentType::VEC4F: { const auto [x, y, z, w] = std::get(args); - write << x << ", " << y << ", " << z << ", " << w; + write << std::dec << x << ", " << y << ", " << z << ", " << w; break; } case GeoArgumentType::VEC4S: { const auto [x, y, z, w] = std::get(args); - write << x << ", " << y << ", " << z << ", " << w; + write << std::dec << x << ", " << y << ", " << z << ", " << w; break; } case GeoArgumentType::STRING: { @@ -282,6 +296,7 @@ std::optional> SM64::GeoLayoutFactory::parse(std::v break; } case GeoOpcode::Return: + processing = false; case GeoOpcode::OpenNode: case GeoOpcode::CloseNode: { cmd += 0x04 << CMD_SIZE_SHIFT; @@ -390,10 +405,10 @@ std::optional> SM64::GeoLayoutFactory::parse(std::v auto ptr = cur_geo_cmd_u32(0x10); auto type = cur_geo_cmd_s16(0x02); + arguments.emplace_back(type); arguments.emplace_back(pos); arguments.emplace_back(focus); arguments.emplace_back(ptr); - arguments.emplace_back(type); cmd += 0x14 << CMD_SIZE_SHIFT; break; @@ -469,11 +484,12 @@ std::optional> SM64::GeoLayoutFactory::parse(std::v auto cmd_pos = reinterpret_cast(cmd); arguments.emplace_back(layer); - arguments.emplace_back(RegisterAutoGen(ptr, "GFX")); read_vec3s(translation, &cmd_pos[1]); arguments.emplace_back(translation); + arguments.emplace_back(RegisterAutoGen(ptr, "GFX")); + cmd += 0x0C << CMD_SIZE_SHIFT; break; } diff --git a/src/factories/sm64/geo/GeoCommand.h b/src/factories/sm64/geo/GeoCommand.h index e7b2966..2fdad6b 100644 --- a/src/factories/sm64/geo/GeoCommand.h +++ b/src/factories/sm64/geo/GeoCommand.h @@ -157,10 +157,10 @@ inline std::ostream& operator<<(std::ostream& out, const GeoOpcode& opcode) { (cmd[CMD_PROCESS_OFFSET(offset)]) #define cur_geo_cmd_s16(offset) \ - BSWAP16((*(int16_t *) &cmd[CMD_PROCESS_OFFSET(offset)])) + (int16_t)BSWAP16((*(int16_t *) &cmd[CMD_PROCESS_OFFSET(offset)])) #define cur_geo_cmd_s32(offset) \ - BSWAP32((*(s32 *) &cmd[CMD_PROCESS_OFFSET(offset)])) + (s32)BSWAP32((*(s32 *) &cmd[CMD_PROCESS_OFFSET(offset)])) #define cur_geo_cmd_u32(offset) \ (uint32_t) BSWAP32((*(uint32_t *) &cmd[CMD_PROCESS_OFFSET(offset)])) -- cgit v1.2.3