상속: global::ProtoBuf.IExtensible
예제 #1
0
        public static void CreateItem(uint def_index, uint quality,
            uint rarity, uint level, List<ItemAttribute> attribs, Stream file, ItemData dataHeader)
        {
            CSGOItemProto econItem = new CSGOItemProto();

            econItem.id = 0;
            econItem.inventory = 0;
            econItem.def_index = def_index;
            econItem.level = level;
            econItem.rarity = rarity;
            econItem.quality = quality;
            econItem.flags = 0;
            econItem.origin = 0;

            econItem.attribute = new List<CSOEconItemAttribute>();

            foreach (var attrib in attribs)
            {
                CSOEconItemAttribute itemAttribute = new CSOEconItemAttribute();

                itemAttribute.def_index = attrib.Id;
                itemAttribute.value_bytes = BitConverter.GetBytes(attrib.ValueByte);

                econItem.attribute.Add(itemAttribute);
            }

            dataHeader.Type = 1;
            dataHeader.Length = CalcProtoBufSize(econItem);

            Write(file, dataHeader);

            Serializer.Serialize<CSGOItemProto>(file, econItem);
        }
예제 #2
0
        private void SaveCheckBoxListItemState()
        {
            savedSelected = new CompleteItemInfo();

            Dictionary<AttributeInfo, CSOEconItemAttribute> attibuteInfoWithCso = new Dictionary<AttributeInfo, CSOEconItemAttribute>();
            AttributeInfo attrInfo = new AttributeInfo();
            CSOEconItemAttribute csoAttr = new CSOEconItemAttribute();

            int stickerCount = 0;
            foreach (var item in tlpInventoryAttr.Controls)
            {
                if (item is ComboBox)
                {
                    if (((ComboBox)item).Name.Contains("cmbReadItemAttr"))
                    {
                        attrInfo = (AttributeInfo)((ComboBox)item).SelectedItem;
                        csoAttr = new CSOEconItemAttribute();
                    }

                    if (((ComboBox)item).Name.Contains("cmbSelectedItemAttr"))
                    {
                        csoAttr.def_index = (uint)attrInfo.CodedValue;
                        // paint kits
                        if (attrInfo.CodedValue == 6)
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.PaintAttributeLookup = (PaintInfo)((ComboBox)item).SelectedItem;
                                csoAttr.value_bytes = BitConverter.GetBytes(Convert.ToSingle(savedSelected.PaintAttributeLookup.CodedValue));
                            }
                        }
                        // sticker
                        else if (attrInfo.CodedName.Contains("sticker slot "))
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.StickerAttributeLookup.Add((StickerInfo)((ComboBox)item).SelectedItem);
                                csoAttr.value_bytes = BitConverter.GetBytes(savedSelected.StickerAttributeLookup[stickerCount].CodedValue);
                                stickerCount++;
                            }
                        }
                        // music
                        else if (attrInfo.CodedValue == 166)
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.MusicAttributeLookup = (MusicInfo)((ComboBox)item).SelectedItem;
                                csoAttr.value_bytes = BitConverter.GetBytes(savedSelected.MusicAttributeLookup.CodedValue);
                            }
                        }
                    }
                }// wear
                else if (item is TrackBar)
                {
                    if (string.IsNullOrEmpty(savedSelected.PaintAttributeLookup.Name) == false)
                    {
                        csoAttr.def_index = Convert.ToUInt32(attrInfo.CodedValue);

                        float wearLevel = Convert.ToSingle((((TrackBar)item).Value / 100f));
                        csoAttr.value_bytes = BitConverter.GetBytes(wearLevel);
                    }
                }
                else if (item is TextBox)
                {
                    if (((TextBox)item).Name.Contains("tbAttrValue"))
                    {
                        csoAttr.def_index = Convert.ToUInt32(attrInfo.CodedValue);

                        if (attrInfo.IsInteger)
                        {
                            csoAttr.value_bytes = BitConverter.GetBytes(int.Parse(((TextBox)item).Text));
                        }
                        else if (attrInfo.IsString)
                        {
                            csoAttr.value = Convert.ToUInt32(int.Parse(((TextBox)item).Text));
                        }
                        else
                        {
                            csoAttr.value_bytes = BitConverter.GetBytes(float.Parse(((TextBox)item).Text));
                        }
                    }
                }
                else
                {
                    continue;
                }

                if (attrInfo.CodedValue > 0 && csoAttr.def_index > 0)
                {
                    savedSelected.CompleteAttributes.Add(attrInfo, csoAttr);
                }
            }

            foreach (var item in tlpInventoryDesc.Controls)
            {
                if (item is ComboBox)
                {
                    if (((ComboBox)item).Name.Contains("cmbSelectedItemType"))
                    {
                        savedSelected.Item = (ItemInfo)((ComboBox)item).SelectedItem;
                    }
                    else if (((ComboBox)item).Name.Contains("cmbSelectedItemQuality"))
                    {
                        savedSelected.Quality = (QualityInfo)((ComboBox)item).SelectedItem;
                    }
                    else if (((ComboBox)item).Name.Contains("cmbSelectedItemRarity"))
                    {
                        savedSelected.Rarity = (RarityInfo)((ComboBox)item).SelectedItem;
                    }
                }
                else if (item is TextBox)
                {
                    foreach (var attr in savedSelected.CompleteAttributes)
                    {
                        // it has name tag
                        if (attr.Key.CodedValue == 111)
                        {
                            if (((TextBox)item).Name.Contains("tbAttrNameTag"))
                            {
                                savedSelected.CustomName = ((TextBox)item).Text;
                            }
                        }
                    }
                }

                savedSelected.IsChanged = true;
            }

            if (clbInventories.SelectedIndex != currentSelectedItemIdx)
            {
                if (currentSelectedItemIdx != -1)
                {
                    oldSelectedItemIdx = currentSelectedItemIdx;
                    currentSelectedItemIdx = clbInventories.SelectedIndex;
                }

                if (savedSelected != null)
                {
                    if (savedSelected.Item.CodedValue > 0)
                    {
                        if (oldSelectedItemIdx < clbInventories.Items.Count)
                        {
                            clbInventories.SelectedIndexChanged -= clbInventories_SelectedIndexChanged;
                            clbInventories.Items[oldSelectedItemIdx] = savedSelected;
                            clbInventories.SelectedIndexChanged += clbInventories_SelectedIndexChanged;
                        }
                    }
                }
            }
            else
            {
                if (savedSelected != null)
                {
                    if (savedSelected.Item.CodedValue > 0)
                    {
                        clbInventories.SelectedIndexChanged -= clbInventories_SelectedIndexChanged;
                        clbInventories.Items[currentSelectedItemIdx] = savedSelected;
                        clbInventories.SelectedIndexChanged += clbInventories_SelectedIndexChanged;
                    }
                }
            }
        }