Merge pull request #291 from TheKodeToad/betterjavalauncher
This commit is contained in:
commit
30607c34a1
@ -1,8 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -436,6 +437,17 @@ QStringList MinecraftInstance::javaArguments()
|
||||
return args;
|
||||
}
|
||||
|
||||
QString MinecraftInstance::getLauncher()
|
||||
{
|
||||
auto profile = m_components->getProfile();
|
||||
|
||||
// use legacy launcher if the traits are set
|
||||
if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch"))
|
||||
return "legacy";
|
||||
|
||||
return "standard";
|
||||
}
|
||||
|
||||
QMap<QString, QString> MinecraftInstance::getVariables()
|
||||
{
|
||||
QMap<QString, QString> out;
|
||||
@ -627,26 +639,13 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS
|
||||
launchScript += "sessionId " + session->session + "\n";
|
||||
}
|
||||
|
||||
// libraries and class path.
|
||||
{
|
||||
QStringList jars, nativeJars;
|
||||
profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
|
||||
for(auto file: jars)
|
||||
{
|
||||
launchScript += "cp " + file + "\n";
|
||||
}
|
||||
for(auto file: nativeJars)
|
||||
{
|
||||
launchScript += "ext " + file + "\n";
|
||||
}
|
||||
launchScript += "natives " + getNativePath() + "\n";
|
||||
}
|
||||
|
||||
for (auto trait : profile->getTraits())
|
||||
{
|
||||
launchScript += "traits " + trait + "\n";
|
||||
}
|
||||
launchScript += "launcher onesix\n";
|
||||
|
||||
launchScript += "launcher " + getLauncher() + "\n";
|
||||
|
||||
// qDebug() << "Generated launch script:" << launchScript;
|
||||
return launchScript;
|
||||
}
|
||||
@ -782,6 +781,8 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr
|
||||
out << "Window size: " + QString::number(width) + " x " + QString::number(height);
|
||||
}
|
||||
out << "";
|
||||
out << "Launcher: " + getLauncher();
|
||||
out << "";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -130,6 +131,7 @@ public:
|
||||
QString createLaunchScript(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin);
|
||||
/// get arguments passed to java
|
||||
QStringList javaArguments();
|
||||
QString getLauncher();
|
||||
|
||||
/// get variables for launch command variable substitution/environment
|
||||
QMap<QString, QString> getVariables() override;
|
||||
|
@ -42,19 +42,20 @@ MIT licensed.
|
||||
|
||||
Java launcher part for Minecraft.
|
||||
|
||||
It:
|
||||
It does the following:
|
||||
|
||||
- Starts a process
|
||||
- Waits for a launch script on stdin
|
||||
- Consumes the launch script you feed it
|
||||
- Proceeds with launch when it gets the `launcher` command
|
||||
- Waits for a launch script on stdin.
|
||||
- Consumes the launch script you feed it.
|
||||
- Proceeds with launch when it gets the `launcher` command.
|
||||
|
||||
If "abort" is sent, the process will exit.
|
||||
|
||||
This means the process is essentially idle until the final command is sent. You can, for example, attach a profiler before you send it.
|
||||
|
||||
A `legacy` and `onesix` launchers are available.
|
||||
The `standard` and `legacy` launchers are available.
|
||||
|
||||
- `standard` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title).
|
||||
- `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated.
|
||||
- `onesix` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title).
|
||||
|
||||
Example (some parts have been censored):
|
||||
|
||||
@ -64,7 +65,7 @@ mainClass net.minecraft.launchwrapper.Launch
|
||||
param --username
|
||||
param CENSORED
|
||||
param --version
|
||||
param MultiMC5
|
||||
param Prism Launcher
|
||||
param --gameDir
|
||||
param /home/peterix/minecraft/FTB/17ForgeTest/minecraft
|
||||
param --assetsDir
|
||||
@ -81,58 +82,11 @@ param --userType
|
||||
param mojang
|
||||
param --tweakClass
|
||||
param cpw.mods.fml.common.launcher.FMLTweaker
|
||||
windowTitle MultiMC: 172ForgeTest
|
||||
windowTitle Prism Launcher: 172ForgeTest
|
||||
windowParams 854x480
|
||||
userName CENSORED
|
||||
sessionId token:CENSORED:CENSORED
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/mojang/realms/1.3.5/realms-1.3.5.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/io/netty/netty-all/4.0.10.Final/netty-all-4.0.10.Final.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/google/guava/guava/16.0/guava-16.0.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/mojang/authlib/1.5.16/authlib-1.5.16.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/tv/twitch/twitch/5.16/twitch-5.16.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/minecraftforge/forge/1.7.10-10.13.0.1178/forge-1.7.10-10.13.0.1178.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/net/minecraft/launchwrapper/1.9/launchwrapper-1.9.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/typesafe/akka/akka-actor_2.11/2.3.3/akka-actor_2.11-2.3.3.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/com/typesafe/config/1.2.1/config-1.2.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-actors-migration_2.11/1.1.0/scala-actors-migration_2.11-1.1.0.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-library_2.11/1.0.2/scala-continuations-library_2.11-1.0.2.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-plugin_2.11.1/1.0.2/scala-continuations-plugin_2.11.1-1.0.2.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-parser-combinators_2.11/1.0.1/scala-parser-combinators_2.11-1.0.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-swing_2.11/1.0.1/scala-swing_2.11-1.0.1.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar
|
||||
cp /home/peterix/minecraft/FTB/libraries/lzma/lzma/0.0.1/lzma-0.0.1.jar
|
||||
ext /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl-platform/2.9.1/lwjgl-platform-2.9.1-natives-linux.jar
|
||||
ext /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar
|
||||
natives /home/peterix/minecraft/FTB/17ForgeTest/natives
|
||||
cp /home/peterix/minecraft/FTB/versions/1.7.10/1.7.10.jar
|
||||
launcher onesix
|
||||
launcher standard
|
||||
```
|
||||
|
||||
Available under `GPL-3.0-only` (with classpath exception), sublicensed from its original `Apache-2.0` codebase
|
||||
|
1
libraries/launcher/.gitignore
vendored
1
libraries/launcher/.gitignore
vendored
@ -4,3 +4,4 @@ out
|
||||
.classpath
|
||||
.idea
|
||||
.project
|
||||
bin/
|
||||
|
@ -4,18 +4,21 @@ find_package(Java 1.7 REQUIRED COMPONENTS Development)
|
||||
|
||||
include(UseJava)
|
||||
set(CMAKE_JAVA_JAR_ENTRY_POINT org.prismlauncher.EntryPoint)
|
||||
set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unchecked)
|
||||
set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7)
|
||||
|
||||
set(SRC
|
||||
org/prismlauncher/EntryPoint.java
|
||||
org/prismlauncher/Launcher.java
|
||||
org/prismlauncher/LauncherFactory.java
|
||||
org/prismlauncher/impl/OneSixLauncher.java
|
||||
org/prismlauncher/applet/LegacyFrame.java
|
||||
org/prismlauncher/launcher/Launcher.java
|
||||
org/prismlauncher/launcher/impl/AbstractLauncher.java
|
||||
org/prismlauncher/launcher/impl/StandardLauncher.java
|
||||
org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java
|
||||
org/prismlauncher/launcher/impl/legacy/LegacyFrame.java
|
||||
org/prismlauncher/exception/ParameterNotFoundException.java
|
||||
org/prismlauncher/exception/ParseException.java
|
||||
org/prismlauncher/utils/Parameters.java
|
||||
org/prismlauncher/utils/Utils.java
|
||||
org/prismlauncher/utils/ReflectionUtils.java
|
||||
org/prismlauncher/utils/logging/Level.java
|
||||
org/prismlauncher/utils/logging/Log.java
|
||||
net/minecraft/Launcher.java
|
||||
)
|
||||
add_jar(NewLaunch ${SRC})
|
||||
|
@ -1,5 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -18,24 +56,28 @@ package net.minecraft;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.applet.AppletStub;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/*
|
||||
/**
|
||||
* WARNING: This class is reflectively accessed by legacy Forge versions.
|
||||
* Changing field and method declarations without further testing is not recommended.
|
||||
* <p>
|
||||
* Changing field and method declarations without further testing is not
|
||||
* recommended.
|
||||
*/
|
||||
public final class Launcher extends Applet implements AppletStub {
|
||||
|
||||
private final Map<String, String> params = new TreeMap<>();
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Map<String, String> params = new HashMap<>();
|
||||
|
||||
private Applet wrappedApplet;
|
||||
|
||||
private URL documentBase;
|
||||
|
||||
private final URL documentBase;
|
||||
private boolean active = false;
|
||||
|
||||
public Launcher(Applet applet) {
|
||||
@ -43,35 +85,36 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
}
|
||||
|
||||
public Launcher(Applet applet, URL documentBase) {
|
||||
this.setLayout(new BorderLayout());
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
this.add(applet, "Center");
|
||||
add(applet, "Center");
|
||||
|
||||
this.wrappedApplet = applet;
|
||||
wrappedApplet = applet;
|
||||
|
||||
try {
|
||||
if (documentBase != null) {
|
||||
this.documentBase = documentBase;
|
||||
} else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) {
|
||||
if (documentBase == null) {
|
||||
if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) {
|
||||
// Special case only for Classic versions
|
||||
|
||||
this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/");
|
||||
documentBase = new URL("http://www.minecraft.net:80/game/");
|
||||
} else {
|
||||
this.documentBase = new URL("http://www.minecraft.net/game/");
|
||||
documentBase = new URL("http://www.minecraft.net/game/");
|
||||
}
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
this.documentBase = documentBase;
|
||||
}
|
||||
|
||||
public void replace(Applet applet) {
|
||||
this.wrappedApplet = applet;
|
||||
wrappedApplet = applet;
|
||||
|
||||
applet.setStub(this);
|
||||
applet.setSize(getWidth(), getHeight());
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(applet, "Center");
|
||||
setLayout(new BorderLayout());
|
||||
add(applet, "Center");
|
||||
|
||||
applet.init();
|
||||
|
||||
@ -82,32 +125,38 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
validate();
|
||||
}
|
||||
|
||||
public void setParameter(String name, String value) {
|
||||
params.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
String param = params.get(name);
|
||||
|
||||
if (param != null)
|
||||
return param;
|
||||
|
||||
try {
|
||||
return super.getParameter(name);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appletResize(int width, int height) {
|
||||
wrappedApplet.resize(width, height);
|
||||
public URL getDocumentBase() {
|
||||
return documentBase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getCodeBase() {
|
||||
try {
|
||||
return new URL("http://www.minecraft.net/game/");
|
||||
} catch (MalformedURLException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String key) {
|
||||
String param = params.get(key);
|
||||
|
||||
if (param != null)
|
||||
return param;
|
||||
|
||||
try {
|
||||
return super.getParameter(key);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,8 +165,8 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(Dimension d) {
|
||||
wrappedApplet.resize(d);
|
||||
public void resize(Dimension size) {
|
||||
wrappedApplet.resize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,33 +189,37 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
wrappedApplet.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getCodeBase() {
|
||||
try {
|
||||
return new URL("http://www.minecraft.net/game/");
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public void appletResize(int width, int height) {
|
||||
wrappedApplet.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDocumentBase() {
|
||||
return documentBase;
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
|
||||
wrappedApplet.setVisible(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
super.setVisible(b);
|
||||
|
||||
wrappedApplet.setVisible(b);
|
||||
public void paint(Graphics graphics) {
|
||||
}
|
||||
|
||||
public void update(Graphics paramGraphics) {}
|
||||
@Override
|
||||
public void update(Graphics graphics) {
|
||||
}
|
||||
|
||||
public void paint(Graphics paramGraphics) {}
|
||||
public void setParameter(String key, String value) {
|
||||
params.put(key, value);
|
||||
}
|
||||
|
||||
public void setParameter(String key, boolean value) {
|
||||
setParameter(key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea, <fr3shtea@outlook.com>
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -52,113 +54,125 @@
|
||||
|
||||
package org.prismlauncher;
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.impl.StandardLauncher;
|
||||
import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
public final class EntryPoint {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("EntryPoint");
|
||||
|
||||
private final Parameters params = new Parameters();
|
||||
|
||||
public static void main(String[] args) {
|
||||
EntryPoint listener = new EntryPoint();
|
||||
ExitCode code = listen();
|
||||
|
||||
int retCode = listener.listen();
|
||||
if (code != ExitCode.NORMAL) {
|
||||
Log.fatal("Exiting with " + code);
|
||||
|
||||
if (retCode != 0) {
|
||||
LOGGER.info("Exiting with " + retCode);
|
||||
|
||||
System.exit(retCode);
|
||||
System.exit(code.numeric);
|
||||
}
|
||||
}
|
||||
|
||||
private Action parseLine(String inData) throws ParseException {
|
||||
String[] tokens = inData.split("\\s+", 2);
|
||||
private static ExitCode listen() {
|
||||
Parameters params = new Parameters();
|
||||
PreLaunchAction action = PreLaunchAction.PROCEED;
|
||||
|
||||
if (tokens.length == 0)
|
||||
throw new ParseException("Unexpected empty string!");
|
||||
|
||||
switch (tokens[0]) {
|
||||
case "launch": {
|
||||
return Action.Launch;
|
||||
}
|
||||
|
||||
case "abort": {
|
||||
return Action.Abort;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (tokens.length != 2)
|
||||
throw new ParseException("Error while parsing:" + inData);
|
||||
|
||||
params.add(tokens[0], tokens[1]);
|
||||
|
||||
return Action.Proceed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int listen() {
|
||||
Action action = Action.Proceed;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
System.in,
|
||||
StandardCharsets.UTF_8
|
||||
))) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
|
||||
while (action == Action.Proceed) {
|
||||
if ((line = reader.readLine()) != null) {
|
||||
action = parseLine(line);
|
||||
} else {
|
||||
action = Action.Abort;
|
||||
while (action == PreLaunchAction.PROCEED) {
|
||||
if ((line = reader.readLine()) != null)
|
||||
action = parseLine(line, params);
|
||||
else
|
||||
action = PreLaunchAction.ABORT;
|
||||
}
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Launcher ABORT due to exception:", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.fatal("Aborting due to wrong argument", e);
|
||||
|
||||
return 1;
|
||||
return ExitCode.ILLEGAL_ARGUMENT;
|
||||
} catch (Throwable e) {
|
||||
Log.fatal("Aborting due to exception", e);
|
||||
|
||||
return ExitCode.ABORT;
|
||||
}
|
||||
|
||||
// Main loop
|
||||
if (action == Action.Abort) {
|
||||
LOGGER.info("Launch aborted by the launcher.");
|
||||
if (action == PreLaunchAction.ABORT) {
|
||||
Log.fatal("Launch aborted by the launcher");
|
||||
|
||||
return 1;
|
||||
return ExitCode.ABORT;
|
||||
}
|
||||
|
||||
try {
|
||||
Launcher launcher =
|
||||
LauncherFactory
|
||||
.getInstance()
|
||||
.createLauncher(params);
|
||||
Launcher launcher;
|
||||
String type = params.getString("launcher");
|
||||
|
||||
switch (type) {
|
||||
case "standard":
|
||||
launcher = new StandardLauncher(params);
|
||||
break;
|
||||
|
||||
case "legacy":
|
||||
launcher = new LegacyLauncher(params);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid launcher type: " + type);
|
||||
}
|
||||
|
||||
launcher.launch();
|
||||
|
||||
return 0;
|
||||
return ExitCode.NORMAL;
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.log(Level.SEVERE, "Wrong argument.", e);
|
||||
Log.fatal("Illegal argument", e);
|
||||
|
||||
return 1;
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
|
||||
return ExitCode.ILLEGAL_ARGUMENT;
|
||||
} catch (Throwable e) {
|
||||
Log.fatal("Exception caught from launcher", e);
|
||||
|
||||
return 1;
|
||||
return ExitCode.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
Proceed,
|
||||
Launch,
|
||||
Abort
|
||||
private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException {
|
||||
switch (input) {
|
||||
case "":
|
||||
break;
|
||||
|
||||
case "launch":
|
||||
return PreLaunchAction.LAUNCH;
|
||||
|
||||
case "abort":
|
||||
return PreLaunchAction.ABORT;
|
||||
|
||||
default:
|
||||
String[] pair = input.split(" ", 2);
|
||||
|
||||
if (pair.length != 2)
|
||||
throw new ParseException(input, "[key] [value]");
|
||||
|
||||
params.add(pair[0], pair[1]);
|
||||
}
|
||||
|
||||
return PreLaunchAction.PROCEED;
|
||||
}
|
||||
|
||||
private enum PreLaunchAction {
|
||||
PROCEED, LAUNCH, ABORT
|
||||
}
|
||||
|
||||
private enum ExitCode {
|
||||
NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65);
|
||||
|
||||
private final int numeric;
|
||||
|
||||
ExitCode(int numeric) {
|
||||
this.numeric = numeric;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher;
|
||||
|
||||
public interface Launcher {
|
||||
|
||||
void launch() throws Exception;
|
||||
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.applet;
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class LegacyFrame extends Frame {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("LegacyFrame");
|
||||
|
||||
private final Launcher appletWrap;
|
||||
|
||||
public LegacyFrame(String title, Applet mcApplet) {
|
||||
super(title);
|
||||
|
||||
appletWrap = new Launcher(mcApplet);
|
||||
|
||||
mcApplet.setStub(appletWrap);
|
||||
|
||||
try {
|
||||
setIconImage(ImageIO.read(new File("icon.png")));
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.WARNING, "Unable to read Minecraft icon!", e);
|
||||
}
|
||||
|
||||
addWindowListener(new ForceExitHandler());
|
||||
}
|
||||
|
||||
public void start (
|
||||
String user,
|
||||
String session,
|
||||
int winSizeW,
|
||||
int winSizeH,
|
||||
boolean maximize,
|
||||
String serverAddress,
|
||||
String serverPort,
|
||||
boolean isDemo
|
||||
) {
|
||||
// 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.
|
||||
|
||||
Path mpticketFile =
|
||||
Paths.get(System.getProperty("user.dir"), "..", "mpticket");
|
||||
|
||||
Path mpticketFileCorrupt =
|
||||
Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
|
||||
|
||||
if (Files.exists(mpticketFile)) {
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8);
|
||||
|
||||
if (lines.size() < 3) {
|
||||
Files.move(
|
||||
mpticketFile,
|
||||
mpticketFileCorrupt,
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
);
|
||||
|
||||
LOGGER.warning("Mpticket file is corrupted!");
|
||||
} else {
|
||||
// Assumes parameters are valid and in the correct order
|
||||
appletWrap.setParameter("server", lines.get(0));
|
||||
appletWrap.setParameter("port", lines.get(1));
|
||||
appletWrap.setParameter("mppass", lines.get(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
appletWrap.setParameter("server", serverAddress);
|
||||
appletWrap.setParameter("port", serverPort);
|
||||
}
|
||||
|
||||
appletWrap.setParameter("username", user);
|
||||
appletWrap.setParameter("sessionid", session);
|
||||
appletWrap.setParameter("stand-alone", "true"); // Show the quit button.
|
||||
appletWrap.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
|
||||
appletWrap.setParameter("demo", isDemo ? "true" : "false");
|
||||
appletWrap.setParameter("fullscreen", "false");
|
||||
|
||||
add(appletWrap);
|
||||
|
||||
appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH));
|
||||
|
||||
pack();
|
||||
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(true);
|
||||
|
||||
if (maximize)
|
||||
this.setExtendedState(MAXIMIZED_BOTH);
|
||||
|
||||
validate();
|
||||
|
||||
appletWrap.init();
|
||||
appletWrap.start();
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private final class ForceExitHandler extends WindowAdapter {
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(30000L);
|
||||
} catch (InterruptedException localInterruptedException) {
|
||||
localInterruptedException.printStackTrace();
|
||||
}
|
||||
|
||||
LOGGER.info("Forcing exit!");
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (appletWrap != null) {
|
||||
appletWrap.stop();
|
||||
appletWrap.destroy();
|
||||
}
|
||||
|
||||
// old minecraft versions can hang without this >_<
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.exception;
|
||||
|
||||
public final class ParameterNotFoundException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ParameterNotFoundException(String key) {
|
||||
super("Unknown parameter name: " + key);
|
||||
super(String.format("Required parameter '%s' was not found", key));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,25 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.exception;
|
||||
|
||||
public final class ParseException extends IllegalArgumentException {
|
||||
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ParseException(String input, String format) {
|
||||
super(String.format("For input '%s' - should match '%s'", input, format));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,190 +0,0 @@
|
||||
/* Copyright 2012-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.impl;
|
||||
|
||||
import org.prismlauncher.Launcher;
|
||||
import org.prismlauncher.applet.LegacyFrame;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.Utils;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class OneSixLauncher implements Launcher {
|
||||
|
||||
private static final int DEFAULT_WINDOW_WIDTH = 854;
|
||||
private static final int DEFAULT_WINDOW_HEIGHT = 480;
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("OneSixLauncher");
|
||||
|
||||
// parameters, separated from ParamBucket
|
||||
private final List<String> mcParams;
|
||||
private final List<String> traits;
|
||||
private final String appletClass;
|
||||
private final String mainClass;
|
||||
private final String userName, sessionId;
|
||||
private final String windowTitle;
|
||||
|
||||
// secondary parameters
|
||||
private final int winSizeW;
|
||||
private final int winSizeH;
|
||||
private final boolean maximize;
|
||||
private final String cwd;
|
||||
|
||||
private final String serverAddress;
|
||||
private final String serverPort;
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public OneSixLauncher(Parameters params) {
|
||||
classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
mcParams = params.allSafe("param", new ArrayList<String>());
|
||||
mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
|
||||
appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||
traits = params.allSafe("traits", new ArrayList<String>());
|
||||
|
||||
userName = params.first("userName");
|
||||
sessionId = params.first("sessionId");
|
||||
windowTitle = params.firstSafe("windowTitle", "Minecraft");
|
||||
|
||||
serverAddress = params.firstSafe("serverAddress", null);
|
||||
serverPort = params.firstSafe("serverPort", null);
|
||||
|
||||
cwd = System.getProperty("user.dir");
|
||||
|
||||
String windowParams = params.firstSafe("windowParams", null);
|
||||
|
||||
if (windowParams != null) {
|
||||
String[] dimStrings = windowParams.split("x");
|
||||
|
||||
if (windowParams.equalsIgnoreCase("max")) {
|
||||
maximize = true;
|
||||
|
||||
winSizeW = DEFAULT_WINDOW_WIDTH;
|
||||
winSizeH = DEFAULT_WINDOW_HEIGHT;
|
||||
} else if (dimStrings.length == 2) {
|
||||
maximize = false;
|
||||
|
||||
winSizeW = Integer.parseInt(dimStrings[0]);
|
||||
winSizeH = Integer.parseInt(dimStrings[1]);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams);
|
||||
}
|
||||
} else {
|
||||
maximize = false;
|
||||
|
||||
winSizeW = DEFAULT_WINDOW_WIDTH;
|
||||
winSizeH = DEFAULT_WINDOW_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeMain(Class<?> mainClass) throws Exception {
|
||||
Method method = mainClass.getMethod("main", String[].class);
|
||||
|
||||
method.invoke(null, (Object) mcParams.toArray(new String[0]));
|
||||
}
|
||||
|
||||
private void legacyLaunch() throws Exception {
|
||||
// Get the Minecraft Class and set the base folder
|
||||
Class<?> minecraftClass = classLoader.loadClass(mainClass);
|
||||
|
||||
Field baseDirField = Utils.getMinecraftBaseDirField(minecraftClass);
|
||||
|
||||
if (baseDirField == null) {
|
||||
LOGGER.warning("Could not find Minecraft path field.");
|
||||
} else {
|
||||
baseDirField.setAccessible(true);
|
||||
|
||||
baseDirField.set(null, new File(cwd));
|
||||
}
|
||||
|
||||
System.setProperty("minecraft.applet.TargetDirectory", cwd);
|
||||
|
||||
if (!traits.contains("noapplet")) {
|
||||
LOGGER.info("Launching with applet wrapper...");
|
||||
|
||||
try {
|
||||
Class<?> mcAppletClass = classLoader.loadClass(appletClass);
|
||||
|
||||
Applet mcApplet = (Applet) mcAppletClass.getConstructor().newInstance();
|
||||
|
||||
LegacyFrame mcWindow = new LegacyFrame(windowTitle, mcApplet);
|
||||
|
||||
mcWindow.start(
|
||||
userName,
|
||||
sessionId,
|
||||
winSizeW,
|
||||
winSizeH,
|
||||
maximize,
|
||||
serverAddress,
|
||||
serverPort,
|
||||
mcParams.contains("--demo")
|
||||
);
|
||||
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Applet wrapper failed: ", e);
|
||||
|
||||
LOGGER.warning("Falling back to using main class.");
|
||||
}
|
||||
}
|
||||
|
||||
invokeMain(minecraftClass);
|
||||
}
|
||||
|
||||
private void launchWithMainClass() throws Exception {
|
||||
// window size, title and state, onesix
|
||||
|
||||
// FIXME: there is no good way to maximize the minecraft window in onesix.
|
||||
// the following often breaks linux screen setups
|
||||
// mcparams.add("--fullscreen");
|
||||
|
||||
if (!maximize) {
|
||||
mcParams.add("--width");
|
||||
mcParams.add(Integer.toString(winSizeW));
|
||||
mcParams.add("--height");
|
||||
mcParams.add(Integer.toString(winSizeH));
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
mcParams.add("--server");
|
||||
mcParams.add(serverAddress);
|
||||
mcParams.add("--port");
|
||||
mcParams.add(serverPort);
|
||||
}
|
||||
|
||||
invokeMain(classLoader.loadClass(mainClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launch() throws Exception {
|
||||
if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch")) {
|
||||
// legacy launch uses the applet wrapper
|
||||
legacyLaunch();
|
||||
} else {
|
||||
// normal launch just calls main()
|
||||
launchWithMainClass();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
libraries/launcher/org/prismlauncher/launcher/Launcher.java
Normal file
44
libraries/launcher/org/prismlauncher/launcher/Launcher.java
Normal file
@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.launcher;
|
||||
|
||||
public interface Launcher {
|
||||
|
||||
void launch() throws Throwable;
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
public abstract class AbstractLauncher implements Launcher {
|
||||
|
||||
private static final int DEFAULT_WINDOW_WIDTH = 854, DEFAULT_WINDOW_HEIGHT = 480;
|
||||
|
||||
// parameters, separated from ParamBucket
|
||||
protected final List<String> gameArgs;
|
||||
|
||||
// secondary parameters
|
||||
protected final int width, height;
|
||||
protected final boolean maximize;
|
||||
protected final String serverAddress, serverPort;
|
||||
|
||||
protected final String mainClassName;
|
||||
|
||||
protected AbstractLauncher(Parameters params) {
|
||||
gameArgs = params.getList("param", new ArrayList<String>());
|
||||
mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft");
|
||||
|
||||
serverAddress = params.getString("serverAddress", null);
|
||||
serverPort = params.getString("serverPort", null);
|
||||
|
||||
String windowParams = params.getString("windowParams", null);
|
||||
|
||||
if ("max".equals(windowParams) || windowParams == null) {
|
||||
maximize = windowParams != null;
|
||||
|
||||
width = DEFAULT_WINDOW_WIDTH;
|
||||
height = DEFAULT_WINDOW_HEIGHT;
|
||||
} else {
|
||||
maximize = false;
|
||||
|
||||
String[] sizePair = windowParams.split("x", 2);
|
||||
|
||||
if (sizePair.length == 2) {
|
||||
try {
|
||||
width = Integer.parseInt(sizePair[0]);
|
||||
height = Integer.parseInt(sizePair[1]);
|
||||
return;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new ParseException(windowParams, "[width]x[height]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.ReflectionUtils;
|
||||
|
||||
public final class StandardLauncher extends AbstractLauncher {
|
||||
|
||||
public StandardLauncher(Parameters params) {
|
||||
super(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launch() throws Throwable {
|
||||
// window size, title and state
|
||||
// FIXME doesn't support maximisation
|
||||
if (!maximize) {
|
||||
gameArgs.add("--width");
|
||||
gameArgs.add(Integer.toString(width));
|
||||
gameArgs.add("--height");
|
||||
gameArgs.add(Integer.toString(height));
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
gameArgs.add("--server");
|
||||
gameArgs.add(serverAddress);
|
||||
gameArgs.add("--port");
|
||||
gameArgs.add(serverPort);
|
||||
}
|
||||
|
||||
// find and invoke the main method
|
||||
MethodHandle method = ReflectionUtils.findMainMethod(mainClassName);
|
||||
method.invokeExact(gameArgs.toArray(new String[0]));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
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;
|
||||
|
||||
private final Launcher launcher;
|
||||
|
||||
public LegacyFrame(String title, Applet applet) {
|
||||
super(title);
|
||||
|
||||
launcher = new Launcher(applet);
|
||||
|
||||
applet.setStub(launcher);
|
||||
|
||||
try {
|
||||
setIconImage(ImageIO.read(new File("icon.png")));
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to read window icon", e);
|
||||
}
|
||||
|
||||
addWindowListener(new ForceExitHandler());
|
||||
}
|
||||
|
||||
public void start(String user, String session, int width, int height, boolean maximize, String serverAddress,
|
||||
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.
|
||||
Path instanceFolder = Paths.get("..");
|
||||
Path mpticket = instanceFolder.resolve("mpticket");
|
||||
Path mpticketCorrupt = instanceFolder.resolve("mpticket.corrupt");
|
||||
|
||||
if (Files.exists(mpticket)) {
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(mpticket, StandardCharsets.UTF_8);
|
||||
|
||||
if (lines.size() < 3) {
|
||||
Files.move(mpticket, mpticketCorrupt, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
Log.warning("mpticket file is corrupted");
|
||||
} else {
|
||||
// Assumes parameters are valid and in the correct order
|
||||
launcher.setParameter("server", lines.get(0));
|
||||
launcher.setParameter("port", lines.get(1));
|
||||
launcher.setParameter("mppass", lines.get(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to read mpticket file", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
launcher.setParameter("server", serverAddress);
|
||||
launcher.setParameter("port", serverPort);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
add(launcher);
|
||||
|
||||
launcher.setPreferredSize(new Dimension(width, height));
|
||||
|
||||
pack();
|
||||
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(true);
|
||||
|
||||
if (maximize)
|
||||
setExtendedState(MAXIMIZED_BOTH);
|
||||
|
||||
validate();
|
||||
|
||||
launcher.init();
|
||||
launcher.start();
|
||||
|
||||
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() {
|
||||
try {
|
||||
Thread.sleep(30000L);
|
||||
} catch (InterruptedException e) {
|
||||
Log.error("Thread interrupted", e);
|
||||
}
|
||||
|
||||
Log.warning("Forcing exit");
|
||||
System.exit(0);
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (launcher != null) {
|
||||
launcher.stop();
|
||||
launcher.destroy();
|
||||
}
|
||||
|
||||
// old minecraft versions can hang without this >_<
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* 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>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
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.
|
||||
*/
|
||||
public final class LegacyLauncher extends AbstractLauncher {
|
||||
|
||||
private final String user, session;
|
||||
private final String title;
|
||||
private final String appletClass;
|
||||
private final boolean useApplet;
|
||||
private final String gameDir;
|
||||
|
||||
public LegacyLauncher(Parameters params) {
|
||||
super(params);
|
||||
|
||||
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());
|
||||
useApplet = !traits.contains("noapplet");
|
||||
|
||||
gameDir = System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launch() throws Throwable {
|
||||
Class<?> main = ClassLoader.getSystemClassLoader().loadClass(mainClassName);
|
||||
Field gameDirField = ReflectionUtils.findMinecraftGameDirField(main);
|
||||
|
||||
if (gameDirField == null)
|
||||
Log.warning("Could not find Minecraft folder field");
|
||||
else {
|
||||
gameDirField.setAccessible(true);
|
||||
gameDirField.set(null, new File(gameDir));
|
||||
}
|
||||
|
||||
if (useApplet) {
|
||||
System.setProperty("minecraft.applet.TargetDirectory", gameDir);
|
||||
|
||||
try {
|
||||
LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(appletClass));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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]));
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
* 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>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -16,31 +54,31 @@
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
import org.prismlauncher.exception.ParameterNotFoundException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.prismlauncher.exception.ParameterNotFoundException;
|
||||
|
||||
public final class Parameters {
|
||||
|
||||
private final Map<String, List<String>> paramsMap = new HashMap<>();
|
||||
private final Map<String, List<String>> map = new HashMap<>();
|
||||
|
||||
public void add(String key, String value) {
|
||||
List<String> params = paramsMap.get(key);
|
||||
List<String> params = map.get(key);
|
||||
|
||||
if (params == null) {
|
||||
params = new ArrayList<>();
|
||||
|
||||
paramsMap.put(key, params);
|
||||
map.put(key, params);
|
||||
}
|
||||
|
||||
params.add(value);
|
||||
}
|
||||
|
||||
public List<String> all(String key) throws ParameterNotFoundException {
|
||||
List<String> params = paramsMap.get(key);
|
||||
public List<String> getList(String key) throws ParameterNotFoundException {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
if (params == null)
|
||||
throw new ParameterNotFoundException(key);
|
||||
@ -48,8 +86,8 @@ public final class Parameters {
|
||||
return params;
|
||||
}
|
||||
|
||||
public List<String> allSafe(String key, List<String> def) {
|
||||
List<String> params = paramsMap.get(key);
|
||||
public List<String> getList(String key, List<String> def) {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
if (params == null || params.isEmpty())
|
||||
return def;
|
||||
@ -57,8 +95,8 @@ public final class Parameters {
|
||||
return params;
|
||||
}
|
||||
|
||||
public String first(String key) throws ParameterNotFoundException {
|
||||
List<String> list = all(key);
|
||||
public String getString(String key) throws ParameterNotFoundException {
|
||||
List<String> list = getList(key);
|
||||
|
||||
if (list.isEmpty())
|
||||
throw new ParameterNotFoundException(key);
|
||||
@ -66,8 +104,8 @@ public final class Parameters {
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
public String firstSafe(String key, String def) {
|
||||
List<String> params = paramsMap.get(key);
|
||||
public String getString(String key, String def) {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
if (params == null || params.isEmpty())
|
||||
return def;
|
||||
|
154
libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java
Normal file
154
libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java
Normal file
@ -0,0 +1,154 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
public final class ReflectionUtils {
|
||||
|
||||
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
||||
private static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
||||
|
||||
/**
|
||||
* Construct a Java applet by its class name.
|
||||
*
|
||||
* @param clazz The class name
|
||||
* @return The applet instance
|
||||
* @throws Throwable
|
||||
*/
|
||||
public static Applet createAppletClass(String clazz) throws Throwable {
|
||||
Class<?> appletClass = LOADER.loadClass(clazz);
|
||||
|
||||
MethodHandle appletConstructor = LOOKUP.findConstructor(appletClass, MethodType.methodType(void.class));
|
||||
return (Applet) appletConstructor.invoke();
|
||||
}
|
||||
|
||||
/**
|
||||
* Best guess of the game directory field within net.minecraft.client.Minecraft.
|
||||
* Designed for legacy versions - newer versions do not use a static field.
|
||||
*
|
||||
* @param clazz The class
|
||||
* @return The first field matching criteria
|
||||
*/
|
||||
public static Field findMinecraftGameDirField(Class<?> clazz) {
|
||||
Log.debug("Resolving minecraft game directory field");
|
||||
|
||||
// search for private static File
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getType() != File.class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int fieldModifiers = field.getModifiers();
|
||||
|
||||
if (!Modifier.isStatic(fieldModifiers)) {
|
||||
Log.debug("Rejecting field " + field.getName() + " because it is not static");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Modifier.isPrivate(fieldModifiers)) {
|
||||
Log.debug("Rejecting field " + field.getName() + " because it is not private");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Modifier.isFinal(fieldModifiers)) {
|
||||
Log.debug("Rejecting field " + field.getName() + " because it is final");
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.debug("Identified field " + field.getName() + " to match conditions for game directory field");
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the main method within a class.
|
||||
*
|
||||
* @param clazz The class
|
||||
* @return A method matching the descriptor of a main method
|
||||
* @throws ClassNotFoundException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static MethodHandle findMainMethod(Class<?> clazz) throws NoSuchMethodException, IllegalAccessException {
|
||||
return LOOKUP.findStatic(clazz, "main", MethodType.methodType(void.class, String[].class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the main method within a class by its name.
|
||||
*
|
||||
* @param clazz The class name
|
||||
* @return A method matching the descriptor of a main method
|
||||
* @throws ClassNotFoundException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static MethodHandle findMainMethod(String clazz)
|
||||
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException {
|
||||
return findMainMethod(LOADER.loadClass(clazz));
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class Utils {
|
||||
|
||||
private Utils() {}
|
||||
|
||||
/**
|
||||
* Finds a field that looks like a Minecraft base folder in a supplied class
|
||||
*
|
||||
* @param clazz the class to scan
|
||||
*/
|
||||
public static Field getMinecraftBaseDirField(Class<?> clazz) {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
// Has to be File
|
||||
if (f.getType() != File.class)
|
||||
continue;
|
||||
|
||||
// And Private Static.
|
||||
if (!Modifier.isStatic(f.getModifiers()) || !Modifier.isPrivate(f.getModifiers()))
|
||||
continue;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea, <fr3shtea@outlook.com>
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -33,48 +33,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher;
|
||||
package org.prismlauncher.utils.logging;
|
||||
|
||||
import org.prismlauncher.impl.OneSixLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
public enum Level {
|
||||
LAUNCHER("Launcher"),
|
||||
DEBUG("Debug"),
|
||||
INFO("Info"),
|
||||
MESSAGE("Message"),
|
||||
WARNING("Warning"),
|
||||
ERROR("Error", true),
|
||||
FATAL("Fatal", true);
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
String name;
|
||||
boolean stderr;
|
||||
|
||||
public final class LauncherFactory {
|
||||
|
||||
private static final LauncherFactory INSTANCE = new LauncherFactory();
|
||||
|
||||
private final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
|
||||
|
||||
private LauncherFactory() {
|
||||
launcherRegistry.put("onesix", new LauncherProvider() {
|
||||
@Override
|
||||
public Launcher provide(Parameters parameters) {
|
||||
return new OneSixLauncher(parameters);
|
||||
}
|
||||
});
|
||||
Level(String name) {
|
||||
this(name, false);
|
||||
}
|
||||
|
||||
public Launcher createLauncher(Parameters parameters) {
|
||||
String name = parameters.first("launcher");
|
||||
|
||||
LauncherProvider launcherProvider = launcherRegistry.get(name);
|
||||
|
||||
if (launcherProvider == null)
|
||||
throw new IllegalArgumentException("Invalid launcher type: " + name);
|
||||
|
||||
return launcherProvider.provide(parameters);
|
||||
}
|
||||
|
||||
public static LauncherFactory getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public interface LauncherProvider {
|
||||
|
||||
Launcher provide(Parameters parameters);
|
||||
|
||||
Level(String name, boolean stderr) {
|
||||
this.name = name;
|
||||
this.stderr = stderr;
|
||||
}
|
||||
|
||||
}
|
104
libraries/launcher/org/prismlauncher/utils/logging/Log.java
Normal file
104
libraries/launcher/org/prismlauncher/utils/logging/Log.java
Normal file
@ -0,0 +1,104 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.utils.logging;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* Used to print messages with different levels used to colourise the output.
|
||||
* Used instead of a logging framework, as the launcher knows how to parse these
|
||||
* messages.
|
||||
*/
|
||||
public final class Log {
|
||||
|
||||
// original before possibly overridden by MC
|
||||
private static final PrintStream OUT = new PrintStream(System.out), ERR = new PrintStream(System.err);
|
||||
private static final boolean DEBUG = Boolean.getBoolean("org.prismlauncher.debug");
|
||||
|
||||
public static void launcher(String message) {
|
||||
log(message, Level.LAUNCHER);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
log(message, Level.ERROR);
|
||||
}
|
||||
|
||||
public static void debug(String message) {
|
||||
log(message, Level.DEBUG);
|
||||
}
|
||||
|
||||
public static void warning(String message) {
|
||||
log(message, Level.WARNING);
|
||||
}
|
||||
|
||||
public static void error(String message, Throwable e) {
|
||||
error(message);
|
||||
e.printStackTrace(ERR);
|
||||
}
|
||||
|
||||
public static void fatal(String message) {
|
||||
log(message, Level.FATAL);
|
||||
}
|
||||
|
||||
public static void fatal(String message, Throwable e) {
|
||||
fatal(message);
|
||||
e.printStackTrace(ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message with the prefix <code>!![LEVEL]!</code>. This is picked up by
|
||||
* the log viewer to give it nice colours.
|
||||
*
|
||||
* @param message The message
|
||||
* @param level The level
|
||||
*/
|
||||
public static void log(String message, Level level) {
|
||||
if (!DEBUG && level == Level.DEBUG)
|
||||
return;
|
||||
|
||||
String prefix = "!![" + level.name + "]!";
|
||||
// prefix first line
|
||||
message = prefix + message;
|
||||
// prefix subsequent lines
|
||||
message = message.replace("\n", "\n" + prefix);
|
||||
|
||||
if (level.stderr)
|
||||
ERR.println(message);
|
||||
else
|
||||
OUT.println(message);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user