From 8f72664f6cb92b60958349e2b81831785b1a7d46 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 05:18:42 -0700 Subject: [PATCH] feat(editor): WAUH JSON round-trip closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds --export-wauh-json / --import-wauh-json with the established readEnumField template factoring int+name dual encoding for factionAccess ("both"/"alliance"/"horde"/"neutral"). All 3 presets (stormwind/orgrimmar/bootybay) byte-identical binary roundtrip OK including the Booty Bay neutral 15%/15% rate configuration. Live-tested economic-trap validator: hand-mutated Booty Bay deposit to 60% + cut to 50% (sum 110%). Validator correctly errored: "depositRatePct=6000 + cutPct=5000 = 11000 basis points — seller would lose money on every sale (combined rates >= 100%)". Catches misconfigured AH rates that would silently trap players into negative expected returns on every listing. CLI flag count 1452 -> 1454. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_auction_houses_catalog.cpp | 171 ++++++++++++++++++++ tools/editor/cli_help.cpp | 4 + 3 files changed, 176 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 85afdefc..6e36a565 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -427,6 +427,7 @@ const char* const kArgRequired[] = { "--export-wprc-json", "--import-wprc-json", "--gen-auh-stormwind", "--gen-auh-orgrimmar", "--gen-auh-bootybay", "--info-wauh", "--validate-wauh", + "--export-wauh-json", "--import-wauh-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_auction_houses_catalog.cpp b/tools/editor/cli_auction_houses_catalog.cpp index 85b3fae1..dcb3ca82 100644 --- a/tools/editor/cli_auction_houses_catalog.cpp +++ b/tools/editor/cli_auction_houses_catalog.cpp @@ -146,6 +146,53 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseFactionAccessToken(const std::string& s) { + using A = wowee::pipeline::WoweeAuctionHouses; + if (s == "both") return A::Both; + if (s == "alliance") return A::Alliance; + if (s == "horde") return A::Horde; + if (s == "neutral") return A::Neutral; + return -1; +} + +template +bool readEnumField(const nlohmann::json& je, + const char* intKey, + const char* nameKey, + ParseFn parseFn, + const char* label, + uint32_t entryId, + uint8_t& outValue) { + if (je.contains(intKey)) { + const auto& v = je[intKey]; + if (v.is_string()) { + int parsed = parseFn(v.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wauh-json: unknown %s token " + "'%s' on entry id=%u\n", + label, v.get().c_str(), + entryId); + return false; + } + outValue = static_cast(parsed); + return true; + } + if (v.is_number_integer()) { + outValue = static_cast(v.get()); + return true; + } + } + if (je.contains(nameKey) && je[nameKey].is_string()) { + int parsed = parseFn(je[nameKey].get()); + if (parsed >= 0) { + outValue = static_cast(parsed); + return true; + } + } + return true; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -303,6 +350,122 @@ 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 = stripWauhExt(base); + if (out.empty()) out = base + ".wauh.json"; + if (!wowee::pipeline::WoweeAuctionHousesLoader::exists(base)) { + std::fprintf(stderr, + "export-wauh-json: WAUH not found: %s.wauh\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeAuctionHousesLoader::load(base); + nlohmann::json j; + j["magic"] = "WAUH"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"ahId", e.ahId}, + {"name", e.name}, + {"factionAccess", e.factionAccess}, + {"factionAccessName", + factionAccessName(e.factionAccess)}, + {"depositRatePct", e.depositRatePct}, + {"cutPct", e.cutPct}, + {"minListingDurationHours", + e.minListingDurationHours}, + {"maxListingDurationHours", + e.maxListingDurationHours}, + {"feePerSlot", e.feePerSlot}, + {"npcAuctioneerId", e.npcAuctioneerId}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wauh-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu houses)\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) == ".wauh.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wauh"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wauh-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-wauh-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeAuctionHouses c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wauh-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeAuctionHouses::Entry e; + e.ahId = je.value("ahId", 0u); + e.name = je.value("name", std::string{}); + if (!readEnumField(je, "factionAccess", + "factionAccessName", + parseFactionAccessToken, + "factionAccess", e.ahId, + e.factionAccess)) return 1; + e.depositRatePct = static_cast( + je.value("depositRatePct", 0)); + e.cutPct = static_cast( + je.value("cutPct", 0)); + e.minListingDurationHours = static_cast( + je.value("minListingDurationHours", 0)); + e.maxListingDurationHours = static_cast( + je.value("maxListingDurationHours", 0)); + e.feePerSlot = je.value("feePerSlot", 0u); + e.npcAuctioneerId = je.value("npcAuctioneerId", 0u); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeAuctionHousesLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wauh-json: failed to save %s.wauh\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wauh (%zu houses)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleAuctionHousesCatalog(int& i, int argc, char** argv, @@ -326,6 +489,14 @@ bool handleAuctionHousesCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wauh-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wauh-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 49f2a0db..aba98c40 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2709,6 +2709,10 @@ void printUsage(const char* argv0) { std::printf(" Print WAUH entries (id / faction / depositPct / cutPct / hour range / fee / npcAuctioneerId / name)\n"); std::printf(" --validate-wauh [--json]\n"); std::printf(" Static checks: id+name required, factionAccess 0..3, depositRatePct + cutPct each in 0..10000 (basis points), no duplicate ahIds, no duplicate (faction,name) pairs, no duplicate npcAuctioneerId (gossip dispatch tie), maxListingDuration > 0 and minListing <= maxListing; CRITICAL: combined depositRatePct + cutPct < 10000 (else seller loses money on every sale). Warns on combined > 50%% (sellers may abandon AH; verify intentional like neutral AH penalty)\n"); + std::printf(" --export-wauh-json [out.json]\n"); + std::printf(" Export binary .wauh to a human-editable JSON sidecar (defaults to .wauh.json; emits factionAccess as int + name string)\n"); + std::printf(" --import-wauh-json [out-base]\n"); + std::printf(" Import a .wauh.json sidecar back into binary .wauh (factionAccess int OR \"both\"/\"alliance\"/\"horde\"/\"neutral\" — round-trips per-AH config byte-identical)\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");