using Newtonsoft.Json; using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; public sealed partial class CustomApi { private ApiResponse Edit(string controller, JObject account, ApiRequest request) { var inv = account.Obj("Inventory"); var body = request.ObjectBody(); JObject gear; if (controller == "addXpController") { foreach (var property in body.Properties()) { if (!Inventory.EquipmentKeys.Contains(property.Name) || property.Value is not JArray updates) throw new ApiException(400, "Invalid equipment XP category"); foreach (var item in updates.OfType()) { var owned = Inventory.Equipment(inv, property.Name, Wire.Id(item["ItemId"])); if (catalog.Get(owned.RequiredString("ItemType")).Meta.Value("maxLevelCap") > 30 && owned.Value("Polarized") < 5) owned["Polarized"] = 5; } InventoryProgress.Equipment(inv, property.Name, updates); } return ApiResponse.Text(); } if (controller == "equipmentFeaturesController") { gear = Inventory.Equipment(inv, Query(request, "Category"), Query(request, "ItemId")); var bit = QueryInt(request, "bit", 1, 1024); if (!new[] { 1, 2, 4, 8, 32, 64, 512, 1024 }.Contains(bit)) throw new ApiException(400, "Unknown equipment feature"); if (bit == 512) { var type = gear.RequiredString("ItemType"); var parent = GameData.Find("Weapons", type)?.Value("parentName"); var evolution = WorldData.Get("evolutionWeapons").Values().ToHashSet(); var target = evolution.Contains(type) ? type : parent is not null && evolution.Contains(parent) ? parent : throw new ApiException(400, "Weapon does not support Incarnon Genesis"); gear["SkillTree"] = "0"; if (!inv.Array("EvolutionProgress").Any(x => x.Value("ItemType") == target)) inv.Array("EvolutionProgress").Add(new JObject { ["ItemType"] = target, ["Progress"] = 0, ["Rank"] = 1 }); } gear["Features"] = gear.Value("Features") ^ bit; return ApiResponse.Text(); } if (controller is "pushArchonCrystalUpgradeController" or "popArchonCrystalUpgradeController") { gear = Inventory.Equipment(inv, "Suits", Query(request, "oid")); var type = Query(request, "type"); if (!type.StartsWith("/Lotus/Upgrades/", StringComparison.Ordinal)) throw new ApiException(400, "Invalid shard upgrade"); var upgrades = gear.Array("ArchonCrystalUpgrades"); if (controller == "pushArchonCrystalUpgradeController") { var count = QueryInt(request, "count", 1, 10000, 1); if (upgrades.Count + count > 10000) throw new ApiException(400, "Too many shard overrides"); for (var i = 0; i < count; i++) upgrades.Add(new JObject { ["UpgradeType"] = type }); } else foreach (var upgrade in upgrades.Where(x => x.Value("UpgradeType") == type).ToArray()) upgrade.Remove(); return ApiResponse.Json(gear); } if (controller == "unlockLevelCapController") { Inventory.Equipment(inv, body.RequiredString("Category"), Wire.Id(body["ItemId"]))["Polarized"] = body.Integer("Polarized", 0, 10000); return ApiResponse.Text(); } if (controller is "setInvigorationController" or "setUmbraEchoesController") { gear = Inventory.Equipment(inv, "Suits", body.RequiredString("oid")); if (controller == "setUmbraEchoesController") { var date = body.Integer("UmbraDate", 0, 253402300799000); if (date == 0) gear.Remove("UmbraDate"); else gear["UmbraDate"] = Wire.Date(date); } else if (!string.IsNullOrEmpty(body.Value("DefensiveUpgrade")) && !string.IsNullOrEmpty(body.Value("OffensiveUpgrade")) && body.Value("UpgradesExpiry") > 0) { foreach (var key in new[] { "DefensiveUpgrade", "OffensiveUpgrade" }) { if (!body.RequiredString(key).StartsWith("/Lotus/Upgrades/", StringComparison.Ordinal)) throw new ApiException(400, "Invalid invigoration upgrade"); gear[key] = body[key]!.DeepClone(); } gear["UpgradesExpiry"] = Wire.Date(body.Integer("UpgradesExpiry", 1, 253402300799000)); } else foreach (var key in new[] { "DefensiveUpgrade", "OffensiveUpgrade", "UpgradesExpiry" }) gear.Remove(key); return ApiResponse.Json(gear); } var category = body.RequiredString("category"); gear = category == "Upgrades" ? inv.Array("Upgrades").OfType().FirstOrDefault(x => Wire.Id(x["ItemId"]) == body.Value("oid")) ?? throw new ApiException(404, "Owned mod not found") : Inventory.Equipment(inv, category, body.RequiredString("oid")); if (controller == "abilityOverrideController") { if (category != "Suits") throw new ApiException(400, "Ability override requires a Warframe"); var index = (int)body.Integer("configIndex", 0, 7); var configs = gear.Array("Configs"); while (configs.Count <= index) configs.Add(new JObject()); var config = (JObject)configs[index]; if (body.Value("action") == "remove") ExperimentalAbilities.Set(config, new()); else if (body.Value("action") == "set") { var ability = body["AbilityOverride"] as JObject ?? throw new ApiException(400, "Missing ability override"); ExperimentalAbilities.Set(config, new JObject { [ability.Integer("Index", 0, 3).ToString()] = ability.RequiredString("Ability") }); } else throw new ApiException(400, "Unknown override action"); return ApiResponse.Json(gear); } if (controller == "updateFingerprintController") { if (body.Value("action") == "remove") { gear.Remove("UpgradeFingerprint"); gear.Remove("UpgradeType"); } else if (body.Value("action") == "set") { var fingerprint = body["upgradeFingerprint"] as JObject ?? throw new ApiException(400, "Missing upgrade fingerprint"); if (category != "Upgrades") { if (fingerprint["buffs"] is not JArray { Count: > 0 and <= 32 } buffs) throw new ApiException(400, "Missing weapon modifiers"); foreach (var buff in buffs.OfType()) { buff.RequiredString("Tag"); var value = buff.Value("Value"); if (!double.IsFinite(value)) throw new ApiException(400, "Invalid upgrade value"); } fingerprint["compat"] ??= gear["ItemType"]!.DeepClone(); gear["UpgradeType"] = body.RequiredString("upgradeType"); } gear["UpgradeFingerprint"] = fingerprint.ToString(Formatting.None); } else throw new ApiException(400, "Unknown fingerprint action"); return ApiResponse.Text(); } if (controller == "changeModularPartsController") { if (body["modularParts"] is not JArray { Count: >= 3 and <= 6 } parts) throw new ApiException(400, "Invalid modular parts"); foreach (var part in parts) { if (catalog.Get(part.ToString()).Category != "MiscItems") throw new ApiException(400, "Unknown modular part"); if (WorldData.Get("modularPartTypeMapping")[part.ToString()]?[category] is JToken type) gear["ItemType"] = type.DeepClone(); } gear["ModularParts"] = parts.DeepClone(); return ApiResponse.Text(); } throw new ApiException(400, "Unknown equipment editor operation"); } private ApiResponse SetCheat(JObject account, JObject body) { var inv = account.Obj("Inventory"); var key = body.RequiredString("key"); var boolean = WorldData.Get("accountCheatBooleans").Any(x => x.ToString() == key); if (boolean) { if (body["value"]?.Type != JTokenType.Boolean) throw new ApiException(400, "Cheat value must be boolean"); } else { var field = Assets.Json("editor/settings.json")["groups"]!["account"]!.OfType().FirstOrDefault(x => x.Value("key") == key); if (!WorldData.Get("accountCheatNumbers").Any(x => x.ToString() == key) || field is null || body["value"] is null) throw new ApiException(400, "Invalid numeric cheat"); AccountEditor.Validate(field, body["value"]!); } inv[key] = body["value"]!.DeepClone(); if (boolean && body.Value("value") && CleanupKeys.Contains(key)) { var cleaned = (JObject)inv.DeepClone(); CleanupCheat(cleaned, key); if (!JToken.DeepEquals(inv, cleaned)) return ApiResponse.Text("retroactivable"); } return ApiResponse.Text(); } private static readonly string[] CleanupKeys = ["alertsRepeatable", "syndicateMissionsRepeatable", "noVendorPurchaseLimits", "noDeathMarks", "noNemesis", "noMasteryRankUpCooldown", "noBlessingCooldown", "noKimCooldowns"]; private void CleanupCheat(JObject inv, string key) { switch (key) { case "alertsRepeatable": inv["CompletedAlerts"] = new JArray(); inv["PeriodicMissionCompletions"] = new JArray(); break; case "syndicateMissionsRepeatable": inv["CompletedSyndicates"] = new JArray(); break; case "noVendorPurchaseLimits": inv["RecentVendorPurchases"] = new JArray(); inv["UsedDailyDeals"] = new JArray(); break; case "noDeathMarks": inv["DeathMarks"] = new JArray(); inv["Harvestable"] = false; inv["DeathSquadable"] = false; break; case "noNemesis": inv.Remove("Nemesis"); inv["NemesisAbandonedRewards"] = new JArray(); inv.Remove("NemesisTaxedCredits"); break; case "noMasteryRankUpCooldown": if (Wire.DateMs(inv["TrainingDate"]) > clock.GetUtcNow().ToUnixTimeMilliseconds()) inv["TrainingDate"] = Wire.Date(clock.GetUtcNow().ToUnixTimeMilliseconds()); break; case "noBlessingCooldown": if (Wire.DateMs(inv["BlessingCooldown"]) > clock.GetUtcNow().ToUnixTimeMilliseconds()) inv["BlessingCooldown"] = Wire.Date(clock.GetUtcNow().ToUnixTimeMilliseconds()); break; case "noKimCooldowns": foreach (var dialogue in (inv["DialogueHistory"]?["Dialogues"] as JArray ?? []).OfType()) foreach (var field in new[] { "AvailableDate", "AvailableGiftDate" }) if (Wire.DateMs(dialogue[field]) > clock.GetUtcNow().ToUnixTimeMilliseconds()) dialogue[field] = Wire.Date(clock.GetUtcNow().ToUnixTimeMilliseconds()); break; default: throw new ApiException(400, "Cheat has no retroactive operation"); } } }