Skip to content

Commit 4b950ba

Browse files
committed
Tick Shift renderer & refactor
1 parent e862bf4 commit 4b950ba

File tree

7 files changed

+117
-22
lines changed

7 files changed

+117
-22
lines changed

common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.lambda.event.callback.Cancellable
66
import com.lambda.event.callback.ICancellable
77
import com.lambda.event.events.PacketEvent.Receive
88
import com.lambda.event.events.PacketEvent.Send
9+
import com.lambda.util.ClientPacket
10+
import com.lambda.util.ServerPacket
911
import net.minecraft.network.listener.ClientPacketListener
1012
import net.minecraft.network.listener.ServerPacketListener
1113
import net.minecraft.network.packet.Packet
@@ -36,14 +38,14 @@ abstract class PacketEvent : Event {
3638
*
3739
* @param packet the packet that is about to be sent.
3840
*/
39-
class Pre(val packet: Packet<out ServerPacketListener>) : Send(), ICancellable by Cancellable()
41+
class Pre(val packet: ClientPacket) : Send(), ICancellable by Cancellable()
4042

4143
/**
4244
* Represents the event triggered after a packet is sent.
4345
*
4446
* @param packet the packet that has been sent.
4547
*/
46-
class Post(val packet: Packet<out ServerPacketListener>) : Send()
48+
class Post(val packet: ClientPacket) : Send()
4749
}
4850

4951
/**
@@ -56,13 +58,13 @@ abstract class PacketEvent : Event {
5658
*
5759
* @param packet the packet that is about to be received.
5860
*/
59-
class Pre(val packet: Packet<out ClientPacketListener>) : Receive(), ICancellable by Cancellable()
61+
class Pre(val packet: ServerPacket) : Receive(), ICancellable by Cancellable()
6062

6163
/**
6264
* Represents the event triggered after a packet is received.
6365
*
6466
* @param packet the packet that has been received.
6567
*/
66-
class Post(val packet: Packet<out ClientPacketListener>) : Receive()
68+
class Post(val packet: ServerPacket) : Receive()
6769
}
6870
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/FilledRectRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FilledRectRenderer : AbstractRectRenderer(
4141
val halfSize = size * 0.5
4242
val maxRadius = min(halfSize.x, halfSize.y)
4343

44-
val round = min(roundRadius, maxRadius)
44+
val round = roundRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
4545

4646
val p1 = pos1 - 0.25
4747
val p2 = pos2 + 0.25

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OutlineRectRenderer : AbstractRectRenderer(
4747

4848
val halfSize = r.size * 0.5
4949
val maxRadius = min(halfSize.x, halfSize.y) - 0.5
50-
val round = (roundRadius + size).coerceAtMost(maxRadius)
50+
val round = (roundRadius + size).coerceAtMost(maxRadius).coerceAtLeast(0.0)
5151

5252
fun MutableList<Int>.buildCorners(base: Vec2d, c: Color, angleRange: IntRange) = repeat(quality) {
5353
val min = angleRange.first.toDouble()

common/src/main/kotlin/com/lambda/module/HudModule.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.lambda.module
22

33
import com.lambda.event.events.RenderEvent
4+
import com.lambda.event.events.TickEvent
45
import com.lambda.event.listener.SafeListener.Companion.listener
6+
import com.lambda.graphics.animation.AnimationTicker
7+
import com.lambda.gui.api.GuiEvent
58
import com.lambda.gui.api.RenderLayer
69
import com.lambda.gui.api.component.core.DockingRect
710
import com.lambda.module.tag.ModuleTag
@@ -52,6 +55,7 @@ abstract class HudModule(
5255

5356
var position by rectHandler::position
5457
val rect by rectHandler::rect
58+
val animation = AnimationTicker()
5559

5660
private val renderer = RenderLayer()
5761

@@ -68,5 +72,9 @@ abstract class HudModule(
6872

6973
renderer.render()
7074
}
75+
76+
listener<TickEvent.Pre> {
77+
animation.tick()
78+
}
7179
}
7280
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.lambda.module.hud
2+
3+
import com.lambda.graphics.animation.Animation.Companion.exp
4+
import com.lambda.module.HudModule
5+
import com.lambda.module.modules.client.ClickGui
6+
import com.lambda.module.modules.client.GuiSettings
7+
import com.lambda.module.modules.client.GuiSettings.primaryColor
8+
import com.lambda.module.modules.movement.TickShift
9+
import com.lambda.module.tag.ModuleTag
10+
import com.lambda.util.math.ColorUtils.multAlpha
11+
import com.lambda.util.math.Rect
12+
import java.awt.Color
13+
14+
object TickShiftCharge : HudModule(
15+
name = "TickShiftCharge",
16+
defaultTags = setOf(ModuleTag.CLIENT),
17+
) {
18+
private val isActive get() = TickShift.isEnabled && TickShift.isActive && TickShift.boost
19+
private val activeAnimation by animation.exp(0.0, 1.0, 0.6, ::isActive)
20+
21+
private val progress get() = if (!TickShift.isActive) 0.0
22+
else (TickShift.balance / TickShift.maxBalance.toDouble()).coerceIn(0.0..1.0)
23+
24+
private val renderProgress by animation.exp(::progress, 0.8)
25+
26+
override val width = 70.0
27+
override val height = 14.0
28+
29+
init {
30+
onRender {
31+
filled.build(
32+
rect = rect,
33+
roundRadius = ClickGui.windowRadius,
34+
color = GuiSettings.backgroundColor,
35+
shade = GuiSettings.shadeBackground
36+
)
37+
38+
val padding = 1.0
39+
filled.build(
40+
rect = Rect.basedOn(rect.leftTop, rect.size.x * renderProgress, rect.size.y).shrink(padding),
41+
roundRadius = ClickGui.windowRadius - padding,
42+
color = GuiSettings.mainColor.multAlpha(0.3),
43+
shade = true
44+
)
45+
46+
outline.build(
47+
rect = rect,
48+
roundRadius = ClickGui.windowRadius,
49+
color = (if (GuiSettings.shadeBackground) Color.WHITE else primaryColor).multAlpha(activeAnimation),
50+
glowRadius = ClickGui.glowRadius * activeAnimation,
51+
shade = true
52+
)
53+
}
54+
}
55+
}

common/src/main/kotlin/com/lambda/module/modules/movement/TickShift.kt

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,37 @@ import com.lambda.module.modules.combat.KillAura
1010
import com.lambda.module.tag.ModuleTag
1111
import com.lambda.threading.runConcurrent
1212
import com.lambda.util.Communication.info
13+
import com.lambda.util.PacketUtils.handlePacketSilently
1314
import com.lambda.util.PacketUtils.sendPacketSilently
1415
import kotlinx.coroutines.delay
15-
import net.minecraft.network.ClientConnection
1616
import net.minecraft.network.packet.c2s.common.CommonPongC2SPacket
17+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket
1718
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket
1819

1920
object TickShift : Module(
2021
name = "TickShift",
2122
description = "Smort tickshift for smort anticheats",
2223
defaultTags = setOf(ModuleTag.MOVEMENT)
2324
) {
24-
private val maxBalance by setting("Max Balance", 20, 3..400, 1)
25+
val maxBalance by setting("Max Balance", 20, 3..400, 1)
2526
private val boostAmount by setting("Boost", 3.0, 1.1..20.0, 0.01)
2627
private val slowdown by setting("Slowdown", 0.35, 0.01..0.9, 0.01)
28+
private val delaySetting by setting("Delay", 0, 0..2000, 10)
29+
private val strict by setting("Strict", true)
2730
private val shiftVelocity by setting("Shift velocity", true)
2831
private val requiresAura by setting("Requires Aura", false)
2932

30-
private val isActive get() = (KillAura.isEnabled && KillAura.target != null) || !requiresAura
33+
val isActive: Boolean get() {
34+
if (requiresAura && (!KillAura.isEnabled || KillAura.target == null)) return false
35+
return System.currentTimeMillis() - lastBoost > delaySetting
36+
}
3137

3238
private var pingPool = ArrayDeque<CommonPongC2SPacket>()
3339
private var lastVelocity: EntityVelocityUpdateS2CPacket? = null
3440

35-
private var balance = 0
36-
private var boost = false
41+
var balance = 0
42+
var boost = false
43+
private var lastBoost = 0L
3744

3845
init {
3946
listener<TickEvent.Post> {
@@ -42,26 +49,43 @@ object TickShift : Module(
4249
disable()
4350
}
4451

45-
if (--balance <= 0) {
52+
if (strict) balance--
53+
54+
if (balance <= 0) {
4655
balance = 0
47-
boost = false
4856
poolPackets()
57+
58+
if (boost) {
59+
boost = false
60+
lastBoost = System.currentTimeMillis()
61+
}
4962
}
5063
}
5164

65+
listener<PacketEvent.Send.Pre> {
66+
if (it.packet !is PlayerMoveC2SPacket) return@listener
67+
if (!strict) balance--
68+
}
69+
5270
runConcurrent {
5371
while (true) {
5472
delay(50)
5573

56-
if (++balance >= maxBalance) {
57-
balance = maxBalance
58-
boost = isActive
74+
if (isEnabled) {
75+
if (++balance >= maxBalance) {
76+
balance = maxBalance
77+
boost = isActive
78+
}
5979
}
6080
}
6181
}
6282

6383
listener<ClientEvent.Timer> {
64-
if (!isActive) return@listener
84+
if (!isActive) {
85+
poolPackets()
86+
return@listener
87+
}
88+
6589
it.speed = if (boost) boostAmount else slowdown
6690
}
6791

@@ -94,17 +118,20 @@ object TickShift : Module(
94118
}
95119

96120
onDisable {
121+
balance = 0
122+
boost = false
123+
97124
poolPackets()
98125
}
99126
}
100-
127+
101128
private fun SafeContext.poolPackets() {
102129
while (pingPool.isNotEmpty()) {
103130
connection.sendPacketSilently(pingPool.removeFirst())
104131
}
105132

106-
lastVelocity?.let { velocity ->
107-
ClientConnection.handlePacket(velocity, connection.connection.packetListener)
133+
lastVelocity?.let {
134+
connection.handlePacketSilently(it)
108135
lastVelocity = null
109136
}
110137
}

common/src/main/kotlin/com/lambda/util/PacketUtils.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object PacketUtils {
1414
*
1515
* @param packet The packet to send.
1616
*/
17-
fun ClientPlayNetworkHandler.sendPacketSilently(packet: Packet<out ServerPacketListener>) {
17+
fun ClientPlayNetworkHandler.sendPacketSilently(packet: ClientPacket) {
1818
if (!connection.isOpen) return
1919
connection.send(packet, null, true)
2020
connection.packetsSentCounter++
@@ -27,11 +27,14 @@ object PacketUtils {
2727
*
2828
* @param packet The packet to handle.
2929
*/
30-
fun ClientPlayNetworkHandler.handlePacketSilently(packet: Packet<out ClientPacketListener>) {
30+
fun ClientPlayNetworkHandler.handlePacketSilently(packet: ServerPacket) {
3131
if (!connection.isOpen) return
3232
if (connection.packetListener?.accepts(packet) == false) return
3333

3434
ClientConnection.handlePacket(packet, connection.packetListener)
3535
connection.packetsReceivedCounter++
3636
}
3737
}
38+
39+
typealias ClientPacket = Packet<out ServerPacketListener>
40+
typealias ServerPacket = Packet<out ClientPacketListener>

0 commit comments

Comments
 (0)