From 4aeb3ce81828e9f9e0ef899a7d634876b51d50bf Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 11 May 2017 00:32:31 -0700 Subject: [PATCH] Add cxd starter TID/SID correlation check --- PKHeX/Legality/Checks.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index 24669bbfa..9d049437c 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -1365,13 +1365,32 @@ namespace PKHeX.Core { // Starters have a correlation to the Trainer ID numbers var spec = ((EncounterStatic) EncounterMatch).Species; + var rev = int.MinValue; switch (spec) { + // pidiv reversed 5x yields SID, again == TID. +7 if another PKM is generated case 133: // Eevee - case 196: // Espeon - case 197: // Umbreon - break; // todo + rev = 5; break; + + case 197: // Umbreon (generated before Espeon) + rev = 5; break; + case 196: // Espeon (generated after Umbreon) + rev = 12; break; } + if (rev == int.MinValue) + return; + + var pidiv = MethodFinder.Analyze(pkm); + if (pidiv == null || pidiv.Type != PIDType.CXD) + { + AddLine(Severity.Invalid, V400, CheckIdentifier.PID); + return; + } + var seed = pidiv.OriginSeed; + var SIDf = pidiv.RNG.Reverse(seed, rev); + var TIDf = pidiv.RNG.Prev(SIDf); + if (SIDf >> 16 != pkm.SID || TIDf >> 16 != pkm.TID) + AddLine(Severity.Invalid, V400, CheckIdentifier.PID); } else if (pkm.WasEgg) // can't obtain eggs in CXD {