aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/ftbsc/bscv/Boscovicino.java22
-rw-r--r--src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java4
-rw-r--r--src/main/java/ftbsc/bscv/modules/network/PacketLogger.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AntiHunger.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoFish.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/Freecam.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/Immovable.java2
-rw-r--r--src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java2
-rw-r--r--src/main/java/ftbsc/bscv/patches/PacketPatch.java107
-rw-r--r--src/main/java/ftbsc/bscv/system/PacketHandler.java69
13 files changed, 94 insertions, 126 deletions
diff --git a/build.gradle b/build.gradle
index 0f30ca8..3fda9f1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -66,7 +66,7 @@ dependencies {
}
compileJava { //mappings for lillero-processor
- options.compilerArgs << '-AmappingsFile=https://data.fantabos.co/output.tsrg'
+ options.compilerArgs << '-AmappingsFile=https://data.fantabos.co/1.16.5.tsrg'
}
jar {
diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java
index 65c5830..56ac76a 100644
--- a/src/main/java/ftbsc/bscv/Boscovicino.java
+++ b/src/main/java/ftbsc/bscv/Boscovicino.java
@@ -8,6 +8,7 @@ import ftbsc.bscv.api.IModule;
import ftbsc.bscv.patches.CommandsPatch.CommandsBuiltEvent;
import ftbsc.bscv.system.Friends;
import ftbsc.bscv.system.ModManager;
+import ftbsc.bscv.system.PacketHandler;
import net.minecraft.client.gui.screen.IngameMenuScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.command.CommandSource;
@@ -27,9 +28,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-@Mod("bscv")
+@Mod(Boscovicino.MOD_ID)
public class Boscovicino implements ICommons {
- public static String MOD_ID = "bscv";
+ public static final String MOD_ID = "bscv";
public static final Logger LOGGER = LogManager.getLogger();
@@ -40,7 +41,12 @@ public class Boscovicino implements ICommons {
public static ForgeConfigSpec spec;
private static Friends friends;
- public static Friends friends() { return Boscovicino.friends; }
+
+ private static PacketHandler packetHandler;
+
+ public static Friends friends() {
+ return Boscovicino.friends;
+ }
public Boscovicino() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetupComplete);
@@ -48,13 +54,16 @@ public class Boscovicino implements ICommons {
ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder();
CommandDispatcher<CommandSource> dp = this.dispatcher;
+ // load mods
Boscovicino.modManager = new ModManager(cfg, dp);
Boscovicino.modManager.load();
-
Boscovicino.modManager.finish();
-
Boscovicino.spec = cfg.build();
+ // initialise packet handler
+ Boscovicino.packetHandler = new PacketHandler();
+
+ // initialise friend manager
ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder();
Boscovicino.friends = new Friends(friendSpec, dp);
@@ -62,7 +71,7 @@ public class Boscovicino implements ICommons {
ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml");
ModLoadingContext.get().registerConfig(Type.CLIENT, friendSpec.build(), "friends.toml");
- // Register ourselves for server and other game events we are interested in
+ // register ourselves on the event bus
MinecraftForge.EVENT_BUS.register(this);
}
@@ -79,7 +88,6 @@ public class Boscovicino implements ICommons {
private void onSetupComplete(final FMLLoadCompleteEvent event) {
LOGGER.info("Initializing modules");
-
for (IModule m : modManager.mods) {
if (m.isEnabled()) {
m.enable(); // re-run enable() to register on the event bus and run enabled callbacks
diff --git a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java
index 2df6b10..c957bad 100644
--- a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java
+++ b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java
@@ -3,7 +3,7 @@ package ftbsc.bscv.modules.hud;
import com.google.auto.service.AutoService;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.HudModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.network.play.NetworkPlayerInfo;
import net.minecraft.network.play.server.SUpdateTimePacket;
diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java
index 3de7772..686bc8e 100644
--- a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java
+++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java
@@ -1,12 +1,10 @@
package ftbsc.bscv.modules.motion;
import com.google.auto.service.AutoService;
-import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
-import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.network.play.client.CPlayerPacket;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.ForgeConfigSpec;
diff --git a/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java b/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java
index e0b8431..50b3f09 100644
--- a/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java
+++ b/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java
@@ -24,7 +24,7 @@ import com.google.gson.JsonPrimitive;
import ftbsc.bscv.Boscovicino;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import net.minecraft.network.IPacket;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
diff --git a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java
index d98f61f..6dc608f 100644
--- a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java
+++ b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java
@@ -4,7 +4,7 @@ import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.AbstractModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.client.CEntityActionPacket;
import net.minecraft.network.play.client.CEntityActionPacket.Action;
diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java
index a05ca06..ec23183 100644
--- a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java
+++ b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java
@@ -4,7 +4,7 @@ import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.AbstractModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.server.SDisconnectPacket;
import net.minecraft.network.play.server.SUpdateHealthPacket;
diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java
index 7d9f5c7..519a86d 100644
--- a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java
+++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java
@@ -4,7 +4,7 @@ import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.AbstractModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPlaySoundEffectPacket;
diff --git a/src/main/java/ftbsc/bscv/modules/self/Freecam.java b/src/main/java/ftbsc/bscv/modules/self/Freecam.java
index 2811178..c7166b5 100644
--- a/src/main/java/ftbsc/bscv/modules/self/Freecam.java
+++ b/src/main/java/ftbsc/bscv/modules/self/Freecam.java
@@ -5,7 +5,7 @@ import ftbsc.bscv.Boscovicino;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Keyboard;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.entity.player.RemoteClientPlayerEntity;
diff --git a/src/main/java/ftbsc/bscv/modules/self/Immovable.java b/src/main/java/ftbsc/bscv/modules/self/Immovable.java
index b27b117..14dcf86 100644
--- a/src/main/java/ftbsc/bscv/modules/self/Immovable.java
+++ b/src/main/java/ftbsc/bscv/modules/self/Immovable.java
@@ -7,7 +7,7 @@ import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.BlockPushPatch.PlayerBlockPushEvent;
import ftbsc.bscv.patches.EntityPushPatch.PlayerEntityPushEvent;
import ftbsc.bscv.patches.LiquidPushPatch.PlayerLiquidPushEvent;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.server.SEntityVelocityPacket;
import net.minecraft.network.play.server.SExplosionPacket;
diff --git a/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java b/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java
index 6db66f1..cdec4cb 100644
--- a/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java
+++ b/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java
@@ -12,7 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
-import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.system.PacketHandler.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
diff --git a/src/main/java/ftbsc/bscv/patches/PacketPatch.java b/src/main/java/ftbsc/bscv/patches/PacketPatch.java
deleted file mode 100644
index 603dd09..0000000
--- a/src/main/java/ftbsc/bscv/patches/PacketPatch.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package ftbsc.bscv.patches;
-
-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.tools.InsnSequence;
-import ftbsc.lll.tools.PatternMatcher;
-import ftbsc.lll.tools.debug.BytecodePrinter;
-import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.util.concurrent.Future;
-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 PacketEvent {
- @Cancelable
- public static class Outgoing extends Event {
- public final IPacket<?> packet;
-
- public Outgoing(IPacket<?> packet) {
- this.packet = packet;
- }
- }
-
- @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 {
- @Find(parent = PacketPatch.class)
- abstract MethodProxy pktIn();
-
- @Target
- public abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak);
-
- @Injector
- public void inject(ClassNode clazz, MethodNode main) {
- AbstractInsnNode found = PatternMatcher.builder()
- .opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ)
- .ignoreFrames()
- .ignoreLabels()
- .ignoreLineNumbers()
- .build()
- .find(main)
- .getLast();
-
- LabelNode skip = new LabelNode();
- InsnSequence is = new InsnSequence();
- is.add(new VarInsnNode(ALOAD, 2));
- is.add(new MethodProxyInsnNode(INVOKESTATIC, pktIn()));
- is.add(new JumpInsnNode(IFEQ, skip));
- is.add(new InsnNode(RETURN));
- is.add(skip);
-
- main.instructions.insert(found, is);
- }
- }
-
- @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel outgoing packets")
- public abstract static class OutgoingPacketInterceptor implements Opcodes {
- @Find(parent = PacketPatch.class)
- abstract MethodProxy pktOut();
-
- @Target
- public abstract void sendPacket(IPacket<?> pak, GenericFutureListener<? extends Future<? super Void>> gfl);
-
- @Injector
- public void inject(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 JumpInsnNode(IFEQ, skip));
- is.add(new InsnNode(RETURN));
- is.add(skip);
-
- main.instructions.insert(is);
- }
- }
-}
diff --git a/src/main/java/ftbsc/bscv/system/PacketHandler.java b/src/main/java/ftbsc/bscv/system/PacketHandler.java
new file mode 100644
index 0000000..7c80db2
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/system/PacketHandler.java
@@ -0,0 +1,69 @@
+package ftbsc.bscv.system;
+
+import ftbsc.bscv.Boscovicino;
+import io.netty.channel.*;
+import net.minecraft.network.IPacket;
+import net.minecraft.network.NetworkManager;
+import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.eventbus.api.Cancelable;
+import net.minecraftforge.eventbus.api.Event;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+@ChannelHandler.Sharable
+public class PacketHandler extends ChannelDuplexHandler {
+
+ public PacketHandler() {
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ if(processPacket(msg, false))
+ super.channelRead(ctx, msg);
+ }
+
+ @Override
+ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
+ if(processPacket(msg, true))
+ super.write(ctx, msg, promise);
+ }
+
+ private static boolean processPacket(Object msg, boolean outgoing) {
+ if(msg instanceof IPacket) {
+ IPacket<?> pkt = (IPacket<?>) msg;
+ PacketEvent event = outgoing ? new PacketEvent.Outgoing(pkt) : new PacketEvent.Incoming(pkt);
+ MinecraftForge.EVENT_BUS.post(event);
+ return !event.isCanceled();
+ } else return true;
+ }
+
+ @SubscribeEvent
+ public void registerOnLogin(ClientPlayerNetworkEvent.LoggedInEvent event) {
+ NetworkManager nm = event.getNetworkManager();
+ if(nm != null) {
+ nm.channel().pipeline().addBefore("packet_handler", "bscv_handler", this);
+ Boscovicino.LOGGER.info("Successfully registered PacketHandler!");
+ } else Boscovicino.LOGGER.error("Failed to register PacketHandler: NetworkManager was null!");
+ }
+
+ @Cancelable
+ public static class PacketEvent extends Event {
+
+ public static class Outgoing extends PacketEvent {
+ public final IPacket<?> packet;
+
+ public Outgoing(IPacket<?> packet) {
+ this.packet = packet;
+ }
+ }
+
+ public static class Incoming extends PacketEvent {
+ public final IPacket<?> packet;
+
+ public Incoming(IPacket<?> packet) {
+ this.packet = packet;
+ }
+ }
+ }
+}