Refactor[jar launcher]: rework swap thread & classpath
This commit is contained in:
1 parent
d72d84dd57
commit
7829917534
7 files changed
+126
-120
No files matched your search
@@ -43,14 +43,13 @@ public class PojavLauncher {
|
||||
}
|
||||
});
|
||||
|
||||
System.setProperty("cacio.managed.screensize", args[2]);
|
||||
try {
|
||||
// Try to initialize Caciocavallo17
|
||||
Class.forName("com.github.caciocavallosilano.cacio.ctc.CTCPreloadClassLoader");
|
||||
} catch (ClassNotFoundException e) {}
|
||||
|
||||
if (args[0].equals("--launchJar")) {
|
||||
UIKit.callback_JavaGUIViewController_launchJarFile(args[1]);
|
||||
if (args[0].equals("-jar")) {
|
||||
UIKit.callback_JavaGUIViewController_launchJarFile(args[1], Arrays.copyOfRange(args, 2, args.length));
|
||||
} else {
|
||||
launchMinecraft(args);
|
||||
}
|
||||
@@ -61,8 +60,9 @@ public class PojavLauncher {
|
||||
System.setProperty("appdir", "./spiral");
|
||||
System.setProperty("resource_dir", "./spiral/rsrc");
|
||||
|
||||
System.setProperty("glfw.windowSize", args[2]);
|
||||
String[] size = args[2].split("x");
|
||||
String sizeStr = System.getProperty("cacio.managed.screensize");
|
||||
System.setProperty("glfw.windowSize", sizeStr);
|
||||
String[] size = sizeStr.split("x");
|
||||
MCOptionUtils.load();
|
||||
MCOptionUtils.set("fullscreen", "false");
|
||||
MCOptionUtils.set("overrideWidth", size[0]);
|
||||
|
||||
@@ -29,45 +29,7 @@ public class UIKit {
|
||||
System.setProperty("os.name", osName);
|
||||
}
|
||||
|
||||
public static void callback_JavaGUIViewController_launchJarFile(final String filepath) throws Throwable {
|
||||
// Thread for refreshing the AWT buffer
|
||||
new Thread(() -> {
|
||||
Method getCurrentScreenRGB;
|
||||
try {
|
||||
try {
|
||||
getCurrentScreenRGB = Class.forName("net.java.openjdk.cacio.ctc.CTCScreen").getMethod("getCurrentScreenRGB");
|
||||
} catch (ClassNotFoundException e) {
|
||||
getCurrentScreenRGB = Class.forName("com.github.caciocavallosilano.cacio.ctc.CTCScreen").getMethod("getCurrentScreenRGB");
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
System.err.println("Failed to find class CTCScreen");
|
||||
th.printStackTrace();
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
long lastTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
int[] pixelsArray = null;
|
||||
try{
|
||||
pixelsArray = (int[])getCurrentScreenRGB.invoke(null);
|
||||
} catch (Throwable e) {}
|
||||
if (pixelsArray != null) {
|
||||
//System.out.println(java.util.Arrays.toString(pixelsArray));
|
||||
refreshAWTBuffer(pixelsArray);
|
||||
}
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - lastTime < 16) {
|
||||
try {
|
||||
Thread.sleep(16 - (currentTime - lastTime));
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastTime = currentTime;
|
||||
}
|
||||
}, "AWTFBRefreshThread").start();
|
||||
|
||||
public static void callback_JavaGUIViewController_launchJarFile(final String filepath, String[] args) throws Throwable {
|
||||
// Launch the JAR file
|
||||
String mainClassName = null;
|
||||
|
||||
@@ -78,15 +40,12 @@ public class UIKit {
|
||||
throw new IllegalArgumentException("no main manifest attribute, in \"" + filepath + "\"");
|
||||
}
|
||||
|
||||
PojavClassLoader loader = (PojavClassLoader) ClassLoader.getSystemClassLoader();
|
||||
loader.addURL(new File(filepath).toURI().toURL());
|
||||
|
||||
// LabyMod Installer uses FlatLAF which has some macOS-specific codes, so we make it think it's running on Linux.
|
||||
patch_FlatLAF_setLinux();
|
||||
|
||||
Class<?> clazz = loader.loadClass(mainClass);
|
||||
Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(mainClass);
|
||||
Method method = clazz.getMethod("main", String[].class);
|
||||
method.invoke(null, new Object[]{new String[]{}});
|
||||
method.invoke(null, new Object[]{args});
|
||||
}
|
||||
|
||||
public static void updateMCGuiScale() {
|
||||
|
||||
Reference in new issue
Block a user