PKHeX/PKHeX.Core/Legality/RNG/SeedInfo.cs
Kurt 9380ca25d9 Update current RNG frame detection methods
Still not hooked in or handling every case, but is enough progress for
now.
2017-05-14 12:42:27 -07:00

60 lines
1.7 KiB
C#

using System.Collections.Generic;
namespace PKHeX.Core
{
public class SeedInfo
{
public uint Seed;
public bool Charm3;
public static IEnumerable<SeedInfo> getSeedsUntilNature(PIDIV pidiv, SearchCriteria info)
{
bool reverse = pidiv.Type.IsReversedPID();
bool charm3 = false;
var seed = pidiv.OriginSeed;
yield return new SeedInfo { Seed = seed };
var s1 = seed;
var s2 = pidiv.RNG.Prev(s1);
while (true)
{
var a = s2 >> 16;
var b = s1 >> 16;
var pid = reverse ? a << 16 | b : b << 16 | a;
// Process Conditions
switch (verifyPIDCriteria(pid, info))
{
case LockInfo.Pass:
yield break;
case LockInfo.Gender:
charm3 = true;
break;
}
s1 = pidiv.RNG.Prev(s2);
s2 = pidiv.RNG.Prev(s1);
yield return new SeedInfo { Seed = s1, Charm3 = charm3 };
}
}
private static LockInfo verifyPIDCriteria(uint pid, SearchCriteria info)
{
// Nature locks are always a given
var nval = pid % 25;
if (nval != info.Nature)
return LockInfo.Nature;
if (!info.Gendered)
return LockInfo.Pass;
var gender = pid & 0xFF;
if (info.GenderLow > gender || gender > info.GenderHigh)
return LockInfo.Gender;
return LockInfo.Pass;
}
}
}