From 3fa743f64b2b5e5560f6ef17f7233553016ade6e Mon Sep 17 00:00:00 2001 From: Archi Date: Mon, 18 Mar 2024 12:22:07 +0100 Subject: [PATCH] Add body for asset It makes sense to expose entire underlying asset to the callers, as underlying body might have features they like, such as currencyid or est_usd - values that do not exist in json and we're not making use of them, but we still want to keep if provided e.g. by ArchiHandler. --- ArchiSteamFarm/Steam/Data/Asset.cs | 41 ++++++++++++++++--- .../Steam/Integration/ArchiHandler.cs | 2 +- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm/Steam/Data/Asset.cs b/ArchiSteamFarm/Steam/Data/Asset.cs index dc8e80a83..0d3bd7338 100644 --- a/ArchiSteamFarm/Steam/Data/Asset.cs +++ b/ArchiSteamFarm/Steam/Data/Asset.cs @@ -24,6 +24,7 @@ using System; using System.Text.Json.Serialization; using JetBrains.Annotations; +using SteamKit2.Internal; namespace ArchiSteamFarm.Steam.Data; @@ -34,6 +35,9 @@ public sealed class Asset { public const ulong SteamCommunityContextID = 6; public const ulong SteamPointsShopInstanceID = 3865004543; + [JsonIgnore] + public CEcon_Asset Body { get; } = new(); + [JsonIgnore] public bool IsSteamPointsShopItem => !Tradable && (InstanceID == SteamPointsShopInstanceID); @@ -56,26 +60,41 @@ public sealed class Asset { [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] [JsonPropertyName("amount")] [JsonRequired] - public uint Amount { get; internal set; } + public uint Amount { + get => (uint) Body.amount; + internal set => Body.amount = value; + } [JsonInclude] [JsonPropertyName("appid")] - public uint AppID { get; private init; } + public uint AppID { + get => Body.appid; + private init => Body.appid = value; + } [JsonInclude] [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] [JsonPropertyName("assetid")] - public ulong AssetID { get; private init; } + public ulong AssetID { + get => Body.assetid; + private init => Body.assetid = value; + } [JsonInclude] [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] [JsonPropertyName("classid")] - public ulong ClassID { get; private init; } + public ulong ClassID { + get => Body.classid; + private init => Body.classid = value; + } [JsonInclude] [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] [JsonPropertyName("contextid")] - public ulong ContextID { get; private init; } + public ulong ContextID { + get => Body.contextid; + private init => Body.contextid = value; + } [JsonIgnore] public InventoryDescription? Description { get; internal set; } @@ -83,7 +102,10 @@ public sealed class Asset { [JsonInclude] [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] [JsonPropertyName("instanceid")] - public ulong InstanceID { get; private init; } + public ulong InstanceID { + get => Body.instanceid; + private init => Body.instanceid = value; + } [JsonInclude] [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] @@ -93,6 +115,13 @@ public sealed class Asset { init => AssetID = value; } + public Asset(CEcon_Asset asset, InventoryDescription? description = null) { + ArgumentNullException.ThrowIfNull(asset); + + Body = asset; + Description = description; + } + public Asset(uint appID, ulong contextID, ulong classID, uint amount, InventoryDescription? description = null, ulong assetID = 0, ulong instanceID = 0) { ArgumentOutOfRangeException.ThrowIfZero(appID); ArgumentOutOfRangeException.ThrowIfZero(contextID); diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index 5cb49c39e..ba46fb864 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -238,7 +238,7 @@ public sealed class ArchiHandler : ClientMsgHandler { continue; } - yield return new Asset(asset.appid, asset.contextid, asset.classid, (uint) asset.amount, description, asset.assetid, asset.instanceid); + yield return new Asset(asset, description); } if (!response.more_items) {