2018-08-02 01:30:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-02-28 04:57:24 +00:00
|
|
|
|
using System.Linq;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
public abstract class EggMoves
|
|
|
|
|
{
|
|
|
|
|
protected int Count;
|
|
|
|
|
public int[] Moves;
|
|
|
|
|
public int FormTableIndex;
|
2018-06-09 23:04:06 +00:00
|
|
|
|
|
|
|
|
|
public bool GetHasEggMove(int move) => Moves.Contains(move);
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
2017-02-28 04:57:24 +00:00
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
public sealed class EggMoves2 : EggMoves
|
2017-02-28 04:57:24 +00:00
|
|
|
|
{
|
|
|
|
|
private EggMoves2(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
Count = data.Length;
|
|
|
|
|
Moves = data.Select(i => (int) i).ToArray();
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static EggMoves[] GetArray(byte[] data, int count)
|
2017-02-28 04:57:24 +00:00
|
|
|
|
{
|
|
|
|
|
int[] ptrs = new int[count+1];
|
2018-08-03 03:11:42 +00:00
|
|
|
|
int baseOffset = (data[1] << 8 | data[0]) - (count * 2);
|
2017-02-28 04:57:24 +00:00
|
|
|
|
for (int i = 1; i < ptrs.Length; i++)
|
2018-08-03 03:11:42 +00:00
|
|
|
|
{
|
|
|
|
|
var ofs = (i - 1) * 2;
|
|
|
|
|
ptrs[i] = (data[ofs + 1] << 8 | data[ofs]) - baseOffset;
|
|
|
|
|
}
|
2017-02-28 04:57:24 +00:00
|
|
|
|
|
2017-03-31 07:04:29 +00:00
|
|
|
|
EggMoves[] entries = new EggMoves[count + 1];
|
2018-08-03 03:11:42 +00:00
|
|
|
|
entries[0] = new EggMoves2(Array.Empty<byte>());
|
2017-02-28 04:57:24 +00:00
|
|
|
|
for (int i = 1; i < entries.Length; i++)
|
|
|
|
|
entries[i] = new EggMoves2(data.Skip(ptrs[i]).TakeWhile(b => b != 0xFF).ToArray());
|
|
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
|
|
|
|
public sealed class EggMoves6 : EggMoves
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
private EggMoves6(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
if (data.Length < 2 || data.Length % 2 != 0)
|
2018-08-02 01:30:51 +00:00
|
|
|
|
{ Count = 0; Moves = Array.Empty<int>(); return; }
|
2016-11-08 16:43:57 +00:00
|
|
|
|
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
|
|
|
|
{
|
|
|
|
|
Moves = new int[Count = br.ReadUInt16()];
|
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
|
Moves[i] = br.ReadUInt16();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static EggMoves[] GetArray(byte[][] entries)
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-03-31 07:04:29 +00:00
|
|
|
|
EggMoves[] data = new EggMoves[entries.Length];
|
2016-11-08 16:43:57 +00:00
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
data[i] = new EggMoves6(entries[i]);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
|
|
|
|
public sealed class EggMoves7 : EggMoves
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
private EggMoves7(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
if (data.Length < 2 || data.Length % 2 != 0)
|
2018-08-02 01:30:51 +00:00
|
|
|
|
{ Count = 0; Moves = Array.Empty<int>(); return; }
|
2016-11-08 16:43:57 +00:00
|
|
|
|
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
|
|
|
|
{
|
|
|
|
|
FormTableIndex = br.ReadUInt16();
|
|
|
|
|
Count = br.ReadUInt16();
|
|
|
|
|
Moves = new int[Count];
|
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
|
Moves[i] = br.ReadUInt16();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static EggMoves[] GetArray(byte[][] entries)
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-03-31 07:04:29 +00:00
|
|
|
|
EggMoves[] data = new EggMoves[entries.Length];
|
2016-11-08 16:43:57 +00:00
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
data[i] = new EggMoves7(entries[i]);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|