From 382e57a2cfdd615e138ad83bbcf5268ae08a9fa7 Mon Sep 17 00:00:00 2001 From: ftbsc Date: Wed, 8 Feb 2023 00:10:31 +0100 Subject: feat: initial work on packet patch --- src/main/java/ftbsc/bscv/patches/PacketPatch.java | 76 +++++++++++++++++++++++ src/main/java/ftbsc/bscv/patches/TestPatch.java | 51 --------------- 2 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 src/main/java/ftbsc/bscv/patches/PacketPatch.java delete mode 100644 src/main/java/ftbsc/bscv/patches/TestPatch.java (limited to 'src/main/java/ftbsc') diff --git a/src/main/java/ftbsc/bscv/patches/PacketPatch.java b/src/main/java/ftbsc/bscv/patches/PacketPatch.java new file mode 100644 index 0000000..6588f0b --- /dev/null +++ b/src/main/java/ftbsc/bscv/patches/PacketPatch.java @@ -0,0 +1,76 @@ +package ftbsc.bscv.patches; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.VarInsnNode; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.lll.IInjector; +import ftbsc.lll.tools.DescriptorBuilder; +import ftbsc.lll.tools.InsnSequence; +import ftbsc.lll.tools.PatternMatcher; +import net.minecraft.network.IPacket; + +public class PacketPatch { + + public static class LazyPacketCatcher { + private static LazyPacketCatcher INSTANCE = new LazyPacketCatcher(); + + public static LazyPacketCatcher getInstance() { + return LazyPacketCatcher.INSTANCE; + } + + public void debug_pkt(IPacket pkt) { + BoSCoVicino.LOGGER.info("got pkt : {}", pkt.toString()); + } + + public static void debug_static_pkt(IPacket pkt) { + BoSCoVicino.LOGGER.info("got pkt : {}", pkt.toString()); + } + } + + public static class IncomingPacketInterceptor implements IInjector, Opcodes { + public String name() { return "IncomingPacketInterceptor"; } + public String reason() { return "add hook to intercept and alter/cancel incoming packets"; } + public String targetClass() { return "net.minecraft.network.NetworkManager"; } + public String methodName() { return "channelRead0"; } + public String methodDesc() { + return + new DescriptorBuilder() + .setReturnType(void.class) + .addParameter("io.netty.channel.ChannelHandlerContext") + .addParameter("net.minecraft.network.IPacket") + .build(); + } + + public void inject(ClassNode clazz, MethodNode main) { + // ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ + AbstractInsnNode found = PatternMatcher.builder() + .opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ) + .ignoreFrames() + .ignoreLabels() + .ignoreLineNumbers() + .build() + .find(main) + .getLast(); + + InsnSequence is = new InsnSequence(); + is.add(new VarInsnNode(ALOAD, 2)); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/PacketPatch$LazyPacketCatcher", + "debug_static_pkt", + new DescriptorBuilder().addParameter("net.minecraft.network.IPacket").build() + )); + + main.instructions.insert(found, is); + } + } +} diff --git a/src/main/java/ftbsc/bscv/patches/TestPatch.java b/src/main/java/ftbsc/bscv/patches/TestPatch.java deleted file mode 100644 index 5c6c152..0000000 --- a/src/main/java/ftbsc/bscv/patches/TestPatch.java +++ /dev/null @@ -1,51 +0,0 @@ -package ftbsc.bscv.patches; - -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.MethodNode; - -import ftbsc.lll.IInjector; - -/** - * When working as intended, this patch will crash the game - * as soon it finished loading with a NegativeArraySizeException. - */ -public class TestPatch { - - public static class FramerateFix implements IInjector, Opcodes { - public String name() { return "FramerateFix"; } - public String targetClass() { return "net.minecraft.client.Minecraft"; } - public String methodName() { return "func_213243_aC"; } // getFramerateLimit() - public String methodDesc() { return "()I"; } - - public void inject(ClassNode clazz, MethodNode main) { - // InsnList insnList = new InsnList(); - // insnList.add(new InsnNode(POP)); - // main.instructions.insert(insnList); - } - } - - - public static class TickPatch implements IInjector, Opcodes { - public String name() { return "TickPatch"; } - public String targetClass() { return "net.minecraft.client.Minecraft"; } - public String methodName() { return "func_71407_l"; } // tick() - public String methodDesc() { return "()V"; } - - public void inject(ClassNode clazz, MethodNode main) { - // InsnList insnList = new InsnList(); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // insnList.add(new InsnNode(POP)); - // main.instructions.insert(insnList); - } - } - -} -- cgit v1.2.3-56-ga3b1