chore: moved packetpatch stuff in pktpatch class

This commit is contained in:
əlemi 2023-03-11 22:52:39 +01:00
parent f0488fdd5d
commit a456396f8f
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 37 additions and 40 deletions

View file

@ -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;
}
}

View file

@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons; import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Setting; import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.client.CEntityActionPacket; import net.minecraft.network.play.client.CEntityActionPacket;
import net.minecraft.network.play.client.CEntityActionPacket.Action; import net.minecraft.network.play.client.CEntityActionPacket.Action;
@ -35,8 +35,7 @@ public class AntiHunger extends AbstractModule implements ICommons {
} }
@SubscribeEvent @SubscribeEvent
public void onPacket(PacketEvent event) { public void onPacket(PacketEvent.Outgoing event) {
if (!event.outgoing) return;
if (this.sprint.get() && event.packet instanceof CEntityActionPacket) { if (this.sprint.get() && event.packet instanceof CEntityActionPacket) {
CEntityActionPacket packet = (CEntityActionPacket) event.packet; CEntityActionPacket packet = (CEntityActionPacket) event.packet;
if ( if (

View file

@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons; import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Setting; import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.server.SDisconnectPacket; import net.minecraft.network.play.server.SDisconnectPacket;
import net.minecraft.network.play.server.SUpdateHealthPacket; import net.minecraft.network.play.server.SUpdateHealthPacket;
@ -28,8 +28,7 @@ public class AutoDisconnect extends AbstractModule implements ICommons {
} }
@SubscribeEvent @SubscribeEvent
public void onPacket(PacketEvent event) { public void onPacket(PacketEvent.Incoming event) {
if (event.outgoing) return;
if (event.packet instanceof SUpdateHealthPacket) { if (event.packet instanceof SUpdateHealthPacket) {
SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet; SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet;
if (packet.getHealth() < this.threshold.get()) { if (packet.getHealth() < this.threshold.get()) {

View file

@ -3,8 +3,8 @@ package ftbsc.bscv.modules.self;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons; import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Setting; import ftbsc.bscv.tools.Setting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPlaySoundEffectPacket; import net.minecraft.network.play.server.SPlaySoundEffectPacket;
@ -37,9 +37,7 @@ public class AutoFish extends AbstractModule implements ICommons {
} }
@SubscribeEvent @SubscribeEvent
public void onPacket(PacketEvent event) { public void onPacket(PacketEvent.Incoming event) {
if (event.outgoing) return;
if (event.packet instanceof SPlaySoundEffectPacket) { if (event.packet instanceof SPlaySoundEffectPacket) {
SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet; SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet;
if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) { if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) {

View file

@ -4,8 +4,8 @@ import com.google.auto.service.AutoService;
import ftbsc.bscv.Boscovicino; import ftbsc.bscv.Boscovicino;
import ftbsc.bscv.ICommons; import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.QuickModule; import ftbsc.bscv.modules.QuickModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Keyboard; import ftbsc.bscv.tools.Keyboard;
import ftbsc.bscv.tools.Setting; import ftbsc.bscv.tools.Setting;
import net.minecraft.client.entity.player.RemoteClientPlayerEntity; import net.minecraft.client.entity.player.RemoteClientPlayerEntity;
@ -57,9 +57,9 @@ public class Freecam extends QuickModule implements ICommons {
} }
@SubscribeEvent @SubscribeEvent
public void onPacket(PacketEvent event) { public void onPacket(PacketEvent.Outgoing event) {
if (MC.player == null) return; 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()) { if (this.log.get()) {
Boscovicino.log(String.format("[X] %s", event.packet.getClass().getName())); Boscovicino.log(String.format("[X] %s", event.packet.getClass().getName()));
} }

View file

@ -1,6 +1,5 @@
package ftbsc.bscv.patches; package ftbsc.bscv.patches;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
@ -11,19 +10,40 @@ import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.IPacket; import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraftforge.common.MinecraftForge; 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.Opcodes;
import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.*;
public class PacketPatch { public class PacketPatch {
public static class PacketHook { 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) { public static boolean pktIn(IPacket<?> pkt) {
return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, false)); return MinecraftForge.EVENT_BUS.post(new PacketEvent.Incoming(pkt));
} }
public static boolean pktOut(IPacket<?> pkt) { public static boolean pktOut(IPacket<?> pkt) {
return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, true)); return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt));
}
} }
@Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets") @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets")
@ -49,7 +69,7 @@ public class PacketPatch {
is.add(new VarInsnNode(ALOAD, 2)); is.add(new VarInsnNode(ALOAD, 2));
is.add(new MethodInsnNode( is.add(new MethodInsnNode(
INVOKESTATIC, INVOKESTATIC,
"ftbsc/bscv/patches/PacketPatch$PacketHook", "ftbsc/bscv/patches/PacketPatch",
"pktIn", "pktIn",
"(Lnet/minecraft/network/IPacket;)Z" "(Lnet/minecraft/network/IPacket;)Z"
)); ));
@ -75,7 +95,7 @@ public class PacketPatch {
is.add(new VarInsnNode(ALOAD, 1)); is.add(new VarInsnNode(ALOAD, 1));
is.add(new MethodInsnNode( is.add(new MethodInsnNode(
INVOKESTATIC, INVOKESTATIC,
"ftbsc/bscv/patches/PacketPatch$PacketHook", "ftbsc/bscv/patches/PacketPatch",
"pktOut", "pktOut",
"(Lnet/minecraft/network/IPacket;)Z" "(Lnet/minecraft/network/IPacket;)Z"
)); ));
@ -85,6 +105,5 @@ public class PacketPatch {
main.instructions.insert(is); main.instructions.insert(is);
} }
} }
} }