Skip to content

Commit

Permalink
Blacklist capes too for reserved names. b1.2_02-20110517 tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Aug 17, 2024
1 parent e06470f commit c7d9307
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@

public class SkinRequests {
// name->uuid requests have a rate limit, so here's cache
public static HashMap<String, String> nameToUUID = new HashMap<String, String>();
private static HashMap<String, String> nameToUUID = new HashMap<String, String>();

private static final String[] BLACKLISTED_NAMES = {"Player", "DemoUser"};

public static String getUUIDfromName(String username) {
for(String s : BLACKLISTED_NAMES) {
if(s.equals(username)) {
return null;
}
}
String cachedUUID = nameToUUID.get(username);

if(cachedUUID != null) {
Expand Down Expand Up @@ -136,9 +143,6 @@ public static byte[] getCape(String name, SkinType skinType) {
}

public static byte[] getSkin(String name, SkinType skinType) {
if(name.equals("Player") || name.equals("DemoUser")) { // Reserved usernames
return null;
}
String uuid = getUUIDfromName(name);
if(uuid == null) {
return null;
Expand Down
205 changes: 205 additions & 0 deletions src/main/java/org/mcphackers/launchwrapper/tweak/DevBetaTweak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package org.mcphackers.launchwrapper.tweak;

import static org.mcphackers.launchwrapper.util.InsnHelper.*;
import static org.mcphackers.rdi.util.InsnHelper.*;
import static org.objectweb.asm.Opcodes.*;

import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.mcphackers.rdi.util.NodeHelper;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;

public class DevBetaTweak extends LegacyTweak {

public DevBetaTweak(ClassNodeSource source, LaunchConfig launch) {
super(source, launch);
}
public boolean transform() {
if(!super.transform()) {
return false;
}
ClassNode titleScreen = source.getClass("net/minecraft/client/title/TitleScreen");
if(titleScreen != null) {
MethodNode init = NodeHelper.getMethod(titleScreen, "init", "()V");
if(init != null) {
AbstractInsnNode insn1 = init.instructions.getFirst();
while(insn1 != null) {
AbstractInsnNode[] insns = fill(insn1, 4);
if(compareInsn(insns[0], ALOAD, 0)
&& compareInsn(insns[1], GETFIELD, null, null, "L" + minecraft.name + ";")
&& compareInsn(insns[2], NEW, "net/minecraft/client/gamemode/secret/SecretMode")
&& compareInsn(insns[3], DUP)) {
tweakInfo("Dev build titlescreen patch");
init.instructions.insertBefore(insn1, new InsnNode(RETURN));
break;
}
insn1 = nextInsn(insn1);
}
source.overrideClass(titleScreen);
}
}
boolean bindsAdded = false;
ClassNode options = source.getClass("net/minecraft/client/Options");
if(options != null) {
String[] keys = {"drop", "inventory", "chat"};
String[] fields = {"keyDrop", "keyInventory", "keyChat"};
int[] codes = {16, 23, 20};
MethodNode init = NodeHelper.getMethod(options, "<init>", "()V");
MethodNode init2 = NodeHelper.getMethod(options, "<init>", "(Lnet/minecraft/client/Minecraft;Ljava/io/File;)V");
MethodNode[] initNodes = new MethodNode[]{init, init2};
for(MethodNode current : initNodes) {
if(current == null) {
break;
}
AbstractInsnNode insn1 = current.instructions.getFirst();
AbstractInsnNode initBefore = null;
AbstractInsnNode storeBefore = null;
AbstractInsnNode arraySize = null;
AbstractInsnNode fogKeyIndex = null;
while(insn1 != null) {
AbstractInsnNode[] insns = fill(insn1, 5);
if(compareInsn(insns[0], ALOAD, 0)
&& compareInsn(insns[1], BIPUSH, 7)
&& compareInsn(insns[2], ANEWARRAY, "net/minecraft/client/KeyMapping")) {
initBefore = insns[0];
arraySize = insns[1];
}
if(arraySize != null
&& compareInsn(insns[0], DUP)
&& compareInsn(insns[1], BIPUSH, 6)
&& compareInsn(insns[2], ALOAD, 0)
&& compareInsn(insns[3], GETFIELD, null, "keyFog", "Lnet/minecraft/client/KeyMapping;")
&& compareInsn(insns[4], AASTORE)) {
storeBefore = insns[0];
fogKeyIndex = insns[1];
break;
}
insn1 = nextInsn(insn1);
}
if(arraySize != null && fogKeyIndex != null && initBefore != null && storeBefore != null) {
init.instructions.set(fogKeyIndex, intInsn(9));
init.instructions.set(arraySize, intInsn(10));
InsnList insns = new InsnList();
InsnList insns2 = new InsnList();
int n = 6;
for(int i = 0; i < 3; i++) {
insns2.add(new IntInsnNode(ALOAD, 0));
insns2.add(new TypeInsnNode(NEW, "net/minecraft/client/KeyMapping"));
insns2.add(new InsnNode(DUP));
insns2.add(new LdcInsnNode("key." + keys[i]));
insns2.add(intInsn(codes[i]));
insns2.add(new MethodInsnNode(INVOKESPECIAL, "net/minecraft/client/KeyMapping", "<init>", "(Ljava/lang/String;I)V"));
insns2.add(new FieldInsnNode(PUTFIELD, "net/minecraft/client/Options", fields[i], "Lnet/minecraft/client/KeyMapping;"));

insns.add(new InsnNode(DUP));
insns.add(intInsn(n+i));
insns.add(new IntInsnNode(ALOAD, 0));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Options", fields[i], "Lnet/minecraft/client/KeyMapping;"));
insns.add(new InsnNode(AASTORE));
}
init.instructions.insertBefore(initBefore, insns2);
init.instructions.insertBefore(storeBefore, insns);
tweakInfo("Add options patch");
source.overrideClass(options);
bindsAdded = true;
}
}
for(int i = 0; i < 3; i++) {
options.fields.add(new FieldNode(ACC_PUBLIC, fields[i], "Lnet/minecraft/client/KeyMapping;", null, null));
}
}

MethodNode runTick = NodeHelper.getMethod(minecraft, "tick", "()V");
if(bindsAdded && runTick != null) {

AbstractInsnNode insn1 = runTick.instructions.getFirst();
while(insn1 != null) {
AbstractInsnNode[] insns = fill(insn1, 8);
if(compareInsn(insns[0], INVOKESTATIC, "org/lwjgl/input/Keyboard", "getEventKey", "()I")
&& compareInsn(insns[1], ICONST_1)
&& compareInsn(insns[2], IF_ICMPNE)
&& compareInsn(insns[3], ALOAD, 0)
&& compareInsn(insns[4], INVOKEVIRTUAL)) {
LabelNode label = new LabelNode();
InsnList list = new InsnList();
list.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/input/Keyboard", "getEventKey", "()I"));
list.add(new IntInsnNode(ALOAD, 0));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "options", "Lnet/minecraft/client/Options;"));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Options", "keyInventory", "Lnet/minecraft/client/KeyMapping;"));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/KeyMapping", "key", "I"));
list.add(new JumpInsnNode(IF_ICMPNE, label));
list.add(new IntInsnNode(ALOAD, 0));
list.add(new TypeInsnNode(NEW, "net/minecraft/client/gui/inventory/InventoryScreen"));
list.add(new InsnNode(DUP));
list.add(new IntInsnNode(ALOAD, 0));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "player", "Lnet/minecraft/client/player/LocalPlayer;"));
list.add(new MethodInsnNode(INVOKESPECIAL, "net/minecraft/client/gui/inventory/InventoryScreen", "<init>", "(Lnet/minecraft/world/entity/player/Player;)V"));
list.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/client/Minecraft", "setScreen", "(Lnet/minecraft/client/gui/Screen;)V"));
list.add(label);
label = new LabelNode();
list.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/input/Keyboard", "getEventKey", "()I"));
list.add(new IntInsnNode(ALOAD, 0));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "options", "Lnet/minecraft/client/Options;"));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Options", "keyDrop", "Lnet/minecraft/client/KeyMapping;"));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/KeyMapping", "key", "I"));
list.add(new JumpInsnNode(IF_ICMPNE, label));
list.add(new IntInsnNode(ALOAD, 0));
list.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "player", "Lnet/minecraft/client/player/LocalPlayer;"));
list.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/world/entity/player/Player", "drop", "()V"));
list.add(label);
tweakInfo("Restore inventory and drop");
runTick.instructions.insertBefore(insns[0], list);
}
insn1 = nextInsn(insn1);
}
}
ClassNode container = source.getClass("net/minecraft/client/gui/inventory/AbstractContainerScreen");
if(container != null) {
MethodNode keyPressed = NodeHelper.getMethod(container, "keyPressed", "(CI)V");
if(keyPressed != null) {
InsnList insns = new InsnList();
LabelNode label = new LabelNode();
LabelNode label2 = new LabelNode();
insns.add(new IntInsnNode(ILOAD, 2));
insns.add(intInsn(1));
insns.add(new JumpInsnNode(IF_ICMPNE, label));
insns.add(new JumpInsnNode(GOTO, label2));
insns.add(label);
label = new LabelNode();
insns.add(new IntInsnNode(ILOAD, 2));
insns.add(new IntInsnNode(ALOAD, 0));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/gui/Screen", "minecraft", "Lnet/minecraft/client/Minecraft;"));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "options", "Lnet/minecraft/client/Options;"));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Options", "keyInventory", "Lnet/minecraft/client/KeyMapping;"));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/KeyMapping", "key", "I"));
insns.add(new JumpInsnNode(IF_ICMPNE, label));
insns.add(label2);
insns.add(new IntInsnNode(ALOAD, 0));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/gui/Screen", "minecraft", "Lnet/minecraft/client/Minecraft;"));
insns.add(new FieldInsnNode(GETFIELD, "net/minecraft/client/Minecraft", "player", "Lnet/minecraft/client/player/LocalPlayer;"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/client/player/LocalPlayer", "closeContainer", "()V"));
insns.add(label);
insns.add(new InsnNode(RETURN));
keyPressed.instructions = insns;
source.overrideClass(container);
tweakInfo("Fix container close");
}

}

return true;
}

}
47 changes: 4 additions & 43 deletions src/main/java/org/mcphackers/launchwrapper/tweak/LegacyTweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.lang.reflect.Field;
import java.net.URL;

import org.mcphackers.launchwrapper.Launch;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.LaunchTarget;
import org.mcphackers.launchwrapper.MainLaunchTarget;
Expand Down Expand Up @@ -77,7 +76,6 @@ public class LegacyTweak extends Tweak {
protected MethodNode main;
protected SkinType skinType = null;
protected int port = -1;
private boolean classic;

public LegacyTweak(ClassNodeSource source, LaunchConfig launch) {
super(source, launch);
Expand All @@ -94,7 +92,6 @@ public boolean transform() {
}
MethodNode runTick = getTickMethod(run);
fixSplash();
fixIndevLaunch();
addIndevSaving();
fixA111GrayScreen();
fixShutdown(run);
Expand Down Expand Up @@ -410,7 +407,6 @@ private void bitDepthFix(MethodNode init) {

private void displayPatch(MethodNode init, boolean supportsResizing) {
boolean foundTitle = false;
this.classic = isClassic();
String canvasName = null;

int thisIndex = 0;
Expand Down Expand Up @@ -463,7 +459,7 @@ && compareInsn(insns[3], SIPUSH)
&& compareInsn(insns[4], INVOKESPECIAL, "org/lwjgl/opengl/DisplayMode", "<init>", "(II)V")
&& compareInsn(insns[5], INVOKESTATIC, "org/lwjgl/opengl/Display", "setDisplayMode", "(Lorg/lwjgl/opengl/DisplayMode;)V")) {
tweakInfo("Pre-classic resolution patch");
InsnList insert = getIcon(classic);
InsnList insert = getIcon(isClassic());
if(launch.forceVsync.get()) {
insert.add(new InsnNode(ICONST_1));
insert.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/opengl/Display", "setVSyncEnabled", "(Z)V"));
Expand All @@ -488,7 +484,7 @@ && compareInsn(insns[4], INVOKESPECIAL, "org/lwjgl/opengl/DisplayMode", "<init>"
&& compareInsn(insns[1], INVOKESTATIC, "org/lwjgl/opengl/Display", "setFullscreen", "(Z)V")
&& compareInsn(insns[2], INVOKESTATIC, "org/lwjgl/opengl/Display", "create", "()V")) {
tweakInfo("Pre-classic resolution patch");
InsnList insert = getIcon(classic);
InsnList insert = getIcon(isClassic());
if(launch.forceVsync.get()) {
insert.add(new InsnNode(ICONST_1));
insert.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/opengl/Display", "setVSyncEnabled", "(Z)V"));
Expand Down Expand Up @@ -566,7 +562,7 @@ && compareInsn(insns[4], INVOKESPECIAL, null, "<init>")) {
insnList.insertBefore(afterLabel, aLabel);
InsnList insert = new InsnList();
// Place that outside of the condition?
insert.add(getIcon(classic));
insert.add(getIcon(isClassic()));
if(supportsResizing) {
insert.add(new InsnNode(ICONST_1));
insert.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/opengl/Display", "setResizable", "(Z)V"));
Expand Down Expand Up @@ -1064,41 +1060,6 @@ && compareInsn(insns2[2], INVOKEVIRTUAL, minecraft.name, null, null)) {
}
}

private void fixIndevLaunch() {
MethodNode setLevel = null;
for(MethodNode m : minecraft.methods) {
AbstractInsnNode insn = m.instructions.getLast();
if(insn == null)
continue;
AbstractInsnNode insn2 = insn.getPrevious();
if(compareInsn(insn2, INVOKESTATIC, "java/lang/System", "gc", "()V")
&& compareInsn(insn, RETURN)) {
setLevel = m;
break;
}
}
if(setLevel != null) {
if(setLevel.tryCatchBlocks.size() > 0) {
TryCatchBlockNode handler = setLevel.tryCatchBlocks.get(0);
LabelNode lbl = handler.end;
LabelNode lbl2 = null;
AbstractInsnNode insn = lbl.getPrevious();
while(insn != null) {
if(insn.getType() == AbstractInsnNode.LABEL) {
lbl2 = (LabelNode) insn;
break;
}
insn = insn.getPrevious();
}
if(lbl2 != null) {
tweakInfo("Indev launch");
removeRange(setLevel.instructions, handler.start.getNext(), lbl2);
setLevel.tryCatchBlocks.remove(handler);
}
}
}
}

private MethodNode getInit(MethodNode run) {
for(AbstractInsnNode insn : run.instructions) {
if(insn.getType() == AbstractInsnNode.METHOD_INSN) {
Expand Down Expand Up @@ -1188,7 +1149,7 @@ protected MethodNode getMain() {
insns.add(new MethodInsnNode(INVOKESPECIAL, "java/awt/Frame", "<init>", "(Ljava/lang/String;)V"));
insns.add(new VarInsnNode(ASTORE, frameIndex));
insns.add(new VarInsnNode(ALOAD, frameIndex));
insns.add(booleanInsn(classic));
insns.add(booleanInsn(isClassic()));
insns.add(new MethodInsnNode(INVOKESTATIC, "org/mcphackers/launchwrapper/inject/Inject", "getIcon", "(Z)Ljava/awt/image/BufferedImage;"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Frame", "setIconImage", "(Ljava/awt/Image;)V"));
insns.add(new VarInsnNode(ALOAD, frameIndex));
Expand Down
14 changes: 4 additions & 10 deletions src/test/java/org/mcphackers/launchwrapper/test/DebugLaunch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@

import org.mcphackers.launchwrapper.Launch;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.protocol.SkinType;

public class DebugLaunch {
public static void main(String[] args) {
Launch.CLASS_LOADER.setDebugOutput(new File("./debug"));
LaunchConfig config = new LaunchConfig(args);
config.username.set("Player");
if(config.username.get() == null) {
config.username.set("Player");
}
config.session.set("-");
config.accessToken.set("-");
config.applet.set(false);
config.gameDir.set(new File("./game"));
config.fullscreen.set(true);
config.lwjglFrame.set(true);
config.skinProxy.set(SkinType.PRE_B1_9);
// config.tweakClass.set("org.mcphackers.launchwrapper.tweak.LegacyTweak");
config.resourcesProxyPort.set(11702);
Launch.create(config).launch();
Launch.create(config).launch();
}

}

0 comments on commit c7d9307

Please sign in to comment.