2022-08-27 06:43:36 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using Xunit;
|
2019-07-11 07:13:52 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
namespace PKHeX.Core.Tests.Saves;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public static class PokeDex
|
2019-07-11 07:13:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData(Species.Bulbasaur)]
|
|
|
|
[InlineData(Species.Voltorb)]
|
|
|
|
[InlineData(Species.Genesect)]
|
|
|
|
public static void Gen5(Species species)
|
2019-07-11 07:13:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var bw = new SAV5B2W2();
|
2022-08-27 06:43:36 +00:00
|
|
|
SetDexSpecies(bw, (ushort)species, 0x54);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData(Species.Landorus)]
|
|
|
|
public static void Gen5Form(Species species)
|
|
|
|
{
|
|
|
|
var bw = new SAV5B2W2();
|
2022-08-27 06:43:36 +00:00
|
|
|
SetDexSpecies(bw, (ushort)species, 0x54);
|
|
|
|
CheckDexFlags5(bw, (ushort)species, 0, 0x54, 0xB);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static void SetDexSpecies(SaveFile sav, ushort species, int regionSize)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var pk5 = new PK5 {Species = species, TID16 = 1337}; // non-shiny
|
2022-06-18 18:04:24 +00:00
|
|
|
pk5.Gender = pk5.GetSaneGender();
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
sav.SetBoxSlotAtIndex(pk5, 0);
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CheckFlags(sav, species, regionSize);
|
|
|
|
}
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static void CheckFlags(SaveFile sav, ushort species, int regionSize)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var dex = sav.PokeDex;
|
|
|
|
var data = sav.Data;
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var bit = species - 1;
|
|
|
|
var value = (byte) (1 << (bit & 7));
|
|
|
|
var offset = bit >> 3;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check the regular flag regions.
|
|
|
|
var span = data.AsSpan(dex + 0x08);
|
|
|
|
span[offset].Should().Be(value, "caught flag");
|
|
|
|
span[offset + regionSize].Should().Be(value, "seen flag");
|
|
|
|
span[offset + regionSize + (regionSize * 4)].Should().Be(value, "displayed flag");
|
|
|
|
}
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-08-27 19:53:30 +00:00
|
|
|
private static void CheckDexFlags5(SaveFile sav, ushort species, byte form, int regionSize, int formRegionSize)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var dex = sav.PokeDex;
|
|
|
|
var data = sav.Data;
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
var fc = sav.Personal[species].FormCount;
|
2022-06-18 18:04:24 +00:00
|
|
|
var bit = ((SAV5)sav).Zukan.DexFormIndexFetcher(species, fc);
|
|
|
|
if (bit < 0)
|
|
|
|
return;
|
|
|
|
bit += form;
|
|
|
|
var value = (byte)(1 << (bit & 7));
|
|
|
|
var offset = bit >> 3;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check the form flag regions.
|
|
|
|
var span = data.AsSpan(dex + 0x08 + (regionSize * 9));
|
|
|
|
span[offset].Should().Be(value, "seen flag");
|
|
|
|
span[offset + (formRegionSize * 2)].Should().Be(value, "displayed flag");
|
2019-07-11 07:13:52 +00:00
|
|
|
}
|
|
|
|
}
|