mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-12 13:42:36 +00:00
47071b41f3
Existing `get`/`set` logic is flawed in that it doesn't work on Big Endian operating systems, and it allocates heap objects when it doesn't need to. `System.Buffers.Binary.BinaryPrimitives` in the `System.Memory` NuGet package provides both Little Endian and Big Endian methods to read and write data; all the `get`/`set` operations have been reworked to use this new API. This removes the need for PKHeX's manual `BigEndian` class, as all functions are already covered by the BinaryPrimitives API. The `StringConverter` has now been rewritten to accept a Span to read from & write to, no longer requiring a temporary StringBuilder. Other Fixes included: - The Super Training UI for Gen6 has been reworked according to the latest block structure additions. - Cloning a Stadium2 Save File now works correctly (opening from the Folder browser list). - Checksum & Sanity properties removed from parent PKM class, and is now implemented via interface.
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using System;
|
|
using Xunit;
|
|
using FluentAssertions;
|
|
using PKHeX.Core;
|
|
|
|
namespace PKHeX.Tests.Saves
|
|
{
|
|
public static class PokeDex
|
|
{
|
|
[Theory]
|
|
[InlineData(Species.Bulbasaur)]
|
|
[InlineData(Species.Voltorb)]
|
|
[InlineData(Species.Genesect)]
|
|
public static void Gen5(Species species)
|
|
{
|
|
var bw = new SAV5B2W2();
|
|
SetDexSpecies(bw, (int)species, 0x54);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(Species.Landorus)]
|
|
public static void Gen5Form(Species species)
|
|
{
|
|
var bw = new SAV5B2W2();
|
|
SetDexSpecies(bw, (int)species, 0x54);
|
|
CheckDexFlags5(bw, (int)species, 0, 0x54, 0xB);
|
|
}
|
|
|
|
private static void SetDexSpecies(SaveFile sav, int species, int regionSize)
|
|
{
|
|
var pk5 = new PK5 {Species = species, TID = 1337}; // non-shiny
|
|
pk5.Gender = pk5.GetSaneGender();
|
|
|
|
sav.SetBoxSlotAtIndex(pk5, 0);
|
|
|
|
CheckFlags(sav, species, regionSize);
|
|
}
|
|
|
|
private static void CheckFlags(SaveFile sav, int species, int regionSize)
|
|
{
|
|
var dex = sav.PokeDex;
|
|
var data = sav.Data;
|
|
|
|
var bit = species - 1;
|
|
var value = (byte) (1 << (bit & 7));
|
|
var offset = bit >> 3;
|
|
|
|
// 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");
|
|
}
|
|
|
|
private static void CheckDexFlags5(SaveFile sav, int species, int form, int regionSize, int formRegionSize)
|
|
{
|
|
var dex = sav.PokeDex;
|
|
var data = sav.Data;
|
|
|
|
int fc = sav.Personal[species].FormCount;
|
|
var bit = ((SAV5)sav).Zukan.DexFormIndexFetcher(species, fc);
|
|
if (bit < 0)
|
|
return;
|
|
bit += form;
|
|
var value = (byte)(1 << (bit & 7));
|
|
var offset = bit >> 3;
|
|
|
|
// 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");
|
|
}
|
|
}
|
|
}
|