From a1d538f2999539edc1af5eae754e7e292aeeb498 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 18 Mar 2023 22:09:40 +0100 Subject: [PATCH] feat: better packet antikick for vanillaflight --- .../bscv/modules/motion/VanillaFlight.java | 64 +++++++++++++------ .../resources/META-INF/accesstransformer.cfg | 1 + 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java index c6ef507..3de7772 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java +++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java @@ -4,6 +4,7 @@ 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.tools.Setting; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.network.play.client.CPlayerPacket; @@ -14,12 +15,7 @@ import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) -public class VanillaFlight extends QuickModule implements ICommons { - - @Override - protected int getDefaultKey() { - return UNBOUND; - } +public class VanillaFlight extends QuickModule { private enum AntikickMode { NONE, @@ -27,11 +23,14 @@ public class VanillaFlight extends QuickModule implements ICommons { FORCED } + private static final int MS_PER_TICK = 50; + public final ForgeConfigSpec.ConfigValue force; public final ForgeConfigSpec.ConfigValue speed; public final ForgeConfigSpec.ConfigValue antikick; public final ForgeConfigSpec.ConfigValue antikick_magnitude; public final ForgeConfigSpec.ConfigValue antikick_cycle; + public final ForgeConfigSpec.ConfigValue antikick_duration; private int tick = 0; @@ -71,11 +70,28 @@ public class VanillaFlight extends QuickModule implements ICommons { .name("cycle") .comment("how often to run antikick routine") .build(this); + + this.antikick_duration = Setting.Number.builder() + .min(1) + .max(80) + .fallback(5) + .name("duration") + .comment("how long to apply antikick (only for PACKET)") + .build(this); } + private long last_event = 0; + private boolean couldFlyBefore = false; private float flyingSpeedBefore = 0.05f; + private AntikickState antikickState = AntikickState.COOLDOWN; + + private enum AntikickState { + COOLDOWN, + ACTIVE + } + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase == Phase.END) return; @@ -90,19 +106,31 @@ public class VanillaFlight extends QuickModule implements ICommons { this.tick = ( this.tick + 1 ) % this.antikick_cycle.get(); Vector3d pos = MC.player.position(); - if (this.tick == 0) { - switch (this.antikick.get()) { - case PACKET: - MC.player.connection.send( - new CPlayerPacket.PositionPacket(pos.x, pos.y - this.antikick_magnitude.get(), pos.z, false) - ); + if (this.tick == 0 && this.antikick.get() == AntikickMode.PACKET) { + MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z); + } + } + + @SubscribeEvent + public void onPacketSent(PacketEvent.Outgoing event) { + long now = System.currentTimeMillis(); + switch (this.antikickState) { + case COOLDOWN: + if (now - this.last_event < this.antikick_cycle.get() * MS_PER_TICK) break; + this.last_event = now; + this.antikickState = AntikickState.ACTIVE; // don't break and also run ACTIVE + case ACTIVE: + if (now - this.last_event > this.antikick_duration.get() * MS_PER_TICK) { + this.antikickState = AntikickState.COOLDOWN; break; - case FORCED: - MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z); - break; - case NONE: - break; - } + } + if ( + event.packet instanceof CPlayerPacket.PositionPacket || + event.packet instanceof CPlayerPacket.PositionRotationPacket + ) { + CPlayerPacket packet = (CPlayerPacket) event.packet; + packet.y = packet.y - this.antikick_magnitude.get(); + } } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index f67a604..5be5b4b 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -2,5 +2,6 @@ public net.minecraft.client.gui.screen.Screen field_230710_m_ # buttons public net.minecraft.client.gui.screen.Screen field_230705_e_ # children public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b # gameMode public net.minecraft.network.play.client.CPlayerPacket field_149474_g # onGround +public net.minecraft.network.play.client.CPlayerPacket field_149477_b # y public net.minecraft.client.multiplayer.PlayerController func_78750_j()V # ensureHasSentCarriedItem() public net.minecraft.client.Minecraft field_71467_ac # rightClickDelay