1
- from valorantrpc import webserver ,riot_api ,utils ,oauth ,client_api ,match_session
1
+ from valorantrpc import webserver ,riot_api ,utils ,oauth ,client_api ,match_session ,unenhanced_match_session
2
+ from valorantrpc .exceptions import AuthError
2
3
import pypresence ,asyncio ,json ,base64 ,time ,threading ,os ,subprocess ,psutil ,ctypes ,sys ,pystray
3
4
from win10toast import ToastNotifier
4
5
from pystray import Icon as icon , Menu as menu , MenuItem as item
19
20
systray = None
20
21
loop = None
21
22
window_shown = False
22
- client_id = str ( os . environ . get ( 'CLIENT_ID' ))
23
- client_secret = str ( os . environ . get ( 'CLIENT_SECRET' ))
23
+ client_id = None
24
+ client_secret = None
24
25
client = None
25
26
last_presence = {}
26
27
session = None
31
32
config = {}
32
33
33
34
34
-
35
+ default_client_id = "811469787657928704"
35
36
current_release = "v2.0b1" #don't forget to update this you bimbo
36
37
37
38
@@ -84,8 +85,7 @@ def close_program():
84
85
def update_rpc (data ):
85
86
if data is None :
86
87
return
87
- global session
88
-
88
+ global session ,use_enhanced_presence ,party_invites_enabled
89
89
if not data ["isIdle" ]:
90
90
#menu
91
91
if data ["sessionLoopState" ] == "MENUS" and data ["partyState" ] != "CUSTOM_GAME_SETUP" :
@@ -99,7 +99,7 @@ def update_rpc(data):
99
99
small_text = "Party Leader" if utils .validate_party_size (data ) else None ,
100
100
party_id = data ["partyId" ],
101
101
party_size = data ["party_size" ],
102
- join = data ["join_state" ]
102
+ join = data ["join_state" ] if party_invites_enabled else None
103
103
)
104
104
105
105
#custom setup
@@ -115,7 +115,21 @@ def update_rpc(data):
115
115
small_text = "Party Leader" if utils .validate_party_size (data ) else None ,
116
116
party_id = data ["partyId" ],
117
117
party_size = data ['party_size' ],
118
- join = data ['join_state' ]
118
+ join = data ['join_state' ] if party_invites_enabled else None
119
+ )
120
+
121
+ #in da range
122
+ elif data ["sessionLoopState" ] == "INGAME" and data ["provisioningFlow" ] == "ShootingRange" :
123
+ game_map = utils .maps [data ["matchMap" ].split ("/" )[- 1 ]]
124
+ client .set_activity (
125
+ state = data ['party_state' ],
126
+ details = "THE RANGE" ,
127
+ large_image = f"splash_{ game_map .lower ()} " ,
128
+ large_text = game_map ,
129
+ small_image = utils .mode_images [data ['queue_id' ].lower ()],
130
+ party_id = data ["partyId" ],
131
+ party_size = data ['party_size' ],
132
+ join = data ['join_state' ] if party_invites_enabled else None
119
133
)
120
134
121
135
if use_enhanced_presence :
@@ -137,7 +151,20 @@ def update_rpc(data):
137
151
138
152
else :
139
153
# if not, use older presence stuff
140
- pass
154
+ if data ["sessionLoopState" ] == "PREGAME" :
155
+ if last_state != "PREGAME" :
156
+ # new game session, create match object
157
+ if session is None :
158
+ session = unenhanced_match_session .Session (client )
159
+ session .init_pregame (data )
160
+ print ('new sesh' )
161
+
162
+ elif data ["sessionLoopState" ] == "INGAME" :
163
+ # if a match doesn't have a pregame
164
+ if last_state != "INGAME" :
165
+ if session is None :
166
+ session = unenhanced_match_session .Session (client )
167
+ session .init_ingame (data )
141
168
142
169
143
170
@@ -212,44 +239,43 @@ def main(loop):
212
239
startup routine: load config, start VALORANT, load lockfile, wait for presence
213
240
once startup is complete, run the listening loop
214
241
'''
215
- global client ,client_id ,client_secret ,config
216
-
217
- print ('''
218
- _ _____ __ ____ ____ ___ _ ________ ____ ____ ______
219
- | | / / | / / / __ \/ __ \/ | / | / /_ __/ / __ \/ __ \/ ____/
220
- | | / / /| | / / / / / / /_/ / /| | / |/ / / / ______ / /_/ / /_/ / /
221
- | |/ / ___ |/ /___/ /_/ / _, _/ ___ |/ /| / / / /_____/ / _, _/ ____/ /___
222
- |___/_/ |_/_____/\____/_/ |_/_/ |_/_/ |_/ /_/ /_/ |_/_/ \____/
223
-
224
- https://github.com/colinhartigan/valorant-rpc
225
-
226
- ''' )
242
+ global client ,client_id ,client_secret ,config ,use_enhanced_presence ,party_invites_enabled
227
243
228
244
# load config
229
245
config = utils .get_config ()
246
+
230
247
launch_timeout = config ['settings' ]['launch_timeout' ]
231
- if config ['rpc-client-override' ]['client_id' ] != "" :
248
+ if config ['rpc-client-override' ]['client_id' ] != "" and config [ 'rpc-client-override' ][ 'client_id' ] != default_client_id :
232
249
print ("[i] overriding client id!" )
233
250
client_id = config ['rpc-client-override' ]['client_id' ]
251
+ else :
252
+ client_id = default_client_id
234
253
if config ['rpc-client-override' ]['client_secret' ] != "" :
235
254
print ("[i] overriding client secret!" )
236
255
client_secret = config ['rpc-client-override' ]['client_secret' ]
256
+ party_invites_enabled = True
237
257
else :
238
258
party_invites_enabled = False
239
259
240
260
if config ['riot-account' ]['username' ] != '' and config ['riot-account' ]['password' ] != '' :
241
- use_enhanced_presence = True
261
+ use_enhanced_presence = True
242
262
else :
243
263
print ('[i] no riot account detected, using old presence' )
244
264
use_enhanced_presence = False
245
265
#figure out if i can still use client.set_activity without whitelisting/oauthing; if so, then just use that
246
266
247
-
248
267
# setup client
249
- client = pypresence .Client (client_id ,loop = loop )
268
+ client = pypresence .Client (int ( client_id ) ,loop = loop )
250
269
webserver .run ()
251
270
client .start ()
252
- #oauth.authorize(client,client_id,client_secret)
271
+
272
+ # authorize app if party invites enabled
273
+ if party_invites_enabled :
274
+ try :
275
+ oauth .authorize (client ,client_id ,client_secret )
276
+ except :
277
+ use_enhanced_presence = False
278
+ print ('[!] could not authenticate, check the client secret' )
253
279
254
280
launch_timer = 0
255
281
@@ -298,11 +324,6 @@ def main(loop):
298
324
if launch_timer >= launch_timeout :
299
325
close_program ()
300
326
time .sleep (1 )
301
- print ("[i] lockfile loaded! hiding window..." )
302
- time .sleep (1 )
303
- systray_thread = threading .Thread (target = run_systray )
304
- systray_thread .start ()
305
- user32 .ShowWindow (hWnd , 0 )
306
327
307
328
#check for presence
308
329
launch_timer = 0
@@ -315,6 +336,13 @@ def main(loop):
315
336
if launch_timer >= launch_timeout :
316
337
close_program ()
317
338
time .sleep (1 )
339
+
340
+ print ("[i] presence detected! hiding window..." )
341
+ time .sleep (1 )
342
+ systray_thread = threading .Thread (target = run_systray )
343
+ systray_thread .start ()
344
+ user32 .ShowWindow (hWnd , 0 )
345
+
318
346
print ("[i] starting loop" )
319
347
update_rpc (presence )
320
348
#print(f"LOCKFILE: {lockfile}")
0 commit comments