-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
349 lines (291 loc) · 11.7 KB
/
main.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
import webview
import modelfetch
import json
import os
import psutil
import humanize
import GPUtil
import platform
# import portablemc
from portablemc.standard import Context, Version, Watcher
from pathlib import Path
# https://github.com/mindstorm38/portablemc/blob/main/doc/API.md
# Global variables declaration
global lastaccount, firsttime, lastinstance, maximizedefault, winwidth, winheight
global demomode, multiplayer, gamechat, minmem, maxmem, javapath, jvmargs, customtheme, lastuuid
syshost = modelfetch.system.Model
print(r"""
_ _ _
| || | (_)
____ __| || | __ _ __ _ _ __ ___ ___ ___ _ __
|_ / / _` || |/ /| '__|| || '_ ` _ \ / __| / _ \ | '_ \
/ / | (_| || < | | | || | | | | |\__ \| (_) || | | |
/___| \__,_||_|\_\|_| |_||_| |_| |_||___/ \___/ |_| |_|
Beta 1.1 -Launch Update-
Written by MTSyntho Dev
""")
# Function to initialize or reset settings
def initialize_settings():
global lastaccount, firsttime, lastinstance, maximizedefault
global winwidth, winheight, demomode, multiplayer, gamechat, accounts
global minmem, maxmem, javapath, jvmargs, customtheme, configjson, lastuuid
config = {
"lastaccount": "",
"lastuuid": "",
"firsttime": 1,
"maximizedefault": False,
"winwidth": 854,
"winheight": 480,
"demomode": False,
"nomultiplayer": True,
"nogamechat": True,
"minmem": 512,
"maxmem": 1024,
"javapath": "javaw",
"jvmargs": "",
"customtheme": ""
}
accounts = {}
# File/Folder Checking
if not os.path.exists(".zdkrimson"):
print(".zdkrimson folder doesn't exist, created one just now.")
os.mkdir(".zdkrimson")
if not os.path.exists(".zdkrimson\\settings.json"):
print("Settings File may be missing! `settings.json` has been created.")
with open(".zdkrimson\\settings.json", "w") as outfile:
json.dump(config, outfile, indent=2)
if not os.path.exists(".zdkrimson\\accounts.json"):
print("Accounts File may be missing! `accounts.json` has been created.")
with open(".zdkrimson\\accounts.json", "w") as outfile:
json.dump(accounts, outfile, indent=2)
if not os.path.exists(".zdkrimson\\instances.json"):
print("Instances File may be missing! `instances.json` has been created.")
with open(".zdkrimson\\instances.json", "w") as outfile:
json.dump(accounts, outfile, indent=2)
if not os.path.exists(".zdkrimson\\lastinstance.txt"):
print("Last Open Instance File may be missing! `lastinstance.txt` has been created.")
with open(".zdkrimson\\lastinstance.txt", 'w') as outfile:
outfile.write('')
# Loading settings from JSON
try:
with open('.zdkrimson\\settings.json', 'r') as openfile:
configjson = json.load(openfile)
lastaccount = configjson['lastaccount']
lastuuid = configjson['lastuuid']
firsttime = configjson['firsttime']
maximizedefault = configjson['maximizedefault']
winwidth = configjson['winwidth']
winheight = configjson['winheight']
demomode = configjson['demomode']
nomultiplayer = configjson['multiplayer']
nogamechat = configjson['gamechat']
minmem = configjson['minmem']
maxmem = configjson['maxmem']
javapath = configjson['javapath']
jvmargs = configjson['jvmargs']
customtheme = configjson['customtheme']
print("Successfully imported 'settings.json'")
if lastaccount == "":
print("Last Used Account: Not Logged In!")
else:
print("Last Used Account:", lastaccount)
except KeyError:
print("Settings file isn't up-to-date, settings file should now be updated (info reset)")
with open(".zdkrimson\\settings.json", "w") as outfile:
json.dump(config, outfile, indent=2)
# Initialize global variables after resetting settings
lastaccount = ""
lastuuid = ""
firsttime = 1
maximizedefault = False
winwidth = 854
winheight = 480
demomode = False
nomultiplayer = True
nogamechat = True
minmem = 512
maxmem = 1024
javapath = "javaw"
jvmargs = ""
customtheme = ""
with open('.zdkrimson\\lastinstance.txt', 'r') as openfile:
global lastinstance
lastinstance = openfile.read();
print('Last Instance: ' + lastinstance)
# Initialize or reset settings
initialize_settings()
class Api:
def get_host(self):
print("System Host:", syshost)
return syshost
def get_username(self, uuid):
print("Account UUID:", uuid)
if uuid == 'recent':
return lastaccount
def get_last_account(self):
return lastaccount
def save_account_change(self, name, uuid):
print('Saving Details for Logged In Account.')
print('Account Name: ' + name)
print('Account UUID: ' + uuid)
# my brain hurt
def get_settings(self):
return configjson
def get_mem(self):
print("Total RAM:", psutil.virtual_memory().total)
print("Formatted RAM:", humanize.naturalsize(psutil.virtual_memory().total))
return humanize.naturalsize(psutil.virtual_memory().total)
def get_gpu(self):
gpus = GPUtil.getGPUs()
if not gpus:
print('No GPUs Detected.')
return 'No Dedicated GPUs Found'
else:
print('GPU:', gpus[0].name)
return gpus[0].name
def get_cpu(self):
cpu_info = platform.uname()
print('CPU:', cpu_info.processor)
return cpu_info.processor
def write_settings(self, name, data):
global maximizedefault, winwidth, winheight, demomode, multiplayer, gamechat
global minmem, maxmem, javapath, jvmargs, customtheme, lastaccount, lastuuid
if name == 'maximizedefault':
maximizedefault = data
elif name == 'lastaccount':
lastaccount = data
elif name == 'lastuuid':
lastuuid = data
elif name == 'demomode':
demomode = data
elif name == 'multiplayer':
multiplayer = data
elif name == 'gamechat':
gamechat = data
elif name == 'customtheme':
customtheme = data
elif name == 'javapath':
javapath = data
elif name == 'jvmargs':
jvmargs = data
elif name == 'minmem':
minmem = data
elif name == 'maxmem':
maxmem = data
elif name == 'winwidth':
winwidth = data
elif name == 'winheight':
winheight = data
print('Loading Settings')
def save_settings(self):
print('Saving Settings')
config = {
"lastaccount": lastaccount,
"lastuuid": lastuuid,
"firsttime": firsttime,
"maximizedefault": maximizedefault,
"winwidth": winwidth,
"winheight": winheight,
"demomode": demomode,
"multiplayer": multiplayer,
"gamechat": gamechat,
"minmem": minmem,
"maxmem": maxmem,
"javapath": javapath,
"jvmargs": jvmargs,
"customtheme": customtheme
}
print(config)
with open(".zdkrimson\\settings.json", "w") as outfile:
json.dump(config, outfile, indent=2)
print("'settings.json' Saved Successfully")
return "'settings.json' Saved Successfully"
def get_recentinstance(self):
print("Last Instance:", lastinstance)
return lastinstance
def save_recentinstance(self, name):
global lastinstance
lastinstance = name
with open(".zdkrimson\\lastinstance.txt", 'w') as outfile:
outfile.write(lastinstance)
# def offline_account(self, zdoffline):
# print('Offline Username: ' + str(zdoffline[0]))
# print('Offline UUID: ' + str(zdoffline[1]))
# print(zdoffline)
# chatgtp wrote this function cuz i struggled with appending offline_account, bruh
def offline_account(self, username, uuid):
print('Offline Username: ' + username)
print('Offline UUID: ' + uuid)
offline_account = {
"username": username,
"uuid": uuid
}
file_path = '.zdkrimson\\accounts.json'
if os.path.exists(file_path):
with open(file_path, 'r') as openfile:
try:
accountsjson = json.load(openfile)
if not isinstance(accountsjson, list):
raise ValueError("JSON data is not a list")
except (json.JSONDecodeError, ValueError) as e:
print(f"Error reading JSON file: {e}")
accountsjson = []
else:
accountsjson = []
accountsjson.append(offline_account)
with open(file_path, 'w') as openfile:
json.dump(accountsjson, openfile, indent=4)
print("New account has been appended to the file.")
def get_accounts(self):
file_path = '.zdkrimson\\accounts.json'
if os.path.exists(file_path):
with open(file_path, 'r') as openfile:
return json.load(openfile)
else:
print('Cant fetch accounts.json')
def get_instances(self):
file_path = '.zdkrimson\\instances.json'
if os.path.exists(file_path):
with open(file_path, 'r') as openfile:
return json.load(openfile)
else:
print('Cant fetch instances.json')
def add_instance(self, name, version, icon):
new_inst = {
"name": name,
"version": version,
"icon": icon
}
file_path = '.zdkrimson\\instances.json'
if os.path.exists(file_path):
with open(file_path, 'r') as openfile:
try:
instancesjson = json.load(openfile)
if not isinstance(instancesjson, list):
raise ValueError("JSON data is not a list")
except (json.JSONDecodeError, ValueError) as e:
print(f"Error reading JSON file: {e}")
instancesjson = []
else:
instancesjson = []
instancesjson.append(new_inst)
with open(file_path, 'w') as openfile:
json.dump(instancesjson, openfile, indent=4)
def launch_minecraft(self, username, uuid, instancename, version, modloader):
print(f'\nLaunching Minecraft {version} in instance {instancename} with username: {username} (uuid: {uuid})\n')
mcver = Version(version)
mccontext = Context(Path(".zdkrimson\\resources"), Path(".zdkrimson\\.minecraft"))
class MyWatcher(Watcher):
def handle(self, event) -> None:
print("Raw PortableMC Log: ", event)
mcver.set_auth_offline(username, uuid)
env = mcver.install(watcher=MyWatcher())
env.run()
# Big thanks 2 ChatGPT for making the variables work globally throughtout the project, i didnt know how to get it working.
# Instantiate Api class
api = Api()
# Create and start webview window
webview.create_window('zdkrimson', background_color="#210202", url="index.html", js_api=api)
# webview.start()
# Disable this line prior to compiling and use the one prior, please...
webview.start(debug=True)