mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
03182ebd3d
Adds support for Scarlet & Violet. Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com> Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com> Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Generation 7 Evolution Branch Entries
|
|
/// </summary>
|
|
public static class EvolutionSet7
|
|
{
|
|
private const int SIZE = 8;
|
|
|
|
private static EvolutionMethod[] GetMethods(ReadOnlySpan<byte> data, bool LevelUpBypass)
|
|
{
|
|
if (data.Length == 0)
|
|
return Array.Empty<EvolutionMethod>();
|
|
|
|
var result = new EvolutionMethod[data.Length / SIZE];
|
|
int i = 0, offset = 0;
|
|
while (true)
|
|
{
|
|
var entry = data.Slice(offset, SIZE);
|
|
result[i] = ReadEvolution(entry, LevelUpBypass);
|
|
offset += SIZE;
|
|
if (offset >= data.Length)
|
|
return result;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private static EvolutionMethod ReadEvolution(ReadOnlySpan<byte> entry, bool levelUpBypass)
|
|
{
|
|
var type = (EvolutionType)entry[0];
|
|
var arg = ReadUInt16LittleEndian(entry[2..]);
|
|
var species = ReadUInt16LittleEndian(entry[4..]);
|
|
var form = entry[6];
|
|
var level = entry[7];
|
|
var lvlup = !levelUpBypass && type.IsLevelUpRequired() ? (byte)1 : (byte)0;
|
|
return new EvolutionMethod(type, species, form, arg, level, lvlup);
|
|
}
|
|
|
|
public static IReadOnlyList<EvolutionMethod[]> GetArray(BinLinkerAccessor data, bool LevelUpBypass)
|
|
{
|
|
var evos = new EvolutionMethod[data.Length][];
|
|
for (int i = 0; i < evos.Length; i++)
|
|
evos[i] = GetMethods(data[i], LevelUpBypass);
|
|
return evos;
|
|
}
|
|
}
|