Finishing touches

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2023-01-06 10:45:59 +00:00
parent 17317ea308
commit be7f81421a
8 changed files with 38 additions and 35 deletions

View File

@ -93,13 +93,12 @@ public final class Launcher extends Applet implements AppletStub {
try {
if (documentBase == null) {
if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) {
if (applet.getClass().getPackage().getName().startsWith("com.mojang"))
// Special case only for Classic versions
documentBase = new URL("http://www.minecraft.net:80/game/");
} else {
else
documentBase = new URL("http://www.minecraft.net/game/");
}
}
} catch (MalformedURLException e) {
throw new AssertionError(e);
}

View File

@ -131,7 +131,7 @@ final class LegacyFrame extends JFrame {
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("stand-alone", true); // Show the quit button. This often doesn't seem to work.
launcher.setParameter("haspaid", true); // Some old versions need this for world saves to work.
launcher.setParameter("demo", demo);
launcher.setParameter("fullscreen", false);

View File

@ -71,7 +71,7 @@ import org.prismlauncher.utils.ReflectionUtils;
import org.prismlauncher.utils.logging.Log;
/**
* Used to launch old versions that support applets.
* Used to launch old versions which support applets.
*/
final class LegacyLauncher extends AbstractLauncher {
@ -119,8 +119,8 @@ final class LegacyLauncher extends AbstractLauncher {
}
}
// find and invoke the main method, this time without size parameters
// in all versions that support applets, these are ignored
// 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]));
}
@ -128,18 +128,16 @@ final class LegacyLauncher extends AbstractLauncher {
private static Applet createAppletClass(String clazz) throws Throwable {
Class<?> appletClass = ClassLoader.getSystemClassLoader().loadClass(clazz);
MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class));
MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass,
MethodType.methodType(void.class));
return (Applet) appletConstructor.invoke();
}
private 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) {
if (field.getType() != File.class)
continue;
}
int fieldModifiers = field.getModifiers();

View File

@ -4,6 +4,7 @@ import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.legacy.fix.online.OnlineFixes;
import org.prismlauncher.utils.Parameters;
// implementation of LegacyProxy
public final class LegacyProxy {
public static Launcher createLauncher(Parameters params) {

View File

@ -12,8 +12,10 @@ import java.net.URLConnection;
import javax.imageio.ImageIO;
import org.prismlauncher.legacy.utils.api.*;
import org.prismlauncher.legacy.utils.url.*;
import org.prismlauncher.legacy.utils.api.MojangApi;
import org.prismlauncher.legacy.utils.api.Texture;
import org.prismlauncher.legacy.utils.url.CustomUrlConnection;
import org.prismlauncher.legacy.utils.url.UrlUtils;
final class SkinFix {
@ -25,7 +27,8 @@ final class SkinFix {
String capeOwner = findCapeOwner(address);
if (capeOwner != null) {
// since we do not need to process the image, open a direct connection bypassing Handler
// since we do not need to process the image, open a direct connection bypassing
// Handler
Texture texture = MojangApi.getTexture(MojangApi.getUuid(capeOwner), "CAPE");
if (texture == null)
return null;
@ -45,7 +48,7 @@ final class SkinFix {
try (InputStream in = connection.getInputStream()) {
// thank you craftycodie!
// this is heavily based on
// https://github.com/Mojang/LegacyLauncher/pull/33/files#diff-b61023785a9260651ca0a223573ea9acb5be5eec478bff626dafb7abe13ffebaR99
// https://github.com/craftycodie/MineOnline/blob/4f4f86f9d051e0a6fd7ff0b95b2a05f7437683d7/src/main/java/gg/codie/mineonline/gui/textures/TextureHelper.java#L17
BufferedImage image = ImageIO.read(in);
Graphics2D graphics = image.createGraphics();
graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
@ -59,7 +62,7 @@ final class SkinFix {
}
if (texture.isSlim()) {
// convert slim to wide
// convert slim to classic
subimage = image.getSubimage(45, 16, 9, 16);
graphics.drawImage(subimage, 46, 16, null);
@ -72,7 +75,7 @@ final class SkinFix {
graphics.dispose();
// crop the image
// crop the image - old versions disregard all secondary layers besides the hat
ByteArrayOutputStream out = new ByteArrayOutputStream();
image = image.getSubimage(0, 0, 64, 32);
ImageIO.write(image, "png", out);

View File

@ -47,7 +47,8 @@ import java.util.List;
import java.util.Map;
/**
* Single-file JSON parser to allow for usage in versions without GSON.
* A lightweight portable JSON parser used instead of GSON since it is not
* available in a lot of versions.
*/
public final class JsonParser {
@ -55,15 +56,15 @@ public final class JsonParser {
private char[] buffer;
private int pos, length;
public static Object parse(String in) throws JsonParseException, IOException {
public static Object parse(String in) throws IOException {
return parse(new StringReader(in));
}
public static Object parse(InputStream in) throws JsonParseException, IOException {
public static Object parse(InputStream in) throws IOException {
return parse(new InputStreamReader(in, StandardCharsets.UTF_8));
}
public static Object parse(Reader in) throws JsonParseException, IOException {
public static Object parse(Reader in) throws IOException {
return new JsonParser(in).readSingleValue();
}
@ -336,6 +337,7 @@ public final class JsonParser {
if (character() == '0') {
result.append((char) character());
read();
if (isDigit())
throw new JsonParseException("Found superfluous leading zero");
} else if (!isDigit())
@ -395,11 +397,10 @@ public final class JsonParser {
if (read() == 'r' && read() == 'u' && read() == 'e') {
return true;
}
} else if (character() == 'f') {
if (read() == 'a' && read() == 'l' && read() == 's' && read() == 'e') {
} else if (character() == 'f' && read() == 'a' && read() == 'l' && read() == 's' && read() == 'e') {
return false;
}
}
return null;
}

View File

@ -40,10 +40,11 @@ import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import org.prismlauncher.legacy.utils.*;
import org.prismlauncher.legacy.utils.Base64;
import org.prismlauncher.legacy.utils.JsonParser;
/**
* Basic access to Mojang's Minecraft API.
* Basic wrapper for Mojang's Minecraft API.
*/
@SuppressWarnings("unchecked")
public final class MojangApi {
@ -55,18 +56,18 @@ public final class MojangApi {
}
}
public static Texture getTexture(String player, String name) throws IOException {
public static Texture getTexture(String player, String id) throws IOException {
Map<String, Object> map = getTextures(player);
if (map != null) {
map = (Map<String, Object>) map.get(name);
map = (Map<String, Object>) map.get(id);
if (map == null)
return null;
URL url = new URL((String) map.get("url"));
boolean slim = false;
if (name.equals("SKIN")) {
if (id.equals("SKIN")) {
map = (Map<String, Object>) map.get("metadata");
if (map != null && "slim".equals(map.get("model")))
slim = true;