Skip to content

Commit 757c47c

Browse files
author
Mila432
committed
working version..
1 parent 03bfbc6 commit 757c47c

File tree

15 files changed

+2018
-193
lines changed

15 files changed

+2018
-193
lines changed

api.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import config
22
import pokemon_pb2
3-
import public_proto_pb2
43
import time
54
import requests
65
import logic
@@ -13,27 +12,7 @@ def use_api(target_api,prot1):
1312
if config.debug:
1413
print '[!] using api:',target_api
1514
r=config.s.post(target_api,data=prot1,verify=False)
16-
if r.status_code==200:
17-
return r.content
18-
else:
19-
print '[-] error code %s'%(r.status_code)
20-
return use_api(target_api,prot1)
21-
except:
22-
print '[!] repeat use_api'
23-
time.sleep(3)
24-
return use_api(target_api,prot1)
25-
26-
def use_api_p(target_api,prot1):
27-
try:
28-
if config.debug:
29-
print '[!] using api:',target_api
30-
r=config.s.post(target_api,data=prot1,verify=False)
31-
if r.status_code==200:
32-
p_ret = public_proto_pb2.ResponseEnvelop()
33-
p_ret.ParseFromString(r.content)
34-
return p_ret
35-
else:
36-
return use_api(target_api,prot1)
15+
return r.content
3716
except:
3817
print '[!] repeat use_api'
3918
time.sleep(3)
@@ -43,17 +22,14 @@ def get_rpc_server(access_token,first_data):
4322
try:
4423
r=config.s.post(config.api_url,data=first_data,verify=False,timeout=3)
4524
get_session_data = pokemon_pb2.get_session_data()
46-
try:
47-
get_session_data.ParseFromString(r.content)
48-
except:
49-
return get_rpc_server(access_token,first_data)
25+
get_session_data.ParseFromString(r.content)
5026
if get_session_data is not None and get_session_data.rpc_server is not None:
5127
if 'plfe' in get_session_data.rpc_server:
5228
return get_session_data
5329
else:
54-
return get_rpc_server(access_token,first_data)
30+
get_rpc_server(access_token,first_data)
5531
else:
56-
return get_rpc_server(access_token,first_data)
32+
get_rpc_server(access_token,first_data)
5733
except requests.exceptions.RequestException as e:
5834
print '[-] offline..'
5935
time.sleep(3)

api.pyc

1.56 KB
Binary file not shown.

config.pyc

1.41 KB
Binary file not shown.

dirty.py

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33
import time
44
import pokemon_pb2
55
import location
6-
import json
76
import config
87
from multiprocessing import Process
98

109
multi=False
11-
show_pok=True
1210

1311
def start_private_show(access_token,ltype,loc):
14-
#try:
1512
location.set_location(loc)
1613
print '[+] Token:',access_token[:40]+'...'
1714
prot1=logic.gen_first_data(access_token,ltype)
1815
local_ses=api.get_rpc_server(access_token,prot1)
19-
try:
20-
new_rcp_point='https://%s/rpc'%(local_ses.rpc_server,)
21-
except:
22-
start_private_show(access_token,ltype,loc)
16+
new_rcp_point='https://%s/rpc'%(local_ses.rpc_server,)
2317
while(True):
2418
work_stop(local_ses,new_rcp_point)
25-
#except:
26-
# start_private_show(access_token,ltype,loc)
27-
19+
2820
def walk_random():
2921
COORDS_LATITUDE, COORDS_LONGITUDE, COORDS_ALTITUDE=location.get_location_coords()
3022
COORDS_LATITUDE=location.l2f(COORDS_LATITUDE)
@@ -44,55 +36,34 @@ def work_half_list(part,local_ses,new_rcp_point):
4436
print '[!] farming pokestop..'
4537
work_with_stops(t,local_ses.ses,new_rcp_point)
4638

47-
def get_pok_name(pok):
48-
with open('pokemon.json') as data_file:
49-
data = json.load(data_file)
50-
for u in data:
51-
print str(u['Number'])
52-
5339
def work_stop(local_ses,new_rcp_point):
5440
proto_all=logic.all_stops(local_ses)
5541
all_stops=api.use_api(new_rcp_point,proto_all)
5642
maps = pokemon_pb2.maps()
5743
maps.ParseFromString(all_stops)
58-
if show_pok:
59-
data_list=location.get_near_p(maps)
60-
if len(data_list)>0:
61-
print '[!] found %s pokemon near you'%(len(data_list),)
62-
for idx, pok in enumerate(data_list):
63-
print '[!]:%s Type:%s its %s m away'%(idx,pok[0],pok[len(pok)-1],)
64-
#if pok[0] < 22:
65-
#if pok[len(pok)-1] < 20:
66-
catch_prot= logic.catch_it(local_ses.ses,pok)
67-
tmp_api=api.use_api(new_rcp_point,catch_prot)
68-
#exit()
69-
walk_random()
70-
walk_random()
71-
time.sleep(2)
44+
data_list=location.get_near(maps)
45+
data_list = sorted(data_list, key = lambda x: x[1])
46+
if len(data_list)>0:
47+
print '[+] found: %s Pokestops near'%(len(data_list))
48+
if local_ses is not None and data_list is not None:
49+
print '[+] starting show'
50+
if multi:
51+
a,b=split_list(data_list)
52+
p = Process(target=work_half_list, args=(a,local_ses.ses,new_rcp_point))
53+
o = Process(target=work_half_list, args=(a,local_ses.ses,new_rcp_point))
54+
p.start()
55+
o.start()
56+
p.join()
57+
o.join()
58+
print '[!] farming done..'
59+
else:
60+
for t in data_list:
61+
if config.debug:
62+
print '[!] farming pokestop..'
63+
work_with_stops(t,local_ses.ses,new_rcp_point)
7264
else:
73-
data_list=location.get_near(maps)
74-
data_list = sorted(data_list, key = lambda x: x[1])
75-
if len(data_list)>0:
76-
print '[+] found: %s Pokestops within %s m'%(len(data_list),config.distance,)
77-
if local_ses is not None and data_list is not None:
78-
print '[+] starting show'
79-
if multi:
80-
a,b=split_list(data_list)
81-
p = Process(target=work_half_list, args=(a,local_ses.ses,new_rcp_point))
82-
o = Process(target=work_half_list, args=(a,local_ses.ses,new_rcp_point))
83-
p.start()
84-
o.start()
85-
p.join()
86-
o.join()
87-
print '[!] farming done..'
88-
else:
89-
for t in data_list:
90-
if config.debug:
91-
print '[!] farming pokestop..'
92-
work_with_stops(t,local_ses.ses,new_rcp_point)
93-
else:
94-
walk_random()
95-
work_stop(local_ses,new_rcp_point)
65+
walk_random()
66+
work_stop(local_ses,new_rcp_point)
9667

9768
def work_with_stops(current_stop,ses,new_rcp_point):
9869
Kinder= logic.gen_stop_data(ses,current_stop)

dirty.pyc

3.5 KB
Binary file not shown.

location.py

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def get_lat():
2222
def get_lot():
2323
return COORDS_LONGITUDE
2424

25+
def set_lat(new):
26+
global COORDS_LATITUDE
27+
COORDS_LATITUDE = f2i(new)
28+
29+
def set_lot(new):
30+
global COORDS_LONGITUDE
31+
COORDS_LONGITUDE= f2i(new)
32+
2533
def set_location(location_name):
2634
geolocator = GoogleV3()
2735
loc = geolocator.geocode(location_name)
@@ -40,6 +48,24 @@ def set_location_coords(lat, long, alt):
4048
COORDS_LONGITUDE = f2i(long)
4149
COORDS_ALTITUDE = f2i(alt)
4250

51+
def encode(cellid):
52+
output = []
53+
encoder._VarintEncoder()(output.append, cellid)
54+
return ''.join(output)
55+
56+
def getNeighbors():
57+
origin = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)).parent(15)
58+
walk = [origin.id()]
59+
# 10 before and 10 after
60+
next = origin.next()
61+
prev = origin.prev()
62+
for i in range(10):
63+
walk.append(prev.id())
64+
walk.append(next.id())
65+
next = next.next()
66+
prev = prev.prev()
67+
return walk
68+
4369
def i2f(int):
4470
return struct.unpack('<Q', struct.pack('<d', int))[0]
4571

@@ -57,25 +83,44 @@ def h2f(hex):
5783

5884
def get_near(map):
5985
ms=[]
86+
ms.append(('start',get_lat(),get_lot(),get_distance(get_lat(),get_lot(),COORDS_LATITUDE,COORDS_LONGITUDE)))
6087
for cell in [map]:
6188
for block in cell.b:
6289
for obj in block.c:
6390
for stop in obj.s:
64-
if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
65-
ms.append((stop.name,stop.lat,stop.lon,get_distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE)))
91+
#if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
92+
ms.append((stop.name,stop.lat,stop.lon,get_distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE)))
6693
return ms
6794

6895
def get_near_p(map):
6996
ms=[]
97+
ms.append(('start',get_lat(),get_lot(),'start','start',get_distance(get_lat(),get_lot(),COORDS_LATITUDE,COORDS_LONGITUDE)))
7098
for cell in [map]:
7199
for block in cell.b:
72100
for obj in block.c:
73101
for stop in obj.p:
74-
if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
75-
ms.append((stop.t.type,stop.lat,stop.lon,stop.name,stop.hash,get_distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE)))
102+
#if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
103+
ms.append((stop.t.type,stop.lat,stop.lon,stop.name,stop.hash,get_distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE)))
104+
#for stop in obj.s:
105+
# if stop.p.type:
106+
# ms.append((stop.p.type,stop.lat,stop.lon,stop.name,stop.p.u2,get_distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE)))
76107
return ms
77108

78-
109+
def move_to(lat1, lot1,lat2, lot2):
110+
if (lat1>lat2):
111+
while(lat1<lat2):
112+
lat1=lat1-0.000095
113+
else:
114+
while(lat1<lat2):
115+
lat1=lat1+0.000095
116+
if (lot1>lot2):
117+
while(lot1>lot2):
118+
lot1=lot1-0.000095
119+
else:
120+
while(lot2>lot1):
121+
lot1=lot1+0.000095
122+
return lat1, lot1,lat2, lot2
123+
79124
def distance(lat1, lon1,lat2, lon2):
80125
lat1=l2f(lat1)
81126
lon1=l2f(lon1)
@@ -95,14 +140,15 @@ def get_distance(lat1, lon1,lat2, lon2):
95140
lon1=l2f(lon1)
96141
lat2=l2f(lat2)
97142
lon2=l2f(lon2)
98-
radius = 6371 # km *1000 m
99-
dlat = math.radians(lat2-lat1)
100-
dlon = math.radians(lon2-lon1)
101-
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
102-
* math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
103-
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
104-
d = radius * c * 1000
105-
return d
143+
# convert decimal degrees to radians
144+
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
145+
# haversine formula
146+
dlon = lon2 - lon1
147+
dlat = lat2 - lat1
148+
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
149+
c = 2 * asin(sqrt(a))
150+
meter = 6367000 * c
151+
return meter
106152

107153
def haversine(lon1, lat1, lon2, lat2):
108154
lat1=l2f(lat1)

location.pyc

6.8 KB
Binary file not shown.

logic.py

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import base64
55
from google.protobuf.internal import encoder
66
from s2sphere import *
7-
from binascii import unhexlify
87

98
def simulate_walking(ses,cur_session):
109
walk = pokemon_pb2.walk()
@@ -116,6 +115,7 @@ def all_stops(cur_session):
116115
def gen_stop_data(ses,cur_session):
117116
stop_request = pokemon_pb2.stop_request()
118117
stop_request.time = 2 #1
118+
#stop_request.rpc_id = 9077956684869009422 #3 static
119119
stop_request.rpc_id = 2212820743501119519-randint(0,999) #3 static
120120
stop_request.unk1 = cur_session[1]#-randint(0,9) #7
121121
stop_request.unk2 = cur_session[2]#-randint(0,9) #8
@@ -164,100 +164,4 @@ def gen_first_data(access_token,ltype):
164164
req5.type = 5
165165
return login_request.SerializeToString()
166166

167-
def long_to_bytes (val, endianness='big'):
168-
"""
169-
Use :ref:`string formatting` and :func:`~binascii.unhexlify` to
170-
convert ``val``, a :func:`long`, to a byte :func:`str`.
171-
172-
:param long val: The value to pack
173-
174-
:param str endianness: The endianness of the result. ``'big'`` for
175-
big-endian, ``'little'`` for little-endian.
176-
177-
If you want byte- and word-ordering to differ, you're on your own.
178-
179-
Using :ref:`string formatting` lets us use Python's C innards.
180-
"""
181-
182-
# one (1) hex digit per four (4) bits
183-
width = val.bit_length()
184-
185-
# unhexlify wants an even multiple of eight (8) bits, but we don't
186-
# want more digits than we need (hence the ternary-ish 'or')
187-
width += 8 - ((width % 8) or 8)
188-
189-
# format width specifier: four (4) bits per hex digit
190-
fmt = '%%0%dx' % (width // 4)
191-
192-
# prepend zero (0) to the width, to zero-pad the output
193-
s = unhexlify(fmt % val)
194-
195-
if endianness == 'little':
196-
# see http://stackoverflow.com/a/931095/309233
197-
s = s[::-1]
198-
199-
return s
200-
201-
def catch_it(ses,cur_session):
202-
#cur_session (21, 4632737554732154986L, 4621790981467132021L, u'47b185ff63b', 10215399323137525133L, 86.69675826461956)
203-
stop_requests = pokemon_pb2.stop_requests()
204-
stop_requests.time = 2 #1
205-
stop_requests.rpc_id = 2212820743501119519-randint(0,999) #3 static
206-
#stop_requests.unk1 = cur_session[1]#-randint(0,9) #7
207-
stop_requests.unk1 = location.get_lat()#-randint(0,9) #7
208-
#stop_requests.unk2 = cur_session[2]#-randint(0,9) #8
209-
stop_requests.unk2 = location.get_lot()#-randint(0,9) #8
210-
stop_requests.unk3 = 0x4049000000000000 #9 static
211-
stop_requests.unknown12 = randint(0,999999) #12 static
212-
stop_requests.sess.ses1 = ses.session_hash #12
213-
stop_requests.sess.time = ses.session_live #12
214-
stop_requests.sess.ses2 = ses.session_id #12
215-
216-
req1 = stop_requests.requests.add()
217-
m1 = pokemon_pb2.stop_requests.Requests()
218-
m1.type = 143
219-
#req1.message.unknown4 = long_to_bytes(cur_session[4])
220-
#m = pokemon_pb2.RequestEnvelop.Unknown9()
221-
m = pokemon_pb2.stop_requests.Unknown9()
222-
#req1.message.unknown4 = cur_session[4]
223-
#req1.message.unknown5 = 1#-randint(0,9)
224-
#req1.message.unknown6 = 0x3ff1c8dcc0000000#-randint(0,9)
225-
#req1.message.unknown7 = cur_session[3]#-randint(0,9) #last-1
226-
#req1.message.unknown8 = 1#-randint(0,9) #last
227-
#req1.message.unknown9 = 0x3f35c54100000000#-randint(0,9) #last
228-
#req1.message.unknown10 = 0x3ff0000000000000#-randint(0,9) #last
229-
230-
m.unknown4 = cur_session[4]
231-
m.unknown5 = cur_session[3]#-randint(0,9)
232-
#m.unknown5 = 1#-randint(0,9)
233-
#m.unknown6 = 0x4000000000000000#-randint(0,9)
234-
#m.unknown7 = cur_session[3]#-randint(0,9) #last-1
235-
#m.unknown8 = 1#-randint(0,9) #last
236-
#m.unknown9 = 0x3f35c54100000000#-randint(0,9) #last
237-
#m.unknown10 = 0x3ff0000000000000#-randint(0,9) #last
238-
m1.message = m.SerializeToString()
239-
req1.MergeFrom(m1)
240-
241-
req2 = stop_requests.requests.add()
242-
req2.type = 126
243-
req5 = stop_requests.requests.add()
244-
req5.type = 4
245-
req3 = stop_requests.requests.add()
246-
req3.type = 129
247-
req4 = stop_requests.requests.add()
248-
req4.type = 5
249-
req4.MergeFrom(m5)
250-
m5 = pokemon_pb2.stop_requests.Requests()
251-
m = pokemon_pb2.stop_requests.MessageSingleString()
252-
m.bytes = "05daf51635c82611d1aac95c0b051d3ec088a930"
253-
m5.message = m.SerializeToString()
254-
255-
req6 = stop_requests.requests.add()
256-
req6.type =142
257-
m = pokemon_pb2.stop_requests.MessageSingleString()
258-
m.unknown1=
259-
m.unknown2=
260-
261-
#req4.message.unknown4 = '05daf51635c82611d1aac95c0b051d3ec088a930' #static
262-
#location.set_location_coords(location.l2f(cur_session[1]),location.l2f(cur_session[2]),location.l2f(0x4049000000000000))
263-
return stop_requests.SerializeToString()
167+

logic.pyc

5.05 KB
Binary file not shown.

login.pyc

6.08 KB
Binary file not shown.

0 commit comments

Comments
 (0)