Ejemplo n.º 1
0
        internal static ItemTrackerState FromItemLocationMap(IEnumerable <ItemLocation> itemLocations)
        {
            var unlockedProgressionItems = itemLocations
                                           .Where(l => l.IsPickedUp && l.ItemInfo.IsProgression)
                                           .Select(l => l.ItemInfo)
                                           .ToArray();

            var obtainedProgressiveItems = unlockedProgressionItems
                                           .OfType <ProgressiveItemInfo>();

            var obtainedSingleItems = unlockedProgressionItems
                                      .Where(i => !(i is ProgressiveItemInfo));

            var obtainedItemIdentifiers = obtainedSingleItems
                                          .Select(i => i.Identifier)
                                          .Concat(obtainedProgressiveItems.SelectMany(pi => pi.GetAllUnlockedItems().Select(i => i.Identifier)));

            var trackerState = new ItemTrackerState();

            foreach (var item in obtainedItemIdentifiers)
            {
                SetMemberForItem(trackerState, item);
            }

            return(trackerState);
        }
Ejemplo n.º 2
0
        static void SetMemberForItem(ItemTrackerState trackerState, ItemIdentifier itemInfo)
        {
            if (!ItemToMemberMap.TryGetValue(itemInfo, out var expression))
            {
                return;
            }

            var memberExpression = (MemberExpression)expression.Body;
            var fieldInfo        = (FieldInfo)memberExpression.Member;

            fieldInfo.SetValue(trackerState, true);
        }
Ejemplo n.º 3
0
        public static void UpdateState(ItemTrackerState state)
        {
            var formatter = new BinaryFormatter();

            using (var fileStream = new FileStream(StateFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, FileSize))
            {
                fileStream.SetLength(FileSize);

                using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
                    using (var stream = memmoryMappedFIle.CreateViewStream(0, 0, MemoryMappedFileAccess.Write))
                        formatter.Serialize(stream, state);
            }
        }
Ejemplo n.º 4
0
        public static ItemTrackerState LoadState()
        {
            var formatter = new BinaryFormatter();

            try
            {
                using (var fileStream = new FileStream(StateFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, FileSize))
                {
                    fileStream.SetLength(FileSize);

                    using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
                        using (var stream = memmoryMappedFIle.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
                            lastSuccessfullRead = (ItemTrackerState)formatter.Deserialize(stream);
                }
            }
            catch
            {
            }

            return(lastSuccessfullRead);
        }