2022-09-07 22:49:53 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies the specific origin data of <see cref="GameVersion.CXD"/> encounters.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class CXDVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Misc;
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = data.Entity;
|
2023-08-12 23:01:16 +00:00
|
|
|
if (data.EncounterMatch is EncounterStatic3Colo { IsColoStarter: true })
|
|
|
|
VerifyStarterColo(data);
|
|
|
|
else if (data.EncounterMatch is EncounterStatic3XD { Species: (ushort)Species.Eevee })
|
|
|
|
VerifyStarterXD(data);
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.OT_Gender == 1)
|
|
|
|
data.AddLine(GetInvalid(LG3OTGender, CheckIdentifier.Trainer));
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyStarterColo(LegalityAnalysis data)
|
|
|
|
{
|
|
|
|
var type = data.Info.PIDIV.Type;
|
|
|
|
if (type is not (PIDType.CXD or PIDType.CXDAnti or PIDType.CXD_ColoStarter))
|
|
|
|
return; // already flagged as invalid
|
|
|
|
if (type != PIDType.CXD_ColoStarter)
|
|
|
|
data.AddLine(GetInvalid(LEncConditionBadRNGFrame, CheckIdentifier.PID));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void VerifyStarterXD(LegalityAnalysis data)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var (type, seed) = data.Info.PIDIV;
|
|
|
|
if (type is not (PIDType.CXD or PIDType.CXDAnti or PIDType.CXD_ColoStarter))
|
|
|
|
return; // already flagged as invalid
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-09-07 22:49:53 +00:00
|
|
|
bool valid;
|
2023-08-12 23:01:16 +00:00
|
|
|
var pk = data.Entity;
|
|
|
|
if (type == PIDType.CXD_ColoStarter && pk.Species == (int)Species.Umbreon)
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
// reset pidiv type to be CXD -- ColoStarter is same correlation as Eevee->Umbreon
|
|
|
|
data.Info.PIDIV = new PIDIV(PIDType.CXD, seed);
|
|
|
|
valid = true;
|
2022-09-07 22:49:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
valid = LockFinder.IsXDStarterValid(seed, pk.TID16, pk.SID16);
|
|
|
|
if (valid) // unroll seed to origin that generated TID16/SID16->pkm
|
|
|
|
data.Info.PIDIV = new PIDIV(PIDType.CXD, XDRNG.Prev4(seed));
|
2022-09-07 22:49:53 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!valid)
|
|
|
|
data.AddLine(GetInvalid(LEncConditionBadRNGFrame, CheckIdentifier.PID));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
|
|
|
}
|