From b3f11e01884b6300723f16f103da126736ca3175 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 14 Jan 2019 16:03:55 -0300 Subject: [PATCH] Add Marketable property into inventory Assets (#1031) * Add files via upload Add Marketable * Add files via upload Add Marketable * Fix --- ArchiSteamFarm/ArchiWebHandler.cs | 23 ++++++++++++++--------- ArchiSteamFarm/Json/Steam.cs | 12 +++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 0a462de7e..b30999824 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1066,7 +1066,7 @@ namespace ArchiSteamFarm { return null; } - Dictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type)> descriptions = new Dictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type)>(); + Dictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type, bool Marketable)> descriptions = new Dictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type, bool Marketable)>(); foreach (KeyValue description in response["descriptions"].Children) { uint appID = description["appid"].AsUnsignedInteger(); @@ -1104,9 +1104,11 @@ namespace ArchiSteamFarm { if (!string.IsNullOrEmpty(descriptionType)) { type = GetItemType(descriptionType); } - } + } + + bool marketable = description["marketable"].AsBoolean(); - descriptions[(appID, classID)] = (realAppID, type); + descriptions[(appID, classID)] = (realAppID, type, marketable); } HashSet result = new HashSet(); @@ -1437,7 +1439,7 @@ namespace ArchiSteamFarm { return null; } - Dictionary descriptions = new Dictionary(); + Dictionary descriptions = new Dictionary(); foreach (Steam.InventoryResponse.Description description in response.Descriptions.Where(description => description != null)) { if (description.ClassID == 0) { @@ -1463,16 +1465,17 @@ namespace ArchiSteamFarm { } } - descriptions[description.ClassID] = (description.Tradable, realAppID, type); + descriptions[description.ClassID] = (description.Tradable, description.Marketable, realAppID, type); } foreach (Steam.Asset asset in response.Assets.Where(asset => asset != null)) { - if (descriptions.TryGetValue(asset.ClassID, out (bool Tradable, uint RealAppID, Steam.Asset.EType Type) description)) { + if (descriptions.TryGetValue(asset.ClassID, out (bool Tradable, bool Marketable, uint RealAppID, Steam.Asset.EType Type) description)) { if ((tradable.HasValue && (description.Tradable != tradable.Value)) || (wantedRealAppIDs?.Contains(description.RealAppID) == false) || (wantedSets?.Contains((description.RealAppID, description.Type)) == false) || (wantedTypes?.Contains(description.Type) == false) || (skippedSets?.Contains((description.RealAppID, description.Type)) == true)) { continue; } asset.Tradable = description.Tradable; + asset.Marketable = description.Marketable; asset.RealAppID = description.RealAppID; asset.Type = description.Type; } else if (tradable.HasValue || (wantedRealAppIDs != null) || (wantedSets != null) || (wantedTypes != null) || (skippedSets != null)) { @@ -2379,7 +2382,7 @@ namespace ArchiSteamFarm { return uri.AbsolutePath.StartsWith("/login", StringComparison.Ordinal) || uri.Host.Equals("lostauth"); } - private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type)> descriptions, IReadOnlyCollection input, ICollection output) { + private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID), (uint RealAppID, Steam.Asset.EType Type, bool Marketable)> descriptions, IReadOnlyCollection input, ICollection output) { if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) { ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); @@ -2421,13 +2424,15 @@ namespace ArchiSteamFarm { uint realAppID = 0; Steam.Asset.EType type = Steam.Asset.EType.Unknown; + bool marketable = true; - if (descriptions.TryGetValue((appID, classID), out (uint RealAppID, Steam.Asset.EType Type) description)) { + if (descriptions.TryGetValue((appID, classID), out (uint RealAppID, Steam.Asset.EType Type, bool Marketable) description)) { realAppID = description.RealAppID; type = description.Type; + marketable = description.Marketable; } - Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, amount, realAppID, type); + Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, amount, realAppID, type, marketable); output.Add(steamAsset); } diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 31911c2aa..54f2e01fc 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -60,6 +60,9 @@ namespace ArchiSteamFarm.Json { [PublicAPI] public bool Tradable { get; internal set; } + [PublicAPI] + public bool Marketable { get; internal set; } + [PublicAPI] public EType Type { get; internal set; } @@ -157,7 +160,7 @@ namespace ArchiSteamFarm.Json { } // Constructed from trades being received or plugins - public Asset(uint appID, uint contextID, ulong classID, uint amount, uint realAppID = 0, EType type = EType.Unknown) { + public Asset(uint appID, uint contextID, ulong classID, uint amount, uint realAppID = 0, EType type = EType.Unknown, bool marketable = true) { if ((appID == 0) || (contextID == 0) || (classID == 0) || (amount == 0)) { throw new ArgumentNullException(nameof(appID) + " || " + nameof(contextID) + " || " + nameof(classID) + " || " + nameof(amount)); } @@ -168,6 +171,7 @@ namespace ArchiSteamFarm.Json { Amount = amount; RealAppID = realAppID; Type = type; + Marketable = marketable; } [JsonConstructor] @@ -439,6 +443,7 @@ namespace ArchiSteamFarm.Json { internal ulong ClassID { get; private set; } internal bool Tradable { get; private set; } + internal bool Marketable { get; private set; } [JsonProperty(PropertyName = "classid", Required = Required.Always)] private string ClassIDText { @@ -464,6 +469,11 @@ namespace ArchiSteamFarm.Json { set => Tradable = value > 0; } + [JsonProperty(PropertyName = "marketable", Required = Required.Always)] + private byte MarketableNumber { + set => Marketable = value > 0; + } + [JsonConstructor] private Description() { } }