@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
|
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
@ -55,21 +54,20 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractLauncher implements Launcher {
|
||||
|
||||
private static final int DEFAULT_WINDOW_WIDTH = 854;
|
||||
private static final int DEFAULT_WINDOW_HEIGHT = 480;
|
||||
private static final int DEFAULT_WINDOW_WIDTH = 854, DEFAULT_WINDOW_HEIGHT = 480;
|
||||
|
||||
// parameters, separated from ParamBucket
|
||||
protected final List<String> mcParams;
|
||||
protected final List<String> gameArgs;
|
||||
|
||||
// secondary parameters
|
||||
protected final int width, height;
|
||||
@ -79,34 +77,34 @@ public abstract class AbstractLauncher implements Launcher {
|
||||
protected final String mainClassName;
|
||||
|
||||
protected AbstractLauncher(Parameters params) {
|
||||
this.mcParams = params.getList("param", new ArrayList<String>());
|
||||
this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft");
|
||||
gameArgs = params.getList("param", new ArrayList<String>());
|
||||
mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft");
|
||||
|
||||
this.serverAddress = params.getString("serverAddress", null);
|
||||
this.serverPort = params.getString("serverPort", null);
|
||||
serverAddress = params.getString("serverAddress", null);
|
||||
serverPort = params.getString("serverPort", null);
|
||||
|
||||
String windowParams = params.getString("windowParams", null);
|
||||
|
||||
this.maximize = "max".equalsIgnoreCase(windowParams);
|
||||
if ("max".equals(windowParams) || windowParams == null) {
|
||||
maximize = windowParams != null;
|
||||
|
||||
width = DEFAULT_WINDOW_WIDTH;
|
||||
height = DEFAULT_WINDOW_HEIGHT;
|
||||
} else {
|
||||
maximize = false;
|
||||
|
||||
if (windowParams != null && !"max".equalsIgnoreCase(windowParams)) {
|
||||
String[] sizePair = StringUtils.splitStringPair('x', windowParams);
|
||||
|
||||
if (sizePair != null) {
|
||||
try {
|
||||
this.width = Integer.parseInt(sizePair[0]);
|
||||
this.height = Integer.parseInt(sizePair[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams),
|
||||
e);
|
||||
width = Integer.parseInt(sizePair[0]);
|
||||
height = Integer.parseInt(sizePair[1]);
|
||||
return;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
} else {
|
||||
throw new ParseException(
|
||||
String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams));
|
||||
}
|
||||
} else {
|
||||
this.width = DEFAULT_WINDOW_WIDTH;
|
||||
this.height = DEFAULT_WINDOW_HEIGHT;
|
||||
|
||||
throw new ParseException(windowParams, "[width]x[height]");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
@ -55,11 +54,11 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.ReflectionUtils;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
public final class StandardLauncher extends AbstractLauncher {
|
||||
|
||||
public StandardLauncher(Parameters params) {
|
||||
@ -69,27 +68,24 @@ public final class StandardLauncher extends AbstractLauncher {
|
||||
@Override
|
||||
public void launch() throws Throwable {
|
||||
// window size, title and state
|
||||
|
||||
// FIXME: there is no good way to maximize the minecraft window from here.
|
||||
// the following often breaks linux screen setups
|
||||
// mcparams.add("--fullscreen");
|
||||
|
||||
if (!this.maximize) {
|
||||
this.mcParams.add("--width");
|
||||
this.mcParams.add(Integer.toString(this.width));
|
||||
this.mcParams.add("--height");
|
||||
this.mcParams.add(Integer.toString(this.height));
|
||||
// FIXME doesn't support maximisation
|
||||
if (!maximize) {
|
||||
gameArgs.add("--width");
|
||||
gameArgs.add(Integer.toString(width));
|
||||
gameArgs.add("--height");
|
||||
gameArgs.add(Integer.toString(height));
|
||||
}
|
||||
|
||||
if (this.serverAddress != null) {
|
||||
this.mcParams.add("--server");
|
||||
this.mcParams.add(this.serverAddress);
|
||||
this.mcParams.add("--port");
|
||||
this.mcParams.add(this.serverPort);
|
||||
if (serverAddress != null) {
|
||||
gameArgs.add("--server");
|
||||
gameArgs.add(serverAddress);
|
||||
gameArgs.add("--port");
|
||||
gameArgs.add(serverPort);
|
||||
}
|
||||
|
||||
MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName);
|
||||
method.invokeExact(this.mcParams.toArray(new String[0]));
|
||||
// find and invoke the main method
|
||||
MethodHandle method = ReflectionUtils.findMainMethod(mainClassName);
|
||||
method.invokeExact(gameArgs.toArray(new String[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 flow <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
@ -55,13 +54,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@ -75,6 +67,13 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
public final class LegacyFrame extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -84,85 +83,85 @@ public final class LegacyFrame extends JFrame {
|
||||
public LegacyFrame(String title, Applet applet) {
|
||||
super(title);
|
||||
|
||||
this.launcher = new Launcher(applet);
|
||||
launcher = new Launcher(applet);
|
||||
|
||||
applet.setStub(this.launcher);
|
||||
applet.setStub(launcher);
|
||||
|
||||
try {
|
||||
this.setIconImage(ImageIO.read(new File("icon.png")));
|
||||
setIconImage(ImageIO.read(new File("icon.png")));
|
||||
} catch (IOException e) {
|
||||
Log.error("Unable to read Minecraft icon", e);
|
||||
Log.error("Failed to read window icon", e);
|
||||
}
|
||||
|
||||
this.addWindowListener(new ForceExitHandler());
|
||||
addWindowListener(new ForceExitHandler());
|
||||
}
|
||||
|
||||
public void start(String user, String session, int width, int height, boolean maximize, String serverAddress,
|
||||
String serverPort, boolean isDemo) {
|
||||
String serverPort, boolean demo) {
|
||||
// Implements support for launching in to multiplayer on classic servers using a
|
||||
// mpticket
|
||||
// file generated by an external program and stored in the instance's root
|
||||
// folder.
|
||||
// mpticket file generated by an external program and stored in the instance's
|
||||
// root folder.
|
||||
Path instanceFolder = Paths.get("..");
|
||||
Path mpticket = instanceFolder.resolve("mpticket");
|
||||
Path mpticketCorrupt = instanceFolder.resolve("mpticket.corrupt");
|
||||
|
||||
Path mpticketFile = Paths.get(System.getProperty("user.dir"), "..", "mpticket");
|
||||
|
||||
Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
|
||||
|
||||
if (Files.exists(mpticketFile)) {
|
||||
if (Files.exists(mpticket)) {
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8);
|
||||
List<String> lines = Files.readAllLines(mpticket, StandardCharsets.UTF_8);
|
||||
|
||||
if (lines.size() < 3) {
|
||||
Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.move(mpticket, mpticketCorrupt, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
Log.warning("Mpticket file is corrupted!");
|
||||
Log.warning("mpticket file is corrupted");
|
||||
} else {
|
||||
// Assumes parameters are valid and in the correct order
|
||||
this.launcher.setParameter("server", lines.get(0));
|
||||
this.launcher.setParameter("port", lines.get(1));
|
||||
this.launcher.setParameter("mppass", lines.get(2));
|
||||
launcher.setParameter("server", lines.get(0));
|
||||
launcher.setParameter("port", lines.get(1));
|
||||
launcher.setParameter("mppass", lines.get(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Unable to read mpticket file", e);
|
||||
Log.error("Failed to read mpticket file", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
this.launcher.setParameter("server", serverAddress);
|
||||
this.launcher.setParameter("port", serverPort);
|
||||
launcher.setParameter("server", serverAddress);
|
||||
launcher.setParameter("port", serverPort);
|
||||
}
|
||||
|
||||
this.launcher.setParameter("username", user);
|
||||
this.launcher.setParameter("sessionid", session);
|
||||
this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work?
|
||||
this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
|
||||
this.launcher.setParameter("demo", isDemo ? "true" : "false");
|
||||
this.launcher.setParameter("fullscreen", "false");
|
||||
launcher.setParameter("username", user);
|
||||
launcher.setParameter("sessionid", session);
|
||||
launcher.setParameter("stand-alone", true); // Show the quit button. TODO: why won't this work?
|
||||
launcher.setParameter("haspaid", true); // Some old versions need this for world saves to work.
|
||||
launcher.setParameter("demo", demo);
|
||||
launcher.setParameter("fullscreen", false);
|
||||
|
||||
this.add(this.launcher);
|
||||
add(launcher);
|
||||
|
||||
this.launcher.setPreferredSize(new Dimension(width, height));
|
||||
launcher.setPreferredSize(new Dimension(width, height));
|
||||
|
||||
this.pack();
|
||||
pack();
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setResizable(true);
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(true);
|
||||
|
||||
if (maximize)
|
||||
setExtendedState(MAXIMIZED_BOTH);
|
||||
|
||||
this.validate();
|
||||
validate();
|
||||
|
||||
this.launcher.init();
|
||||
this.launcher.start();
|
||||
launcher.init();
|
||||
launcher.start();
|
||||
|
||||
this.setVisible(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private final class ForceExitHandler extends WindowAdapter {
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent event) {
|
||||
// FIXME better solution
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -177,9 +176,9 @@ public final class LegacyFrame extends JFrame {
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (LegacyFrame.this.launcher != null) {
|
||||
LegacyFrame.this.launcher.stop();
|
||||
LegacyFrame.this.launcher.destroy();
|
||||
if (launcher != null) {
|
||||
launcher.stop();
|
||||
launcher.destroy();
|
||||
}
|
||||
|
||||
// old minecraft versions can hang without this >_<
|
||||
|
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 flow <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
@ -56,17 +55,17 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
import org.prismlauncher.launcher.impl.AbstractLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.ReflectionUtils;
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.prismlauncher.launcher.impl.AbstractLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.ReflectionUtils;
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
/**
|
||||
* Used to launch old versions that support applets.
|
||||
*/
|
||||
@ -75,51 +74,53 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
private final String user, session;
|
||||
private final String title;
|
||||
private final String appletClass;
|
||||
private final boolean usesApplet;
|
||||
private final String cwd;
|
||||
private final boolean useApplet;
|
||||
private final String gameDir;
|
||||
|
||||
public LegacyLauncher(Parameters params) {
|
||||
super(params);
|
||||
|
||||
this.user = params.getString("userName");
|
||||
this.session = params.getString("sessionId");
|
||||
this.title = params.getString("windowTitle", "Minecraft");
|
||||
this.appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||
user = params.getString("userName");
|
||||
session = params.getString("sessionId");
|
||||
title = params.getString("windowTitle", "Minecraft");
|
||||
appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||
|
||||
List<String> traits = params.getList("traits", Collections.<String>emptyList());
|
||||
this.usesApplet = !traits.contains("noapplet");
|
||||
useApplet = !traits.contains("noapplet");
|
||||
|
||||
this.cwd = System.getProperty("user.dir");
|
||||
gameDir = System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launch() throws Throwable {
|
||||
Class<?> main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName);
|
||||
Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main);
|
||||
Class<?> main = ClassLoader.getSystemClassLoader().loadClass(mainClassName);
|
||||
Field gameDirField = ReflectionUtils.findMinecraftGameDirField(main);
|
||||
|
||||
if (gameDirField == null)
|
||||
Log.warning("Could not find Minecraft path field");
|
||||
Log.warning("Could not find Minecraft folder field");
|
||||
else {
|
||||
gameDirField.setAccessible(true);
|
||||
gameDirField.set(null /* field is static, so instance is null */, new File(this.cwd));
|
||||
gameDirField.set(null, new File(gameDir));
|
||||
}
|
||||
|
||||
if (this.usesApplet) {
|
||||
Log.launcher("Launching with applet wrapper...");
|
||||
if (useApplet) {
|
||||
System.setProperty("minecraft.applet.TargetDirectory", gameDir);
|
||||
|
||||
try {
|
||||
LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass));
|
||||
LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(appletClass));
|
||||
|
||||
window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress,
|
||||
this.serverPort, this.mcParams.contains("--demo"));
|
||||
window.start(user, session, width, height, maximize, serverAddress, serverPort,
|
||||
gameArgs.contains("--demo"));
|
||||
return;
|
||||
} catch (Throwable e) {
|
||||
Log.error("Running applet wrapper failed with exception; falling back to main class", e);
|
||||
}
|
||||
}
|
||||
|
||||
MethodHandle method = ReflectionUtils.findMainEntrypoint(main);
|
||||
method.invokeExact(this.mcParams.toArray(new String[0]));
|
||||
// find and invoke the main method, this time without size parameters
|
||||
// in all versions that support applets, these are ignored
|
||||
MethodHandle method = ReflectionUtils.findMainMethod(main);
|
||||
method.invokeExact(gameArgs.toArray(new String[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user