Beispiel #1
0
        private void DumpPublishedRequirements(StreamWriter stream, DumpAchievementItem dumpAchievement,
                                               RequirementGroupViewModel requirementGroupViewModel, NumberFormat numberFormat)
        {
            bool      needsAmpersand = false;
            const int MaxWidth       = 106; // 120 - "    trigger = ".Length
            int       width          = MaxWidth;

            var requirementEnumerator = requirementGroupViewModel.Requirements.GetEnumerator();

            while (requirementEnumerator.MoveNext())
            {
                if (String.IsNullOrEmpty(requirementEnumerator.Current.Definition))
                {
                    continue;
                }

                var  addSources  = new StringBuilder();
                var  subSources  = new StringBuilder();
                var  addHits     = new StringBuilder();
                bool isCombining = true;
                do
                {
                    switch (requirementEnumerator.Current.Requirement.Type)
                    {
                    case RequirementType.AddSource:
                        requirementEnumerator.Current.Requirement.Left.AppendString(addSources, numberFormat);
                        addSources.Append(" + ");
                        break;

                    case RequirementType.SubSource:
                        subSources.Append(" - ");
                        requirementEnumerator.Current.Requirement.Left.AppendString(subSources, numberFormat);
                        break;

                    case RequirementType.AddHits:
                        requirementEnumerator.Current.Requirement.AppendString(addHits, numberFormat);
                        addHits.Append(" || ");
                        break;

                    default:
                        isCombining = false;
                        break;
                    }

                    if (!isCombining)
                    {
                        break;
                    }

                    if (!requirementEnumerator.MoveNext())
                    {
                        return;
                    }
                } while (true);

                var definition = new StringBuilder();
                requirementEnumerator.Current.Requirement.AppendString(definition, numberFormat,
                                                                       addSources.Length > 0 ? addSources.ToString() : null,
                                                                       subSources.Length > 0 ? subSources.ToString() : null,
                                                                       addHits.Length > 0 ? addHits.ToString() : null);

                foreach (var memoryItem in dumpAchievement.MemoryAddresses.Where(m => !String.IsNullOrEmpty(m.FunctionName)))
                {
                    var memoryReference = Field.GetMemoryReference(memoryItem.Address, memoryItem.Size);
                    var functionCall    = memoryItem.FunctionName + "()";
                    definition.Replace(memoryReference, functionCall);
                }

                if (needsAmpersand)
                {
                    stream.Write(" && ");
                    width -= 4;
                }
                else
                {
                    needsAmpersand = true;
                }

                while (definition.Length > MaxWidth)
                {
                    var index = width;
                    while (index > 0 && definition[index] != ' ')
                    {
                        index--;
                    }

                    stream.Write(definition.ToString().Substring(0, index));
                    stream.WriteLine();
                    stream.Write("              ");
                    definition.Remove(0, index);
                    width = MaxWidth;
                }

                if (width - definition.Length < 0)
                {
                    stream.WriteLine();
                    stream.Write("              ");
                    width = MaxWidth;
                }

                width -= definition.Length;
                stream.Write(definition.ToString());
            }
        }
Beispiel #2
0
        private void LoadGame(int gameId, string raCacheDirectory)
        {
            _game = new GameViewModel(GameId.Value.GetValueOrDefault(), "", raCacheDirectory);
            _game.PopulateEditorList(null);
            DialogTitle = "New Script - " + _game.Title;

            _achievements.Clear();
            _ticketNotes.Clear();
            _memoryItems.Clear();
            MemoryAddresses.Rows.Clear();

            var unofficialAchievements = new List <DumpAchievementItem>();

            foreach (var achievement in _game.Editors.OfType <GeneratedAchievementViewModel>())
            {
                AchievementViewModel source = achievement.Core;
                if (source.Achievement == null)
                {
                    source = achievement.Unofficial;
                    if (source.Achievement == null)
                    {
                        continue;
                    }
                }

                var dumpAchievement = new DumpAchievementItem(achievement.Id, source.Title.Text);
                if (achievement.Core.Achievement == null)
                {
                    dumpAchievement.IsUnofficial = true;
                    unofficialAchievements.Add(dumpAchievement);
                }
                else
                {
                    _achievements.Add(dumpAchievement);
                }

                foreach (var group in source.RequirementGroups)
                {
                    foreach (var requirement in group.Requirements)
                    {
                        if (requirement.Requirement == null)
                        {
                            continue;
                        }

                        if (requirement.Requirement.Left != null && requirement.Requirement.Left.IsMemoryReference)
                        {
                            var memoryItem = AddMemoryAddress(requirement.Requirement.Left);
                            if (memoryItem != null && !dumpAchievement.MemoryAddresses.Contains(memoryItem))
                            {
                                dumpAchievement.MemoryAddresses.Add(memoryItem);
                            }
                        }

                        if (requirement.Requirement.Right != null && requirement.Requirement.Right.IsMemoryReference)
                        {
                            var memoryItem = AddMemoryAddress(requirement.Requirement.Right);
                            if (memoryItem != null && !dumpAchievement.MemoryAddresses.Contains(memoryItem))
                            {
                                dumpAchievement.MemoryAddresses.Add(memoryItem);
                            }
                        }
                    }
                }

                dumpAchievement.IsSelected       = true;
                dumpAchievement.PropertyChanged += DumpAchievement_PropertyChanged;
            }

            foreach (var unofficialAchievement in unofficialAchievements)
            {
                _achievements.Add(unofficialAchievement);
            }

            foreach (var kvp in _game.Notes)
            {
                FieldSize size  = FieldSize.Byte;
                Token     token = new Token(kvp.Value, 0, kvp.Value.Length);
                if (token.Contains("16-bit", StringComparison.OrdinalIgnoreCase) ||
                    token.Contains("16 bit", StringComparison.OrdinalIgnoreCase))
                {
                    size = FieldSize.Word;
                }
                else if (token.Contains("32-bit", StringComparison.OrdinalIgnoreCase) ||
                         token.Contains("32 bit", StringComparison.OrdinalIgnoreCase))
                {
                    size = FieldSize.DWord;
                }

                AddMemoryAddress(new Field {
                    Size = size, Type = FieldType.MemoryAddress, Value = (uint)kvp.Key
                });
            }

            if (_achievements.Count == 0)
            {
                SelectedCodeNotesFilter = CodeNoteFilter.All;
            }

            UpdateMemoryGrid();

            IsGameLoaded     = true;
            GameId.IsEnabled = false;

            if (_achievements.Count > 0)
            {
                ServiceRepository.Instance.FindService <IBackgroundWorkerService>().RunAsync(MergeOpenTickets);
            }
        }