using System.Globalization; using System.Security.Cryptography; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; /// Typed desktop editing. Never authenticates by borrowing a game's nonce. public sealed partial class AccountEditor(ItemCatalog catalog, TimeProvider clock, ServerOptions options) { private static readonly string[] Categories = [.. Inventory.EquipmentKeys, .. Inventory.CountedKeys, "Upgrades", "QuestKeys", "Boosters", "EvolutionProgress", "FlavourItems", "WeaponSkins"]; private static readonly IReadOnlyDictionary Labels = new Dictionary { ["Suits"] = "战甲", ["SpaceSuits"] = "Archwing", ["Sentinels"] = "守护", ["LongGuns"] = "主武器", ["Pistols"] = "副武器", ["Melee"] = "近战武器", ["SpaceGuns"] = "Archwing 枪械", ["SpaceMelee"] = "Archwing 近战", ["SentinelWeapons"] = "守护武器", ["Hoverboards"] = "K 驱悬浮板", ["OperatorAmps"] = "指挥官增幅器", ["MechSuits"] = "殁世机甲", ["MoaPets"] = "机械伙伴", ["KubrowPets"] = "动物伙伴", ["Upgrades"] = "已升级 MOD 与紫卡", ["RawUpgrades"] = "未升级 MOD", ["QuestKeys"] = "系列任务", ["Boosters"] = "加成", ["EvolutionProgress"] = "灵化进度" }; private static readonly Lazy AccountSettings = new(() => (JArray)Assets.Json("editor/settings.json")["groups"]!["account"]!); private static readonly string[] Cleanup = ["alertsRepeatable", "syndicateMissionsRepeatable", "noVendorPurchaseLimits", "noDeathMarks", "noNemesis", "noMasteryRankUpCooldown", "noBlessingCooldown", "noKimCooldowns"]; public JObject Read(JObject state, JObject account, ApiRequest request) { catalog = catalog.WithLanguage(request.Q("lang")); var category = request.Q("category") ?? "Suits"; if (!Categories.Contains(category) && !GuildCategories.ContainsKey(category) && category is not ("settings" or "progress" or "templates")) throw new ApiException(400, "不支持的编辑分类。"); var inv = account.Obj("Inventory"); var result = new JObject { ["version"] = Version(state, account), ["category"] = category, ["canImport"] = true, ["canExport"] = true, ["categories"] = new JArray(Categories.Select(x => new JObject { ["key"] = x, ["label"] = Labels.GetValueOrDefault(x, x) }).Concat([ new JObject { ["key"] = "settings", ["label"] = "账号规则" }, new JObject { ["key"] = "progress", ["label"] = "解锁与进度" }, new JObject { ["key"] = "templates", ["label"] = "存档模板" }])) }; foreach (var group in GuildCategories) result.Array("categories").Add(new JObject { ["key"] = group.Key, ["label"] = group.Value }); if (GuildCategories.ContainsKey(category)) return ReadGuild(state, account, request, result); if (category == "settings") { var fields = (JArray)AccountSettings.Value.DeepClone(); foreach (var field in fields.OfType()) { var fieldKey = field.RequiredString("key"); field["value"] = inv[fieldKey] ?? (field.Value("type") == "bool" ? new JValue(false) : new JValue(fieldKey.Contains("Multiplier", StringComparison.Ordinal) ? 1 : field.Value("min") ?? 0)); } result["fields"] = fields; result["items"] = new JArray(); result["total"] = 0; return result; } if (category == "progress") { result["actions"] = ProgressActions(inv); result["items"] = new JArray(); result["total"] = 0; return result; } if (category == "templates") { result["actions"] = TemplateActions(); result["items"] = new JArray(); result["total"] = 0; return result; } var query = (request.Q("q") ?? "").Trim(); if (query.Length > 200) throw new ApiException(400, "搜索文字过长。"); var entries = inv.Array(category).Select(AsItem).Select(x => new { Item = x, Name = Name(x) }) .Where(x => x.Name.Contains(query, StringComparison.OrdinalIgnoreCase) || (x.Item.Value("ItemType") ?? "").Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(); var skip = int.TryParse(request.Q("skip"), out var offset) && offset >= 0 ? offset : 0; result["total"] = entries.Length; result["batchActions"] = BatchActions(category, inv); result["actions"] = CreationActions(category, inv); if (category == "QuestKeys") result["creationActions"] = result["actions"]!.DeepClone(); result["items"] = new JArray(entries.Skip(skip).Take(40).Select(x => new JObject { ["key"] = Key(x.Item), ["name"] = x.Name, ["type"] = x.Item["ItemType"], ["editActions"] = new JArray(Actions(category, x.Item, inv).Select(a => a.Value("key"))), ["canEdit"] = true, ["presentation"] = catalog.Presentation(x.Item.Value("ItemType") ?? ""), ["quest"] = category == "QuestKeys" ? QuestSummary(x.Item, inv) : null, ["detail"] = category == "Boosters" ? "到期 " + x.Item["ExpiryDate"] : category == "QuestKeys" ? QuestSummary(x.Item, inv).Value("label") : $"经验 {x.Item.Value("XP"):N0} · 数量 {x.Item.Value("ItemCount") ?? 1:N0}" })); if (request.Q("item") is string key && inv.Array(category).Select(AsItem).FirstOrDefault(x => Key(x) == key) is JObject item) { result["selectedKey"] = key; result["selectedName"] = Name(item); result["actions"] = Actions(category, item, inv); result["summary"] = category == "Suits" ? SuitSummary(item) : Name(item); if (category == "Suits") result["relatedEquipment"] = RelatedWeapons(item, inv); if (HasModding(category, item)) result["modding"] = ModdingView(category, item, inv); if (category == "Upgrades" && item.Value("ItemType")?.StartsWith(RivenCalculator.Prefix, StringComparison.Ordinal) == true) result["riven"] = item.DeepClone(); } return result; } private static JObject QuestSummary(JObject item, JObject inventory) { var progress = item["Progress"] as JArray ?? []; var run = progress.FirstOrDefault()?.Value("c") ?? 0; var stage = run == 0 ? progress.Count : progress.Select(x => x.Value("c") ?? 0).ToList().LastIndexOf(run); var completed = item.Value("Completed"); var active = inventory.Value("ActiveQuest") == item.Value("ItemType"); // Match the original frontend: c is the zero-based run; its displayed replays value is c + 1. var replays = run > 0 ? run + 1 : 0; return new JObject { ["completed"] = completed, ["stage"] = stage, ["replays"] = replays, ["active"] = active, ["label"] = string.Join(" · ", new[] { completed ? "已完成" : $"阶段 {stage}", replays > 0 ? $"重玩 {replays}" : "", active ? "进行中" : "" }.Where(x => x.Length > 0)) }; } public JObject Apply(JObject state, JObject account, JObject body) { if (!Wire.SecretEquals(body.RequiredString("version", 64), Version(state, account))) throw new ApiException(409, "存档已在其他位置更新。请刷新后重新编辑。"); var action = body.RequiredString("action", 100); var values = body["values"] as JObject ?? new(); var inv = account.Obj("Inventory"); if (action == "syndicate") { var syndicateForm = ProgressActions(inv).OfType().First(x => x.Value("key") == "syndicate"); ValidateFields(syndicateForm, values); inv["SupportedSyndicate"] = values["type"]!.DeepClone(); return Done(); } if (action == "settings") { if (values.Count is < 1 or > 63) throw new ApiException(400, "请选择需要修改的设置。"); var cleanup = new JArray(); foreach (var field in values.Properties()) { var schema = AccountSettings.Value.OfType().FirstOrDefault(x => x.Value("key") == field.Name) ?? throw new ApiException(400, "未知账号设置。"); Validate(schema, field.Value); var response = Custom("setAccountCheat", new JObject { ["key"] = field.Name, ["value"] = field.Value.DeepClone() }); if (response.Body == "retroactivable") cleanup.Add(field.Name); } return new JObject { ["version"] = Version(state, account), ["cleanup"] = cleanup }; } if (action == "cleanup") { var key = values.RequiredString("key"); if (!Cleanup.Contains(key) || !inv.Value(key)) throw new ApiException(400, "该规则当前不能追溯应用。"); Custom("retroactivelyApplyCheat", query: new() { ["cheat"] = key }); return Done(); } if (ProgressRoutes.TryGetValue(action, out var progress)) { Custom(progress, query: action == "unlock.normalMissions" ? new() { ["normalOnly"] = "1" } : null); return Done(); } if (action == "unlock.focus") { var focus = new FocusApi(); foreach (var school in new[] { "Attack", "Defense", "Tactic", "Power", "Ward" }) { var type = $"/Lotus/Upgrades/Focus/{school}/{school}FocusAbility"; if (inv.Array("FocusUpgrades").Any(x => x.Value("ItemType") == type)) continue; focus.Handle(account, Request("/api/focus.php", new JObject { ["FocusType"] = JValue.CreateNull() }, new() { ["op"] = "ActivateWay" })); focus.Handle(account, Request("/api/focus.php", new JObject { ["FocusType"] = type }, new() { ["op"] = "UnlockWay" })); } return Done(); } if (action == "unlock.helminth") { new HelminthApi(clock).Handle(account, Request("/api/infestedFoundry.php", query: new() { ["mode"] = "custom_unlockall" })); return Done(); } if (ApplyExtended(state, account, body, action, values)) return Done(); if (action.StartsWith("guild.", StringComparison.Ordinal)) { ApplyGuild(state, account, body, action, values); return Done(); } var category = body.RequiredString("category", 60); if (!Categories.Contains(category)) throw new ApiException(400, "不支持的编辑分类。"); if (action.StartsWith("create.", StringComparison.Ordinal)) { CreateItem(account, category, action, values); return Done(); } if (action.StartsWith("batch.", StringComparison.Ordinal)) { ApplyBatch(account, category, action); return Done(); } var keyValue = body.RequiredString("item", 1024); var item = inv.Array(category).Select(AsItem).FirstOrDefault(x => Key(x) == keyValue) ?? throw new ApiException(404, "该物品已不存在。"); var descriptor = Actions(category, item, inv).OfType().FirstOrDefault(x => x.Value("key") == action) ?? throw new ApiException(400, "该物品不支持此操作。"); var fields = (JArray)descriptor["fields"]!; if (values.Properties().Any(x => !fields.Any(f => f.Value("key") == x.Name))) throw new ApiException(400, "包含未知编辑字段。"); var legacyAbilities = action.StartsWith("ability.multiple.", StringComparison.Ordinal) && values.Count == 4 && Enumerable.Range(1, 4).All(i => values.ContainsKey("ability" + i)); foreach (var field in fields.OfType()) { if (legacyAbilities && field.RequiredString("key").Contains('_')) continue; Validate(field, values[field.Value("key")!] ?? throw new ApiException(400, "缺少 " + field.Value("label"))); } var id = Wire.Id(item["ItemId"]); var typeName = item.RequiredString("ItemType"); switch (action) { case "rename": var name = values.Value("name")!.Trim(); if (name.Length > 100 || name.Any(char.IsControl) || category == "KubrowPets" && name.Length == 0) throw new ApiException(400, "名称无效。"); if (category == "KubrowPets") item.Obj("Details")["Name"] = name; else if (name.Length == 0) item.Remove("ItemName"); else item["ItemName"] = name; break; case "experience": SetExperience(account, category, item, values.Value("xp")); break; case "max": MaxExperience(account, category, item); break; case "remove": RemoveItem(account, category, item, values.Value("count") ?? 1); break; case "mod.rank": SetModRank(inv, category, item, values.Value("rank")); break; case "forma": Custom("unlockLevelCap", new JObject { ["Category"] = category, ["ItemId"] = id, ["Polarized"] = values["count"]!.DeepClone() }); break; case "mature": new PetApi().Handle("maturePetController", account, Request("/api/maturePet.php", new JObject { ["petId"] = id, ["revert"] = values["puppy"]!.DeepClone() })); break; case "features": foreach (var field in fields.OfType()) { var bit = int.Parse(field.RequiredString("key"), CultureInfo.InvariantCulture); var wanted = values.Value(field.Value("key")!); if (((item.Value("Features") & bit) != 0) != wanted) Custom("equipmentFeatures", query: new() { ["Category"] = category, ["ItemId"] = id, ["bit"] = bit.ToString(CultureInfo.InvariantCulture) }); } break; case "quest": Custom("manageQuests", query: new() { ["itemType"] = typeName, ["operation"] = values.RequiredString("operation") }); break; case "booster": Custom("setBooster", new JArray(new JObject { ["ItemType"] = typeName, ["ExpiryDate"] = values.Value("expiry") / 1000 })); break; case "parts": ChangeParts(category, item, values); break; case "valence": SetValence(item, values); break; case "evolution": Custom("setEvolutionProgress", new JArray(new JObject { ["ItemType"] = typeName, ["Rank"] = values["rank"]!.DeepClone(), ["Delete"] = values["delete"]!.DeepClone() })); break; case "shards.add": Custom("pushArchonCrystalUpgrade", query: new() { ["oid"] = id, ["type"] = values.RequiredString("type"), ["count"] = values.Value("count").ToString(CultureInfo.InvariantCulture) }); break; case "shards.remove": Custom("popArchonCrystalUpgrade", query: new() { ["oid"] = id, ["type"] = values.RequiredString("type") }); break; case "umbra": Custom("setUmbraEchoes", new JObject { ["oid"] = id, ["UmbraDate"] = values["expiry"]!.DeepClone() }); break; case "umbra.remove": Custom("setUmbraEchoes", new JObject { ["oid"] = id, ["UmbraDate"] = 0 }); break; case "invigoration": Custom("setInvigoration", new JObject { ["oid"] = id, ["OffensiveUpgrade"] = values["offensive"]!.DeepClone(), ["DefensiveUpgrade"] = values["defensive"]!.DeepClone(), ["UpgradesExpiry"] = values["expiry"]!.DeepClone() }); break; case "invigoration.remove": Custom("setInvigoration", new JObject { ["oid"] = id, ["UpgradesExpiry"] = 0 }); break; case "exalted.prepare": PrepareExalted(account, item, values.RequiredString("type")); break; default: if (action.StartsWith("loadout.mods.", StringComparison.Ordinal)) SaveModding(category, item, inv, int.Parse(action[13..], CultureInfo.InvariantCulture), values); else if (action.StartsWith("exalted.mods.", StringComparison.Ordinal)) SaveExaltedMods(inv, item, int.Parse(action[13..], CultureInfo.InvariantCulture), values); else if (action.StartsWith("legacy.", StringComparison.Ordinal)) ApplyLegacy(item, action, values); else if (action.StartsWith("ability.multiple.", StringComparison.Ordinal)) { var configIndex = int.Parse(action[17..], CultureInfo.InvariantCulture); var selected = new JObject(); for (var slot = 0; slot < 4; slot++) { var bank = new JObject(); for (var index = 0; index < 3; index++) { var ability = values.Value("ability" + (slot + 1) + (index == 0 ? "" : "_" + (index + 1))); if (!string.IsNullOrEmpty(ability)) bank[bank.Count.ToString(CultureInfo.InvariantCulture)] = ability; } if (bank.Count > 0) selected[slot.ToString(CultureInfo.InvariantCulture)] = bank; } selected = ExperimentalAbilities.NormalizeBanks(selected); var configs = item.Array("Configs"); while (configs.Count <= configIndex) configs.Add(new JObject()); ExperimentalAbilities.SetBanks((JObject)configs[configIndex], selected); } else if (action.StartsWith("ability.", StringComparison.Ordinal)) { Custom("abilityOverride", new JObject { ["category"] = category, ["oid"] = id, ["configIndex"] = int.Parse(action[8..], CultureInfo.InvariantCulture), ["action"] = values.Value("ability") == "" ? "remove" : "set", ["AbilityOverride"] = new JObject { ["Ability"] = values["ability"]!.DeepClone(), ["Index"] = values.Value("slot") - 1 } }); } else throw new ApiException(400, "未知编辑操作。"); break; } return Done(); JObject Done() => new() { ["version"] = Version(state, account), ["saved"] = true }; ApiResponse Custom(string route, JToken? payload = null, Dictionary? query = null) => new CustomApi(catalog, clock, options).Handle(route switch { "setBooster" => "setBoosterController", _ => route + "Controller" }, state, account, Request("/custom/" + route, payload, query)); ApiRequest Request(string path, JToken? payload = null, Dictionary? query = null) => new("POST", path, query ?? [], payload?.ToString(Formatting.None) ?? "", options.AdminToken); } public static string Version(JObject account) => Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(new JObject { ["inventory"] = account["Inventory"]?.DeepClone(), ["loadouts"] = account["Loadouts"]?.DeepClone(), ["rooms"] = account["PersonalRooms"]?.DeepClone(), ["stats"] = account["Stats"]?.DeepClone(), ["inbox"] = account["Inbox"]?.DeepClone() }.ToString(Formatting.None)))); public static string Version(JObject state, JObject account) { var guild = GuildApi.Find(state, Wire.Id(account["Inventory"]?["GuildId"])); var alliance = AllianceApi.Find(state, guild?.Value("AllianceId")); return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(Version(account) + guild?.ToString(Formatting.None) + alliance?.ToString(Formatting.None)))); } private static string Key(JObject item) => Wire.Id(item["ItemId"]) is { Length: > 0 } id ? id : item.Value("ItemType") ?? ""; private static JObject AsItem(JToken item) => item as JObject ?? new JObject { ["ItemType"] = item.ToString() }; private string Name(JObject item) => catalog.InstanceName(item); private JArray Actions(string category, JObject item, JObject inv) { var actions = new JArray(); if (LevelCategories.Contains(category)) { actions.Add(Action("rename", "修改名称", Text("name", category == "KubrowPets" ? "名称" : "名称(留空恢复原名)", item.Value("ItemName") ?? item["Details"]?.Value("Name") ?? ""))); actions.Add(Action("experience", "设置经验", Number("xp", "经验值", item.Value("XP"), 0, 1000000000))); actions.Add(Action("max", "升至最高等级")); actions.Add(Action("forma", "极化与等级上限", Number("count", "极化次数", item.Value("Polarized"), 0, 10000))); var bits = new List<(int Bit, string Label, string? Forced)>(); if (category != "OperatorAmps") bits.Add((1, "双倍容量", "unlockDoubleCapacityPotatoesEverywhere")); if (category is "Suits" or "LongGuns" or "Pistols" or "Melee") bits.Add((2, "特殊槽", "unlockExilusEverywhere")); if (item["ModularParts"] is JArray { Count: > 0 }) bits.Add((8, "镀金", null)); if (category is "LongGuns" or "Pistols" or "Melee" or "SpaceGuns" or "OperatorAmps") bits.Add((32, "赋能槽", "unlockArcanesEverywhere")); if (category == "SpaceGuns") { bits.Add((4, "重力磁抵器", null)); bits.Add((64, "第二赋能槽", "unlockArcanesEverywhere")); } var type = item.Value("ItemType") ?? ""; if (EvolutionType(type) is string evolution && !WorldData.Get("permanentEvolutionWeapons").Any(x => x.ToString() == evolution)) bits.Add((512, "灵化适配器", null)); if (category is "LongGuns" or "Pistols" or "Melee" or "SpaceGuns" or "SpaceMelee" && item["UpgradeFingerprint"] is not null) bits.Add((1024, "赋能转接器", null)); var features = bits.Where(x => x.Forced is null || !inv.Value(x.Forced)).Select(x => Boolean(x.Bit.ToString(CultureInfo.InvariantCulture), x.Label, (item.Value("Features") & x.Bit) != 0)).ToArray(); if (features.Length > 0) actions.Add(Action("features", "装备特性", features)); } if (category == "KubrowPets") actions.Add(Action("mature", "成长阶段", Boolean("puppy", "幼年形态", item["Details"]?.Value("IsPuppy") ?? false))); if (category == "QuestKeys") actions.Add(Action("quest", "任务进度", Choice("operation", "操作", "completeKey", [ ("completeKey", "完成任务"), ("nextStage", "下一阶段"), ("prevStage", "上一阶段"), ("resetKey", "重置任务"), ("setInactive", "取消激活")]))); if (category == "Boosters") actions.Add(Action("booster", "修改加成期限", Date("expiry", "到期时间(清空即移除)", item.Value("ExpiryDate") * 1000))); if (category == "EvolutionProgress") actions.Add(Action("evolution", "灵化进度", Number("rank", "等级", item.Value("Rank"), 0, EvolutionMax(item.Value("ItemType")!)), Boolean("delete", "移除此进度", false))); if (category is "Upgrades" or "RawUpgrades") { var meta = ModMetadata(item.RequiredString("ItemType")); if (meta?.Value("fusionLimit") > 0) actions.Add(Action("mod.rank", "调整 MOD 等级", Number("rank", "等级(未升级堆叠每次处理 1 张)", category == "Upgrades" ? JObject.Parse(item.Value("UpgradeFingerprint") ?? "{}").Value("lvl") : 0, 0, meta.Value("fusionLimit")))); } if (category is not ("EvolutionProgress" or "Boosters")) actions.Add(Action("remove", "移除所选物品", Inventory.CountedKeys.Contains(category) ? [Number("count", "移除数量", 1, 1, Math.Min(1000000, item.Value("ItemCount")))] : [])); if (category == "Suits") { AddSuitActions(actions, item); var related = RelatedWeaponTypes(item).Select(x => (x, Name(new JObject { ["ItemType"] = x }))).ToArray(); if (related.Length > 0) actions.Add(Action("exalted.prepare", "建立显赫武器配装", Choice("type", "显赫武器", related[0].x, related))); } if (category == "SpecialItems") AddExaltedModActions(actions, item, inv); AddModdingActions(actions, category, item); AddEquipmentActions(actions, category, item); if (category == "Upgrades") LegacyActions(actions, item); return actions; } private static readonly IReadOnlyDictionary ProgressRoutes = new Dictionary { ["unlock.intrinsics"] = "unlockAllIntrinsics", ["unlock.scans"] = "unlockAllScans", ["unlock.ship"] = "unlockAllShipFeatures", ["unlock.captura"] = "unlockAllCapturaScenes", ["unlock.missions"] = "completeAllMissions", ["unlock.normalMissions"] = "completeAllMissions", ["unlock.bounties"] = "unlockAllJobChainBounties", ["unlock.simaris"] = "unlockAllSimarisResearchEntries", ["unlock.helminthRecipes"] = "addMissingHelminthBlueprints", ["unlock.mods"] = "addMissingMaxRankMods", ["unlock.badges"] = "removeIsNew" }; private JArray ProgressActions(JObject inv) { var result = new JArray( new[] { ("unlock.intrinsics", "内源之力满级"), ("unlock.scans", "解锁全部扫描"), ("unlock.ship", "解锁全部飞船模块"), ("unlock.captura", "解锁全部 Captura 场景"), ("unlock.missions", "完成普通与钢铁星图"), ("unlock.normalMissions", "完成普通星图"), ("unlock.bounties", "解锁赏金链"), ("unlock.simaris", "解锁 Simaris 研究"), ("unlock.helminthRecipes", "补齐 Helminth 蓝图"), ("unlock.mods", "补齐满级 MOD"), ("unlock.badges", "清除新获得标记"), ("unlock.focus", "解锁全部专精学派"), ("unlock.helminth", "Helminth 满级"), ("unlock.plexus", "Plexus 满级"), ("inbox.read", "全部邮件标为已读") }.Select(x => Action(x.Item1, x.Item2))); result.Add(Action("syndicate", "选择支持集团", Choice("type", "集团", inv.Value("SupportedSyndicate") ?? "", [("", "不支持任何集团"), .. GameData.Table("Syndicates").Properties().Select(x => (x.Name, catalog.Name((JObject)x.Value, x.Name)))]))); return result; } public static void Validate(JObject field, JToken value) { var type = field.Value("type"); var name = field.Value("label") ?? field.Value("key"); if (type == "bool" && value.Type == JTokenType.Boolean) return; if (type == "text" && value.Type == JTokenType.String && value.ToString().Length <= 1024 && !value.ToString().Any(char.IsControl)) return; if (type == "choice" && field["options"] is JArray choices && choices.Any(x => JToken.DeepEquals(x["value"], value))) return; if (type is "number" or "date" or "stat" && value.Type is JTokenType.Integer or JTokenType.Float) { var number = value.Value(); if (double.IsFinite(number) && number >= (field.Value("min") ?? 0) && number <= (field.Value("max") ?? 1000000) && (field.Value("integer") != true || number == Math.Truncate(number))) return; } throw new ApiException(400, name + " 的值无效或超出允许范围。"); } private static JObject Action(string key, string label, params JObject[] fields) => new() { ["key"] = key, ["label"] = label, ["fields"] = new JArray(fields) }; private static JObject Text(string key, string label, string value = "") => new() { ["key"] = key, ["label"] = label, ["type"] = "text", ["value"] = value }; private static JObject Boolean(string key, string label, bool value) => new() { ["key"] = key, ["label"] = label, ["type"] = "bool", ["value"] = value }; private static JObject Number(string key, string label, long value, long min, long max) => new() { ["key"] = key, ["label"] = label, ["type"] = "number", ["integer"] = true, ["value"] = value, ["min"] = min, ["max"] = max }; private static JObject Date(string key, string label, long value) => new() { ["key"] = key, ["label"] = label, ["type"] = "date", ["integer"] = true, ["value"] = value, ["min"] = 0, ["max"] = 253402300799000L }; private static JObject Choice(string key, string label, string value, (string Value, string Label)[] options) => new() { ["key"] = key, ["label"] = label, ["type"] = "choice", ["value"] = value, ["options"] = new JArray(options.Select(x => new JObject { ["value"] = x.Value, ["label"] = x.Label })) }; }