public static async Task CheckMSniper(ISession session, CancellationToken cancellationToken) { OpenSocket(); //return;//NEW SNIPE METHOD WILL BE ACTIVATED var pth = Path.Combine(session.LogicSettings.ProfilePath, "SnipeMS.json"); try { if (!File.Exists(pth)) { return; } if (!await SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { return; } var sr = new StreamReader(pth, Encoding.UTF8); var jsn = sr.ReadToEnd(); sr.Close(); var mSniperLocation2 = JsonConvert.DeserializeObject <List <EncounterInfo> >(jsn); File.Delete(pth); foreach (var location in mSniperLocation2) { cancellationToken.ThrowIfCancellationRequested(); session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = location.PokemonId, Source = "MSniperService", Iv = location.Iv }); await CatchFromService(session, cancellationToken, location); await Task.Delay(1000, cancellationToken); } } catch (Exception ex) { File.Delete(pth); var ee = new ErrorEvent { Message = ex.Message }; if (ex.InnerException != null) { ee.Message = ex.InnerException.Message; } session.EventDispatcher.Send(ee); } }
public static async Task CheckMSniperLocation(ISession session, CancellationToken cancellationToken) { string pth = Path.Combine(session.LogicSettings.ProfilePath, "SnipeMS.json"); try { if (session.LogicSettings.CatchPokemon == true && session.LogicSettings.SnipeAtPokestops == false && session.LogicSettings.UseSnipeLocationServer == false )//extra security { if (!File.Exists(pth)) { return; } if (!await SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { return; } var CurrentLatitude = session.Client.CurrentLatitude; var CurrentLongitude = session.Client.CurrentLongitude; StreamReader sr = new StreamReader(pth, Encoding.UTF8); string jsn = sr.ReadToEnd(); sr.Close(); List <MSniperInfo> MSniperLocation = JsonConvert.DeserializeObject <List <MSniperInfo> >(jsn); File.Delete(pth); foreach (var location in MSniperLocation) { session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = location.Id, Source = "MSniper" }); await OwnSnipe(session, location.Id, location.Latitude, location.Longitude, cancellationToken); } await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(CurrentLatitude, CurrentLongitude, session.Client.CurrentAltitude)); } } catch (Exception ex) { File.Delete(pth);//fixing deserialize errors ErrorEvent ee = new ErrorEvent { Message = ex.Message }; if (ex.InnerException != null) { ee.Message = ex.InnerException.Message; } session.EventDispatcher.Send(ee); } }
public static async Task CheckMSniperLocation(ISession session, CancellationToken cancellationToken) { try { if (session.LogicSettings.CatchPokemon && session.LogicSettings.SnipeAtPokestops == false)//must be { if (!await SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { return; } string pth = Path.Combine(session.LogicSettings.ConfigurationDirectory, "SnipeMS.json"); if (!File.Exists(pth)) { return; } StreamReader sr = new StreamReader(pth, Encoding.UTF8); string jsn = sr.ReadToEnd(); sr.Close(); List <MSniperInfo> MSniperLocation = JsonConvert.DeserializeObject <List <MSniperInfo> >(jsn); File.Delete(pth); foreach (var location in MSniperLocation) { session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = location.Id, Source = "MSniper" }); await SnipePokemonTask.Snipe(session, session.LogicSettings.PokemonToSnipe.Pokemon, location.Latitude, location.Longitude, cancellationToken); } } } catch (Exception ex) { session.EventDispatcher.Send(new ErrorEvent { Message = ex.Message }); } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { if (!CheckSnipeConditions(session)) { return; } inProgress = true; double originalLatitude = session.Client.CurrentLatitude; double originalLongitude = session.Client.CurrentLongitude; session.KnownLatitudeBeforeSnipe = originalLatitude; session.KnownLongitudeBeforeSnipe = originalLongitude; //Logger.Write($"DEBUG : Location before snipe : {originalLatitude},{originalLongitude}"); var pth = Path.Combine(Directory.GetCurrentDirectory(), "SnipeMS.json"); try { if (OutOffBallBlock > DateTime.Now || ( File.Exists(pth) && autoSnipePokemons.Count == 0 && manualSnipePokemons.Count == 0 && pokedexSnipePokemons.Count == 0)) { return; } if (autoSnipePokemons.Count > 0 && !SnipePokemonTask.CheckPokeballsToSnipe( session.LogicSettings.MinPokeballsToSnipe + 1, session, cancellationToken)) { session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(TranslationString.AutoSnipeDisabled, session.LogicSettings.SnipePauseOnOutOfBallTime) }); OutOffBallBlock = DateTime.Now.AddMinutes(session.LogicSettings.SnipePauseOnOutOfBallTime); return; } List <MSniperInfo2> mSniperLocation2 = new List <MSniperInfo2>(); if (File.Exists(pth)) { var sr = new StreamReader(pth, Encoding.UTF8); var jsn = sr.ReadToEnd(); sr.Close(); mSniperLocation2 = JsonConvert.DeserializeObject <List <MSniperInfo2> >(jsn); File.Delete(pth); if (mSniperLocation2 == null) { mSniperLocation2 = new List <MSniperInfo2>(); } } lock (locker) { if (pokedexSnipePokemons.Count > 0) { mSniperLocation2.Add(pokedexSnipePokemons.OrderByDescending(x => x.PokemonId).FirstOrDefault()); pokedexSnipePokemons.Clear(); } if (manualSnipePokemons.Count > 0) { mSniperLocation2.AddRange(manualSnipePokemons); manualSnipePokemons.Clear(); } else { autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now); // || ( x.ExpiredTime >0 && x.ExpiredTime < DateTime.Now.ToUnixTime())); autoSnipePokemons.OrderBy(x => x.Priority) .ThenByDescending(x => PokemonGradeHelper.GetPokemonGrade((PokemonId)x.PokemonId)) .ThenByDescending(x => x.Iv) .ThenByDescending(x => x.PokemonId) .ThenByDescending(x => x.AddedTime); var batch = autoSnipePokemons.Take(session.LogicSettings.AutoSnipeBatchSize); if (batch != null && batch.Count() > 0) { mSniperLocation2.AddRange(batch); autoSnipePokemons.RemoveAll(x => batch.Contains(x)); } } } foreach (var location in mSniperLocation2) { if (session.Stats.CatchThresholdExceeds(session) || isBlocking) { break; } lock (locker) { if (location.EncounterId > 0 && expiredCache.Get(location.EncounterId.ToString()) != null) { continue; } if (pokedexSnipePokemons.Count > 0 || manualSnipePokemons.Count > 0) { break; //should return item back to snipe list } } session.EventDispatcher.Send(new SnipePokemonStarted(location)); if (location.EncounterId > 0 && session.Cache[location.EncounterId.ToString()] != null) { continue; } if (!SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(TranslationString.AutoSnipeDisabled) }); OutOffBallBlock = DateTime.Now.AddMinutes(session.LogicSettings.SnipePauseOnOutOfBallTime); break; } if (location.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now) { continue; } //If bot already catch the same pokemon, and very close this location. string uniqueCacheKey = $"{session.Settings.PtcUsername}{session.Settings.GoogleUsername}{Math.Round(location.Latitude, 6)}{location.PokemonId}{Math.Round(location.Longitude, 6)}"; if (session.Cache.Get(uniqueCacheKey) != null) { continue; } session.Cache.Add(location.EncounterId.ToString(), true, DateTime.Now.AddMinutes(15)); cancellationToken.ThrowIfCancellationRequested(); TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested(); session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = (PokemonId)location.PokemonId, Source = "InternalSnipe", Iv = location.Iv }); session.Stats.IsSnipping = true; var result = (location.IsVerified()) ? await CatchFromService(session, cancellationToken, location) : await CatchWithSnipe(session, location, cancellationToken); LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(originalLatitude, originalLongitude), 0); if (result) { snipeFailedCount = 0; } else { snipeFailedCount++; if (snipeFailedCount >= 3) { break; //maybe softban, stop snipe wait until verify it not been } } //await Task.Delay(1000, cancellationToken); session.Stats.LastSnipeTime = DateTime.Now; session.Stats.SnipeCount++; waitNextPokestop = true; } } catch (ActiveSwitchByPokemonException ex) { throw ex; } catch (ActiveSwitchAccountManualException ex) { throw ex; } catch (ActiveSwitchByRuleException ex) { throw ex; } catch (CaptchaException cex) { throw cex; } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException is CaptchaException) { throw ex.InnerException; } File.Delete(pth); var ee = new ErrorEvent { Message = ex.Message }; if (ex.InnerException != null) { ee.Message = ex.InnerException.Message; } session.EventDispatcher.Send(ee); } finally { inProgress = false; session.Stats.IsSnipping = false; //Logger.Write($"DEBUG : Back to home location: {originalLatitude},{originalLongitude}"); LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(originalLatitude, originalLongitude), 0); } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { if (inProgress) { return; } inProgress = true; //if (session.LogicSettings.ActivateMSniper) // OpenSocket(); //return;//NEW SNIPE METHOD WILL BE ACTIVATED var pth = Path.Combine(Directory.GetCurrentDirectory(), "SnipeMS.json"); try { if ((!File.Exists(pth) && autoSnipePokemons.Count == 0) || OutOffBallBlock > DateTime.Now) { autoSnipePokemons.Clear(); inProgress = false; return; } if (!await SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { inProgress = false; session.EventDispatcher.Send(new WarnEvent() { Message = "Your are out of ball because snipe so fast, you can reduce snipe speed by update MinIVForAutoSnipe or SnipePokemonFilters, Auto snipe will be disable in 5 mins" }); OutOffBallBlock = DateTime.Now.AddMinutes(5); return; } List <MSniperInfo2> mSniperLocation2 = new List <MSniperInfo2>(); if (File.Exists(pth)) { var sr = new StreamReader(pth, Encoding.UTF8); var jsn = sr.ReadToEnd(); sr.Close(); mSniperLocation2 = JsonConvert.DeserializeObject <List <MSniperInfo2> >(jsn); File.Delete(pth); if (mSniperLocation2 == null) { mSniperLocation2 = new List <MSniperInfo2>(); } } mSniperLocation2.AddRange(autoSnipePokemons); autoSnipePokemons.Clear(); foreach (var location in mSniperLocation2) { if (session.Cache[location.EncounterId.ToString()] != null) { continue; } session.Cache.Add(location.EncounterId.ToString(), true, DateTime.Now.AddMinutes(15)); cancellationToken.ThrowIfCancellationRequested(); session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = (PokemonId)location.PokemonId, Source = "MSniperService", Iv = location.Iv }); if (location.EncounterId != 0) { await CatchFromService(session, cancellationToken, location); } else { await CatchWithSnipe(session, cancellationToken, location); } await Task.Delay(1000, cancellationToken); } } catch (ActiveSwitchByRuleException ex) { throw ex; } catch (Exception ex) { File.Delete(pth); var ee = new ErrorEvent { Message = ex.Message }; if (ex.InnerException != null) { ee.Message = ex.InnerException.Message; } session.EventDispatcher.Send(ee); } finally { inProgress = false; } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { if (inProgress || OutOffBallBlock > DateTime.Now) { return; } inProgress = true; var pth = Path.Combine(Directory.GetCurrentDirectory(), "SnipeMS.json"); try { if ((!File.Exists(pth) && autoSnipePokemons.Count == 0) || OutOffBallBlock > DateTime.Now) { autoSnipePokemons.Clear(); return; } if (!await SnipePokemonTask.CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) { session.EventDispatcher.Send(new WarnEvent() { Message = "Your are out of ball because snipe so fast, you can reduce snipe speed by update MinIVForAutoSnipe or SnipePokemonFilters, Auto snipe will be disable in 5 mins" }); OutOffBallBlock = DateTime.Now.AddMinutes(5); return; } List <MSniperInfo2> mSniperLocation2 = new List <MSniperInfo2>(); if (File.Exists(pth)) { var sr = new StreamReader(pth, Encoding.UTF8); var jsn = sr.ReadToEnd(); sr.Close(); mSniperLocation2 = JsonConvert.DeserializeObject <List <MSniperInfo2> >(jsn); File.Delete(pth); if (mSniperLocation2 == null) { mSniperLocation2 = new List <MSniperInfo2>(); } } if (manualSnipePokemons.Count > 0) { mSniperLocation2.AddRange(manualSnipePokemons); manualSnipePokemons.Clear(); } else { autoSnipePokemons.Reverse(); mSniperLocation2.AddRange(autoSnipePokemons.Take(10)); autoSnipePokemons.Clear(); } foreach (var location in mSniperLocation2) { if (location.EncounterId > 0 && session.Cache[location.EncounterId.ToString()] != null) { continue; } //If bot already catch the same pokemon, and very close this location. string uniqueCacheKey = $"{session.Settings.PtcUsername}{session.Settings.GoogleUsername}{Math.Round(location.Latitude, 6)}{location.PokemonId}{Math.Round(location.Longitude, 6)}"; if (session.Cache.Get(uniqueCacheKey) != null) { continue; } session.Cache.Add(location.EncounterId.ToString(), true, DateTime.Now.AddMinutes(15)); cancellationToken.ThrowIfCancellationRequested(); session.EventDispatcher.Send(new SnipeScanEvent { Bounds = new Location(location.Latitude, location.Longitude), PokemonId = (PokemonId)location.PokemonId, Source = "MSniperService", Iv = location.Iv }); if (location.EncounterId != 0) { if (!await CatchFromService(session, cancellationToken, location)) { //inventory full, out of ball break snipe break; } } else { await CatchWithSnipe(session, location, cancellationToken); } await Task.Delay(1000, cancellationToken); } } catch (ActiveSwitchByRuleException ex) { throw ex; } catch (CaptchaException cex) { throw cex; } catch (Exception ex) { File.Delete(pth); var ee = new ErrorEvent { Message = ex.Message }; if (ex.InnerException != null) { ee.Message = ex.InnerException.Message; } session.EventDispatcher.Send(ee); } finally { inProgress = false; } }