2018-05-19 19:07:50 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-05-19 19:07:50 +00:00
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 4 Evolution Branch Entries
|
|
|
|
/// </summary>
|
2019-03-23 17:36:28 +00:00
|
|
|
public static class EvolutionSet4
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
private static EvolutionMethod GetMethod(ReadOnlySpan<byte> data)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
var method = data[0]; // other byte unnecessary
|
|
|
|
int arg = ReadUInt16LittleEndian(data[2..]);
|
|
|
|
int species = ReadUInt16LittleEndian(data[4..]);
|
2018-05-19 19:07:50 +00:00
|
|
|
|
|
|
|
if (method == 0)
|
2021-08-21 23:51:50 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(method));
|
2019-03-23 08:01:04 +00:00
|
|
|
|
|
|
|
// To have the same structure as gen 6
|
2018-05-19 19:07:50 +00:00
|
|
|
// Gen 4 Method 6 is Gen 6 Method 7, G4 7 = G6 8, and so on
|
|
|
|
if (method > 6)
|
|
|
|
method++;
|
|
|
|
|
2020-01-25 23:42:17 +00:00
|
|
|
var lvl = EvolutionSet6.EvosWithArg.Contains(method) ? 0 : arg;
|
2022-04-24 04:33:17 +00:00
|
|
|
return new EvolutionMethod(method, species, argument: arg, level: (byte)lvl);
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
public static IReadOnlyList<EvolutionMethod[]> GetArray(ReadOnlySpan<byte> data)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
const int bpe = 6; // bytes per evolution entry
|
2019-03-23 08:01:04 +00:00
|
|
|
const int entries = 7; // amount of entries per species
|
|
|
|
const int size = (entries * bpe) + 2; // bytes per species entry, + 2 alignment bytes
|
2018-05-19 19:07:50 +00:00
|
|
|
|
2019-03-23 17:36:28 +00:00
|
|
|
var evos = new EvolutionMethod[data.Length / size][];
|
2019-03-23 08:01:04 +00:00
|
|
|
for (int i = 0; i < evos.Length; i++)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
int offset = i * size;
|
2019-03-23 08:01:04 +00:00
|
|
|
int count = 0;
|
|
|
|
for (; count < entries; count++)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2019-03-23 08:01:04 +00:00
|
|
|
var methodOffset = offset + (count * bpe);
|
|
|
|
var method = data[methodOffset];
|
|
|
|
if (method == 0)
|
2018-05-19 19:07:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-23 08:01:04 +00:00
|
|
|
if (count == 0)
|
|
|
|
{
|
2019-03-23 17:36:28 +00:00
|
|
|
evos[i] = Array.Empty<EvolutionMethod>();
|
2019-03-23 08:01:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var set = new EvolutionMethod[count];
|
|
|
|
for (int j = 0; j < set.Length; j++)
|
2022-01-03 05:35:59 +00:00
|
|
|
set[j] = GetMethod(data.Slice(offset + (j * bpe), bpe));
|
2019-03-23 17:36:28 +00:00
|
|
|
evos[i] = set;
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
|
|
|
return evos;
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
}
|