diff --git a/src/factories/sf64/HitboxFactory.cpp b/src/factories/sf64/HitboxFactory.cpp index 24af087..510dd7f 100644 --- a/src/factories/sf64/HitboxFactory.cpp +++ b/src/factories/sf64/HitboxFactory.cpp @@ -62,13 +62,13 @@ ExportResult SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_p for(int i = 0; i < (int)count; i++) { if(hitbox->mTypes[i] == 4) { - write << fourSpaceTab << "HITBOX_TYPE_4, "; + write << fourSpaceTab << "HITBOX_WHOOSH, "; index++; } else if (hitbox->mTypes[i] == 3) { - write << fourSpaceTab << "HITBOX_TYPE_3, "; + write << fourSpaceTab << "HITBOX_SHADOW, "; index++; } else if (hitbox->mTypes[i] == 2) { - write << fourSpaceTab << "HITBOX_TYPE_2, "; + write << fourSpaceTab << "HITBOX_ROTATED, "; index++; for(int j = 0; j < 3; j++) { auto tempf = hitbox->mData[index++]; @@ -76,7 +76,7 @@ ExportResult SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_p write << ", "; } } else { - write << " /* HITBOX_TYPE_1 */ "; + write << " /* HITBOX_STANDARD */ "; } if(hasType2 && hitbox->mTypes[i] != 2) { for(int j = 0; j < 7; j++) { diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp index 9251cf2..c68de1a 100644 --- a/src/factories/sf64/ScriptFactory.cpp +++ b/src/factories/sf64/ScriptFactory.cpp @@ -4,10 +4,14 @@ #include "Companion.h" #include "utils/Decompressor.h" #include "utils/TorchUtils.h" -#include +#include "regex.h" #include "storm/SWrapper.h" +#define CLAMP_MAX(val, max) (((val) < (max)) ? (val) : (max)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define VALUE_TO_ENUM(val, enumname, fallback) (Companion::Instance->GetEnumFromValue(enumname, val).value_or("/*" + std::string(fallback) + " */ " + std::to_string(val))); + SF64::ScriptData::ScriptData(std::vector ptrs, std::vector cmds, std::map sizeMap, uint32_t ptrsStart, uint32_t cmdsStart): mPtrs(ptrs), mCmds(cmds), mSizeMap(sizeMap), mPtrsStart(ptrsStart), mCmdsStart(cmdsStart) { } @@ -16,7 +20,7 @@ ExportResult SF64::ScriptHeaderExporter::Export(std::ostream &write, std::shared const auto symbol = GetSafeNode(node, "symbol", entryName); if(Companion::Instance->IsOTRMode()){ - write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; return std::nullopt; } @@ -30,20 +34,17 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { std::ostringstream cmd; std::ostringstream comment; - auto enumName = Companion::Instance->GetEnumFromValue("EventOpcode", opcode).value_or("/* EVOP_UNK */ " + std::to_string(opcode)); - switch (opcode) { case 0: case 1: { auto f3 = arg1 & 0x7F; - auto zm = (arg1 >> 7) & 3; - auto zmode = Companion::Instance->GetEnumFromValue("EventModeZ", zm).value_or("/* EVOP_UNK */ " + std::to_string(zm)); - - cmd << "EVENT_SET_" << (opcode ? "ACCEL" : "SPEED") << "(" << std::dec << f3 << ", " << zmode << ", " << s2 << "),"; + auto zmode = VALUE_TO_ENUM((arg1 >> 7) & 3, "EventModeZ", "EVOP_UNK"); + + cmd << "EVENT_SET_" << (opcode ? "ACCEL" : "SPEED") << "(" << std::dec << f3 << ", " << zmode << ", " << s2; comment << " // wait " << s2 << " frames"; } break; case 2: - cmd << "EVENT_SET_BASE_ZVEL(" << std::dec << s2 << "),"; + cmd << "EVENT_SET_BASE_ZVEL(" << std::dec << s2; break; case 9: case 10: @@ -55,97 +56,124 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { case 19: case 20: case 21: { - auto rotcmd = enumName.replace(0, 4, "EVENT"); - cmd << rotcmd << "(" << std::dec << s2 << ", " << std::fixed << std::setprecision(1) << arg1 / 10.0f << "),"; + auto rotcmd = VALUE_TO_ENUM(opcode, "EventOpcode", "EVOP_UNK"); + cmd << rotcmd.replace(0, 4, "EVENT") << "(" << std::dec << s2 << ", " << std::fixed << std::setprecision(1) << arg1 / 10.0f; if(opcode < 16 && arg1 != 0) { comment << " // wait " << 10 * s2 / arg1 << " frames"; } } break; case 24: - cmd << "EVENT_SET_ROTATE(),"; + cmd << "EVENT_SET_ROTATE("; break; case 25: - cmd << "EVENT_STOP_ROTATE(),"; + cmd << "EVENT_STOP_ROTATE("; break; - case 56: - cmd << "EVENT_SET_CALL(" << std::dec << s2 << ", " << arg1 << "),"; + case 44: + cmd << "EVENT_CHASE_TARGET(" << std::dec << arg1 << ", " << s2; break; - case 57: - cmd << "EVENT_RESTORE_TEAM(" << std::dec << s2 << "),"; - break; - case 58: { - auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); - cmd << "EVENT_PLAY_SFX(" << sfxIndex << "),"; + case 45: { + auto teamId = VALUE_TO_ENUM(arg1, "TeamId", "TEAMID_UNK"); + cmd << "EVENT_SET_TARGET(" << teamId << ", " << std::dec << s2; } break; + case 56: + cmd << "EVENT_SET_CALL(" << std::dec << s2 << ", " << arg1; + break; + case 57: { + auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); + cmd << "EVENT_RESTORE_TEAM(" << teamId; + } break; + case 58: case 59: { - auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); - cmd << "EVENT_STOP_SFX(" << sfxIndex << "),"; + auto sfxIndex = VALUE_TO_ENUM(s2, "EventSfx", "EVSFX_UNK"); + cmd << "EVENT_" << ((opcode == 58) ? "PLAY" : "STOP") << "_SFX(" << sfxIndex; } break; case 96: if(s2 == 0) { - cmd << "EVENT_CLEAR_TRIGGER(" << std::dec << arg1 << "),"; - } else if(s2 >= 100) { - auto condition = Companion::Instance->GetEnumFromValue("EventCondition", 100).value_or("/* EVC_UNK */ " + std::to_string(s2)); - cmd << "EVENT_SET_TRIGGER(" << condition << " + " << std::dec << (s2 - 100) << ", " << std::dec << arg1 << "),"; + cmd << "EVENT_CLEAR_TRIGGER(" << std::dec << arg1; } else { - auto condition = Companion::Instance->GetEnumFromValue("EventCondition", s2).value_or("/* EVC_UNK */ " + std::to_string(s2)); - cmd << "EVENT_SET_TRIGGER(" << condition << ", " << std::dec << arg1 << "),"; + if (s2 >= 100) { + cmd << "EVENT_SET_Z_TRIGGER(" << std::dec << (s2 - 100) * 10 << ", "; + } else { + auto condition = VALUE_TO_ENUM(s2, "EventCondition", "EVC_UNK"); + cmd << "EVENT_SET_TRIGGER(" << condition << ", "; + } + cmd << ((arg1 < 200) ? "" : "EVENT_AI_CHANGE + ") << std::dec << ((arg1 < 200) ? arg1 : arg1 - 200); } break; case 104: { - auto actorinfo = Companion::Instance->GetEnumFromValue("EventActorInfo", s2).value_or("/* EINFO_UNK */ " + std::to_string(s2)); - cmd << "EVENT_INIT_ACTOR(" << actorinfo << ", " << std::dec << arg1 << "),"; + // auto actorinfo = Companion::Instance->GetEnumFromValue("EventActorInfo", s2).value_or("/* EINFO_UNK */ " + std::to_string(s2)); + auto actorInfo = VALUE_TO_ENUM(s2, "EventActorInfo", "EINFO_UNK"); + cmd << "EVENT_INIT_ACTOR(" << actorInfo << ", " << std::dec << arg1; + } break; + case 105: { + auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); + cmd << "EVENT_SET_TEAM_ID(" << teamId; } break; case 112:{ - auto actiontype = Companion::Instance->GetEnumFromValue("EventAction", s2).value_or("/* EVACT_UNK */ " + std::to_string(s2)); - cmd << "EVENT_SET_ACTION(" << actiontype << "),"; + // auto actiontype = Companion::Instance->GetEnumFromValue("EventAction", s2).value_or("/* EVACT_UNK */ " + std::to_string(s2)); + auto actiontype = VALUE_TO_ENUM(s2, "EventAction", "EVACT_UNK"); + cmd << "EVENT_SET_ACTION(" << actiontype; if((s2 == 14 || s2 == 15)) { comment << " // wait 1 frame"; } } break; case 113: - cmd << "EVENT_ADD_TO_GROUP(" << std::dec << s2 << ", " << arg1 << "),"; + cmd << "EVENT_ADD_TO_GROUP(" << std::dec << s2 << ", " << arg1; break; case 116: { - auto itemtype = Companion::Instance->GetEnumFromValue("ItemDrop", s2).value_or("/* DROP_UNK */ " + std::to_string(s2)); - cmd << "EVENT_DROP_ITEM(" << itemtype << "),"; + // auto itemtype = Companion::Instance->GetEnumFromValue("ItemDrop", s2).value_or("/* DROP_UNK */ " + std::to_string(s2)); + auto itemType = VALUE_TO_ENUM(s2, "ItemDrop", "DROP_UNK"); + cmd << "EVENT_DROP_ITEM(" << itemType; } break; - case 118: - cmd << "EVENT_SET_REVERB(" << std::dec << s2 << "),"; + case 118: + cmd << "EVENT_SET_REVERB(" << std::dec << s2; break; case 119: { - auto groundtype = Companion::Instance->GetEnumFromValue("GroundType", s2).value_or("/* GROUNDTYPE_UNK */ " + std::to_string(s2)); - cmd << "EVENT_SET_GROUND(" << groundtype << "),"; + // auto groundtype = Companion::Instance->GetEnumFromValue("GroundType", s2).value_or("/* GROUNDTYPE_UNK */ " + std::to_string(s2)); + auto groundtype = VALUE_TO_ENUM(s2, "GroundType", "GROUNDTYPE_UNK"); + cmd << "EVENT_SET_GROUND(" << groundtype; } break; case 120: { - auto rcidName = Companion::Instance->GetEnumFromValue("RadioCharacterId", arg1).value_or("/* RCID_UNK */ " + std::to_string(arg1)); - cmd << "EVENT_PLAY_MSG(" << rcidName << ", " << std::dec << std::setw(5) << s2 << "),"; + // auto rcidName = Companion::Instance->GetEnumFromValue("RadioCharacterId", arg1).value_or("/* RCID_UNK */ " + std::to_string(arg1)); + auto rcidName = VALUE_TO_ENUM(arg1, "RadioCharacterId", "RCID_UNK"); + cmd << "EVENT_PLAY_MSG(" << rcidName << ", " << std::dec << s2; } break; - case 122: - cmd << "EVENT_STOP_BGM(),"; + case 121: { + auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); + cmd << "EVENT_DAMAGE_TEAM(" << teamId << ", " << std::dec << arg1; + } break; + case 122: + cmd << "EVENT_STOP_BGM("; break; case 124: { - auto color = Companion::Instance->GetEnumFromValue("TexLineColor", s2).value_or("/* TXLC_UNK */ " + std::to_string(s2)); - cmd << "EVENT_MAKE_TEXLINE(" << color << "),"; + // auto color = Companion::Instance->GetEnumFromValue("TexLineColor", s2).value_or("/* TXLC_UNK */ " + std::to_string(s2)); + auto color = VALUE_TO_ENUM(s2, "TexLineColor", "TXLC_UNK"); + cmd << "EVENT_MAKE_TEXLINE(" << color; } break; case 125: - cmd << "EVENT_STOP_TEXLINE(),"; + cmd << "EVENT_STOP_TEXLINE("; break; - case 126: - cmd << "EVENT_LOOP(" << std::dec << arg1 << ", " << s2 << "),"; + case 126: + cmd << ((s2 == 0) ? "EVENT_GOTO(" : "EVENT_LOOP("); + if(s2 != 0) { + cmd << std::dec << s2 << ", "; + } + cmd << ((arg1 < 200) ? "" : "EVENT_AI_CHANGE + ") << std::dec << ((arg1 < 200) ? arg1 : arg1 - 200); break; case 127: - cmd << "EVENT_STOP_SCRIPT(),"; + cmd << "EVENT_STOP_SCRIPT("; comment << "// wait"; break; - default: - cmd << "EVENT_CMD(" << enumName << ", " << std::dec << arg1 << ", " << s2 << "),"; + default: { + // auto opcodeName = Companion::Instance->GetEnumFromValue("EventOpcode", opcode).value_or("/* EVOP_UNK */ " + std::to_string(opcode)); + auto opcodeName = VALUE_TO_ENUM(opcode, "EventOpcode", "EVOP_UNK"); + cmd << "EVENT_CMD(" << opcodeName << ", " << std::dec << arg1 << ", " << s2; if(opcode >= 40 && opcode <= 48) { comment << " // wait"; } - break; + } break; } - cmd << comment.str(); + cmd << "), " << comment.str(); return cmd.str(); } @@ -178,7 +206,7 @@ ExportResult SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_p // } write << MakeScriptCmd(script->mCmds[cmdIndex], script->mCmds[cmdIndex + 1]); } - + write << "\n};\n"; cmdOff += 4 * cmdCount;