Implemented JVM arguments and rules

This commit is contained in:
Fierelier 2021-03-29 12:20:57 +02:00
parent 1b27f8efca
commit c0ac09389f

View File

@ -124,6 +124,8 @@ def checkRules(ruleList):
if "arch" in rule["os"]: if "arch" in rule["os"]:
if lv["jvmArch"] != rule["os"]["arch"]: continue if lv["jvmArch"] != rule["os"]["arch"]: continue
if "version" in rule["os"]: continue
action = rule["action"] action = rule["action"]
return action return action
@ -133,9 +135,10 @@ def processVersion(versionsPath,libraryPath,nativePath,version):
clientJson = readJsonFile(p(versionPath,version + ".json")) clientJson = readJsonFile(p(versionPath,version + ".json"))
libraries = [] libraries = []
arguments = [] arguments = []
jvmArguments = []
if "inheritsFrom" in clientJson: if "inheritsFrom" in clientJson:
_,libraries,arguments = processVersion(versionsPath,libraryPath,nativePath,clientJson["inheritsFrom"]) _,libraries,arguments,jvmArguments = processVersion(versionsPath,libraryPath,nativePath,clientJson["inheritsFrom"])
for library in clientJson["libraries"]: for library in clientJson["libraries"]:
l = {} l = {}
@ -160,6 +163,7 @@ def processVersion(versionsPath,libraryPath,nativePath,version):
l["filePathOS"] = p(nativePath,native["path"].replace("/",os.path.sep)) l["filePathOS"] = p(nativePath,native["path"].replace("/",os.path.sep))
if "url" in native and native["url"] != "": if "url" in native and native["url"] != "":
l["url"] = native["url"] l["url"] = native["url"]
libraries.append(l)
native = False native = False
if "natives-" +lv["osName"] in library["downloads"]["classifiers"]: if "natives-" +lv["osName"] in library["downloads"]["classifiers"]:
@ -181,16 +185,33 @@ def processVersion(versionsPath,libraryPath,nativePath,version):
libraries.append({"type":"client","filePathOS":p(versionPath,version + ".jar")}) libraries.append({"type":"client","filePathOS":p(versionPath,version + ".jar")})
if "arguments" in clientJson: if "arguments" in clientJson:
if "game" in clientJson["arguments"]:
for arg in clientJson["arguments"]["game"]: for arg in clientJson["arguments"]["game"]:
if type(arg) != str: continue if type(arg) != str: continue
arguments.append(arg) arguments.append(arg)
if "jvm" in clientJson["arguments"]:
for arg in clientJson["arguments"]["jvm"]:
if type(arg) != str:
if "value" in arg:
if type(arg["value"]) != list:
arg["value"] = [arg["value"]]
if "rules" in arg:
if checkRules(arg["rules"]) == "allow":
for value in arg["value"]:
jvmArguments.append(value)
else:
for value in arg["value"]:
jvmArguments.append(value)
else:
jvmArguments.append(arg)
elif "minecraftArguments" in clientJson: elif "minecraftArguments" in clientJson:
margs = clientJson["minecraftArguments"].replace('"',"").split(" ") margs = clientJson["minecraftArguments"].replace('"',"").split(" ")
for arg in margs: for arg in margs:
if type(arg) != str: continue if type(arg) != str: continue
arguments.append(arg) arguments.append(arg)
return clientJson,libraries,arguments return clientJson,libraries,arguments,jvmArguments
def main(): def main():
print("Reading config...") print("Reading config...")
@ -242,7 +263,7 @@ def main():
versionsPath = p(lv["gamePath"],"versions") versionsPath = p(lv["gamePath"],"versions")
libraryPath = p(lv["gamePath"],"libraries") libraryPath = p(lv["gamePath"],"libraries")
nativePath = p(lv["gamePath"],"natives") nativePath = p(lv["gamePath"],"natives")
clientJson,libraries,arguments = processVersion(versionsPath,libraryPath,nativePath,lv["version"]) clientJson,libraries,arguments,jvmArguments = processVersion(versionsPath,libraryPath,nativePath,lv["version"])
versionPath = p(lv["gamePath"],"versions",lv["version"]) versionPath = p(lv["gamePath"],"versions",lv["version"])
nativesOutPath = p(versionPath,"natives-" +lv["osName"]+ "." +lv["jvmArch"]) nativesOutPath = p(versionPath,"natives-" +lv["osName"]+ "." +lv["jvmArch"])
@ -294,15 +315,36 @@ def main():
launcherVariables["auth_uuid"] = hashlib.md5(lv["name"].encode('utf-8')).hexdigest() launcherVariables["auth_uuid"] = hashlib.md5(lv["name"].encode('utf-8')).hexdigest()
launcherVariables["user_type"] = "offline" launcherVariables["user_type"] = "offline"
launcherVariables["version_type"] = clientJson["type"] launcherVariables["version_type"] = clientJson["type"]
launcherVariables["natives_directory"] = nativesOutPath
launcherVariables["launcher_name"] = "offline-minecraft-launcher"
launcherVariables["launcher_version"] = "0.0"
launcherVariables["classpath"] = libraryList
# legacy: # legacy:
launcherVariables["game_assets"] = assetsPath launcherVariables["game_assets"] = assetsPath
launcherVariables["auth_session"] = "-" launcherVariables["auth_session"] = "-"
args = json.loads(lv["jvmArguments"]) # JVM arguments:
args = []
djavaFound = False
cpFound = False
for arg in jvmArguments:
if arg.startswith("-Djava-library.path="): djavaFound = True
if arg == "-cp": cpFound = True
if djavaFound == False:
args.append("-Djava.library.path=" +nativesOutPath) args.append("-Djava.library.path=" +nativesOutPath)
if cpFound == False:
args.append("-cp") args.append("-cp")
args.append(libraryList) args.append(libraryList)
for arg in jvmArguments:
for var in launcherVariables:
arg = arg.replace("${" +var+ "}",launcherVariables[var])
args.append(arg)
args = args + json.loads(lv["jvmArguments"])
args.append(clientJson["mainClass"]) args.append(clientJson["mainClass"])
for arg in arguments: for arg in arguments: