From a81e69c78d8f930052f8b0847c119f2d3b775812 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 20:30:17 -0700 Subject: [PATCH] feat(pipeline): add WMAC (Wowee Macro / Slash Command) catalog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 58th open format — novel format with no direct DBC equivalent. WoW historically stored player macros client-side in the user profile and system slash commands as hardcoded engine handlers; WMAC unifies both into a single structured catalog so default macros, system slash commands, and shipped player presets can be authored, validated, and shipped as content alongside the rest of the open-format graph. 5 macro kinds (SystemSlash for engine /sit /dance handlers, DefaultMacro for shipped presets, PlayerTemplate for user templates, GuildMacro for guild-shared, SharedMacro for account-wide). Multi-line macro bodies are stored verbatim with literal '\n' separators — the client parses /cast / /target / /run lines at runtime. Cross-references with prior formats — requiredClassMask uses WCHC.classId bit positions (Warrior=0x02, etc, same as WGLY/ WSET/WGTP). CLI: --gen-mac (3 system slash — /sit, /dance, /target with [@mouseover] modifier), --gen-mac-combat (4 warrior combat templates — heroic strike spam, charge/intercept stance dance, intercept stance switch, victory rush+bloodthirst fallback — each with default key bindings), --gen-mac-utility (3 universal utility — /follow target, mass /inv with %targetN tokens, /releasecorpse via RepopMe()), --info-wmac, --validate-wmac with --json variants. Validator catches id+name+body required, kind 0..4, body within maxLength cap, body starting with '/' or '#' (slash command or showtooltip annotation), and SystemSlash + classMask warning (slash commands are class- agnostic — restricting them to a class makes no sense). Format graph: 57 → 58 binary formats. CLI flag count: 814 → 819. --- CMakeLists.txt | 3 + include/pipeline/wowee_macros.hpp | 104 ++++++++++++ src/pipeline/wowee_macros.cpp | 244 ++++++++++++++++++++++++++++ tools/editor/cli_arg_required.cpp | 2 + tools/editor/cli_dispatch.cpp | 2 + tools/editor/cli_format_table.cpp | 1 + tools/editor/cli_help.cpp | 10 ++ tools/editor/cli_list_formats.cpp | 1 + tools/editor/cli_macros_catalog.cpp | 243 +++++++++++++++++++++++++++ tools/editor/cli_macros_catalog.hpp | 11 ++ 10 files changed, 621 insertions(+) create mode 100644 include/pipeline/wowee_macros.hpp create mode 100644 src/pipeline/wowee_macros.cpp create mode 100644 tools/editor/cli_macros_catalog.cpp create mode 100644 tools/editor/cli_macros_catalog.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e4580323..66078752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -646,6 +646,7 @@ set(WOWEE_SOURCES src/pipeline/wowee_keybindings.cpp src/pipeline/wowee_spell_schools.cpp src/pipeline/wowee_lfg.cpp + src/pipeline/wowee_macros.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/dbc_layout.cpp @@ -1446,6 +1447,7 @@ add_executable(wowee_editor tools/editor/cli_spell_schools_catalog.cpp tools/editor/cli_lfg_catalog.cpp tools/editor/cli_catalog_grep.cpp + tools/editor/cli_macros_catalog.cpp tools/editor/cli_quest_objective.cpp tools/editor/cli_quest_reward.cpp tools/editor/cli_clone.cpp @@ -1570,6 +1572,7 @@ add_executable(wowee_editor src/pipeline/wowee_keybindings.cpp src/pipeline/wowee_spell_schools.cpp src/pipeline/wowee_lfg.cpp + src/pipeline/wowee_macros.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/terrain_mesh.cpp diff --git a/include/pipeline/wowee_macros.hpp b/include/pipeline/wowee_macros.hpp new file mode 100644 index 00000000..d38448b4 --- /dev/null +++ b/include/pipeline/wowee_macros.hpp @@ -0,0 +1,104 @@ +#pragma once + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +// Wowee Open Macro / Slash Command catalog (.wmac) — novel +// open format with no direct DBC equivalent. WoW historically +// stored player macros client-side in the user profile and +// system slash commands as hardcoded engine handlers; this +// format unifies both into a single structured catalog so +// default macros, system slash commands, and shipped player +// presets can be authored, validated, and shipped as content. +// +// Each entry has a macro body (the actual `/cast Foo` text, +// multi-line allowed via `\n`), a kind classification +// (system slash / default macro / player template / guild / +// shared), a class-restriction mask, and an optional default +// key binding to fire the macro from the keyboard. +// +// Cross-references with previously-added formats: +// WMAC.entry.requiredClassMask uses WCHC.classId bit +// positions (same convention as +// WGLY/WSET/WGTP). +// The macroBody text is opaque to this catalog — the +// client parses /cast / /target / /run lines at runtime +// against WSPL spell names, action lists, and Lua scripting. +// +// Binary layout (little-endian): +// magic[4] = "WMAC" +// version (uint32) = current 1 +// nameLen + name (catalog label) +// entryCount (uint32) +// entries (each): +// macroId (uint32) +// nameLen + name +// descLen + description +// iconLen + iconPath +// bodyLen + macroBody +// bindLen + bindKey +// macroKind (uint8) / pad[3] +// requiredClassMask (uint32) +// maxLength (uint16) / pad[2] +struct WoweeMacro { + enum MacroKind : uint8_t { + SystemSlash = 0, // /sit, /dance, /yell — engine handlers + DefaultMacro = 1, // shipped with client, user can clone + PlayerTemplate = 2, // template for player-authored macros + GuildMacro = 3, // guild-wide shared macro + SharedMacro = 4, // account-shared (across alts) + }; + + struct Entry { + uint32_t macroId = 0; + std::string name; + std::string description; + std::string iconPath; + std::string macroBody; // can contain \n for multi-line + std::string bindKey; // empty = no default binding + uint8_t macroKind = SystemSlash; + uint32_t requiredClassMask = 0; // 0 = any class + uint16_t maxLength = 255; // body size cap (UI hint) + }; + + std::string name; + std::vector entries; + + bool isValid() const { return !entries.empty(); } + + const Entry* findById(uint32_t macroId) const; + + static const char* macroKindName(uint8_t k); +}; + +class WoweeMacroLoader { +public: + static bool save(const WoweeMacro& cat, + const std::string& basePath); + static WoweeMacro load(const std::string& basePath); + static bool exists(const std::string& basePath); + + // Preset emitters used by --gen-mac* variants. + // + // makeStarter — 3 system slash commands (/sit, /dance, + // /target) — SystemSlash kind, no class + // restriction. + // makeCombat — 4 warrior combat macros (heroic strike + // spam, charge, intercept-on-cooldown, + // victory rush) — PlayerTemplate kind, + // classMask = Warrior. + // makeUtility — 3 universal utility macros (/follow + // target, mass invite, /releasecorpse) + // — DefaultMacro kind, no class + // restriction. + static WoweeMacro makeStarter(const std::string& catalogName); + static WoweeMacro makeCombat(const std::string& catalogName); + static WoweeMacro makeUtility(const std::string& catalogName); +}; + +} // namespace pipeline +} // namespace wowee diff --git a/src/pipeline/wowee_macros.cpp b/src/pipeline/wowee_macros.cpp new file mode 100644 index 00000000..5b933e70 --- /dev/null +++ b/src/pipeline/wowee_macros.cpp @@ -0,0 +1,244 @@ +#include "pipeline/wowee_macros.hpp" + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +namespace { + +constexpr char kMagic[4] = {'W', 'M', 'A', 'C'}; +constexpr uint32_t kVersion = 1; + +template +void writePOD(std::ofstream& os, const T& v) { + os.write(reinterpret_cast(&v), sizeof(T)); +} + +template +bool readPOD(std::ifstream& is, T& v) { + is.read(reinterpret_cast(&v), sizeof(T)); + return is.gcount() == static_cast(sizeof(T)); +} + +void writeStr(std::ofstream& os, const std::string& s) { + uint32_t n = static_cast(s.size()); + writePOD(os, n); + if (n > 0) os.write(s.data(), n); +} + +bool readStr(std::ifstream& is, std::string& s) { + uint32_t n = 0; + if (!readPOD(is, n)) return false; + if (n > (1u << 20)) return false; + s.resize(n); + if (n > 0) { + is.read(s.data(), n); + if (is.gcount() != static_cast(n)) { + s.clear(); + return false; + } + } + return true; +} + +std::string normalizePath(std::string base) { + if (base.size() < 5 || base.substr(base.size() - 5) != ".wmac") { + base += ".wmac"; + } + return base; +} + +} // namespace + +const WoweeMacro::Entry* +WoweeMacro::findById(uint32_t macroId) const { + for (const auto& e : entries) + if (e.macroId == macroId) return &e; + return nullptr; +} + +const char* WoweeMacro::macroKindName(uint8_t k) { + switch (k) { + case SystemSlash: return "system-slash"; + case DefaultMacro: return "default-macro"; + case PlayerTemplate: return "player-template"; + case GuildMacro: return "guild-macro"; + case SharedMacro: return "shared-macro"; + default: return "unknown"; + } +} + +bool WoweeMacroLoader::save(const WoweeMacro& cat, + const std::string& basePath) { + std::ofstream os(normalizePath(basePath), std::ios::binary); + if (!os) return false; + os.write(kMagic, 4); + writePOD(os, kVersion); + writeStr(os, cat.name); + uint32_t entryCount = static_cast(cat.entries.size()); + writePOD(os, entryCount); + for (const auto& e : cat.entries) { + writePOD(os, e.macroId); + writeStr(os, e.name); + writeStr(os, e.description); + writeStr(os, e.iconPath); + writeStr(os, e.macroBody); + writeStr(os, e.bindKey); + writePOD(os, e.macroKind); + uint8_t pad3[3] = {0, 0, 0}; + os.write(reinterpret_cast(pad3), 3); + writePOD(os, e.requiredClassMask); + writePOD(os, e.maxLength); + uint8_t pad2[2] = {0, 0}; + os.write(reinterpret_cast(pad2), 2); + } + return os.good(); +} + +WoweeMacro WoweeMacroLoader::load(const std::string& basePath) { + WoweeMacro out; + std::ifstream is(normalizePath(basePath), std::ios::binary); + if (!is) return out; + char magic[4]; + is.read(magic, 4); + if (std::memcmp(magic, kMagic, 4) != 0) return out; + uint32_t version = 0; + if (!readPOD(is, version) || version != kVersion) return out; + if (!readStr(is, out.name)) return out; + uint32_t entryCount = 0; + if (!readPOD(is, entryCount)) return out; + if (entryCount > (1u << 20)) return out; + out.entries.resize(entryCount); + for (auto& e : out.entries) { + if (!readPOD(is, e.macroId)) { + out.entries.clear(); return out; + } + if (!readStr(is, e.name) || !readStr(is, e.description) || + !readStr(is, e.iconPath) || !readStr(is, e.macroBody) || + !readStr(is, e.bindKey)) { + out.entries.clear(); return out; + } + if (!readPOD(is, e.macroKind)) { + out.entries.clear(); return out; + } + uint8_t pad3[3]; + is.read(reinterpret_cast(pad3), 3); + if (is.gcount() != 3) { out.entries.clear(); return out; } + if (!readPOD(is, e.requiredClassMask) || + !readPOD(is, e.maxLength)) { + out.entries.clear(); return out; + } + uint8_t pad2[2]; + is.read(reinterpret_cast(pad2), 2); + if (is.gcount() != 2) { out.entries.clear(); return out; } + } + return out; +} + +bool WoweeMacroLoader::exists(const std::string& basePath) { + std::ifstream is(normalizePath(basePath), std::ios::binary); + return is.good(); +} + +WoweeMacro WoweeMacroLoader::makeStarter( + const std::string& catalogName) { + WoweeMacro c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, const char* body, + const char* desc) { + WoweeMacro::Entry e; + e.macroId = id; e.name = name; + e.description = desc; e.macroBody = body; + e.iconPath = "Interface/Icons/INV_Misc_Note_01.blp"; + e.macroKind = WoweeMacro::SystemSlash; + c.entries.push_back(e); + }; + add(1, "Sit", "/sit", + "Toggle sitting on the ground."); + add(2, "Dance", "/dance", + "Perform race-specific dance emote."); + add(3, "Target", + "/target [@mouseover]", + "Target the unit your mouse is currently hovering over."); + return c; +} + +WoweeMacro WoweeMacroLoader::makeCombat( + const std::string& catalogName) { + WoweeMacro c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, const char* body, + const char* bindKey, const char* desc) { + WoweeMacro::Entry e; + e.macroId = id; e.name = name; + e.description = desc; + e.macroBody = body; + e.bindKey = bindKey; + e.iconPath = std::string("Interface/Icons/Ability_Warrior_") + + name + ".blp"; + e.macroKind = WoweeMacro::PlayerTemplate; + e.requiredClassMask = 1u << 1; // WCHC Warrior bit + c.entries.push_back(e); + }; + // Multi-line macros encoded with \n inside the body. + add(100, "HeroicStrikeSpam", + "#showtooltip Heroic Strike\n" + "/cast Heroic Strike", + "1", + "Single-rank Heroic Strike with #showtooltip — bind to 1."); + add(101, "Charge", + "#showtooltip Charge\n" + "/cast [combat] Intercept; Charge", + "Q", + "Auto-switches between Charge and Intercept based on " + "combat state."); + add(102, "Intercept", + "/cast [stance:1/3] Berserker Stance\n" + "/cast Intercept", + "T", + "Stance-dance into Berserker if not already, then Intercept."); + add(103, "VictoryRush", + "#showtooltip Victory Rush\n" + "/cast Victory Rush\n" + "/cast Bloodthirst", + "F", + "Victory Rush with Bloodthirst fallback."); + return c; +} + +WoweeMacro WoweeMacroLoader::makeUtility( + const std::string& catalogName) { + WoweeMacro c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, const char* body, + const char* desc) { + WoweeMacro::Entry e; + e.macroId = id; e.name = name; + e.description = desc; + e.macroBody = body; + e.iconPath = std::string("Interface/Icons/INV_Misc_") + + name + ".blp"; + e.macroKind = WoweeMacro::DefaultMacro; + c.entries.push_back(e); + }; + add(200, "FollowTarget", + "/follow [@target]", + "Follow the unit you have currently targeted."); + add(201, "MassInvite", + "/inv %target1\n" + "/inv %target2\n" + "/inv %target3\n" + "/inv %target4", + "Invite up to four players in one click. Replace " + "%targetN with player names."); + add(202, "ReleaseCorpse", + "/script RepopMe()", + "Release spirit immediately on death."); + return c; +} + +} // namespace pipeline +} // namespace wowee diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 5b01e7a7..39443614 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -176,6 +176,8 @@ const char* const kArgRequired[] = { "--gen-lfg", "--gen-lfg-heroic", "--gen-lfg-raid", "--info-wlfg", "--validate-wlfg", "--export-wlfg-json", "--import-wlfg-json", + "--gen-mac", "--gen-mac-combat", "--gen-mac-utility", + "--info-wmac", "--validate-wmac", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_dispatch.cpp b/tools/editor/cli_dispatch.cpp index 599989e4..60cc8b13 100644 --- a/tools/editor/cli_dispatch.cpp +++ b/tools/editor/cli_dispatch.cpp @@ -93,6 +93,7 @@ #include "cli_spell_schools_catalog.hpp" #include "cli_lfg_catalog.hpp" #include "cli_catalog_grep.hpp" +#include "cli_macros_catalog.hpp" #include "cli_quest_objective.hpp" #include "cli_quest_reward.hpp" #include "cli_clone.hpp" @@ -227,6 +228,7 @@ constexpr DispatchFn kDispatchTable[] = { handleSpellSchoolsCatalog, handleLFGCatalog, handleCatalogGrep, + handleMacrosCatalog, handleQuestObjective, handleQuestReward, handleClone, diff --git a/tools/editor/cli_format_table.cpp b/tools/editor/cli_format_table.cpp index d372f63b..a0332cef 100644 --- a/tools/editor/cli_format_table.cpp +++ b/tools/editor/cli_format_table.cpp @@ -60,6 +60,7 @@ constexpr FormatMagicEntry kFormats[] = { {{'W','K','B','D'}, ".wkbd", "input", "--info-wkbd", "Keybinding catalog"}, {{'W','S','C','H'}, ".wsch", "spells", "--info-wsch", "Spell school / damage type catalog"}, {{'W','L','F','G'}, ".wlfg", "social", "--info-wlfg", "LFG / Dungeon Finder catalog"}, + {{'W','M','A','C'}, ".wmac", "ui", "--info-wmac", "Macro / slash command catalog"}, {{'W','F','A','C'}, ".wfac", "factions", nullptr, "Faction catalog"}, {{'W','L','C','K'}, ".wlck", "locks", nullptr, "Lock catalog"}, {{'W','S','K','L'}, ".wskl", "skills", nullptr, "Skill catalog"}, diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index bce6dcab..e1d4cdaa 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1545,6 +1545,16 @@ void printUsage(const char* argv0) { std::printf(" Export binary .wlfg to a human-editable JSON sidecar (defaults to .wlfg.json)\n"); std::printf(" --import-wlfg-json [out-base]\n"); std::printf(" Import a .wlfg.json sidecar back into binary .wlfg (accepts difficulty/expansion int OR name string; groupSize defaults to 5, role mask to kRoleAll)\n"); + std::printf(" --gen-mac [name]\n"); + std::printf(" Emit .wmac starter: 3 system slash commands (/sit, /dance, /target with [@mouseover])\n"); + std::printf(" --gen-mac-combat [name]\n"); + std::printf(" Emit .wmac 4 warrior combat macros (Heroic Strike spam, Charge/Intercept stance dance, Victory Rush) with bind keys + classMask\n"); + std::printf(" --gen-mac-utility [name]\n"); + std::printf(" Emit .wmac 3 utility macros (/follow target, mass /inv with %%targetN, /releasecorpse via RepopMe)\n"); + std::printf(" --info-wmac [--json]\n"); + std::printf(" Print WMAC entries (id / kind / classMask / bindKey / maxLen / body length / name)\n"); + std::printf(" --validate-wmac [--json]\n"); + std::printf(" Static checks: id+name+body required, kind 0..4, body within maxLength, body starts with '/' or '#', SystemSlash + classMask warning\n"); std::printf(" --gen-weather-temperate [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n"); diff --git a/tools/editor/cli_list_formats.cpp b/tools/editor/cli_list_formats.cpp index 36da2aa3..09ca3988 100644 --- a/tools/editor/cli_list_formats.cpp +++ b/tools/editor/cli_list_formats.cpp @@ -82,6 +82,7 @@ constexpr FormatRow kFormats[] = { {"WKBD", ".wkbd", "input", "KeyBinding.dbc + default binds", "Default keybinding catalog"}, {"WSCH", ".wsch", "spells", "SpellSchools.dbc + Resistances", "Spell school / damage type catalog"}, {"WLFG", ".wlfg", "social", "LFGDungeons.dbc + LFG rewards", "LFG / Dungeon Finder catalog"}, + {"WMAC", ".wmac", "ui", "(client-side macro storage)", "Macro / slash command catalog"}, // Additional pipeline catalogs without the alternating // gen/info/validate CLI surface (loaded by the engine diff --git a/tools/editor/cli_macros_catalog.cpp b/tools/editor/cli_macros_catalog.cpp new file mode 100644 index 00000000..34a223f9 --- /dev/null +++ b/tools/editor/cli_macros_catalog.cpp @@ -0,0 +1,243 @@ +#include "cli_macros_catalog.hpp" +#include "cli_arg_parse.hpp" +#include "cli_box_emitter.hpp" + +#include "pipeline/wowee_macros.hpp" +#include + +#include +#include +#include +#include +#include +#include + +namespace wowee { +namespace editor { +namespace cli { + +namespace { + +std::string stripWmacExt(std::string base) { + stripExt(base, ".wmac"); + return base; +} + +bool saveOrError(const wowee::pipeline::WoweeMacro& c, + const std::string& base, const char* cmd) { + if (!wowee::pipeline::WoweeMacroLoader::save(c, base)) { + std::fprintf(stderr, "%s: failed to save %s.wmac\n", + cmd, base.c_str()); + return false; + } + return true; +} + +void printGenSummary(const wowee::pipeline::WoweeMacro& c, + const std::string& base) { + std::printf("Wrote %s.wmac\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" macros : %zu\n", c.entries.size()); +} + +int handleGenStarter(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "StarterMacros"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWmacExt(base); + auto c = wowee::pipeline::WoweeMacroLoader::makeStarter(name); + if (!saveOrError(c, base, "gen-mac")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenCombat(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "CombatMacros"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWmacExt(base); + auto c = wowee::pipeline::WoweeMacroLoader::makeCombat(name); + if (!saveOrError(c, base, "gen-mac-combat")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenUtility(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "UtilityMacros"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWmacExt(base); + auto c = wowee::pipeline::WoweeMacroLoader::makeUtility(name); + if (!saveOrError(c, base, "gen-mac-utility")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleInfo(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWmacExt(base); + if (!wowee::pipeline::WoweeMacroLoader::exists(base)) { + std::fprintf(stderr, "WMAC not found: %s.wmac\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMacroLoader::load(base); + if (jsonOut) { + nlohmann::json j; + j["wmac"] = base + ".wmac"; + j["name"] = c.name; + j["count"] = c.entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"macroId", e.macroId}, + {"name", e.name}, + {"description", e.description}, + {"iconPath", e.iconPath}, + {"macroBody", e.macroBody}, + {"bindKey", e.bindKey}, + {"macroKind", e.macroKind}, + {"macroKindName", wowee::pipeline::WoweeMacro::macroKindName(e.macroKind)}, + {"requiredClassMask", e.requiredClassMask}, + {"maxLength", e.maxLength}, + }); + } + j["entries"] = arr; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("WMAC: %s.wmac\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" macros : %zu\n", c.entries.size()); + if (c.entries.empty()) return 0; + std::printf(" id kind classMask bindKey maxLen bodyLen name\n"); + for (const auto& e : c.entries) { + std::printf(" %4u %-15s 0x%08x %-8s %5u %6zu %s\n", + e.macroId, + wowee::pipeline::WoweeMacro::macroKindName(e.macroKind), + e.requiredClassMask, + e.bindKey.empty() ? "-" : e.bindKey.c_str(), + e.maxLength, e.macroBody.size(), + e.name.c_str()); + } + return 0; +} + +int handleValidate(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWmacExt(base); + if (!wowee::pipeline::WoweeMacroLoader::exists(base)) { + std::fprintf(stderr, + "validate-wmac: WMAC not found: %s.wmac\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMacroLoader::load(base); + std::vector errors; + std::vector warnings; + if (c.entries.empty()) { + warnings.push_back("catalog has zero entries"); + } + std::vector idsSeen; + for (size_t k = 0; k < c.entries.size(); ++k) { + const auto& e = c.entries[k]; + std::string ctx = "entry " + std::to_string(k) + + " (id=" + std::to_string(e.macroId); + if (!e.name.empty()) ctx += " " + e.name; + ctx += ")"; + if (e.macroId == 0) + errors.push_back(ctx + ": macroId is 0"); + if (e.name.empty()) + errors.push_back(ctx + ": name is empty"); + if (e.macroBody.empty()) + errors.push_back(ctx + + ": macroBody is empty (macro does nothing)"); + if (e.macroKind > wowee::pipeline::WoweeMacro::SharedMacro) { + errors.push_back(ctx + ": macroKind " + + std::to_string(e.macroKind) + " not in 0..4"); + } + if (e.maxLength != 0 && e.macroBody.size() > e.maxLength) { + errors.push_back(ctx + + ": macroBody length " + + std::to_string(e.macroBody.size()) + + " exceeds maxLength " + + std::to_string(e.maxLength)); + } + // Macro body must start with `/` (slash command) — any + // line that doesn't is a stray comment / orphan text. + if (!e.macroBody.empty() && e.macroBody[0] != '/' && + e.macroBody[0] != '#') { + warnings.push_back(ctx + + ": macroBody doesn't start with '/' or '#' " + "(likely missing slash on first line)"); + } + // SystemSlash macros are run by the engine, not by the + // player — assigning a class restriction makes no sense + // since the slash command is shared by all classes. + if (e.macroKind == wowee::pipeline::WoweeMacro::SystemSlash && + e.requiredClassMask != 0) { + warnings.push_back(ctx + + ": SystemSlash kind with requiredClassMask != 0 " + "(slash commands are class-agnostic)"); + } + for (uint32_t prev : idsSeen) { + if (prev == e.macroId) { + errors.push_back(ctx + ": duplicate macroId"); + break; + } + } + idsSeen.push_back(e.macroId); + } + bool ok = errors.empty(); + if (jsonOut) { + nlohmann::json j; + j["wmac"] = base + ".wmac"; + j["ok"] = ok; + j["errors"] = errors; + j["warnings"] = warnings; + std::printf("%s\n", j.dump(2).c_str()); + return ok ? 0 : 1; + } + std::printf("validate-wmac: %s.wmac\n", base.c_str()); + if (ok && warnings.empty()) { + std::printf(" OK — %zu macros, all macroIds unique, " + "all bodies within length cap\n", c.entries.size()); + return 0; + } + if (!warnings.empty()) { + std::printf(" warnings (%zu):\n", warnings.size()); + for (const auto& w : warnings) + std::printf(" - %s\n", w.c_str()); + } + if (!errors.empty()) { + std::printf(" ERRORS (%zu):\n", errors.size()); + for (const auto& e : errors) + std::printf(" - %s\n", e.c_str()); + } + return ok ? 0 : 1; +} + +} // namespace + +bool handleMacrosCatalog(int& i, int argc, char** argv, int& outRc) { + if (std::strcmp(argv[i], "--gen-mac") == 0 && i + 1 < argc) { + outRc = handleGenStarter(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-mac-combat") == 0 && i + 1 < argc) { + outRc = handleGenCombat(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-mac-utility") == 0 && i + 1 < argc) { + outRc = handleGenUtility(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--info-wmac") == 0 && i + 1 < argc) { + outRc = handleInfo(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--validate-wmac") == 0 && i + 1 < argc) { + outRc = handleValidate(i, argc, argv); return true; + } + return false; +} + +} // namespace cli +} // namespace editor +} // namespace wowee diff --git a/tools/editor/cli_macros_catalog.hpp b/tools/editor/cli_macros_catalog.hpp new file mode 100644 index 00000000..df03e454 --- /dev/null +++ b/tools/editor/cli_macros_catalog.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace wowee { +namespace editor { +namespace cli { + +bool handleMacrosCatalog(int& i, int argc, char** argv, int& outRc); + +} // namespace cli +} // namespace editor +} // namespace wowee