Ejemplo n.º 1
0
      public int GetPokemonNumber(string input) {
         var cachedPokenames = model.GetOptions(PokemonNameTable);

         if (input.StartsWith(GroupStart)) input = input.Substring(1, input.Length - 2);
         input = input.ToLower();
         var names = cachedPokenames.Select(name => name.Trim('"').ToLower()).ToList();
         return names.IndexOfPartial(input);
      }
Ejemplo n.º 2
0
        public override IDataFormat CreateDataFormat(IDataModel data, int index)
        {
            Debug.Assert(data == model);
            var moveNames  = model.GetOptions(HardcodeTablesModel.MoveNamesTable);
            var position   = index - Start;
            var groupStart = position % 2 == 1 ? position - 1 : position;

            position -= groupStart;
            var value = data.ReadMultiByteValue(Start + groupStart, 2);

            var(level, move) = SplitToken(value);
            var moveName = moveNames.Count > move ? moveNames[move] : move.ToString();

            return(new PlmItem(groupStart + Start, position, level, move, moveName));
        }
Ejemplo n.º 3
0
        public PLMRun(IDataModel dataModel, int start, SortedSpan <int> pointerSources = null) : base(start, pointerSources)
        {
            model = dataModel;
            var moveNames = dataModel.GetOptions(HardcodeTablesModel.MoveNamesTable);

            Length = 1;
            for (int i = Start; i < model.Count; i += 2)
            {
                var value = model.ReadMultiByteValue(i, 2);
                if (value == 0xFFFF)
                {
                    Length = i - Start + 2;
                    break;
                }
                // validate value
                var(level, move) = SplitToken(value);
                if (level > 101 || level < 1)
                {
                    break;
                }
                if (move > moveNames.Count)
                {
                    break;
                }
            }
        }
        public override string ToText(IDataModel rawData, int offset, bool deep = false)
        {
            var result    = "(";
            var bitOffset = 0;

            foreach (var segment in Elements)
            {
                if (string.IsNullOrEmpty(segment.Name))
                {
                    // don't append unnamed segments
                }
                else if (!string.IsNullOrEmpty(segment.SourceName))
                {
                    var options = rawData.GetOptions(segment.SourceName);
                    var value   = segment.Read(rawData, offset, bitOffset);
                    var text    = options.Count > value ? options[value] : value.ToString();
                    result += text.Contains(" ") && !text.Contains("\"") ? '"' + text + '"' : text;
                    result += " ";
                }
                else if (segment.BitWidth == 1)
                {
                    result += segment.Read(rawData, offset, bitOffset) == 1 ? "true " : "false ";
                }
                else
                {
                    result += segment.Read(rawData, offset, bitOffset) + " ";
                }
                bitOffset += segment.BitWidth;
            }
            return(result.Trim() + ")");
        }
Ejemplo n.º 5
0
        public string Convert(IDataModel model, int value)
        {
            var byteText = value.ToString($"X{Length * 2}");

            if (string.IsNullOrEmpty(EnumTableName))
            {
                return(byteText);
            }
            var table = model.GetOptions(EnumTableName);

            if ((table?.Count ?? 0) <= value)
            {
                return(byteText);
            }
            return(table[value]);
        }
Ejemplo n.º 6
0
        public void AppendTo(IDataModel model, StringBuilder text, int start, int length, bool deep)
        {
            var moveNames = model.GetOptions(HardcodeTablesModel.MoveNamesTable);

            for (int i = 0; i < length && i < Length; i += 2)
            {
                if (i > 0)
                {
                    text.Append(" ");
                }
                if (i + start - Start == Length - 2)
                {
                    text.Append("[]"); continue;
                }
                var(level, move) = SplitToken(model.ReadMultiByteValue(start + i, 2));
                var moveName = moveNames.Count > move ? moveNames[move] : move.ToString();
                text.Append($"{level} {moveName},");
            }
        }
        public static IEnumerable <string> GetOptions(IDataModel model, string enumName)
        {
            if (int.TryParse(enumName, out var result))
            {
                return(result.Range().Select(i => i.ToString()));
            }
            IEnumerable <string> options = model.GetOptions(enumName);

            // we _need_ options for the table tool
            // if we have none, just create "0", "1", ..., "n-1" based on the length of the EnumName table.
            if (!options.Any())
            {
                if (model.GetNextRun(model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, enumName)) is ITableRun tableRun)
                {
                    options = tableRun.ElementCount.Range().Select(i => i.ToString());
                }
            }

            return(options);
        }
        public static bool TryParse(string enumName, IDataModel model, string text, out int value)
        {
            var options = model.GetOptions(enumName);

            return(TryMatch(text, options, out value));
        }
Ejemplo n.º 9
0
            public TeamData(IDataModel model, string[] lines, bool showFullIVByteRange)
            {
                this.model = model;
                this.showFullIVByteRange = showFullIVByteRange;
                var currentPokemonMoveCount = 0;
                var moveNames    = model.GetOptions(HardcodeTablesModel.MoveNamesTable);
                var itemNames    = model.GetOptions(HardcodeTablesModel.ItemsTableName);
                var pokemonNames = model.GetOptions(HardcodeTablesModel.PokemonNameTable);

                foreach (var line in lines)
                {
                    if (line.Trim() is "")
                    {
                        continue;
                    }
                    if (line.Trim().StartsWith("-"))
                    {
                        if (pokemons.Count == 0)
                        {
                            continue;
                        }
                        if (currentPokemonMoveCount > 3)
                        {
                            continue;
                        }
                        MovesIncluded = true;
                        var move      = line.Trim().Substring(1).Trim(' ', '"');
                        var moveIndex = moveNames.IndexOfPartial(move);
                        if (moveIndex < 0)
                        {
                            moveIndex = 0;
                        }
                        moves[(pokemons.Count - 1) * 4 + currentPokemonMoveCount] = moveIndex;
                        currentPokemonMoveCount++;
                    }
                    else
                    {
                        if (pokemons.Count == 6)
                        {
                            continue;
                        }

                        var levelTokenized = line.Split(new[] { ' ' }, 2);
                        if (levelTokenized.Length != 2)
                        {
                            continue;
                        }
                        if (!int.TryParse(levelTokenized[0], out int level))
                        {
                            continue;
                        }
                        levels.Add(level);

                        var itemTokenized = levelTokenized[1].Split(new[] { '@' }, 2);
                        AddItem(itemNames, items, itemTokenized);

                        var ivTokenized = itemTokenized[0].Split(new[] { '(' }, 2);
                        AddIV(ivs, ivTokenized);

                        var pokemon      = ivTokenized[0].Trim();
                        var pokemonIndex = pokemonNames.IndexOfPartial(pokemon);
                        if (pokemonIndex < 0)
                        {
                            pokemonIndex = 0;
                        }
                        pokemons.Add(pokemonIndex);
                        moves.AddRange(new[] { 0, 0, 0, 0 });
                        currentPokemonMoveCount = 0;
                    }
                }

                if (pokemons.Count == 0)
                {
                    pokemons.Add(0);
                    ivs.Add(0);
                    levels.Add(0);
                    moves.AddRange(new[] { 0, 0, 0, 0 });
                }
            }