Ported to java 5
This commit is contained in:
parent
054b616d87
commit
7c60d1adac
7 changed files with 70 additions and 50 deletions
|
@ -14,7 +14,7 @@ repositories {
|
|||
group = 'org.mcphackers'
|
||||
archivesBaseName = 'launchwrapper'
|
||||
version = '1.0'
|
||||
sourceCompatibility = 1.6
|
||||
sourceCompatibility = 1.5
|
||||
|
||||
dependencies {
|
||||
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4'
|
||||
|
|
|
@ -57,16 +57,16 @@ public class LaunchConfig {
|
|||
while(i < args.length) {
|
||||
if(args[i].startsWith("--")) {
|
||||
String paramName = args[i].substring(2);
|
||||
LaunchParameter<?> param = parameters.get(paramName.toLowerCase(Locale.ROOT));
|
||||
if(param != null && param.isSwitch()) {
|
||||
((LaunchParameterSwitch)param).set(true);
|
||||
}
|
||||
else if(paramName.equalsIgnoreCase("awtFrame")) {
|
||||
LaunchParameter<?> param = parameters.get(paramName.toLowerCase(Locale.ENGLISH));
|
||||
if(paramName.equalsIgnoreCase("awtFrame")) {
|
||||
lwjglFrame.set(false);
|
||||
}
|
||||
else if(i + 1 < args.length) {
|
||||
try {
|
||||
if(param != null) {
|
||||
else if(param != null) {
|
||||
if(param.isSwitch()) {
|
||||
((LaunchParameterSwitch)param).set(true);
|
||||
}
|
||||
else if(i + 1 < args.length) {
|
||||
try {
|
||||
//TODO better handling for alternative parameter names
|
||||
if(param.equals(session)) {
|
||||
sessionid.set(args[i + 1]);
|
||||
|
@ -82,8 +82,8 @@ public class LaunchConfig {
|
|||
}
|
||||
param.setString(args[i + 1]);
|
||||
i++;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
@ -138,7 +138,7 @@ public class LaunchConfig {
|
|||
protected LaunchParameter(String name, boolean wrapper) {
|
||||
this.name = name;
|
||||
this.wrapperOnly = wrapper;
|
||||
parameters.put(name.toLowerCase(Locale.ROOT), this);
|
||||
parameters.put(name.toLowerCase(Locale.ENGLISH), this);
|
||||
}
|
||||
|
||||
public boolean isSwitch() {
|
||||
|
@ -282,7 +282,7 @@ public class LaunchConfig {
|
|||
|
||||
@Override
|
||||
public void set(Boolean value) {
|
||||
this.value = value;
|
||||
this.value = value == null ? false : value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,24 +36,15 @@ public class SkinRequests {
|
|||
|
||||
public static JSONObject requestUUIDfromName(String name) {
|
||||
try {
|
||||
int attemptCount = 0;
|
||||
while(attemptCount < 2) {
|
||||
attemptCount++;
|
||||
URL nametouuidURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||
HttpURLConnection connection = (HttpURLConnection)nametouuidURL.openConnection();
|
||||
if(connection.getResponseCode() == 429) {
|
||||
// wait for the block to pass
|
||||
Thread.sleep(300000);
|
||||
continue;
|
||||
}
|
||||
InputStream connStream = connection.getInputStream();
|
||||
JSONObject uuidjson = new JSONObject(new String(Util.readStream(connStream), "UTF-8"));
|
||||
|
||||
return uuidjson;
|
||||
}
|
||||
URL profileURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||
InputStream connStream = profileURL.openConnection().getInputStream();
|
||||
JSONObject uuidJson = new JSONObject(new String(Util.readStream(connStream), "UTF-8"));
|
||||
|
||||
return uuidJson;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SkinData fetchSkin(String uuid) {
|
||||
|
|
|
@ -74,7 +74,11 @@ public class IsomTweak extends LegacyTweak {
|
|||
public LaunchTarget getLaunchTarget(LaunchClassLoader loader) {
|
||||
if(isomApplet != null) {
|
||||
AppletLaunchTarget launchTarget = new AppletLaunchTarget(loader, isomApplet.name);
|
||||
launchTarget.setTitle("Isometric Preview");
|
||||
if(launch.title.get() != null) {
|
||||
launchTarget.setTitle(launch.title.get());
|
||||
} else {
|
||||
launchTarget.setTitle("IsomPreview");
|
||||
}
|
||||
launchTarget.setIcon(Inject.getIcon());
|
||||
launchTarget.setResolution(launch.width.get(), launch.height.get());
|
||||
return launchTarget;
|
||||
|
|
|
@ -23,21 +23,20 @@ public abstract class Tweak {
|
|||
if(launch.isom.get()) {
|
||||
return new IsomTweak(classLoader, launch);
|
||||
}
|
||||
if(classLoader.getClass(VanillaTweak.MAIN_CLASS) == null) {
|
||||
for(String cls : LegacyTweak.MAIN_CLASSES) {
|
||||
if(classLoader.getClass(cls) != null) {
|
||||
return new LegacyTweak(classLoader, launch);
|
||||
}
|
||||
}
|
||||
for(String cls : LegacyTweak.MAIN_APPLETS) {
|
||||
if(classLoader.getClass(cls) != null) {
|
||||
return new LegacyTweak(classLoader, launch);
|
||||
}
|
||||
}
|
||||
return null; // Tweak not found
|
||||
} else {
|
||||
if(classLoader.getClass(VanillaTweak.MAIN_CLASS) != null) {
|
||||
return new VanillaTweak(classLoader, launch);
|
||||
}
|
||||
for(String cls : LegacyTweak.MAIN_CLASSES) {
|
||||
if(classLoader.getClass(cls) != null) {
|
||||
return new LegacyTweak(classLoader, launch);
|
||||
}
|
||||
}
|
||||
for(String cls : LegacyTweak.MAIN_APPLETS) {
|
||||
if(classLoader.getClass(cls) != null) {
|
||||
return new LegacyTweak(classLoader, launch);
|
||||
}
|
||||
}
|
||||
return null; // Tweak not found
|
||||
}
|
||||
|
||||
protected void debugInfo(String msg) {
|
||||
|
|
|
@ -45,6 +45,7 @@ public class VanillaTweak extends Tweak {
|
|||
MethodInsnNode invoke = (MethodInsnNode)insn;
|
||||
minecraft = source.getClass(invoke.owner);
|
||||
run = InjectUtils.getMethod(minecraft, invoke.name, invoke.desc);
|
||||
debugInfo(minecraft.name + "." + invoke.name + invoke.desc + " is Minecraft.run()");
|
||||
break;
|
||||
}
|
||||
insn = previousInsn(insn);
|
||||
|
@ -71,15 +72,28 @@ public class VanillaTweak extends Tweak {
|
|||
injectAssetsDirectory(assets);
|
||||
}
|
||||
}
|
||||
replaceIconAndTitle(getInit(run));
|
||||
MethodNode init = getInit(run);
|
||||
boolean fixedTitle = replaceTitle(init);
|
||||
boolean fixedIcon = replaceIcon(init);
|
||||
for(MethodNode m : minecraft.methods) {
|
||||
if(!fixedTitle) {
|
||||
fixedTitle = replaceTitle(m);
|
||||
}
|
||||
if(!fixedIcon) {
|
||||
fixedIcon = replaceIcon(m);
|
||||
}
|
||||
if(fixedTitle && fixedIcon) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
source.overrideClass(minecraft);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void replaceIconAndTitle(MethodNode init) {
|
||||
AbstractInsnNode insn = init.instructions.getFirst();
|
||||
private boolean replaceTitle(MethodNode m) {
|
||||
AbstractInsnNode insn = m.instructions.getFirst();
|
||||
while(insn != null) {
|
||||
AbstractInsnNode[] insns = fill(insn, 6);
|
||||
AbstractInsnNode[] insns = fill(insn, 2);
|
||||
if(compareInsn(insns[0], LDC)
|
||||
&& compareInsn(insns[1], INVOKESTATIC, "org/lwjgl/opengl/Display", "setTitle", "(Ljava/lang/String;)V")) {
|
||||
LdcInsnNode ldc = (LdcInsnNode)insn;
|
||||
|
@ -87,21 +101,32 @@ public class VanillaTweak extends Tweak {
|
|||
if(launch.title.get() != null) {
|
||||
debugInfo("Replaced title");
|
||||
ldc.cst = launch.title.get();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
insn = nextInsn(insn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean replaceIcon(MethodNode m) {
|
||||
AbstractInsnNode insn = m.instructions.getFirst();
|
||||
while(insn != null) {
|
||||
if(launch.icon.get() != null && hasIcon(launch.icon.get())
|
||||
&& compareInsn(insn, INVOKESTATIC, "org/lwjgl/opengl/Display", "setIcon", "([Ljava/nio/ByteBuffer;)I")) {
|
||||
IdentifyCall call = new IdentifyCall((MethodInsnNode)insn);
|
||||
for(AbstractInsnNode[] arg : call.getArguments()) {
|
||||
remove(init.instructions, arg);
|
||||
remove(m.instructions, arg);
|
||||
}
|
||||
MethodInsnNode insert = new MethodInsnNode(INVOKESTATIC, "org/mcphackers/launchwrapper/inject/Inject", "loadIcons", "()[Ljava/nio/ByteBuffer;");
|
||||
init.instructions.insertBefore(insn, insert);
|
||||
m.instructions.insertBefore(insn, insert);
|
||||
debugInfo("Replaced icon");
|
||||
return true;
|
||||
}
|
||||
insn = nextInsn(insn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasIcon(File[] icons) {
|
||||
|
@ -154,6 +179,7 @@ public class VanillaTweak extends Tweak {
|
|||
m.instructions.remove(insns[3]);
|
||||
m.instructions.set(insns[5], new MethodInsnNode(INVOKESPECIAL, "java/io/File", "<init>", "(Ljava/lang/String;)V"));
|
||||
}
|
||||
debugInfo("Replaced assets path");
|
||||
}
|
||||
insn = nextInsn(insn);
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public final class Util {
|
|||
try {
|
||||
md = MessageDigest.getInstance("SHA-1");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IOException(e);
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
BufferedInputStream bs = new BufferedInputStream(is);
|
||||
byte[] buffer = new byte[1024];
|
||||
|
|
Loading…
Reference in a new issue