Skip to content

Commit

Permalink
Update ArchiSteamFarm to 6.0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Feb 25, 2024
1 parent f7fdd95 commit d6f4efd
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 148 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 174 files
14 changes: 7 additions & 7 deletions CS2Interface/CS2Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Plugins.Interfaces;
using Newtonsoft.Json.Linq;
using SteamKit2;
using System.Collections.Concurrent;
using System.Text.Json;

namespace CS2Interface {
[Export(typeof(IPlugin))]
Expand All @@ -25,24 +25,24 @@ public Task OnLoaded() {

public async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) => await Commands.Response(bot, access, steamID, message, args).ConfigureAwait(false);

public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return Task.FromResult(0);
}

return Task.FromResult(0);
}

public Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
public Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return Task.FromResult(0);
}

foreach (KeyValuePair<string, JToken> configProperty in additionalConfigProperties) {
foreach (KeyValuePair<string, JsonElement> configProperty in additionalConfigProperties) {
switch (configProperty.Key) {
case "AutoStartCS2Interface" when configProperty.Value.Type == JTokenType.Boolean: {
bot.ArchiLogger.LogGenericInfo("AutoStartCS2Interface : " + configProperty.Value);
AutoStart[bot.BotName] = configProperty.Value.ToObject<bool>();
case "AutoStartCS2Interface" when (configProperty.Value.ValueKind == JsonValueKind.True || configProperty.Value.ValueKind == JsonValueKind.False): {
bot.ArchiLogger.LogGenericInfo("AutoStartCS2Interface : " + configProperty.Value.GetBoolean());
AutoStart[bot.BotName] = configProperty.Value.GetBoolean();
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions CS2Interface/Data/InspectItem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using SteamKit2.GC.CSGO.Internal;

namespace CS2Interface {
internal sealed class InspectItem : Item {
[JsonProperty(PropertyName = "iteminfo")]
internal CEconItemPreviewDataBlock ItemInfo;
[JsonInclude]
[JsonPropertyName("iteminfo")]
internal CEconItemPreviewDataBlock ItemInfo { get; private init; }
internal string s;
internal string a;
internal string d;
Expand Down
27 changes: 16 additions & 11 deletions CS2Interface/Data/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using ArchiSteamFarm.Core;
using Newtonsoft.Json;
using SteamKit2;
using SteamKit2.GC.CSGO.Internal;

namespace CS2Interface {
internal sealed class InventoryItem : Item {
[JsonProperty(PropertyName = "iteminfo")]
internal CSOEconItem ItemInfo;
[JsonInclude]
[JsonPropertyName("iteminfo")]
internal CSOEconItem ItemInfo { get; private init; }

[JsonProperty(PropertyName = "attributes")]
[JsonInclude]
[JsonPropertyName("attributes")]
[JsonConverter (typeof(AttributeConverter))]
Dictionary<string, IAttribute>? Attributes;
internal Dictionary<string, IAttribute>? Attributes { get; private set; }

[JsonProperty(PropertyName = "position")]
internal uint? Position;
[JsonInclude]
[JsonPropertyName("position")]
internal uint? Position { get; private set; }

[JsonProperty(PropertyName = "casket_id")]
internal ulong? CasketID;
[JsonInclude]
[JsonPropertyName("casket_id")]
internal ulong? CasketID { get; private set; }

[JsonProperty(PropertyName = "moveable")]
internal bool? Moveable;
[JsonInclude]
[JsonPropertyName("moveable")]
internal bool? Moveable { get; private set; }

public bool ShouldSerializeAttributes() => Attributes != null && ShouldSerializeAdditionalProperties;
public bool ShouldSerializePosition() => Position != null && ShouldSerializeAdditionalProperties;
Expand Down
117 changes: 70 additions & 47 deletions CS2Interface/Data/Item.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using SteamKit2;

namespace CS2Interface {
Expand All @@ -14,74 +14,97 @@ internal class Item {
internal uint Rarity;
internal uint Origin;

[JsonProperty(PropertyName = "full_name")]
internal string? FullName;
[JsonInclude]
[JsonPropertyName("full_name")]
internal string? FullName { get; private set; }

[JsonProperty(PropertyName = "full_type_name")]
internal string? FullTypeName;
[JsonInclude]
[JsonPropertyName("full_type_name")]
internal string? FullTypeName { get; private set; }

[JsonProperty(PropertyName = "rarity_name")]
internal string? RarityName;
[JsonInclude]
[JsonPropertyName("rarity_name")]
internal string? RarityName { get; private set; }

[JsonProperty(PropertyName = "quality_name")]
internal string? QualityName;
[JsonInclude]
[JsonPropertyName("quality_name")]
internal string? QualityName { get; private set; }

[JsonProperty(PropertyName = "origin_name")]
internal string? OriginName;
[JsonInclude]
[JsonPropertyName("origin_name")]
internal string? OriginName { get; private set; }

[JsonProperty(PropertyName = "type_name")]
internal string? TypeName;
[JsonInclude]
[JsonPropertyName("type_name")]
internal string? TypeName { get; private set; }

[JsonProperty(PropertyName = "item_name")]
internal string? ItemName;
[JsonInclude]
[JsonPropertyName("item_name")]
internal string? ItemName { get; private set; }

[JsonProperty(PropertyName = "tool_name")]
internal string? ToolName;
[JsonInclude]
[JsonPropertyName("tool_name")]
internal string? ToolName { get; private set; }

[JsonProperty(PropertyName = "tint_name")]
internal string? TintName;
[JsonInclude]
[JsonPropertyName("tint_name")]
internal string? TintName { get; private set; }

[JsonProperty(PropertyName = "weapon_image_url")]
internal string? WeaponImageURL;
[JsonInclude]
[JsonPropertyName("weapon_image_url")]
internal string? WeaponImageURL { get; private set; }

[JsonProperty(PropertyName = "weapon_name")]
internal string? WeaponName;
[JsonInclude]
[JsonPropertyName("weapon_name")]
internal string? WeaponName { get; private set; }

[JsonProperty(PropertyName = "wear_name")]
internal string? WearName;
[JsonInclude]
[JsonPropertyName("wear_name")]
internal string? WearName { get; private set; }

[JsonProperty(PropertyName = "wear")]
internal double? Wear;
[JsonInclude]
[JsonPropertyName("wear")]
internal double? Wear { get; set; }

[JsonProperty(PropertyName = "wear_min")]
internal float? WearMin;
[JsonInclude]
[JsonPropertyName("wear_min")]
internal float? WearMin { get; private set; }

[JsonProperty(PropertyName = "wear_max")]
internal float? WearMax;
[JsonInclude]
[JsonPropertyName("wear_max")]
internal float? WearMax { get; private set; }

[JsonProperty(PropertyName = "name_id")]
internal string? NameID;
[JsonInclude]
[JsonPropertyName("name_id")]
internal string? NameID { get; private set; }

[JsonProperty(PropertyName = "set_name_id")]
internal string? SetNameID;
[JsonInclude]
[JsonPropertyName("set_name_id")]
internal string? SetNameID { get; private set; }

[JsonProperty(PropertyName = "set_name")]
internal string? SetName;
[JsonInclude]
[JsonPropertyName("set_name")]
internal string? SetName { get; private set; }

[JsonProperty(PropertyName = "crate_name_id")]
internal string? CrateNameID;
[JsonInclude]
[JsonPropertyName("crate_name_id")]
internal string? CrateNameID { get; private set; }

[JsonProperty(PropertyName = "crate_defindex")]
internal uint? CrateDefIndex;
[JsonInclude]
[JsonPropertyName("crate_defindex")]
internal uint? CrateDefIndex { get; private set; }

[JsonProperty(PropertyName = "crate_supply_series")]
internal uint? CrateSupplySeries;
[JsonInclude]
[JsonPropertyName("crate_supply_series")]
internal uint? CrateSupplySeries { get; private set; }

[JsonProperty(PropertyName = "crate_name")]
internal string? CrateName;
[JsonInclude]
[JsonPropertyName("crate_name")]
internal string? CrateName { get; private set; }

[JsonProperty(PropertyName = "defs")]
internal ItemData? ItemData;
[JsonInclude]
[JsonPropertyName("defs")]
internal ItemData? ItemData { get; private set; }

protected static bool ShouldSerializeAdditionalProperties = true;
protected static bool ShouldSerializeDefs = true;
Expand Down
24 changes: 13 additions & 11 deletions CS2Interface/Data/ItemData.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
using System;
using System.Text.Json.Serialization;
using ArchiSteamFarm.Core;
using Newtonsoft.Json;
using SteamKit2;

namespace CS2Interface {
internal class ItemData {
[JsonProperty(PropertyName = "item_def")]
internal ItemDef ItemDef;
[JsonInclude]
[JsonPropertyName("item_def")]
internal ItemDef ItemDef { get; private init; }

[JsonProperty(PropertyName = "paint_kit_def")]
internal ItemDef? PaintKitDef;
[JsonInclude]
[JsonPropertyName("paint_kit_def")]
internal ItemDef? PaintKitDef { get; private init; }

[JsonProperty(PropertyName = "sticker_kit_def")]
internal ItemDef? StickerKitDef;
[JsonInclude]
[JsonPropertyName("sticker_kit_def")]
internal ItemDef? StickerKitDef { get; private init; }

[JsonProperty(PropertyName = "music_def")]
internal ItemDef? MusicDef;
[JsonInclude]
[JsonPropertyName("music_def")]
internal ItemDef? MusicDef { get; private init; }

public bool ShouldSerializeItemDef() => ItemDef != null;
public bool ShouldSerializePaintKitDef() => PaintKitDef != null;
Expand Down Expand Up @@ -48,8 +52,6 @@ private bool MergePrefab(ItemDef itemDef, string? prefab) {
return true;
}

// STACK OVERFLOW HERE

// Some items have multiple prefabs separated by a space, but only one is valid (it has an entry in ItemsGame)
// Ex: "valve weapon_case_key": "valve" isn't valid, but "weapon_case_key" is
// Ex: "antwerp2022_sticker_capsule_prefab antwerp2022_sellable_item_with_payment_rules": "antwerp2022_sticker_capsule_prefab" is valid, but "antwerp2022_sellable_item_with_payment_rules" isn't
Expand Down
8 changes: 5 additions & 3 deletions CS2Interface/Data/ItemDef.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using SteamKit2;

namespace CS2Interface {
internal class ItemDef {
[JsonProperty(PropertyName = "defs", ItemConverterType = typeof(KVConverter))]
internal List<KeyValue> Defs = new();
[JsonInclude]
[JsonPropertyName("defs")]
[JsonConverter(typeof(JsonListItemConverter<KeyValue, KVConverter>))]
internal List<KeyValue> Defs { get; private init; } = new();

internal ItemDef(KeyValue? def) {
AddDef(def);
Expand Down
50 changes: 19 additions & 31 deletions CS2Interface/Helpers/AttributeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using ArchiSteamFarm.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace CS2Interface {
public sealed class AttributeConverter : JsonConverter {
public override bool CanConvert(Type objectType) {
return objectType == typeof(Dictionary<string, IAttribute>);
public sealed class AttributeConverter : JsonConverter<Dictionary<string, IAttribute>> {

public override Dictionary<string, IAttribute> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
throw new NotImplementedException();
}

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) {
JObject json = new();
if (value is Dictionary<string, IAttribute> attributes) {
foreach (var kvp in attributes) {
var attribute = kvp.Value;
try {
if (attribute.Type == typeof(uint)) {
json.Add(attribute.Name, attribute.ToUInt32());
} if (attribute.Type == typeof(float)) {
json.Add(attribute.Name, attribute.ToSingle());
} else if (attribute.Type == typeof(string)) {
json.Add(attribute.Name, attribute.ToString());
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);

public override void Write(Utf8JsonWriter writer, Dictionary<string, IAttribute> value, JsonSerializerOptions options) {
foreach (var kvp in value) {
var attribute = kvp.Value;
try {
if (attribute.Type == typeof(uint)) {
writer.WriteNumber(attribute.Name, attribute.ToUInt32());
} if (attribute.Type == typeof(float)) {
writer.WriteNumber(attribute.Name, attribute.ToSingle());
} else if (attribute.Type == typeof(string)) {
writer.WriteString(attribute.Name, attribute.ToString());
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}

json.WriteTo(writer);
}

public override bool CanRead {
get { return false; }
}

public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) {
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit d6f4efd

Please sign in to comment.