2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2019-04-14 08:06:34 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using PKHeX.Core.Searching;
|
|
|
|
using static PKHeX.Core.CheckIdentifier;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Analyzes content within a <see cref="SaveFile"/> for overall <see cref="PKM"/> legality analysis.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class BulkAnalysis
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly IReadOnlyList<SlotCache> AllData;
|
|
|
|
public readonly IReadOnlyList<LegalityAnalysis> AllAnalysis;
|
|
|
|
public readonly ITrainerInfo Trainer;
|
|
|
|
public readonly List<CheckResult> Parse = new();
|
|
|
|
public readonly Dictionary<ulong, SlotCache> Trackers = new();
|
|
|
|
public readonly bool Valid;
|
|
|
|
|
|
|
|
private readonly IBulkAnalysisSettings Settings;
|
|
|
|
private readonly bool[] CloneFlags;
|
|
|
|
|
|
|
|
public BulkAnalysis(SaveFile sav, IBulkAnalysisSettings settings)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Trainer = sav;
|
|
|
|
Settings = settings;
|
|
|
|
var list = new List<SlotCache>(sav.BoxSlotCount + (sav.HasParty ? 6 : 0) + 5);
|
|
|
|
SlotInfoLoader.AddFromSaveFile(sav, list);
|
|
|
|
list.RemoveAll(IsEmptyData);
|
|
|
|
AllData = list;
|
2022-06-27 03:02:57 +00:00
|
|
|
AllAnalysis = GetIndividualAnalysis(list);
|
2022-06-18 18:04:24 +00:00
|
|
|
CloneFlags = new bool[AllData.Count];
|
|
|
|
|
|
|
|
ScanAll();
|
2022-06-26 23:04:55 +00:00
|
|
|
Valid = Parse.Count == 0 || Parse.All(z => z.Valid);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Remove things that aren't actual stored data, or already flagged by legality checks.
|
|
|
|
private static bool IsEmptyData(SlotCache obj)
|
|
|
|
{
|
|
|
|
var pk = obj.Entity;
|
|
|
|
if ((uint)(pk.Species - 1) >= pk.MaxSpeciesID)
|
|
|
|
return true;
|
|
|
|
if (!pk.ChecksumValid)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-14 23:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ScanAll()
|
|
|
|
{
|
|
|
|
CheckClones();
|
|
|
|
if (Trainer.Generation <= 2)
|
|
|
|
return;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CheckIDReuse();
|
|
|
|
CheckPIDReuse();
|
|
|
|
if (Trainer.Generation >= 6)
|
2022-02-22 15:34:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CheckECReuse();
|
|
|
|
if (Settings.CheckActiveHandler)
|
|
|
|
CheckHandlerFlag();
|
2022-02-22 15:34:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CheckDuplicateOwnedGifts();
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static string GetSummary(SlotCache entry) => $"[{entry.Identify()}] {entry.Entity.FileName}";
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void AddLine(SlotCache first, SlotCache second, string msg, CheckIdentifier i, Severity s = Severity.Invalid)
|
|
|
|
{
|
|
|
|
var c = $"{msg}{Environment.NewLine}{GetSummary(first)}{Environment.NewLine}{GetSummary(second)}";
|
|
|
|
var chk = new CheckResult(s, c, i);
|
|
|
|
Parse.Add(chk);
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void AddLine(SlotCache first, string msg, CheckIdentifier i, Severity s = Severity.Invalid)
|
|
|
|
{
|
|
|
|
var c = $"{msg}{Environment.NewLine}{GetSummary(first)}";
|
|
|
|
var chk = new CheckResult(s, c, i);
|
|
|
|
Parse.Add(chk);
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckClones()
|
|
|
|
{
|
|
|
|
var dict = new Dictionary<string, SlotCache>();
|
|
|
|
for (int i = 0; i < AllData.Count; i++)
|
2020-02-13 02:29:47 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var cs = AllData[i];
|
|
|
|
var ca = AllAnalysis[i];
|
|
|
|
Debug.Assert(cs.Entity.Format == Trainer.Generation);
|
2020-02-13 02:29:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check the upload tracker to see if there's any duplication.
|
|
|
|
if (cs.Entity is IHomeTrack home)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (home.Tracker != 0)
|
2020-02-13 00:37:59 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var tracker = home.Tracker;
|
|
|
|
if (Trackers.TryGetValue(tracker, out var clone))
|
2023-01-22 04:02:33 +00:00
|
|
|
AddLine(cs, clone, "Clone detected (Duplicate Tracker).", Encounter);
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
|
|
|
Trackers.Add(tracker, cs);
|
2020-02-13 00:37:59 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (ca.Info.Generation is (< 8 and not -1))
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
AddLine(cs, "Missing tracker.", Encounter);
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Hash Details like EC/IV to see if there's any duplication.
|
|
|
|
var identity = SearchUtil.HashByDetails(cs.Entity);
|
|
|
|
if (!dict.TryGetValue(identity, out var ps))
|
|
|
|
{
|
|
|
|
dict.Add(identity, cs);
|
|
|
|
continue;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
CloneFlags[i] = true;
|
2023-01-22 04:02:33 +00:00
|
|
|
AddLine(ps, cs, "Clone detected (Details).", Encounter);
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckDuplicateOwnedGifts()
|
|
|
|
{
|
|
|
|
var combined = new CombinedReference[AllData.Count];
|
|
|
|
for (int i = 0; i < combined.Length; i++)
|
|
|
|
combined[i] = new CombinedReference(AllData[i], AllAnalysis[i]);
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var dupes = combined.Where(z =>
|
|
|
|
z.Analysis.Info.Generation >= 3
|
|
|
|
&& z.Analysis.EncounterMatch is MysteryGift {EggEncounter: true} && !z.Slot.Entity.WasTradedEgg)
|
|
|
|
.GroupBy(z => ((MysteryGift)z.Analysis.EncounterMatch).CardTitle);
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var dupe in dupes)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var tidGroup = dupe.GroupBy(z => z.Slot.Entity.TID16 | (z.Slot.Entity.SID16 << 16))
|
2022-06-18 18:04:24 +00:00
|
|
|
.Select(z => z.ToList())
|
|
|
|
.Where(z => z.Count >= 2).ToList();
|
|
|
|
if (tidGroup.Count == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var first = tidGroup[0][0].Slot;
|
|
|
|
var second = tidGroup[0][1].Slot;
|
|
|
|
AddLine(first, second, $"Receipt of the same egg mystery gifts detected: {dupe.Key}", Encounter);
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckECReuse()
|
|
|
|
{
|
|
|
|
var dict = new Dictionary<uint, CombinedReference>();
|
|
|
|
for (int i = 0; i < AllData.Count; i++)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CloneFlags[i])
|
|
|
|
continue; // already flagged
|
|
|
|
var cp = AllData[i];
|
|
|
|
var ca = AllAnalysis[i];
|
|
|
|
Debug.Assert(cp.Entity.Format >= 6);
|
|
|
|
var id = cp.Entity.EncryptionConstant;
|
|
|
|
|
|
|
|
var cr = new CombinedReference(cp, ca);
|
2023-01-22 04:02:33 +00:00
|
|
|
if (!dict.TryGetValue(id, out var pa))
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
dict.Add(id, cr);
|
|
|
|
continue;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyECShare(pa, cr);
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckPIDReuse()
|
|
|
|
{
|
|
|
|
var dict = new Dictionary<uint, CombinedReference>();
|
|
|
|
for (int i = 0; i < AllData.Count; i++)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CloneFlags[i])
|
|
|
|
continue; // already flagged
|
|
|
|
var cp = AllData[i];
|
|
|
|
var ca = AllAnalysis[i];
|
|
|
|
bool g345 = ca.Info.Generation is 3 or 4 or 5;
|
|
|
|
var id = g345 ? cp.Entity.EncryptionConstant : cp.Entity.PID;
|
|
|
|
|
|
|
|
var cr = new CombinedReference(cp, ca);
|
2023-01-22 04:02:33 +00:00
|
|
|
if (!dict.TryGetValue(id, out var pr))
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
dict.Add(id, cr);
|
|
|
|
continue;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyPIDShare(pr, cr);
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckHandlerFlag()
|
|
|
|
{
|
|
|
|
for (var i = 0; i < AllData.Count; i++)
|
2022-06-05 20:18:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!AllAnalysis[i].Valid)
|
|
|
|
continue;
|
|
|
|
var cs = AllData[i];
|
|
|
|
var pk = cs.Entity;
|
|
|
|
var tr = cs.SAV;
|
|
|
|
var withOT = tr.IsFromTrainer(pk);
|
|
|
|
var flag = pk.CurrentHandler;
|
|
|
|
var expect = withOT ? 0 : 1;
|
|
|
|
if (flag != expect)
|
|
|
|
AddLine(cs, LegalityCheckStrings.LTransferCurrentHandlerInvalid, CheckIdentifier.Trainer);
|
|
|
|
|
|
|
|
if (flag == 1)
|
2022-06-05 20:18:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.HT_Name != tr.OT)
|
|
|
|
AddLine(cs, LegalityCheckStrings.LTransferHTMismatchName, CheckIdentifier.Trainer);
|
|
|
|
if (pk is IHandlerLanguage h && h.HT_Language != tr.Language)
|
|
|
|
AddLine(cs, LegalityCheckStrings.LTransferHTMismatchLanguage, CheckIdentifier.Trainer);
|
2022-06-05 20:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-06-05 20:18:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private sealed record CombinedReference(SlotCache Slot, LegalityAnalysis Analysis);
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckIDReuse()
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var dict = new Dictionary<uint, CombinedReference>();
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < AllData.Count; i++)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CloneFlags[i])
|
|
|
|
continue; // already flagged
|
|
|
|
var cs = AllData[i];
|
|
|
|
var ca = AllAnalysis[i];
|
2023-01-22 04:02:33 +00:00
|
|
|
var id = cs.Entity.ID32;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (!dict.TryGetValue(id, out var pr))
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var r = new CombinedReference(cs, ca);
|
|
|
|
dict.Add(id, r);
|
|
|
|
continue;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pa = pr.Analysis;
|
|
|
|
// ignore GB era collisions
|
2023-01-22 04:02:33 +00:00
|
|
|
// a 16bit TID16 can reasonably occur for multiple trainers, and versions
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ca.Info.Generation <= 2 && pa.Info.Generation <= 2)
|
|
|
|
continue;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var ps = pr.Slot;
|
|
|
|
if (VerifyIDReuse(ps, pa, cs, ca))
|
|
|
|
continue;
|
2019-04-14 23:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// egg encounters can be traded before hatching
|
|
|
|
// store the current loop pk if it's a better reference
|
|
|
|
if (ps.Entity.WasTradedEgg && !cs.Entity.WasTradedEgg)
|
|
|
|
dict[id] = new CombinedReference(cs, ca);
|
|
|
|
}
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyECShare(CombinedReference pr, CombinedReference cr)
|
|
|
|
{
|
|
|
|
var (ps, pa) = pr;
|
|
|
|
var (cs, ca) = cr;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
const CheckIdentifier ident = PID;
|
|
|
|
int gen = pa.Info.Generation;
|
|
|
|
bool gbaNDS = gen is 3 or 4 or 5;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!gbaNDS)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
|
|
|
if (ca.Info.Generation != gen)
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
AddLine(ps, cs, "EC sharing across generations detected.", ident);
|
2019-04-14 08:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
AddLine(ps, cs, "EC sharing for 3DS-onward origin detected.", ident);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// 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;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (eggMysteryCurrent != eggMysteryPrevious)
|
|
|
|
{
|
|
|
|
AddLine(ps, cs, "EC sharing across RNG encounters detected.", ident);
|
|
|
|
}
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyPIDShare(CombinedReference pr, CombinedReference cr)
|
|
|
|
{
|
|
|
|
var ps = pr.Slot;
|
|
|
|
var pa = pr.Analysis;
|
|
|
|
var cs = cr.Slot;
|
|
|
|
var ca = cr.Analysis;
|
|
|
|
const CheckIdentifier ident = PID;
|
|
|
|
int gen = pa.Info.Generation;
|
|
|
|
|
|
|
|
if (ca.Info.Generation != gen)
|
|
|
|
{
|
|
|
|
AddLine(ps, cs, "PID sharing across generations detected.", ident);
|
|
|
|
return;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool gbaNDS = gen is 3 or 4 or 5;
|
|
|
|
if (!gbaNDS)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
AddLine(ps, cs, "PID sharing for 3DS-onward origin detected.", ident);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-14 16:06:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// 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;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (eggMysteryCurrent != eggMysteryPrevious)
|
|
|
|
{
|
|
|
|
AddLine(ps, cs, "PID sharing across RNG encounters detected.", ident);
|
|
|
|
}
|
|
|
|
}
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool VerifyIDReuse(SlotCache ps, LegalityAnalysis pa, SlotCache cs, LegalityAnalysis ca)
|
|
|
|
{
|
|
|
|
if (pa.EncounterMatch is MysteryGift {EggEncounter: false})
|
|
|
|
return false;
|
|
|
|
if (ca.EncounterMatch is MysteryGift {EggEncounter: false})
|
|
|
|
return false;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
const CheckIdentifier ident = CheckIdentifier.Trainer;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pp = ps.Entity;
|
|
|
|
var cp = cs.Entity;
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// 32bit ID-SID16 should only occur for one generation
|
|
|
|
// Trainer-ID-SID16 should only occur for one version
|
2022-06-18 18:04:24 +00:00
|
|
|
if (IsSharedVersion(pp, pa, cp, ca))
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
AddLine(ps, cs, "TID16 sharing across versions detected.", ident);
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// ID-SID16 should only occur for one Trainer name
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pp.OT_Name != cp.OT_Name)
|
2019-04-14 08:06:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var severity = ca.Info.Generation == 4 ? Severity.Fishy : Severity.Invalid;
|
2023-01-22 04:02:33 +00:00
|
|
|
AddLine(ps, cs, "TID16 sharing across different trainer names detected.", ident, severity);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool IsSharedVersion(PKM pp, LegalityAnalysis pa, PKM cp, LegalityAnalysis ca)
|
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
if (pp.Version == cp.Version || pp.Version == 0 || cp.Version == 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Traded eggs retain the original version ID, only on the same generation
|
|
|
|
if (pa.Info.Generation != ca.Info.Generation)
|
|
|
|
return false;
|
|
|
|
|
2022-10-28 23:18:06 +00:00
|
|
|
// Gen3/4 traded eggs do not have an Egg Location, and do not update the Version upon hatch.
|
2023-01-22 04:02:33 +00:00
|
|
|
// These eggs can obtain another trainer's TID16/SID16/OT and be valid with a different version ID.
|
2022-10-28 23:18:06 +00:00
|
|
|
if (pa.EncounterMatch.EggEncounter && IsTradedEggVersionNoUpdate(pp, pa))
|
2022-06-18 18:04:24 +00:00
|
|
|
return false; // version doesn't update on trade
|
2022-10-28 23:18:06 +00:00
|
|
|
if (ca.EncounterMatch.EggEncounter && IsTradedEggVersionNoUpdate(cp, ca))
|
2022-06-18 18:04:24 +00:00
|
|
|
return false; // version doesn't update on trade
|
|
|
|
|
2022-10-28 23:18:06 +00:00
|
|
|
static bool IsTradedEggVersionNoUpdate(PKM pk, LegalityAnalysis la) => la.Info.Generation switch
|
|
|
|
{
|
|
|
|
3 => true, // No egg location, assume can be traded. Doesn't update version upon hatch.
|
|
|
|
4 => pk.WasTradedEgg, // Gen4 traded eggs do not update version upon hatch.
|
|
|
|
_ => false, // Gen5+ eggs have an egg location, and update the version upon hatch.
|
|
|
|
};
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-14 08:06:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static IReadOnlyList<LegalityAnalysis> GetIndividualAnalysis(IReadOnlyList<SlotCache> pkms)
|
|
|
|
{
|
|
|
|
var results = new LegalityAnalysis[pkms.Count];
|
|
|
|
for (int i = 0; i < pkms.Count; i++)
|
2022-06-27 03:02:57 +00:00
|
|
|
results[i] = Get(pkms[i]);
|
2022-06-18 18:04:24 +00:00
|
|
|
return results;
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|
2022-06-27 03:02:57 +00:00
|
|
|
|
|
|
|
private static LegalityAnalysis Get(SlotCache cache) => new(cache.Entity, cache.SAV.Personal, cache.Source.Origin);
|
2019-04-14 08:06:34 +00:00
|
|
|
}
|