#!/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) import configparser 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(): config = configparser.ConfigParser() config.read(os.path.splitext(s)[0] + ".ini") lv = config["default"] for var in lv: glbs = globals() for glb in glbs: lv[var] = lv[var].replace("$+" +glb+ "$",str(glbs[glb])) lcs = locals() for lc in lcs: lv[var] = lv[var].replace("$" +lc+ "$",str(lcs[lc])) if lv["osName"] == "": lv["osName"] = platform.system().lower() if lv["osName"] == "darwin": lv["osName"] = "macos" if len(sys.argv) > 1: for arg in sys.argv[1:]: argSplit = arg.split("=",1) if len(argSplit) > 1: lv[argSplit[0]] = argSplit[1] else: lv[argSplit[0]] = True 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.") print("") if not "version" in lv: lv["version"] = input("Version ID: ") if not "name" in lv: lv["name"] = input("Player name: ") versionPath = p(lv["gamePath"],"versions",lv["version"]) libraryPath = p(lv["gamePath"],"libraries") nativesPath = p(lv["gamePath"],"natives") nativesOutPath = p(versionPath,"natives-" +lv["osName"]) assetsPath = p(lv["gamePath"],"assets") print("Extracting natives...") clientJson = readJsonFile(p(versionPath,lv["version"] + ".json")) libraryList = "" separator = ";" if lv["osName"] != "windows": separator = ":" for library in clientJson["libraries"]: if "artifact" in library["downloads"]: library["downloads"]["artifact"]["path"] = library["downloads"]["artifact"]["path"].replace("/",os.path.sep) libraryList += p(libraryPath,library["downloads"]["artifact"]["path"]) + separator if "classifiers" in library["downloads"]: native = False if "natives-" +lv["osName"] in library["downloads"]["classifiers"]: native = library["downloads"]["classifiers"]["natives-" +lv["osName"]] if lv["osName"] == "macos" and native == False and "natives-osx" in library["downloads"]["classifiers"]: native = library["downloads"]["classifiers"]["natives-osx"] if native != False: 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) libraryList += p(versionPath,lv["version"] + ".jar") #print(libraryList) launcherVariables = {} launcherVariables["auth_player_name"] = lv["name"] launcherVariables["version_name"] = lv["version"] launcherVariables["game_directory"] = lv["gamePath"] launcherVariables["assets_root"] = assetsPath launcherVariables["assets_index_name"] = clientJson["assets"] launcherVariables["auth_access_token"] = "-" launcherVariables["auth_uuid"] = hashlib.md5(lv["name"].encode('utf-8')).hexdigest() launcherVariables["user_type"] = "offline" launcherVariables["version_type"] = clientJson["type"] # legacy: launcherVariables["game_assets"] = assetsPath launcherVariables["auth_session"] = "-" args = json.loads(lv["jvmArguments"]) 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...") 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) main()