Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gps noise #3912

Merged
merged 7 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
},
"websocket_server": false,
"walk": 4.16,
"replicate_gps_noise": False,
"gps_noise_range": 0.00025,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
18 changes: 18 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,24 @@ def _json_loader(filename):
type=float,
default=1
)
add_config(
parser,
load,
short_flag="-rgn",
long_flag="--replicate_gps_noise",
help="Add noise to current position",
type=bool,
default=False
)
add_config(
parser,
load,
short_flag="-gpr",
long_flag="--gps_noise_range",
help="Intensity of gps noise, high values may cause issues (default=0.00025)",
type=float,
default=0.00025
)

# Start to parse other attrs
config = parser.parse_args()
Expand Down
12 changes: 6 additions & 6 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
class PokemonGoBot(object):
@property
def position(self):
return self.api._position_lat, self.api._position_lng, 0
return self.api.actual_lat, self.api.actual_lng, self.api.actual_alt

@position.setter
def position(self, position_tuple):
self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple
#@position.setter # these should be called through api now that gps replication is there...
#def position(self, position_tuple):
# self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple

@property
def player_data(self):
Expand Down Expand Up @@ -625,7 +625,7 @@ def check_session(self, position):
)
position = self.position
self.api = ApiWrapper()
self.position = position
self.api.set_position(*position)
self.login()
self.api.activate_signature(self.get_encryption_lib())

Expand Down Expand Up @@ -694,7 +694,7 @@ def get_encryption_lib(self):

def _setup_api(self):
# instantiate pgoapi
self.api = ApiWrapper()
self.api = ApiWrapper(self.config.replicate_gps_noise, self.config.gps_noise_range)

# provide player position on the earth
self._set_starting_position()
Expand Down
22 changes: 20 additions & 2 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
from pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType

from human_behaviour import sleep
from human_behaviour import sleep, gps_noise_rng

class ApiWrapper(PGoApi):
def __init__(self):
def __init__(self, replicate_gps_noise=False, gps_noise_range=0.00025):
PGoApi.__init__(self)
self.useVanillaRequest = False

if replicate_gps_noise:
self.gps_noise_range = gps_noise_range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine if every request uses the exact same noise, it isn't really noise, right?

Copy link
Contributor Author

@kanemasa1987 kanemasa1987 Aug 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If you are moving, they can't separate gps noise from your actual position (so it should be ok.)
  2. If you are stopping for a long while, they can check if the user is using gaussian distribution or not, but I guess usual gps noises look like gaussian, so they should detect normal user as bot at the same time(as far as the parameters are set correctly)
  3. Those tests cause headaching problem.
  4. I'm not sure with altitude, checks are needed (might be better to just set it to zero).
  5. I believe drawing new random noise at set_position is quite fine at this point.
  6. If anyone is paranoid, he can develop time, position and velocity dependent covariant random noise himself (and share it with us!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noise in altitude IS required to make the whole thing more legitimate. Noise in altitude can be up to 15 meters according to sources (http://gpsinformation.net/main/altitude.htm).

Copy link
Contributor Author

@kanemasa1987 kanemasa1987 Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some sources say gps altitude precision is worse than lat, and lng to make those two more accurate (with the cost of altitude accuracy).
Since I'm also not sure if the app is actually sending altitude, and the alt should be handled differently,
I will separate altitude conf.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is 8 for altitude according to the API, and this does not change. Changing the altitude by a random factor is required, however like @kanemasa1987 said, this should be separate from the gps position (2 configuration parameters, the default height and the maximum variation (default 15))

else:
self.gps_noise_range = 0.0

def create_request(self):
RequestClass = ApiRequest
if self.useVanillaRequest:
Expand All @@ -37,6 +42,19 @@ def login(self, *args):
self.useVanillaRequest = False
return ret_value

def set_position(self, lat, lng, alt=None):
self.actual_lat = lat
self.actual_lng = lng
if None != alt:
self.actual_alt = alt
else:
alt = self.actual_alt
lat_noise, lng_noise, alt_noise = gps_noise_rng(self.gps_noise_range)
PGoApi.set_position(self, lat + lat_noise, lng + lng_noise, alt + alt_noise)

def get_position(self):
return (self.actual_lat, self.actual_lng, self.actual_alt)


class ApiRequest(PGoApiRequest):
def __init__(self, *args):
Expand Down
16 changes: 15 additions & 1 deletion pokemongo_bot/human_behaviour.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import time
from random import random, uniform
from random import random, uniform, gauss


def sleep(seconds, delta=0.3):
Expand All @@ -25,3 +25,17 @@ def random_lat_long_delta():
# should be 364,000 * .000025 = 9.1. So it returns between [-9.1, 9.1]
return ((random() * 0.00001) - 0.000005) * 5

def gps_noise_rng(radius):
'''
Simulates gps noise. This may cause problem, so we need test.
'''
lat_noise = gauss(0, radius/3.0)
lat_noise = min(max(-radius, lat_noise), radius)

lng_noise = gauss(0, radius/3.0)
lng_noise = min(max(-radius, lng_noise), radius)

alt_noise = gauss(0, radius/3.0)
alt_noise = min(max(-radius, alt_noise), radius)
return lat_noise, lng_noise, alt_noise

Empty file modified setup.sh
100755 → 100644
Empty file.