summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-18 22:09:40 +0100
committer alemi <me@alemi.dev>2023-03-18 22:09:40 +0100
commita1d538f2999539edc1af5eae754e7e292aeeb498 (patch)
tree273cecfc6c1133dc3d09ce668b9e1ce64e92ab62
parentfa10646d8f2694f03ad861cafff55651592a02a2 (diff)
feat: better packet antikick for vanillaflight0.3.7
-rw-r--r--src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java64
-rw-r--r--src/main/resources/META-INF/accesstransformer.cfg1
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<Boolean> force;
public final ForgeConfigSpec.ConfigValue<Double> speed;
public final ForgeConfigSpec.ConfigValue<AntikickMode> antikick;
public final ForgeConfigSpec.ConfigValue<Double> antikick_magnitude;
public final ForgeConfigSpec.ConfigValue<Integer> antikick_cycle;
+ public final ForgeConfigSpec.ConfigValue<Integer> 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)
- );
- break;
- case FORCED:
- MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z);
- break;
- case NONE:
+ 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;
- }
+ }
+ 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