forked from nixvio64/InGameRank
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
Latest commit
251 lines (206 loc) · 6.34 KB
/
Copy pathutils.py
File metadata and controls
251 lines (206 loc) · 6.34 KB
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
importsys
importos
importthreading
importwin32gui
fromPySide6.QtGuiimportQPixmap
fromPySide6.QtCoreimportQt
# shared globals
VERSION="v1.0.7"
DEBUG=False
IMPERSONATE_OPTIONS= [
"chrome120", "chrome124",
"edge99", "edge101",
]
FONT_NAME="Segoe UI"
FONT_SIZE=11
CACHE_TTL=300
TRACKER_ATTEMPTS_PER_ROUND=3
TRACKER_RETRY_WAIT=10
FADE_STEP_IN=0.3
FADE_STEP_OUT=1.0/6.0
BASE_SCREEN_W=1920
BASE_SCREEN_H=1080
OVERLAY_WIDTH_PCT=45.00
MIN_HEIGHT_PCT=7.41
HEADER_TOP_PCT=0.74
HEADER_ICON_SIZE_PCT=2.22
DIVIDER_Y_PCT=3.52
ROW_START_Y_PCT=4.26
ROW_HEIGHT_PCT=3.40
INNER_BOTTOM_PADDING_PCT=0.0
RANK_ICON_SIZE_PCT=3.52
DIVISION_HEIGHT_PCT=0.58
DIVISION_GAP_PCT=0.09
MAX_VISIBLE_PLAYERS=8
state= {
"in_match": False,
"players": [],
"lock": threading.Lock(),
}
tracker_cache= {}
pixmap_cache= {}
PLAYLIST_IMAGE_MAP= {
10: "0.png",
11: "1.png",
13: "2.png",
27: "3.png",
28: "4.png",
29: "5.png",
30: "6.png",
34: "7.png",
}
ALL_PLAYLIST_IDS= [10, 11, 13, 27, 28, 29, 30, 34, 61, 63]
# path / pixmap helpers
defresource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
try:
base_path=sys._MEIPASS
exceptException:
base_path=os.path.abspath(".")
returnos.path.join(base_path, relative_path)
defget_pixmap(folder: str, filename: str, target_w, target_h) ->QPixmap:
path=resource_path(os.path.join(folder, filename))
cache_key=f"{path}_{target_w}x{target_h}"
ifcache_keynotinpixmap_cache:
ifos.path.exists(path):
pm=QPixmap(path)
ifnotpm.isNull():
iftarget_wisNone:
scaled=pm.scaledToHeight(
target_h, Qt.TransformationMode.SmoothTransformation
)
eliftarget_hisNone:
scaled=pm.scaledToWidth(
target_w, Qt.TransformationMode.SmoothTransformation
)
else:
scaled=pm.scaled(
target_w,
target_h,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
pixmap_cache[cache_key] =scaled
else:
pixmap_cache[cache_key] =None
else:
pixmap_cache[cache_key] =None
returnpixmap_cache[cache_key]
# rank helpers
defis_bot(primary_id: str) ->bool:
ifnotprimary_id:
returnTrue
if"unknown"inprimary_id.lower():
returnTrue
if"|"notinprimary_id:
returnTrue
returnFalse
defget_platform_tag(primary_id: str) ->str:
ifis_bot(primary_id):
return"[BOT]"
plat=primary_id.split("|")[0].lower()
mapping= {
"steam": "[Steam]",
"epic": "[Epic]",
"xboxone": "[Xbox]",
"ps4": "[PSN]",
"switch": "[Switch]",
}
returnmapping.get(plat, "[?]")
defget_tier_id(rank_name: str) ->int:
ranks= [
"Unranked", "Bronze I", "Bronze II", "Bronze III",
"Silver I", "Silver II", "Silver III", "Gold I", "Gold II", "Gold III",
"Platinum I", "Platinum II", "Platinum III", "Diamond I", "Diamond II", "Diamond III",
"Champion I", "Champion II", "Champion III", "Grand Champion I", "Grand Champion II", "Grand Champion III",
"Supersonic Legend",
]
try:
returnranks.index(rank_name)
exceptValueError:
return0
defget_div_id(div_name: str) ->int:
divs= {"Division I": 1, "Division II": 2, "Division III": 3, "Division IV": 4}
returndivs.get(div_name, 0)
defget_div_color_id(tier_id: int) ->int:
if1<=tier_id<=3:
return1
elif4<=tier_id<=6:
return2
elif7<=tier_id<=9:
return3
elif10<=tier_id<=12:
return4
elif13<=tier_id<=15:
return5
elif16<=tier_id<=18:
return6
elif19<=tier_id<=21:
return7
return7
defshorten_rank(rank_str: str) ->str:
ifnotrank_str:
return"Unranked"
s=rank_str.strip()
ifs.lower() =="supersonic legend":
return"SSL"
ifs.lower() =="unranked":
return"Unranked"
roman_map= {"I": "1", "II": "2", "III": "3"}
parts=s.split()
iflen(parts) >=2:
num=roman_map.get(parts[-1].upper(), parts[-1])
if"Grand Champion"ins:
returnf"GC{num}"
else:
returnf"{parts[0][0].upper()}{num}"
returns
defget_total_matches(stats: dict) ->int:
total=0
forpidinALL_PLAYLIST_IDS:
entry=stats.get(pid)
ifentry:
total+=entry.get("matches_played", 0)
returntotal
# RL window helpers
defget_rl_window(window_title: str) ->int:
"""Returns the handle for the Rocket League window based on a given title for it."""
hwnd=win32gui.FindWindow(None, window_title)
ifnothwnd:
result= []
defenum_cb(h, _):
t=win32gui.GetWindowText(h)
ifwindow_title.lower() int.lower() andwin32gui.IsWindowVisible(h):
result.append(h)
win32gui.EnumWindows(enum_cb, None)
hwnd=result[0] ifresultelseNone
ifnothwnd:
returnNone
returnhwnd
defis_cursor_inside_window(hwnd: int) ->bool:
try:
left, top, right, bottom=win32gui.GetWindowRect(hwnd)
x, y=win32gui.GetCursorPos()
returnleft<=x<=rightandtop<=y<=bottom
exceptException:
returnTrue
defis_rl_focused(window_title: str, require_mouse_over_rl_window: bool) ->bool:
try:
hwnd=win32gui.GetForegroundWindow()
title=win32gui.GetWindowText(hwnd)
ifwindow_title.lower() notintitle.lower():
returnFalse
ifrequire_mouse_over_rl_windowandnotis_cursor_inside_window(hwnd):
returnFalse
returnTrue
exceptException:
returnFalse
# logging
deflog(msg: str, tag: str=None):
"""Print to stdout. [tag] prefix only shown when DEBUG is on. tag=\"DEBUG\" messages are silent unless DEBUG."""
iftag=="DEBUG"andnotDEBUG:
return
iftagandDEBUG:
print(f"[{tag}] {msg}")
else:
print(msg)