-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.py
364 lines (296 loc) · 10.5 KB
/
checker.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import json
import os
import re
from termcolor import colored, cprint
# Custom module imports
import functions.display as display
import functions.formatting as formatting
import functions.knownIssues as knownIssues
import functions.logDetails as logDetails
import functions.mainVersions as mainVersions
import functions.utils as utils
os.system('color')
# Clear terminal based on OS.
clearscreen = lambda userOS: os.system("cls") if userOS == "nt" else os.system("clear")
userOS = os.name
clearscreen(userOS)
# Import config.
with open("./config.json") as config:
config = json.load(config)
# Import ids.
with open("./ids.json") as ids:
ids = json.load(ids)
# Get all files.
dirFiles = lambda: os.listdir("./")
# Look for log file.
def getLog():
fileList = dirFiles()
r = re.compile("^(.*)RagePluginHook(.*).log$", re.I)
searchedFiles = list(filter(r.match, fileList))
if not searchedFiles:
return None
return searchedFiles[0]
logFile = getLog()
# Verify the log file exists.
if not logFile:
cprint(
f'ERROR: There is no log in the current directory! Drop a log file in: "{os.getcwd()}"',
"red",
attrs=["bold"],
)
exit(1)
# Open log and assign to var.
with open(f"./{logFile}", encoding="utf8") as log:
logString = log.read()
logSplit = logString.split("\n")
# Get plugin timeout threshold.
timeout = logDetails.pluginTimeout(logString)
if not timeout:
timeout = (
f"{colored('Plugin Timeout Threshold:', 'green', attrs=['bold'])} (None Set)"
)
else:
timeout = (
f"{colored('Plugin Timeout Threshold:', 'green', attrs=['bold'])} {timeout}"
)
# Get command line options.
commandLine = logDetails.commandLineArgs(logString)
if not commandLine:
commandLine = (
f"{colored('Command Line Arguments:', 'green', attrs=['bold'])}: (None Set)"
)
else:
commandLine = colored(
"Command Line Arguments (New Line Delimited):\n", "green", attrs=["bold"]
) + ",\n\n".join(list(dict.fromkeys(commandLine)))
# Print log details to user.
display.details(commandLine, timeout)
# Check the log for known issues.
issues = knownIssues.check(config["issues"], logString)
if not issues:
issues = [colored("(No Issues Found)", "green", attrs=["bold"])]
else:
issues = [colored(x, "red", attrs=["bold"]) for x in issues]
# Print issues in log to user.
display.knownIssues(issues)
# Check the user's GTA 5 version.
gtaVersion = mainVersions.gta(logString)
if not gtaVersion:
cprint(
f"ERROR: There was an issue getting the GTA 5 version! Please report this to me (DarkVypr).",
"red",
attrs=["bold"],
)
exit(1)
compareGTAVersion = utils.compareVersion(gtaVersion, config["main"]["gta"])
if compareGTAVersion:
gtaVersion = colored(
f"GTA 5 version is out-of-date! Installed: {gtaVersion}, Latest: {config['main']['gta']}",
"red",
attrs=["bold"],
)
else:
gtaVersion = colored(
f"GTA 5 version is up-to-date! Installed: {gtaVersion}, Latest: {config['main']['gta']}",
"green",
attrs=["bold"],
)
# Check the user's RAGE version.
rageVersion = mainVersions.rage(logString)
if not rageVersion:
cprint(
f"ERROR: There was an issue getting the RAGE version! Please report this to me (DarkVypr).",
"red",
attrs=["bold"],
)
exit(1)
compareRageVersion = utils.compareVersion(rageVersion, config["main"]["rage"])
if compareRageVersion:
rageVersion = colored(
f"RAGEPluginHook version is out-of-date! Installed: {rageVersion}, Latest: {config['main']['rage']}",
"red",
attrs=["bold"],
)
else:
rageVersion = colored(
f"RAGEPluginHook version is up-to-date! Installed: {rageVersion}, Latest: {config['main']['rage']}",
"green",
attrs=["bold"],
)
# Print GTA and RAGE Version to user.
display.gtaRage(gtaVersion, rageVersion)
# Check the user's LSPDFR version.
lspdfrVersion = mainVersions.lspdfr(logString)
if not lspdfrVersion:
cprint(
f"\nERROR: There was an issue getting the LSPDFR version! The user's game probably crashed before LSPDFR was able to load.",
"red",
attrs=["bold"],
)
exit(1)
compareLSPDFRVersion = utils.compareVersion(lspdfrVersion, config["main"]["lspdfr"])
if compareLSPDFRVersion:
lspdfrVersion = colored(
f"LSPDFR version is out-of-date! Installed: {lspdfrVersion}, Latest: {config['main']['lspdfr']}",
"red",
attrs=["bold"],
)
else:
lspdfrVersion = colored(
f"LSPDFR version is up-to-date! Installed: {lspdfrVersion}, Latest: {config['main']['lspdfr']}",
"green",
attrs=["bold"],
)
# Check the user's RAGENativeUI version.
nativeuiVersion = mainVersions.nativeui(logString)
if not nativeuiVersion:
nativeuiVersion = colored(
f"RAGENativeUI version was not found in log! Installed: {nativeuiVersion}, Latest: {config['main']['nativeui']}",
"yellow",
attrs=["bold"],
)
else:
comparenativeuiVersion = utils.compareVersion(
nativeuiVersion, config["main"]["nativeui"]
)
if comparenativeuiVersion:
nativeuiVersion = colored(
f"RAGENativeUI version is out-of-date! Installed: {nativeuiVersion}, Latest: {config['main']['nativeui']}",
"red",
attrs=["bold"],
)
else:
nativeuiVersion = colored(
f"RAGENativeUI version is up-to-date! Installed: {nativeuiVersion}, Latest: {config['main']['nativeui']}",
"green",
attrs=["bold"],
)
# Print LSPDFR and NATIVEUI Version to user.
display.lspdfrNative(lspdfrVersion, nativeuiVersion)
# Plugin class.
class Plugin:
def __init__(self, name, version, id, culture, publicKeyToken):
self.name = name
self.version = version
self.id = id
self.culture = culture
self.publicKeyToken = publicKeyToken
self.hardcoded = False
self.latest = None
def getVersion(self):
parsed = utils.parseVersion(self.version)
return parsed
# Get the user's plugins and their details.
userPlugins = utils.findPlugins(logString, logSplit)
if not userPlugins:
cprint(
f"\nSCRIPT END: No plugins were found in that log! Manual review is suggested.",
"yellow",
attrs=["bold"],
)
exit(0)
else:
print(formatting.section(f"Found Plugins ({len(userPlugins)}):", True))
print(formatting.statusUpdate(f"{len(userPlugins)} plugin(s) found\n", True))
# Parse the user's plugins into classes.
userPluginClasses = []
for i in userPlugins:
id = utils.getID(ids, i[0])
userPluginClasses.append(Plugin(i[0], i[1], id, i[2], i[3]))
userPlugins = userPluginClasses
# "deprecated" is for the "remove these plugins" section, and "badPlugins" is for plugins that will error out if checked -- never use them.
deprecated = []
badPlugins = []
ignored = []
incorrect = []
# Loop through all of the plugins to check if they are incorrectly installed. Append those to a list for later use if so.
for plugin in userPlugins:
for i in config["incorrect"]:
if plugin.name == i["name"]:
badPlugins.append(plugin.name)
incorrect.append(
f"{plugin.name}, Current Folder: GTAV/plugins/LSPDFR - Correct Folder: {i['path']}"
if i["path"]
else f"{plugin.name}, Current Folder: GTAV/plugins/LSPDFR - Correct Folder: [Unknown]"
)
# Loop through all of the plugins to check if they are blacklisted. Append those to a list for later use if so.
for plugin in userPlugins:
if plugin.name in badPlugins:
continue
if plugin.name in config["blacklist"]:
badPlugins.append(plugin.name)
ignored.append(f"{plugin.name}, (Ignore because: Blacklisted)")
# Loop through all of the plugins to check if they are deprecated. Append those to a list for later use if so.
for plugin in userPlugins:
if plugin.name in badPlugins:
continue
if plugin.name in config["deprecated"]:
if config["deprecated"][plugin.name]:
deprecated.append(f'{plugin.name}, {config["deprecated"][plugin.name]}')
else:
deprecated.append(plugin.name)
badPlugins.append(plugin.name)
continue
# Loop through all of the plugins to check if they have an ID. Append those to a list for later use if so.
for plugin in userPlugins:
if plugin.name in badPlugins or config["hardcoded"].get(plugin.name):
continue
if not plugin.id:
badPlugins.append(plugin.name)
ignored.append(f"{plugin.name}, (Ignore because: No ID Available)")
# Iterate through all of the plugins and assign their versions.
for plugin in userPlugins:
if plugin.name in badPlugins:
continue
if plugin.name in config["hardcoded"]:
plugin.latest = config["hardcoded"][plugin.name]
plugin.hardcoded = True
continue
latest = utils.getLatest(plugin.id)
if not latest:
badPlugins.append(plugin.name)
ignored.append(
f"{plugin.name}, (Ignore Because: Latest Version Not Assigned From API)"
)
continue
plugin.latest = latest
# Iterate through all of the plugins and check/compare their versions.
upToDate = []
outdated = []
for plugin in userPlugins:
print(
formatting.statusUpdate(
f"checking plugin version for: {plugin.name}, Installed: {plugin.version} - Latest: {plugin.latest}",
True,
),
flush=True,
)
pluginString = (
f"{plugin.name}, Installed: {plugin.version} - Latest: {plugin.latest}"
)
if plugin.name in badPlugins:
continue
if plugin.hardcoded:
pluginString += f" {colored('[HARDCODED]', 'yellow')}"
check = utils.compareVersion(plugin.version, plugin.latest)
if check:
outdated.append(pluginString)
continue
upToDate.append(pluginString)
# Get lengths of arrays for display selection and general info.
lenUpToDate = len(upToDate)
lenOutdated = len(outdated)
lenDeprecated = len(deprecated)
lenIgnored = len(ignored)
lenIncorrect = len(incorrect)
# Print up-to-date plugins if applicable.
display.upToDate(upToDate, lenUpToDate)
# Print out-of-date plugins if applicable.
display.outdated(outdated, lenOutdated)
# Print deprecated plugins if applicable.
display.deprecated(deprecated, lenDeprecated)
# Print incorrectly installed plugins if applicable.
display.incorrect(incorrect, lenIncorrect)
# Print ignored plugins if applicable.
display.ignored(ignored, lenIgnored)
print()