mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-04-24 23:57:12 -05:00
Revise PIDIV check return value to enum
Deduplicates slightly by indicating the true-"ignore" better. Add deferral for Alpha Moves (flagged later via ZA Verifier, not needing a generic Partial error)
This commit is contained in:
parent
291d5be618
commit
048f7cfe30
|
|
@ -287,10 +287,14 @@ private bool IsMatchCorrelation(PKM pk)
|
|||
if (pk.IsShiny)
|
||||
return true;
|
||||
|
||||
return TryGetSeed(pk, out _);
|
||||
var pidiv = TryGetSeed(pk, out _);
|
||||
if (pidiv == SeedCorrelationResult.Success)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed)
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
var ec = pk.EncryptionConstant;
|
||||
var pid = pk.PID;
|
||||
|
|
@ -298,16 +302,16 @@ public bool TryGetSeed(PKM pk, out ulong seed)
|
|||
foreach (var s in seeds)
|
||||
{
|
||||
if (IsMatchSeed(pk, seed = s))
|
||||
return true;
|
||||
return SeedCorrelationResult.Success;
|
||||
}
|
||||
seeds = new XoroMachineSkip(ec, pid ^ 0x1000_0000);
|
||||
foreach (var s in seeds)
|
||||
{
|
||||
if (IsMatchSeed(pk, seed = s))
|
||||
return true;
|
||||
return SeedCorrelationResult.Success;
|
||||
}
|
||||
seed = 0;
|
||||
return false;
|
||||
return SeedCorrelationResult.Invalid;
|
||||
}
|
||||
|
||||
protected virtual bool IsMatchSeed(PKM pk, ulong seed) => Verify(pk, seed);
|
||||
|
|
|
|||
|
|
@ -5,5 +5,12 @@ namespace PKHeX.Core;
|
|||
/// </summary>
|
||||
public interface ISeedCorrelation64<in T>
|
||||
{
|
||||
bool TryGetSeed(T pk, out ulong seed);
|
||||
SeedCorrelationResult TryGetSeed(T pk, out ulong seed);
|
||||
}
|
||||
|
||||
public enum SeedCorrelationResult
|
||||
{
|
||||
Invalid,
|
||||
Ignore,
|
||||
Success,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public bool IsForcedMasteryCorrect(PKM pk)
|
|||
}
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed)
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
// Check if it matches any single-roll seed.
|
||||
var pi = PersonalTable.LA[Species, Form];
|
||||
|
|
@ -256,9 +256,9 @@ public bool TryGetSeed(PKM pk, out ulong seed)
|
|||
if (!Overworld8aRNG.Verify(pk, s, param))
|
||||
continue;
|
||||
seed = s;
|
||||
return true;
|
||||
return SeedCorrelationResult.Success;
|
||||
}
|
||||
seed = 0;
|
||||
return false;
|
||||
return SeedCorrelationResult.Ignore;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ public bool IsForcedMasteryCorrect(PKM pk)
|
|||
}
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed)
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
// Check if it matches any single-roll seed.
|
||||
var param = GetParams();
|
||||
|
|
@ -311,9 +311,9 @@ public bool TryGetSeed(PKM pk, out ulong seed)
|
|||
if (!Overworld8aRNG.Verify(pk, s, param, HasFixedHeight, HasFixedWeight))
|
||||
continue;
|
||||
seed = s;
|
||||
return true;
|
||||
return SeedCorrelationResult.Success;
|
||||
}
|
||||
seed = 0;
|
||||
return false;
|
||||
return SeedCorrelationResult.Ignore;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,8 @@ private EncounterMatchRating IsMatchDeferred(PKM pk)
|
|||
if (Shiny != Shiny.Random && !Shiny.IsValid(pk))
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
if (!TryGetSeed(pk, out _))
|
||||
var pidiv = TryGetSeed(pk, out _);
|
||||
if (pidiv != SeedCorrelationResult.Success)
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
return EncounterMatchRating.Match;
|
||||
|
|
@ -193,13 +194,11 @@ private bool IsMatchPartial(PKM pk)
|
|||
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed)
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
if (GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed))
|
||||
return true;
|
||||
if (pk.IsShiny && !LumioseSolver.SearchShiny1)
|
||||
return true;
|
||||
return false;
|
||||
return SeedCorrelationResult.Success;
|
||||
return SeedCorrelationResult.Invalid;
|
||||
}
|
||||
|
||||
public LumioseCorrelation Correlation => IsAlpha ? LumioseCorrelation.PreApplyIVs : LumioseCorrelation.ReApplyIVs;
|
||||
|
|
@ -218,7 +217,7 @@ public GenerateParam9a GetParams(PersonalInfo9ZA pi)
|
|||
return new GenerateParam9a(gender, FlawlessIVCount, rollCount, Correlation, scaleType, Size, Nature, Ability, Shiny, IVs);
|
||||
}
|
||||
|
||||
private bool IsMatchFixedTrainer(PKM pk, TrainerGift9a trainer)
|
||||
private static bool IsMatchFixedTrainer(PKM pk, TrainerGift9a trainer)
|
||||
{
|
||||
if (pk.ID32 != GetFixedTrainerID32(trainer))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -120,25 +120,28 @@ public bool IsMatchExact(PKM pk, EvoCriteria evo)
|
|||
|
||||
public EncounterMatchRating GetMatchRating(PKM pk)
|
||||
{
|
||||
if (!IsMatchCorrelation(pk))
|
||||
if (IsAlpha && pk is IPlusRecord pa9 && !pa9.GetMovePlusFlag(PersonalTable.ZA[Species, Form].AlphaMove))
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
var pidiv = TryGetSeed(pk, out _);
|
||||
if (pidiv is SeedCorrelationResult.Invalid)
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
if (pidiv is SeedCorrelationResult.Ignore)
|
||||
return EncounterMatchRating.Deferred; // might be a better match with another template
|
||||
|
||||
return EncounterMatchRating.Match;
|
||||
}
|
||||
|
||||
private bool IsMatchCorrelation(PKM pk)
|
||||
{
|
||||
if (TryGetSeed(pk, out _))
|
||||
return true;
|
||||
if (!LumioseSolver.SearchShinyN)
|
||||
return true; // can't check further without brute forcing
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed) => GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed);
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
if (GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed))
|
||||
return SeedCorrelationResult.Success;
|
||||
if (pk.IsShiny && !LumioseSolver.SearchShiny1)
|
||||
return SeedCorrelationResult.Ignore;
|
||||
return SeedCorrelationResult.Invalid;
|
||||
}
|
||||
|
||||
public LumioseCorrelation Correlation => IsAlpha ? LumioseCorrelation.PreApplyIVs : LumioseCorrelation.Normal;
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,11 @@ private EncounterMatchRating IsMatchDeferred(PKM pk)
|
|||
if (Shiny != Shiny.Random && !Shiny.IsValid(pk))
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
if (!TryGetSeed(pk, out _)) // maybe a Slot?
|
||||
if (IsAlpha && pk is IPlusRecord pa9 && !pa9.GetMovePlusFlag(PersonalTable.ZA[Species, Form].AlphaMove))
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
var pidiv = TryGetSeed(pk, out _);
|
||||
if (pidiv is not SeedCorrelationResult.Success)
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
return EncounterMatchRating.Match;
|
||||
|
|
@ -184,13 +188,11 @@ private bool IsMatchPartial(PKM pk)
|
|||
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed)
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
if (GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed))
|
||||
return true;
|
||||
if (pk.IsShiny && !LumioseSolver.SearchShiny1)
|
||||
return true;
|
||||
return false;
|
||||
return SeedCorrelationResult.Success;
|
||||
return SeedCorrelationResult.Invalid;
|
||||
}
|
||||
|
||||
public LumioseCorrelation Correlation => IsAlpha ? LumioseCorrelation.PreApplyIVs : LumioseCorrelation.Normal;
|
||||
|
|
|
|||
|
|
@ -172,7 +172,8 @@ public EncounterMatchRating GetMatchRating(PKM pk)
|
|||
if (pk is IScaledSize3 size3 && size3.Scale != Scale)
|
||||
return EncounterMatchRating.PartialMatch;
|
||||
|
||||
if (!TryGetSeed(pk, out _)) // maybe a Slot?
|
||||
var pidiv = TryGetSeed(pk, out _);
|
||||
if (pidiv is not SeedCorrelationResult.Success)
|
||||
return EncounterMatchRating.DeferredErrors;
|
||||
|
||||
return EncounterMatchRating.Match;
|
||||
|
|
@ -211,7 +212,12 @@ public bool IsMatchExact(PKM pk, EvoCriteria evo)
|
|||
|
||||
#endregion
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed) => GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed);
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
||||
{
|
||||
if (GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed))
|
||||
return SeedCorrelationResult.Success;
|
||||
return SeedCorrelationResult.Invalid;
|
||||
}
|
||||
|
||||
public LumioseCorrelation Correlation => LumioseCorrelation.ReApplyIVs;
|
||||
|
||||
|
|
|
|||
|
|
@ -78,8 +78,12 @@ public override void Verify(LegalityAnalysis data)
|
|||
}
|
||||
else if (enc is ISeedCorrelation64<PKM> s64)
|
||||
{
|
||||
if (s64.TryGetSeed(pk, out var seed))
|
||||
var pidiv = s64.TryGetSeed(pk, out var seed);
|
||||
if (pidiv == SeedCorrelationResult.Success)
|
||||
data.Info.PIDIV = new PIDIV(PIDType.Xoroshiro, seed);
|
||||
else if (pidiv is SeedCorrelationResult.Invalid)
|
||||
data.AddLine(GetInvalid(PIDTypeMismatch));
|
||||
|
||||
if (enc is IMasteryInitialMoveShop8 m && !m.IsForcedMasteryCorrect(pk))
|
||||
data.AddLine(GetInvalid(EncMasteryInitial));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -671,7 +671,7 @@ private bool IsMatchTrainerName(ReadOnlySpan<byte> trainerTrash, PKM pk)
|
|||
|
||||
protected override bool IsMatchDeferred(PKM pk) => false;
|
||||
|
||||
protected override bool IsMatchPartial(PKM pk) => !TryGetSeed(pk, out _);
|
||||
protected override bool IsMatchPartial(PKM pk) => TryGetSeed(pk, out _) != SeedCorrelationResult.Success;
|
||||
|
||||
#region Lazy Ribbon Implementation
|
||||
|
||||
|
|
@ -825,7 +825,10 @@ public bool IsMissingExtraMark(PKM pk, out RibbonIndex missing)
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetSeed(PKM pk, out ulong seed) => GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed);
|
||||
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed) =>
|
||||
GetParams(PersonalTable.ZA[Species, Form]).TryGetSeed(pk, out seed)
|
||||
? SeedCorrelationResult.Success
|
||||
: SeedCorrelationResult.Invalid;
|
||||
|
||||
private GenerateParam9a GetParams(PersonalInfo9ZA pi)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public void CheckDynamaxRaidCharizardPK8()
|
|||
var enc = la.EncounterMatch;
|
||||
if (enc is not ISeedCorrelation64<Core.PKM> s64)
|
||||
throw new ArgumentException(nameof(enc));
|
||||
s64.TryGetSeed(pk8, out ulong detected).Should().BeTrue();
|
||||
s64.TryGetSeed(pk8, out var detected).Should().Be(SeedCorrelationResult.Success);
|
||||
detected.Should().Be(seed);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user