From 7a7c8488f3cb87bd937e6396f802311d8d3470fa Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sat, 26 Mar 2016 17:23:53 -0700 Subject: [PATCH] Add Ingame Trade OT/Nick check --- Legality/Checks.cs | 34 ++++++++++++++++++++++++++++++++++ Legality/Tables.cs | 8 ++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index d729fe650..30dc0dc6f 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -67,6 +67,40 @@ private LegalityCheck verifyNickname() return new LegalityCheck(Severity.Indeterminate, "Species index invalid for Nickname comparison."); if (!Encounter.Valid) return new LegalityCheck(Severity.Valid, "Skipped Nickname check due to other check being invalid."); + + if (pk6.Language > 8) + return new LegalityCheck(Severity.Indeterminate, "Language ID > 8."); + + Type etype = EncounterMatch?.GetType(); + if (etype == typeof(EncounterTrade)) + { + string[] validOT = new string[0]; + int index = -1; + if (pk6.XY) + { + validOT = Legal.TradeXY[pk6.Language]; + index = Array.IndexOf(Legal.TradeGift_XY, EncounterMatch); + } + else if (pk6.AO) + { + validOT = Legal.TradeAO[pk6.Language]; + index = Array.IndexOf(Legal.TradeGift_AO, EncounterMatch); + } + if (validOT.Length == 0) + return new LegalityCheck(Severity.Indeterminate, "Ingame Trade invalid version?"); + if (index == -1 || validOT.Length < index * 2) + return new LegalityCheck(Severity.Indeterminate, "Ingame Trade invalid lookup?"); + + string nick = validOT[index]; + string OT = validOT[validOT.Length/2 + index]; + + if (nick != pk6.Nickname) + return new LegalityCheck(Severity.Fishy, "Ingame Trade nickname has been altered."); + if (OT != pk6.OT_Name) + return new LegalityCheck(Severity.Invalid, "Ingame Trade OT has been altered."); + + return new LegalityCheck(Severity.Valid, "Ingame Trade OT/Nickname have not been altered."); + } if (pk6.IsEgg) { diff --git a/Legality/Tables.cs b/Legality/Tables.cs index badb3bc7c..8b13c550a 100644 --- a/Legality/Tables.cs +++ b/Legality/Tables.cs @@ -444,7 +444,7 @@ public static partial class Legal 538, 539, // Sawk & Throh }; - private static readonly string[][] TradeXY = + internal static readonly string[][] TradeXY = { new string[0], // 0 - None Util.getStringList("tradexy", "ja"), // 1 @@ -456,7 +456,7 @@ public static partial class Legal Util.getStringList("tradexy", "es"), // 7 Util.getStringList("tradexy", "ko"), // 8 }; - private static readonly string[][] TradeAO = + internal static readonly string[][] TradeAO = { new string[0], // 0 - None Util.getStringList("tradeao", "ja"), // 1 @@ -647,7 +647,7 @@ public static partial class Legal }; #endregion #region Trade Tables - private static readonly EncounterTrade[] TradeGift_XY = + internal static readonly EncounterTrade[] TradeGift_XY = { new EncounterTrade { Species = 129, Level = 5, Ability = 1, Gender = 0, TID = 44285, Nature = Nature.Adamant, }, // Magikarp new EncounterTrade { Species = 133, Level = 5, Ability = 1, Gender = 1, TID = 29294, Nature = Nature.Docile, }, // Eevee @@ -662,7 +662,7 @@ public static partial class Legal new EncounterTrade { Species = 280, Level = 5, Ability = 1, Gender = 1, TID = 37110, Nature = Nature.Modest, IVs = new[] {20, 20, 20, 31, 31, 20}, }, // Ralts }; - private static readonly EncounterTrade[] TradeGift_AO = + internal static readonly EncounterTrade[] TradeGift_AO = { new EncounterTrade { Species = 296, Level = 9, Ability = 2, Gender = 0, TID = 30724, Nature = Nature.Brave, IVs = new[] {-1, 31, -1, -1, -1, -1}, }, // Makuhita new EncounterTrade { Species = 300, Level = 25, Ability = 1, Gender = 1, TID = 03239, Nature = Nature.Naughty, IVs = new[] {-1, -1, -1, 31, -1, -1}, }, // Skitty