From 05bb96d23baa002cbcdaa26bda2ca5d5021dd273 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 02:30:32 -0700 Subject: [PATCH] =?UTF-8?q?feat(editor):=20add=20WTRD=20(Trade=20Window=20?= =?UTF-8?q?Rules)=20=E2=80=94=20115th=20open=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Novel replacement for the implicit player-to-player trade policy rules vanilla WoW hardcoded across the trade-window message handlers (CMSG_INITIATE_TRADE, CMSG_SET_TRADE_ITEM, CMSG_SET_TRADE_GOLD), the soulbound-item check, the cross-faction-trade rejection, and the GM-trade audit hooks. Each entry is one trade-policy rule the trade-window state machine consults at every state transition. Seven ruleKind values (Allowed / Forbidden / SoulboundException / CrossFactionAllowed / LevelGated / GoldEscrowMax / AuditLogged) and five targetingFilter values (AnyPlayer / SameRealmOnly / SameFactionOnly / SameAccountOnly / GMOnly) cover the full trade-policy surface. Priority field resolves rule conflicts — higher priority wins (Allowed at 100 overrides Forbidden at 10). Three preset emitters cover real-world deployment patterns: makeStandard (4 baseline rules — Soulbound Forbidden globally, Quest items Forbidden, 2hr Soul- boundException for raid trade-back, SameFactionOnly), makeServerAdmin (3 server-custom overrides — GM-only escrow at priority 100, AccountBound own-character transfer, CrossFactionAllowed at level 80 for RP servers), makeRMTPrevent (4 anti-RMT rules — 10g cap for low-level trades, 500g cap for accounts < 30 days, audit log for trades > 1000g, 24hr first-trade delay). Validator's most novel check is the GoldEscrowMax / goldEscrowMaxCopper consistency rule: a GoldEscrowMax- kind rule MUST specify a non-zero gold cap (zero would mean unlimited which contradicts the rule's purpose). Also warns on GMOnly targeting with priority < 50 (GM- mediated rules typically need high priority to override player-initiated rules) and levelRequirement > 80 (exceeds current cap, rule never applies). Format count 114 -> 115. CLI flag count 1227 -> 1232. --- CMakeLists.txt | 3 + include/pipeline/wowee_trade_rules.hpp | 144 ++++++++++++ src/pipeline/wowee_trade_rules.cpp | 287 +++++++++++++++++++++++ tools/editor/cli_arg_required.cpp | 2 + tools/editor/cli_dispatch.cpp | 2 + tools/editor/cli_format_table.cpp | 1 + tools/editor/cli_help.cpp | 10 + tools/editor/cli_list_formats.cpp | 1 + tools/editor/cli_trade_rules_catalog.cpp | 282 ++++++++++++++++++++++ tools/editor/cli_trade_rules_catalog.hpp | 12 + 10 files changed, 744 insertions(+) create mode 100644 include/pipeline/wowee_trade_rules.hpp create mode 100644 src/pipeline/wowee_trade_rules.cpp create mode 100644 tools/editor/cli_trade_rules_catalog.cpp create mode 100644 tools/editor/cli_trade_rules_catalog.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b6ce952..d1ae5ab3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -703,6 +703,7 @@ set(WOWEE_SOURCES src/pipeline/wowee_movie_credits.cpp src/pipeline/wowee_spell_variants.cpp src/pipeline/wowee_voiceovers.cpp + src/pipeline/wowee_trade_rules.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/dbc_layout.cpp @@ -1569,6 +1570,7 @@ add_executable(wowee_editor tools/editor/cli_movie_credits_catalog.cpp tools/editor/cli_spell_variants_catalog.cpp tools/editor/cli_voiceovers_catalog.cpp + tools/editor/cli_trade_rules_catalog.cpp tools/editor/cli_catalog_pluck.cpp tools/editor/cli_catalog_find.cpp tools/editor/cli_catalog_by_name.cpp @@ -1754,6 +1756,7 @@ add_executable(wowee_editor src/pipeline/wowee_movie_credits.cpp src/pipeline/wowee_spell_variants.cpp src/pipeline/wowee_voiceovers.cpp + src/pipeline/wowee_trade_rules.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/terrain_mesh.cpp diff --git a/include/pipeline/wowee_trade_rules.hpp b/include/pipeline/wowee_trade_rules.hpp new file mode 100644 index 00000000..9fe59379 --- /dev/null +++ b/include/pipeline/wowee_trade_rules.hpp @@ -0,0 +1,144 @@ +#pragma once + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +// Wowee Open Trade Window Rules catalog (.wtrd) — +// novel replacement for the implicit player-to-player +// trade policy rules vanilla WoW hardcoded across the +// trade-window message handlers (CMSG_INITIATE_TRADE, +// CMSG_SET_TRADE_ITEM, CMSG_SET_TRADE_GOLD), the +// soulbound-item check, the cross-faction-trade +// rejection, and the GM-trade audit hooks. Each entry +// is one trade policy rule the trade-window state +// machine consults at every state transition. +// +// Cross-references with previously-added formats: +// WIT: itemCategoryFilter uses the WIT item-class +// + subclass bit conventions (Weapon=2, +// Armor=4, Container=1, etc.). +// WCHC: targetingFilter uses the WCHC faction-bit +// convention for SameFactionOnly. +// +// Binary layout (little-endian): +// magic[4] = "WTRD" +// version (uint32) = current 1 +// nameLen + name (catalog label) +// entryCount (uint32) +// entries (each): +// ruleId (uint32) +// nameLen + name +// descLen + description +// ruleKind (uint8) — Allowed / Forbidden / +// SoulboundException / +// CrossFactionAllowed / +// LevelGated / +// GoldEscrowMax / +// AuditLogged +// targetingFilter (uint8) — AnyPlayer / +// SameRealmOnly / +// SameFactionOnly / +// SameAccountOnly / +// GMOnly +// levelRequirement (uint8) — 0 = no level gate +// priority (uint8) — higher overrides +// lower in conflict +// itemCategoryFilter (uint32) — bitmask of +// WIT item classes +// goldEscrowMaxCopper (uint64) — max gold side for +// this rule (0 = +// unlimited) +// iconColorRGBA (uint32) +struct WoweeTradeRules { + enum RuleKind : uint8_t { + Allowed = 0, // explicitly allow + // (highest-priority + // override) + Forbidden = 1, // block trade if + // category bits + // match + SoulboundException = 2, // 2hr trade-back + // window post-loot + CrossFactionAllowed = 3, // server-custom + // override of base + // same-faction rule + LevelGated = 4, // require both + // players >= + // levelRequirement + GoldEscrowMax = 5, // cap gold side at + // goldEscrowMaxCopper + AuditLogged = 6, // log every trade + // matching this rule + }; + + enum TargetingFilter : uint8_t { + AnyPlayer = 0, + SameRealmOnly = 1, + SameFactionOnly = 2, + SameAccountOnly = 3, // own-character transfer + GMOnly = 4, // requires GM flag on + // initiator + }; + + struct Entry { + uint32_t ruleId = 0; + std::string name; + std::string description; + uint8_t ruleKind = Forbidden; + uint8_t targetingFilter = AnyPlayer; + uint8_t levelRequirement = 0; + uint8_t priority = 1; + uint32_t itemCategoryFilter = 0; + uint64_t goldEscrowMaxCopper = 0; + uint32_t iconColorRGBA = 0xFFFFFFFFu; + }; + + std::string name; + std::vector entries; + + bool isValid() const { return !entries.empty(); } + + const Entry* findById(uint32_t ruleId) const; + + // Returns all rules of one kind (e.g. all Forbidden + // rules to enumerate the explicit blocks). Used by + // the trade-window state machine to dispatch checks + // by kind. + std::vector findByKind(uint8_t ruleKind) const; +}; + +class WoweeTradeRulesLoader { +public: + static bool save(const WoweeTradeRules& cat, + const std::string& basePath); + static WoweeTradeRules load(const std::string& basePath); + static bool exists(const std::string& basePath); + + // Preset emitters used by --gen-trd* variants. + // + // makeStandard — 4 standard trade rules + // (Soulbound Forbidden globally, + // Quest items Forbidden, 2hr + // SoulboundException for raid + // drops, SameFactionOnly default). + // makeServerAdmin — 3 server-admin rules (GM-only + // escrow trade, AccountBound + // own-character transfer, Cross- + // faction at level 80 for custom + // servers). + // makeRMTPrevent — 4 anti-RMT rules (LevelGated 30+ + // for any gold trade, Gold cap for + // new accounts, AuditLogged for + // all trades > 1000g, mandatory + // delay placeholder). + static WoweeTradeRules makeStandard(const std::string& catalogName); + static WoweeTradeRules makeServerAdmin(const std::string& catalogName); + static WoweeTradeRules makeRMTPrevent(const std::string& catalogName); +}; + +} // namespace pipeline +} // namespace wowee diff --git a/src/pipeline/wowee_trade_rules.cpp b/src/pipeline/wowee_trade_rules.cpp new file mode 100644 index 00000000..f2045811 --- /dev/null +++ b/src/pipeline/wowee_trade_rules.cpp @@ -0,0 +1,287 @@ +#include "pipeline/wowee_trade_rules.hpp" + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +namespace { + +constexpr char kMagic[4] = {'W', 'T', 'R', 'D'}; +constexpr uint32_t kVersion = 1; + +template +void writePOD(std::ofstream& os, const T& v) { + os.write(reinterpret_cast(&v), sizeof(T)); +} + +template +bool readPOD(std::ifstream& is, T& v) { + is.read(reinterpret_cast(&v), sizeof(T)); + return is.gcount() == static_cast(sizeof(T)); +} + +void writeStr(std::ofstream& os, const std::string& s) { + uint32_t n = static_cast(s.size()); + writePOD(os, n); + if (n > 0) os.write(s.data(), n); +} + +bool readStr(std::ifstream& is, std::string& s) { + uint32_t n = 0; + if (!readPOD(is, n)) return false; + if (n > (1u << 20)) return false; + s.resize(n); + if (n > 0) { + is.read(s.data(), n); + if (is.gcount() != static_cast(n)) { + s.clear(); + return false; + } + } + return true; +} + +std::string normalizePath(std::string base) { + if (base.size() < 5 || base.substr(base.size() - 5) != ".wtrd") { + base += ".wtrd"; + } + return base; +} + +uint32_t packRgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) { + return (static_cast(a) << 24) | + (static_cast(b) << 16) | + (static_cast(g) << 8) | + static_cast(r); +} + +} // namespace + +const WoweeTradeRules::Entry* +WoweeTradeRules::findById(uint32_t ruleId) const { + for (const auto& e : entries) + if (e.ruleId == ruleId) return &e; + return nullptr; +} + +std::vector +WoweeTradeRules::findByKind(uint8_t ruleKind) const { + std::vector out; + for (const auto& e : entries) + if (e.ruleKind == ruleKind) out.push_back(&e); + return out; +} + +bool WoweeTradeRulesLoader::save(const WoweeTradeRules& cat, + const std::string& basePath) { + std::ofstream os(normalizePath(basePath), std::ios::binary); + if (!os) return false; + os.write(kMagic, 4); + writePOD(os, kVersion); + writeStr(os, cat.name); + uint32_t entryCount = static_cast(cat.entries.size()); + writePOD(os, entryCount); + for (const auto& e : cat.entries) { + writePOD(os, e.ruleId); + writeStr(os, e.name); + writeStr(os, e.description); + writePOD(os, e.ruleKind); + writePOD(os, e.targetingFilter); + writePOD(os, e.levelRequirement); + writePOD(os, e.priority); + writePOD(os, e.itemCategoryFilter); + writePOD(os, e.goldEscrowMaxCopper); + writePOD(os, e.iconColorRGBA); + } + return os.good(); +} + +WoweeTradeRules WoweeTradeRulesLoader::load( + const std::string& basePath) { + WoweeTradeRules out; + std::ifstream is(normalizePath(basePath), std::ios::binary); + if (!is) return out; + char magic[4]; + is.read(magic, 4); + if (std::memcmp(magic, kMagic, 4) != 0) return out; + uint32_t version = 0; + if (!readPOD(is, version) || version != kVersion) return out; + if (!readStr(is, out.name)) return out; + uint32_t entryCount = 0; + if (!readPOD(is, entryCount)) return out; + if (entryCount > (1u << 20)) return out; + out.entries.resize(entryCount); + for (auto& e : out.entries) { + if (!readPOD(is, e.ruleId)) { + out.entries.clear(); return out; + } + if (!readStr(is, e.name) || !readStr(is, e.description)) { + out.entries.clear(); return out; + } + if (!readPOD(is, e.ruleKind) || + !readPOD(is, e.targetingFilter) || + !readPOD(is, e.levelRequirement) || + !readPOD(is, e.priority) || + !readPOD(is, e.itemCategoryFilter) || + !readPOD(is, e.goldEscrowMaxCopper) || + !readPOD(is, e.iconColorRGBA)) { + out.entries.clear(); return out; + } + } + return out; +} + +bool WoweeTradeRulesLoader::exists(const std::string& basePath) { + std::ifstream is(normalizePath(basePath), std::ios::binary); + return is.good(); +} + +WoweeTradeRules WoweeTradeRulesLoader::makeStandard( + const std::string& catalogName) { + using T = WoweeTradeRules; + WoweeTradeRules c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, + uint8_t kind, uint8_t targeting, + uint8_t levelReq, uint8_t prio, + uint32_t catFilter, + uint64_t goldMax, const char* desc) { + T::Entry e; + e.ruleId = id; e.name = name; e.description = desc; + e.ruleKind = kind; + e.targetingFilter = targeting; + e.levelRequirement = levelReq; + e.priority = prio; + e.itemCategoryFilter = catFilter; + e.goldEscrowMaxCopper = goldMax; + e.iconColorRGBA = packRgba(140, 200, 255); // standard blue + c.entries.push_back(e); + }; + // itemClass bits: 0=Consumable, 1=Container, 2=Weapon, + // 3=Gem, 4=Armor, 5=Reagent, 7=Projectile, 9=Recipe, + // 12=Quest, 15=Misc. + add(1, "SoulboundForbidden", T::Forbidden, T::AnyPlayer, + 0, 10, 0xFFFFFFFFu, 0, + "Globally forbid trading soulbound items " + "(itemCategoryFilter=0xFFFFFFFF means all " + "categories). Priority 10 — base default rule."); + add(2, "QuestItemForbidden", T::Forbidden, T::AnyPlayer, + 0, 10, 1u << 12, 0, + "Forbid quest items (itemClass=12). Priority " + "10 — base default. Quest items are inventory-" + "frozen by design."); + add(3, "RaidTradeBackException", T::SoulboundException, + T::SameRealmOnly, + 0, 20, 0, 0, + "2-hour trade-back window for raid loot — " + "overrides the SoulboundForbidden rule when " + "the soulbind happened within 2hr to allow " + "loot redistribution to absent players. " + "Priority 20 — overrides rule 1."); + add(4, "SameFactionOnly", T::Forbidden, T::SameFactionOnly, + 0, 5, 0, 0, + "Default cross-faction trade restriction — " + "Alliance and Horde players cannot initiate " + "trades. Priority 5 — low so server-custom " + "CrossFactionAllowed can override."); + return c; +} + +WoweeTradeRules WoweeTradeRulesLoader::makeServerAdmin( + const std::string& catalogName) { + using T = WoweeTradeRules; + WoweeTradeRules c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, + uint8_t kind, uint8_t targeting, + uint8_t levelReq, uint8_t prio, + uint64_t goldMax, const char* desc) { + T::Entry e; + e.ruleId = id; e.name = name; e.description = desc; + e.ruleKind = kind; + e.targetingFilter = targeting; + e.levelRequirement = levelReq; + e.priority = prio; + e.itemCategoryFilter = 0; + e.goldEscrowMaxCopper = goldMax; + e.iconColorRGBA = packRgba(220, 60, 60); // GM red + c.entries.push_back(e); + }; + add(100, "GMEscrowTrade", T::Allowed, T::GMOnly, + 0, 100, 0, + "GM-only trade with no item/gold restriction " + "for staff-mediated player disputes. Priority " + "100 — overrides all other rules."); + add(101, "AccountBoundOwnTransfer", T::Allowed, + T::SameAccountOnly, + 0, 90, 0, + "Allow trading account-bound items between own " + "characters via a cross-realm trade window. " + "Priority 90 — overrides Soulbound default."); + add(102, "CrossFactionAt80", T::CrossFactionAllowed, + T::AnyPlayer, + 80, 50, 0, + "Allow cross-faction trades at level 80+ for " + "server-custom RP servers. Overrides the " + "default SameFactionOnly Forbidden rule for " + "max-level players. Priority 50."); + return c; +} + +WoweeTradeRules WoweeTradeRulesLoader::makeRMTPrevent( + const std::string& catalogName) { + using T = WoweeTradeRules; + WoweeTradeRules c; + c.name = catalogName; + auto add = [&](uint32_t id, const char* name, + uint8_t kind, uint8_t targeting, + uint8_t levelReq, uint8_t prio, + uint64_t goldMax, const char* desc) { + T::Entry e; + e.ruleId = id; e.name = name; e.description = desc; + e.ruleKind = kind; + e.targetingFilter = targeting; + e.levelRequirement = levelReq; + e.priority = prio; + e.itemCategoryFilter = 0; + e.goldEscrowMaxCopper = goldMax; + e.iconColorRGBA = packRgba(220, 200, 80); // anti-RMT yellow + c.entries.push_back(e); + }; + // costCopper: 1g = 10000 copper, 1000g = 10,000,000. + add(200, "LowLevelGoldCap", T::GoldEscrowMax, + T::AnyPlayer, + 0, 30, 100000, + "Cap gold side at 10g for level <30 trades — " + "anti-RMT (gold-buying typically targets fresh " + "accounts). Priority 30. levelRequirement=0 " + "but the rule is meant to apply to LOW levels; " + "the trade engine inverts this check at runtime."); + add(201, "NewAccountValueCap", T::GoldEscrowMax, + T::AnyPlayer, + 30, 25, 5000000, + "Cap gold side at 500g for level 30+ trades on " + "accounts < 30 days old. Stops mid-tier RMT " + "transfers. Priority 25."); + add(202, "HighValueAuditLog", T::AuditLogged, + T::AnyPlayer, + 0, 15, 10000000, + "Log all trades with gold side > 1000g for " + "audit review. Doesn't block; just records. " + "Priority 15. Server admins can run " + "anti-RMT analytics on the log."); + add(203, "FirstTradeMandatoryDelay", T::Forbidden, + T::AnyPlayer, + 0, 10, 0, + "Block first trade for accounts < 24hr old. " + "Manual placeholder rule — the trade engine " + "enforces the time check externally. " + "Priority 10."); + return c; +} + +} // namespace pipeline +} // namespace wowee diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 1b4f0ff1..fdba3263 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -353,6 +353,8 @@ const char* const kArgRequired[] = { "--gen-vox", "--gen-vox-boss", "--gen-vox-vendor", "--info-wvox", "--validate-wvox", "--export-wvox-json", "--import-wvox-json", + "--gen-trd", "--gen-trd-admin", "--gen-trd-rmt", + "--info-wtrd", "--validate-wtrd", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_dispatch.cpp b/tools/editor/cli_dispatch.cpp index c898b536..7df54e9e 100644 --- a/tools/editor/cli_dispatch.cpp +++ b/tools/editor/cli_dispatch.cpp @@ -159,6 +159,7 @@ #include "cli_movie_credits_catalog.hpp" #include "cli_spell_variants_catalog.hpp" #include "cli_voiceovers_catalog.hpp" +#include "cli_trade_rules_catalog.hpp" #include "cli_catalog_pluck.hpp" #include "cli_catalog_find.hpp" #include "cli_catalog_by_name.hpp" @@ -363,6 +364,7 @@ constexpr DispatchFn kDispatchTable[] = { handleMovieCreditsCatalog, handleSpellVariantsCatalog, handleVoiceoversCatalog, + handleTradeRulesCatalog, handleCatalogPluck, handleCatalogFind, handleCatalogByName, diff --git a/tools/editor/cli_format_table.cpp b/tools/editor/cli_format_table.cpp index 493df265..d0fd006f 100644 --- a/tools/editor/cli_format_table.cpp +++ b/tools/editor/cli_format_table.cpp @@ -117,6 +117,7 @@ constexpr FormatMagicEntry kFormats[] = { {{'W','M','V','C'}, ".wmvc", "cinematic", "--info-wmvc", "Movie credits roll catalog"}, {{'W','S','P','V'}, ".wspv", "spells", "--info-wspv", "Spell variant catalog"}, {{'W','V','O','X'}, ".wvox", "audio", "--info-wvox", "Voiceover audio catalog"}, + {{'W','T','R','D'}, ".wtrd", "social", "--info-wtrd", "Trade window rules catalog"}, {{'W','F','A','C'}, ".wfac", "factions", nullptr, "Faction catalog"}, {{'W','L','C','K'}, ".wlck", "locks", nullptr, "Lock catalog"}, {{'W','S','K','L'}, ".wskl", "skills", nullptr, "Skill catalog"}, diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 7e25d65d..1f9c69c0 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2363,6 +2363,16 @@ void printUsage(const char* argv0) { std::printf(" Export binary .wvox to a human-editable JSON sidecar (defaults to .wvox.json; emits eventKind and genderHint as both int AND name string; transcript as plain string for accessibility editing)\n"); std::printf(" --import-wvox-json [out-base]\n"); std::printf(" Import a .wvox.json sidecar back into binary .wvox (eventKind int OR \"greeting\"/\"aggro\"/\"death\"/\"queststart\"/\"questprogress\"/\"questcomplete\"/\"goodbye\"/\"special\"/\"phase\"; genderHint int OR \"male\"/\"female\"/\"both\"; volumeDb is signed int8)\n"); + std::printf(" --gen-trd [name]\n"); + std::printf(" Emit .wtrd 4 standard trade rules (Soulbound Forbidden / Quest items Forbidden / 2hr SoulboundException for raid drops / SameFactionOnly default)\n"); + std::printf(" --gen-trd-admin [name]\n"); + std::printf(" Emit .wtrd 3 server-admin trade rules (GM-only escrow / AccountBound own-character transfer / CrossFactionAllowed at level 80 for custom servers)\n"); + std::printf(" --gen-trd-rmt [name]\n"); + std::printf(" Emit .wtrd 4 anti-RMT trade rules (LowLevelGoldCap 10g / NewAccountValueCap 500g for accounts <30 days / HighValueAuditLog for trades >1000g / FirstTradeMandatoryDelay 24hr)\n"); + std::printf(" --info-wtrd [--json]\n"); + std::printf(" Print WTRD entries (id / ruleKind / targetingFilter / level requirement / priority / category bitmask / gold cap / name)\n"); + std::printf(" --validate-wtrd [--json]\n"); + std::printf(" Static checks: id+name required, ruleKind 0..6, targetingFilter 0..4, no duplicate ruleIds, GoldEscrowMax kind requires goldEscrowMaxCopper > 0 (else self-contradicting); warns on levelRequirement > 80 (exceeds cap), GMOnly targeting with priority < 50 (would be overridden by player rules)\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"); diff --git a/tools/editor/cli_list_formats.cpp b/tools/editor/cli_list_formats.cpp index 904ec622..93b24927 100644 --- a/tools/editor/cli_list_formats.cpp +++ b/tools/editor/cli_list_formats.cpp @@ -139,6 +139,7 @@ constexpr FormatRow kFormats[] = { {"WMVC", ".wmvc", "cinematic", "embedded cinematic credit-roll blob","Movie credits roll catalog (per-cinematic)"}, {"WSPV", ".wspv", "spells", "implicit Spell.dbc context overrides","Spell variant catalog (stance/talent/racial substitution)"}, {"WVOX", ".wvox", "audio", "CreatureTextSounds + per-quest voice","Voiceover audio catalog (per-NPC, per-event clips)"}, + {"WTRD", ".wtrd", "social", "trade-window state machine policy", "Trade window rules catalog (P2P trade policy)"}, // Additional pipeline catalogs without the alternating // gen/info/validate CLI surface (loaded by the engine diff --git a/tools/editor/cli_trade_rules_catalog.cpp b/tools/editor/cli_trade_rules_catalog.cpp new file mode 100644 index 00000000..5e2f30f4 --- /dev/null +++ b/tools/editor/cli_trade_rules_catalog.cpp @@ -0,0 +1,282 @@ +#include "cli_trade_rules_catalog.hpp" +#include "cli_arg_parse.hpp" +#include "cli_box_emitter.hpp" + +#include "pipeline/wowee_trade_rules.hpp" +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace wowee { +namespace editor { +namespace cli { + +namespace { + +std::string stripWtrdExt(std::string base) { + stripExt(base, ".wtrd"); + return base; +} + +const char* ruleKindName(uint8_t k) { + using T = wowee::pipeline::WoweeTradeRules; + switch (k) { + case T::Allowed: return "allowed"; + case T::Forbidden: return "forbidden"; + case T::SoulboundException: return "soulboundexception"; + case T::CrossFactionAllowed: return "crossfactionallowed"; + case T::LevelGated: return "levelgated"; + case T::GoldEscrowMax: return "goldescrowmax"; + case T::AuditLogged: return "auditlogged"; + default: return "unknown"; + } +} + +const char* targetingFilterName(uint8_t t) { + using T = wowee::pipeline::WoweeTradeRules; + switch (t) { + case T::AnyPlayer: return "anyplayer"; + case T::SameRealmOnly: return "samerealmonly"; + case T::SameFactionOnly: return "samefactiononly"; + case T::SameAccountOnly: return "sameaccountonly"; + case T::GMOnly: return "gmonly"; + default: return "unknown"; + } +} + +bool saveOrError(const wowee::pipeline::WoweeTradeRules& c, + const std::string& base, const char* cmd) { + if (!wowee::pipeline::WoweeTradeRulesLoader::save(c, base)) { + std::fprintf(stderr, "%s: failed to save %s.wtrd\n", + cmd, base.c_str()); + return false; + } + return true; +} + +void printGenSummary(const wowee::pipeline::WoweeTradeRules& c, + const std::string& base) { + std::printf("Wrote %s.wtrd\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" rules : %zu\n", c.entries.size()); +} + +int handleGenStandard(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "StandardTradeRules"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrdExt(base); + auto c = wowee::pipeline::WoweeTradeRulesLoader::makeStandard(name); + if (!saveOrError(c, base, "gen-trd")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenServerAdmin(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "ServerAdminTradeRules"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrdExt(base); + auto c = wowee::pipeline::WoweeTradeRulesLoader::makeServerAdmin(name); + if (!saveOrError(c, base, "gen-trd-admin")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenRMT(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "AntiRMTTradeRules"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrdExt(base); + auto c = wowee::pipeline::WoweeTradeRulesLoader::makeRMTPrevent(name); + if (!saveOrError(c, base, "gen-trd-rmt")) 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 = stripWtrdExt(base); + if (!wowee::pipeline::WoweeTradeRulesLoader::exists(base)) { + std::fprintf(stderr, "WTRD not found: %s.wtrd\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeTradeRulesLoader::load(base); + if (jsonOut) { + nlohmann::json j; + j["wtrd"] = base + ".wtrd"; + j["name"] = c.name; + j["count"] = c.entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"ruleId", e.ruleId}, + {"name", e.name}, + {"description", e.description}, + {"ruleKind", e.ruleKind}, + {"ruleKindName", ruleKindName(e.ruleKind)}, + {"targetingFilter", e.targetingFilter}, + {"targetingFilterName", + targetingFilterName(e.targetingFilter)}, + {"levelRequirement", e.levelRequirement}, + {"priority", e.priority}, + {"itemCategoryFilter", e.itemCategoryFilter}, + {"goldEscrowMaxCopper", e.goldEscrowMaxCopper}, + {"iconColorRGBA", e.iconColorRGBA}, + }); + } + j["entries"] = arr; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("WTRD: %s.wtrd\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" rules : %zu\n", c.entries.size()); + if (c.entries.empty()) return 0; + std::printf(" id kind targeting lvlReq prio catFilter goldMax(c) name\n"); + for (const auto& e : c.entries) { + std::printf(" %4u %-19s %-15s %3u %3u 0x%08X %12llu %s\n", + e.ruleId, + ruleKindName(e.ruleKind), + targetingFilterName(e.targetingFilter), + e.levelRequirement, e.priority, + e.itemCategoryFilter, + (unsigned long long)e.goldEscrowMaxCopper, + e.name.c_str()); + } + return 0; +} + +int handleValidate(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWtrdExt(base); + if (!wowee::pipeline::WoweeTradeRulesLoader::exists(base)) { + std::fprintf(stderr, + "validate-wtrd: WTRD not found: %s.wtrd\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeTradeRulesLoader::load(base); + std::vector errors; + std::vector warnings; + if (c.entries.empty()) { + warnings.push_back("catalog has zero entries"); + } + std::set idsSeen; + 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.ruleId); + if (!e.name.empty()) ctx += " " + e.name; + ctx += ")"; + if (e.ruleId == 0) + errors.push_back(ctx + ": ruleId is 0"); + if (e.name.empty()) + errors.push_back(ctx + ": name is empty"); + if (e.ruleKind > 6) { + errors.push_back(ctx + ": ruleKind " + + std::to_string(e.ruleKind) + + " out of range (must be 0..6)"); + } + if (e.targetingFilter > 4) { + errors.push_back(ctx + ": targetingFilter " + + std::to_string(e.targetingFilter) + + " out of range (must be 0..4)"); + } + if (e.levelRequirement > 80) { + warnings.push_back(ctx + ": levelRequirement " + + std::to_string(e.levelRequirement) + + " > 80 — exceeds current cap, the rule " + "would never apply on a WotLK realm"); + } + // Per-kind validity: GoldEscrowMax must specify + // a non-zero gold cap to be meaningful (zero + // would mean unlimited which contradicts the + // rule's purpose). + using T = wowee::pipeline::WoweeTradeRules; + if (e.ruleKind == T::GoldEscrowMax && + e.goldEscrowMaxCopper == 0) { + errors.push_back(ctx + + ": GoldEscrowMax kind with goldEscrow" + "MaxCopper=0 — rule contradicts itself " + "(0 means unlimited but the rule's " + "purpose is to cap)"); + } + // GMOnly rules with low priority would be useless + // (can't be triggered without GM intervention). + if (e.targetingFilter == T::GMOnly && + e.priority < 50) { + warnings.push_back(ctx + + ": GMOnly targeting with priority " + + std::to_string(e.priority) + + " < 50 — GM-mediated trades typically " + "need high priority to override player-" + "initiated rules"); + } + if (!idsSeen.insert(e.ruleId).second) { + errors.push_back(ctx + ": duplicate ruleId"); + } + } + bool ok = errors.empty(); + if (jsonOut) { + nlohmann::json j; + j["wtrd"] = base + ".wtrd"; + 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-wtrd: %s.wtrd\n", base.c_str()); + if (ok && warnings.empty()) { + std::printf(" OK — %zu rules, all ruleIds unique, " + "per-kind constraints satisfied\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 handleTradeRulesCatalog(int& i, int argc, char** argv, + int& outRc) { + if (std::strcmp(argv[i], "--gen-trd") == 0 && i + 1 < argc) { + outRc = handleGenStandard(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-trd-admin") == 0 && i + 1 < argc) { + outRc = handleGenServerAdmin(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-trd-rmt") == 0 && i + 1 < argc) { + outRc = handleGenRMT(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--info-wtrd") == 0 && i + 1 < argc) { + outRc = handleInfo(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--validate-wtrd") == 0 && i + 1 < argc) { + outRc = handleValidate(i, argc, argv); return true; + } + return false; +} + +} // namespace cli +} // namespace editor +} // namespace wowee diff --git a/tools/editor/cli_trade_rules_catalog.hpp b/tools/editor/cli_trade_rules_catalog.hpp new file mode 100644 index 00000000..6d9e820c --- /dev/null +++ b/tools/editor/cli_trade_rules_catalog.hpp @@ -0,0 +1,12 @@ +#pragma once + +namespace wowee { +namespace editor { +namespace cli { + +bool handleTradeRulesCatalog(int& i, int argc, char** argv, + int& outRc); + +} // namespace cli +} // namespace editor +} // namespace wowee