diff options
Diffstat (limited to 'src/main/java')
6 files changed, 37 insertions, 40 deletions
diff --git a/src/main/java/ftbsc/bscv/events/PacketEvent.java b/src/main/java/ftbsc/bscv/events/PacketEvent.java deleted file mode 100644 index 67808fd..0000000 --- a/src/main/java/ftbsc/bscv/events/PacketEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package ftbsc.bscv.events; - -import net.minecraft.network.IPacket; -import net.minecraftforge.eventbus.api.Cancelable; -import net.minecraftforge.eventbus.api.Event; - -@Cancelable -public class PacketEvent extends Event { - // TODO redo this as two subclasses rather than a BOOL????? - - public IPacket<?> packet; - public boolean outgoing; - - public PacketEvent(IPacket<?> pkt, boolean outgoing) { - this.packet = pkt; - this.outgoing = outgoing; - } -} diff --git a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java index 72fe395..d98f61f 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java +++ b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java @@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self; import com.google.auto.service.AutoService; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.events.PacketEvent; import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Setting; import net.minecraft.network.play.client.CEntityActionPacket; import net.minecraft.network.play.client.CEntityActionPacket.Action; @@ -35,8 +35,7 @@ public class AntiHunger extends AbstractModule implements ICommons { } @SubscribeEvent - public void onPacket(PacketEvent event) { - if (!event.outgoing) return; + public void onPacket(PacketEvent.Outgoing event) { if (this.sprint.get() && event.packet instanceof CEntityActionPacket) { CEntityActionPacket packet = (CEntityActionPacket) event.packet; if ( diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java index 4161f70..a05ca06 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java @@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self; import com.google.auto.service.AutoService; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.events.PacketEvent; import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Setting; import net.minecraft.network.play.server.SDisconnectPacket; import net.minecraft.network.play.server.SUpdateHealthPacket; @@ -28,8 +28,7 @@ public class AutoDisconnect extends AbstractModule implements ICommons { } @SubscribeEvent - public void onPacket(PacketEvent event) { - if (event.outgoing) return; + public void onPacket(PacketEvent.Incoming event) { if (event.packet instanceof SUpdateHealthPacket) { SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet; if (packet.getHealth() < this.threshold.get()) { diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java index b7a35fb..7d9f5c7 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java @@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self; import com.google.auto.service.AutoService; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.events.PacketEvent; import ftbsc.bscv.modules.AbstractModule; +import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Setting; import net.minecraft.client.Minecraft; import net.minecraft.network.play.server.SPlaySoundEffectPacket; @@ -37,9 +37,7 @@ public class AutoFish extends AbstractModule implements ICommons { } @SubscribeEvent - public void onPacket(PacketEvent event) { - if (event.outgoing) return; - + public void onPacket(PacketEvent.Incoming event) { if (event.packet instanceof SPlaySoundEffectPacket) { SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet; if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) { diff --git a/src/main/java/ftbsc/bscv/modules/self/Freecam.java b/src/main/java/ftbsc/bscv/modules/self/Freecam.java index 92351ed..2811178 100644 --- a/src/main/java/ftbsc/bscv/modules/self/Freecam.java +++ b/src/main/java/ftbsc/bscv/modules/self/Freecam.java @@ -4,8 +4,8 @@ import com.google.auto.service.AutoService; import ftbsc.bscv.Boscovicino; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.events.PacketEvent; import ftbsc.bscv.modules.QuickModule; +import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Keyboard; import ftbsc.bscv.tools.Setting; import net.minecraft.client.entity.player.RemoteClientPlayerEntity; @@ -57,9 +57,9 @@ public class Freecam extends QuickModule implements ICommons { } @SubscribeEvent - public void onPacket(PacketEvent event) { + public void onPacket(PacketEvent.Outgoing event) { if (MC.player == null) return; - if (event.outgoing && event.packet instanceof CPlayerPacket) { // TODO must ignore more packets than just this + if (event.packet instanceof CPlayerPacket) { // TODO must ignore more packets than just this if (this.log.get()) { Boscovicino.log(String.format("[X] %s", event.packet.getClass().getName())); } diff --git a/src/main/java/ftbsc/bscv/patches/PacketPatch.java b/src/main/java/ftbsc/bscv/patches/PacketPatch.java index a1b8cb0..7d93625 100644 --- a/src/main/java/ftbsc/bscv/patches/PacketPatch.java +++ b/src/main/java/ftbsc/bscv/patches/PacketPatch.java @@ -1,6 +1,5 @@ package ftbsc.bscv.patches; -import ftbsc.bscv.events.PacketEvent; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; @@ -11,21 +10,42 @@ import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.network.IPacket; import net.minecraft.network.NetworkManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; + import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; public class PacketPatch { - public static class PacketHook { - public static boolean pktIn(IPacket<?> pkt) { - return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, false)); + public static class PacketEvent { + @Cancelable + public static class Outgoing extends Event { + public final IPacket<?> packet; + + public Outgoing(IPacket<?> packet) { + this.packet = packet; + } } - public static boolean pktOut(IPacket<?> pkt) { - return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, true)); + @Cancelable + public static class Incoming extends Event { + public final IPacket<?> packet; + + public Incoming(IPacket<?> packet) { + this.packet = packet; + } } } + 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") public abstract static class IncomingPacketInterceptor implements Opcodes { @Target @@ -49,7 +69,7 @@ public class PacketPatch { is.add(new VarInsnNode(ALOAD, 2)); is.add(new MethodInsnNode( INVOKESTATIC, - "ftbsc/bscv/patches/PacketPatch$PacketHook", + "ftbsc/bscv/patches/PacketPatch", "pktIn", "(Lnet/minecraft/network/IPacket;)Z" )); @@ -75,7 +95,7 @@ public class PacketPatch { is.add(new VarInsnNode(ALOAD, 1)); is.add(new MethodInsnNode( INVOKESTATIC, - "ftbsc/bscv/patches/PacketPatch$PacketHook", + "ftbsc/bscv/patches/PacketPatch", "pktOut", "(Lnet/minecraft/network/IPacket;)Z" )); @@ -85,6 +105,5 @@ public class PacketPatch { main.instructions.insert(is); } - } } |