From 61a621576298eede67ce4be3a91f92bb37e853c1 Mon Sep 17 00:00:00 2001 From: inspectredc <78732756+inspectredc@users.noreply.github.com> Date: Fri, 14 Jun 2024 14:12:39 +0100 Subject: [PATCH] Fix Script Indenting and GeoLayout BranchAndLink to NULL (#139) --- src/factories/sm64/BehaviorScriptFactory.cpp | 6 ++++-- src/factories/sm64/GeoLayoutFactory.cpp | 9 +++++++-- src/factories/sm64/LevelScriptFactory.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/factories/sm64/BehaviorScriptFactory.cpp b/src/factories/sm64/BehaviorScriptFactory.cpp index 953b1de..1033676 100644 --- a/src/factories/sm64/BehaviorScriptFactory.cpp +++ b/src/factories/sm64/BehaviorScriptFactory.cpp @@ -29,14 +29,16 @@ ExportResult SM64::BehaviorScriptCodeExporter::Export(std::ostream &write, std:: for(auto& [opcode, arguments] : commands) { bool commaFlag = false; + if (opcode == BehaviorOpcode::END_LOOP || opcode == BehaviorOpcode::END_REPEAT || opcode == BehaviorOpcode::END_REPEAT_CONTINUE) { + --indentCount; + } + for (uint32_t i = 0; i < indentCount; ++i) { write << fourSpaceTab; } if (opcode == BehaviorOpcode::BEGIN_LOOP || opcode == BehaviorOpcode::BEGIN_REPEAT) { ++indentCount; - } else if (opcode == BehaviorOpcode::END_LOOP || opcode == BehaviorOpcode::END_REPEAT || opcode == BehaviorOpcode::END_REPEAT_CONTINUE) { - --indentCount; } write << opcode << "("; diff --git a/src/factories/sm64/GeoLayoutFactory.cpp b/src/factories/sm64/GeoLayoutFactory.cpp index 4cb924e..ebe679c 100644 --- a/src/factories/sm64/GeoLayoutFactory.cpp +++ b/src/factories/sm64/GeoLayoutFactory.cpp @@ -68,14 +68,16 @@ ExportResult SM64::GeoCodeExporter::Export(std::ostream&write, std::shared_ptr> SM64::GeoLayoutFactory::parse(std::v switch(opcode){ case GeoOpcode::BranchAndLink: { auto ptr = cur_geo_cmd_u32(0x04); + if (ptr == 0) { + processing = false; + } arguments.emplace_back(RegisterAutoGen(ptr, "SM64:GEO_LAYOUT")); cmd += 0x08 << CMD_SIZE_SHIFT; diff --git a/src/factories/sm64/LevelScriptFactory.cpp b/src/factories/sm64/LevelScriptFactory.cpp index dc5e68e..c866a0a 100644 --- a/src/factories/sm64/LevelScriptFactory.cpp +++ b/src/factories/sm64/LevelScriptFactory.cpp @@ -43,14 +43,16 @@ ExportResult SM64::LevelScriptCodeExporter::Export(std::ostream &write, std::sha for(auto& [opcode, arguments] : commands) { bool commaFlag = false; + if (opcode == LevelOpcode::END_AREA) { + --indentCount; + } + for (uint32_t i = 0; i < indentCount; ++i) { write << fourSpaceTab; } if (opcode == LevelOpcode::AREA) { ++indentCount; - } else if (opcode == LevelOpcode::END_AREA) { - --indentCount; } write << opcode << "(";