예제 #1
0
        // TODO: Reimplement
        #region Unused assets code
        //        public async Task<GetAssetDigestResponse> GetAssetsAsync()
        //        {
        //            // check if template cache has been set
        //
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            // TODO: the timestamp comparisons seem to be used for determining if the stored data is invalid and needs refreshed,
        //            //       however, looking at this code I'm not sure it's implemented correctly - or if these refactors still match the behavior of
        //            //       the previous code... same concern with the next method GetItemTemplates()..
        //
        //            var cachedMsg = _session.DataCache.GetCachedAssetDigest();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var assetDigestResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.GetAssetDigest,
        //                    RequestMessage = new GetAssetDigestMessage
        //                    {
        //                        Platform = Platform.Android,
        //                        AppVersion = 2903
        //                    }.ToByteString()
        //                });
        //                var msg = GetAssetDigestResponse.Parser.ParseFrom(assetDigestResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.AssetDigestFile, msg);
        //                return msg;
        //            }
        //        }
        //
        //        public async Task<DownloadItemTemplatesResponse> GetItemTemplatesAsync()
        //        {
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            var cachedMsg = _session.DataCache.GetCachedItemTemplates();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var itemTemplateResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.DownloadItemTemplates
        //                });
        //                var msg = DownloadItemTemplatesResponse.Parser.ParseFrom(itemTemplateResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.ItemTemplatesFile, msg);
        //                return msg;
        //            }
        //        }
        #endregion

        /// <summary>
        ///     It is not recommended to call this. Map objects will update automatically and fire the map update event.
        /// </summary>
        public async Task RefreshMapObjectsAsync()
        {
            var cellIds     = MapUtil.GetCellIdsForLatLong(_session.Player.Coordinate.Latitude, _session.Player.Coordinate.Longitude);
            var sinceTimeMs = new List <long>(cellIds.Length);

            foreach (var cellId in cellIds)
            {
                var cell = _session.Map.Cells.FirstOrDefault(x => x.S2CellId == cellId);

                // TODO: Using the cells' currenttimestamp gives a delta, which is probably better, but we need to merge the result with the existing ones
                //sinceTimeMs.Add(cell?.CurrentTimestampMs ?? 0);
                sinceTimeMs.Add(0);
            }

            var response = await SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = new GetMapObjectsMessage
                {
                    CellId =
                    {
                        cellIds
                    },
                    SinceTimestampMs =
                    {
                        sinceTimeMs.ToArray()
                    },
                    Latitude  = _session.Player.Coordinate.Latitude,
                    Longitude = _session.Player.Coordinate.Longitude
                }.ToByteString()
            });

            var mapObjects = GetMapObjectsResponse.Parser.ParseFrom(response);

            if (mapObjects.Status == MapObjectsStatus.Success)
            {
                // TODO: Cleaner?
                var pokemonCatchable = mapObjects.MapCells.SelectMany(c => c.CatchablePokemons).Count();
                var pokemonWild      = mapObjects.MapCells.SelectMany(c => c.WildPokemons).Count();
                var pokemonNearby    = mapObjects.MapCells.SelectMany(c => c.NearbyPokemons).Count();
                var pokemonCount     = pokemonCatchable + pokemonWild + pokemonNearby;

                Logger.Debug($"Received '{mapObjects.MapCells.Count}' map cells.");
                Logger.Debug($"Received '{pokemonCount}' pokemons. Catchable({pokemonCatchable}) Wild({pokemonWild}) Nearby({pokemonNearby})");
                Logger.Debug($"Received '{mapObjects.MapCells.SelectMany(c => c.Forts).Count()}' forts.");

                if (mapObjects.MapCells.Count == 0)
                {
                    Logger.Error("We received 0 map cells, are your GPS coordinates correct?");
                    return;
                }

                _session.Map.Cells = mapObjects.MapCells;
            }
            else
            {
                Logger.Error($"GetMapObjects status is: '{mapObjects.Status}'.");
            }
        }
예제 #2
0
        // TODO: Reimplement
        #region Unused assets code
        //        public async Task<GetAssetDigestResponse> GetAssetsAsync()
        //        {
        //            // check if template cache has been set
        //
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            // TODO: the timestamp comparisons seem to be used for determining if the stored data is invalid and needs refreshed,
        //            //       however, looking at this code I'm not sure it's implemented correctly - or if these refactors still match the behavior of
        //            //       the previous code... same concern with the next method GetItemTemplates()..
        //
        //            var cachedMsg = _session.DataCache.GetCachedAssetDigest();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var assetDigestResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.GetAssetDigest,
        //                    RequestMessage = new GetAssetDigestMessage
        //                    {
        //                        Platform = Platform.Android,
        //                        AppVersion = 2903
        //                    }.ToByteString()
        //                });
        //                var msg = GetAssetDigestResponse.Parser.ParseFrom(assetDigestResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.AssetDigestFile, msg);
        //                return msg;
        //            }
        //        }
        //
        //        public async Task<DownloadItemTemplatesResponse> GetItemTemplatesAsync()
        //        {
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            var cachedMsg = _session.DataCache.GetCachedItemTemplates();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var itemTemplateResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.DownloadItemTemplates
        //                });
        //                var msg = DownloadItemTemplatesResponse.Parser.ParseFrom(itemTemplateResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.ItemTemplatesFile, msg);
        //                return msg;
        //            }
        //        }
        #endregion

        /// <summary>
        ///     It is not recommended to call this. Map objects will update automatically and fire the map update event.
        /// </summary>
        public async Task RefreshMapObjectsAsync()
        {
            var cellIds     = MapUtil.GetCellIdsForLatLong(_session.Player.Coordinate.Latitude, _session.Player.Coordinate.Longitude);
            var sinceTimeMs = cellIds.Select(x => (long)0).ToArray();

            var response = await SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = new GetMapObjectsMessage
                {
                    CellId =
                    {
                        cellIds
                    },
                    SinceTimestampMs =
                    {
                        sinceTimeMs
                    },
                    Latitude  = _session.Player.Coordinate.Latitude,
                    Longitude = _session.Player.Coordinate.Longitude
                }.ToByteString()
            });

            if (response != null)
            {
                var mapObjects = GetMapObjectsResponse.Parser.ParseFrom(response);
                if (mapObjects.Status == MapObjectsStatus.Success)
                {
                    // TODO: Cleaner?
                    var pokemonCatchable = mapObjects.MapCells.SelectMany(c => c.CatchablePokemons).Count();
                    var pokemonWild      = mapObjects.MapCells.SelectMany(c => c.WildPokemons).Count();
                    var pokemonNearby    = mapObjects.MapCells.SelectMany(c => c.NearbyPokemons).Count();
                    var pokemonCount     = pokemonCatchable + pokemonWild + pokemonNearby;

                    Logger.Debug($"Received '{mapObjects.MapCells.Count}' map cells.");
                    Logger.Debug($"Received '{pokemonCount}' pokemons. Catchable({pokemonCatchable}) Wild({pokemonWild}) Nearby({pokemonNearby})");
                    Logger.Debug($"Received '{mapObjects.MapCells.SelectMany(c => c.Forts).Count()}' forts.");

                    if (mapObjects.MapCells.Count == 0)
                    {
                        Logger.Error("We received 0 map cells, are your GPS coordinates correct?");
                        return;
                    }

                    _session.Map.Cells = mapObjects.MapCells;
                }
                else
                {
                    Logger.Error($"GetMapObjects status is: '{mapObjects.Status}'.");
                }
            }
            else if (_session.State != SessionState.Paused)
            {
                // POGOLib didn't expect this.
                throw new NullReferenceException(nameof(response));
            }
        }
예제 #3
0
        // TODO: Reimplement
        #region Unused assets code
        //        public async Task<GetAssetDigestResponse> GetAssetsAsync()
        //        {
        //            // check if template cache has been set
        //
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            // TODO: the timestamp comparisons seem to be used for determining if the stored data is invalid and needs refreshed,
        //            //       however, looking at this code I'm not sure it's implemented correctly - or if these refactors still match the behavior of
        //            //       the previous code... same concern with the next method GetItemTemplates()..
        //
        //            var cachedMsg = _session.DataCache.GetCachedAssetDigest();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var assetDigestResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.GetAssetDigest,
        //                    RequestMessage = new GetAssetDigestMessage
        //                    {
        //                        Platform = Platform.Android,
        //                        AppVersion = 2903
        //                    }.ToByteString()
        //                });
        //                var msg = GetAssetDigestResponse.Parser.ParseFrom(assetDigestResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.AssetDigestFile, msg);
        //                return msg;
        //            }
        //        }
        //
        //        public async Task<DownloadItemTemplatesResponse> GetItemTemplatesAsync()
        //        {
        //            // Get DownloadRemoteConfig
        //            var remoteConfigResponse = await SendRemoteProcedureCallAsync(new Request
        //            {
        //                RequestType = RequestType.DownloadRemoteConfigVersion,
        //                RequestMessage = new DownloadRemoteConfigVersionMessage
        //                {
        //                    Platform = Platform.Android,
        //                    AppVersion = 2903
        //                }.ToByteString()
        //            });
        //
        //            var remoteConfigParsed = DownloadRemoteConfigVersionResponse.Parser.ParseFrom(remoteConfigResponse);
        //            var timestamp = (ulong) TimeUtil.GetCurrentTimestampInMilliseconds();
        //
        //            var cachedMsg = _session.DataCache.GetCachedItemTemplates();
        //            if (cachedMsg != null && remoteConfigParsed.AssetDigestTimestampMs <= timestamp)
        //            {
        //                return cachedMsg;
        //            }
        //            else
        //            {
        //                // GetAssetDigest
        //                var itemTemplateResponse = await SendRemoteProcedureCallAsync(new Request
        //                {
        //                    RequestType = RequestType.DownloadItemTemplates
        //                });
        //                var msg = DownloadItemTemplatesResponse.Parser.ParseFrom(itemTemplateResponse);
        //                _session.DataCache.SaveData(DataCacheExtensions.ItemTemplatesFile, msg);
        //                return msg;
        //            }
        //        }
        #endregion

        /// <summary>
        ///     It is not recommended to call this. Map objects will update automatically and fire the map update event.
        /// </summary>
        public async Task RefreshMapObjectsAsync()
        {
            var cellIds     = MapUtil.GetCellIdsForLatLong(_session.Player.Coordinate.Latitude, _session.Player.Coordinate.Longitude);
            var sinceTimeMs = new List <long>(cellIds.Length);

            for (var i = 0; i < cellIds.Length; i++)
            {
                sinceTimeMs.Add(0);
            }

            var response = await SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = new GetMapObjectsMessage
                {
                    CellId =
                    {
                        cellIds
                    },
                    SinceTimestampMs =
                    {
                        sinceTimeMs.ToArray()
                    },
                    Latitude  = _session.Player.Coordinate.Latitude,
                    Longitude = _session.Player.Coordinate.Longitude
                }.ToByteString()
            });

            var mapObjects = GetMapObjectsResponse.Parser.ParseFrom(response);

            if (mapObjects.Status == MapObjectsStatus.Success)
            {
                // TODO: Cleaner?
                var pokemonCatchable = mapObjects.MapCells.SelectMany(c => c.CatchablePokemons).Count();
                var pokemonWild      = mapObjects.MapCells.SelectMany(c => c.WildPokemons).Count();
                var pokemonNearby    = mapObjects.MapCells.SelectMany(c => c.NearbyPokemons).Count();
                var pokemonCount     = pokemonCatchable + pokemonWild + pokemonNearby;

                Logger.Debug($"Received '{mapObjects.MapCells.Count}' map cells.");
                Logger.Debug($"Received '{pokemonCount}' pokemons. Catchable({pokemonCatchable}) Wild({pokemonWild}) Nearby({pokemonNearby})");
                Logger.Debug($"Received '{mapObjects.MapCells.SelectMany(c => c.Forts).Count()}' forts.");

                if (mapObjects.MapCells.Count == 0)
                {
                    Logger.Error("We received 0 map cells, are your GPS coordinates correct?");
                    return;
                }

                _session.Map.Cells = mapObjects.MapCells;
            }
            else
            {
                Logger.Error($"GetMapObjects status is: '{mapObjects.Status}'.");
            }
        }
예제 #4
0
        private static RepeatedField <MapCell> SendMapRequest(Credentials credentials, Location location)
        {
            RepeatedField <MapCell> mapCells = null;

            try
            {
                // TODO: Check for reauth here?
                Session session = credentials.Session;

                // set copy position
                session.Player.SetCoordinates(location.Latitude, location.Longitude);


                var cellIds = MapUtil.GetCellIdsForLatLong(session.Player.Latitude,
                                                           session.Player.Longitude);

                var sinceTimeMs = new List <long>(cellIds.Length);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                var response = session.RpcClient.SendRemoteProcedureCall(new Request
                {
                    RequestType    = RequestType.GetMapObjects,
                    RequestMessage = new GetMapObjectsMessage
                    {
                        CellId =
                        {
                            cellIds
                        },
                        SinceTimestampMs =
                        {
                            sinceTimeMs.ToArray()
                        },
                        Latitude  = session.Player.Latitude,
                        Longitude = session.Player.Longitude
                    }.ToByteString()
                });
                stopwatch.Stop();
                Log($"Map request took {stopwatch.ElapsedMilliseconds / 1000.0} seconds");


                var mapResponse = GetMapObjectsResponse.Parser.ParseFrom(response);

                mapCells = mapResponse.MapCells;
            } catch (Exception e)
            {
                Log($"Uncaught exception when downloading map {e.ToString()}");
            }

            return(mapCells);
        }
예제 #5
0
        /// <summary>
        ///     It is not recommended to call this. Map objects will update automatically and fire the <see cref="Map.Update" />
        ///     event.
        /// </summary>
        public void RefreshMapObjects()
        {
            var cellIds = MapUtil.GetCellIdsForLatLong(_session.Player.Coordinate.Latitude,
                                                       _session.Player.Coordinate.Longitude);
            var sinceTimeMs = new List <long>(cellIds.Length);

            for (var i = 0; i < cellIds.Length; i++)
            {
                sinceTimeMs.Add(0);
            }

            var response = SendRemoteProcedureCall(new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = new GetMapObjectsMessage
                {
                    CellId =
                    {
                        cellIds
                    },
                    SinceTimestampMs =
                    {
                        sinceTimeMs.ToArray()
                    },
                    Latitude  = _session.Player.Coordinate.Latitude,
                    Longitude = _session.Player.Coordinate.Longitude
                }.ToByteString()
            });

            var mapObjects = GetMapObjectsResponse.Parser.ParseFrom(response);

            if (mapObjects.Status == MapObjectsStatus.Success)
            {
                Log.Debug($"Received '{mapObjects.MapCells.Count}' map cells.");
                if (mapObjects.MapCells.Count == 0)
                {
                    Log.Error("We received 0 map cells, are your GPS coordinates correct?");
                    return;
                }
                _session.Map.Cells = mapObjects.MapCells;
            }
            else
            {
                Log.Error($"GetMapObjects status is: '{mapObjects.Status}'.");
            }
        }
예제 #6
0
        /// <summary>
        ///     It is not recommended to call this. Map objects will update automatically and fire the map update event.
        /// </summary>
        public async Task RefreshMapObjectsAsync()
        {
            var cellIds     = MapUtil.GetCellIdsForLatLong(_session.Player.Coordinate.Latitude, _session.Player.Coordinate.Longitude);
            var sinceTimeMs = cellIds.Select(x => (long)0).ToArray();

            var response = await SendRemoteProcedureCallAsync(new Request
            {
            });

            if (response != null)
            {
            }
            else if (_session.State != SessionState.Paused)
            {
            }

            //_session.Map.Cells = new RepeatedField<MapCell>();
            throw new SessionStateException("We received 0 map cells or status is empty.");
        }