forked from rastapasta/pokemon-go-mitm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.ingameRadar.coffee
131 lines (110 loc) · 4.66 KB
/
example.ingameRadar.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
###
Pokemon Go (c) ManInTheMiddle Radar "mod"
Michael Strassburger <[email protected]>
Enriches every PokeStop description with information about
- directions to nearby wild pokemons
- time left if a PokeStop has an active lure
###
PokemonGoMITM = require './lib/pokemon-go-mitm'
changeCase = require 'change-case'
moment = require 'moment'
LatLon = require('geodesy').LatLonSpherical
pokemons = []
currentLocation = null
mapRadius = 150 # Approx size of level 15 s2 cell
server = new PokemonGoMITM port: 8081
# Fetch our current location as soon as it gets passed to the API
.addRequestHandler "GetMapObjects", (data) ->
currentLocation = new LatLon data.latitude, data.longitude
console.log "[+] Current position of the player #{currentLocation}"
false
# Parse the wild pokemons nearby
.addResponseHandler "GetMapObjects", (data) ->
return false if not data.map_cells.length
oldPokemons = pokemons
pokemons = []
seen = {}
# Store wild pokemons
addPokemon = (pokemon) ->
return if seen[pokemon.encounter_id]
return if pokemon.time_till_hidden_ms < 0
console.log "new wild pokemon", pokemon
pokemons.push pokemon
seen[pokemon.encounter_id] = pokemon
for cell in data.map_cells
addPokemon pokemon for pokemon in cell.wild_pokemons
# Use server timestamp
timestampMs = Number(data.map_cells[0].current_timestamp_ms)
# Add previously known pokemon, unless expired
for pokemon in oldPokemons when not seen[pokemon.encounter_id]
expirationMs = Number(pokemon.last_modified_timestamp_ms) + pokemon.time_till_hidden_ms
pokemons.push pokemon unless expirationMs < timestampMs
seen[pokemon.encounter_id] = pokemon
# Correct steps display for known nearby Pokémon (idea by @zaksabeast)
return false if not currentLocation
for cell in data.map_cells
for nearby in cell.nearby_pokemons when seen[nearby.encounter_id]
pokemon = seen[nearby.encounter_id]
position = new LatLon pokemon.latitude, pokemon.longitude
nearby.distance_in_meters = Math.floor currentLocation.distanceTo position
data
# Whenever a poke spot is opened, populate it with the radar info!
.addResponseHandler "FortDetails", (data) ->
console.log "fetched fort request", data
info = ""
# Populate some neat info about the pokemon's whereabouts
pokemonInfo = (pokemon) ->
name = changeCase.titleCase pokemon.pokemon_data.pokemon_id
name = name.replace(" Male", "♂").replace(" Female", "♀")
expirationMs = Number(pokemon.last_modified_timestamp_ms) + pokemon.time_till_hidden_ms
position = new LatLon pokemon.latitude, pokemon.longitude
expires = moment(expirationMs).fromNow()
distance = Math.floor currentLocation.distanceTo position
bearing = currentLocation.bearingTo position
direction = switch true
when bearing>330 then "↑"
when bearing>285 then "↖"
when bearing>240 then "←"
when bearing>195 then "↙"
when bearing>150 then "↓"
when bearing>105 then "↘"
when bearing>60 then "→"
when bearing>15 then "↗"
else "↑"
"#{name} #{direction} #{distance}m expires #{expires}"
# Create map marker for pokemon location
markers = {}
addMarker = (id, lat, lon) ->
label = id.charAt(0)
name = changeCase.paramCase id.replace(/_([MF]).*/, "_$1")
icon = "http://raw.github.com/msikma/pokesprite/master/icons/pokemon/regular/#{name}.png"
markers[id] = "&markers=label:#{label}%7Cicon:#{icon}" if not markers[id]
markers[id] += "%7C#{lat},#{lon}"
for modifier in data.modifiers when modifier.item_id is 'ITEM_TROY_DISK'
expires = moment(Number(modifier.expiration_timestamp_ms)).fromNow()
info += "Lure by #{modifier.deployer_player_codename} expires #{expires}\n"
mapPokemons = []
if currentLocation
# Limit to map radius
for pokemon in pokemons
position = new LatLon pokemon.latitude, pokemon.longitude
if mapRadius > currentLocation.distanceTo position
mapPokemons.push pokemon
addMarker(pokemon.pokemon_data.pokemon_id, pokemon.latitude, pokemon.longitude)
# Create map image url
loc = "#{currentLocation.lat},#{currentLocation.lon}"
img = "http://maps.googleapis.com/maps/api/staticmap?" +
"center=#{loc}&zoom=17&size=384x512&markers=color:blue%7Csize:tiny%7C#{loc}"
img += (marker for id, marker of markers).join ""
data.image_urls.unshift img
# Sort pokemons by distance
mapPokemons.sort (p1, p2) ->
d1 = currentLocation.distanceTo new LatLon(p1.latitude, p1.longitude)
d2 = currentLocation.distanceTo new LatLon(p2.latitude, p2.longitude)
d1 - d2
info += if mapPokemons.length
(pokemonInfo(pokemon) for pokemon in mapPokemons).join "\n"
else
"No wild Pokémon near you..."
data.description = info
data