2022-06-18 18:04:24 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Verifies the <see cref="PKM.OriginalTrainerName"/>.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public sealed class TrainerIDVerifier : Verifier
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Trainer;
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = data.Entity;
|
|
|
|
if (!TrainerNameVerifier.IsPlayerOriginalTrainer(data.EncounterMatch))
|
|
|
|
return; // already verified
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.BDSP)
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
// Game loops to ensure a nonzero full-ID
|
|
|
|
// int.MaxValue cannot be yielded by Unity's Random.Range[min, max)
|
|
|
|
var id32 = pk.ID32;
|
|
|
|
if (id32 is 0 or int.MaxValue)
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LOT_IDInvalid));
|
|
|
|
return;
|
2021-11-26 03:15:42 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-22 03:09:35 +00:00
|
|
|
else if (pk.VC)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-22 03:09:35 +00:00
|
|
|
// Only TID is used for Gen 1/2 VC
|
|
|
|
if (pk.SID16 != 0)
|
|
|
|
data.AddLine(GetInvalid(LOT_SID0Invalid));
|
|
|
|
if (pk.TID16 == 0)
|
|
|
|
data.AddLine(Get(LOT_TID0, Severity.Fishy));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (pk.Format <= 2)
|
|
|
|
{
|
|
|
|
// Only TID is used for Gen 1/2
|
|
|
|
if (pk.TID16 == 0)
|
|
|
|
data.AddLine(Get(LOT_TID0, Severity.Fishy));
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (pk is { ID32: 0 })
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOT_IDs0, Severity.Fishy));
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (pk.TID16 == pk.SID16)
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOT_IDEqual, Severity.Fishy));
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (pk.TID16 == 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOT_TID0, Severity.Fishy));
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (pk.SID16 == 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOT_SID0, Severity.Fishy));
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (IsOTIDSuspicious(pk.TID16, pk.SID16))
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOTSuspicious, Severity.Fishy));
|
|
|
|
}
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public static bool IsOTIDSuspicious(ushort tid16, ushort sid16) => (tid16, sid16) switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
(12345, 54321) => true,
|
|
|
|
(15040, 18831) => true, // 1234_123456 (SID7_TID7)
|
|
|
|
_ => false,
|
|
|
|
};
|
2021-11-26 03:15:42 +00:00
|
|
|
}
|