2021-03-27 23:10:28 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
|
|
|
|
oldexcepthook = sys.excepthook
|
|
|
|
def newexcepthook(type,value,traceback):
|
|
|
|
oldexcepthook(type,value,traceback)
|
|
|
|
input("Press ENTER to quit.")
|
|
|
|
sys.excepthook = newexcepthook
|
|
|
|
|
|
|
|
import os
|
|
|
|
p = os.path.join
|
|
|
|
pUp = os.path.dirname
|
|
|
|
s = False
|
|
|
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
|
|
|
s = os.path.realpath(sys.executable)
|
|
|
|
else:
|
|
|
|
s = os.path.realpath(__file__)
|
|
|
|
sp = pUp(s)
|
|
|
|
|
2021-03-28 00:38:06 +00:00
|
|
|
import configparser
|
2021-03-27 23:10:28 +00:00
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
import hashlib
|
|
|
|
import platform
|
|
|
|
|
|
|
|
def readJsonFile(file):
|
|
|
|
fileh = open(file,"r")
|
|
|
|
data = fileh.read()
|
|
|
|
fileh.close()
|
|
|
|
return json.loads(data)
|
|
|
|
|
|
|
|
def main():
|
2021-03-28 00:38:06 +00:00
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(os.path.splitext(s)[0] + ".ini")
|
|
|
|
os.environ["appdata"] = p(sp,"appdata")
|
|
|
|
|
|
|
|
lv = config["default"]
|
|
|
|
if lv["osName"] == "":
|
|
|
|
lv["osName"] = platform.system().lower()
|
|
|
|
if lv["osName"] == "darwin": lv["osName"] = "macos"
|
|
|
|
|
2021-03-27 23:10:28 +00:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
argSplit = arg.split("=",1)
|
|
|
|
if len(argSplit) > 1:
|
2021-03-28 00:38:06 +00:00
|
|
|
lv[argSplit[0]] = argSplit[1]
|
|
|
|
else:
|
|
|
|
lv[argSplit[0]] = True
|
2021-03-27 23:10:28 +00:00
|
|
|
|
2021-03-28 00:38:06 +00:00
|
|
|
if not lv["osName"] in ["windows","linux","macos"]:
|
|
|
|
print("Warning, unsupported OS detected: " +lv["osName"])
|
|
|
|
print("Needs to be either windows, linux or macos. Define it with osName=name in the config.")
|
2021-03-27 23:10:28 +00:00
|
|
|
print("")
|
2021-03-28 00:38:06 +00:00
|
|
|
if not "version" in lv: lv["version"] = input("Version ID: ")
|
|
|
|
if not "name" in lv: lv["name"] = input("Player name: ")
|
2021-03-27 23:10:28 +00:00
|
|
|
|
|
|
|
gamePath = p(os.environ["appdata"],".minecraft")
|
2021-03-28 00:38:06 +00:00
|
|
|
versionPath = p(gamePath,"versions",lv["version"])
|
2021-03-27 23:10:28 +00:00
|
|
|
libraryPath = p(gamePath,"libraries")
|
|
|
|
nativesPath = p(gamePath,"natives")
|
2021-03-28 00:38:06 +00:00
|
|
|
nativesOutPath = p(versionPath,"natives-" +lv["osName"])
|
2021-03-27 23:10:28 +00:00
|
|
|
assetsPath = p(gamePath,"assets")
|
|
|
|
|
|
|
|
print("Extracting natives...")
|
2021-03-28 00:38:06 +00:00
|
|
|
clientJson = readJsonFile(p(versionPath,lv["version"] + ".json"))
|
2021-03-27 23:10:28 +00:00
|
|
|
libraryList = ""
|
2021-03-27 23:34:29 +00:00
|
|
|
separator = ";"
|
2021-03-28 00:38:06 +00:00
|
|
|
if lv["osName"] != "windows": separator = ":"
|
2021-03-27 23:34:29 +00:00
|
|
|
|
2021-03-27 23:10:28 +00:00
|
|
|
for library in clientJson["libraries"]:
|
|
|
|
if "artifact" in library["downloads"]:
|
|
|
|
library["downloads"]["artifact"]["path"] = library["downloads"]["artifact"]["path"].replace("/",os.path.sep)
|
2021-03-27 23:34:29 +00:00
|
|
|
libraryList += p(libraryPath,library["downloads"]["artifact"]["path"]) + separator
|
2021-03-27 23:10:28 +00:00
|
|
|
if "classifiers" in library["downloads"]:
|
2021-03-28 00:38:06 +00:00
|
|
|
if "natives-" +lv["osName"] in library["downloads"]["classifiers"]:
|
|
|
|
native = library["downloads"]["classifiers"]["natives-" +lv["osName"]]
|
2021-03-27 23:10:28 +00:00
|
|
|
native["path"] = native["path"].replace("/",os.path.sep)
|
|
|
|
if not os.path.isdir(nativesOutPath): os.makedirs(nativesOutPath)
|
|
|
|
subprocess.run(["7z","x",p(nativesPath,native["path"]),"-o" +nativesOutPath,"-aos"],check=True,stdout=subprocess.DEVNULL)
|
|
|
|
|
2021-03-28 00:38:06 +00:00
|
|
|
libraryList += p(versionPath,lv["version"] + ".jar")
|
2021-03-27 23:10:28 +00:00
|
|
|
#print(libraryList)
|
|
|
|
|
|
|
|
launcherVariables = {}
|
2021-03-28 00:38:06 +00:00
|
|
|
launcherVariables["auth_player_name"] = lv["name"]
|
|
|
|
launcherVariables["version_name"] = lv["version"]
|
2021-03-27 23:10:28 +00:00
|
|
|
launcherVariables["game_directory"] = gamePath
|
|
|
|
launcherVariables["assets_root"] = assetsPath
|
|
|
|
launcherVariables["assets_index_name"] = clientJson["assets"]
|
|
|
|
launcherVariables["auth_access_token"] = "-"
|
2021-03-28 00:38:06 +00:00
|
|
|
launcherVariables["auth_uuid"] = hashlib.md5(lv["name"].encode('utf-8')).hexdigest()
|
2021-03-27 23:10:28 +00:00
|
|
|
launcherVariables["user_type"] = "offline"
|
|
|
|
launcherVariables["version_type"] = clientJson["type"]
|
|
|
|
|
2021-03-28 00:38:06 +00:00
|
|
|
args = json.loads(lv["jvmArguments"])
|
2021-03-27 23:10:28 +00:00
|
|
|
args.append("-Djava.library.path=" +nativesOutPath)
|
|
|
|
args.append("-cp")
|
|
|
|
args.append(libraryList)
|
|
|
|
args.append(clientJson["mainClass"])
|
|
|
|
|
|
|
|
if "arguments" in clientJson:
|
|
|
|
for arg in clientJson["arguments"]["game"]:
|
|
|
|
if type(arg) != str: continue
|
|
|
|
for var in launcherVariables:
|
|
|
|
arg = arg.replace("${" +var+ "}",launcherVariables[var])
|
|
|
|
args.append(arg)
|
|
|
|
elif "minecraftArguments" in clientJson:
|
|
|
|
margs = clientJson["minecraftArguments"].replace('"',"").split(" ")
|
|
|
|
for arg in margs:
|
|
|
|
if type(arg) != str: continue
|
|
|
|
for var in launcherVariables:
|
|
|
|
arg = arg.replace("${" +var+ "}",launcherVariables[var])
|
|
|
|
args.append(arg)
|
|
|
|
|
|
|
|
print("Launching Minecraft...")
|
2021-03-28 00:38:06 +00:00
|
|
|
if lv["console"] == "1":
|
|
|
|
subprocess.run([lv["java"]] + args,check = True)
|
|
|
|
else:
|
|
|
|
pkwargs = {
|
|
|
|
"stdout": subprocess.DEVNULL,
|
|
|
|
"stdin": subprocess.DEVNULL,
|
|
|
|
"stderr": subprocess.DEVNULL,
|
|
|
|
"close_fds": True
|
|
|
|
}
|
|
|
|
if lv["osName"] == "windows": pkwargs["creationflags"] = 0x00000008
|
|
|
|
subprocess.Popen([lv["java"] + "w"] + args,**pkwargs)
|
2021-03-27 23:10:28 +00:00
|
|
|
|
|
|
|
main()
|