From e249ecb663d27dc65d7d73e5bef72bc6e09c5433 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 26 May 2024 00:54:29 +0200 Subject: [PATCH] add timer --- .../java/com/baseband/client/init/Setup.java | 2 + .../baseband/client/module/client/Client.java | 47 +++++++++++++ .../baseband/client/module/client/Timer.java | 67 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 Client/src/main/java/com/baseband/client/module/client/Timer.java diff --git a/Client/src/main/java/com/baseband/client/init/Setup.java b/Client/src/main/java/com/baseband/client/init/Setup.java index 1f00d2e..bb8a5c3 100644 --- a/Client/src/main/java/com/baseband/client/init/Setup.java +++ b/Client/src/main/java/com/baseband/client/init/Setup.java @@ -6,6 +6,7 @@ import com.baseband.client.module.chat.ChatCrypt; import com.baseband.client.module.chat.ExtraChat; import com.baseband.client.module.client.Client; import com.baseband.client.module.client.MidClick; +import com.baseband.client.module.client.Timer; import com.baseband.client.module.combat.AutoKill; import com.baseband.client.module.combat.AutoTotem; import com.baseband.client.module.command.Bind; @@ -53,6 +54,7 @@ public class Setup { new Bright(), new MidClick(), new Selection(), + new Timer(), }; diff --git a/Client/src/main/java/com/baseband/client/module/client/Client.java b/Client/src/main/java/com/baseband/client/module/client/Client.java index 7301e04..d3518a2 100644 --- a/Client/src/main/java/com/baseband/client/module/client/Client.java +++ b/Client/src/main/java/com/baseband/client/module/client/Client.java @@ -1,10 +1,14 @@ package com.baseband.client.module.client; import com.baseband.client.configuration.annotation.Config; +import com.baseband.client.event.events.PacketEvent; +import com.baseband.client.event.events.PlayerDestroyEvent; import com.baseband.client.gui.GuiTheme; import com.baseband.client.init.BaseBand; import com.baseband.client.module.Feature; import com.baseband.client.util.ingame.ChatUtil; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.SPacketTimeUpdate; import net.minecraftforge.common.MinecraftForge; @com.baseband.client.module.category.Client @@ -52,4 +56,47 @@ public class Client extends Feature { BaseBand.disabled = true; ChatUtil.print("Waiting for config..."); } + + + public float tps = 20; + long lastDiff = 0; + long lastTick = -1; + + public void onPlayerDestroy(PlayerDestroyEvent event) { + tps = 20; + } + + public void onPacket(PacketEvent.Read packetEvent) { + Packet packet = packetEvent.getPacket(); + if (packet instanceof SPacketTimeUpdate) { + long time = System.currentTimeMillis(); + if (lastTick != -1) { + long diff = time - lastTick; + time(diff); + lastDiff = diff; + } + lastTick = time; + } + } + + @Override + public void onTick() { + if (notIngame()) return; + + long time = System.currentTimeMillis(); + if (lastTick != -1) { + long diff = time - lastTick; + if (diff > 3000 && diff > lastDiff) { + time(diff); + } + } + } + + public void time(long diff) { + if (lastTick != -1) { + if (diff > 50) { + tps = (1000f / diff) * 20f; + } + } + } } diff --git a/Client/src/main/java/com/baseband/client/module/client/Timer.java b/Client/src/main/java/com/baseband/client/module/client/Timer.java new file mode 100644 index 0000000..d42b3db --- /dev/null +++ b/Client/src/main/java/com/baseband/client/module/client/Timer.java @@ -0,0 +1,67 @@ +package com.baseband.client.module.client; + +import com.baseband.client.configuration.annotation.Config; +import com.baseband.client.configuration.annotation.Gate; +import com.baseband.client.configuration.annotation.Range; +import com.baseband.client.event.events.PacketEvent; +import com.baseband.client.event.events.PlayerDestroyEvent; +import com.baseband.client.init.BaseBand; +import com.baseband.client.module.Feature; +import com.baseband.client.module.category.Client; +import com.baseband.client.util.misc.FieldFinder; +import com.baseband.client.util.misc.Marker; +import net.minecraft.client.Minecraft; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.SPacketTimeUpdate; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Client +public class Timer extends Feature { + + @Config("Multiplier") + @Range("0.05..7.5") + float m = 0.5f; + @Config("Adjust to server") + @Marker(1) + public boolean adjust = false; + @Config("Fasten") + @Gate(1) + boolean fasten = false; + @Config("Slowdown") + @Gate(1) + boolean slowdown = true; + + @Override + public void onDisable() { + setGameTimer(20); + } + + public void onPlayerDestroy(PlayerDestroyEvent event) { + toggle(); + } + + @SubscribeEvent + public void onRender(RenderWorldLastEvent event) { + onTick(); + } + + @Override + public void onTick() { + setGameTimer(BaseBand.getFeature(com.baseband.client.module.client.Client.class).tps * m); + } + + @Override + public String toString() { + return "Timer [TPS: " + BaseBand.getFeature(com.baseband.client.module.client.Client.class).tps * m + "]"; + } + + public void setGameTimer(float tps) { + try { + Object timer = FieldFinder.findUnmarked(Minecraft.class, net.minecraft.util.Timer.class, 0).get(mc); + FieldFinder.findUnmarked(net.minecraft.util.Timer.class, float.class, 2).setFloat(timer, 1000f / tps); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +}