diff options
author | alemi <me@alemi.dev> | 2023-06-20 23:54:17 +0200 |
---|---|---|
committer | alemi <me@alemi.dev> | 2023-06-20 23:54:17 +0200 |
commit | 954a8c806fabeabba436f9b158e835b9eaeee621 (patch) | |
tree | db91f0b7685c7b91e8d9c7f3716d7487df8b0cc4 /src | |
parent | 5a86e4e2befc30fb4e0f07e3ebf5cbc77620ac50 (diff) | |
parent | f4ec2cddb11c99b28fbec76ce7aa9dd2158707cb (diff) |
Merge branch 'processor5' into dev
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/BackgroundPatch.java | 27 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/BlockPushPatch.java | 25 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/BoatPatch.java | 77 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/ChatPatch.java | 8 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/CommandsPatch.java | 27 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/EntityPushPatch.java | 31 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/LiquidPushPatch.java | 31 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/NoSlowPatch.java | 25 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/PacketPatch.java | 50 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java | 6 |
10 files changed, 158 insertions, 149 deletions
diff --git a/src/main/java/ftbsc/bscv/patches/BackgroundPatch.java b/src/main/java/ftbsc/bscv/patches/BackgroundPatch.java index 5a5a8a7..e9444c0 100644 --- a/src/main/java/ftbsc/bscv/patches/BackgroundPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BackgroundPatch.java @@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; @@ -20,11 +20,6 @@ import org.objectweb.asm.tree.*; import com.mojang.blaze3d.matrix.MatrixStack; public class BackgroundPatch implements ICommons { - - public static boolean shouldDrawBackground(Screen screen) { - return MinecraftForge.EVENT_BUS.post(new RenderBackgroundEvent(screen)); - } - @Cancelable public static class RenderBackgroundEvent extends Event { public final Screen screen; @@ -34,15 +29,21 @@ public class BackgroundPatch implements ICommons { } } - @Patch(value = Screen.class, reason = "add hook to cancel background on some screens") + @Patch(Screen.class) public abstract static class BackgroundOverride implements Opcodes { - @Find(parent = BackgroundPatch.class) - abstract MethodProxy shouldDrawBackground(); - @Target + @Find(BackgroundOverride.class) + MethodProxy shouldDrawBackground; + + @Target(of = "shouldDrawBackground") + public static boolean shouldDrawBackground(Screen screen) { + return MinecraftForge.EVENT_BUS.post(new RenderBackgroundEvent(screen)); + } + + @Target(of = "injectCancelBackgroundHook") abstract void renderBackground(MatrixStack stack, int x); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel background on some screens") + public void injectCancelBackgroundHook(ClassNode clazz, MethodNode main) { AbstractInsnNode found = PatternMatcher.builder() .opcodes(ALOAD, ALOAD, ICONST_0, ICONST_0) .ignoreFrames() @@ -55,7 +56,7 @@ public class BackgroundPatch implements ICommons { LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 0)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldDrawBackground())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldDrawBackground)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); diff --git a/src/main/java/ftbsc/bscv/patches/BlockPushPatch.java b/src/main/java/ftbsc/bscv/patches/BlockPushPatch.java index 26745d5..a52a23e 100644 --- a/src/main/java/ftbsc/bscv/patches/BlockPushPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BlockPushPatch.java @@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -20,23 +20,24 @@ public class BlockPushPatch { @Cancelable public static class PlayerBlockPushEvent extends Event {} - public static boolean shouldCancelBlockCollisions() { - return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent()); - } - - @Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel block collisions") + @Patch(ClientPlayerEntity.class) public abstract static class BlockCollisionsOverride implements Opcodes { - @Find(parent = BlockPushPatch.class) - abstract MethodProxy shouldCancelBlockCollisions(); + @Find(BlockCollisionsOverride.class) + MethodProxy shouldCancelBlockCollisions; + + @Target(of = "shouldCancelBlockCollisions") + public static boolean shouldCancelBlockCollisions() { + return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent()); + } - @Target + @Target(of = "injectCancelCollisionsHook") abstract void moveTowardsClosestSpace(double x, double z); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel block collisions") + public void injectCancelCollisionsHook(ClassNode clazz, MethodNode main) { LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); - is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelBlockCollisions())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelBlockCollisions)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java index 7c35e9a..4de534f 100644 --- a/src/main/java/ftbsc/bscv/patches/BoatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import net.minecraft.entity.Entity; @@ -30,35 +30,25 @@ public class BoatPatch implements ICommons { public static class Gravity extends Event { } } - public static boolean boatControl() { - return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); - } - - public static boolean boatClampRotation() { - return MinecraftForge.EVENT_BUS.post(new BoatEvent.ClampRotation()); - } - - public static boolean boatGravityCheck(Entity entity) { - if (MC.player == null) return false; - if (MC.player.getVehicle() == null) return false; - if (MC.player.getVehicle() != entity) return false; - return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); - } - - @Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls") + @Patch(BoatEntity.class) public abstract static class BoatControlOverride implements Opcodes { - @Find(parent = BoatPatch.class) - abstract MethodProxy boatControl(); + @Find(BoatControlOverride.class) + MethodProxy boatControl; - @Target + @Target(of = "boatControl") + public static boolean boatControl() { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); + } + + @Target(of = "injectBoatControlHook") public abstract void controlBoat(); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel vanilla boat controls") + public void injectBoatControlHook(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); - is.add(new MethodProxyInsnNode(INVOKESTATIC, boatControl())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, boatControl)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); @@ -67,20 +57,25 @@ public class BoatPatch implements ICommons { } } - @Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat rotation clamping") + @Patch(BoatEntity.class) public abstract static class BoatClampOverride implements Opcodes { - @Find(parent = BoatPatch.class) - abstract MethodProxy boatClampRotation(); + @Find(BoatClampOverride.class) + MethodProxy boatClampRotation; - @Target + @Target(of = "boatClampRotation") + public static boolean boatClampRotation() { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.ClampRotation()); + } + + @Target(of = "injectRotationClampingHook") public abstract void clampRotation(Entity e); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel vanilla boat rotation clamping") + public void injectRotationClampingHook(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); - is.add(new MethodProxyInsnNode(INVOKESTATIC, boatClampRotation())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, boatClampRotation)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); @@ -89,21 +84,29 @@ public class BoatPatch implements ICommons { } } - @Patch(value = Entity.class, reason = "add hook to alter vanilla boat gravity") + @Patch(Entity.class) public abstract static class BoatGravityOverride implements Opcodes { - @Find(parent = BoatPatch.class) - abstract MethodProxy boatGravityCheck(); + @Find(BoatGravityOverride.class) + MethodProxy boatGravityCheck; + + @Target(of = "boatGravityCheck") + public static boolean boatGravityCheck(Entity entity) { + if (MC.player == null) return false; + if (MC.player.getVehicle() == null) return false; + if (MC.player.getVehicle() != entity) return false; + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); + } - @Target + @Target(of = "injectGravityHook") public abstract boolean isNoGravity(); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to alter vanilla boat gravity") + public void injectGravityHook(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 0)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, boatGravityCheck())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, boatGravityCheck)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(ICONST_1)); is.add(new InsnNode(IRETURN)); diff --git a/src/main/java/ftbsc/bscv/patches/ChatPatch.java b/src/main/java/ftbsc/bscv/patches/ChatPatch.java index 0441c28..a19bcd3 100644 --- a/src/main/java/ftbsc/bscv/patches/ChatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/ChatPatch.java @@ -14,16 +14,16 @@ import org.objectweb.asm.tree.*; public class ChatPatch { - @Patch(value = Minecraft.class, reason = "add hook to prevent chat from being cleared") + @Patch(Minecraft.class) public abstract static class ChatClearInterceptor implements Opcodes { // TODO this should be optional - @Target + @Target(of = "injectClearChatHook") abstract void setScreen(Screen screen); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "skips chat clearing") + public void injectClearChatHook(ClassNode clazz, MethodNode main) { InsnSequence match = PatternMatcher.builder() .opcodes(ALOAD, GETFIELD, INVOKEVIRTUAL, ICONST_1, INVOKEVIRTUAL) .ignoreLineNumbers() diff --git a/src/main/java/ftbsc/bscv/patches/CommandsPatch.java b/src/main/java/ftbsc/bscv/patches/CommandsPatch.java index d819cbd..b5fbc76 100644 --- a/src/main/java/ftbsc/bscv/patches/CommandsPatch.java +++ b/src/main/java/ftbsc/bscv/patches/CommandsPatch.java @@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.debug.BytecodePrinter; @@ -30,21 +30,21 @@ public class CommandsPatch { } } - public static void cmdBuilt(CommandDispatcher<CommandSource> dispatcher) { - MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher)); - } - - @Patch(value = ClientPlayNetHandler.class, reason = "add hook to insert our command suggestions") + @Patch(ClientPlayNetHandler.class) public abstract static class CommandsDispatcherCatcher implements Opcodes { - @Find(parent = CommandsPatch.class) - abstract MethodProxy cmdBuilt(); + @Find(CommandsDispatcherCatcher.class) + MethodProxy cmdBuilt; + + @Target(of = "cmdBuilt") + public static void cmdBuilt(CommandDispatcher<CommandSource> dispatcher) { + MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher)); + } - @Target + @Target(of = "injectCommandHandler") abstract void handleCommands(SCommandListPacket pkt); - @Injector - public void inject(ClassNode clazz, MethodNode main) { - BytecodePrinter.logAsmMethod(main, "pre.log"); + @Injector(reason = "add hook to insert our command suggestions") + public void injectCommandHandler(ClassNode clazz, MethodNode main) { AbstractInsnNode found = PatternMatcher.builder() .opcodes(ALOAD, INVOKEVIRTUAL, INVOKESPECIAL) .ignoreFrames() @@ -56,10 +56,9 @@ public class CommandsPatch { InsnSequence is = new InsnSequence(); is.add(new InsnNode(DUP)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, cmdBuilt())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, cmdBuilt)); main.instructions.insert(found, is); - BytecodePrinter.logAsmMethod(main, "post.log"); } } } diff --git a/src/main/java/ftbsc/bscv/patches/EntityPushPatch.java b/src/main/java/ftbsc/bscv/patches/EntityPushPatch.java index 9cf74bd..226b471 100644 --- a/src/main/java/ftbsc/bscv/patches/EntityPushPatch.java +++ b/src/main/java/ftbsc/bscv/patches/EntityPushPatch.java @@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import net.minecraft.entity.Entity; @@ -21,27 +21,28 @@ public class EntityPushPatch implements ICommons { @Cancelable public static class PlayerEntityPushEvent extends Event {} - public static boolean shouldCancelEntityCollisions(Entity e) { - if (e.equals(MC.player)) { - return MinecraftForge.EVENT_BUS.post(new PlayerEntityPushEvent()); - } - return false; - } - - @Patch(value = Entity.class, reason = "add hook to cancel entity collisions") + @Patch(Entity.class) public abstract static class EntityCollisionsOverride implements Opcodes { - @Find(parent = EntityPushPatch.class) - abstract MethodProxy shouldCancelEntityCollisions(); + @Find(EntityCollisionsOverride.class) + MethodProxy shouldCancelEntityCollisions; + + @Target(of = "shouldCancelEntityCollisions") + public static boolean shouldCancelEntityCollisions(Entity e) { + if (e.equals(MC.player)) { + return MinecraftForge.EVENT_BUS.post(new PlayerEntityPushEvent()); + } + return false; + } - @Target + @Target(of = "injectEntityCollisionHook") abstract void push(double x, double y, double z); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel entity collisions") + public void injectEntityCollisionHook(ClassNode clazz, MethodNode main) { LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 0)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelEntityCollisions())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelEntityCollisions)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); diff --git a/src/main/java/ftbsc/bscv/patches/LiquidPushPatch.java b/src/main/java/ftbsc/bscv/patches/LiquidPushPatch.java index a800878..e883533 100644 --- a/src/main/java/ftbsc/bscv/patches/LiquidPushPatch.java +++ b/src/main/java/ftbsc/bscv/patches/LiquidPushPatch.java @@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import net.minecraft.entity.player.PlayerEntity; @@ -21,27 +21,28 @@ public class LiquidPushPatch implements ICommons { @Cancelable public static class PlayerLiquidPushEvent extends Event {} - public static boolean shouldCancelLiquidCollisions(PlayerEntity player) { - if (player.equals(MC.player)) { - return MinecraftForge.EVENT_BUS.post(new PlayerLiquidPushEvent()); - } - return false; - } - - @Patch(value = PlayerEntity.class, reason = "add hook to cancel liquid collisions") + @Patch(PlayerEntity.class) public abstract static class LiquidCollisionsOverride implements Opcodes { - @Find(parent = LiquidPushPatch.class) - abstract MethodProxy shouldCancelLiquidCollisions(); + @Find(LiquidCollisionsOverride.class) + MethodProxy shouldCancelLiquidCollisions; + + @Target(of = "shouldCancelLiquidCollisions") + public static boolean shouldCancelLiquidCollisions(PlayerEntity player) { + if (player.equals(MC.player)) { + return MinecraftForge.EVENT_BUS.post(new PlayerLiquidPushEvent()); + } + return false; + } - @Target + @Target(of = "injectLiquidCollisionHook") abstract boolean isPushedByFluid(); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel liquid collisions") + public void injectLiquidCollisionHook(ClassNode clazz, MethodNode main) { LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 0)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelLiquidCollisions())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelLiquidCollisions)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(ICONST_0)); is.add(new InsnNode(IRETURN)); diff --git a/src/main/java/ftbsc/bscv/patches/NoSlowPatch.java b/src/main/java/ftbsc/bscv/patches/NoSlowPatch.java index c9ce730..0399def 100644 --- a/src/main/java/ftbsc/bscv/patches/NoSlowPatch.java +++ b/src/main/java/ftbsc/bscv/patches/NoSlowPatch.java @@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.nodes.MethodProxyInsnNode; @@ -21,21 +21,22 @@ public class NoSlowPatch { @Cancelable public static class PlayerSlowDownEvent extends Event { } - public static boolean shouldSlowPlayer() { - return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent()); - } - - @Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel slowing down effect of using items") + @Patch(ClientPlayerEntity.class) public abstract static class SlowDownOverride implements Opcodes { - @Find(parent = NoSlowPatch.class) - abstract MethodProxy shouldSlowPlayer(); + @Find(SlowDownOverride.class) + MethodProxy shouldSlowPlayer; + + @Target(of = "shouldSlowPlayer") + public static boolean shouldSlowPlayer() { + return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent()); + } - @Target + @Target(of = "injectNoSlowHook") abstract void aiStep(); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to cancel slowing down effect of using items") + public void injectNoSlowHook(ClassNode clazz, MethodNode main) { AbstractInsnNode found = PatternMatcher.builder() .opcodes(ALOAD, INVOKEVIRTUAL, IFEQ, ALOAD, INVOKEVIRTUAL, IFNE) .ignoreFrames() @@ -56,7 +57,7 @@ public class NoSlowPatch { LabelNode skip = new LabelNode(); // TODO can we get the label that the original IF is jumping to without adding one ourselves? InsnSequence is = new InsnSequence(); - is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldSlowPlayer())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldSlowPlayer)); is.add(new JumpInsnNode(IFNE, skip)); main.instructions.insert(found, is); diff --git a/src/main/java/ftbsc/bscv/patches/PacketPatch.java b/src/main/java/ftbsc/bscv/patches/PacketPatch.java index 603dd09..7decc4b 100644 --- a/src/main/java/ftbsc/bscv/patches/PacketPatch.java +++ b/src/main/java/ftbsc/bscv/patches/PacketPatch.java @@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.impl.MethodProxy; import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.debug.BytecodePrinter; @@ -43,24 +43,21 @@ public class PacketPatch { } } - public static boolean pktIn(IPacket<?> pkt) { - return MinecraftForge.EVENT_BUS.post(new PacketEvent.Incoming(pkt)); - } - - public static boolean pktOut(IPacket<?> pkt) { - return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt)); - } - - @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets") + @Patch(NetworkManager.class) public abstract static class IncomingPacketInterceptor implements Opcodes { - @Find(parent = PacketPatch.class) - abstract MethodProxy pktIn(); + @Find(IncomingPacketInterceptor.class) + MethodProxy pktIn; - @Target - public abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak); + @Target(of = "pktIn") + public static boolean pktIn(IPacket<?> pkt) { + return MinecraftForge.EVENT_BUS.post(new PacketEvent.Incoming(pkt)); + } + + @Target(of = "injectIncomingInterceptor") + abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to intercept and alter/cancel incoming packets") + public void injectIncomingInterceptor(ClassNode clazz, MethodNode main) { AbstractInsnNode found = PatternMatcher.builder() .opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ) .ignoreFrames() @@ -73,7 +70,7 @@ public class PacketPatch { LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 2)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, pktIn())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, pktIn)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); @@ -82,21 +79,26 @@ public class PacketPatch { } } - @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel outgoing packets") + @Patch(NetworkManager.class) public abstract static class OutgoingPacketInterceptor implements Opcodes { - @Find(parent = PacketPatch.class) - abstract MethodProxy pktOut(); + @Find(OutgoingPacketInterceptor.class) + MethodProxy pktOut; + + @Target(of = "pktOut") + public static boolean pktOut(IPacket<?> pkt) { + return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt)); + } - @Target + @Target(of = "injectOutgoingInterceptor") public abstract void sendPacket(IPacket<?> pak, GenericFutureListener<? extends Future<? super Void>> gfl); - @Injector - public void inject(ClassNode clazz, MethodNode main) { + @Injector(reason = "add hook to intercept and alter/cancel outgoing packets") + public void injectOutgoingInterceptor(ClassNode clazz, MethodNode main) { // hook at the top LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); is.add(new VarInsnNode(ALOAD, 1)); - is.add(new MethodProxyInsnNode(INVOKESTATIC, pktOut())); + is.add(new MethodProxyInsnNode(INVOKESTATIC, pktOut)); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); is.add(skip); diff --git a/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java b/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java index 7a36e8e..0eaf858 100644 --- a/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java +++ b/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java @@ -13,12 +13,12 @@ import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.tools.PatternMatcher; import net.minecraft.client.entity.player.ClientPlayerEntity; -@Patch(value = ClientPlayerEntity.class, reason = "prevent minecraft from force closing guis when entering portals") +@Patch(ClientPlayerEntity.class) public abstract class PortalGuiPatch implements Opcodes { - @Target + @Target(of = "inject") abstract void handleNetherPortalClient(); - @Injector + @Injector(reason = "prevent minecraft from force closing guis when entering portals") public void inject(ClassNode clazz, MethodNode main) { LabelNode skip = new LabelNode(); |