Some preliminary fixes for launching and experiments in launchwrapper
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2022-11-04 14:40:32 +01:00
parent 2c30e2e76a
commit 22c27bb9ec
Signed by: Johannes
GPG Key ID: E76429612C2929F4
6 changed files with 26 additions and 10 deletions

View File

@ -66,7 +66,7 @@ public class GuiMain {
try {
InstanceList.forEach(instance -> instance.mds().start());
} catch (IOException e) {
Utils.LOGGER.error("Could not initialize MDS");
Utils.LOGGER.error("Could not initialize MDS", e);
}
init();
if (update == null) {

View File

@ -26,7 +26,9 @@ public class GeneralTab extends Tab {
super("General");
this.window = window;
imc = new InstanceManageControls(window.instance);
customJava = new ImBoolean(window.instance.meta().java != null);
String java = window.instance.meta().java;
customJava = new ImBoolean(java != null);
if (java != null) customJavaPath.set(java);
}
@Override

View File

@ -39,6 +39,7 @@ public class RulesAdapter {
switch (reader.nextName()) {
case "name" -> osName = reader.nextString();
case "version" -> osVersion = reader.nextString();
default -> reader.skipValue();
}
}
reader.endObject();
@ -46,10 +47,10 @@ public class RulesAdapter {
}
}
reader.endObject();
if (actionType == null || !actionType.equals("allow") && !actionType.equals("disallow")) {
if (actionType == null || (!actionType.equals("allow") && !actionType.equals("disallow"))) {
throw new JsonParseException("Unexpected action in argument: " + actionType);
}
if (!hasFeatures) valid = false;
if (hasFeatures) valid = false;
if (osName != null && !OSUtils.TYPE.getMojName().equals(osName)) valid = false;
if (osVersion != null && !System.getProperty("os.version").matches(osVersion)) valid = false;
if (actionType.equals("disallow")) valid = !valid;

View File

@ -35,6 +35,7 @@ public class InstanceList {
try {
JFiles.listTo(MetaHolder.INSTANCE_DIR, path -> {
if (!Files.isDirectory(path)) return;
if (!Files.exists(path.resolve("instance.json"))) return;
target.accept(read(path));
});
} catch (Exception e) {

View File

@ -88,11 +88,11 @@ public class InstanceLauncher {
classPath.append(File.pathSeparatorChar);
classPath.append(DownloadLibrariesStep.getLaunchWrapperArtifact().getLocalPath());
// JVM arguments
if (instance.meta().arguments != null && instance.meta().arguments.jvm != null) args.addAll(instance.meta().arguments.jvm);
if (launchType == LaunchType.Client && versionInfo.arguments != null)
args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), authInfo));
if (instance.meta().minMem != null) args.add("-Xms" + instance.meta().minMem);
if (instance.meta().maxMem != null) args.add("-Xmx" + instance.meta().maxMem);
if (instance.meta().arguments != null && instance.meta().arguments.jvm != null) args.addAll(instance.meta().arguments.jvm);
// Forceload natives
if (Files.exists(MetaHolder.FORCE_LOAD_PATH)) {
args.add("-Dinceptum.forceloadNatives=" + MetaHolder.FORCE_LOAD_PATH);
@ -224,7 +224,7 @@ public class InstanceLauncher {
// jvm args
.replace("${natives_directory}", MetaHolder.NATIVES_DIR.resolve(instance.getGameVersion()).toString())
.replace("${launcher_name}", "Inceptum")
.replace("${launcher_version}", BuildMetadata.VERSION.toString())
.replace("${launcher_version}", BuildMetadata.VERSION)
.replace("${classpath}", classPath)
.replace("${user_properties}", "{}");
}

View File

@ -1,12 +1,12 @@
package io.gitlab.jfronny.inceptum.launchwrapper;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.invoke.*;
import java.lang.reflect.Method;
import java.nio.file.*;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
public static void main(String[] args) throws Throwable {
if (args.length == 0) throw new IllegalArgumentException("Missing class argument");
System.out.println("Starting Inceptum launchwrapper");
@ -25,7 +25,19 @@ public class Main {
Class<?> mainClass = Class.forName(args[0]);
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
mainClass.getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
Method mainMethod = mainClass.getMethod("main", String[].class);
MethodHandles.Lookup lookup = MethodHandles.lookup();
Runnable main = (Runnable) LambdaMetafactory.metafactory(
lookup,
"run",
MethodType.methodType(Runnable.class),
MethodType.methodType(Void.TYPE),
MethodHandles.lookup().unreflect(mainMethod),
MethodType.methodType(Void.TYPE)
).getTarget().invokeWithArguments(new Object[]{newArgs});
Thread th = new Thread(main);
th.setName("Minecraft");
th.start();
}
private static void load(Path path) {