Skip to content

Commit

Permalink
Update skin converter. Local skins. Add skin options
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Aug 24, 2024
1 parent 62e646d commit bd8f5fe
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 46 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ Arguments may be as follows:
- **pre-b1.9-pre4** - flip bottom textures and crop to 64x32
- **pre-1.8** - crop to 64x32
- **default** - do nothing with requested skin
- `skinOptions` - list of optional skin convertion steps separated by ","
- **ignoreAlex** - will not fill arm texture for slim models
- **ignoreLayers** - will not flatten any body or hat layers
- **removeHat** - removes head overlay
- **useLeftArm** - left arm texture will be used when converting to 64x32 skin
- **useLeftLeg** - left leg texture will be used when converting to 64x32 skin
- `assetsDir` - Will be used by LaunchWrapper to locate custom index.json
- `assetIndex` - Name of the `assetsDir`/indexes/index.json without .json extension which will be used
- `title` - The display title
- `icon` - List of paths of icon PNGs separated by `;`
- `icon` - List of paths of icon PNGs separated by file system path separator (";" on windows, ":" on unix)
- `applet` - Makes the game think you're running an applet which:
- Removes quit button in versions between Beta 1.0 and release 1.5.2
- Changes mouse input code in classic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -81,6 +83,22 @@ public void launch(ClassLoader loader) {
}
}

private Path getLaunchwrapperSource() {
CodeSource source = Launch.class.getProtectionDomain().getCodeSource();
if(source != null) {
String path = source.getLocation().getPath();
if(path.startsWith("file:")) {
path = path.substring("file:".length());
int i = path.lastIndexOf('!');
if(i != -1) {
path = path.substring(0, i);
}
}
return Paths.get(path);
}
return null;
}

@Override
public boolean locateGame(FabricLauncher launcher, String[] args) {
this.envType = launcher.getEnvironmentType();
Expand All @@ -92,6 +110,9 @@ public boolean locateGame(FabricLauncher launcher, String[] args) {
if (envGameJar != null) {
classifier.process(envGameJar);
}
for(Path p : launcher.getClassPath()) {
System.out.println(p.toAbsolutePath());
}

classifier.process(launcher.getClassPath());

Expand All @@ -100,6 +121,9 @@ public boolean locateGame(FabricLauncher launcher, String[] args) {

gameJar = envGameJar;
launchwrapperJar = classifier.getOrigin(LWLib.LAUNCHWRAPPER);
if(launchwrapperJar == null) {
launchwrapperJar = getLaunchwrapperSource();
}
if(classifier.has(LWLib.LWJGL)) {
lwjglJars.add(classifier.getOrigin(LWLib.LWJGL));
}
Expand All @@ -109,7 +133,7 @@ public boolean locateGame(FabricLauncher launcher, String[] args) {
hasModLoader = classifier.has(LWLib.MODLOADER);
miscGameLibraries.addAll(lwjglJars);
miscGameLibraries.addAll(classifier.getUnmatchedOrigins());
if(launchwrapperJar != null) { // Java 8 in dev env doesn't detect LW for some reason
if(launchwrapperJar != null) {
validParentClassPath.add(launchwrapperJar);
}
validParentClassPath.addAll(classifier.getSystemLibraries());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mcphackers/launchwrapper/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Launch {
CLASS_LOADER.addException("org.objectweb.asm");
CLASS_LOADER.removeException("org.mcphackers.launchwrapper.inject");
}
protected static Launch INSTANCE;
public static Launch INSTANCE;

public final LaunchConfig config;

Expand Down
66 changes: 60 additions & 6 deletions src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.mcphackers.launchwrapper.protocol.SkinOption;
import org.mcphackers.launchwrapper.protocol.SkinType;
import org.mcphackers.launchwrapper.util.OS;

Expand All @@ -29,7 +32,7 @@ public class LaunchConfig {
public LaunchParameterString proxyUser = new LaunchParameterString("proxyUser");
public LaunchParameterString proxyPass = new LaunchParameterString("proxyPass");
public LaunchParameterString username = new LaunchParameterString("username", "Player" + System.currentTimeMillis() % 1000L);
public LaunchParameterString session = new LaunchParameterString("session", null).altName("sessionid");
public LaunchParameterString session = new LaunchParameterString("session", "-").altName("sessionid");
public LaunchParameterString password = new LaunchParameterString("password");
public LaunchParameterString uuid = new LaunchParameterString("uuid");
public LaunchParameterString accessToken = new LaunchParameterString("accessToken");
Expand All @@ -51,6 +54,7 @@ public class LaunchConfig {
public LaunchParameterSwitch forceVsync = new LaunchParameterSwitch("forceVsync", false, true);
public LaunchParameterSwitch forceResizable = new LaunchParameterSwitch("forceResizable", false, true);
public LaunchParameterEnum<SkinType> skinProxy = new LaunchParameterEnum<SkinType>("skinProxy", SkinType.DEFAULT, true);
public LaunchParameterSkinOptions skinOptions = new LaunchParameterSkinOptions("skinOptions");
public LaunchParameterString serverURL = new LaunchParameterString("serverURL", null, true);
public LaunchParameterString serverSHA1 = new LaunchParameterString("serverSHA1", null, true);
public LaunchParameterFileList icon = new LaunchParameterFileList("icon", null, true);
Expand Down Expand Up @@ -275,7 +279,8 @@ public LaunchParameterFileList(String name, File[] defaultValue, boolean wrapper
}

public LaunchParameterFileList altName(String altName) {
return (LaunchParameterFileList)super.altName(altName);
super.altName(altName);
return this;
}

@Override
Expand All @@ -285,7 +290,7 @@ public String getString() {
String s = "";
for(int i = 0; i < value.length; i++) {
if(i != 0) {
s += ";";
s += File.pathSeparator;
}
s += value[i].getAbsolutePath();
}
Expand All @@ -294,7 +299,7 @@ public String getString() {

@Override
public void setString(String argument) {
String[] paths = argument.split(";");
String[] paths = argument.split(Pattern.quote(File.pathSeparator));
File[] newValue = new File[paths.length];
for(int i = 0; i < paths.length; i++) {
newValue[i] = new File(paths[i]);
Expand Down Expand Up @@ -334,7 +339,8 @@ public LaunchParameterSwitch(String name, Boolean defaultVal, boolean wrapper) {
}

public LaunchParameterSwitch altName(String altName) {
return (LaunchParameterSwitch)super.altName(altName);
super.altName(altName);
return this;
}

public boolean isSwitch() {
Expand Down Expand Up @@ -388,7 +394,8 @@ public LaunchParameterString(String name, String defaultValue, boolean wrapper)
}

public LaunchParameterString altName(String altName) {
return (LaunchParameterString)super.altName(altName);
super.altName(altName);
return this;
}

@Override
Expand Down Expand Up @@ -450,6 +457,53 @@ public void set(Integer value) {
}
}

public class LaunchParameterSkinOptions extends LaunchParameter<List<SkinOption>> {
private List<SkinOption> value = Collections.emptyList();

public LaunchParameterSkinOptions(String name) {
super(name, true);
}

@Override
public String getString() {
if(value == null)
return null;
String s = "";
int i = 0;
for(SkinOption option : value) {
if(i != 0) {
s += ',';
}
s += option.name;
i++;
}
return s;
}

@Override
public void setString(String argument) {
String[] optionStrings = argument.split(Pattern.quote(","));
ArrayList<SkinOption> newValue = new ArrayList<SkinOption>();
for(int i = 0; i < optionStrings.length; i++) {
SkinOption opt = SkinOption.getEnum(optionStrings[i]);
if(opt != null) {
newValue.add(opt);
}
}
this.value = newValue;
}

@Override
public List<SkinOption> get() {
return this.value;
}

@Override
public void set(List<SkinOption> value) {
this.value = value;
}
}

public class LaunchParameterEnum<T extends Enum<T>> extends LaunchParameter<T> {
private T value;
private Class<T> enumType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mcphackers.launchwrapper.protocol;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
Expand All @@ -10,10 +11,12 @@ public class LegacyURLStreamHandler extends URLStreamHandlerProxy {

private LaunchConfig config;
private AssetRequests assets;
private SkinRequests skins;

public LegacyURLStreamHandler(LaunchConfig config) {
this.config = config;
this.assets = new AssetRequests(config.assetsDir.get(), config.assetIndex.get());
this.skins = new SkinRequests(new File(config.gameDir.get(), "skin"), config.skinOptions.get(), config.skinProxy.get());
}

@Override
Expand All @@ -31,6 +34,8 @@ protected URLConnection openConnection(URL url) throws IOException {
return new BasicResponseURLConnection(url, "ok");
if(path.equals("/game/"))
return new BasicResponseURLConnection(url, "42069");
if(path.equals("/client"))
return new BasicResponseURLConnection(url, "idk");
if(path.equals("/haspaid.jsp"))
return new BasicResponseURLConnection(url, "true");
if(path.contains("/level/save.html"))
Expand All @@ -42,14 +47,32 @@ protected URLConnection openConnection(URL url) throws IOException {
if(path.startsWith("/MinecraftResources/") || path.startsWith("/resources/"))
return new AssetURLConnection(url, assets);
if(path.startsWith("/MinecraftSkins/") || path.startsWith("/skin/") || path.startsWith("/MinecraftCloaks/") || path.startsWith("/cloak/"))
return new SkinURLConnection(url, config.skinProxy.get());
return new SkinURLConnection(url, skins);
if(host.equals("assets.minecraft.net") && path.equals("/1_6_has_been_released.flag"))
if(config.oneSixFlag.get())
return new BasicResponseURLConnection(url, "https://web.archive.org/web/20130702232237if_/https://mojang.com/2013/07/minecraft-the-horse-update/");
else
return new BasicResponseURLConnection(url, "");
if(host.equals("mcoapi.minecraft.net") && path.equals("/mco/available"))
return new BasicResponseURLConnection(url, "true");

// TODO redirect to something actually useful. Like a local self hosted realm
if(host.equals("mcoapi.minecraft.net")) {
if(path.equals("/mco/available"))
return new BasicResponseURLConnection(url, "true");
if(path.equals("/mco/client/outdated"))
return new BasicResponseURLConnection(url, "false");
if(path.equals("/payments/unused"))
return new BasicResponseURLConnection(url, "0");
// if(path.equals("/invites/count/pending"))
// return new BasicResponseURLConnection(url, "0");
// if(path.equals("/invites/pending"))
// return new BasicResponseURLConnection(url, "{}");
// if(path.equals("/worlds"))
// return new BasicResponseURLConnection(url, "");
// if(path.equals("/worlds/templates"))
// return new BasicResponseURLConnection(url, "");
// if(path.equals("/worlds/test/$LOCATION_ID"))
// return new BasicResponseURLConnection(url, "1");
}
}
return super.openConnection(url);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.mcphackers.launchwrapper.protocol;

public enum SkinOption {
IGNORE_ALEX("ignoreAlex"),
IGNORE_LAYERS("ignoreLayers"),
REMOVE_HAT("removeHat"),
USE_LEFT_ARM("useLeftArm"),
USE_LEFT_LEG("useLeftLeg");

public String name;

private SkinOption(String name) {
this.name = name;
}

public static SkinOption getEnum(String name) {
for(SkinOption skinType : values()) {
if(skinType.name.equals(name)) {
return skinType;
}
}
return null;
}

}
Loading

0 comments on commit bd8f5fe

Please sign in to comment.