2022-06-18 18:04:24 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies the <see cref="PKM.OT_Name"/>.
|
|
|
|
/// </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
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.TID == 0 && pk.SID == 0) // Game loops to ensure a nonzero full-ID
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LOT_IDInvalid));
|
2021-11-26 03:15:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.TID == 0xFFFF && pk.SID == 0x7FFF) // int.MaxValue cannot be yielded by Unity's Random.Range[min, max)
|
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
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (pk.VC && pk.SID != 0)
|
|
|
|
{
|
|
|
|
data.AddLine(GetInvalid(LOT_SID0Invalid));
|
|
|
|
return;
|
|
|
|
}
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.TID == 0 && pk.SID == 0)
|
|
|
|
{
|
|
|
|
data.AddLine(Get(LOT_IDs0, Severity.Fishy));
|
|
|
|
}
|
|
|
|
else if (pk.TID == pk.SID)
|
|
|
|
{
|
|
|
|
data.AddLine(Get(LOT_IDEqual, Severity.Fishy));
|
|
|
|
}
|
|
|
|
else if (pk.TID == 0)
|
|
|
|
{
|
|
|
|
data.AddLine(Get(LOT_TID0, Severity.Fishy));
|
|
|
|
}
|
|
|
|
else if (pk.SID == 0)
|
2021-11-26 03:15:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LOT_SID0, Severity.Fishy));
|
|
|
|
}
|
|
|
|
else if (IsOTIDSuspicious(pk.TID, pk.SID))
|
|
|
|
{
|
|
|
|
data.AddLine(Get(LOTSuspicious, Severity.Fishy));
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static bool IsOTIDSuspicious(int tid16, int sid16)
|
|
|
|
{
|
|
|
|
if (tid16 == 12345 && sid16 == 54321)
|
|
|
|
return true;
|
2021-11-26 03:15:42 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// 1234_123456 (SID7_TID7)
|
|
|
|
if (tid16 == 15040 && sid16 == 18831)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2021-11-26 03:15:42 +00:00
|
|
|
}
|
|
|
|
}
|