BTA and Indev tests

Fix BTA throwing exception when attempting to apply LWJGL frame patch
This commit is contained in:
Lassebq 2023-11-05 21:28:38 +02:00
parent 7e662a411e
commit 304d09d3b3
No known key found for this signature in database
GPG key ID: DE0866BB0C980B6E
4 changed files with 101 additions and 25 deletions

View file

@ -109,6 +109,7 @@ public class LegacyTweak extends Tweak {
if(main == null) {
minecraft.methods.add(main = getMain());
} else {
// Try to patch main instead of replacing. Issues with BTA
minecraft.methods.remove(main);
minecraft.methods.add(main = getMain());
}
@ -1204,7 +1205,12 @@ public class LegacyTweak extends Tweak {
insns.add(new VarInsnNode(ALOAD, appletIndex));
insns.add(new FieldInsnNode(GETFIELD, minecraftApplet.name, mcField, mcDesc));
} else {
insns.add(getNewMinecraftImpl(minecraft, null));
InsnList constructor = getNewMinecraftImpl(minecraft, null);
if(constructor != null) {
insns.add(constructor);
} else {
throw new IllegalStateException("Unexpected constructor!");
}
}
insns.add(new VarInsnNode(ASTORE, mcIndex));
if(width != null && height != null) {
@ -1286,6 +1292,9 @@ public class LegacyTweak extends Tweak {
AbstractInsnNode[] insns2 = fill(insn, 6);
if(compareInsn(insns2[1], PUTFIELD, minecraftApplet.name, mcField, mcDesc)
&& compareInsn(insns2[0], INVOKESPECIAL, null, "<init>")) {
MethodInsnNode invoke = (MethodInsnNode) insns2[0];
InsnList constructor = getNewMinecraftImpl(source.getClass(invoke.owner), canvasField);
if(constructor != null) {
InsnList insns = new InsnList();
insns.add(new VarInsnNode(ALOAD, 0));
insns.add(new FieldInsnNode(GETFIELD, minecraftApplet.name, canvasField, "Ljava/awt/Canvas;"));
@ -1296,8 +1305,7 @@ public class LegacyTweak extends Tweak {
insns.add(new MethodInsnNode(INVOKESPECIAL, "java/awt/Dimension", "<init>", "(II)V"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Canvas", "setPreferredSize", "(Ljava/awt/Dimension;)V"));
init.instructions.insert(insns2[1], insns);
MethodInsnNode invoke = (MethodInsnNode) insns2[0];
init.instructions.insertBefore(insns2[1], getNewMinecraftImpl(source.getClass(invoke.owner), canvasField));
init.instructions.insertBefore(insns2[1], constructor);
IdentifyCall call = new IdentifyCall(invoke);
AbstractInsnNode newInsn = call.getArgument(0)[0].getPrevious();
if(newInsn.getOpcode() == NEW) {
@ -1307,6 +1315,7 @@ public class LegacyTweak extends Tweak {
remove(init.instructions, arg);
}
init.instructions.remove(invoke);
}
insn = insns2[1];
}
if(compareInsn(insns2[0], ALOAD, 0)
@ -1437,13 +1446,15 @@ public class LegacyTweak extends Tweak {
} else if(i == 1) {
insns.add(intInsn(launch.height.get()));
} else {
throw new IllegalStateException("Unexpected constructor: " + init.desc);
return null;
// throw new IllegalStateException("Unexpected constructor: " + init.desc);
}
i++;
} else if(desc.equals("Z")) {
insns.add(booleanInsn(launch.fullscreen.get()));
} else {
throw new IllegalStateException("Unexpected constructor: " + init.desc);
return null;
// throw new IllegalStateException("Unexpected constructor: " + init.desc);
}
}
insns.add(new MethodInsnNode(INVOKESPECIAL, minecraftImpl.name, "<init>", init.desc));

View file

@ -0,0 +1,30 @@
package org.mcphackers.launchwrapper.test;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.tweak.LegacyTweak;
import org.mcphackers.launchwrapper.tweak.Tweak;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
public class BTATest extends TweakTest {
@Override
protected String jarName() {
return "bta.jar";
}
@Override
protected String jarUrl() {
return "https://github.com/Better-than-Adventure/bta-download-repo/releases/download/v1.7.7.0_02/bta.jar";
}
@Override
public Tweak getTweak(ClassNodeSource source, LaunchConfig config) {
return new LegacyTweak(source, config);
}
@Override
public TestFeatureBuilder getTests() {
return new TestFeatureBuilder();
}
}

View file

@ -0,0 +1,35 @@
package org.mcphackers.launchwrapper.test;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.tweak.LegacyTweak;
import org.mcphackers.launchwrapper.tweak.Tweak;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
public class IndevTest extends TweakTest {
@Override
protected String jarName() {
return "in-20100223.jar";
}
@Override
protected String jarUrl() {
return "http://files.betacraft.uk/launcher/assets/versions/in-20100223.jar";
}
@Override
public Tweak getTweak(ClassNodeSource source, LaunchConfig config) {
return new LegacyTweak(source, config);
}
@Override
public TestFeatureBuilder getTests() {
return new TestFeatureBuilder()
.tweakInfoList("Indev launch", "Indev save patch", "Set default width and height",
"Fullscreen init patch", "Replaced icon", "Replaced fullscreen", "Replaced width",
"Replaced height", "Shutdown patch", "Options load fix",
"Replaced title", "Replaced gameDir", "Removed canvas null check",
"Set fullscreen", "Added main");
}
}

View file

@ -30,6 +30,6 @@ public class InfdevTest extends TweakTest {
"Replaced height", "Shutdown patch", "SoundManager shutdown",
"Options load fix", "Replaced canvas getWidth", "Replaced canvas getHeight",
"Replaced title", "Replaced gameDir", "Removed canvas null check", "Set fullscreen",
"Set default width and height", "Added main");
"Added main");
}
}