mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-03 17:29:13 +00:00
95fbf66a6e
In addition to the Method 1 (and other sibling PIDIV types) correlation, an encounter can only be triggered if the calls prior land on the Method {1} seed. The RNG community has dubbed these patterns as "Method J" (D/P/Pt), "Method K" (HG/SS), and "Method H" (Gen3, coined by yours truly). The basic gist of these is that they are pre-requisites, like the Shadow locks of Colosseum/XD. Rename/re-type a bunch of properties to get the codebase more in line with correct property names & more obvious underlying types.
75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using static PKHeX.Core.CheckIdentifier;
|
|
|
|
namespace PKHeX.Core.Bulk;
|
|
|
|
public sealed class DuplicateEncryptionChecker : IBulkAnalyzer
|
|
{
|
|
public void Analyze(BulkAnalysis input)
|
|
{
|
|
if (input.Trainer.Generation < 6)
|
|
return; // no EC yet
|
|
CheckECReuse(input);
|
|
}
|
|
|
|
private static void CheckECReuse(BulkAnalysis input)
|
|
{
|
|
var dict = new Dictionary<uint, CombinedReference>();
|
|
for (int i = 0; i < input.AllData.Count; i++)
|
|
{
|
|
if (input.GetIsClone(i))
|
|
continue; // already flagged
|
|
var cp = input.AllData[i];
|
|
var ca = input.AllAnalysis[i];
|
|
Verify(input, dict, cp, ca);
|
|
}
|
|
}
|
|
|
|
private static void Verify(BulkAnalysis input, Dictionary<uint, CombinedReference> dict, SlotCache cp, LegalityAnalysis ca)
|
|
{
|
|
Debug.Assert(cp.Entity.Format >= 6);
|
|
var id = cp.Entity.EncryptionConstant;
|
|
|
|
var cr = new CombinedReference(cp, ca);
|
|
if (!dict.TryGetValue(id, out var pa))
|
|
{
|
|
dict.Add(id, cr);
|
|
return;
|
|
}
|
|
|
|
VerifyECShare(input, pa, cr);
|
|
}
|
|
|
|
private static void VerifyECShare(BulkAnalysis input, CombinedReference pr, CombinedReference cr)
|
|
{
|
|
var (ps, pa) = pr;
|
|
var (cs, ca) = cr;
|
|
|
|
const CheckIdentifier ident = PID;
|
|
var gen = pa.Info.Generation;
|
|
bool gbaNDS = gen is 3 or 4 or 5;
|
|
|
|
if (!gbaNDS)
|
|
{
|
|
if (ca.Info.Generation != gen)
|
|
{
|
|
input.AddLine(ps, cs, "EC sharing across generations detected.", ident);
|
|
return;
|
|
}
|
|
input.AddLine(ps, cs, "EC sharing for 3DS-onward origin detected.", ident);
|
|
return;
|
|
}
|
|
|
|
// eggs/mystery gifts shouldn't share with wild encounters
|
|
var cenc = ca.Info.EncounterMatch;
|
|
bool eggMysteryCurrent = cenc is EncounterEgg or MysteryGift;
|
|
var penc = pa.Info.EncounterMatch;
|
|
bool eggMysteryPrevious = penc is EncounterEgg or MysteryGift;
|
|
|
|
if (eggMysteryCurrent != eggMysteryPrevious)
|
|
{
|
|
input.AddLine(ps, cs, "EC sharing across RNG encounters detected.", ident);
|
|
}
|
|
}
|
|
}
|