2021-06-29 20:58:06 -07:00
|
|
|
|
using System;
|
2018-07-26 19:34:27 -07:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2018-06-23 22:00:01 -07:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-01 19:17:37 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.OT_Name"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class TrainerNameVerifier : Verifier
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Trainer;
|
|
|
|
|
|
2020-08-30 19:59:21 -07:00
|
|
|
|
private static readonly string[] SuspiciousOTNames =
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
|
|
|
|
"PKHeX",
|
2020-10-04 08:59:33 -07:00
|
|
|
|
"PKHeX",
|
2018-06-23 22:00:01 -07:00
|
|
|
|
};
|
2018-07-26 19:34:27 -07:00
|
|
|
|
|
2018-06-23 22:00:01 -07:00
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
switch (data.EncounterMatch)
|
|
|
|
|
{
|
2020-12-21 23:37:07 -08:00
|
|
|
|
case EncounterTrade:
|
2020-12-21 22:33:48 -08:00
|
|
|
|
case MysteryGift {IsEgg: false}:
|
2020-12-21 23:37:07 -08:00
|
|
|
|
case EncounterStatic5N:
|
2018-06-23 22:00:01 -07:00
|
|
|
|
return; // already verified
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ot = pkm.OT_Name;
|
|
|
|
|
if (ot.Length == 0)
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LOTShort));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
|
|
|
|
|
if (pkm.TID == 0 && pkm.SID == 0)
|
2018-07-26 19:34:27 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(Get(LOT_IDs0, Severity.Fishy));
|
2018-07-26 19:34:27 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
else if (pkm.VC)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.SID != 0)
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LOT_SID0Invalid));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
|
|
|
|
else if (pkm.TID == pkm.SID)
|
2018-07-26 19:34:27 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(Get(LOT_IDEqual, Severity.Fishy));
|
2018-07-26 19:34:27 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
else if (pkm.TID == 0)
|
2018-07-26 19:34:27 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(Get(LOT_TID0, Severity.Fishy));
|
2018-07-26 19:34:27 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
else if (pkm.SID == 0)
|
2018-07-26 19:34:27 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(Get(LOT_SID0, Severity.Fishy));
|
2018-07-26 19:34:27 -07:00
|
|
|
|
}
|
2020-08-30 19:59:21 -07:00
|
|
|
|
else if (IsOTNameSuspicious(ot))
|
|
|
|
|
{
|
|
|
|
|
data.AddLine(Get(LOTSuspicious, Severity.Fishy));
|
|
|
|
|
}
|
|
|
|
|
else if (IsOTIDSuspicious(pkm.TID, pkm.SID))
|
2018-07-26 19:34:27 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(Get(LOTSuspicious, Severity.Fishy));
|
2018-07-26 19:34:27 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
|
|
|
|
|
if (pkm.VC)
|
2018-08-16 20:06:40 -07:00
|
|
|
|
{
|
2018-06-23 22:00:01 -07:00
|
|
|
|
VerifyOTG1(data);
|
2018-08-16 20:06:40 -07:00
|
|
|
|
}
|
2018-10-27 16:06:06 -07:00
|
|
|
|
else if (ot.Length > Legal.GetMaxLengthOT(data.Info.Generation, (LanguageID)pkm.Language))
|
2018-08-15 15:19:54 -07:00
|
|
|
|
{
|
2018-10-27 16:06:06 -07:00
|
|
|
|
if (!IsEdgeCaseLength(pkm, data.EncounterOriginal, ot))
|
|
|
|
|
data.AddLine(Get(LOTLong, Severity.Invalid));
|
2018-08-15 15:19:54 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
|
2018-10-05 19:58:30 -07:00
|
|
|
|
if (ParseSettings.CheckWordFilter)
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
|
|
|
|
if (WordFilter.IsFiltered(ot, out string bad))
|
|
|
|
|
data.AddLine(GetInvalid($"Wordfilter: {bad}"));
|
|
|
|
|
if (WordFilter.IsFiltered(pkm.HT_Name, out bad))
|
|
|
|
|
data.AddLine(GetInvalid($"Wordfilter: {bad}"));
|
2018-10-08 17:57:34 -07:00
|
|
|
|
if (ContainsTooManyNumbers(ot, data.Info.Generation))
|
2020-06-27 23:36:53 -05:00
|
|
|
|
data.AddLine(GetInvalid("Wordfilter: Too many numbers."));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-26 19:34:27 -07:00
|
|
|
|
|
2018-10-27 16:06:06 -07:00
|
|
|
|
public static bool IsEdgeCaseLength(PKM pkm, IEncounterable e, string ot)
|
|
|
|
|
{
|
|
|
|
|
if (e.EggEncounter)
|
|
|
|
|
{
|
2018-11-03 12:44:03 -07:00
|
|
|
|
if (e is WC3 wc3 && pkm.IsEgg && wc3.OT_Name == ot)
|
|
|
|
|
return true; // Fixed OT Mystery Gift Egg
|
2018-12-14 23:30:21 -08:00
|
|
|
|
bool eggEdge = pkm.IsEgg ? pkm.IsTradedEgg || pkm.Format == 3 : pkm.WasTradedEgg;
|
2018-10-27 16:06:06 -07:00
|
|
|
|
if (!eggEdge)
|
|
|
|
|
return false;
|
2020-05-31 12:12:48 -07:00
|
|
|
|
var len = Legal.GetMaxLengthOT(e.Generation, LanguageID.English); // max case
|
2018-10-27 16:06:06 -07:00
|
|
|
|
return ot.Length <= len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e is MysteryGift mg && mg.OT_Name.Length == ot.Length)
|
|
|
|
|
return true; // Mattle Ho-Oh
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-23 22:00:01 -07:00
|
|
|
|
public void VerifyOTG1(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
string tr = pkm.OT_Name;
|
|
|
|
|
|
2020-09-09 22:43:32 -07:00
|
|
|
|
if (tr.Length == 0)
|
|
|
|
|
{
|
2020-12-21 22:33:48 -08:00
|
|
|
|
if (pkm is SK2 {TID: 0, IsRental: true})
|
2020-10-03 21:56:57 -07:00
|
|
|
|
{
|
|
|
|
|
data.AddLine(Get(LOTShort, Severity.Fishy));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data.AddLine(GetInvalid(LOTShort));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-09 22:43:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 20:58:06 -07:00
|
|
|
|
VerifyG1OTWithinBounds(data, tr.AsSpan());
|
2018-06-23 22:00:01 -07:00
|
|
|
|
|
2021-04-18 19:31:22 -07:00
|
|
|
|
if (pkm.OT_Gender == 1)
|
|
|
|
|
{
|
|
|
|
|
if ((pkm.Format == 2 && pkm.Met_Location == 0) || (pkm.Format > 2 && pkm.VC1) || data is {EncounterOriginal: {Generation:1} or EncounterStatic2E {IsGift:true}})
|
|
|
|
|
data.AddLine(GetInvalid(LG1OTGender));
|
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
2018-07-26 19:34:27 -07:00
|
|
|
|
|
2021-06-29 20:58:06 -07:00
|
|
|
|
private void VerifyG1OTWithinBounds(LegalityAnalysis data, ReadOnlySpan<char> str)
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
2019-03-20 21:50:44 -07:00
|
|
|
|
if (StringConverter12.GetIsG1English(str))
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
2020-12-29 00:58:08 -08:00
|
|
|
|
if (str.Length > 7 && data.EncounterOriginal is not EncounterTradeGB) // OT already verified; GER shuckle has 8 chars
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LOTLong));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
2019-03-20 21:50:44 -07:00
|
|
|
|
else if (StringConverter12.GetIsG1Japanese(str))
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
|
|
|
|
if (str.Length > 5)
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LOTLong));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
2019-03-20 21:50:44 -07:00
|
|
|
|
else if (data.pkm.Korean && StringConverter2KOR.GetIsG2Korean(str))
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
|
|
|
|
if (str.Length > 5)
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LOTLong));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
2020-12-30 13:08:15 -08:00
|
|
|
|
else if (data.EncounterOriginal is not EncounterTrade2) // OT already verified; SPA Shuckle/Voltorb transferred from French can yield 2 inaccessible chars
|
2018-06-23 22:00:01 -07:00
|
|
|
|
{
|
2018-09-01 14:11:12 -07:00
|
|
|
|
data.AddLine(GetInvalid(LG1CharOT));
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-26 19:34:27 -07:00
|
|
|
|
|
2020-08-30 19:59:21 -07:00
|
|
|
|
private static bool IsOTNameSuspicious(string name)
|
2018-07-01 10:49:11 -07:00
|
|
|
|
{
|
2021-06-29 20:58:06 -07:00
|
|
|
|
foreach (var s in SuspiciousOTNames)
|
|
|
|
|
{
|
|
|
|
|
if (s.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2018-07-01 10:49:11 -07:00
|
|
|
|
}
|
2018-10-08 17:57:34 -07:00
|
|
|
|
|
2020-08-30 19:59:21 -07:00
|
|
|
|
public static bool IsOTIDSuspicious(int tid16, int sid16)
|
|
|
|
|
{
|
|
|
|
|
if (tid16 == 12345 && sid16 == 54321)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// 1234_123456 (SID7_TID7)
|
|
|
|
|
if (tid16 == 15040 && sid16 == 18831)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 17:57:34 -07:00
|
|
|
|
public static bool ContainsTooManyNumbers(string str, int originalGeneration)
|
|
|
|
|
{
|
|
|
|
|
if (originalGeneration <= 3)
|
|
|
|
|
return false; // no limit from these generations
|
|
|
|
|
int max = originalGeneration < 6 ? 4 : 5;
|
2018-10-09 19:28:18 -07:00
|
|
|
|
if (str.Length <= max)
|
2018-10-08 17:57:34 -07:00
|
|
|
|
return false;
|
|
|
|
|
int count = GetNumberCount(str);
|
|
|
|
|
return count > max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetNumberCount(string str)
|
|
|
|
|
{
|
2019-10-07 18:40:09 -07:00
|
|
|
|
static bool IsNumber(char c)
|
2018-10-08 17:57:34 -07:00
|
|
|
|
{
|
|
|
|
|
if ('0' <= c)
|
|
|
|
|
return c <= '9';
|
2021-06-03 17:08:42 -07:00
|
|
|
|
return (uint)(c - '0') <= 9;
|
2018-10-08 17:57:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 20:58:06 -07:00
|
|
|
|
int ctr = 0;
|
|
|
|
|
foreach (var c in str)
|
|
|
|
|
{
|
|
|
|
|
if (IsNumber(c))
|
|
|
|
|
++ctr;
|
|
|
|
|
}
|
|
|
|
|
return ctr;
|
2018-10-08 17:57:34 -07:00
|
|
|
|
}
|
2018-06-23 22:00:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|