Kelsidavis-WoWee/tools/editor/cli_locks_catalog.cpp

420 lines
16 KiB
C++
Raw Normal View History

feat(pipeline): add WLCK (Wowee Lock Template) format Novel open replacement for Blizzard's Lock.dbc. The 18th open format added to the editor. Closes the cross-reference gap from WGOT.entry.lockId — until now that field pointed to a format that didn't exist yet. A lock is a multi-channel security check. Each lock has up to 5 independent channels; a player can open the lock by satisfying ANY ONE channel: • Item — requires a specific key item (WIT cross-ref) • Lockpick — requires the lockpicking skill at minimum rank (rogue / engineering profession) • Spell — requires casting a specific spell • Damage — can be forced open with attack damage Cross-references with previously-added formats: WGOT.entry.lockId -> WLCK.entry.lockId WLCK.channel.targetId (Item) -> WIT.entry.itemId WLCK.channel.targetId (Lockpick) -> future WSKL skillId WLCK.channel.targetId (Spell) -> future WSPL spellId The starter and dungeon presets' lockIds (1 and 2) deliberately match WGOT.makeDungeon's iron-door lockId=1 and bandit-strongbox lockId=2, so the demo content stack already wires together: WSPN spawn -> WGOT object template -> WLCK lock template -> WIT key items. Format: • magic "WLCK", version 1, little-endian • per lock: lockId / name / flags / 5 fixed channel slots • per channel: kind / skillRequired / targetId • all 5 slots written even when unused (kind=None + zeroed fields), keeping the per-entry size constant for fast random access Enums: • ChannelKind: None / Item / Lockpick / Spell / Damage • Flags: DestructOnOpen / RespawnOnKey / TrapOnFail API: WoweeLockLoader::save / load / exists / findById; presets makeStarter (Iron Door + Wooden Chest), makeDungeon (matches WGOT cross-references; light/heavy lockpicks + boss-key-only seal), makeProfessions (4-tier rogue lockpick progression at ranks 1/100/175/250). CLI added (5 flags, 521 documented total now): --gen-locks / --gen-locks-dungeon / --gen-locks-professions --info-wlck / --validate-wlck Validator catches: lockId=0 + duplicates, all-None channels (lock can never open), Item/Spell/Lockpick channels with targetId=0 (no resource referenced), unknown channel kind, skillRequired set on non-Lockpick channel (silently ignored at runtime — flag as warning).
2026-05-09 15:44:26 -07:00
#include "cli_locks_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_locks.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWlckExt(std::string base) {
stripExt(base, ".wlck");
return base;
}
void appendLockFlagsStr(std::string& s, uint32_t flags) {
if (flags & wowee::pipeline::WoweeLock::DestructOnOpen) s += "destruct ";
if (flags & wowee::pipeline::WoweeLock::RespawnOnKey) s += "respawn ";
if (flags & wowee::pipeline::WoweeLock::TrapOnFail) s += "trap ";
if (s.empty()) s = "-";
else if (s.back() == ' ') s.pop_back();
}
bool saveOrError(const wowee::pipeline::WoweeLock& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeLockLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wlck\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeLock& c,
const std::string& base) {
std::printf("Wrote %s.wlck\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" locks : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterLocks";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWlckExt(base);
auto c = wowee::pipeline::WoweeLockLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-locks")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenDungeon(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "DungeonLocks";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWlckExt(base);
auto c = wowee::pipeline::WoweeLockLoader::makeDungeon(name);
if (!saveOrError(c, base, "gen-locks-dungeon")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenProfessions(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "ProfessionLocks";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWlckExt(base);
auto c = wowee::pipeline::WoweeLockLoader::makeProfessions(name);
if (!saveOrError(c, base, "gen-locks-professions")) 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 = stripWlckExt(base);
if (!wowee::pipeline::WoweeLockLoader::exists(base)) {
std::fprintf(stderr, "WLCK not found: %s.wlck\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeLockLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wlck"] = base + ".wlck";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
std::string fs;
appendLockFlagsStr(fs, e.flags);
nlohmann::json je;
je["lockId"] = e.lockId;
je["name"] = e.name;
je["flags"] = e.flags;
je["flagsStr"] = fs;
nlohmann::json chans = nlohmann::json::array();
for (int k = 0; k < wowee::pipeline::WoweeLock::kChannelSlots; ++k) {
const auto& ch = e.channels[k];
chans.push_back({
{"slot", k},
{"kind", ch.kind},
{"kindName", wowee::pipeline::WoweeLock::channelKindName(ch.kind)},
{"skillRequired", ch.skillRequired},
{"targetId", ch.targetId},
});
}
je["channels"] = chans;
arr.push_back(je);
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WLCK: %s.wlck\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" locks : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
for (const auto& e : c.entries) {
std::string fs;
appendLockFlagsStr(fs, e.flags);
std::printf("\n lockId=%u flags=%s %s\n",
e.lockId, fs.c_str(), e.name.c_str());
for (int k = 0; k < wowee::pipeline::WoweeLock::kChannelSlots; ++k) {
const auto& ch = e.channels[k];
if (ch.kind == wowee::pipeline::WoweeLock::ChannelNone) continue;
std::printf(" slot %d : %-9s target=%u skillReq=%u\n",
k,
wowee::pipeline::WoweeLock::channelKindName(ch.kind),
ch.targetId, ch.skillRequired);
}
}
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
// Mirrors the JSON pairs added for every other novel
// open format. Each lock emits scalar fields plus the
// 5 fixed channel slots; channel.kind emits dual int +
// name forms.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWlckExt(base);
if (outPath.empty()) outPath = base + ".wlck.json";
if (!wowee::pipeline::WoweeLockLoader::exists(base)) {
std::fprintf(stderr,
"export-wlck-json: WLCK not found: %s.wlck\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeLockLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
std::string fs;
appendLockFlagsStr(fs, e.flags);
nlohmann::json je;
je["lockId"] = e.lockId;
je["name"] = e.name;
je["flags"] = e.flags;
nlohmann::json fa = nlohmann::json::array();
if (e.flags & wowee::pipeline::WoweeLock::DestructOnOpen) fa.push_back("destruct");
if (e.flags & wowee::pipeline::WoweeLock::RespawnOnKey) fa.push_back("respawn");
if (e.flags & wowee::pipeline::WoweeLock::TrapOnFail) fa.push_back("trap");
je["flagsList"] = fa;
nlohmann::json chans = nlohmann::json::array();
for (int k = 0; k < wowee::pipeline::WoweeLock::kChannelSlots; ++k) {
const auto& ch = e.channels[k];
chans.push_back({
{"slot", k},
{"kind", ch.kind},
{"kindName", wowee::pipeline::WoweeLock::channelKindName(ch.kind)},
{"skillRequired", ch.skillRequired},
{"targetId", ch.targetId},
});
}
je["channels"] = chans;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wlck-json: cannot write %s\n", outPath.c_str());
return 1;
}
out << j.dump(2) << "\n";
out.close();
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" source : %s.wlck\n", base.c_str());
std::printf(" locks : %zu\n", c.entries.size());
return 0;
}
int handleImportJson(int& i, int argc, char** argv) {
std::string jsonPath = argv[++i];
std::string outBase;
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
if (outBase.empty()) {
outBase = jsonPath;
std::string suffix = ".wlck.json";
if (outBase.size() > suffix.size() &&
outBase.substr(outBase.size() - suffix.size()) == suffix) {
outBase = outBase.substr(0, outBase.size() - suffix.size());
} else if (outBase.size() > 5 &&
outBase.substr(outBase.size() - 5) == ".json") {
outBase = outBase.substr(0, outBase.size() - 5);
}
}
outBase = stripWlckExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wlck-json: cannot read %s\n", jsonPath.c_str());
return 1;
}
nlohmann::json j;
try { in >> j; }
catch (const std::exception& e) {
std::fprintf(stderr,
"import-wlck-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto kindFromName = [](const std::string& s) -> uint8_t {
if (s == "-" || s.empty()) return wowee::pipeline::WoweeLock::ChannelNone;
if (s == "item") return wowee::pipeline::WoweeLock::ChannelItem;
if (s == "lockpick") return wowee::pipeline::WoweeLock::ChannelLockpick;
if (s == "spell") return wowee::pipeline::WoweeLock::ChannelSpell;
if (s == "damage") return wowee::pipeline::WoweeLock::ChannelDamage;
return wowee::pipeline::WoweeLock::ChannelNone;
};
auto flagFromName = [](const std::string& s) -> uint32_t {
if (s == "destruct") return wowee::pipeline::WoweeLock::DestructOnOpen;
if (s == "respawn") return wowee::pipeline::WoweeLock::RespawnOnKey;
if (s == "trap") return wowee::pipeline::WoweeLock::TrapOnFail;
return 0;
};
wowee::pipeline::WoweeLock c;
c.name = j.value("name", std::string{});
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeLock::Entry e;
e.lockId = je.value("lockId", 0u);
e.name = je.value("name", std::string{});
if (je.contains("flags") && je["flags"].is_number_integer()) {
e.flags = je["flags"].get<uint32_t>();
} else if (je.contains("flagsList") && je["flagsList"].is_array()) {
for (const auto& f : je["flagsList"]) {
if (f.is_string()) e.flags |= flagFromName(f.get<std::string>());
}
}
if (je.contains("channels") && je["channels"].is_array()) {
int slotIdx = 0;
for (const auto& jc : je["channels"]) {
if (slotIdx >= wowee::pipeline::WoweeLock::kChannelSlots) break;
auto& ch = e.channels[slotIdx];
if (jc.contains("kind") && jc["kind"].is_number_integer()) {
ch.kind = static_cast<uint8_t>(jc["kind"].get<int>());
} else if (jc.contains("kindName") && jc["kindName"].is_string()) {
ch.kind = kindFromName(jc["kindName"].get<std::string>());
}
ch.skillRequired = static_cast<uint16_t>(jc.value("skillRequired", 0));
ch.targetId = jc.value("targetId", 0u);
++slotIdx;
}
}
c.entries.push_back(std::move(e));
}
}
if (!wowee::pipeline::WoweeLockLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wlck-json: failed to save %s.wlck\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wlck\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" locks : %zu\n", c.entries.size());
return 0;
}
feat(pipeline): add WLCK (Wowee Lock Template) format Novel open replacement for Blizzard's Lock.dbc. The 18th open format added to the editor. Closes the cross-reference gap from WGOT.entry.lockId — until now that field pointed to a format that didn't exist yet. A lock is a multi-channel security check. Each lock has up to 5 independent channels; a player can open the lock by satisfying ANY ONE channel: • Item — requires a specific key item (WIT cross-ref) • Lockpick — requires the lockpicking skill at minimum rank (rogue / engineering profession) • Spell — requires casting a specific spell • Damage — can be forced open with attack damage Cross-references with previously-added formats: WGOT.entry.lockId -> WLCK.entry.lockId WLCK.channel.targetId (Item) -> WIT.entry.itemId WLCK.channel.targetId (Lockpick) -> future WSKL skillId WLCK.channel.targetId (Spell) -> future WSPL spellId The starter and dungeon presets' lockIds (1 and 2) deliberately match WGOT.makeDungeon's iron-door lockId=1 and bandit-strongbox lockId=2, so the demo content stack already wires together: WSPN spawn -> WGOT object template -> WLCK lock template -> WIT key items. Format: • magic "WLCK", version 1, little-endian • per lock: lockId / name / flags / 5 fixed channel slots • per channel: kind / skillRequired / targetId • all 5 slots written even when unused (kind=None + zeroed fields), keeping the per-entry size constant for fast random access Enums: • ChannelKind: None / Item / Lockpick / Spell / Damage • Flags: DestructOnOpen / RespawnOnKey / TrapOnFail API: WoweeLockLoader::save / load / exists / findById; presets makeStarter (Iron Door + Wooden Chest), makeDungeon (matches WGOT cross-references; light/heavy lockpicks + boss-key-only seal), makeProfessions (4-tier rogue lockpick progression at ranks 1/100/175/250). CLI added (5 flags, 521 documented total now): --gen-locks / --gen-locks-dungeon / --gen-locks-professions --info-wlck / --validate-wlck Validator catches: lockId=0 + duplicates, all-None channels (lock can never open), Item/Spell/Lockpick channels with targetId=0 (no resource referenced), unknown channel kind, skillRequired set on non-Lockpick channel (silently ignored at runtime — flag as warning).
2026-05-09 15:44:26 -07:00
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWlckExt(base);
if (!wowee::pipeline::WoweeLockLoader::exists(base)) {
std::fprintf(stderr,
"validate-wlck: WLCK not found: %s.wlck\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeLockLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
idsSeen.reserve(c.entries.size());
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.lockId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.lockId == 0) {
errors.push_back(ctx + ": lockId is 0");
}
// At least one channel must be active or the lock can
// never be opened.
bool anyActive = false;
for (int ci = 0; ci < wowee::pipeline::WoweeLock::kChannelSlots; ++ci) {
const auto& ch = e.channels[ci];
if (ch.kind != wowee::pipeline::WoweeLock::ChannelNone) {
anyActive = true;
}
if (ch.kind > wowee::pipeline::WoweeLock::ChannelDamage) {
errors.push_back(ctx + " slot " + std::to_string(ci) +
": kind " + std::to_string(ch.kind) +
" not in known range 0..4");
}
// Item / Spell / Lockpick channels need a non-zero
// targetId; Damage channels don't.
if ((ch.kind == wowee::pipeline::WoweeLock::ChannelItem ||
ch.kind == wowee::pipeline::WoweeLock::ChannelSpell ||
ch.kind == wowee::pipeline::WoweeLock::ChannelLockpick) &&
ch.targetId == 0) {
errors.push_back(ctx + " slot " + std::to_string(ci) +
": kind requires non-zero targetId");
}
// skillRequired only meaningful for Lockpick — flag
// odd usage on other kinds.
if (ch.kind != wowee::pipeline::WoweeLock::ChannelLockpick &&
ch.kind != wowee::pipeline::WoweeLock::ChannelNone &&
ch.skillRequired != 0) {
warnings.push_back(ctx + " slot " + std::to_string(ci) +
": skillRequired set on non-Lockpick channel (ignored at runtime)");
}
}
if (!anyActive) {
errors.push_back(ctx + ": all 5 channels are None (lock can never open)");
}
for (uint32_t prev : idsSeen) {
if (prev == e.lockId) {
errors.push_back(ctx + ": duplicate lockId");
break;
}
}
idsSeen.push_back(e.lockId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wlck"] = base + ".wlck";
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-wlck: %s.wlck\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu locks, all lockIds unique\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 handleLocksCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-locks") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-locks-dungeon") == 0 && i + 1 < argc) {
outRc = handleGenDungeon(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-locks-professions") == 0 && i + 1 < argc) {
outRc = handleGenProfessions(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wlck") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wlck") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wlck-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wlck-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
feat(pipeline): add WLCK (Wowee Lock Template) format Novel open replacement for Blizzard's Lock.dbc. The 18th open format added to the editor. Closes the cross-reference gap from WGOT.entry.lockId — until now that field pointed to a format that didn't exist yet. A lock is a multi-channel security check. Each lock has up to 5 independent channels; a player can open the lock by satisfying ANY ONE channel: • Item — requires a specific key item (WIT cross-ref) • Lockpick — requires the lockpicking skill at minimum rank (rogue / engineering profession) • Spell — requires casting a specific spell • Damage — can be forced open with attack damage Cross-references with previously-added formats: WGOT.entry.lockId -> WLCK.entry.lockId WLCK.channel.targetId (Item) -> WIT.entry.itemId WLCK.channel.targetId (Lockpick) -> future WSKL skillId WLCK.channel.targetId (Spell) -> future WSPL spellId The starter and dungeon presets' lockIds (1 and 2) deliberately match WGOT.makeDungeon's iron-door lockId=1 and bandit-strongbox lockId=2, so the demo content stack already wires together: WSPN spawn -> WGOT object template -> WLCK lock template -> WIT key items. Format: • magic "WLCK", version 1, little-endian • per lock: lockId / name / flags / 5 fixed channel slots • per channel: kind / skillRequired / targetId • all 5 slots written even when unused (kind=None + zeroed fields), keeping the per-entry size constant for fast random access Enums: • ChannelKind: None / Item / Lockpick / Spell / Damage • Flags: DestructOnOpen / RespawnOnKey / TrapOnFail API: WoweeLockLoader::save / load / exists / findById; presets makeStarter (Iron Door + Wooden Chest), makeDungeon (matches WGOT cross-references; light/heavy lockpicks + boss-key-only seal), makeProfessions (4-tier rogue lockpick progression at ranks 1/100/175/250). CLI added (5 flags, 521 documented total now): --gen-locks / --gen-locks-dungeon / --gen-locks-professions --info-wlck / --validate-wlck Validator catches: lockId=0 + duplicates, all-None channels (lock can never open), Item/Spell/Lockpick channels with targetId=0 (no resource referenced), unknown channel kind, skillRequired set on non-Lockpick channel (silently ignored at runtime — flag as warning).
2026-05-09 15:44:26 -07:00
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee