diff --git a/CS2Interface/GameData/GameObjects/Items/InspectItem.cs b/CS2Interface/GameData/GameObjects/Items/InspectItem.cs index 87086d9..f047d42 100644 --- a/CS2Interface/GameData/GameObjects/Items/InspectItem.cs +++ b/CS2Interface/GameData/GameObjects/Items/InspectItem.cs @@ -24,6 +24,7 @@ internal InspectItem(CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse it PaintIndex = ItemInfo.paintindex; StickerID = ItemInfo.stickers.FirstOrDefault()?.sticker_id; TintID = ItemInfo.stickers.FirstOrDefault()?.tint_id; + KeychainID = ItemInfo.keychains.FirstOrDefault()?.sticker_id; Quality = ItemInfo.quality; Rarity = ItemInfo.rarity; Origin = ItemInfo.origin; diff --git a/CS2Interface/GameData/GameObjects/Items/InventoryItem.cs b/CS2Interface/GameData/GameObjects/Items/InventoryItem.cs index 88e854c..762aeb6 100644 --- a/CS2Interface/GameData/GameObjects/Items/InventoryItem.cs +++ b/CS2Interface/GameData/GameObjects/Items/InventoryItem.cs @@ -46,6 +46,7 @@ internal InventoryItem(CSOEconItem item) { StickerID = Attributes.GetValueOrDefault("sticker slot 0 id")?.ToUInt32(); TintID = Attributes.GetValueOrDefault("spray tint id")?.ToUInt32(); MusicID = Attributes.GetValueOrDefault("music id")?.ToUInt32(); + KeychainID = Attributes.GetValueOrDefault("keychain slot 0 id")?.ToUInt32(); if (Attributes.GetValueOrDefault("set item texture wear") != null) { Wear = (double) BitConverter.UInt32BitsToSingle(BitConverter.SingleToUInt32Bits(Attributes.GetValueOrDefault("set item texture wear")!.ToSingle())); } diff --git a/CS2Interface/GameData/GameObjects/Items/Item.cs b/CS2Interface/GameData/GameObjects/Items/Item.cs index 1f7bcd6..1967527 100644 --- a/CS2Interface/GameData/GameObjects/Items/Item.cs +++ b/CS2Interface/GameData/GameObjects/Items/Item.cs @@ -11,6 +11,7 @@ public class Item : GameObject { public uint? StickerID; public uint? TintID; public uint? MusicID; + public uint? KeychainID; public uint Quality; public uint Rarity; public uint Origin; @@ -164,7 +165,7 @@ protected override bool SetAdditionalProperties() { // Set the item name, which will be something like: what kind of sticker it is, or the name of the weapon skin, or the type of pin/coin // If an item has a wear value, but uses the default paint_kit (vanilla knives for example), this will be "-" - ItemName = GameData.CsgoEnglish[(ItemData.MusicDef?["loc_name"].Value ?? ItemData.StickerKitDef?["item_name"].Value ?? ItemData.PaintKitDef?["description_tag"].Value ?? ItemData.ItemDef["item_name"].Value)?.Substring(1)]; + ItemName = GameData.CsgoEnglish[(ItemData.KeychainDef?["loc_name"].Value ?? ItemData.MusicDef?["loc_name"].Value ?? ItemData.StickerKitDef?["item_name"].Value ?? ItemData.PaintKitDef?["description_tag"].Value ?? ItemData.ItemDef["item_name"].Value)?.Substring(1)]; // Set the tool named, used for various things like differentiating between Graffiti and Sealed Graffiti if (ItemData.ItemDef["prefab"].Value == "csgo_tool") { @@ -205,7 +206,7 @@ protected override bool SetAdditionalProperties() { FullTypeName = String.Format("{0} {1} {2}", displayQualityName, RarityName, TypeName).Trim(); // FullTypeName = String.Format(GameData.CsgoEnglish.Format("ItemTypeDescKillEater") ?? "{0} {1} {2}", displayQualityName, RarityName, TypeName).Trim(); - if (PaintIndex == 0 && ItemData.StickerKitDef == null && ItemData.MusicDef == null) { + if (PaintIndex == 0 && ItemData.StickerKitDef == null && ItemData.MusicDef == null && ItemData.KeychainDef == null) { FullName = String.Format("{0} {1}", displayQualityName, ToolName ?? WeaponName ?? ItemName).Trim(); // Collectibles (Pins, Coins), Vanilla Knives } else if (WearName != null || TintName != null) { FullName = String.Format("{0} {1} | {2} ({3})", displayQualityName, WeaponName ?? ToolName ?? TypeName, ItemName, WearName ?? TintName).Trim(); // Weapon Skins, Gloves, Graffiti @@ -217,10 +218,10 @@ protected override bool SetAdditionalProperties() { } // Set the name id, used for determining related set and crate - if (PaintIndex == 0 && ItemData.StickerKitDef == null && ItemData.MusicDef == null) { + if (PaintIndex == 0 && ItemData.StickerKitDef == null && ItemData.MusicDef == null && ItemData.KeychainDef == null) { NameID = ItemData.ItemDef["name"].Value; // Collectibles, Vanilla Knives } else { - NameID = String.Format("[{0}]{1}", (ItemData.MusicDef ?? ItemData.StickerKitDef ?? ItemData.PaintKitDef)?["name"].Value, ItemData.ItemDef["name"].Value); // Everything else + NameID = String.Format("[{0}]{1}", (ItemData.KeychainDef ?? ItemData.MusicDef ?? ItemData.StickerKitDef ?? ItemData.PaintKitDef)?["name"].Value, ItemData.ItemDef["name"].Value); // Everything else } if (NameID != null) { diff --git a/CS2Interface/GameData/GameObjects/Items/ItemData.cs b/CS2Interface/GameData/GameObjects/Items/ItemData.cs index 6001f21..84001c2 100644 --- a/CS2Interface/GameData/GameObjects/Items/ItemData.cs +++ b/CS2Interface/GameData/GameObjects/Items/ItemData.cs @@ -26,16 +26,23 @@ public class ItemData { [JsonConverter(typeof(KVConverter))] public KeyValue? MusicDef { get; private init; } + [JsonInclude] + [JsonPropertyName("keychain_def")] + [JsonConverter(typeof(KVConverter))] + public KeyValue? KeychainDef { get; private init; } + public bool ShouldSerializeItemDef() => ItemDef != null; public bool ShouldSerializePaintKitDef() => PaintKitDef != null; public bool ShouldSerializeStickerKitDef() => StickerKitDef != null; public bool ShouldSerializeMusicDef() => MusicDef != null; + public bool ShouldSerializeKeychainDefDef() => KeychainDef != null; internal ItemData(Item item) { ItemDef = CreateItemDef(item); PaintKitDef = CreatePaintKitDef(item); StickerKitDef = CreateStickerKitDef(item); MusicDef = CreateMusicDef(item); + KeychainDef = CreateKeychainDef(item); } private KeyValue CreateItemDef(Item item) { @@ -160,5 +167,24 @@ private bool MergePrefab(KeyValue itemDef, string? prefab) { return musicDef.Clone(); } + + + private KeyValue? CreateKeychainDef(Item item) { + if (item.KeychainID == null + || !( + item.DefIndex == 1355 // Charm + ) + ) { + // This item has no keychain definition + return null; + } + + KeyValue? keychainDef = GameData.ItemsGame.GetDef("keychain_definitions", item.KeychainID.ToString()!); + if (keychainDef == null) { + throw new Exception(); + } + + return keychainDef.Clone(); + } } } \ No newline at end of file