Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 89e15e4

Browse files
committed
installer stuff
1 parent 2910e8e commit 89e15e4

10 files changed

+218
-48
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ build/
55
dist/
66
.env
77
config.json
8-
main.spec
8+
main.spec
9+
installer/

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Colin Hartigan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

installer/installer compiler.iss

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; Script generated by the Inno Setup Script Wizard.
2+
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
3+
4+
#define MyAppName "VALORANT-RPC Installer"
5+
#define MyAppVersion "2.0"
6+
#define MyAppPublisher "Colin Hartigan"
7+
#define MyAppURL "https://github.com/colinhartigan/valorant-rpc"
8+
#define MyAppExeName "valorant-rpc.exe"
9+
10+
[Setup]
11+
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
12+
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
13+
AppId={{C7C0CB9D-5B3A-46FC-8C0D-35D85EBD30F4}
14+
AppName={#MyAppName}
15+
AppVersion={#MyAppVersion}
16+
;AppVerName={#MyAppName} {#MyAppVersion}
17+
AppPublisher={#MyAppPublisher}
18+
AppPublisherURL={#MyAppURL}
19+
AppSupportURL={#MyAppURL}
20+
AppUpdatesURL={#MyAppURL}
21+
DefaultDirName={autopf}\valorant-rpc
22+
DefaultGroupName=VALORANT-RPC
23+
DisableProgramGroupPage=yes
24+
LicenseFile=D:\colin\programming\VALORANT\valorant-rpc\LICENSE.txt
25+
InfoAfterFile=D:\colin\programming\VALORANT\valorant-rpc\installer\post-install.txt
26+
; Uncomment the following line to run in non administrative install mode (install for current user only.)
27+
;PrivilegesRequired=lowest
28+
PrivilegesRequiredOverridesAllowed=dialog
29+
OutputDir=D:\colin\programming\VALORANT\valorant-rpc\installer\installer output
30+
OutputBaseFilename=VALORANT-RPC installer
31+
SetupIconFile=D:\colin\programming\VALORANT\valorant-rpc\assets\game_icon_white.ico
32+
Compression=lzma
33+
SolidCompression=yes
34+
WizardStyle=modern
35+
36+
[Languages]
37+
Name: "english"; MessagesFile: "compiler:Default.isl"
38+
39+
[Tasks]
40+
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
41+
42+
[Files]
43+
Source: "D:\colin\programming\VALORANT\valorant-rpc\dist\valorant-rpc\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
44+
Source: "D:\colin\programming\VALORANT\valorant-rpc\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
45+
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
46+
47+
[Icons]
48+
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
49+
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
50+
51+
[Run]
52+
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
53+

installer/post-install.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Thank you for installing VALORANT-RPC!
2+
https://github.com/colinhartigan/valorant-rpc
3+
4+
You're almost done installing, but there's one more step to ensure a seamless experience while using the client:
5+
https://github.com/colinhartigan/valorant-rpc#part-2-changing-the-valorant-launch-target

main.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
from valorantrpc import main
22

3-
main.run()
3+
if __name__ == "__main__":
4+
print('''
5+
_ _____ __ ____ ____ ___ _ ________ ____ ____ ______
6+
| | / / | / / / __ \/ __ \/ | / | / /_ __/ / __ \/ __ \/ ____/
7+
| | / / /| | / / / / / / /_/ / /| | / |/ / / / ______ / /_/ / /_/ / /
8+
| |/ / ___ |/ /___/ /_/ / _, _/ ___ |/ /| / / / /_____/ / _, _/ ____/ /___
9+
|___/_/ |_/_____/\____/_/ |_/_/ |_/_/ |_/ /_/ /_/ |_/_/ \____/
10+
11+
https://github.com/colinhartigan/valorant-rpc
12+
13+
''')
14+
main.run()

valorant-rpc.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ block_cipher = None
66
a = Analysis(['main.py'],
77
pathex=['D:\\colin\\programming\\VALORANT\\valorant-rpc'],
88
binaries=[],
9-
datas=[("data/config.json", "data"),("data/.env", "data"), ("data/favicon.ico", "data")],
9+
datas=[("data/favicon.ico", "data")],
1010
hiddenimports=['pystray._win32'],
1111
hookspath=[],
1212
runtime_hooks=[],
13-
excludes=[],
13+
excludes=['matplotlib','notebook'],
1414
win_no_prefer_redirects=False,
1515
win_private_assemblies=False,
1616
cipher=block_cipher,

valorantrpc/main.py

+59-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
23
import pypresence,asyncio,json,base64,time,threading,os,subprocess,psutil,ctypes,sys,pystray
34
from win10toast import ToastNotifier
45
from pystray import Icon as icon, Menu as menu, MenuItem as item
@@ -19,8 +20,8 @@
1920
systray = None
2021
loop = None
2122
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
2425
client = None
2526
last_presence = {}
2627
session = None
@@ -31,7 +32,7 @@
3132
config = {}
3233

3334

34-
35+
default_client_id = "811469787657928704"
3536
current_release = "v2.0b1" #don't forget to update this you bimbo
3637

3738

@@ -84,8 +85,7 @@ def close_program():
8485
def update_rpc(data):
8586
if data is None:
8687
return
87-
global session
88-
88+
global session,use_enhanced_presence,party_invites_enabled
8989
if not data["isIdle"]:
9090
#menu
9191
if data["sessionLoopState"] == "MENUS" and data["partyState"] != "CUSTOM_GAME_SETUP":
@@ -99,7 +99,7 @@ def update_rpc(data):
9999
small_text="Party Leader" if utils.validate_party_size(data) else None,
100100
party_id=data["partyId"],
101101
party_size=data["party_size"],
102-
join=data["join_state"]
102+
join=data["join_state"] if party_invites_enabled else None
103103
)
104104

105105
#custom setup
@@ -115,7 +115,21 @@ def update_rpc(data):
115115
small_text="Party Leader" if utils.validate_party_size(data) else None,
116116
party_id=data["partyId"],
117117
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
119133
)
120134

121135
if use_enhanced_presence:
@@ -137,7 +151,20 @@ def update_rpc(data):
137151

138152
else:
139153
# 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)
141168

142169

143170

@@ -212,44 +239,43 @@ def main(loop):
212239
startup routine: load config, start VALORANT, load lockfile, wait for presence
213240
once startup is complete, run the listening loop
214241
'''
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
227243

228244
# load config
229245
config = utils.get_config()
246+
230247
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:
232249
print("[i] overriding client id!")
233250
client_id = config['rpc-client-override']['client_id']
251+
else:
252+
client_id = default_client_id
234253
if config['rpc-client-override']['client_secret'] != "":
235254
print("[i] overriding client secret!")
236255
client_secret = config['rpc-client-override']['client_secret']
256+
party_invites_enabled = True
237257
else:
238258
party_invites_enabled = False
239259

240260
if config['riot-account']['username'] != '' and config['riot-account']['password'] != '':
241-
use_enhanced_presence = True
261+
use_enhanced_presence = True
242262
else:
243263
print('[i] no riot account detected, using old presence')
244264
use_enhanced_presence = False
245265
#figure out if i can still use client.set_activity without whitelisting/oauthing; if so, then just use that
246266

247-
248267
# setup client
249-
client = pypresence.Client(client_id,loop=loop)
268+
client = pypresence.Client(int(client_id),loop=loop)
250269
webserver.run()
251270
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')
253279

254280
launch_timer = 0
255281

@@ -298,11 +324,6 @@ def main(loop):
298324
if launch_timer >= launch_timeout:
299325
close_program()
300326
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)
306327

307328
#check for presence
308329
launch_timer = 0
@@ -315,6 +336,13 @@ def main(loop):
315336
if launch_timer >= launch_timeout:
316337
close_program()
317338
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+
318346
print("[i] starting loop")
319347
update_rpc(presence)
320348
#print(f"LOCKFILE: {lockfile}")

valorantrpc/match_session.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import utils,riot_api,client_api
1+
from . import utils,client_api
22
from .exceptions import AuthError
33
import os
44
import asyncio
@@ -68,7 +68,6 @@ def pregame_loop(self,presence_data):
6868

6969
self.client.set_activity(
7070
state=presence_data['party_state'],
71-
#details=("Selecting Agent" if not self.selected else "Agent Locked"),# + (f" - {self.mode}" if self.mode else ""),
7271
details="Pregame" + (f" - {self.mode}" if self.mode else ""),
7372
end=self.state_end_time,
7473
large_image=f"agent_{self.agent_name.lower()}" if (self.agent_name != "Selecting" and self.agent_name != "Observer") else "game_icon_white",

valorantrpc/oauth.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from dotenv import load_dotenv
44
import os
55
from . import utils
6+
from valorantrpc.exceptions import AuthError
67

78
api_endpoint = 'https://discord.com/api/v8'
89

910
def exchange_code(code,client_id,client_secret):
11+
dir_path = os.path.dirname(os.path.realpath(__file__))
1012
data = {
1113
'client_id': client_id,
1214
'client_secret': client_secret,
@@ -20,7 +22,7 @@ def exchange_code(code,client_id,client_secret):
2022
}
2123
r = requests.post('%s/oauth2/token' % api_endpoint, data=data, headers=headers)
2224
r.raise_for_status()
23-
with open('config.json','r+') as f:
25+
with open(os.path.join(dir_path, '../data/config.json'), 'r+') as f:
2426
data = json.load(f)
2527
data['rpc-oauth'] = r.json()
2628
f.seek(0)
@@ -30,6 +32,7 @@ def exchange_code(code,client_id,client_secret):
3032
return r.json()
3133

3234
def refresh_token(refresh_token,client_id,client_secret):
35+
dir_path = os.path.dirname(os.path.realpath(__file__))
3336
data = {
3437
'client_id': client_id,
3538
'client_secret': client_secret,
@@ -43,7 +46,7 @@ def refresh_token(refresh_token,client_id,client_secret):
4346
}
4447
r = requests.post('%s/oauth2/token' % api_endpoint, data=data, headers=headers)
4548
r.raise_for_status()
46-
with open('config.json','r+') as f:
49+
with open(os.path.join(dir_path, '../data/config.json'), 'r+') as f:
4750
data = json.load(f)
4851
data['rpc-oauth'] = r.json()
4952
f.seek(0)
@@ -56,13 +59,21 @@ def refresh_token(refresh_token,client_id,client_secret):
5659
def authorize(client,client_id,client_secret):
5760
config = utils.get_config()
5861
if config['rpc-oauth'] == {}:
59-
print("authenticating with discord")
60-
auth = client.authorize(client_id,['rpc'])
61-
config = utils.get_config()
62-
code_grant = auth['data']['code']
63-
result = exchange_code(code_grant,client_id,client_secret)
64-
client.authenticate(result['access_token'])
62+
try:
63+
print("[i] authenticating with discord")
64+
auth = client.authorize(client_id,['rpc'])
65+
config = utils.get_config()
66+
code_grant = auth['data']['code']
67+
result = exchange_code(code_grant,client_id,client_secret)
68+
print(result)
69+
client.authenticate(result['access_token'])
70+
except Exception as e:
71+
print(e)
72+
raise AuthError
6573
else:
66-
print("already authenticated!")
67-
new_token = refresh_token(config['rpc-oauth']['refresh_token'],client_id,client_secret)
68-
client.authenticate(new_token['access_token'])
74+
try:
75+
print("[i] already authenticated! refreshing token...")
76+
new_token = refresh_token(config['rpc-oauth']['refresh_token'],client_id,client_secret)
77+
client.authenticate(new_token['access_token'])
78+
except:
79+
raise AuthError

0 commit comments

Comments
 (0)