From fd60369438bd3f079a391c9085638ba41d58fe38 Mon Sep 17 00:00:00 2001 From: drgoku282 Date: Sat, 25 Mar 2017 14:25:13 -0600 Subject: [PATCH] Add basic ribbon check for Wonder Trade bots --- PKMN-NTR/Bot/Bot.cs | 41 ++++++++++++++++++++++++++++++-- PKMN-NTR/Bot/Bot_WonderTrade6.cs | 21 +++++++++------- PKMN-NTR/Bot/Bot_WonderTrade7.cs | 21 +++++++++------- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/PKMN-NTR/Bot/Bot.cs b/PKMN-NTR/Bot/Bot.cs index b1e00be..56ac35a 100644 --- a/PKMN-NTR/Bot/Bot.cs +++ b/PKMN-NTR/Bot/Bot.cs @@ -16,9 +16,15 @@ public static void Report(string message) public static bool IsLegal(PKM poke) { - if (poke.GenNumber >= 6) + if (Program.gCmdWindow.enableillegal) + { + Report("Bot: Illegal mode enabled, skip check"); + return true; + } + + LegalityAnalysis Legal = new LegalityAnalysis(poke); + if (Legal.Parsed) { - LegalityAnalysis Legal = new LegalityAnalysis(poke); return Legal.Valid; } else @@ -27,6 +33,37 @@ public static bool IsLegal(PKM poke) } } + public static bool IsTradeable(PKM poke) + { + if (!IsLegal(poke)) + { // Don't trade illegal pokemon + return false; + } + + if (poke.IsEgg) + { // Don't trade eggs + return false; + } + + if (poke.Format == 6) + { + var poke6 = new PK6(poke.Data); + if (poke6.RibbonCountry || poke6.RibbonWorld || poke6.RibbonClassic || poke6.RibbonPremier || poke6.RibbonEvent || poke6.RibbonBirthday || poke6.RibbonSpecial || poke6.RibbonSouvenir || poke6.RibbonWishing || poke6.RibbonChampionBattle || poke6.RibbonChampionRegional || poke6.RibbonChampionNational || poke6.RibbonChampionWorld) + { // Check for Special Ribbons + return false; + } + } + if (poke.Format == 7) + { + var poke7 = new PK7(poke.Data); + if (poke7.RibbonCountry || poke7.RibbonWorld || poke7.RibbonClassic || poke7.RibbonPremier || poke7.RibbonEvent || poke7.RibbonBirthday || poke7.RibbonSpecial || poke7.RibbonSouvenir || poke7.RibbonWishing || poke7.RibbonChampionBattle || poke7.RibbonChampionRegional || poke7.RibbonChampionNational || poke7.RibbonChampionWorld) + { // Check for Special Ribbons + return false; + } + } + return true; + } + public static uint GetBoxOff(uint startOff, NumericUpDown boxSource, NumericUpDown slotSource) { return startOff + (uint)(boxSource.Value - 1) * 30 * 232 + (uint)(slotSource.Value - 1) * 232; diff --git a/PKMN-NTR/Bot/Bot_WonderTrade6.cs b/PKMN-NTR/Bot/Bot_WonderTrade6.cs index 9b79d9c..c9a512f 100644 --- a/PKMN-NTR/Bot/Bot_WonderTrade6.cs +++ b/PKMN-NTR/Bot/Bot_WonderTrade6.cs @@ -250,19 +250,22 @@ public async void RunBot() else { // Valid pkm, check legality attempts = 0; - if (IsLegal(WTpoke) || Program.gCmdWindow.enableillegal) + if (IsTradeable(WTpoke)) { - if (Program.gCmdWindow.enableillegal) - { - Report("Bot: Illegal pokémon, will trade it anyways"); - } currentCHK = WTpoke.Checksum; Report("Bot: Pokémon found - 0x" + currentCHK.ToString("X4")); botstate = botstates.pressWTbutton; } else { - Report("Bot: Illegal pokémon"); + if (Program.gCmdWindow.enableillegal) + { + Report("Bot: Pokémon cannot be traded, is an egg or have special ribbons."); + } + else + { + Report("Bot: Pokémon cannot be traded, is illegal or is an egg or have special ribbons."); + } getNextSlot(); } } @@ -279,14 +282,14 @@ public async void RunBot() if (temp.Length == 232) { PK6 pkmn = new PK6(temp); - if (IsLegal(pkmn) || Program.gCmdWindow.enableillegal) + if (IsTradeable(pkmn)) { // Legal pkm - Report("Bot: Illegal pokémon, will write it anyways"); + Report("Bot: Valid PK6 file"); pklist.Add(pkmn); } else { // Illegal pkm - Report("Bot: File " + pkf + " is illegal, will not be traded"); + Report("Bot: File " + pkf + " cannot be traded"); } } else diff --git a/PKMN-NTR/Bot/Bot_WonderTrade7.cs b/PKMN-NTR/Bot/Bot_WonderTrade7.cs index 3da1f31..7b87974 100644 --- a/PKMN-NTR/Bot/Bot_WonderTrade7.cs +++ b/PKMN-NTR/Bot/Bot_WonderTrade7.cs @@ -266,19 +266,22 @@ public async void RunBot() else { // Valid pkm, check legality attempts = 0; - if (IsLegal(WTpoke) || Program.gCmdWindow.enableillegal) + if (IsTradeable(WTpoke)) { - if (Program.gCmdWindow.enableillegal) - { - Report("Bot: Illegal pokémon, will trade it anyways"); - } currentCHK = WTpoke.Checksum; Report("Bot: Pokémon found - 0x" + currentCHK.ToString("X4")); botstate = botstates.writelastbox; } else { - Report("Bot: Illegal pokémon"); + if (Program.gCmdWindow.enableillegal) + { + Report("Bot: Pokémon cannot be traded, is an egg or have special ribbons."); + } + else + { + Report("Bot: Pokémon cannot be traded, is illegal or is an egg or have special ribbons."); + } getNextSlot(); } } @@ -295,14 +298,14 @@ public async void RunBot() if (temp.Length == 232) { PK7 pkmn = new PK7(temp); - if (IsLegal(pkmn)) + if (IsTradeable(pkmn)) { // Legal pkm - Report("Bot: Illegal pokémon, will write it anyways"); + Report("Bot: Valid PK7 ifle"); pklist.Add(pkmn); } else { // Illegal pkm - Report("Bot: File " + pkf + " is illegal, will not be traded"); + Report("Bot: File " + pkf + " cannot be traded"); } } else