-
Notifications
You must be signed in to change notification settings - Fork 45
/
saliens.py
298 lines (264 loc) · 10.7 KB
/
saliens.py
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import requests
import json
from time import sleep
import datetime
# Get from: https://steamcommunity.com/saliengame/gettoken
TOKEN = ""
STEAMID = ""
s = requests.session()
s.headers.update({
'User-Agent': 'steam-salien-cheat on GitHub Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
'Referer': 'https://steamcommunity.com/saliengame/play/',
'Origin': 'https://steamcommunity.com',
'Accept': '*/*'
})
def steam64_to_steam3(commid):
'''Converts a STEAM64ID to a STEAM3ID
:param commid: the STEAM64 ID
:returns: the STEAM3ID (or "" if commid is "")
'''
if commid == "":
return commid
steamid64ident = 76561197960265728
steamidacct = int(commid) - steamid64ident
return steamidacct
def get_zone():
'''Searches for the best zone and planet to play in
:returns: the zone type, position(id), difficulty, planet id, planet name, and if the zone is a boss zone or not
'''
data = {
'active_only': 1,
'language':'english'
}
result = s.get("https://community.steam-api.com/ITerritoryControlMinigameService/GetPlanets/v0001/", params=data)
if result.status_code != 200:
print("Get planets errored... trying again(after 10s cooldown)")
sleep(10)
get_zone()
json_data = result.json()
valid = []
# Loop through the planets and sort the planets/zones into a list of the best planets/zones to choose from
for planet in json_data["response"]["planets"]:
info_data = {'id': planet["id"]}
info = s.get("https://community.steam-api.com/ITerritoryControlMinigameService/GetPlanet/v0001/", params=info_data)
if info.status_code != 200:
print("Get planet errored... trying the next planet")
continue
info_json = info.json()
# Loop through the zones and filtering out the bad planets
for zone in info_json["response"]["planets"][0]["zones"]:
if not zone["captured"]:
if zone["type"] == 4 and zone["boss_active"] and not zone["captured"]:
valid += [(zone["type"], zone["zone_position"], zone["difficulty"], planet["id"], planet["state"]["name"], True)]
if zone["type"] == 3 and "capture_progress" in zone and zone["capture_progress"] < 0.9 and zone["capture_progress"] != 0:
valid += [(zone["type"], zone["zone_position"], zone["difficulty"], planet["id"], planet["state"]["name"], False)]
return sorted(valid, key = lambda x: (x[0], x[2]), reverse=True)[0]
def get_user_info():
'''Gets user info and user's current state in the game. Used to leave current zones/planets
:returns: the active planet that the user is on
'''
data = {'access_token': TOKEN}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/GetPlayerInfo/v0001/", data=data)
if result.status_code != 200:
print("Getting user info errored... trying again(after 10s cooldown)")
sleep(10)
play_game()
# Check if the user is stuck in a game
if "active_zone_game" in result.json()["response"]:
print("Stuck on zone... trying to leave")
leave_game(result.json()["response"]["active_zone_game"])
if "active_boss_game" in result.json()["response"]:
print("Stuck on boss zone... trying to leave")
leave_game(result.json()["response"]["active_boss_game"])
if "active_planet" in result.json()["response"]:
return result.json()["response"]["active_planet"]
else:
return -1
def leave_game(current):
'''Leaves zones and planets so the user doesn't get stuck on them
:param current: the gameid to leave
:returns: None
'''
data = {
'gameid': current,
'access_token': TOKEN
}
result = s.post("https://community.steam-api.com/IMiniGameService/LeaveGame/v0001/", data=data)
if result.status_code != 200:
print("Leave planet {} errored... trying again(after 10s cooldown)".format(str(current)))
sleep(10)
play_game()
def join_planet(planet_id, planet_name):
'''Joins a planet
:param planet_id: the planet id to join
:param planet_name: the name of the planet to join
:returns: None
'''
data = {
'id': planet_id,
'access_token': TOKEN
}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/JoinPlanet/v0001/", data=data)
if result.status_code != 200:
print("Join planet {} ({}) errored... trying again(after 10s cooldown)".format(
str(planet_name),
str(planet_id)))
sleep(10)
play_game()
else:
print("Joined planet: {} ({}) \n".format(
str(planet_name),
str(planet_id)))
def join_zone(zone_position, difficulty):
'''Joins a zone
:param zone_position: the zone id to join
:param difficulty: the difficulty of the zone
:returns: None
'''
dstr = {
1: 'Easy',
2: 'Medium',
3: 'Hard'
}
data = {
'zone_position': zone_position,
'access_token': TOKEN
}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/JoinZone/v0001/", data=data)
if result.status_code != 200 or result.json() == {'response':{}}:
print("Join zone {} errored... trying again(after 10s cooldown)".format(str(zone_position)))
sleep(10)
play_game()
else:
print("Joined zone: {} (Difficulty: {})".format(
str(zone_position),
dstr.get(difficulty, difficulty)))
def report_score(difficulty):
'''Reports the user's score for this game
:param difficulty: the difficulty of the game, used to calculate the max score to report
:returns: None
'''
# Score calculation
score = 600 * (2 ** (difficulty - 1))
data = {
'access_token': TOKEN,
'score': score,
'language':'english'
}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/ReportScore/v0001/", data=data)
if result.status_code != 200 or result.json() == {'response':{}}:
print("Report score errored... Current zone likely completed...\n")
play_game()
else:
res = result.json()["response"]
if "next_level_score" not in res:
# Level 25 has no next level score in API response
print("Level: {} | Score: {} -> {}".format(
res["new_level"],
res["old_score"],
res["new_score"]))
else:
# Calculate the ETA to the next level
score_delta = int(res["next_level_score"]) - int(res["new_score"])
eta_seconds = int(score_delta // score) * 110
d = datetime.timedelta(seconds=eta_seconds)
print("Level: {} | Score: {} -> {} | Level-Up Score: {} ETA: {} {}\n".format(
res["new_level"],
res["old_score"],
res["new_score"],
res["next_level_score"],
d,
"Level UP!" if res["old_level"] != res["new_level"] else ""))
def play_boss(zone_position):
'''Plays the boss game mode
:param zone_position: the boss game zone position
:returns: None
'''
data = {
'zone_position': zone_position,
'access_token': TOKEN
}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/JoinBossZone/v0001/", data=data)
if result.status_code != 200 or result.json() == {'response':{}}:
print("Join boss zone {} errored... trying again(after 10s cooldown)".format(str(zone_position)))
sleep(10)
play_game()
else:
heal = 24
max_retries = 3
print("Joined boss zone: {}".format(str(zone_position)))
while 1:
sleep(5)
# Heal every 120 seconds
if heal == 0:
use_heal = 1
heal = 24
else:
use_heal = 0
damage_data = {
'access_token': TOKEN,
'use_heal_ability': use_heal,
'damage_to_boss': 1,
'damage_taken': 0
}
result = s.post("https://community.steam-api.com/ITerritoryControlMinigameService/ReportBossDamage/v0001/", data=damage_data)
if result.status_code != 200 or result.json() == {'response':{}}:
print("Report boss score errored... retrying")
if max_retries == 0:
break
max_retries = max_retries - 1
continue
res = result.json()["response"]
if res["waiting_for_players"]:
continue
if res["game_over"]:
break
# Print out boss game information, filter down the output to current user if steamid is provided
print("Boss HP: {}/{} | Lasers: {} | Team Heals: {}\n".format(
res["boss_status"]["boss_hp"],
res["boss_status"]["boss_max_hp"],
res["num_laser_uses"],
res["num_team_heals"]))
for player in res["boss_status"]["boss_players"]:
STEAM3ID = steam64_to_steam3(STEAMID)
if player["accountid"] == STEAM3ID or STEAM3ID == "":
print("Name: {} | HP: {}/{} | XP Earned: {}".format(
player["name"],
player["hp"],
player["max_hp"],
player["xp_earned"]))
if player["accountid"] == STEAM3ID and player["hp"] <= 0:
print("You've died... rejoining...")
get_user_info()
play_boss(zone_position)
heal = heal - 1
def play_game():
'''The main function to play the entire game
:returns: None
'''
print("Checking if user is currently on a planet")
current = get_user_info()
if current != -1:
print("Leaving current planet")
leave_game(current)
while 1:
print("Finding a planet and zone")
zone_type, zone_position, difficulty, planet_id, planet_name, boss = get_zone()
join_planet(planet_id, planet_name)
if boss:
play_boss(zone_position)
else:
join_zone(zone_position, difficulty)
print("Sleeping for 1 minute 50 seconds")
sleep(110)
report_score(difficulty)
get_user_info() # get user info and leave game, incase user gets stuck
while 1:
try:
play_game()
except KeyboardInterrupt:
print("User cancelled script")
exit(1)
except Exception as e:
print(e)
continue