private void btn_Inject_Click(object sender, EventArgs e) { if (tb_FileInjection.Text == "") { MessageBox.Show("Please select a file!", "Ledybot", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] pkmEncrypted = System.IO.File.ReadAllBytes(tb_FileInjection.Text); byte[] cloneshort = PKHeX.encryptArray(pkmEncrypted.Take(232).ToArray()); uint boxIndex = Decimal.ToUInt32((nud_BoxInjection.Value - 1) * 30 + nud_SlotInjection.Value - 1); uint count = Decimal.ToUInt32(nud_CountInjection.Value); if (boxIndex + count > 32 * 30) { uint newCount = 32 * 30 - boxIndex; count = newCount; } byte[] dataToWrite = new byte[count * 232]; for (int i = 0; i < count; i++) { cloneshort.CopyTo(dataToWrite, i * 232); } uint offset = boxOff + boxIndex * 232; Program.scriptHelper.write(offset, dataToWrite, pid); MessageBox.Show("Injection Successful!"); }
static void Main() { ntrClient = new NTR(); scriptHelper = new ScriptHelper(); helper = new RemoteControl(); PKTable = new LookupTable(); pkhex = new PKHeX(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); f1 = new MainForm(); gd = new GiveawayDetails(); bld = new BanlistDetails(); Application.Run(f1); }
static void Main() { ntrClient = new NTR(); ntrClient.DataReady += NTR.handleDataReady; PKTable = new LookupTable(); pkhex = new PKHeX(); data = new Data(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); f1 = new MainForm(); gd = new GiveawayDetails(); bld = new BanlistDetails(); scriptHelper = new ScriptHelper(ntrClient); scriptHelper.onAutoDisconnect += f1.startAutoDisconnect; helper = new RemoteControl(scriptHelper, ntrClient); helper.onDumpedPKHeXData += setDumpedData; Application.Run(f1); }
public async Task <int> RunBot() { byte[] pokemonIndex = new byte[2]; byte pokemonGender = 0x0; byte pokemonLevel = 0x0; byte[] full = BitConverter.GetBytes(iPokemonToFind); pokemonIndex[0] = full[0]; pokemonIndex[1] = full[1]; full = BitConverter.GetBytes(iPokemonToFindGender); pokemonGender = full[0]; full = BitConverter.GetBytes(iPokemonToFindLevel); pokemonLevel = full[0]; try { while (!botstop) { switch (botState) { case (int)gtsbotstates.botstart: if (bReddit) { Program.f1.updateJSON(); } botState = (int)gtsbotstates.pressSeek; break; case (int)gtsbotstates.updatecomments: Program.f1.updateJSON(); botState = (int)gtsbotstates.research; break; case (int)gtsbotstates.pressSeek: correctScreen = await isCorrectWindow(SeekDepositScreen); if (!correctScreen) { botState = (int)gtsbotstates.panic; break; } Program.f1.ChangeStatus("Pressing seek button"); await Program.helper.waitbutton(Program.PKTable.keyA); await Task.Delay(1000); botState = (int)gtsbotstates.startsearch; break; case (int)gtsbotstates.startsearch: correctScreen = await isCorrectWindow(SearchScreen); if (!correctScreen) { botState = (int)gtsbotstates.panic; break; } //Write wanted Pokemon, Level, Gender to Ram, won't Display it but works. Program.f1.ChangeStatus("Setting Pokemon to find"); waitTaskbool = Program.helper.waitNTRwrite(PokemonToFind, pokemonIndex, iPID); waitTaskbool = Program.helper.waitNTRwrite(PokemonToFindGender, pokemonGender, iPID); waitTaskbool = Program.helper.waitNTRwrite(PokemonToFindLevel, pokemonLevel, iPID); botState = (int)gtsbotstates.presssearch; break; case (int)gtsbotstates.presssearch: Program.f1.ChangeStatus("Pressing Search button"); Program.helper.quicktouch(200, 180, commandtime); if (searchDirection == SEARCHDIRECTION_FROMBACK) { //Write Index while Loading the Frame. await Task.Delay(1000); await Program.helper.waitNTRwrite(GTSPageIndex, (uint)startIndex, iPID); } await Task.Delay(4000); botState = (int)gtsbotstates.findPokemon; break; case (int)gtsbotstates.findPokemon: correctScreen = await isCorrectWindow(GTSScreen); if (!correctScreen) { botState = (int)gtsbotstates.panic; break; } else { } await Program.helper.waitNTRread(GTSPageSize); uint Entries = (Program.helper.lastRead); CurrentView = Entries; if (Entries == 100 && !foundLastPage && searchDirection == SEARCHDIRECTION_FROMBACK) { Program.f1.ChangeStatus("Moving to last page"); int PageMoveAttemps = 0; // Change current Page, everytime + 100 while (!foundLastPage) { startIndex += 100; await Program.helper.waitNTRwrite(GTSPageIndex, (uint)startIndex, iPID); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime + 1000); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime + 1000); await Program.helper.waitNTRread(GTSPageSize); Entries = Program.helper.lastRead; if (Entries < 99) { foundLastPage = true; CurrentView = Entries; } if (PageMoveAttemps >= 10) { // Frame writen to low, return Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 1000); botState = (int)gtsbotstates.pressSeek; } PageMoveAttemps++; } } Program.f1.ChangeStatus("Looking for a Pokemon to Trade"); if (Entries > 100) { Entries = 1; } // Workaroung for only 1 Entry on List // Check the Trade Direction Back to Front or Front to Back if (searchDirection == SEARCHDIRECTION_FROMBACK || searchDirection == SEARCHDIRECTION_FROMBACKFIRSTPAGEONLY) { CurrentView = Entries; iStartIndex = (int)Entries - 1; iEndIndex = 1; iDirection = -1; } else { CurrentView = 0; iStartIndex = 1; iEndIndex = (int)Entries + 1; iDirection = 1; } // Reading all Entries on Current Page await Program.helper.waitNTRread(GTSListBlock, (uint)(256 * 100)); byte[] blockBytes = Program.helper.lastArray; for (int i = iStartIndex; i *iDirection < iEndIndex; i += iDirection) { //Get the Current Entry Data Array.Copy(blockBytes, (GTSBlockEntrySize * i) - Program.helper.lastRead, block, 0, 256); //Collect Data dex = BitConverter.ToInt16(block, 0x0); if (Program.f1.giveawayDetails.ContainsKey(dex)) { Program.f1.giveawayDetails.TryGetValue(dex, out details); if (details.Item1 == "") { string szNickname = Encoding.Unicode.GetString(block, 0x4, 24).Substring(2).Trim('\0'); //fix to prevent nickname clipping. Count should be 24, 2 bytes per letter, 2x12=24, not 20. string szFileToFind = details.Item2 + szNickname + ".pk7"; if (!File.Exists(szFileToFind)) { continue; } } Array.Copy(block, 0x3C, principal, 0, 4); byte check = Program.f1.calculateChecksum(principal); byte[] friendcode = new byte[8]; Array.Copy(principal, 0, friendcode, 0, 4); friendcode[4] = check; long i_FC = BitConverter.ToInt64(friendcode, 0); szFC = i_FC.ToString().PadLeft(12, '0'); int gender = block[0x2]; int level = block[0x3]; if ((gender == 0 || gender == details.Item3) && (level == 0 || level == details.Item4)) { szTrainerName = Encoding.Unicode.GetString(block, 0x40, 24).Trim('\0'); //Phrase = Encoding.Unicode.GetString(block, 0x5A, 30).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x2F); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x31); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); if (useLedySync && !Program.f1.banlist.Contains(szFC) && canThisTrade(principal, consoleName, szTrainerName, country, subregion, Program.PKTable.Species6[dex - 1], szFC, PageIndex + "", (i - 1) + "")) { PokemonFound = true; CurrentView = (uint)i; Program.f1.ChangeStatus("Found a pokemon to trade"); botState = (int)gtsbotstates.trade; break; } else if (!useLedySync) { if ((!bReddit || Program.f1.commented.Contains(szFC)) && !details.Item6.Contains(BitConverter.ToInt32(principal, 0)) && !Program.f1.banlist.Contains(szFC)) { PokemonFound = true; CurrentView = (uint)i; Program.f1.ChangeStatus("Found a pokemon to trade"); botState = (int)gtsbotstates.trade; break; } } } } if (searchDirection == SEARCHDIRECTION_FROMBACK && startIndex > 100 && i * iDirection < iEndIndex) { Program.f1.ChangeStatus("No pokemon to trade on this page, try previous page"); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime + 1000); startIndex -= 200; await Program.helper.waitNTRwrite(GTSPageIndex, (uint)startIndex, iPID); await Task.Delay(commandtime + delaytime + 1000); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime + 1000); await Program.helper.waitNTRread(GTSPageSize); i = (int)Program.helper.lastRead; } PokemonFound = false; } // No Pokemon found, return to Seek/Deposit Screen if (!PokemonFound) { Program.f1.ChangeStatus("No Pokemon Found"); botState = (int)gtsbotstates.research; break; } break; case (int)gtsbotstates.trade: Program.f1.ChangeStatus("Found a pokemon to trade"); waitTaskbool = Program.helper.waitNTRread(GTSPageIndex); if (await waitTaskbool) { string szNickname = Encoding.Unicode.GetString(block, 0x4, 24).Substring(2).Trim('\0'); //fix to prevent nickname clipping. Count should be 24, 2 bytes per letter, 2x12=24, not 20. string szPath = details.Item1; string szFileToFind = details.Item2 + szNickname + ".pk7"; if (File.Exists(szFileToFind)) { szPath = szFileToFind; } string szTrainerName = Encoding.Unicode.GetString(block, 0x40, 24).Trim('\0'); //Phrase = Encoding.Unicode.GetString(block, 0x5A, 30).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x30); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x30); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); if (bBlacklist) { details.Item6.Add(BitConverter.ToInt32(principal, 0)); } //Inject Pokemon to Box1 Slot1 byte[] pkmEncrypted = System.IO.File.ReadAllBytes(szPath); byte[] cloneshort = PKHeX.encryptArray(pkmEncrypted.Take(232).ToArray()); string ek7 = BitConverter.ToString(cloneshort).Replace("-", ", 0x"); Program.scriptHelper.write(BoxInject, cloneshort, iPID); await Program.helper.waitNTRread(GTSPageIndex); PageIndex = (Program.helper.lastRead + 1); Program.f1.AppendListViewItem(szTrainerName, szNickname, country, subregion, Program.PKTable.Species6[dex - 1], szFC, (PageIndex / 100).ToString(), CurrentView.ToString()); // Open Settings, write CurrentView Index to wanted, return. Program.helper.quickbuton(Program.PKTable.keyY, 200); await Task.Delay(1200); await Program.helper.waitNTRwrite(GTSCurrentView, (uint)CurrentView, iPID); Program.helper.quickbuton(Program.PKTable.keyB, 200); await Task.Delay(1500); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(3000); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(1500); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(1500); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(1500); //Now we have the right Entry, enter current viewed Entry Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(500); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(500); Program.helper.quickbuton(Program.PKTable.keyA, 200); await Task.Delay(500); Program.helper.quickbuton(Program.PKTable.keyA, 200); Program.f1.ChangeStatus("Trading pokemon on page " + (PageIndex / 100).ToString() + " index " + CurrentView.ToString() + ""); await Task.Delay(10000); if (details.Item5 > 0) { Program.f1.giveawayDetails[dex] = new Tuple <string, string, int, int, int, ArrayList>(details.Item1, details.Item2, details.Item3, details.Item4, details.Item5 - 1, details.Item6); foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dex.ToString()) { int count = int.Parse(row[5].ToString()) - 1; row[5] = count; break; } } } foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dex.ToString()) { int amount = int.Parse(row[6].ToString()) + 1; row[6] = amount; break; } } //In Case the Pokemon is already traded, go back to Seek/Deposit Screen Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(1000); // wait if trade is finished await Task.Delay(35000); bool cont = false; foreach (KeyValuePair <int, Tuple <string, string, int, int, int, ArrayList> > pair in Program.f1.giveawayDetails) { if (pair.Value.Item5 != 0) { cont = true; break; } } if (!cont) { botresult = 1; botState = (int)gtsbotstates.botexit; break; } startIndex = 0; CurrentView = 0; foundLastPage = false; PokemonFound = false; if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.botstart; break; } } break; case (int)gtsbotstates.research: Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(3000); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(3000); botState = (int)gtsbotstates.pressSeek; break; case (int)gtsbotstates.botexit: Program.f1.ChangeStatus("Stopped"); botstop = true; break; case (int)gtsbotstates.panic: if (!Program.Connected) { Program.scriptHelper.connect(szIP, 8000); } Program.f1.ChangeStatus("Recovery Mode"); //In case of a Communication Error Program.helper.quicktouch(50, 0, commandtime); await Task.Delay(250); Program.helper.quickbuton(Program.PKTable.keySELECT, commandtime); //Check if Connected waitTaskbool = Program.helper.waitNTRread(IsConnected); if (await waitTaskbool) { if (Program.helper.lastRead == 0) { Program.f1.ChangeStatus("Recovery Mode - lost connection, trying to reconnect..."); Program.helper.quicktouch(235, 5, commandtime); await Task.Delay(2000); Program.helper.quicktouch(150, 140, commandtime); await Task.Delay(3000); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(30000); //Disconnected } } await Program.helper.waitNTRread(PSSMenuOFF); //Re-Enter GTS if (Program.helper.lastRead == PSSMenuIN) { Program.f1.ChangeStatus("Recovery Mode - PSS Menu detected, re-enter GTS..."); Program.helper.quicktouch(100, 50, commandtime); await Task.Delay(3000); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(15000); botState = (int)gtsbotstates.botstart; break; } await Program.helper.waitNTRread(currentScreen); if ((int)Program.helper.lastRead == GTSScreen) { Program.f1.ChangeStatus("Recovery Mode - GTS Screen Detected!"); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(2000); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(2000); botState = (int)gtsbotstates.botstart; break; } if ((int)Program.helper.lastRead == SearchScreen) { Program.f1.ChangeStatus("Recovery Mode - Search Screen Detected!"); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(2000); botState = (int)gtsbotstates.botstart; break; } if ((int)Program.helper.lastRead == SeekDepositScreen) { Program.f1.ChangeStatus("Recovery Mode - Seek/Deposit Screen Detected!"); botState = (int)gtsbotstates.botstart; break; } if ((int)Program.helper.lastRead == iPokemonToFind) { Program.f1.ChangeStatus("Recovery Mode - Search Screen Detected!"); Program.helper.quicktouch(50, 0, commandtime); await Task.Delay(2000); Program.helper.quickbuton(Program.PKTable.keyB, 250); await Task.Delay(2000); botState = (int)gtsbotstates.botstart; break; } // Spam B to get out of GTS for (int i = 0; i < 20; i++) { Program.f1.ChangeStatus("Recovery Mode - trying return to PSS Menu..."); Program.helper.quickbuton(Program.PKTable.keyB, commandtime + 200); await Task.Delay(500); } await Task.Delay(10000); botState = (int)gtsbotstates.botstart; break; default: botresult = -1; botstop = true; break; } } } catch { botState = (int)gtsbotstates.panic; } if (this.serverEndPoint != null) { client.Close(); } return(botresult); }
public async Task <int> RunBot() { bool correctScreen = true; byte[] pokemonIndex = new byte[2]; byte pokemonGender = 0x0; byte pokemonLevel = 0x0; byte[] full = BitConverter.GetBytes(iPokemonToFind); pokemonIndex[0] = full[0]; pokemonIndex[1] = full[1]; full = BitConverter.GetBytes(iPokemonToFindGender); pokemonGender = full[0]; full = BitConverter.GetBytes(iPokemonToFindLevel); pokemonLevel = full[0]; int panicAttempts = 0; while (!botstop) { if (botState != (int)gtsbotstates.panic) { panicAttempts = 0; } switch (botState) { case (int)gtsbotstates.botstart: if (bReddit) { Program.f1.updateJSON(); } botState = (int)gtsbotstates.startsearch; break; case (int)gtsbotstates.updatecomments: Program.f1.updateJSON(); botState = (int)gtsbotstates.research; break; case (int)gtsbotstates.startsearch: Program.f1.ChangeStatus("Setting Pokemon to find"); waitTaskbool = Program.helper.waitNTRwrite(addr_pokemonToFind, pokemonIndex, iPID); waitTaskbool = Program.helper.waitNTRwrite(addr_pokemonToFindGender, pokemonGender, iPID); waitTaskbool = Program.helper.waitNTRwrite(addr_pokemonToFindLevel, pokemonLevel, iPID); botState = (int)gtsbotstates.pressSeek; break; case (int)gtsbotstates.pressSeek: Program.f1.ChangeStatus("Pressing seek button"); //Seek/Deposite pokemon screen correctScreen = await isCorrectWindow(val_Quit_SeekScreen); if (!correctScreen) { botState = (int)gtsbotstates.panic; break; } await Program.helper.waittouch(160, 80); await Task.Delay(commandtime + delaytime); botState = (int)gtsbotstates.presssearch; break; case (int)gtsbotstates.presssearch: Program.f1.ChangeStatus("Press search button"); correctScreen = await isCorrectWindow(val_SearchScreen); if (!correctScreen) { botState = (int)gtsbotstates.panic; break; } //Pokemon wanted screen again, this time with filled out information await Task.Delay(2000); waitTaskbool = Program.helper.waittouch(160, 185); if (await waitTaskbool) { botState = (int)gtsbotstates.findfromstart; await Task.Delay(2250); } else { attempts++; botresult = 6; botState = (int)gtsbotstates.startsearch; } break; case (int)gtsbotstates.findfromstart: correctScreen = await isCorrectWindow(val_GTSListScreen); if (!correctScreen) { //Hotfix for Only one Pokemon on List if (Program.helper.lastRead == 0x40F5) { // No Entries found. botState = (int)gtsbotstates.panic; break; } else if (Program.helper.lastRead == 0x40C0) { // Only one Pokemon on List, ignore. } else { botState = (int)gtsbotstates.panic; break; } } //GTS entry list screen, cursor at position 1 await Program.helper.waitNTRread(addr_PageSize); attempts = 0; listlength = (int)Program.helper.lastRead; if (listlength == 100 && !foundLastPage && searchDirection == SEARCHDIRECTION_FROMBACK) { Program.f1.ChangeStatus("Moving to last page"); waitTaskbool = Program.helper.waitNTRread(addr_PageStartingIndex); if (await waitTaskbool) { startIndex = (int)Program.helper.lastRead; waitTaskbool = Program.helper.waitNTRwrite(addr_PageStartingIndex, (uint)(startIndex + 200), iPID); if (await waitTaskbool) { startIndex += 100; Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); //prevent potential loop by going left once more before the page is actually loaded Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); await Program.helper.waitNTRread(addr_PageStartingIndex); if (Program.helper.lastRead == 0) { foundLastPage = true; } else { botState = (int)gtsbotstates.findfromend; } } } } else { Program.f1.ChangeStatus("Looking for a pokemon to trade"); foundLastPage = true; attempts = 0; listlength = (int)Program.helper.lastRead; dexnumber = 0; if (searchDirection == SEARCHDIRECTION_FROMBACK || searchDirection == SEARCHDIRECTION_FROMBACKFIRSTPAGEONLY) { await Program.helper.waitNTRread(addr_PageEndStartRecord); } else { await Program.helper.waitNTRread(addr_PageStartStartRecord); } addr_PageEntry = Program.helper.lastRead; await Program.helper.waitNTRread(addr_ListOfAllPageEntries, (uint)(256 * 100)); byte[] blockBytes = Program.helper.lastArray; int iStartIndex, iEndIndex, iDirection, iNextPrevBlockOffest; if (searchDirection == SEARCHDIRECTION_FROMBACK || searchDirection == SEARCHDIRECTION_FROMBACKFIRSTPAGEONLY) { iStartIndex = listlength; iEndIndex = 0; iDirection = -1; iNextPrevBlockOffest = 0; } else { iStartIndex = 1; iEndIndex = listlength + 1; iDirection = 1; iNextPrevBlockOffest = 4; } for (int i = iStartIndex; i *iDirection < iEndIndex; i += iDirection) { Array.Copy(blockBytes, addr_PageEntry - addr_ListOfAllPageEntries, block, 0, 256); dexnumber = BitConverter.ToInt16(block, 0xC); if (Program.f1.giveawayDetails.ContainsKey(dexnumber)) { Program.f1.giveawayDetails.TryGetValue(dexnumber, out details); if (details.Item1 == "") { string szNickname = Encoding.Unicode.GetString(block, 0x14, 24).Trim('\0'); //fix to prevent nickname clipping. Count should be 24, 2 bytes per letter, 2x12=24, not 20. string szFileToFind = details.Item2 + szNickname + ".pk7"; if (!File.Exists(szFileToFind)) { addr_PageEntry = BitConverter.ToUInt32(block, iNextPrevBlockOffest); continue; } } Array.Copy(block, 0x48, principal, 0, 4); byte checksum = Program.f1.calculateChecksum(principal); byte[] fc = new byte[8]; Array.Copy(principal, 0, fc, 0, 4); fc[4] = checksum; long iFC = BitConverter.ToInt64(fc, 0); szFC = iFC.ToString().PadLeft(12, '0'); int gender = block[0xE]; int level = block[0xF]; if ((gender == 0 || gender == details.Item3) && (level == 0 || level == details.Item4)) { string szTrainerName = Encoding.Unicode.GetString(block, 0x4C, 24).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x68); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x6A); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); int ipage = Convert.ToInt32(Math.Floor(startIndex / 100.0)) + 1; if (useLedySync && !Program.f1.banlist.Contains(szFC) && canThisTrade(principal, consoleName, szTrainerName, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, ipage + "", (i - 1) + "")) { Program.f1.ChangeStatus("Found a pokemon to trade"); tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } else if (!useLedySync) { if ((!bReddit || Program.f1.commented.Contains(szFC)) && !details.Item6.Contains(BitConverter.ToInt32(principal, 0)) && !Program.f1.banlist.Contains(szFC)) { tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } } } } addr_PageEntry = BitConverter.ToUInt32(block, iNextPrevBlockOffest); } if (tradeIndex == -1) { if (startIndex == 0) { Program.f1.ChangeStatus("No pokemon to trade found"); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } else { Program.f1.ChangeStatus("No pokemon to trade on this page, try previous page"); startIndex -= 100; Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(2250); botState = (int)gtsbotstates.findfromend; } } } break; case (int)gtsbotstates.findfromend: correctScreen = await isCorrectWindow(val_GTSListScreen); { //Hotfix for Only one Pokemon on List if (Program.helper.lastRead == 0x40F5) { // No Entries found. botState = (int)gtsbotstates.panic; break; } else if (Program.helper.lastRead == 0x40C0) { // Only one Pokemon on List, ignore. } else { botState = (int)gtsbotstates.panic; break; } } //also GTS entry list screen, but cursor is at the end of the list in this case await Program.helper.waitNTRread(addr_PageSize); attempts = 0; listlength = (int)Program.helper.lastRead; if (listlength == 100 && !foundLastPage) { Program.f1.ChangeStatus("Moving to last page"); startIndex += 100; Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); await Program.helper.waitNTRread(addr_PageStartingIndex); if (Program.helper.lastRead == 0) { foundLastPage = true; } botState = (int)gtsbotstates.findfromstart; } else { foundLastPage = true; attempts = 0; listlength = (int)Program.helper.lastRead; dexnumber = 0; await Program.helper.waitNTRread(addr_PageEndStartRecord); addr_PageEntry = Program.helper.lastRead; await Program.helper.waitNTRread(addr_ListOfAllPageEntries, (uint)(256 * 100)); byte[] blockBytes = Program.helper.lastArray; for (int i = listlength; i > 0; i--) { Program.f1.ChangeStatus("Looking for a pokemon to trade"); Array.Copy(blockBytes, addr_PageEntry - addr_ListOfAllPageEntries, block, 0, 256); dexnumber = BitConverter.ToInt16(block, 0xC); if (Program.f1.giveawayDetails.ContainsKey(dexnumber)) { Program.f1.giveawayDetails.TryGetValue(dexnumber, out details); if (details.Item1 == "") { string szNickname = Encoding.Unicode.GetString(block, 0x14, 24).Trim('\0'); //fix to prevent nickname clipping. Count should be 24, 2 bytes per letter, 2x12=24, not 20. string szFileToFind = details.Item2 + szNickname + ".pk7"; if (!File.Exists(szFileToFind)) { addr_PageEntry = BitConverter.ToUInt32(block, 0); continue; } } Array.Copy(block, 0x48, principal, 0, 4); byte checksum = Program.f1.calculateChecksum(principal); byte[] fc = new byte[8]; Array.Copy(principal, 0, fc, 0, 4); fc[4] = checksum; long iFC = BitConverter.ToInt64(fc, 0); szFC = iFC.ToString().PadLeft(12, '0'); int gender = block[0xE]; int level = block[0xF]; if ((gender == 0 || gender == details.Item3) && (level == 0 || level == details.Item4)) { string szTrainerName = Encoding.Unicode.GetString(block, 0x4C, 24).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x68); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x6A); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); int ipage = Convert.ToInt32(Math.Floor(startIndex / 100.0)) + 1; if (useLedySync && !Program.f1.banlist.Contains(szFC) && canThisTrade(principal, consoleName, szTrainerName, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, ipage + "", (i - 1) + "")) { Program.f1.ChangeStatus("Found a pokemon to trade"); tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } else if (!useLedySync) { if ((!bReddit || Program.f1.commented.Contains(szFC)) && !details.Item6.Contains(BitConverter.ToInt32(principal, 0)) && !Program.f1.banlist.Contains(szFC)) { tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } } } } addr_PageEntry = BitConverter.ToUInt32(block, 0); } if (tradeIndex == -1) { if (listlength < 100 && startIndex >= 200) { Program.f1.ChangeStatus("No pokemon to trade on this page, try previous page"); for (int i = 0; i < listlength; i++) { Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); } startIndex -= 100; await Task.Delay(2250); botState = (int)gtsbotstates.findfromend; //hope this is right } else if (startIndex >= 200) { Program.f1.ChangeStatus("No pokemon to trade on this page, try previous page"); waitTaskbool = Program.helper.waitNTRwrite(addr_PageStartingIndex, (uint)(startIndex - 200), iPID); if (await waitTaskbool) { await Program.helper.waitNTRwrite(addr_PageSize, 0x64, iPID); startIndex -= 100; Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); botState = (int)gtsbotstates.findfromstart; } } else if (startIndex == 0) { Program.f1.ChangeStatus("No pokemon to trade found"); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } else if (startIndex < 200) { Program.f1.ChangeStatus("No pokemon to trade found"); botState = (int)gtsbotstates.quicksearch; } } } break; case (int)gtsbotstates.trade: //still in GTS list screen //write index we want to trade int page = Convert.ToInt32(Math.Floor(startIndex / 100.0)) + 1; Program.f1.ChangeStatus("Trading pokemon on page " + page + " index " + tradeIndex + ""); waitTaskbool = Program.helper.waitNTRwrite(addr_PageCurrentView, BitConverter.GetBytes(tradeIndex), iPID); if (await waitTaskbool) { string szNickname = Encoding.Unicode.GetString(block, 0x14, 24).Trim('\0'); //fix to prevent nickname clipping. Count should be 24, 2 bytes per letter, 2x12=24, not 20. string szPath = details.Item1; string szFileToFind = details.Item2 + szNickname + ".pk7"; if (File.Exists(szFileToFind)) { szPath = szFileToFind; } byte[] pkmEncrypted = System.IO.File.ReadAllBytes(szPath); byte[] cloneshort = PKHeX.encryptArray(pkmEncrypted.Take(232).ToArray()); string ek7 = BitConverter.ToString(cloneshort).Replace("-", ", 0x"); //optional: grab some trainer data string szTrainerName = Encoding.Unicode.GetString(block, 0x4C, 24).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x68); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x6A); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); if (bBlacklist) { details.Item6.Add(BitConverter.ToInt32(principal, 0)); } Program.f1.AppendListViewItem(szTrainerName, szNickname, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, page + "", tradeIndex + ""); //Inject the Pokemon to box1slot1 Program.scriptHelper.write(addr_box1slot1, cloneshort, iPID); //spam a to trade pokemon Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime + 2500 + o3dswaittime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); if (details.Item5 > 0) { Program.f1.giveawayDetails[dexnumber] = new Tuple <string, string, int, int, int, ArrayList>(details.Item1, details.Item2, details.Item3, details.Item4, details.Item5 - 1, details.Item6); foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dexnumber.ToString()) { int count = int.Parse(row[5].ToString()) - 1; row[5] = count; break; } } } foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dexnumber.ToString()) { int amount = int.Parse(row[6].ToString()) + 1; row[6] = amount; break; } } //during the trade spam a/b to get back to the start screen in case of "this pokemon has been traded" await Task.Delay(10250); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(32000); bool cont = false; foreach (KeyValuePair <int, Tuple <string, string, int, int, int, ArrayList> > pair in Program.f1.giveawayDetails) { if (pair.Value.Item5 != 0) { cont = true; break; } } if (!cont) { botresult = 1; botState = (int)gtsbotstates.botexit; break; } startIndex = 0; tradeIndex = -1; listlength = 0; addr_PageEntry = 0; foundLastPage = false; if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } break; case (int)gtsbotstates.quicksearch: //end of list reach, press b and "search" again to reach GTS list again Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); await Program.helper.waittouch(160, 185); await Task.Delay(2250); botState = (int)gtsbotstates.findfromstart; break; case (int)gtsbotstates.research: //press a and "search" again to reach GTS list again Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime + 1000); await Program.helper.waittouch(160, 185); await Task.Delay(2250); botState = (int)gtsbotstates.findfromstart; break; case (int)gtsbotstates.botexit: Program.f1.ChangeStatus("Stopped"); botstop = true; break; case (int)gtsbotstates.panic: Program.f1.ChangeStatus("Recovery mode!"); //recover from weird state here await Program.helper.waitNTRread(addr_currentScreen); int screenID = (int)Program.helper.lastRead; if (screenID == val_PlazaScreen) { await Program.helper.waittouch(200, 120); await Task.Delay(1000); await Program.helper.waittouch(200, 120); await Task.Delay(8000); correctScreen = await isCorrectWindow(val_Quit_SeekScreen); if (correctScreen) { botState = (int)gtsbotstates.startsearch; break; } else { botState = (int)gtsbotstates.botexit; break; } } else if (screenID == val_Quit_SeekScreen) { //press b, press where seek button would be, press b again -> guaranteed seek screen Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); await Program.helper.waittouch(160, 80); await Task.Delay(2250); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); botState = (int)gtsbotstates.startsearch; break; } else if (screenID == val_WhatPkmnScreen) { //can only exit this one by pressing the ok button waitTaskbool = Program.helper.waitbutton(Program.PKTable.keySTART); if (await waitTaskbool) { waitTaskbool = Program.helper.waitbutton(Program.PKTable.keyA); if (await waitTaskbool) { botState = (int)gtsbotstates.panic; break; } } } else // if(screenID == val_SearchScreen || screenID == val_BoxScreen || screenID == val_GTSListScreen) { //spam b a lot and hope we get to val_quit_seekscreen like this for (int i = 0; i < 5; i++) { Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); await Task.Delay(1000); } correctScreen = await isCorrectWindow(val_Quit_SeekScreen); if (correctScreen) { botState = (int)gtsbotstates.panic; break; } else { Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime + 500); for (int i = 0; i < 5; i++) { Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); await Task.Delay(1000); } correctScreen = await isCorrectWindow(val_Quit_SeekScreen); if (correctScreen) { botState = (int)gtsbotstates.panic; break; } else { if (panicAttempts == 0) { panicAttempts++; botState = (int)gtsbotstates.panic; break; } botState = (int)gtsbotstates.botexit; break; } } } break; default: botresult = -1; botstop = true; break; } } if (this.serverEndPointSync != null) { syncClient.Close(); } if (this.serverEndPointTV != null) { tvClient.Close(); } return(botresult); }
public async Task <int> RunBot() { while (!botstop) { switch (botState) { case (int)gtsbotstates.botstart: if (bReddit) { Program.f1.updateJSON(); } botState = (int)gtsbotstates.startsearch; break; case (int)gtsbotstates.updatecomments: Program.f1.updateJSON(); botState = (int)gtsbotstates.research; break; case (int)gtsbotstates.startsearch: Program.helper.quicktouch(128, 64, commandtime); await Task.Delay(commandtime + delaytime); botState = (int)gtsbotstates.openpokemonwanted; break; case (int)gtsbotstates.openpokemonwanted: await Task.Delay(500); Program.helper.quicktouch(128, 50, commandtime); await Task.Delay(commandtime + delaytime); botState = (int)gtsbotstates.openwhatpokemon; break; case (int)gtsbotstates.openwhatpokemon: await Task.Delay(500); Program.helper.quickbuton(Program.PKTable.DpadUP, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); botState = (int)gtsbotstates.typepokemon; break; case (int)gtsbotstates.typepokemon: await Task.Delay(3000); byte[] name = new byte[this.szPokemonToFind.Length * 2]; for (int i = 0; i < szPokemonToFind.Length; i++) { name[i * 2] = (byte)szPokemonToFind[i]; name[i * 2 + 1] = 0x00; } //I like this solution so much waitTaskbool = Program.helper.waitNTRwrite(0x301118D4, name, iPID); if (await waitTaskbool) { attempts = 0; waitTaskbool = Program.helper.waitbutton(Program.PKTable.keySTART); if (await waitTaskbool) { waitTaskbool = Program.helper.waitbutton(Program.PKTable.keyA); if (await waitTaskbool) { botState = (int)gtsbotstates.presssearch; } } } else { attempts = 11; botresult = -1; botState = (int)gtsbotstates.botexit; break; } break; case (int)gtsbotstates.presssearch: await Task.Delay(2000); waitTaskbool = Program.helper.waittouch(160, 185); if (await waitTaskbool) { botState = (int)gtsbotstates.findfromstart; await Task.Delay(2250); } else { attempts++; botresult = 6; botState = (int)gtsbotstates.startsearch; } break; case (int)gtsbotstates.findfromstart: await Program.helper.waitNTRread(addr_PageSize); attempts = 0; listlength = (int)Program.helper.lastRead; if (listlength == 100 && !foundLastPage) { waitTaskbool = Program.helper.waitNTRread(addr_PageStartingIndex); if (await waitTaskbool) { startIndex = (int)Program.helper.lastRead; waitTaskbool = Program.helper.waitNTRwrite(addr_PageStartingIndex, (uint)(startIndex + 200), iPID); if (await waitTaskbool) { startIndex += 100; Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); await Program.helper.waitNTRread(addr_PageStartingIndex); if (Program.helper.lastRead == 0) { foundLastPage = true; } else { botState = (int)gtsbotstates.findfromend; } } } } else { foundLastPage = true; attempts = 0; listlength = (int)Program.helper.lastRead; dexnumber = 0; await Program.helper.waitNTRread(addr_PageEndStartRecord); addr_PageEntry = Program.helper.lastRead; await Program.helper.waitNTRread(0x32A6A7C4, (uint)(256 * 100)); byte[] blockBytes = Program.helper.lastArray; for (int i = listlength; i > 0; i--) { Array.Copy(blockBytes, addr_PageEntry - 0x32A6A7C4, block, 0, 256); dexnumber = BitConverter.ToInt16(block, 0xC); if (Program.f1.giveawayDetails.ContainsKey(dexnumber)) { Program.f1.giveawayDetails.TryGetValue(dexnumber, out details); if (details.Item1 == "") { string szNickname = Encoding.Unicode.GetString(block, 0x14, 20).Trim('\0'); string szFileToFind = details.Item2 + szNickname + ".pk7"; if (!File.Exists(szFileToFind)) { addr_PageEntry = BitConverter.ToUInt32(block, 0); continue; } } Array.Copy(block, 0x48, principal, 0, 4); byte checksum = Program.f1.calculateChecksum(principal); byte[] fc = new byte[8]; Array.Copy(principal, 0, fc, 0, 4); fc[4] = checksum; long iFC = BitConverter.ToInt64(fc, 0); szFC = iFC.ToString().PadLeft(12, '0'); if ((!bReddit || Program.f1.commented.Contains(szFC)) && !details.Item6.Contains(BitConverter.ToInt32(principal, 0)) && !Program.f1.banlist.Contains(szFC)) { int gender = block[0xE]; int level = block[0xF]; if ((gender == 0 || gender == details.Item3) && (level == 0 || level == details.Item4)) { tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } } } addr_PageEntry = BitConverter.ToUInt32(block, 0); } //for (int i = listlength; i > 0; i--) //{ // await Program.helper.waitNTRread(addr_PageEntry + 0xC, 2); // dexnumber = BitConverter.ToInt16(Program.helper.lastArray, 0); // if (dexnumber == dexNum) // { // await Program.helper.waitNTRread(addr_PageEntry + 0xE, 1); // int gender = Program.helper.lastArray[0]; // await Program.helper.waitNTRread(addr_PageEntry + 0xF, 1); // int level = Program.helper.lastArray[0]; // if ((gender == 0 || gender == genderIndex) && (level == 0 || level == (levelIndex))) // { // tradeIndex = i - 1; // botState = (int)gtsbotstates.trade; // break; // } // } // await Program.helper.waitNTRread(addr_PageEntry); // addr_PageEntry = Program.helper.lastRead; //} if (tradeIndex == -1) { if (startIndex == 0) { Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } else { startIndex -= 100; Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(2250); botState = (int)gtsbotstates.findfromend; } } } break; case (int)gtsbotstates.findfromend: await Program.helper.waitNTRread(addr_PageSize); attempts = 0; listlength = (int)Program.helper.lastRead; if (listlength == 100 && !foundLastPage) { startIndex += 100; Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); await Program.helper.waitNTRread(addr_PageCurrentView); if (Program.helper.lastRead == 0) { foundLastPage = true; } botState = (int)gtsbotstates.findfromstart; } else { foundLastPage = true; attempts = 0; listlength = (int)Program.helper.lastRead; dexnumber = 0; await Program.helper.waitNTRread(addr_PageEndStartRecord); addr_PageEntry = Program.helper.lastRead; await Program.helper.waitNTRread(0x32A6A7C4, (uint)(256 * 100)); byte[] blockBytes = Program.helper.lastArray; for (int i = listlength; i > 0; i--) { Array.Copy(blockBytes, addr_PageEntry - 0x32A6A7C4, block, 0, 256); dexnumber = BitConverter.ToInt16(block, 0xC); if (Program.f1.giveawayDetails.ContainsKey(dexnumber)) { Program.f1.giveawayDetails.TryGetValue(dexnumber, out details); if (details.Item1 == "") { string szNickname = Encoding.Unicode.GetString(block, 0x14, 20).Trim('\0'); string szFileToFind = details.Item2 + szNickname + ".pk7"; if (!File.Exists(szFileToFind)) { addr_PageEntry = BitConverter.ToUInt32(block, 0); continue; } } Array.Copy(block, 0x48, principal, 0, 4); byte checksum = Program.f1.calculateChecksum(principal); byte[] fc = new byte[8]; Array.Copy(principal, 0, fc, 0, 4); fc[4] = checksum; long iFC = BitConverter.ToInt64(fc, 0); szFC = iFC.ToString().PadLeft(12, '0'); if ((!bReddit || Program.f1.commented.Contains(szFC)) && !details.Item6.Contains(BitConverter.ToInt32(principal, 0)) && !Program.f1.banlist.Contains(szFC)) { int gender = block[0xE]; int level = block[0xF]; if ((gender == 0 || gender == details.Item3) && (level == 0 || level == details.Item4)) { tradeIndex = i - 1; botState = (int)gtsbotstates.trade; break; } } } addr_PageEntry = BitConverter.ToUInt32(block, 0); } //for (int i = listlength; i > 0; i--) //{ // await Program.helper.waitNTRread(addr_PageEntry + 0xC, 2); // dexnumber = BitConverter.ToInt16(Program.helper.lastArray, 0); // if (dexnumber == dexNum) // { // await Program.helper.waitNTRread(addr_PageEntry + 0xE, 1); // int gender = Program.helper.lastArray[0]; // await Program.helper.waitNTRread(addr_PageEntry + 0xF, 1); // int level = Program.helper.lastArray[0]; // if ((gender == 0 || gender == genderIndex) && (level == 0 || level == (levelIndex))) // { // tradeIndex = i - 1; // botState = (int)gtsbotstates.trade; // break; // } // } // await Program.helper.waitNTRread(addr_PageEntry); // addr_PageEntry = Program.helper.lastRead; //} if (tradeIndex == -1) { if (listlength < 100 && startIndex >= 200) { for (int i = 0; i < listlength; i++) { Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); } await Task.Delay(2250); } else if (startIndex >= 200) { waitTaskbool = Program.helper.waitNTRwrite(addr_PageStartingIndex, (uint)(startIndex - 200), iPID); if (await waitTaskbool) { await Program.helper.waitNTRwrite(addr_PageSize, 0x64, iPID); startIndex -= 100; Program.helper.quickbuton(Program.PKTable.DpadLEFT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.DpadRIGHT, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(3000); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); Program.helper.quicktouch(10, 10, commandtime); await Task.Delay(commandtime + delaytime + 250); botState = (int)gtsbotstates.findfromstart; } } else if (startIndex == 0) { Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } else if (startIndex < 200) { botState = (int)gtsbotstates.quicksearch; } } } break; case (int)gtsbotstates.trade: waitTaskbool = Program.helper.waitNTRwrite(addr_PageCurrentView, BitConverter.GetBytes(tradeIndex), iPID); if (await waitTaskbool) { string szNickname = Encoding.Unicode.GetString(block, 0x14, 20).Trim('\0'); string szPath = details.Item1; string szFileToFind = details.Item2 + szNickname + ".pk7"; if (File.Exists(szFileToFind)) { szPath = szFileToFind; } byte[] pkmEncrypted = System.IO.File.ReadAllBytes(szPath); byte[] cloneshort = PKHeX.encryptArray(pkmEncrypted.Take(232).ToArray()); string ek7 = BitConverter.ToString(cloneshort).Replace("-", ", 0x"); //optional: grab some trainer data string szTrainerName = Encoding.Unicode.GetString(block, 0x4C, 20).Trim('\0'); int countryIndex = BitConverter.ToInt16(block, 0x68); string country = "-"; Program.f1.countries.TryGetValue(countryIndex, out country); Program.f1.getSubRegions(countryIndex); int subRegionIndex = BitConverter.ToInt16(block, 0x6A); string subregion = "-"; Program.f1.regions.TryGetValue(subRegionIndex, out subregion); if (bBlacklist) { details.Item6.Add(BitConverter.ToInt32(principal, 0)); } Program.f1.AppendListViewItem(szTrainerName, szNickname, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC); //Inject the Pokemon to box1slot1 Program.scriptHelper.write(0x330d9838, cloneshort, iPID); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime + 2500); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); if (details.Item5 > 0) { Program.f1.giveawayDetails[dexnumber] = new Tuple <string, string, int, int, int, ArrayList>(details.Item1, details.Item2, details.Item3, details.Item4, details.Item5 - 1, details.Item6); foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dexnumber.ToString()) { int count = int.Parse(row[5].ToString()) - 1; row[5] = count; break; } } } foreach (System.Data.DataRow row in Program.gd.details.Rows) { if (row[0].ToString() == dexnumber.ToString()) { int amount = int.Parse(row[6].ToString()) + 1; row[6] = amount; break; } } await Task.Delay(10250); Program.helper.quickbuton(Program.PKTable.keyA, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(1000); Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime); await Task.Delay(32000); bool cont = false; foreach (KeyValuePair <int, Tuple <string, string, int, int, int, ArrayList> > pair in Program.f1.giveawayDetails) { if (pair.Value.Item5 != 0) { cont = true; break; } } if (!cont) { botresult = 1; botState = (int)gtsbotstates.botexit; break; } startIndex = 0; tradeIndex = -1; listlength = 0; addr_PageEntry = 0; foundLastPage = false; if (bReddit) { botState = (int)gtsbotstates.updatecomments; } else { botState = (int)gtsbotstates.research; } } break; case (int)gtsbotstates.quicksearch: Program.helper.quickbuton(Program.PKTable.keyB, commandtime); await Task.Delay(commandtime + delaytime + 500); await Program.helper.waittouch(160, 185); await Task.Delay(2250); botState = (int)gtsbotstates.findfromstart; break; case (int)gtsbotstates.research: Program.helper.quicktouch(128, 64, commandtime); await Task.Delay(commandtime + delaytime + 1000); await Program.helper.waittouch(160, 185); await Task.Delay(2250); botState = (int)gtsbotstates.findfromstart; break; case (int)gtsbotstates.botexit: botstop = true; break; default: botresult = -1; botstop = true; break; } } return(botresult); }
public void DoWork() { bool bPokemonFound = false; ScriptHelper h = Program.scriptHelper; while (!_shouldStop) { Thread.Sleep(2000); bool bSent = false; if (!bPokemonFound) { h.press(h.Abtn); Thread.Sleep(1000); h.press(h.Abtn); Thread.Sleep(1000); h.press(h.up); Thread.Sleep(1000); //What Pokemon? h.press(h.Abtn); //black screen Thread.Sleep(3000); //"type" the name of the pokemon we want to find byte[] name = new byte[this.szPokemonToFind.Length * 2]; for (int i = 0; i < szPokemonToFind.Length; i++) { name[i * 2] = (byte)szPokemonToFind[i]; name[i * 2 + 1] = 0x00; } //I like this solution so much Program.scriptHelper.write(0x301118D4, name, iPID); Thread.Sleep(1000); h.press(h.start); Thread.Sleep(1000); h.press(h.Abtn); //black screen Thread.Sleep(4000); bPokemonFound = true; } else { h.press(h.Abtn); Thread.Sleep(2000); } h.touch(h.searchBtn); //finding pokemon Thread.Sleep(4000); for (int i = 0; i < 25; i++) { string szReqPokemon = h.readSafe(addr_RequestedPokemon, 20, iPID); if (szReqPokemon == this.szPokemonToGive) { string szLevel = h.readSafe(addr_RequestedLevel, 12, iPID); szLevel = szLevel.ToLower(); if (szLevel.Contains(this.szLevel) || (!this.bSpanish && szLevel.Contains("any")) || (this.bSpanish && szLevel.Contains("cual"))) { string szNickname = h.readSafe(addr_DepositedPokemonNickname, 20, iPID); string szPath = this.szDefaultPk7; string szFileToFind = this.szPk7Folder + szNickname + ".pk7"; if (File.Exists(szFileToFind)) { szPath = szFileToFind; } byte[] pkmEncrypted = System.IO.File.ReadAllBytes(szPath); byte[] cloneshort = PKHeX.encryptArray(pkmEncrypted.Take(232).ToArray()); string ek7 = BitConverter.ToString(cloneshort).Replace("-", ", 0x"); //optional: grab some trainer data string szTrainerName = h.readSafe(addr_TrainerName, 20, iPID); string szCountry = h.readSafe(addr_TrainerCountry, 20, iPID); string szSubCountry = h.readSafe(addr_TrainerSubCountry, 20, iPID); Program.f1.AppendListViewItem(szTrainerName, szNickname, szCountry, szSubCountry); //Inject the Pokemon to box1slot1 Program.scriptHelper.write(0x330d9838, cloneshort, iPID); Thread.Sleep(1000); h.press(h.Abtn); Thread.Sleep(3000); h.press(h.Abtn); Thread.Sleep(1000); h.press(h.Abtn); Thread.Sleep(1000); h.press(h.Abtn); //trade starts here Thread.Sleep(10000); //if the pokemon has been traded we have 35 seconds to get back to the starting spot for the bot by spamming b a bit h.press(h.Abtn); Thread.Sleep(1000); h.press(h.Bbtn); Thread.Sleep(1000); h.press(h.Bbtn); Thread.Sleep(1000); h.press(h.Bbtn); Thread.Sleep(1000); h.press(h.Bbtn); Thread.Sleep(1000); h.press(h.Bbtn); //if the trade is still going on wait for it to finish Thread.Sleep(30000); bSent = true; break; } } h.press(h.right); Thread.Sleep(500); } if (!bSent) { //no tradable pokemon in the last X pokemon, start from the front of the list again h.press(h.Bbtn); Thread.Sleep(1000); h.press(h.Bbtn); Thread.Sleep(1000); } } }
private void handlePokeRead(object args_obj) { DataReadyWaiting args = (DataReadyWaiting)args_obj; validator.Data = PKHeX.decryptArray(args.data); }