XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
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 <report.json>");
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<string>().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<string>("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<string>("typeName")!, count * part.Value<int>("purchaseQuantity"), tier, depth + 1);
        return;
    }
    if (category == "Boosters")
    {
        if (!(inv["Boosters"] as JArray ?? []).Any(b => b.Value<string>("ItemType") == meta.Value<string>("typeName") && b.Value<long>("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<string>("bin")!;
        if (inv[bin]!.Value<int>("Slots") - (baseline[bin]?.Value<int>("Slots") ?? 0) < count * meta.Value<int>("purchaseQuantity")) throw new InvalidDataException("Inventory slots were not granted");
        return;
    }
    if (category == "CreditBundles") { if (inv.Value<long>("RegularCredits") <= baseline.Value<long>("RegularCredits")) throw new InvalidDataException("Credit bundle was not granted"); return; }
    if (category == "FusionBundles") { if (inv.Value<long>("FusionPoints") < count * meta.Value<long>("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<string>("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<bool>(); var booster = item.Category == "Boosters" && !item.Type.Contains("Blessing", StringComparison.Ordinal);
    if (!item.Meta.Value<bool>("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<bool>("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<long?>(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<string,string>(), 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<long>(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<bool>("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;