From cd49406bfec2d019cd9533f7a020107e551e7d61 Mon Sep 17 00:00:00 2001 From: icelimetea Date: Sun, 5 Jun 2022 01:18:59 +0100 Subject: [PATCH 1/2] Fix launching process for some legacy Forge versions --- .../launcher/net/minecraft/Launcher.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 265fa66a..0b4d1c5c 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -28,11 +28,15 @@ public final class Launcher extends Applet implements AppletStub { private final Map params = new TreeMap<>(); - private final Applet wrappedApplet; + private Applet wrappedApplet; private boolean active = false; public Launcher(Applet applet) { + this(applet, null); + } + + public Launcher(Applet applet, URL documentBase) { this.setLayout(new BorderLayout()); this.add(applet, "Center"); @@ -40,8 +44,25 @@ public final class Launcher extends Applet implements AppletStub { this.wrappedApplet = applet; } - public void setParameter(String name, String value) - { + public void replace(Applet applet) { + this.wrappedApplet = applet; + + applet.setStub(this); + applet.setSize(getWidth(), getHeight()); + + this.setLayout(new BorderLayout()); + this.add(applet, "Center"); + + applet.init(); + + active = true; + + applet.start(); + + validate(); + } + + public void setParameter(String name, String value) { params.put(name, value); } From dd6d8e000238bdf9fad76cbebb787bf70546201d Mon Sep 17 00:00:00 2001 From: icelimetea Date: Sun, 5 Jun 2022 02:43:14 +0100 Subject: [PATCH 2/2] Make Launcher class to look more like original --- .../launcher/net/minecraft/Launcher.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 0b4d1c5c..6bf671be 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -24,12 +24,18 @@ import java.net.URL; 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. + */ public final class Launcher extends Applet implements AppletStub { private final Map params = new TreeMap<>(); private Applet wrappedApplet; + private URL documentBase; + private boolean active = false; public Launcher(Applet applet) { @@ -42,6 +48,20 @@ public final class Launcher extends Applet implements AppletStub { this.add(applet, "Center"); this.wrappedApplet = applet; + + try { + if (documentBase != null) { + this.documentBase = documentBase; + } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) { + // Special case only for Classic versions + + this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); + } else { + this.documentBase = new URL("http://www.minecraft.net/game/"); + } + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } } public void replace(Applet applet) { @@ -75,7 +95,7 @@ public final class Launcher extends Applet implements AppletStub { try { return super.getParameter(name); - } catch (Exception ignore) {} + } catch (Exception ignored) {} return null; } @@ -129,25 +149,13 @@ public final class Launcher extends Applet implements AppletStub { try { return new URL("http://www.minecraft.net/game/"); } catch (MalformedURLException e) { - e.printStackTrace(); + throw new RuntimeException(e); } - - return null; } @Override public URL getDocumentBase() { - try { - // Special case only for Classic versions - if (wrappedApplet.getClass().getCanonicalName().startsWith("com.mojang")) - return new URL("http", "www.minecraft.net", 80, "/game/"); - - return new URL("http://www.minecraft.net/game/"); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return null; + return documentBase; } @Override