Add config
This commit is contained in:
parent
47f9336089
commit
37bec841fd
12
minecraftLauncher.ini
Normal file
12
minecraftLauncher.ini
Normal file
@ -0,0 +1,12 @@
|
||||
[default]
|
||||
# Set the path to the java executable. Don't add a file extension.
|
||||
java=java
|
||||
|
||||
# Set the arguments to launch minecraft with. Formatted in json. Use [] for none.
|
||||
jvmArguments = ["-Xms128M","-Xmx800M"]
|
||||
|
||||
# Enable/disable console.
|
||||
console=1
|
||||
|
||||
# Override the OS name. Choose windows, linux or macos, if the detection doesn't work right.
|
||||
osName=
|
@ -17,16 +17,11 @@ else:
|
||||
s = os.path.realpath(__file__)
|
||||
sp = pUp(s)
|
||||
|
||||
import configparser
|
||||
import subprocess
|
||||
import json
|
||||
import hashlib
|
||||
import platform
|
||||
p = os.path.join
|
||||
os.environ["appdata"] = p(sp,"appdata")
|
||||
java = p(sp,"java","bin","java.exe")
|
||||
jvmArguments = ["-Xms256M","-Xmx800M"]
|
||||
osName = platform.system().lower()
|
||||
if osName == "darwin": osName = "macos"
|
||||
|
||||
def readJsonFile(file):
|
||||
fileh = open(file,"r")
|
||||
@ -35,61 +30,69 @@ def readJsonFile(file):
|
||||
return json.loads(data)
|
||||
|
||||
def main():
|
||||
global version
|
||||
global name
|
||||
global osName
|
||||
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"
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
for arg in sys.argv[1:]:
|
||||
argSplit = arg.split("=",1)
|
||||
if len(argSplit) > 1:
|
||||
globals()[argSplit[0]] = argSplit[1]
|
||||
lv[argSplit[0]] = argSplit[1]
|
||||
else:
|
||||
lv[argSplit[0]] = True
|
||||
|
||||
if not osName in ["windows","linux","macos"]:
|
||||
print("Warning, unsupported OS detected: " +osName)
|
||||
print("Needs to be either windows, linux or macos. Define it with osName=name in the commandline.")
|
||||
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 globals(): version = input("Version ID: ")
|
||||
if not "name" in globals(): name = input("Player name: ")
|
||||
if not "version" in lv: lv["version"] = input("Version ID: ")
|
||||
if not "name" in lv: lv["name"] = input("Player name: ")
|
||||
|
||||
gamePath = p(os.environ["appdata"],".minecraft")
|
||||
versionPath = p(gamePath,"versions",version)
|
||||
versionPath = p(gamePath,"versions",lv["version"])
|
||||
libraryPath = p(gamePath,"libraries")
|
||||
nativesPath = p(gamePath,"natives")
|
||||
nativesOutPath = p(versionPath,"natives")
|
||||
nativesOutPath = p(versionPath,"natives-" +lv["osName"])
|
||||
assetsPath = p(gamePath,"assets")
|
||||
|
||||
print("Extracting natives...")
|
||||
clientJson = readJsonFile(p(versionPath,version + ".json"))
|
||||
clientJson = readJsonFile(p(versionPath,lv["version"] + ".json"))
|
||||
libraryList = ""
|
||||
separator = ";"
|
||||
if osName != "windows": 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"]:
|
||||
if "natives-" +osName in library["downloads"]["classifiers"]:
|
||||
native = library["downloads"]["classifiers"]["natives-" +osName]
|
||||
if "natives-" +lv["osName"] in library["downloads"]["classifiers"]:
|
||||
native = library["downloads"]["classifiers"]["natives-" +lv["osName"]]
|
||||
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,version + ".jar")
|
||||
libraryList += p(versionPath,lv["version"] + ".jar")
|
||||
#print(libraryList)
|
||||
|
||||
launcherVariables = {}
|
||||
launcherVariables["auth_player_name"] = name
|
||||
launcherVariables["version_name"] = version
|
||||
launcherVariables["auth_player_name"] = lv["name"]
|
||||
launcherVariables["version_name"] = lv["version"]
|
||||
launcherVariables["game_directory"] = gamePath
|
||||
launcherVariables["assets_root"] = assetsPath
|
||||
launcherVariables["assets_index_name"] = clientJson["assets"]
|
||||
launcherVariables["auth_access_token"] = "-"
|
||||
launcherVariables["auth_uuid"] = hashlib.md5(name.encode('utf-8')).hexdigest()
|
||||
launcherVariables["auth_uuid"] = hashlib.md5(lv["name"].encode('utf-8')).hexdigest()
|
||||
launcherVariables["user_type"] = "offline"
|
||||
launcherVariables["version_type"] = clientJson["type"]
|
||||
|
||||
args = jvmArguments
|
||||
args = json.loads(lv["jvmArguments"])
|
||||
args.append("-Djava.library.path=" +nativesOutPath)
|
||||
args.append("-cp")
|
||||
args.append(libraryList)
|
||||
@ -110,7 +113,16 @@ def main():
|
||||
args.append(arg)
|
||||
|
||||
print("Launching Minecraft...")
|
||||
subprocess.call([java] + args)
|
||||
|
||||
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()
|
Loading…
Reference in New Issue
Block a user