using Newtonsoft.Json; using Newtonsoft.Json.Linq; using XFEWarframe.Core; using XFEWarframe.Core.Data; using XFEWarframe.Core.Services; if (args.Length != 1) throw new ArgumentException("Usage: MarketAudit "); var catalog = new ItemCatalog(); var service = new PurchaseApi(catalog, TimeProvider.System, syncOfficialEvents: false); var baseline = Inventory.New(); baseline["RegularCredits"] = 900000000L; baseline["PremiumCredits"] = 900000000L; baseline["PremiumCreditsFree"] = 0; foreach (var bin in Inventory.EquipmentKeys.Select(Inventory.SlotFor).OfType().Distinct()) baseline[bin] = new JObject { ["Slots"] = 10000, ["Extra"] = 10000 }; var template = new JObject { ["id"] = "111111111111111111111111", ["DisplayName"] = "MarketAudit", ["BuildLabel"] = "2026.10.22.13.12", ["Inventory"] = baseline, ["Loadouts"] = new JObject(), ["PersonalRooms"] = new JObject(), ["Inbox"] = new JArray() }; var results = new JArray(); var omitted = new JArray(); var tested = 0; bool Quoted(string type, bool premium, int depth = 0) { if (depth > 8) return false; try { var (category, meta) = catalog.Get(type); if (category == "Boosters") return premium && !type.Contains("Blessing", StringComparison.Ordinal); if (meta[premium ? "platinumCost" : "creditsCost"]?.Type == JTokenType.Integer) return true; return category == "Bundles" && meta["components"] is JArray { Count: > 0 } parts && parts.All(p => Quoted(p.Value("typeName")!, premium, depth + 1)); } catch (ApiException) { return false; } } void Granted(JObject inv, string type, int count = 1, int tier = 0, int depth = 0) { if (depth > 8) throw new InvalidDataException("Recursive grant verification"); type = catalog.ResolveType(type); var (category, meta) = catalog.Get(type); if (category == "Bundles") { foreach (var part in (JArray)meta["components"]!) Granted(inv, part.Value("typeName")!, count * part.Value("purchaseQuantity"), tier, depth + 1); return; } if (category == "Boosters") { if (!(inv["Boosters"] as JArray ?? []).Any(b => b.Value("ItemType") == meta.Value("typeName") && b.Value("ExpiryDate") >= DateTimeOffset.UtcNow.ToUnixTimeSeconds() + new[] {3,7,30}[tier] * 86400 - 10)) throw new InvalidDataException("Booster duration was not granted"); return; } if (category == "SlotItems") { var bin = meta.Value("bin")!; if (inv[bin]!.Value("Slots") - (baseline[bin]?.Value("Slots") ?? 0) < count * meta.Value("purchaseQuantity")) throw new InvalidDataException("Inventory slots were not granted"); return; } if (category == "CreditBundles") { if (inv.Value("RegularCredits") <= baseline.Value("RegularCredits")) throw new InvalidDataException("Credit bundle was not granted"); return; } if (category == "FusionBundles") { if (inv.Value("FusionPoints") < count * meta.Value("fusionPoints")) throw new InvalidDataException("Fusion bundle was not granted"); return; } if (category == "BoosterPacks") return; // Random contents validated separately by their purchase response. if (category == "LevelKeys" && meta["chainStages"] is JArray) category = "QuestKeys"; var entries = (inv[category] as JArray ?? []).Concat(category == "RawUpgrades" ? inv["Upgrades"] as JArray ?? [] : []); if (!entries.Any(e => e.Value("ItemType") == type)) throw new InvalidDataException("Purchased item was not granted to " + category); } foreach (var item in catalog.Entries.OrderBy(x => x.Type, StringComparer.Ordinal)) { var modes = new List(); var booster = item.Category == "Boosters" && !item.Type.Contains("Blessing", StringComparison.Ordinal); if (!item.Meta.Value("excludeFromMarket")) { if (Quoted(item.Type, true)) modes.Add(true); if (Quoted(item.Type, false)) modes.Add(false); } if (modes.Count == 0) { omitted.Add(new JObject { ["type"] = item.Type, ["category"] = item.Category, ["reason"] = item.Meta.Value("excludeFromMarket") ? "not offered in the market" : "no market price; vendor/reward/external purchase item" }); continue; } foreach (var premium in modes) foreach (var tier in booster ? new[] {0,1,2} : new[] {0}) { var account = (JObject)template.DeepClone(); var state = new JObject { ["config"] = new JObject(), ["worldState"] = new JObject() }; var price = booster ? new[] {40L,80L,200L}[tier] : item.Meta.Value(premium ? "platinumCost" : "creditsCost") ?? 0; var row = new JObject { ["type"] = item.Type, ["category"] = item.Category, ["premium"] = premium, ["tier"] = tier }; var body = new JObject { ["PurchaseParams"] = new JObject { ["Source"] = 0, ["StoreItem"] = GameData.StoreType(item.Type), ["UsePremium"] = premium, ["Quantity"] = 1, ["Durability"] = tier, ["ExpectedPrice"] = price } }; try { var response = service.Handle(state, account, new("POST", "/api/purchase.php", new Dictionary(), body.ToString(Formatting.None))); if (response.Status != 200) throw new InvalidOperationException(response.Body); var changes = Wire.ReadObject(response.Body)["InventoryChanges"] as JObject ?? throw new InvalidDataException("Missing inventory changes"); if (!changes.HasValues) throw new InvalidDataException("Purchase returned no inventory changes"); Granted(account.Obj("Inventory"), item.Type, tier: tier); var spent = 900000000L - account.Obj("Inventory").Value(premium ? "PremiumCredits" : "RegularCredits"); if (price > 0 && spent != price) throw new InvalidDataException("Currency deduction mismatch"); row["passed"] = true; row["spent"] = spent; } catch (Exception ex) { row["passed"] = false; row["error"] = ex.Message; row["status"] = ex is ApiException api ? api.Status : 500; } results.Add(row); tested++; if (tested % 250 == 0) Console.WriteLine($"Tested {tested} purchase variants"); } } var failures = new JArray(results.Where(r => !r.Value("passed")).Select(r => r.DeepClone())); var report = new JObject { ["scope"] = "Isolated direct market purchase controller calls; each offer uses a fresh account. No live game or player data modified.", ["catalogEntries"] = catalog.Entries.Count(), ["testedVariants"] = tested, ["passed"] = tested - failures.Count, ["failures"] = failures, ["results"] = results, ["notMarketOffers"] = omitted }; var reportPath = Path.GetFullPath(args[0]); Directory.CreateDirectory(Path.GetDirectoryName(reportPath)!); File.WriteAllText(reportPath, report.ToString(Formatting.Indented)); Console.WriteLine($"Variants {tested}; passed {tested-failures.Count}; failed {failures.Count}; catalog rows {catalog.Entries.Count()}"); Environment.ExitCode = failures.Count == 0 ? 0 : 1;