feat(editor): WAUH JSON round-trip closure

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.
This commit is contained in:
Kelsi 2026-05-10 05:18:42 -07:00
parent 4b63025e4a
commit 8f72664f6c
3 changed files with 176 additions and 0 deletions

View file

@ -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",

View file

@ -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 <typename ParseFn>
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<std::string>());
if (parsed < 0) {
std::fprintf(stderr,
"import-wauh-json: unknown %s token "
"'%s' on entry id=%u\n",
label, v.get<std::string>().c_str(),
entryId);
return false;
}
outValue = static_cast<uint8_t>(parsed);
return true;
}
if (v.is_number_integer()) {
outValue = static_cast<uint8_t>(v.get<int>());
return true;
}
}
if (je.contains(nameKey) && je[nameKey].is_string()) {
int parsed = parseFn(je[nameKey].get<std::string>());
if (parsed >= 0) {
outValue = static_cast<uint8_t>(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<uint16_t>(
je.value("depositRatePct", 0));
e.cutPct = static_cast<uint16_t>(
je.value("cutPct", 0));
e.minListingDurationHours = static_cast<uint16_t>(
je.value("minListingDurationHours", 0));
e.maxListingDurationHours = static_cast<uint16_t>(
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;
}

View file

@ -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 <wauh-base> [--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 <wauh-base> [out.json]\n");
std::printf(" Export binary .wauh to a human-editable JSON sidecar (defaults to <base>.wauh.json; emits factionAccess as int + name string)\n");
std::printf(" --import-wauh-json <json-path> [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 <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");