public void LogData()
        {
            InventoryDescription description = new InventoryDescription();

            foreach (InventoryItem item in ItemDeltas)
            {
                if (item.Added > 0)
                {
                    description.Add(EntityId, BlockId, item.Index, item.InventoryType, InvAction.Add, item.Added, item.TypeId.ToString(), item.SubtypeId.ToString());
                }

                if (item.Removed > 0)
                {
                    description.Add(EntityId, BlockId, item.Index, item.InventoryType, InvAction.Remove, item.Removed, item.TypeId.ToString(), item.SubtypeId.ToString());
                }
            }

            SQLQueryData.WriteToDatabase(description);
            ItemDeltas.Clear();
        }
Example #2
0
 public static string GetDescription(IInventorySTUDInstance instance, Dictionary <ulong, Record> map, CASCHandler handler)
 {
     if (instance.Header.description != 0)
     {
         using (Stream descStream = Util.OpenFile(map[instance.Header.description], handler)) {
             STUD description = new STUD(descStream);
             if (description.Instances == null)
             {
                 return(null);
             }
             InventoryDescription desc = description.Instances[0] as InventoryDescription;
             if (desc == null)
             {
                 return(null);
             }
             return(Util.GetString(desc.Header.str, map, handler));
         }
     }
     return(null);
 }
        public InventoryComponent(MyEntity entity)
        {
            Entity = entity;

            if (entity.HasInventory)
            {
                Entity.OnClose += OnClose;

                InventoryDescription description = new InventoryDescription();

                if (Output != null)
                {
                    Output.BeforeContentsChanged += OnBeforeOutputChange;
                    Output.ContentsChanged       += OnOutputChange;

                    if (!(entity is MyCharacter))
                    {
                        foreach (var item in Output.GetItems())
                        {
                            description.Add(EntityId, BlockId, item.ItemId, InvType.Output, InvAction.Current, item.Amount, item.Content.TypeId.ToString(), item.Content.SubtypeId.ToString());
                        }
                    }
                }

                if (Input != null)
                {
                    Input.BeforeContentsChanged += OnBeforeInputChange;
                    Input.ContentsChanged       += OnInputChange;

                    foreach (var item in Input.GetItems())
                    {
                        description.Add(EntityId, BlockId, item.ItemId, InvType.Input, InvAction.Current, item.Amount, item.Content.TypeId.ToString(), item.Content.SubtypeId.ToString());
                    }
                }

                SQLQueryData.WriteToDatabase(description);
            }
        }
Example #4
0
        public static void GetInventoryName(ulong key, bool ex, Dictionary <ulong, Record> map, CASCHandler handler, string heroName)
        {
            Tuple <string, STUD, IInventorySTUDInstance> data = GetInventoryName(key, map, handler);

            if (data == null)
            {
                return;
            }
            string name = data.Item1;
            STUD   stud = data.Item2;
            IInventorySTUDInstance instance = data.Item3;

            if (name == null && instance.Name != stud.Manager.GetName(typeof(CreditItem)))
            {
                Console.Out.WriteLine("\t\t(Untitled-{0:X12}) ({1} {2})", GUID.LongKey(key), instance.Header.rarity, stud.Instances[0].Name);
                return;
            }
#if OUTPUT_STUDINVENTORY
            Stream studStream = Util.OpenFile(map[key], handler);
            string filename   = string.Format("{0}_{1}", instance.Name, name);
            foreach (var c in Path.GetInvalidFileNameChars())
            {
                filename = filename.Replace(c, '_');
            }
            string outFilename = string.Format("./STUDs/Inventory/{0}/{1}.stud", heroName, filename);
            string putPathname = outFilename.Substring(0, outFilename.LastIndexOf('/'));
            Directory.CreateDirectory(putPathname);
            Stream OutWriter = File.Create(outFilename);
            studStream.CopyTo(OutWriter);
            OutWriter.Close();
            studStream.Close();
#endif

            string addt = string.Empty;

            if (instance.Name == stud.Manager.GetName(typeof(CreditItem)))
            {
                CreditItem credits = (CreditItem)instance;
                name = $"{credits.Data.value} Credits";
            }
            if (instance.Name == stud.Manager.GetName(typeof(WeaponSkinItem)))
            {
                WeaponSkinItem weapon = (WeaponSkinItem)instance;
                addt = $" Index {weapon.Data.index}";
            }

            if (ex)
            {
                Console.Out.WriteLine("\t\t{0} ({1} {2} in file {3:X16}){4}", name, instance.Header.rarity, stud.Instances[0].Name, GUID.LongKey(key), addt);
            }
            else
            {
                Console.Out.WriteLine("\t\t{0} ({1} {2}){3}", name, instance.Header.rarity, stud.Instances[0].Name, addt);
            }

            if (instance.Header.description != 0)
            {
                using (Stream descStream = Util.OpenFile(map[instance.Header.description], handler)) {
                    STUD description = new STUD(descStream);
                    if (description.Instances == null)
                    {
                        return;
                    }
                    InventoryDescription desc = description.Instances[0] as InventoryDescription;
                    if (desc == null)
                    {
                        return;
                    }
                    string descriptionStr = Util.GetString(desc.Header.str, map, handler);
                    if (!string.IsNullOrEmpty(descriptionStr))
                    {
                        Console.Out.WriteLine("\t\t\t{0}", descriptionStr);
                    }
                }
            }
        }