diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index d2ee6668..04e1976d 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -327,6 +327,7 @@ const char* const kArgRequired[] = { "--export-wldn-json", "--import-wldn-json", "--gen-cre", "--gen-cre-elites", "--gen-cre-immune", "--info-wcre", "--validate-wcre", + "--export-wcre-json", "--import-wcre-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_creature_resists_catalog.cpp b/tools/editor/cli_creature_resists_catalog.cpp index 31c0bd81..bb64587d 100644 --- a/tools/editor/cli_creature_resists_catalog.cpp +++ b/tools/editor/cli_creature_resists_catalog.cpp @@ -158,6 +158,193 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +// Parse a "+"-joined token bitmask into the +// ccImmunityMask bits. "all" → 0xFFFF, "none" or empty → 0. +// Returns -1 on unknown token (no partial result). +int parseCcImmunityString(const std::string& s) { + using R = wowee::pipeline::WoweeCreatureResists; + if (s.empty() || s == "none") return 0; + if (s == "all") return 0xFFFF; + int mask = 0; + size_t pos = 0; + while (pos < s.size()) { + size_t plus = s.find('+', pos); + std::string tok = (plus == std::string::npos) + ? s.substr(pos) : s.substr(pos, plus - pos); + if (tok == "root") mask |= R::ImmuneRoot; + else if (tok == "snare") mask |= R::ImmuneSnare; + else if (tok == "stun") mask |= R::ImmuneStun; + else if (tok == "fear") mask |= R::ImmuneFear; + else if (tok == "sleep") mask |= R::ImmuneSleep; + else if (tok == "silence") mask |= R::ImmuneSilence; + else if (tok == "charm") mask |= R::ImmuneCharm; + else if (tok == "disarm") mask |= R::ImmuneDisarm; + else if (tok == "polymorph") mask |= R::ImmunePolymorph; + else if (tok == "banish") mask |= R::ImmuneBanish; + else if (tok == "knockback") mask |= R::ImmuneKnockback; + else if (tok == "interrupt") mask |= R::ImmuneInterrupt; + else if (tok == "taunt") mask |= R::ImmuneTaunt; + else if (tok == "bleed") mask |= R::ImmuneBleed; + else return -1; + if (plus == std::string::npos) break; + pos = plus + 1; + } + return mask; +} + +int handleExportJson(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string out; + if (parseOptArg(i, argc, argv)) out = argv[++i]; + base = stripWcreExt(base); + if (out.empty()) out = base + ".wcre.json"; + if (!wowee::pipeline::WoweeCreatureResistsLoader::exists(base)) { + std::fprintf(stderr, + "export-wcre-json: WCRE not found: %s.wcre\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeCreatureResistsLoader::load(base); + nlohmann::json j; + j["magic"] = "WCRE"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"resistId", e.resistId}, + {"name", e.name}, + {"description", e.description}, + {"creatureEntry", e.creatureEntry}, + {"holyResist", e.holyResist}, + {"fireResist", e.fireResist}, + {"natureResist", e.natureResist}, + {"frostResist", e.frostResist}, + {"shadowResist", e.shadowResist}, + {"arcaneResist", e.arcaneResist}, + {"physicalResistPct", e.physicalResistPct}, + {"ccImmunityMask", e.ccImmunityMask}, + {"ccImmunityNames", + ccImmunityString(e.ccImmunityMask)}, + {"mechanicImmunityMask", e.mechanicImmunityMask}, + {"schoolImmunityMask", e.schoolImmunityMask}, + {"iconColorRGBA", e.iconColorRGBA}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wcre-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu resist profiles)\n", + out.c_str(), c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string in = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = in; + if (outBase.size() >= 10 && + outBase.substr(outBase.size() - 10) == ".wcre.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wcre"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wcre-json: cannot open %s\n", in.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wcre-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeCreatureResists c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wcre-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeCreatureResists::Entry e; + e.resistId = je.value("resistId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.creatureEntry = je.value("creatureEntry", 0u); + e.holyResist = static_cast( + je.value("holyResist", 0)); + e.fireResist = static_cast( + je.value("fireResist", 0)); + e.natureResist = static_cast( + je.value("natureResist", 0)); + e.frostResist = static_cast( + je.value("frostResist", 0)); + e.shadowResist = static_cast( + je.value("shadowResist", 0)); + e.arcaneResist = static_cast( + je.value("arcaneResist", 0)); + e.physicalResistPct = static_cast( + je.value("physicalResistPct", 0u)); + // ccImmunityMask: int OR "+"-joined token string. + if (je.contains("ccImmunityMask")) { + const auto& cm = je["ccImmunityMask"]; + if (cm.is_string()) { + int parsed = parseCcImmunityString( + cm.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wcre-json: unknown " + "ccImmunityMask token in '%s' on " + "entry id=%u\n", + cm.get().c_str(), + e.resistId); + return 1; + } + e.ccImmunityMask = static_cast(parsed); + } else if (cm.is_number_integer()) { + e.ccImmunityMask = static_cast( + cm.get()); + } + } else if (je.contains("ccImmunityNames") && + je["ccImmunityNames"].is_string()) { + int parsed = parseCcImmunityString( + je["ccImmunityNames"].get()); + if (parsed >= 0) + e.ccImmunityMask = static_cast(parsed); + } + e.mechanicImmunityMask = je.value( + "mechanicImmunityMask", 0u); + e.schoolImmunityMask = static_cast( + je.value("schoolImmunityMask", 0u)); + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeCreatureResistsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wcre-json: failed to save %s.wcre\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wcre (%zu resist profiles)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -291,6 +478,12 @@ bool handleCreatureResistsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wcre") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wcre-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wcre-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index b6da838c..41549b1f 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2247,6 +2247,10 @@ void printUsage(const char* argv0) { std::printf(" Print WCRE entries (id / creatureEntry / 6 school resists / phys%% / school-immune mask / CC-immune token list / name)\n"); std::printf(" --validate-wcre [--json]\n"); std::printf(" Static checks: id+name+creatureEntry required, no duplicate resistIds OR creatureEntries (damage-calc lookup ambiguity); warns on resist<-100 (extreme negative >2x dmg taken), physicalResistPct>75 (clamped at runtime), schoolImmunityMask reserved bits 0xC0 set\n"); + std::printf(" --export-wcre-json [out.json]\n"); + std::printf(" Export binary .wcre to a human-editable JSON sidecar (defaults to .wcre.json; emits ccImmunityMask as both raw uint16 AND \"+\"-joined name string \"root+stun+fear\" / \"all\" / \"none\")\n"); + std::printf(" --import-wcre-json [out-base]\n"); + std::printf(" Import a .wcre.json sidecar back into binary .wcre (ccImmunityMask int OR token string \"all\"/\"none\"/\"+\"-joined from {root,snare,stun,fear,sleep,silence,charm,disarm,polymorph,banish,knockback,interrupt,taunt,bleed})\n"); std::printf(" --catalog-pluck [--json]\n"); std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n"); std::printf(" --catalog-find [--magic ] [--json]\n");