(no message)

Spegeli [2016-07-24 03:48:02]

Filename
PokemonGo.RocketAPI.Console/Resources/PokemonsNotToCatch.txt
PokemonGo.RocketAPI.Console/Resources/PokemonsToEvolve.txt
PokemonGo.RocketAPI.Logic/Logic.cs
PokemonGo.RocketAPI.Logic/Utils/Statistics.cs
PokemonGo.RocketAPI/Client.cs
PokemonGo.RocketAPI/Login/PtcLogin.cs
PokemonGo.RocketAPI/PokemonGo.RocketAPI.csproj
PokemonGo.RocketAPI/Properties/AssemblyInfo.cs
PokemonGo.RocketAPI/Proto/AllEnum.proto
diff --git a/PokemonGo.RocketAPI.Console/Resources/PokemonsNotToCatch.txt b/PokemonGo.RocketAPI.Console/Resources/PokemonsNotToCatch.txt
index b251c0b..e69de29 100644
--- a/PokemonGo.RocketAPI.Console/Resources/PokemonsNotToCatch.txt
+++ b/PokemonGo.RocketAPI.Console/Resources/PokemonsNotToCatch.txt
@@ -1,2 +0,0 @@
-Pidgey
-Rattata
\ No newline at end of file
diff --git a/PokemonGo.RocketAPI.Console/Resources/PokemonsToEvolve.txt b/PokemonGo.RocketAPI.Console/Resources/PokemonsToEvolve.txt
index 64c427b..4799a51 100644
--- a/PokemonGo.RocketAPI.Console/Resources/PokemonsToEvolve.txt
+++ b/PokemonGo.RocketAPI.Console/Resources/PokemonsToEvolve.txt
@@ -1,38 +1,39 @@
-Pidgey
-Rattata
-Spearow
-Ekans
-Pikachu
-Sandshrew
+Caterpie
 Clefable
-Vulpix
-Jigglypuff
-Zubat
-Paras
-Venonat
+Cubone
 Diglett
-Meowth
-Psyduck
-Mankey
-Growlithe
-Tentacool
-Ponyta
-Slowpoke
-Magnemite
 Doduo
-Seel
-Grimer
-Shellder
+Dratini
 Drowzee
-Krabby
-Voltorb
+Ekans
 Exeggcute
-Cubone
+Goldeen
+Grimer
+Growlithe
+Horsea
+Jigglypuff
+Kabuto
 Koffing
+Krabby
+Magnemite
+Mankey
+Meowth
+Omanyte
+Paras
+Pidgey
+Ponyta
+Psyduck
+Rattata
 Rhyhorn
-Horsea
-Goldeen
+Sandshrew
+Seel
+Shellder
+Slowpoke
+Spearow
 Staryu
-Omanyte
-Kabuto
-Dratini
\ No newline at end of file
+Tentacool
+Venonat
+Voltorb
+Vulpix
+Weedle
+Zubat
\ No newline at end of file
diff --git a/PokemonGo.RocketAPI.Logic/Logic.cs b/PokemonGo.RocketAPI.Logic/Logic.cs
index 91b6689..5ad692e 100644
--- a/PokemonGo.RocketAPI.Logic/Logic.cs
+++ b/PokemonGo.RocketAPI.Logic/Logic.cs
@@ -106,10 +106,9 @@ namespace PokemonGo.RocketAPI.Logic
                     Logger.Error($"{ex}");
                     await Execute();
                 }
-                catch (InvalidResponseException ex)
+                catch (InvalidResponseException)
                 {
                     Logger.Error("InvalidResponseException - Restarting");
-                    Logger.Error($"{ex}");
                     await Execute();
                 }
                 catch (AggregateException ex)
@@ -131,7 +130,7 @@ namespace PokemonGo.RocketAPI.Logic
                 await Inventory.getCachedInventory(_client);
                 _playerProfile = await _client.GetProfile();

-                _stats.updateConsoleTitle(_inventory);
+                _stats.UpdateConsoleTitle(_inventory);

                 var _currentLevelInfos = await Statistics._getcurrentLevelInfos(_inventory);

@@ -184,8 +183,6 @@ namespace PokemonGo.RocketAPI.Logic
         private async Task ExecuteFarmingPokestopsAndPokemons()
         {
             var mapObjects = await _client.GetMapObjects();
-            //var pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts).Where(i => i.Type == FortType.Checkpoint && i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).OrderBy(i => LocationUtils.CalculateDistanceInMeters(new Navigation.Location(_client.CurrentLat, _client.CurrentLng), new Navigation.Location(i.Latitude, i.Longitude)));
-            //var pokeStops = Navigation.pathByNearestNeighbour(mapObjects.MapCells.SelectMany(i => i.Forts).Where(i => i.Type == FortType.Checkpoint && i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).OrderBy(i => LocationUtils.CalculateDistanceInMeters(new Navigation.Location(_client.CurrentLat, _client.CurrentLng), new Navigation.Location(i.Latitude, i.Longitude))).ToArray());

             var pokeStops =
                 Navigation.pathByNearestNeighbour(
@@ -211,13 +208,14 @@ namespace PokemonGo.RocketAPI.Logic
                 var fortInfo = await _client.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
                 var fortSearch = await _client.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

-                _stats.addExperience(fortSearch.ExperienceAwarded);
-                _stats.updateConsoleTitle(_inventory);
-
                 Logger.Normal(ConsoleColor.Cyan, $"(POKESTOP) Name: {fortInfo.Name} in {distance:0.##} m distance");
                 if (fortSearch.ExperienceAwarded > 0)
-                    Logger.Normal(ConsoleColor.Cyan, $"(POKESTOP) XP: {fortSearch.ExperienceAwarded}, Gems: {fortSearch.GemsAwarded}, Eggs: {fortSearch.PokemonDataEgg} Items: {StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded)}");
+                {
+                    _stats.AddExperience(fortSearch.ExperienceAwarded);
+                    _stats.UpdateConsoleTitle(_inventory);

+                    Logger.Normal(ConsoleColor.Cyan, $"(POKESTOP) XP: {fortSearch.ExperienceAwarded}, Gems: {fortSearch.GemsAwarded}, Eggs: {fortSearch.PokemonDataEgg} Items: {StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded)}");
+                }
                 await RandomHelper.RandomDelay(50, 200);
                 await RecycleItems();
             }
@@ -227,8 +225,6 @@ namespace PokemonGo.RocketAPI.Logic
         {
             var mapObjects = await _client.GetMapObjects();

-            //var pokemons = mapObjects.MapCells.SelectMany(i => i.CatchablePokemons).OrderBy(i => LocationUtils.CalculateDistanceInMeters(new Navigation.Location(_client.CurrentLat, _client.CurrentLng), new Navigation.Location(i.Latitude, i.Longitude)));
-
             var pokemons =
                 mapObjects.MapCells.SelectMany(i => i.CatchablePokemons)
                 .OrderBy(
@@ -289,16 +285,16 @@ namespace PokemonGo.RocketAPI.Logic
                 if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                 {
                     foreach (int xp in caughtPokemonResponse.Scores.Xp)
-                        _stats.addExperience(xp);
-                    _stats.increasePokemons();
+                        _stats.AddExperience(xp);
+                    _stats.IncreasePokemons();
                     var profile = await _client.GetProfile();
-                    _stats.getStardust(profile.Profile.Currency.ToArray()[1].Amount);
+                    _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount);
                 }
-                _stats.updateConsoleTitle(_inventory);
+                _stats.UpdateConsoleTitle(_inventory);
                 Logger.Normal(ConsoleColor.Yellow,
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
-                    ? $"(POKEBATTLE) Caught {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m distance | with {bestPokeball} and received XP {caughtPokemonResponse.Scores.Xp.Sum()}"
-                    : $"(POKEBATTLE) Missed/Escaped {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} {caughtPokemonResponse.Status} | {Math.Round(distance)}m distance | using a {bestPokeball}.."
+                    ? $"(POKEBATTLE) Caught {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m dist | with {bestPokeball} and received XP {caughtPokemonResponse.Scores.Xp.Sum()}"
+                    : $"(POKEBATTLE) Missed/Escaped {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} {caughtPokemonResponse.Status} | {Math.Round(distance)}m dist | using a {bestPokeball}.."
                     );
                 await RandomHelper.RandomDelay(750, 1250);
             }
@@ -335,12 +331,13 @@ namespace PokemonGo.RocketAPI.Logic
             foreach (var duplicatePokemon in duplicatePokemons)
             {
                 //if (PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >= _clientSettings.KeepMinIVPercentage || duplicatePokemon.Cp > _clientSettings.KeepMinCP)
-                //    continue;
+                if (duplicatePokemon.Cp >= _clientSettings.KeepMinCP)
+                    continue;

                 var transfer = await _client.TransferPokemon(duplicatePokemon.Id);

-                _stats.increasePokemonsTransfered();
-                _stats.updateConsoleTitle(_inventory);
+                _stats.IncreasePokemonsTransfered();
+                _stats.UpdateConsoleTitle(_inventory);

                 var bestPokemonOfType = await _inventory.GetHighestPokemonOfTypeByCP(duplicatePokemon);
                 Logger.Normal(ConsoleColor.DarkYellow, $"(TRANSFER) {duplicatePokemon.PokemonId} (CP {duplicatePokemon.Cp} | {PokemonInfo.CalculatePokemonPerfection(duplicatePokemon).ToString("0.00")} % perfect) | (Best: {bestPokemonOfType.Cp} CP | {PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType).ToString("0.00")} % perfect)");
@@ -359,8 +356,8 @@ namespace PokemonGo.RocketAPI.Logic
                 var transfer = await _client.RecycleItem((ItemId)item.Item_, item.Count);
                 Logger.Normal(ConsoleColor.DarkMagenta, $"(RECYCLED) {item.Count}x {(ItemId)item.Item_}");

-                _stats.addItemsRemoved(item.Count);
-                _stats.updateConsoleTitle(_inventory);
+                _stats.AddItemsRemoved(item.Count);
+                _stats.UpdateConsoleTitle(_inventory);

                 await Task.Delay(100);
             }
diff --git a/PokemonGo.RocketAPI.Logic/Utils/Statistics.cs b/PokemonGo.RocketAPI.Logic/Utils/Statistics.cs
index 38bdf06..d682a60 100644
--- a/PokemonGo.RocketAPI.Logic/Utils/Statistics.cs
+++ b/PokemonGo.RocketAPI.Logic/Utils/Statistics.cs
@@ -10,79 +10,83 @@ using PokemonGo.RocketAPI.GeneratedCode;

 namespace PokemonGo.RocketAPI.Logic.Utils
 {
-    class Statistics
+    internal class Statistics
     {
-        public static int _totalExperience;
-        public static int _totalPokemons;
-        public static int _totalItemsRemoved;
-        public static int _totalPokemonsTransfered;
-        public static int _totalStardust;
-        public static string _currentLevelInfos;
+        public static int TotalExperience;
+        public static int TotalPokemons;
+        public static int TotalItemsRemoved;
+        public static int TotalPokemonsTransfered;
+        public static int TotalStardust;
+        public static string CurrentLevelInfos;
         public static int Currentlevel = -1;

-        public static DateTime _initSessionDateTime = DateTime.Now;
-        public static TimeSpan duration = (DateTime.Now - _initSessionDateTime);
+        public static DateTime InitSessionDateTime = DateTime.Now;
+        public static TimeSpan Duration = DateTime.Now - InitSessionDateTime;

-        public static double _getSessionRuntime()
+        public static async Task<string> _getcurrentLevelInfos(Inventory inventory)
         {
-            return ((DateTime.Now - _initSessionDateTime).TotalSeconds) / 3600;
+            var stats = await inventory.GetPlayerStats();
+            var output = string.Empty;
+            var stat = stats.FirstOrDefault();
+            if (stat != null)
+            {
+                var ep = (stat.NextLevelXp - stat.PrevLevelXp) - (stat.Experience - stat.PrevLevelXp);
+                var hours = Math.Round(ep/(TotalExperience / _getSessionRuntime()), 2);
+
+                output = $"{stat.Level} (LvLUp in {hours}hours | {stat.Experience - stat.PrevLevelXp - GetXpDiff(stat.Level)}/{stat.NextLevelXp - stat.PrevLevelXp - GetXpDiff(stat.Level)} XP)";
+                //output = $"{stat.Level} (LvLUp in {_hours}hours // EXP required: {_ep})";
+            }
+            return output;
         }

-        public static string _getSessionRuntimeInTimeFormat()
+        public static double _getSessionRuntime()
         {
-            return ((DateTime.Now - _initSessionDateTime).ToString(@"dd\.hh\:mm\:ss"));
+            return (DateTime.Now - InitSessionDateTime).TotalSeconds/3600;
         }

-        public void addExperience(int xp)
+        public static string _getSessionRuntimeInTimeFormat()
         {
-            _totalExperience += xp;
+            return (DateTime.Now - InitSessionDateTime).ToString(@"dd\.hh\:mm\:ss");
         }

-        public static async Task<string> _getcurrentLevelInfos(Inventory _inventory)
+        public void AddExperience(int xp)
         {
-            var stats = await _inventory.GetPlayerStats();
-            var output = string.Empty;
-            PlayerStats stat = stats.FirstOrDefault();
-            if (stat != null)
-            {
-                var _ep = (stat.NextLevelXp - stat.PrevLevelXp) - (stat.Experience - stat.PrevLevelXp);
-                var _hours = Math.Round(_ep / (_totalExperience / _getSessionRuntime()),2);
-
-                output = $"{stat.Level} (LvLUp in {_hours}hours // {stat.Experience - stat.PrevLevelXp - GetXpDiff(stat.Level)}/{stat.NextLevelXp - stat.PrevLevelXp - GetXpDiff(stat.Level)} XP)";
-                //output = $"{stat.Level} (LvLUp in {_hours}hours // EXP required: {_ep})";
-            }
-            return output;
+            TotalExperience += xp;
         }

-        public void increasePokemons()
+        public void AddItemsRemoved(int count)
         {
-            _totalPokemons += 1;
+            TotalItemsRemoved += count;
         }

-        public void getStardust(int stardust)
+        public void GetStardust(int stardust)
         {
-            _totalStardust = stardust;
+            TotalStardust = stardust;
         }

-        public void addItemsRemoved(int count)
+        public void IncreasePokemons()
         {
-            _totalItemsRemoved += count;
+            TotalPokemons += 1;
         }

-        public void increasePokemonsTransfered()
+        public void IncreasePokemonsTransfered()
         {
-            _totalPokemonsTransfered += 1;
+            TotalPokemonsTransfered += 1;
         }

-        public async void updateConsoleTitle(Inventory _inventory)
+        public async void UpdateConsoleTitle(Inventory _inventory)
         {
-            _currentLevelInfos = await _getcurrentLevelInfos(_inventory);
+            CurrentLevelInfos = await _getcurrentLevelInfos(_inventory);
             Console.Title = ToString();
         }

         public override string ToString()
-        {
-            return string.Format("SessionRuntime {0} - LvL: {1:0} | EXP/H: {2:0} | P/H: {3:0} | Stardust: {4:0} | Pokemon Transfered: {5:0} | Items Removed: {6:0}",  _getSessionRuntimeInTimeFormat(), _currentLevelInfos, _totalExperience / _getSessionRuntime(), _totalPokemons / _getSessionRuntime(), _totalStardust, _totalPokemonsTransfered, _totalItemsRemoved);
+        {
+            return
+                string.Format(
+                    "Runtime {0} - Lvl: {1:0} | EXP/H: {2:0} | P/H: {3:0} | Stardust: {4:0} | Transfered: {5:0} | Items Recycled: {6:0}",
+                    _getSessionRuntimeInTimeFormat(), CurrentLevelInfos, TotalExperience / _getSessionRuntime(),
+                    TotalPokemons / _getSessionRuntime(), TotalStardust, TotalPokemonsTransfered, TotalItemsRemoved);
         }

         public static int GetXpDiff(int level)
diff --git a/PokemonGo.RocketAPI/Client.cs b/PokemonGo.RocketAPI/Client.cs
index a812bd8..501edfc 100644
--- a/PokemonGo.RocketAPI/Client.cs
+++ b/PokemonGo.RocketAPI/Client.cs
@@ -8,9 +8,9 @@ using System.Threading.Tasks;
 using Google.Protobuf;
 using PokemonGo.RocketAPI.Enums;
 using PokemonGo.RocketAPI.Exceptions;
+using PokemonGo.RocketAPI.Extensions;
 using PokemonGo.RocketAPI.GeneratedCode;
 using PokemonGo.RocketAPI.Helpers;
-using PokemonGo.RocketAPI.Extensions;
 using PokemonGo.RocketAPI.Login;
 using static PokemonGo.RocketAPI.GeneratedCode.Response.Types;

@@ -21,17 +21,11 @@ namespace PokemonGo.RocketAPI
 {
     public class Client
     {
-        public ISettings Settings { get; }
         private readonly HttpClient _httpClient;
-        private AuthType _authType = AuthType.Google;
-        public string AccessToken { get; set; }
         private string _apiUrl;
+        private AuthType _authType = AuthType.Google;
         private Request.Types.UnknownAuth _unknownAuth;

-        public double CurrentLat { get; private set; }
-        public double CurrentLng { get; private set; }
-        public double CurrentAltitude { get; private set; }
-
         public Client(ISettings settings)
         {
             Settings = settings;
@@ -47,11 +41,23 @@ namespace PokemonGo.RocketAPI
                 var latlngFromFile = File.ReadAllText(path + filename);
                 var latlng = latlngFromFile.Split(':');
                 double latitude, longitude;
-                if ((latlng[0].Length > 0 && double.TryParse(latlng[0], out latitude) && latitude >= -90.0 && latitude <= 90.0) && (latlng[1].Length > 0 && double.TryParse(latlng[1], out longitude) && longitude >= -180.0 && longitude <= 180.0))
+                if (latlng[0].Length != 0 && latlng[1].Length != 0)
                 {
                     try
                     {
-                        SetCoordinates(latitude, longitude, Settings.DefaultAltitude);
+                        double temp_lat = Convert.ToDouble(latlng[0]);
+                        double temp_long = Convert.ToDouble(latlng[1]);
+
+                        if (temp_lat >= -90 && temp_lat <= 90 && temp_long >= -180 && temp_long <= 180)
+                        {
+                            SetCoordinates(Convert.ToDouble(latlng[0]), Convert.ToDouble(latlng[1]),
+                            Settings.DefaultAltitude);
+                        }
+                        else
+                        {
+                            Logger.Error("Coordinates in \"Configs\\Coords.txt\" file is invalid, using the default coordinates");
+                            SetCoordinates(Settings.DefaultLatitude, Settings.DefaultLongitude, Settings.DefaultAltitude);
+                        }
                     }
                     catch (FormatException)
                     {
@@ -71,14 +77,14 @@ namespace PokemonGo.RocketAPI
             }

             //Setup HttpClient and create default headers
-            HttpClientHandler handler = new HttpClientHandler()
+            var handler = new HttpClientHandler
             {
                 AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                 AllowAutoRedirect = false
             };
             _httpClient = new HttpClient(new RetryHandler(handler));
             _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Niantic App");
-                //"Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G900F Build/LMY48G)");
+            //"Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G900F Build/LMY48G)");
             _httpClient.DefaultRequestHeaders.ExpectContinue = false;
             _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Connection", "keep-alive");
             _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "*/*");
@@ -86,18 +92,37 @@ namespace PokemonGo.RocketAPI
                 "application/x-www-form-urlencoded");
         }

-        public void SaveLatLng(double lat, double lng)
-        {
-            string latlng = lat.ToString() + ":" + lng.ToString();
-            File.WriteAllText(Directory.GetCurrentDirectory() + "\\Configs\\LastCoords.txt", latlng);
-        }
+        public ISettings Settings { get; }
+        public string AccessToken { get; set; }

-        private void SetCoordinates(double lat, double lng, double altitude)
+        public double CurrentLat { get; private set; }
+        public double CurrentLng { get; private set; }
+        public double CurrentAltitude { get; private set; }
+
+        public async Task<CatchPokemonResponse> CatchPokemon(ulong encounterId, string spawnPointGuid, double pokemonLat,
+    double pokemonLng, MiscEnums.Item pokeball)
         {
-            CurrentLat = lat;
-            CurrentLng = lng;
-            CurrentAltitude = altitude;
-            SaveLatLng(lat, lng);
+
+            var customRequest = new Request.Types.CatchPokemonRequest
+            {
+                EncounterId = encounterId,
+                Pokeball = (int)pokeball,
+                SpawnPointGuid = spawnPointGuid,
+                HitPokemon = 1,
+                NormalizedReticleSize = Utils.FloatAsUlong(1.950),
+                SpinModifier = Utils.FloatAsUlong(1),
+                NormalizedHitPosition = Utils.FloatAsUlong(1)
+            };
+
+            var catchPokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
+                {
+                    Type = (int)RequestType.CATCH_POKEMON,
+                    Message = customRequest.ToByteString()
+                });
+            return
+                await
+                    _httpClient.PostProtoPayload<Request, CatchPokemonResponse>($"https://{_apiUrl}/rpc", catchPokemonRequest);
         }

         public async Task DoGoogleLogin()
@@ -116,79 +141,80 @@ namespace PokemonGo.RocketAPI
                 var deviceCode = await GoogleLogin.GetDeviceCode();
                 tokenResponse = await GoogleLogin.GetAccessToken(deviceCode);
                 Settings.GoogleRefreshToken = tokenResponse?.refresh_token;
+                Logger.Normal("Refreshtoken " + tokenResponse?.refresh_token + " saved");
                 AccessToken = tokenResponse?.id_token;
             }

         }

-        /// <summary>
-        /// For GUI clients only. GUI clients don't use the DoGoogleLogin, but call the GoogleLogin class directly
-        /// </summary>
-        /// <param name="type"></param>
-        public void SetAuthType(AuthType type)
-        {
-            _authType = type;
-        }
-
         public async Task DoPtcLogin(string username, string password)
         {
             AccessToken = await PtcLogin.GetAccessToken(username, password);
             _authType = AuthType.Ptc;
         }

-        public async Task<PlayerUpdateResponse> UpdatePlayerLocation(double lat, double lng, double alt)
+        public async Task<EncounterResponse> EncounterPokemon(ulong encounterId, string spawnPointGuid)
         {
-            this.SetCoordinates(lat, lng, alt);
-            var customRequest = new Request.Types.PlayerUpdateProto()
+            var customRequest = new Request.Types.EncounterRequest
             {
-                Lat = Utils.FloatAsUlong(CurrentLat),
-                Lng = Utils.FloatAsUlong(CurrentLng)
+                EncounterId = encounterId,
+                SpawnpointId = spawnPointGuid,
+                PlayerLatDegrees = Utils.FloatAsUlong(CurrentLat),
+                PlayerLngDegrees = Utils.FloatAsUlong(CurrentLng)
             };

-            var updateRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+            var encounterResponse = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
                 {
-                    Type = (int)RequestType.PLAYER_UPDATE,
+                    Type = (int)RequestType.ENCOUNTER,
                     Message = customRequest.ToByteString()
                 });
-            var updateResponse =
-                await
-                    _httpClient.PostProtoPayload<Request, PlayerUpdateResponse>($"https://{_apiUrl}/rpc", updateRequest);
-            return updateResponse;
+            return await _httpClient.PostProtoPayload<Request, EncounterResponse>($"https://{_apiUrl}/rpc", encounterResponse);
         }

-        public async Task SetServer()
+        public async Task<EvolvePokemonOut> EvolvePokemon(ulong pokemonId)
         {
-            var serverRequest = RequestBuilder.GetInitialRequest(AccessToken, _authType, CurrentLat, CurrentLng, CurrentAltitude,
-                RequestType.GET_PLAYER, RequestType.GET_HATCHED_OBJECTS, RequestType.GET_INVENTORY,
-                RequestType.CHECK_AWARDED_BADGES, RequestType.DOWNLOAD_SETTINGS);
-            var serverResponse = await _httpClient.PostProto<Request>(Resources.RpcUrl, serverRequest);
-
-            if (serverResponse.Auth == null)
-                throw new AccessTokenExpiredException();
-
-            _unknownAuth = new Request.Types.UnknownAuth()
+            var customRequest = new EvolvePokemon
             {
-                Unknown71 = serverResponse.Auth.Unknown71,
-                Timestamp = serverResponse.Auth.Timestamp,
-                Unknown73 = serverResponse.Auth.Unknown73,
+                PokemonId = pokemonId
             };

-            _apiUrl = serverResponse.ApiUrl;
+            var releasePokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
+                {
+                    Type = (int)RequestType.EVOLVE_POKEMON,
+                    Message = customRequest.ToByteString()
+                });
+            return
+                await
+                    _httpClient.PostProtoPayload<Request, EvolvePokemonOut>($"https://{_apiUrl}/rpc", releasePokemonRequest);
         }

-        public async Task<GetPlayerResponse> GetProfile()
+        public async Task<FortDetailsResponse> GetFort(string fortId, double fortLat, double fortLng)
         {
-            var profileRequest = RequestBuilder.GetInitialRequest(AccessToken, _authType, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests() { Type = (int)RequestType.GET_PLAYER });
-            return await _httpClient.PostProtoPayload<Request, GetPlayerResponse>($"https://{_apiUrl}/rpc", profileRequest);
+            var customRequest = new Request.Types.FortDetailsRequest
+            {
+                Id = ByteString.CopyFromUtf8(fortId),
+                Latitude = Utils.FloatAsUlong(fortLat),
+                Longitude = Utils.FloatAsUlong(fortLng)
+            };
+
+            var fortDetailRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
+                {
+                    Type = (int)RequestType.FORT_DETAILS,
+                    Message = customRequest.ToByteString()
+                });
+            return
+                await
+                    _httpClient.PostProtoPayload<Request, FortDetailsResponse>($"https://{_apiUrl}/rpc",
+                        fortDetailRequest);
         }

-        public async Task<DownloadSettingsResponse> GetSettings()
+        public async Task<GetInventoryResponse> GetInventory()
         {
-            var settingsRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                RequestType.DOWNLOAD_SETTINGS);
-            return await _httpClient.PostProtoPayload<Request, DownloadSettingsResponse>($"https://{_apiUrl}/rpc", settingsRequest);
+            var inventoryRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude, RequestType.GET_INVENTORY);
+            return await _httpClient.PostProtoPayload<Request, GetInventoryResponse>($"https://{_apiUrl}/rpc", inventoryRequest);
         }

         public async Task<DownloadItemTemplatesResponse> GetItemTemplates()
@@ -201,11 +227,9 @@ namespace PokemonGo.RocketAPI
                         settingsRequest);
         }

-
-
         public async Task<GetMapObjectsResponse> GetMapObjects()
         {
-            var customRequest = new Request.Types.MapObjectsRequest()
+            var customRequest = new Request.Types.MapObjectsRequest
             {
                 CellIds =
                     ByteString.CopyFrom(
@@ -217,23 +241,23 @@ namespace PokemonGo.RocketAPI
             };

             var mapRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+                new Request.Types.Requests
                 {
                     Type = (int)RequestType.GET_MAP_OBJECTS,
                     Message = customRequest.ToByteString()
                 },
-                new Request.Types.Requests() { Type = (int)RequestType.GET_HATCHED_OBJECTS },
-                new Request.Types.Requests()
+                new Request.Types.Requests { Type = (int)RequestType.GET_HATCHED_OBJECTS },
+                new Request.Types.Requests
                 {
                     Type = (int)RequestType.GET_INVENTORY,
-                    Message = new Request.Types.Time() { Time_ = DateTime.UtcNow.ToUnixTime() }.ToByteString()
+                    Message = new Request.Types.Time() {Time_ = DateTime.UtcNow.ToUnixTime()}.ToByteString()
                 },
                 new Request.Types.Requests() { Type = (int)RequestType.CHECK_AWARDED_BADGES },
                 new Request.Types.Requests()
                 {
                     Type = (int)RequestType.DOWNLOAD_SETTINGS,
                     Message =
-                        new Request.Types.SettingsGuid()
+                        new Request.Types.SettingsGuid
                         {
                             Guid = ByteString.CopyFromUtf8("4a2e9bc330dae60e7b74fc85b98868ab4700802e")
                         }.ToByteString()
@@ -242,27 +266,46 @@ namespace PokemonGo.RocketAPI
             return await _httpClient.PostProtoPayload<Request, GetMapObjectsResponse>($"https://{_apiUrl}/rpc", mapRequest);
         }

-        public async Task<FortDetailsResponse> GetFort(string fortId, double fortLat, double fortLng)
+        public async Task<GetPlayerResponse> GetProfile()
+        {
+            var profileRequest = RequestBuilder.GetInitialRequest(AccessToken, _authType, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests { Type = (int)RequestType.GET_PLAYER });
+            return await _httpClient.PostProtoPayload<Request, GetPlayerResponse>($"https://{_apiUrl}/rpc", profileRequest);
+        }
+
+        public async Task<DownloadSettingsResponse> GetSettings()
         {
-            var customRequest = new Request.Types.FortDetailsRequest()
+            var settingsRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                RequestType.DOWNLOAD_SETTINGS);
+            return await _httpClient.PostProtoPayload<Request, DownloadSettingsResponse>($"https://{_apiUrl}/rpc", settingsRequest);
+        }
+
+        public async Task<RecycleInventoryItemResponse> RecycleItem(ItemId itemId, int amount)
+        {
+            var customRequest = new RecycleInventoryItem
             {
-                Id = ByteString.CopyFromUtf8(fortId),
-                Latitude = Utils.FloatAsUlong(fortLat),
-                Longitude = Utils.FloatAsUlong(fortLng),
+                ItemId = (ItemId)Enum.Parse(typeof(ItemId), itemId.ToString()),
+                Count = amount
             };

-            var fortDetailRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+            var releasePokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
                 {
-                    Type = (int)RequestType.FORT_DETAILS,
+                    Type = (int)RequestType.RECYCLE_INVENTORY_ITEM,
                     Message = customRequest.ToByteString()
                 });
-            return await _httpClient.PostProtoPayload<Request, FortDetailsResponse>($"https://{_apiUrl}/rpc", fortDetailRequest);
+            return await _httpClient.PostProtoPayload<Request, RecycleInventoryItemResponse>($"https://{_apiUrl}/rpc", releasePokemonRequest);
+        }
+
+        public void SaveLatLng(double lat, double lng)
+        {
+            var latlng = lat + ":" + lng;
+            File.WriteAllText(Directory.GetCurrentDirectory() + "\\Coords.txt", latlng);
         }

         public async Task<FortSearchResponse> SearchFort(string fortId, double fortLat, double fortLng)
         {
-            var customRequest = new Request.Types.FortSearchRequest()
+            var customRequest = new Request.Types.FortSearchRequest
             {
                 Id = ByteString.CopyFromUtf8(fortId),
                 FortLatDegrees = Utils.FloatAsUlong(fortLat),
@@ -272,75 +315,54 @@ namespace PokemonGo.RocketAPI
             };

             var fortDetailRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+                new Request.Types.Requests
                 {
                     Type = (int)RequestType.FORT_SEARCH,
                     Message = customRequest.ToByteString()
                 });
-            return await _httpClient.PostProtoPayload<Request, FortSearchResponse>($"https://{_apiUrl}/rpc", fortDetailRequest);
+            return
+                await
+                    _httpClient.PostProtoPayload<Request, FortSearchResponse>($"https://{_apiUrl}/rpc",
+                        fortDetailRequest);
         }

-        public async Task<EncounterResponse> EncounterPokemon(ulong encounterId, string spawnPointGuid)
+        /// <summary>
+        /// For GUI clients only. GUI clients don't use the DoGoogleLogin, but call the GoogleLogin class directly
+        /// </summary>
+        /// <param name="type"></param>
+        public void SetAuthType(AuthType type)
         {
-            var customRequest = new Request.Types.EncounterRequest()
-            {
-                EncounterId = encounterId,
-                SpawnpointId = spawnPointGuid,
-                PlayerLatDegrees = Utils.FloatAsUlong(CurrentLat),
-                PlayerLngDegrees = Utils.FloatAsUlong(CurrentLng)
-            };
-
-            var encounterResponse = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
-                {
-                    Type = (int)RequestType.ENCOUNTER,
-                    Message = customRequest.ToByteString()
-                });
-            return await _httpClient.PostProtoPayload<Request, EncounterResponse>($"https://{_apiUrl}/rpc", encounterResponse);
+            _authType = type;
         }

-        public async Task<UseItemCaptureRequest> UseCaptureItem(ulong encounterId, ItemId itemId, string spawnPointGuid)
+        private void SetCoordinates(double lat, double lng, double altitude)
         {
-            var customRequest = new UseItemCaptureRequest
-            {
-                EncounterId = encounterId,
-                ItemId = itemId,
-                SpawnPointGuid = spawnPointGuid
-            };
+            if (double.IsNaN(lat) || double.IsNaN(lng)) return;

-            var useItemRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
-                {
-                    Type = (int)RequestType.USE_ITEM_CAPTURE,
-                    Message = customRequest.ToByteString()
-                });
-            return await _httpClient.PostProtoPayload<Request, UseItemCaptureRequest>($"https://{_apiUrl}/rpc", useItemRequest);
+            CurrentLat = lat;
+            CurrentLng = lng;
+            CurrentAltitude = altitude;
+            SaveLatLng(lat, lng);
         }

-        public async Task<CatchPokemonResponse> CatchPokemon(ulong encounterId, string spawnPointGuid, double pokemonLat,
-            double pokemonLng, MiscEnums.Item pokeball)
+        public async Task SetServer()
         {
+            var serverRequest = RequestBuilder.GetInitialRequest(AccessToken, _authType, CurrentLat, CurrentLng, CurrentAltitude,
+                RequestType.GET_PLAYER, RequestType.GET_HATCHED_OBJECTS, RequestType.GET_INVENTORY,
+                RequestType.CHECK_AWARDED_BADGES, RequestType.DOWNLOAD_SETTINGS);
+            var serverResponse = await _httpClient.PostProto(Resources.RpcUrl, serverRequest);

-            var customRequest = new Request.Types.CatchPokemonRequest()
+            if (serverResponse.Auth == null)
+                throw new AccessTokenExpiredException();
+
+            _unknownAuth = new Request.Types.UnknownAuth
             {
-                EncounterId = encounterId,
-                Pokeball = (int)pokeball,
-                SpawnPointGuid = spawnPointGuid,
-                HitPokemon = 1,
-                NormalizedReticleSize = Utils.FloatAsUlong(1.950),
-                SpinModifier = Utils.FloatAsUlong(1),
-                NormalizedHitPosition = Utils.FloatAsUlong(1)
+                Unknown71 = serverResponse.Auth.Unknown71,
+                Timestamp = serverResponse.Auth.Timestamp,
+                Unknown73 = serverResponse.Auth.Unknown73
             };

-            var catchPokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
-                {
-                    Type = (int)RequestType.CATCH_POKEMON,
-                    Message = customRequest.ToByteString()
-                });
-            return
-                await
-                    _httpClient.PostProtoPayload<Request, CatchPokemonResponse>($"https://{_apiUrl}/rpc", catchPokemonRequest);
+            _apiUrl = serverResponse.ApiUrl;
         }

         public async Task<TransferPokemonOut> TransferPokemon(ulong pokemonId)
@@ -351,7 +373,7 @@ namespace PokemonGo.RocketAPI
             };

             var releasePokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+                new Request.Types.Requests
                 {
                     Type = (int)RequestType.RELEASE_POKEMON,
                     Message = customRequest.ToByteString()
@@ -359,45 +381,44 @@ namespace PokemonGo.RocketAPI
             return await _httpClient.PostProtoPayload<Request, TransferPokemonOut>($"https://{_apiUrl}/rpc", releasePokemonRequest);
         }

-        public async Task<EvolvePokemonOut> EvolvePokemon(ulong pokemonId)
+        public async Task<PlayerUpdateResponse> UpdatePlayerLocation(double lat, double lng, double alt)
         {
-            var customRequest = new EvolvePokemon
+            SetCoordinates(lat, lng, alt);
+            var customRequest = new Request.Types.PlayerUpdateProto
             {
-                PokemonId = pokemonId
+                Lat = Utils.FloatAsUlong(CurrentLat),
+                Lng = Utils.FloatAsUlong(CurrentLng)
             };

-            var releasePokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+            var updateRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
                 {
-                    Type = (int)RequestType.EVOLVE_POKEMON,
+                    Type = (int)RequestType.PLAYER_UPDATE,
                     Message = customRequest.ToByteString()
                 });
-            return
+            var updateResponse =
                 await
-                    _httpClient.PostProtoPayload<Request, EvolvePokemonOut>($"https://{_apiUrl}/rpc", releasePokemonRequest);
-        }
-
-        public async Task<GetInventoryResponse> GetInventory()
-        {
-            var inventoryRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude, RequestType.GET_INVENTORY);
-            return await _httpClient.PostProtoPayload<Request, GetInventoryResponse>($"https://{_apiUrl}/rpc", inventoryRequest);
+                    _httpClient.PostProtoPayload<Request, PlayerUpdateResponse>($"https://{_apiUrl}/rpc", updateRequest);
+            return updateResponse;
         }

-        public async Task<RecycleInventoryItemResponse> RecycleItem(ItemId itemId, int amount)
+        public async Task<UseItemCaptureRequest> UseCaptureItem(ulong encounterId, ItemId itemId, string spawnPointGuid)
         {
-            var customRequest = new RecycleInventoryItem
+            var customRequest = new UseItemCaptureRequest
             {
-                ItemId = (ItemId)Enum.Parse(typeof(ItemId), itemId.ToString()),
-                Count = amount
+                EncounterId = encounterId,
+                ItemId = itemId,
+                SpawnPointGuid = spawnPointGuid
             };

-            var releasePokemonRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
-                new Request.Types.Requests()
+            var useItemRequest = RequestBuilder.GetRequest(_unknownAuth, CurrentLat, CurrentLng, CurrentAltitude,
+                new Request.Types.Requests
                 {
-                    Type = (int)RequestType.RECYCLE_INVENTORY_ITEM,
+                    Type = (int)RequestType.USE_ITEM_CAPTURE,
                     Message = customRequest.ToByteString()
                 });
-            return await _httpClient.PostProtoPayload<Request, RecycleInventoryItemResponse>($"https://{_apiUrl}/rpc", releasePokemonRequest);
+            return await _httpClient.PostProtoPayload<Request, UseItemCaptureRequest>($"https://{_apiUrl}/rpc", useItemRequest);
         }
+
     }
 }
diff --git a/PokemonGo.RocketAPI/Login/PtcLogin.cs b/PokemonGo.RocketAPI/Login/PtcLogin.cs
index 19f5078..d1c7e25 100644
--- a/PokemonGo.RocketAPI/Login/PtcLogin.cs
+++ b/PokemonGo.RocketAPI/Login/PtcLogin.cs
@@ -29,7 +29,7 @@ namespace PokemonGo.RocketAPI.Login
                 var data = await sessionResp.Content.ReadAsStringAsync();
                 if (data == null) throw new PtcOfflineException();

-                if (sessionResp.StatusCode == HttpStatusCode.InternalServerError || data.Contains("<title>Maintenance"))
+                if (sessionResp.StatusCode == HttpStatusCode.InternalServerError)
                     throw new PtcOfflineException();

                 var lt = JsonHelper.GetValue(data, "lt");
@@ -48,7 +48,14 @@ namespace PokemonGo.RocketAPI.Login
                         }));

                 if (loginResp.Headers.Location == null)
+                {
+                    //This should be sufficient for catching AccountNotVerified exceptions
+                    if (loginResp.StatusCode == HttpStatusCode.OK && !loginResp.Headers.Contains("Set-Cookies"))
+                        throw new AccountNotVerifiedException();
+
                     throw new PtcOfflineException();
+                }
+

                 var ticketId = HttpUtility.ParseQueryString(loginResp.Headers.Location.Query)["ticket"];
                 if (ticketId == null)
diff --git a/PokemonGo.RocketAPI/PokemonGo.RocketAPI.csproj b/PokemonGo.RocketAPI/PokemonGo.RocketAPI.csproj
index e6b8ae8..dc246d9 100644
--- a/PokemonGo.RocketAPI/PokemonGo.RocketAPI.csproj
+++ b/PokemonGo.RocketAPI/PokemonGo.RocketAPI.csproj
@@ -17,7 +17,7 @@
     <UpdateAssemblyInfoVersion>False</UpdateAssemblyInfoVersion>
     <AssemblyVersionSettings>YearStamp.MonthStamp.DayStamp.Increment</AssemblyVersionSettings>
     <PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
-    <AssemblyVersion>2016.7.23.159</AssemblyVersion>
+    <AssemblyVersion>2016.7.23.163</AssemblyVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
diff --git a/PokemonGo.RocketAPI/Properties/AssemblyInfo.cs b/PokemonGo.RocketAPI/Properties/AssemblyInfo.cs
index 3273a9e..483916f 100644
--- a/PokemonGo.RocketAPI/Properties/AssemblyInfo.cs
+++ b/PokemonGo.RocketAPI/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2016.7.23.159")]
+[assembly: AssemblyVersion("2016.7.23.163")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PokemonGo.RocketAPI/Proto/AllEnum.proto b/PokemonGo.RocketAPI/Proto/AllEnum.proto
index c32bf55..47aed32 100644
--- a/PokemonGo.RocketAPI/Proto/AllEnum.proto
+++ b/PokemonGo.RocketAPI/Proto/AllEnum.proto
@@ -1,6 +1,7 @@
 syntax = "proto3";

 package AllEnum;
+option csharp_namespace = "PokemonGo.RocketAPI.GeneratedCode";

 enum RpcDirection {
   UNKNOWN = 0;
You may download the files in Public Git.