Set species flag on ck3/xk3->pk3

Make GetG3Species return ushort

Fixes regression caused by 5942a74147
Copying SpeciesID3 instead of Species is fine as it skips the map/unmap step, but it also skips the setting of the HasSpecies flag. So we'll just set it in the individual ConvertToPK3 methods.
This commit is contained in:
Kurt 2022-08-04 09:53:15 -07:00
parent bab2cc11d6
commit ec45ca1a83
9 changed files with 21 additions and 19 deletions

View file

@ -35,7 +35,7 @@ public sealed class CK3 : G3PKM, IShadowPKM
// Future Attributes
public override ushort SpeciesID3 { get => ReadUInt16BigEndian(Data.AsSpan(0x00)); set => WriteUInt16BigEndian(Data.AsSpan(0x00), value); } // raw access
public override int Species { get => SpeciesConverter.GetG4Species(SpeciesID3); set => SpeciesID3 = (ushort)SpeciesConverter.GetG3Species(value); }
public override int Species { get => SpeciesConverter.GetG4Species(SpeciesID3); set => SpeciesID3 = SpeciesConverter.GetG3Species(value); }
// 02-04 unused
public override uint PID { get => ReadUInt32BigEndian(Data.AsSpan(0x04)); set => WriteUInt32BigEndian(Data.AsSpan(0x04), value); }
public override int Version { get => GetGBAVersionID(Data[0x08]); set => Data[0x08] = GetGCVersionID(value); }
@ -192,6 +192,7 @@ public sealed class CK3 : G3PKM, IShadowPKM
public PK3 ConvertToPK3()
{
var pk = ConvertTo<PK3>();
pk.FlagHasSpecies = pk.SpeciesID3 != 0; // Update Flag
pk.RefreshChecksum();
return pk;
}

View file

@ -76,8 +76,8 @@ public sealed class PK3 : G3PKM, ISanityChecksum
get => SpeciesConverter.GetG4Species(SpeciesID3);
set
{
SpeciesID3 = (ushort)SpeciesConverter.GetG3Species(value);
FlagHasSpecies = Species > 0;
var s3 = SpeciesConverter.GetG3Species(value);
FlagHasSpecies = (SpeciesID3 = s3) != 0;
}
}

View file

@ -25,7 +25,7 @@ public static class SpeciesConverter
/// </summary>
/// <param name="species">National Dex ID</param>
/// <returns>Generation 3 species ID.</returns>
public static int GetG3Species(int species) => (uint)species >= table3_Internal.Length ? 0 : table3_Internal[species];
public static ushort GetG3Species(int species) => (uint)species >= table3_Internal.Length ? (ushort)0 : table3_Internal[species];
/// <summary>
/// Converts Generation 3 species ID to National Dex ID.

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using static System.Buffers.Binary.BinaryPrimitives;
@ -32,7 +32,7 @@ public sealed class XK3 : G3PKM, IShadowPKM
public Span<byte> NicknameCopy_Trash => Data.AsSpan(0x64, 22);
public override ushort SpeciesID3 { get => ReadUInt16BigEndian(Data.AsSpan(0x00)); set => WriteUInt16BigEndian(Data.AsSpan(0x00), value); } // raw access
public override int Species { get => SpeciesConverter.GetG4Species(SpeciesID3); set => SpeciesID3 = (ushort)SpeciesConverter.GetG3Species(value); }
public override int Species { get => SpeciesConverter.GetG4Species(SpeciesID3); set => SpeciesID3 = SpeciesConverter.GetG3Species(value); }
public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem);
public override int HeldItem { get => ReadUInt16BigEndian(Data.AsSpan(0x02)); set => WriteUInt16BigEndian(Data.AsSpan(0x02), (ushort)value); }
public override int Stat_HPCurrent { get => ReadUInt16BigEndian(Data.AsSpan(0x04)); set => WriteUInt16BigEndian(Data.AsSpan(0x04), (ushort)value); }
@ -216,6 +216,7 @@ public sealed class XK3 : G3PKM, IShadowPKM
if (IsOriginXD())
pk.FatefulEncounter = true;
}
pk.FlagHasSpecies = pk.SpeciesID3 != 0; // Update Flag
pk.RefreshChecksum();
return pk;
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
@ -21,7 +21,7 @@ public abstract class ShadowInfoEntryXD
// Gen3 Species ID
public ushort RawSpecies { get => ReadUInt16BigEndian(Data.AsSpan(0x1A)); set => WriteUInt16BigEndian(Data.AsSpan(0x1A), value); }
public int Species { get => SpeciesConverter.GetG4Species(RawSpecies); set => RawSpecies = (ushort)SpeciesConverter.GetG3Species(value); }
public int Species { get => SpeciesConverter.GetG4Species(RawSpecies); set => RawSpecies = SpeciesConverter.GetG3Species(value); }
public uint PID { get => ReadUInt32BigEndian(Data.AsSpan(0x1C)); set => WriteUInt32BigEndian(Data.AsSpan(0x1C), value); }
public int Purification { get => ReadInt32BigEndian(Data.AsSpan(0x24)); set => WriteInt32BigEndian(Data.AsSpan(0x24), value); }

View file

@ -1,4 +1,4 @@
using System;
using System;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
@ -37,7 +37,7 @@ public sealed class Roamer3 : IContestStats, IContestStatsMutable
public int Species
{
get => SpeciesConverter.GetG4Species(ReadInt16LittleEndian(Data.AsSpan(Offset + 8)));
set => WriteInt16LittleEndian(Data.AsSpan(Offset + 8), (short)SpeciesConverter.GetG3Species(value));
set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 8), SpeciesConverter.GetG3Species(value));
}
public int HP_Current

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using static System.Buffers.Binary.BinaryPrimitives;
@ -83,15 +83,15 @@ public sealed class StrategyMemoEntry
{
get
{
int val = ReadUInt16BigEndian(Data.AsSpan(0)) & 0x1FF;
var val = ReadUInt16BigEndian(Data.AsSpan(0)) & 0x1FF;
return SpeciesConverter.GetG4Species(val);
}
set
{
value = SpeciesConverter.GetG3Species(value);
int cval = ReadUInt16BigEndian(Data.AsSpan(0));
cval &= 0xE00; value &= 0x1FF; cval |= value;
WriteUInt16BigEndian(Data.AsSpan(0x00), (ushort)cval);
var val = SpeciesConverter.GetG3Species(value);
var cval = ReadUInt16BigEndian(Data.AsSpan(0));
cval &= 0xE00; val &= 0x1FF; cval |= val;
WriteUInt16BigEndian(Data.AsSpan(0x00), cval);
}
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using static PKHeX.Core.Move;
using static PKHeX.Core.Species;
@ -32,7 +32,7 @@ public sealed class Swarm3
public Swarm3(Species species, byte level, byte map, Move m1, Move m2 = 0, Move m3 = 0, Move m4 = 0) : this(new byte[SIZE])
{
Gen3Species = (ushort)SpeciesConverter.GetG3Species((int)species);
Gen3Species = SpeciesConverter.GetG3Species((int)species);
Level = level;
MapNum = map;
Move1 = (ushort)m1;

View file

@ -75,7 +75,7 @@ public partial class SAV_Misc3 : Form
{
var species = (ushort) WinFormsUtil.GetIndex(cba[i]);
var g3Species = SpeciesConverter.GetG3Species(species);
SAV.SetWork(0x43 + i, (ushort)g3Species);
SAV.SetWork(0x43 + i, g3Species);
}
}