feat(editor): WBRD JSON round-trip closure

Adds --export-wbrd-json / --import-wbrd-json. battlegroundName
emitted as informational field; battlegroundId int is
authoritative. All 3 presets (av/wsg/ab) byte-identical binary
roundtrip OK including the AB preset's weekly bonus quest token
binding.

Live-tested incentive-inversion validator: hand-mutated WSG
bracket 6 (rewardId 15) to swap winHonor and lossHonor — loss
becomes 750, win becomes 375. Validator correctly errored:
"lossHonor=750 > winHonor=375 — losing rewards more than winning
(no win incentive)". Catches the class of reward-config bugs
where misordered fields would silently flip the optimal player
strategy from "play to win" to "AFK and lose for max XP/hour".

CLI flag count 1461 -> 1463.
This commit is contained in:
Kelsi 2026-05-10 05:27:03 -07:00
parent a10497a026
commit a2f0055a4d
3 changed files with 128 additions and 0 deletions

View file

@ -430,6 +430,7 @@ const char* const kArgRequired[] = {
"--export-wauh-json", "--import-wauh-json",
"--gen-brd-av", "--gen-brd-wsg", "--gen-brd-ab",
"--info-wbrd", "--validate-wbrd",
"--export-wbrd-json", "--import-wbrd-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -266,6 +266,121 @@ int handleValidate(int& i, int argc, char** argv) {
return ok ? 0 : 1;
}
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 = stripWbrdExt(base);
if (out.empty()) out = base + ".wbrd.json";
if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::exists(base)) {
std::fprintf(stderr,
"export-wbrd-json: WBRD not found: %s.wbrd\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::load(base);
nlohmann::json j;
j["magic"] = "WBRD";
j["version"] = 1;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"rewardId", e.rewardId},
{"battlegroundId", e.battlegroundId},
{"battlegroundName", bgName(e.battlegroundId)},
{"bracketIndex", e.bracketIndex},
{"minPlayersToStart", e.minPlayersToStart},
{"winHonor", e.winHonor},
{"lossHonor", e.lossHonor},
{"markItemId", e.markItemId},
{"winMarks", e.winMarks},
{"lossMarks", e.lossMarks},
{"bonusItemId", e.bonusItemId},
{"bonusItemCount", e.bonusItemCount},
});
}
j["entries"] = arr;
std::ofstream os(out);
if (!os) {
std::fprintf(stderr,
"export-wbrd-json: failed to open %s for write\n",
out.c_str());
return 1;
}
os << j.dump(2) << "\n";
std::printf("Wrote %s (%zu stages)\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) == ".wbrd.json") {
outBase.resize(outBase.size() - 10);
} else {
stripExt(outBase, ".json");
stripExt(outBase, ".wbrd");
}
}
std::ifstream is(in);
if (!is) {
std::fprintf(stderr,
"import-wbrd-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-wbrd-json: JSON parse error: %s\n", ex.what());
return 1;
}
wowee::pipeline::WoweeBattlegroundRewards c;
c.name = j.value("name", std::string{});
if (!j.contains("entries") || !j["entries"].is_array()) {
std::fprintf(stderr,
"import-wbrd-json: missing or non-array 'entries'\n");
return 1;
}
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeBattlegroundRewards::Entry e;
e.rewardId = je.value("rewardId", 0u);
e.battlegroundId = static_cast<uint16_t>(
je.value("battlegroundId", 0));
e.bracketIndex = static_cast<uint8_t>(
je.value("bracketIndex", 0));
e.minPlayersToStart = static_cast<uint8_t>(
je.value("minPlayersToStart", 0));
e.winHonor = je.value("winHonor", 0u);
e.lossHonor = je.value("lossHonor", 0u);
e.markItemId = je.value("markItemId", 0u);
e.winMarks = static_cast<uint16_t>(
je.value("winMarks", 0));
e.lossMarks = static_cast<uint16_t>(
je.value("lossMarks", 0));
e.bonusItemId = je.value("bonusItemId", 0u);
e.bonusItemCount = static_cast<uint16_t>(
je.value("bonusItemCount", 0));
c.entries.push_back(e);
}
if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wbrd-json: failed to save %s.wbrd\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wbrd (%zu stages)\n",
outBase.c_str(), c.entries.size());
return 0;
}
} // namespace
bool handleBattlegroundRewardsCatalog(int& i, int argc, char** argv,
@ -289,6 +404,14 @@ bool handleBattlegroundRewardsCatalog(int& i, int argc, char** argv,
i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wbrd-json") == 0 &&
i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wbrd-json") == 0 &&
i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}

View file

@ -2723,6 +2723,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WBRD entries (id / bg / bracket / minPlayers / win+loss honor / markId / win+loss marks / bonusItem)\n");
std::printf(" --validate-wbrd <wbrd-base> [--json]\n");
std::printf(" Static checks: id+battlegroundId required, bracketIndex 1..6 (vanilla), minPlayersToStart > 0 (else queue would never start a match), no duplicate rewardIds, no duplicate (bgId,bracket) pairs (runtime reward-lookup tie), bonusItemCount > 0 requires bonusItemId; CRITICAL: lossHonor <= winHonor (else losing rewards more than winning, no incentive to play to win). Warns on winMarks=0 with markItemId set (vanilla wins always granted at least 1 mark)\n");
std::printf(" --export-wbrd-json <wbrd-base> [out.json]\n");
std::printf(" Export binary .wbrd to a human-editable JSON sidecar (defaults to <base>.wbrd.json; battlegroundName field is informational; battlegroundId int is authoritative)\n");
std::printf(" --import-wbrd-json <json-path> [out-base]\n");
std::printf(" Import a .wbrd.json sidecar back into binary .wbrd (battlegroundName ignored; bgId int authoritative — round-trips per-bracket reward tables byte-identical)\n");
std::printf(" --catalog-pluck <wXXX-file> <id> [--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 <directory> <id> [--magic <WXXX>] [--json]\n");