summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc
diff options
context:
space:
mode:
author ftbsc <dev@fantabos.co>2023-02-08 00:10:31 +0100
committer ftbsc <dev@fantabos.co>2023-02-08 00:10:31 +0100
commit382e57a2cfdd615e138ad83bbcf5268ae08a9fa7 (patch)
tree9701a33f6da056a9c971c7fc609add0d475e4df4 /src/main/java/ftbsc
parent0591511859ee5aa0fb9dc3f66ff62d28415e152f (diff)
feat: initial work on packet patch
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r--src/main/java/ftbsc/bscv/patches/PacketPatch.java76
-rw-r--r--src/main/java/ftbsc/bscv/patches/TestPatch.java51
2 files changed, 76 insertions, 51 deletions
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);
- }
- }
-
-}