Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.74 KB | None | 0 0
  1. //71c7b12
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Globalization;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using System.Xml;
  18. using AllEnum;
  19. using PokemonGo.RocketAPI.Enums;
  20. using PokemonGo.RocketAPI.Exceptions;
  21. using PokemonGo.RocketAPI.Extensions;
  22. using PokemonGo.RocketAPI.GeneratedCode;
  23. using System.Configuration;
  24. using GMap.NET;
  25. using GMap.NET.MapProviders;
  26. using GMap.NET.WindowsForms;
  27. using GMap.NET.WindowsForms.Markers;
  28. using GMap.NET.WindowsForms.ToolTips;
  29. using System.Threading;
  30. using BrightIdeasSoftware;
  31. using PokemonGo.RocketAPI.Helpers;
  32.  
  33. namespace PokemonGo.RocketAPI.Window
  34. {
  35. public partial class MainForm : Form
  36. {
  37. public static MainForm Instance;
  38. public static SynchronizationContext synchronizationContext;
  39.  
  40. GMapOverlay searchAreaOverlay = new GMapOverlay("areas");
  41. GMapOverlay pokestopsOverlay = new GMapOverlay("pokestops");
  42. GMapOverlay pokemonsOverlay = new GMapOverlay("pokemons");
  43. GMapOverlay playerOverlay = new GMapOverlay("players");
  44.  
  45. GMarkerGoogle playerMarker;
  46.  
  47. IEnumerable<FortData> pokeStops;
  48. IEnumerable<WildPokemon> wildPokemons;
  49.  
  50. public MainForm()
  51. {
  52. synchronizationContext = SynchronizationContext.Current;
  53. InitializeComponent();
  54. ClientSettings = Settings.Instance;
  55. Instance = this;
  56. }
  57.  
  58. private void MainForm_Load(object sender, EventArgs e)
  59. {
  60. gMapControl1.MapProvider = GoogleMapProvider.Instance;
  61. gMapControl1.Manager.Mode = AccessMode.ServerOnly;
  62. GMapProvider.WebProxy = null;
  63. gMapControl1.Position = new PointLatLng(ClientSettings.DefaultLatitude, ClientSettings.DefaultLongitude);
  64. gMapControl1.DragButton = MouseButtons.Left;
  65.  
  66. gMapControl1.MinZoom = 1;
  67. gMapControl1.MaxZoom = 20;
  68. gMapControl1.Zoom = 15;
  69.  
  70. gMapControl1.Overlays.Add(searchAreaOverlay);
  71. gMapControl1.Overlays.Add(pokestopsOverlay);
  72. gMapControl1.Overlays.Add(pokemonsOverlay);
  73. gMapControl1.Overlays.Add(playerOverlay);
  74.  
  75. playerMarker = new GMarkerGoogle(new PointLatLng(ClientSettings.DefaultLatitude, ClientSettings.DefaultLongitude),
  76. GMarkerGoogleType.orange_small);
  77. playerOverlay.Markers.Add(playerMarker);
  78.  
  79. InitializeMap();
  80. }
  81.  
  82. public void Restart()
  83. {
  84. InitializeMap();
  85. }
  86.  
  87. private void InitializeMap()
  88. {
  89. playerMarker.Position = new PointLatLng(ClientSettings.DefaultLatitude, ClientSettings.DefaultLongitude);
  90.  
  91. searchAreaOverlay.Polygons.Clear();
  92. S2GMapDrawer.DrawS2Cells(S2Helper.GetNearbyCellIds(ClientSettings.DefaultLongitude, ClientSettings.DefaultLatitude), searchAreaOverlay);
  93. }
  94.  
  95. public static ISettings ClientSettings;
  96. private static int Currentlevel = -1;
  97. private static int TotalExperience = 0;
  98. private static int TotalPokemon = 0;
  99. private static bool Stopping = false;
  100. private static bool ForceUnbanning = false;
  101. private static bool FarmingStops = false;
  102. private static bool FarmingPokemons = false;
  103. private static DateTime TimeStarted = DateTime.Now;
  104. public static DateTime InitSessionDateTime = DateTime.Now;
  105.  
  106. Client client;
  107. LocationManager locationManager;
  108.  
  109. public static double GetRuntime()
  110. {
  111. return ((DateTime.Now - TimeStarted).TotalSeconds) / 3600;
  112. }
  113.  
  114. public void CheckVersion()
  115. {
  116. try
  117. {
  118. var match =
  119. new Regex(
  120. @"\[assembly\: AssemblyVersion\(""(\d{1,})\.(\d{1,})\.(\d{1,})\.(\d{1,})""\)\]")
  121. .Match(DownloadServerVersion());
  122.  
  123. if (!match.Success) return;
  124. var gitVersion =
  125. new Version(
  126. string.Format(
  127. "{0}.{1}.{2}.{3}",
  128. match.Groups[1],
  129. match.Groups[2],
  130. match.Groups[3],
  131. match.Groups[4]));
  132. // makes sense to display your version and say what the current one is on github
  133. if (Assembly.GetExecutingAssembly().GetName().Version != gitVersion)
  134. {
  135. ColoredConsoleWrite(Color.Red, "Created By Remex!");
  136. ColoredConsoleWrite(Color.Red, "Boosting accounts.");
  137. }
  138. }
  139. catch (Exception)
  140. {
  141. ColoredConsoleWrite(Color.Red, "Unable to check for updates now...");
  142. }
  143. }
  144.  
  145. private static string DownloadServerVersion()
  146. {
  147. using (var wC = new WebClient())
  148. return
  149. wC.DownloadString(
  150. "https://raw.githubusercontent.com/WooAf/PoGoBoT/master/PokemonGo/RocketAPI/Window/Properties/AssemblyInfo.cs");
  151. }
  152.  
  153. public static void ColoredConsoleWrite(Color color, string text)
  154. {
  155. if (MainForm.Instance.InvokeRequired)
  156. {
  157. MainForm.Instance.Invoke(new Action<Color, string>(ColoredConsoleWrite), color, text);
  158. return;
  159. }
  160.  
  161. MainForm.Instance.logTextBox.Select(MainForm.Instance.logTextBox.Text.Length, 1); // Reset cursor to last
  162.  
  163. string textToAppend = "[" + DateTime.Now.ToString("HH:mm:ss tt") + "] " + text + "\r\n";
  164. MainForm.Instance.logTextBox.SelectionColor = color;
  165. MainForm.Instance.logTextBox.AppendText(textToAppend);
  166.  
  167. object syncRoot = new object();
  168. lock (syncRoot) // Added locking to prevent text file trying to be accessed by two things at the same time
  169. {
  170. var dir = AppDomain.CurrentDomain.BaseDirectory + @"\Logs";
  171. if (!Directory.Exists(dir))
  172. Directory.CreateDirectory(dir);
  173. File.AppendAllText(dir + @"\" + DateTime.Today.ToString("yyyyMMdd") + ".txt", "[" + DateTime.Now.ToString("HH:mm:ss tt") + "] " + text + "\r\n");
  174. }
  175. }
  176.  
  177. public void ConsoleClear()
  178. {
  179. if (InvokeRequired)
  180. {
  181. Invoke(new Action(ConsoleClear));
  182. return;
  183. }
  184.  
  185. logTextBox.Clear();
  186. }
  187.  
  188. public void SetStatusText(string text)
  189. {
  190. if (InvokeRequired)
  191. {
  192. Invoke(new Action<string>(SetStatusText), text);
  193. return;
  194. }
  195.  
  196. statusLabel.Text = text;
  197. }
  198.  
  199. private async Task EvolvePokemons(Client client)
  200. {
  201. var inventory = await client.GetInventory();
  202. var pokemons =
  203. inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.Pokemon)
  204. .Where(p => p != null && p?.PokemonId > 0);
  205.  
  206. await EvolveAllGivenPokemons(client, pokemons);
  207. }
  208.  
  209. private async Task EvolveAllGivenPokemons(Client client, IEnumerable<PokemonData> pokemonToEvolve)
  210. {
  211. foreach (var pokemon in pokemonToEvolve)
  212. {
  213. /*
  214. enum Holoholo.Rpc.Types.EvolvePokemonOutProto.Result {
  215. UNSET = 0;
  216. SUCCESS = 1;
  217. FAILED_POKEMON_MISSING = 2;
  218. FAILED_INSUFFICIENT_RESOURCES = 3;
  219. FAILED_POKEMON_CANNOT_EVOLVE = 4;
  220. FAILED_POKEMON_IS_DEPLOYED = 5;
  221. }
  222. }*/
  223.  
  224. var countOfEvolvedUnits = 0;
  225. var xpCount = 0;
  226.  
  227. EvolvePokemonOut evolvePokemonOutProto;
  228. do
  229. {
  230. evolvePokemonOutProto = await client.EvolvePokemon(pokemon.Id);
  231. //todo: someone check whether this still works
  232.  
  233. if (evolvePokemonOutProto.Result == 1)
  234. {
  235. ColoredConsoleWrite(Color.Cyan,
  236. $"Evolved {pokemon.PokemonId} successfully for {evolvePokemonOutProto.ExpAwarded}xp");
  237.  
  238. countOfEvolvedUnits++;
  239. xpCount += evolvePokemonOutProto.ExpAwarded;
  240. }
  241. else
  242. {
  243. var result = evolvePokemonOutProto.Result;
  244. /*
  245. ColoredConsoleWrite(ConsoleColor.White, $"Failed to evolve {pokemon.PokemonId}. " +
  246. $"EvolvePokemonOutProto.Result was {result}");
  247.  
  248. ColoredConsoleWrite(ConsoleColor.White, $"Due to above error, stopping evolving {pokemon.PokemonId}");
  249. */
  250. }
  251. } while (evolvePokemonOutProto.Result == 1);
  252. if (countOfEvolvedUnits > 0)
  253. ColoredConsoleWrite(Color.Cyan,
  254. $"Evolved {countOfEvolvedUnits} pieces of {pokemon.PokemonId} for {xpCount}xp");
  255.  
  256. await Task.Delay(3000);
  257. }
  258. }
  259.  
  260. private async void Execute()
  261. {
  262. if (dGrid.InvokeRequired)
  263. {
  264. dGrid.BeginInvoke(new MethodInvoker(delegate {
  265. dGrid.ColumnCount = 4;
  266. dGrid.Columns[0].Name = "Action";
  267. dGrid.Columns[1].Name = "Pokemon";
  268. dGrid.Columns[2].Name = "CP";
  269. dGrid.Columns[3].Name = "IV";
  270. }));
  271. }
  272. else
  273. {
  274. dGrid.ColumnCount = 4;
  275. dGrid.Columns[0].Name = "Action";
  276. dGrid.Columns[1].Name = "Pokemon";
  277. dGrid.Columns[2].Name = "CP";
  278. dGrid.Columns[3].Name = "IV";
  279. }
  280.  
  281. client = new Client(ClientSettings);
  282. this.locationManager = new LocationManager(client, ClientSettings.TravelSpeed);
  283. try
  284. {
  285. switch (ClientSettings.AuthType)
  286. {
  287. case AuthType.Ptc:
  288. ColoredConsoleWrite(Color.Green, "Login Type: Pokemon Trainers Club");
  289. break;
  290. case AuthType.Google:
  291. ColoredConsoleWrite(Color.Green, "Login Type: Google");
  292. break;
  293. }
  294.  
  295.  
  296. await client.Login();
  297. await client.SetServer();
  298. var profile = await client.GetProfile();
  299. var settings = await client.GetSettings();
  300. var mapObjects = await client.GetMapObjects();
  301. var inventory = await client.GetInventory();
  302. var pokemons =
  303. inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.Pokemon)
  304. .Where(p => p != null && p?.PokemonId > 0);
  305.  
  306. updateUserStatusBar(client);
  307.  
  308. // Write the players ingame details
  309. ColoredConsoleWrite(Color.Yellow, "----------------------------");
  310. /*// dont actually want to display info but keeping here incase people want to \O_O/
  311. * if (ClientSettings.AuthType == AuthType.Ptc)
  312. {
  313. ColoredConsoleWrite(Color.Cyan, "Account: " + ClientSettings.PtcUsername);
  314. ColoredConsoleWrite(Color.Cyan, "Password: " + ClientSettings.PtcPassword + "\n");
  315. }
  316. else
  317. {
  318. ColoredConsoleWrite(Color.Cyan, "Email: " + ClientSettings.Email);
  319. ColoredConsoleWrite(Color.Cyan, "Password: " + ClientSettings.Password + "\n");
  320. }*/
  321. string lat2 = System.Convert.ToString(ClientSettings.DefaultLatitude);
  322. string longit2 = System.Convert.ToString(ClientSettings.DefaultLongitude);
  323. ColoredConsoleWrite(Color.DarkGray, "Name: " + profile.Profile.Username);
  324. ColoredConsoleWrite(Color.DarkGray, "Team: " + profile.Profile.Team);
  325. if (profile.Profile.Currency.ToArray()[0].Amount > 0) // If player has any pokecoins it will show how many they have.
  326. ColoredConsoleWrite(Color.DarkGray, "Pokecoins: " + profile.Profile.Currency.ToArray()[0].Amount);
  327. ColoredConsoleWrite(Color.DarkGray, "Stardust: " + profile.Profile.Currency.ToArray()[1].Amount + "\n");
  328. ColoredConsoleWrite(Color.DarkGray, "Latitude: " + ClientSettings.DefaultLatitude);
  329. ColoredConsoleWrite(Color.DarkGray, "Longitude: " + ClientSettings.DefaultLongitude);
  330. try
  331. {
  332. ColoredConsoleWrite(Color.DarkGray, "Country: " + CallAPI("country", lat2.Replace(',', '.'), longit2.Replace(',', '.')));
  333. ColoredConsoleWrite(Color.DarkGray, "Area: " + CallAPI("place", lat2.Replace(',', '.'), longit2.Replace(',', '.')));
  334. }
  335. catch (Exception)
  336. {
  337. ColoredConsoleWrite(Color.DarkGray, "Unable to get Country/Place");
  338. }
  339.  
  340.  
  341. ColoredConsoleWrite(Color.Yellow, "----------------------------");
  342.  
  343. // I believe a switch is more efficient and easier to read.
  344. switch (ClientSettings.TransferType)
  345. {
  346. case "Leave Strongest":
  347. await TransferAllButStrongestUnwantedPokemon(client);
  348. break;
  349. case "All":
  350. await TransferAllGivenPokemons(client, pokemons);
  351. break;
  352. case "Duplicate":
  353. await TransferDuplicatePokemon(client);
  354. break;
  355. case "IV Duplicate":
  356. await TransferDuplicateIVPokemon(client);
  357. break;
  358. case "CP":
  359. await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
  360. break;
  361. case "IV":
  362. await TransferAllGivenPokemons(client, pokemons, ClientSettings.TransferIVThreshold);
  363. break;
  364. default:
  365. ColoredConsoleWrite(Color.DarkGray, "Transfering pokemon disabled");
  366. break;
  367. }
  368.  
  369.  
  370. if (ClientSettings.EvolveAllGivenPokemons)
  371. await EvolveAllGivenPokemons(client, pokemons);
  372. if (ClientSettings.Recycler)
  373. client.RecycleItems(client);
  374.  
  375. await Task.Delay(5000);
  376. PrintLevel(client);
  377. await ExecuteFarmingPokestopsAndPokemons(client);
  378.  
  379. while (ForceUnbanning)
  380. await Task.Delay(25);
  381.  
  382. // await ForceUnban(client);
  383. if (!Stopping)
  384. {
  385. ColoredConsoleWrite(Color.Red, $"No nearby useful locations found. Please wait 10 seconds.");
  386. await Task.Delay(10000);
  387. Execute();
  388. }
  389. else
  390. {
  391. ConsoleClear();
  392. pokestopsOverlay.Routes.Clear();
  393. pokestopsOverlay.Markers.Clear();
  394. ColoredConsoleWrite(Color.Red, $"Bot successfully stopped.");
  395.  
  396. if (btnStartFarming.InvokeRequired)
  397. {
  398. btnStartFarming.BeginInvoke(new MethodInvoker(delegate
  399. {
  400. btnStartFarming.Text = "Start Farming";
  401. btnPokemon.Enabled = false;
  402. }));
  403. }
  404. else
  405. {
  406. btnStartFarming.Text = "Start Farming";
  407. btnPokemon.Enabled = false;
  408. }
  409.  
  410. Stopping = false;
  411. bot_started = false;
  412. }
  413. }
  414. catch (TaskCanceledException) { ColoredConsoleWrite(Color.Red, "Task Canceled Exception - Restarting"); if (!Stopping) Execute(); }
  415. catch (UriFormatException) { ColoredConsoleWrite(Color.Red, "System URI Format Exception - Restarting"); if (!Stopping) Execute(); }
  416. catch (ArgumentOutOfRangeException) { ColoredConsoleWrite(Color.Red, "ArgumentOutOfRangeException - Restarting"); if (!Stopping) Execute(); }
  417. catch (ArgumentNullException) { ColoredConsoleWrite(Color.Red, "Argument Null Refference - Restarting"); if (!Stopping) Execute(); }
  418. catch (NullReferenceException ex) { ColoredConsoleWrite(Color.Red, ex.ToString()); if (!Stopping) Execute(); }
  419. catch (Exception ex) { ColoredConsoleWrite(Color.Red, ex.ToString()); if (!Stopping) Execute(); }
  420. finally { client = null; }
  421.  
  422. }
  423.  
  424. private static string CallAPI(string elem, string lat, string lon)
  425. {
  426.  
  427. using (XmlReader reader = XmlReader.Create(@"http://api.geonames.org/findNearby?lat=" + lat + "&lng=" + lon + "&username=pokemongobot"))
  428. {
  429. while (reader.Read())
  430. {
  431. if (reader.IsStartElement())
  432. {
  433. switch (elem)
  434. {
  435. case "country":
  436. if (reader.Name == "countryName")
  437. {
  438. return reader.ReadString();
  439. }
  440. break;
  441.  
  442. case "place":
  443. if (reader.Name == "name")
  444. {
  445. return reader.ReadString();
  446. }
  447. break;
  448. default:
  449. return "N/A";
  450. }
  451. }
  452. }
  453. }
  454. return "Error";
  455. }
  456.  
  457. private async Task ExecuteCatchAllNearbyPokemons(Client client)
  458. {
  459. var mapObjects = await client.GetMapObjects();
  460.  
  461. var pokemons = mapObjects.MapCells.SelectMany(i => i.CatchablePokemons);
  462. var inventory2 = await client.GetInventory();
  463. var pokemons2 = inventory2.InventoryDelta.InventoryItems
  464. .Select(i => i.InventoryItemData?.Pokemon)
  465. .Where(p => p != null && p?.PokemonId > 0)
  466. .ToArray();
  467.  
  468. foreach (var pokemon in pokemons)
  469. {
  470. if (ForceUnbanning || Stopping)
  471. break;
  472.  
  473. FarmingPokemons = true;
  474.  
  475. await locationManager.update(pokemon.Latitude, pokemon.Longitude);
  476.  
  477. string pokemonName;
  478. if (ClientSettings.Language == "german")
  479. {
  480. string name_english = Convert.ToString(pokemon.PokemonId);
  481. var request = (HttpWebRequest)WebRequest.Create("http://boosting-service.de/pokemon/index.php?pokeName=" + name_english);
  482. var response = (HttpWebResponse)request.GetResponse();
  483. pokemonName = new StreamReader(response.GetResponseStream()).ReadToEnd();
  484. }
  485. else
  486. pokemonName = Convert.ToString(pokemon.PokemonId);
  487.  
  488. await client.UpdatePlayerLocation(pokemon.Latitude, pokemon.Longitude);
  489. UpdatePlayerLocation(pokemon.Latitude, pokemon.Longitude);
  490. UpdateMap();
  491. var encounterPokemonResponse = await client.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnpointId);
  492. var pokemonCP = encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp;
  493. var pokemonIV = Math.Round(Perfect(encounterPokemonResponse?.WildPokemon?.PokemonData));
  494. CatchPokemonResponse caughtPokemonResponse;
  495. ColoredConsoleWrite(Color.Green, $"Encounter a {pokemonName} with {pokemonCP} CP and {pokemonIV}% IV");
  496. do
  497. {
  498. if (ClientSettings.RazzBerryMode == "cp")
  499. if (pokemonCP > ClientSettings.RazzBerrySetting)
  500. await client.UseRazzBerry(client, pokemon.EncounterId, pokemon.SpawnpointId);
  501. if (ClientSettings.RazzBerryMode == "probability")
  502. if (encounterPokemonResponse.CaptureProbability.CaptureProbability_.First() < ClientSettings.RazzBerrySetting)
  503. await client.UseRazzBerry(client, pokemon.EncounterId, pokemon.SpawnpointId);
  504. caughtPokemonResponse = await client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, MiscEnums.Item.ITEM_POKE_BALL, pokemonCP); ; //note: reverted from settings because this should not be part of settings but part of logic
  505. } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
  506.  
  507. if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
  508. {
  509. Color c = Color.LimeGreen;
  510. if (pokemonIV >= 80)
  511. {
  512. c = Color.Yellow;
  513. }
  514.  
  515. if (dGrid.InvokeRequired)
  516. {
  517. dGrid.BeginInvoke(new MethodInvoker(delegate
  518. {
  519. dGrid.Rows.Insert(0, "Captured", pokemonName, pokemonCP, pokemonIV);
  520. }));
  521. }
  522. else
  523. {
  524. dGrid.Rows.Insert(0, "Captured", pokemonName, pokemonCP, pokemonIV);
  525. }
  526.  
  527. ColoredConsoleWrite(c, $"We caught a {pokemonName} with {pokemonCP} CP and {pokemonIV}% IV");
  528. foreach (int xp in caughtPokemonResponse.Scores.Xp)
  529. TotalExperience += xp;
  530. TotalPokemon += 1;
  531. }
  532. else
  533. {
  534. if (dGrid.InvokeRequired)
  535. {
  536. dGrid.BeginInvoke(new MethodInvoker(delegate
  537. {
  538. dGrid.Rows.Insert(0, "Flew Away", pokemonName, pokemonCP, pokemonIV);
  539. }));
  540. }
  541. else
  542. {
  543. dGrid.Rows.Insert(0, "Flew Away", pokemonName, pokemonCP, pokemonIV);
  544. }
  545.  
  546. ColoredConsoleWrite(Color.Red, $"{pokemonName} with {pokemonCP} CP and {pokemonIV}% IV got away..");
  547. }
  548.  
  549.  
  550. // I believe a switch is more efficient and easier to read.
  551. switch (ClientSettings.TransferType)
  552. {
  553. case "Leave Strongest":
  554. await TransferAllButStrongestUnwantedPokemon(client);
  555. break;
  556. case "All":
  557. await TransferAllGivenPokemons(client, pokemons2);
  558. break;
  559. case "Duplicate":
  560. await TransferDuplicatePokemon(client);
  561. break;
  562. case "IV Duplicate":
  563. await TransferDuplicateIVPokemon(client);
  564. break;
  565. case "CP":
  566. await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
  567. break;
  568. case "IV":
  569. await TransferAllGivenPokemons(client, pokemons2, ClientSettings.TransferIVThreshold);
  570. break;
  571. default:
  572. ColoredConsoleWrite(Color.DarkGray, "Transfering pokemon disabled");
  573. break;
  574. }
  575.  
  576. FarmingPokemons = false;
  577. await Task.Delay(3000);
  578. }
  579. pokemons = null;
  580. }
  581.  
  582. private void UpdatePlayerLocation(double latitude, double longitude)
  583. {
  584. synchronizationContext.Post(new SendOrPostCallback(o =>
  585. {
  586. playerMarker.Position = (PointLatLng)o;
  587.  
  588. searchAreaOverlay.Polygons.Clear();
  589.  
  590. }), new PointLatLng(latitude, longitude));
  591.  
  592. ColoredConsoleWrite(Color.Gray, $"Moving player location to Lat: {latitude}, Lng: {longitude}");
  593. }
  594.  
  595. private void UpdateMap()
  596. {
  597. synchronizationContext.Post(new SendOrPostCallback(o =>
  598. {
  599. pokestopsOverlay.Markers.Clear();
  600. List<PointLatLng> routePoint = new List<PointLatLng>();
  601.  
  602. /*foreach (var pokeStop in pokeStops)
  603. {
  604. GMarkerGoogleType type = GMarkerGoogleType.blue_small;
  605. if (pokeStop.CooldownCompleteTimestampMs > DateTime.UtcNow.ToUnixTime())
  606. {
  607. type = GMarkerGoogleType.gray_small;
  608. }
  609. var pokeStopLoc = new PointLatLng(pokeStop.Latitude, pokeStop.Longitude);
  610. var pokestopMarker = new GMarkerGoogle(pokeStopLoc, type);
  611. //pokestopMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
  612. //pokestopMarker.ToolTip = new GMapBaloonToolTip(pokestopMarker);
  613. pokestopsOverlay.Markers.Add(pokestopMarker);
  614.  
  615. routePoint.Add(pokeStopLoc);
  616. }
  617. */
  618. pokestopsOverlay.Routes.Clear();
  619. pokestopsOverlay.Routes.Add(new GMapRoute(routePoint, "Walking Path"));
  620.  
  621.  
  622. pokemonsOverlay.Markers.Clear();
  623. if (wildPokemons != null)
  624. {
  625. foreach (var pokemon in wildPokemons)
  626. {
  627. var pokemonMarker = new GMarkerGoogle(new PointLatLng(pokemon.Latitude, pokemon.Longitude),
  628. GMarkerGoogleType.red_small);
  629. pokemonsOverlay.Markers.Add(pokemonMarker);
  630. }
  631. }
  632.  
  633. S2GMapDrawer.DrawS2Cells(S2Helper.GetNearbyCellIds(ClientSettings.DefaultLongitude, ClientSettings.DefaultLatitude), searchAreaOverlay);
  634. }), null);
  635. }
  636.  
  637. private async Task ExecuteFarmingPokestopsAndPokemons(Client client)
  638. {
  639. var mapObjects = await client.GetMapObjects();
  640.  
  641. FortData[] rawPokeStops = mapObjects.MapCells.SelectMany(i => i.Forts).Where(i => i.Type == FortType.Checkpoint && i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).ToArray();
  642. if (rawPokeStops == null || rawPokeStops.Count() <= 0)
  643. {
  644. ColoredConsoleWrite(Color.Red, $"No PokeStops to visit here, please stop the bot and change your location.");
  645. return;
  646. }
  647. pokeStops = rawPokeStops;
  648. UpdateMap();
  649. ColoredConsoleWrite(Color.Cyan, $"Finding fastest route through all PokeStops..");
  650. LatLong startingLatLong = new LatLong(ClientSettings.DefaultLatitude, ClientSettings.DefaultLongitude);
  651. pokeStops = RouteOptimizer.Optimize(rawPokeStops, startingLatLong, pokestopsOverlay);
  652. wildPokemons = mapObjects.MapCells.SelectMany(i => i.WildPokemons);
  653. if (!ForceUnbanning && !Stopping)
  654. ColoredConsoleWrite(Color.Cyan, $"Visiting {pokeStops.Count()} PokeStops");
  655.  
  656. UpdateMap();
  657. foreach (var pokeStop in pokeStops)
  658. {
  659. if (ForceUnbanning || Stopping)
  660. break;
  661.  
  662. FarmingStops = true;
  663. await locationManager.update(pokeStop.Latitude, pokeStop.Longitude);
  664. UpdatePlayerLocation(pokeStop.Latitude, pokeStop.Longitude);
  665. UpdateMap();
  666.  
  667. var fortInfo = await client.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
  668. var fortSearch = await client.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
  669. StringWriter PokeStopOutput = new StringWriter();
  670. PokeStopOutput.Write($"");
  671. if (fortInfo.Name != string.Empty)
  672. PokeStopOutput.Write("PokeStop: " + fortInfo.Name);
  673. if (fortSearch.ExperienceAwarded != 0)
  674. PokeStopOutput.Write($", XP: {fortSearch.ExperienceAwarded}");
  675. if (fortSearch.GemsAwarded != 0)
  676. PokeStopOutput.Write($", Gems: {fortSearch.GemsAwarded}");
  677. if (fortSearch.PokemonDataEgg != null)
  678. PokeStopOutput.Write($", Eggs: {fortSearch.PokemonDataEgg}");
  679. if (GetFriendlyItemsString(fortSearch.ItemsAwarded) != string.Empty)
  680. PokeStopOutput.Write($", Items: {GetFriendlyItemsString(fortSearch.ItemsAwarded)} ");
  681. ColoredConsoleWrite(Color.Cyan, PokeStopOutput.ToString());
  682.  
  683. if (fortSearch.ExperienceAwarded != 0)
  684. TotalExperience += (fortSearch.ExperienceAwarded);
  685.  
  686. pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + 300000;
  687.  
  688. if (ClientSettings.CatchPokemon)
  689. await ExecuteCatchAllNearbyPokemons(client);
  690. }
  691. FarmingStops = false;
  692. if (!ForceUnbanning && !Stopping)
  693. {
  694. client.RecycleItems(client);
  695. await ExecuteFarmingPokestopsAndPokemons(client);
  696. }
  697.  
  698. updateUserStatusBar(client);
  699. }
  700.  
  701. private async Task ForceUnban(Client client)
  702. {
  703. if (!ForceUnbanning && !Stopping)
  704. {
  705. ColoredConsoleWrite(Color.LightGreen, "Waiting for last farming action to be complete...");
  706. ForceUnbanning = true;
  707.  
  708. while (FarmingStops || FarmingPokemons)
  709. {
  710. await Task.Delay(25);
  711. }
  712.  
  713. ColoredConsoleWrite(Color.LightGreen, "Starting force unban...");
  714.  
  715. pokestopsOverlay.Routes.Clear();
  716. pokestopsOverlay.Markers.Clear();
  717. bool done = false;
  718. foreach (var pokeStop in pokeStops)
  719. {
  720. if (pokeStop.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime())
  721. {
  722. await locationManager.update(pokeStop.Latitude, pokeStop.Longitude);
  723. UpdatePlayerLocation(pokeStop.Latitude, pokeStop.Longitude);
  724. UpdateMap();
  725.  
  726. var fortInfo = await client.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
  727. if (fortInfo.Name != string.Empty)
  728. {
  729. ColoredConsoleWrite(Color.LightGreen, "Chosen PokeStop " + fortInfo.Name + " for force unban");
  730. for (int i = 1; i <= 50; i++)
  731. {
  732. var fortSearch = await client.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
  733. if (fortSearch.ExperienceAwarded == 0)
  734. {
  735. ColoredConsoleWrite(Color.LightGreen, "Attempt: " + i);
  736. }
  737. else
  738. {
  739. ColoredConsoleWrite(Color.LightGreen, "Fuck yes, you are now unbanned! Total attempts: " + i);
  740. done = true;
  741. break;
  742. }
  743. }
  744. if (done)
  745. break;
  746. }
  747. }
  748. }
  749. if (!done)
  750. ColoredConsoleWrite(Color.LightGreen, "Force unban failed, please try again.");
  751. ForceUnbanning = false;
  752. }
  753. else
  754. {
  755. ColoredConsoleWrite(Color.Red, "A action is in play... Please wait.");
  756. }
  757.  
  758.  
  759. }
  760.  
  761. private string GetFriendlyItemsString(IEnumerable<FortSearchResponse.Types.ItemAward> items)
  762. {
  763. var enumerable = items as IList<FortSearchResponse.Types.ItemAward> ?? items.ToList();
  764.  
  765. if (!enumerable.Any())
  766. return string.Empty;
  767.  
  768. return enumerable.GroupBy(i => i.ItemId)
  769. .Select(kvp => new { ItemName = kvp.Key.ToString().Substring(4), Amount = kvp.Sum(x => x.ItemCount) })
  770. .Select(y => $"{y.Amount}x {y.ItemName}")
  771. .Aggregate((a, b) => $"{a}, {b}");
  772. }
  773.  
  774.  
  775. private async Task TransferAllButStrongestUnwantedPokemon(Client client)
  776. {
  777. var unwantedPokemonTypes = new List<PokemonId>();
  778. for (int i = 1; i <= 151; i++)
  779. {
  780. unwantedPokemonTypes.Add((PokemonId)i);
  781. }
  782.  
  783. var inventory = await client.GetInventory();
  784. var pokemons = inventory.InventoryDelta.InventoryItems
  785. .Select(i => i.InventoryItemData?.Pokemon)
  786. .Where(p => p != null && p?.PokemonId > 0)
  787. .ToArray();
  788.  
  789. foreach (var unwantedPokemonType in unwantedPokemonTypes)
  790. {
  791. var pokemonOfDesiredType = pokemons.Where(p => p.PokemonId == unwantedPokemonType)
  792. .OrderByDescending(p => p.Cp)
  793. .ToList();
  794.  
  795. var unwantedPokemon =
  796. pokemonOfDesiredType.Skip(1) // keep the strongest one for potential battle-evolving
  797. .ToList();
  798.  
  799. await TransferAllGivenPokemons(client, unwantedPokemon);
  800. }
  801. }
  802.  
  803. public static float Perfect(PokemonData poke)
  804. {
  805. return ((float)(poke.IndividualAttack + poke.IndividualDefense + poke.IndividualStamina) / (3.0f * 15.0f)) * 100.0f;
  806. }
  807.  
  808. private async Task TransferAllGivenPokemons(Client client, IEnumerable<PokemonData> unwantedPokemons, float keepPerfectPokemonLimit = 80.0f)
  809. {
  810. foreach (var pokemon in unwantedPokemons)
  811. {
  812. if (Perfect(pokemon) >= keepPerfectPokemonLimit) continue;
  813. ColoredConsoleWrite(Color.White, $"Pokemon {pokemon.PokemonId} with {pokemon.Cp} CP has IV percent less than {keepPerfectPokemonLimit}%");
  814.  
  815. if (pokemon.Favorite == 0)
  816. {
  817. var transferPokemonResponse = await client.TransferPokemon(pokemon.Id);
  818.  
  819. /*
  820. ReleasePokemonOutProto.Status {
  821. UNSET = 0;
  822. SUCCESS = 1;
  823. POKEMON_DEPLOYED = 2;
  824. FAILED = 3;
  825. ERROR_POKEMON_IS_EGG = 4;
  826. }*/
  827. string pokemonName;
  828. if (ClientSettings.Language == "german")
  829. {
  830. // Dont really need to print this do we? youll know if its German or not
  831. //ColoredConsoleWrite(Color.DarkCyan, "german");
  832. string name_english = Convert.ToString(pokemon.PokemonId);
  833. var request = (HttpWebRequest)WebRequest.Create("http://boosting-service.de/pokemon/index.php?pokeName=" + name_english);
  834. var response = (HttpWebResponse)request.GetResponse();
  835. pokemonName = new StreamReader(response.GetResponseStream()).ReadToEnd();
  836. }
  837. else
  838. pokemonName = Convert.ToString(pokemon.PokemonId);
  839. if (transferPokemonResponse.Status == 1)
  840. {
  841. ColoredConsoleWrite(Color.Magenta, $"Transferred {pokemonName} with {pokemon.Cp} CP");
  842. }
  843. else
  844. {
  845. var status = transferPokemonResponse.Status;
  846.  
  847. ColoredConsoleWrite(Color.Red, $"Somehow failed to transfer {pokemonName} with {pokemon.Cp} CP. " +
  848. $"ReleasePokemonOutProto.Status was {status}");
  849. }
  850.  
  851. await Task.Delay(3000);
  852. }
  853. }
  854. }
  855.  
  856. private async Task TransferDuplicatePokemon(Client client)
  857. {
  858.  
  859. //ColoredConsoleWrite(ConsoleColor.White, $"Check for duplicates");
  860. var inventory = await client.GetInventory();
  861. var allpokemons =
  862. inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.Pokemon)
  863. .Where(p => p != null && p?.PokemonId > 0);
  864.  
  865. var dupes = allpokemons.OrderBy(x => x.Cp).Select((x, i) => new { index = i, value = x })
  866. .GroupBy(x => x.value.PokemonId)
  867. .Where(x => x.Skip(1).Any());
  868.  
  869. for (var i = 0; i < dupes.Count(); i++)
  870. {
  871. for (var j = 0; j < dupes.ElementAt(i).Count() - 1; j++)
  872. {
  873. var dubpokemon = dupes.ElementAt(i).ElementAt(j).value;
  874. if (dubpokemon.Favorite == 0)
  875. {
  876. var transfer = await client.TransferPokemon(dubpokemon.Id);
  877. string pokemonName;
  878. if (ClientSettings.Language == "german")
  879. {
  880. string name_english = Convert.ToString(dubpokemon.PokemonId);
  881. var request = (HttpWebRequest)WebRequest.Create("http://boosting-service.de/pokemon/index.php?pokeName=" + name_english);
  882. var response = (HttpWebResponse)request.GetResponse();
  883. pokemonName = new StreamReader(response.GetResponseStream()).ReadToEnd();
  884. }
  885. else
  886. pokemonName = Convert.ToString(dubpokemon.PokemonId);
  887. ColoredConsoleWrite(Color.DarkGreen,
  888. $"Transferred {pokemonName} with {dubpokemon.Cp} CP (Highest is {dupes.ElementAt(i).Last().value.Cp})");
  889.  
  890. }
  891. }
  892. }
  893. }
  894.  
  895. private async Task TransferDuplicateIVPokemon(Client client)
  896. {
  897.  
  898. //ColoredConsoleWrite(ConsoleColor.White, $"Check for duplicates");
  899. var inventory = await client.GetInventory();
  900. var allpokemons =
  901. inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.Pokemon)
  902. .Where(p => p != null && p?.PokemonId > 0);
  903.  
  904. var dupes = allpokemons.OrderBy(x => Perfect(x)).Select((x, i) => new { index = i, value = x })
  905. .GroupBy(x => x.value.PokemonId)
  906. .Where(x => x.Skip(1).Any());
  907.  
  908. for (var i = 0; i < dupes.Count(); i++)
  909. {
  910. for (var j = 0; j < dupes.ElementAt(i).Count() - 1; j++)
  911. {
  912. var dubpokemon = dupes.ElementAt(i).ElementAt(j).value;
  913. if (dubpokemon.Favorite == 0)
  914. {
  915. var transfer = await client.TransferPokemon(dubpokemon.Id);
  916. string pokemonName;
  917. if (ClientSettings.Language == "german")
  918. {
  919. string name_english = Convert.ToString(dubpokemon.PokemonId);
  920. var request = (HttpWebRequest)WebRequest.Create("http://boosting-service.de/pokemon/index.php?pokeName=" + name_english);
  921. var response = (HttpWebResponse)request.GetResponse();
  922. pokemonName = new StreamReader(response.GetResponseStream()).ReadToEnd();
  923. }
  924. else
  925. pokemonName = Convert.ToString(dubpokemon.PokemonId);
  926. ColoredConsoleWrite(Color.DarkGreen,
  927. $"Transferred {pokemonName} with {Math.Round(Perfect(dubpokemon))}% IV (Highest is {Math.Round(Perfect(dupes.ElementAt(i).Last().value))}% IV)");
  928.  
  929. }
  930. }
  931. }
  932. }
  933.  
  934. private async Task TransferAllWeakPokemon(Client client, int cpThreshold)
  935. {
  936. //ColoredConsoleWrite(ConsoleColor.White, $"Firing up the meat grinder");
  937.  
  938. PokemonId[] doNotTransfer = new[] //these will not be transferred even when below the CP threshold
  939. { // DO NOT EMPTY THIS ARRAY
  940. //PokemonId.Pidgey,
  941. //PokemonId.Rattata,
  942. //PokemonId.Weedle,
  943. //PokemonId.Zubat,
  944. //PokemonId.Caterpie,
  945. //PokemonId.Pidgeotto,
  946. //PokemonId.NidoranFemale,
  947. //PokemonId.Paras,
  948. //PokemonId.Venonat,
  949. //PokemonId.Psyduck,
  950. //PokemonId.Poliwag,
  951. //PokemonId.Slowpoke,
  952. //PokemonId.Drowzee,
  953. //PokemonId.Gastly,
  954. //PokemonId.Goldeen,
  955. //PokemonId.Staryu,
  956. PokemonId.Magikarp,
  957. PokemonId.Eevee//,
  958. //PokemonId.Dratini
  959. };
  960.  
  961. var inventory = await client.GetInventory();
  962. var pokemons = inventory.InventoryDelta.InventoryItems
  963. .Select(i => i.InventoryItemData?.Pokemon)
  964. .Where(p => p != null && p?.PokemonId > 0)
  965. .ToArray();
  966.  
  967. //foreach (var unwantedPokemonType in unwantedPokemonTypes)
  968. {
  969. List<PokemonData> pokemonToDiscard;
  970. if (doNotTransfer.Count() != 0)
  971. pokemonToDiscard = pokemons.Where(p => !doNotTransfer.Contains(p.PokemonId) && p.Cp < cpThreshold).OrderByDescending(p => p.Cp).ToList();
  972. else
  973. pokemonToDiscard = pokemons.Where(p => p.Cp < cpThreshold).OrderByDescending(p => p.Cp).ToList();
  974.  
  975.  
  976. //var unwantedPokemon = pokemonOfDesiredType.Skip(1) // keep the strongest one for potential battle-evolving
  977. // .ToList();
  978. ColoredConsoleWrite(Color.Gray, $"Grinding {pokemonToDiscard.Count} pokemon below {cpThreshold} CP.");
  979. await TransferAllGivenPokemons(client, pokemonToDiscard);
  980.  
  981. }
  982.  
  983. ColoredConsoleWrite(Color.Gray, $"Finished grinding all the meat");
  984. }
  985.  
  986.  
  987.  
  988. public async Task PrintLevel(Client client)
  989. {
  990. var inventory = await client.GetInventory();
  991. var stats = inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.PlayerStats).ToArray();
  992. foreach (var v in stats)
  993. if (v != null)
  994. {
  995. int XpDiff = GetXpDiff(client, v.Level);
  996. if (ClientSettings.LevelOutput == "time")
  997. ColoredConsoleWrite(Color.Yellow, $"Current Level: " + v.Level + " (" + (v.Experience - XpDiff) + "/" + (v.NextLevelXp - XpDiff) + ")");
  998. else if (ClientSettings.LevelOutput == "levelup")
  999. if (Currentlevel != v.Level)
  1000. {
  1001. Currentlevel = v.Level;
  1002. ColoredConsoleWrite(Color.Magenta, $"Current Level: " + v.Level + ". XP needed for next Level: " + (v.NextLevelXp - v.Experience));
  1003. }
  1004. }
  1005. if (ClientSettings.LevelOutput == "levelup")
  1006. await Task.Delay(1000);
  1007. else
  1008. await Task.Delay(ClientSettings.LevelTimeInterval * 1000);
  1009. PrintLevel(client);
  1010. }
  1011.  
  1012. // Pulled from NecronomiconCoding
  1013. public static string _getSessionRuntimeInTimeFormat()
  1014. {
  1015. return (DateTime.Now - InitSessionDateTime).ToString(@"dd\.hh\:mm\:ss");
  1016. }
  1017.  
  1018. public async Task updateUserStatusBar(Client client)
  1019. {
  1020. var inventory = await client.GetInventory();
  1021. var stats = inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.PlayerStats).ToArray();
  1022. var profile = await client.GetProfile();
  1023. Int16 hoursLeft = 0; Int16 minutesLeft = 0; Int32 secondsLeft = 0; double xpSec = 0;
  1024. foreach (var v in stats)
  1025. if (v != null)
  1026. {
  1027. int XpDiff = GetXpDiff(client, v.Level);
  1028. //Calculating the exp needed to level up
  1029. Single expNextLvl = (v.NextLevelXp - v.Experience);
  1030. //Calculating the exp made per second
  1031. xpSec = (Math.Round(TotalExperience / GetRuntime()) / 60) / 60;
  1032. //Calculating the seconds left to level up
  1033. if (xpSec != 0)
  1034. secondsLeft = Convert.ToInt32((expNextLvl / xpSec));
  1035. //formatting data to make an output like DateFormat
  1036. while (secondsLeft > 60)
  1037. {
  1038. secondsLeft -= 60;
  1039. if (minutesLeft < 60)
  1040. {
  1041. minutesLeft++;
  1042. }
  1043. else
  1044. {
  1045. minutesLeft = 0;
  1046. hoursLeft++;
  1047. }
  1048. }
  1049. SetStatusText(string.Format(profile.Profile.Username + " | Level: {0:0} - ({2:0} / {3:0}) | Runtime {1} | Stardust: {4:0}", v.Level, _getSessionRuntimeInTimeFormat(), (v.Experience - v.PrevLevelXp - XpDiff), (v.NextLevelXp - v.PrevLevelXp - XpDiff), profile.Profile.Currency.ToArray()[1].Amount) + " | XP/Hour: " + Math.Round(TotalExperience / GetRuntime()) + " | Pokemon/Hour: " + Math.Round(TotalPokemon / GetRuntime()) + " | NextLevel in: " + hoursLeft + ":" + minutesLeft + ":" + secondsLeft);
  1050. }
  1051. await Task.Delay(1000);
  1052. updateUserStatusBar(client);
  1053. }
  1054.  
  1055. public static int GetXpDiff(Client client, int Level)
  1056. {
  1057. switch (Level)
  1058. {
  1059. case 1:
  1060. return 0;
  1061. case 2:
  1062. return 1000;
  1063. case 3:
  1064. return 2000;
  1065. case 4:
  1066. return 3000;
  1067. case 5:
  1068. return 4000;
  1069. case 6:
  1070. return 5000;
  1071. case 7:
  1072. return 6000;
  1073. case 8:
  1074. return 7000;
  1075. case 9:
  1076. return 8000;
  1077. case 10:
  1078. return 9000;
  1079. case 11:
  1080. return 10000;
  1081. case 12:
  1082. return 10000;
  1083. case 13:
  1084. return 10000;
  1085. case 14:
  1086. return 10000;
  1087. case 15:
  1088. return 15000;
  1089. case 16:
  1090. return 20000;
  1091. case 17:
  1092. return 20000;
  1093. case 18:
  1094. return 20000;
  1095. case 19:
  1096. return 25000;
  1097. case 20:
  1098. return 25000;
  1099. case 21:
  1100. return 50000;
  1101. case 22:
  1102. return 75000;
  1103. case 23:
  1104. return 100000;
  1105. case 24:
  1106. return 125000;
  1107. case 25:
  1108. return 150000;
  1109. case 26:
  1110. return 190000;
  1111. case 27:
  1112. return 200000;
  1113. case 28:
  1114. return 250000;
  1115. case 29:
  1116. return 300000;
  1117. case 30:
  1118. return 350000;
  1119. case 31:
  1120. return 500000;
  1121. case 32:
  1122. return 500000;
  1123. case 33:
  1124. return 750000;
  1125. case 34:
  1126. return 1000000;
  1127. case 35:
  1128. return 1250000;
  1129. case 36:
  1130. return 1500000;
  1131. case 37:
  1132. return 2000000;
  1133. case 38:
  1134. return 2500000;
  1135. case 39:
  1136. return 1000000;
  1137. case 40:
  1138. return 1000000;
  1139. }
  1140. return 0;
  1141. }
  1142.  
  1143. public void confirmBotStopped()
  1144. {
  1145. //ConsoleClear(); // dont really want the console to be wipped on bot stop, unnecessary
  1146. ColoredConsoleWrite(Color.Red, $"Bot successfully stopped.");
  1147. if (btnStartFarming.InvokeRequired)
  1148. {
  1149. btnStartFarming.BeginInvoke(new MethodInvoker(delegate
  1150. {
  1151. btnStartFarming.Text = "Start Farming";
  1152. btnPokemon.Enabled = false;
  1153. }));
  1154. }
  1155. else
  1156. {
  1157. btnStartFarming.Text = "Start Farming";
  1158. btnPokemon.Enabled = false;
  1159. }
  1160. Stopping = false;
  1161. bot_started = false;
  1162. }
  1163.  
  1164. private void logTextBox_TextChanged(object sender, EventArgs e)
  1165. {
  1166. logTextBox.SelectionStart = logTextBox.Text.Length;
  1167. logTextBox.ScrollToCaret();
  1168. }
  1169.  
  1170. private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
  1171. {
  1172. SettingsForm settingsForm = new SettingsForm();
  1173. settingsForm.ShowDialog();
  1174. }
  1175.  
  1176. private void Client_OnConsoleWrite(ConsoleColor color, string message)
  1177. {
  1178. Color c = Color.White;
  1179. switch (color)
  1180. {
  1181. case ConsoleColor.Green:
  1182. c = Color.Green;
  1183. break;
  1184. case ConsoleColor.DarkCyan:
  1185. c = Color.DarkCyan;
  1186. break;
  1187. }
  1188. ColoredConsoleWrite(c, message);
  1189. }
  1190.  
  1191. private void showAllToolStripMenuItem3_Click(object sender, EventArgs e)
  1192. {
  1193. }
  1194.  
  1195. private void statsToolStripMenuItem_Click(object sender, EventArgs e)
  1196. {
  1197. // todo: add player stats later
  1198. }
  1199.  
  1200. private void pokemonToolStripMenuItem2_Click(object sender, EventArgs e)
  1201. {
  1202. var pForm = new PokeUi();
  1203. pForm.Show();
  1204. }
  1205.  
  1206.  
  1207. #region POKEMON LIST
  1208. private IEnumerable<PokemonFamily> families;
  1209.  
  1210.  
  1211. private Image GetPokemonImage(int pokemonId)
  1212. {
  1213. var Sprites = AppDomain.CurrentDomain.BaseDirectory + "Sprites\\";
  1214. string location = Sprites + pokemonId + ".png";
  1215. if (!Directory.Exists(Sprites))
  1216. Directory.CreateDirectory(Sprites);
  1217. if (!File.Exists(location))
  1218. {
  1219. WebClient wc = new WebClient();
  1220. wc.DownloadFile("http://pokeapi.co/media/sprites/pokemon/" + pokemonId + ".png", @location);
  1221. }
  1222. return Image.FromFile(location);
  1223. }
  1224.  
  1225.  
  1226. private void pokeToolStripMenuItem_Click(object sender, EventArgs e)
  1227. {
  1228.  
  1229. }
  1230.  
  1231. private void objectListView1_SelectedIndexChanged(object sender, EventArgs e)
  1232. {
  1233.  
  1234. }
  1235.  
  1236. private static bool bot_started = false;
  1237. private void btnStartFarming_Click(object sender, EventArgs e)
  1238. {
  1239. if (!bot_started)
  1240. {
  1241. bot_started = true;
  1242.  
  1243. if (btnStartFarming.InvokeRequired)
  1244. {
  1245. btnStartFarming.BeginInvoke(new MethodInvoker(delegate
  1246. {
  1247. btnPokemon.Enabled = true;
  1248. btnStartFarming.Text = "Stop Farming";
  1249. }));
  1250. }
  1251. else
  1252. {
  1253. btnPokemon.Enabled = true;
  1254. btnStartFarming.Text = "Stop Farming";
  1255. }
  1256.  
  1257. Task.Run(() =>
  1258. {
  1259. try
  1260. {
  1261. //ColoredConsoleWrite(ConsoleColor.White, "Coded by Ferox - edited by NecronomiconCoding");
  1262. CheckVersion();
  1263. Execute();
  1264. }
  1265. catch (PtcOfflineException)
  1266. {
  1267. ColoredConsoleWrite(Color.Red, "PTC Servers are probably down OR your credentials are wrong. Try google");
  1268. }
  1269. catch (Exception ex)
  1270. {
  1271. ColoredConsoleWrite(Color.Red, $"Unhandled exception: {ex}");
  1272. }
  1273. });
  1274. }
  1275. else
  1276. {
  1277. if (!ForceUnbanning)
  1278. {
  1279. Stopping = true;
  1280. ColoredConsoleWrite(Color.Red, $"Stopping the bot.. Waiting for the last action to be complete.");
  1281. }
  1282. else
  1283. {
  1284. ColoredConsoleWrite(Color.Red, $"An action is in play, please wait until it's done.");
  1285. }
  1286. }
  1287. }
  1288.  
  1289. private void btnadvoptions_Click(object sender, EventArgs e)
  1290. {
  1291. SettingsForm settingsForm = new SettingsForm();
  1292. settingsForm.ShowDialog();
  1293. }
  1294.  
  1295. private async void btnLuckyEgg_Click(object sender, EventArgs e)
  1296. {
  1297. if (client != null)
  1298. {
  1299. try
  1300. {
  1301. IEnumerable<Item> myItems = await client.GetItems(client);
  1302. IEnumerable<Item> LuckyEggs = myItems.Where(i => (ItemId)i.Item_ == ItemId.ItemLuckyEgg);
  1303. Item LuckyEgg = LuckyEggs.FirstOrDefault();
  1304. if (LuckyEgg != null)
  1305. {
  1306. var useItemXpBoostRequest = await client.UseItemXpBoost(ItemId.ItemLuckyEgg);
  1307. ColoredConsoleWrite(Color.Green, $"Using a Lucky Egg, we have {LuckyEgg.Count} left.");
  1308. ColoredConsoleWrite(Color.Yellow, $"Lucky Egg Valid until: {DateTime.Now.AddMinutes(30).ToString()}");
  1309.  
  1310. var stripItem = sender as ToolStripMenuItem;
  1311. stripItem.Enabled = false;
  1312. await Task.Delay(30000);
  1313. stripItem.Enabled = true;
  1314. }
  1315. else
  1316. {
  1317. ColoredConsoleWrite(Color.Red, $"You don't have any Lucky Egg to use.");
  1318. }
  1319. }
  1320. catch (Exception ex)
  1321. {
  1322. ColoredConsoleWrite(Color.Red, $"Unhandled exception in using lucky egg: {ex}");
  1323. }
  1324. }
  1325. else
  1326. {
  1327. ColoredConsoleWrite(Color.Red, "Please start the bot before trying to use a lucky egg.");
  1328. }
  1329. }
  1330.  
  1331. private async void btnForceUnban_Click(object sender, EventArgs e)
  1332. {
  1333. if (client != null && pokeStops != null)
  1334. {
  1335. if (ForceUnbanning)
  1336. {
  1337. ColoredConsoleWrite(Color.Red, "A force unban attempt is in action... Please wait.");
  1338. }
  1339. else
  1340. {
  1341. await ForceUnban(client);
  1342. }
  1343. }
  1344. else
  1345. {
  1346. ColoredConsoleWrite(Color.Red, "Please start the bot and wait for map to load before trying to force unban");
  1347. }
  1348. }
  1349.  
  1350. private void btnPokemon_Click(object sender, EventArgs e)
  1351. {
  1352. var pForm = new PokeUi();
  1353. pForm.Show();
  1354. }
  1355.  
  1356. private async void btnuseincense_Click(object sender, EventArgs e)
  1357. {
  1358. if (client != null)
  1359. {
  1360. try
  1361. {
  1362. IEnumerable<Item> myItems = await client.GetItems(client);
  1363. IEnumerable<Item> Incenses = myItems.Where(i => (ItemId)i.Item_ == ItemId.ItemIncenseOrdinary);
  1364. Item Incense = Incenses.FirstOrDefault();
  1365. if (Incense != null)
  1366. {
  1367. var useIncenseRequest = await client.UseIncense(ItemId.ItemIncenseOrdinary);
  1368. ColoredConsoleWrite(Color.Green, $"Using an Incense, we have {Incense.Count} left.");
  1369. ColoredConsoleWrite(Color.Yellow, $"Incense valid until: {DateTime.Now.AddMinutes(30).ToString()}");
  1370.  
  1371. var stripItem = sender as ToolStripMenuItem;
  1372. stripItem.Enabled = false;
  1373. await Task.Delay(30000);
  1374. stripItem.Enabled = true;
  1375. }
  1376. else
  1377. {
  1378. ColoredConsoleWrite(Color.Red, $"You don't have any Incense to use.");
  1379. }
  1380. }
  1381. catch (Exception ex)
  1382. {
  1383. ColoredConsoleWrite(Color.Red, $"Unhandled exception in using Incense: {ex}");
  1384. }
  1385. }
  1386. else
  1387. {
  1388. ColoredConsoleWrite(Color.Red, "Please start the bot before trying to use a Incense.");
  1389. }
  1390. }
  1391. }
  1392. }
  1393. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement