diff --git a/build.gradle b/build.gradle index 4424d10..4179cbd 100644 --- a/build.gradle +++ b/build.gradle @@ -88,7 +88,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" - implementation 'ftbsc:lll:0.0.3' + implementation 'ftbsc:lll:0.1.1' } jar { 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); - } - } - -} diff --git a/src/main/resources/META-INF/services/ftbsc.lll.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector index ad31ef9..2aaf90b 100644 --- a/src/main/resources/META-INF/services/ftbsc.lll.IInjector +++ b/src/main/resources/META-INF/services/ftbsc.lll.IInjector @@ -1,2 +1 @@ -ftbsc.bscv.patches.TestPatch$FramerateFix -ftbsc.bscv.patches.TestPatch$TickPatch +ftbsc.bscv.patches.PacketPatch$IncomingPacketInterceptor