|
| 1 | +package com.lambda.module.modules.player |
| 2 | + |
| 3 | +import com.lambda.context.SafeContext |
| 4 | +import com.lambda.event.events.* |
| 5 | +import com.lambda.event.listener.SafeListener.Companion.listener |
| 6 | +import com.lambda.graphics.renderer.esp.DynamicAABB |
| 7 | +import com.lambda.graphics.renderer.esp.builders.buildFilled |
| 8 | +import com.lambda.graphics.renderer.esp.builders.buildOutline |
| 9 | +import com.lambda.graphics.renderer.esp.global.DynamicESP |
| 10 | +import com.lambda.module.Module |
| 11 | +import com.lambda.module.tag.ModuleTag |
| 12 | +import com.lambda.util.math.transform |
| 13 | +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket |
| 14 | +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action |
| 15 | +import com.lambda.util.math.MathUtils.lerp |
| 16 | +import net.minecraft.util.math.Box |
| 17 | +import java.awt.Color |
| 18 | + |
| 19 | +object FastBreak : Module( |
| 20 | + name = "FastBreak", |
| 21 | + description = "Break blocks faster.", |
| 22 | + defaultTags = setOf( |
| 23 | + ModuleTag.PLAYER, ModuleTag.WORLD |
| 24 | + ) |
| 25 | +) { |
| 26 | + private val page by setting("Page", Page.Mining) |
| 27 | + |
| 28 | + private val breakDelay by setting("Break Delay", 5, 0..5, 1, unit = "ticks", description = "The tick delay between breaking blocks", visibility = { page == Page.Mining }) |
| 29 | + private val breakThreshold by setting("Break Threshold", 0.7f, 0.2f..1.0f, 0.1f, description = "The progress at which the block will break.", visibility = { page == Page.Mining }) |
| 30 | + |
| 31 | + private val renderMode by setting("Render Mode", RenderMode.Out, "The animation style of the renders", visibility = { page == Page.Render }) |
| 32 | + private val renderSetting by setting("Render Setting", RenderSetting.Both, "The different ways to draw the renders", visibility = { page == Page.Render && renderMode.isEnabled() }) |
| 33 | + |
| 34 | + private val fillColourMode by setting("Fill Mode", ColourMode.Dynamic, visibility = { page == Page.Render && renderSetting != RenderSetting.Outline }) |
| 35 | + private val staticFillColour by setting("Static Fill Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the static fill of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Static }) |
| 36 | + private val startFillColour by setting("Start Fill Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the start fill of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Dynamic }) |
| 37 | + private val endFillColour by setting("End Fill Colour", Color(0f, 1f, 0f, 0.3f), "The colour used to render the end fill of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Dynamic }) |
| 38 | + |
| 39 | + private val outlineColourMode by setting("Outline Mode", ColourMode.Dynamic, visibility = { page == Page.Render && renderSetting != RenderSetting.Fill }) |
| 40 | + private val staticOutlineColour by setting("Static Outline Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the static outline of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Static }) |
| 41 | + private val startOutlineColour by setting("Start Outline Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the start outline of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Dynamic }) |
| 42 | + private val endOutlineColour by setting("End Outline Colour", Color(0f, 1f, 0f, 0.3f), "The colour used to render the end outline of the box", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Dynamic }) |
| 43 | + private val outlineWidth by setting("Outline Width", 1f, 0f..3f, 0.1f, "the thickness of the outline", visibility = { page == Page.Render && renderMode.isEnabled() && renderSetting != RenderSetting.Fill }) |
| 44 | + |
| 45 | + |
| 46 | + private val renderer = DynamicESP |
| 47 | + private var boxSet = emptySet<Box>() |
| 48 | + |
| 49 | + private enum class Page { |
| 50 | + Mining, Render |
| 51 | + } |
| 52 | + |
| 53 | + private enum class RenderMode { |
| 54 | + Out, In, InOut, OutIn, Static, None; |
| 55 | + |
| 56 | + fun isEnabled(): Boolean = |
| 57 | + this != None |
| 58 | + } |
| 59 | + |
| 60 | + private enum class ColourMode { |
| 61 | + Static, Dynamic |
| 62 | + } |
| 63 | + |
| 64 | + private enum class RenderSetting { |
| 65 | + Both, Fill, Outline |
| 66 | + } |
| 67 | + |
| 68 | + init { |
| 69 | + listener<PacketEvent.Send.Pre> { |
| 70 | + if (it.packet !is PlayerActionC2SPacket |
| 71 | + || it.packet.action != Action.STOP_DESTROY_BLOCK |
| 72 | + ) return@listener |
| 73 | + |
| 74 | + connection.sendPacket( |
| 75 | + PlayerActionC2SPacket( |
| 76 | + Action.ABORT_DESTROY_BLOCK, |
| 77 | + // For the exploit to work, the position must be outside the player range, so any |
| 78 | + // position farther than 6 blocks will work. |
| 79 | + // This is only required for grim 2 and potentially grim 3 in the future if they update it |
| 80 | + it.packet.pos.up(2024 - 4 - 18), |
| 81 | + it.packet.direction |
| 82 | + ) |
| 83 | + ) |
| 84 | + } |
| 85 | + |
| 86 | + listener<TickEvent.Pre> { |
| 87 | + interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay) |
| 88 | + } |
| 89 | + |
| 90 | + listener<InteractionEvent.BreakingProgress.Pre> { |
| 91 | + it.progress += world.getBlockState(it.pos) |
| 92 | + .calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold) |
| 93 | + } |
| 94 | + |
| 95 | + listener<TickEvent.Post> { |
| 96 | + if (!renderMode.isEnabled()) return@listener |
| 97 | + |
| 98 | + val pos = interaction.currentBreakingPos |
| 99 | + boxSet = world.getBlockState(pos).getOutlineShape(world, pos).boundingBoxes.toSet() |
| 100 | + } |
| 101 | + |
| 102 | + listener<RenderEvent.World> { |
| 103 | + if (!interaction.isBreakingBlock || !renderMode.isEnabled()) return@listener |
| 104 | + |
| 105 | + val pos = interaction.currentBreakingPos |
| 106 | + val breakDelta = world.getBlockState(pos).calcBlockBreakingDelta(player, world, pos) |
| 107 | + |
| 108 | + renderer.clear() |
| 109 | + boxSet.forEach { box -> |
| 110 | + val previousFactor = interaction.currentBreakingProgress - breakDelta |
| 111 | + val nextFactor = interaction.currentBreakingProgress |
| 112 | + val currentFactor = lerp(previousFactor, nextFactor, mc.tickDelta) |
| 113 | + |
| 114 | + val fillColour = if (fillColourMode == ColourMode.Dynamic) { |
| 115 | + lerp(startFillColour, endFillColour, currentFactor.toDouble()) |
| 116 | + } else { |
| 117 | + staticFillColour |
| 118 | + } |
| 119 | + |
| 120 | + val outlineColour = if (outlineColourMode == ColourMode.Dynamic) { |
| 121 | + lerp(startOutlineColour, endOutlineColour, currentFactor.toDouble()) |
| 122 | + } else { |
| 123 | + staticOutlineColour |
| 124 | + } |
| 125 | + |
| 126 | + val renderBox = if (renderMode != RenderMode.Static) { |
| 127 | + getLerpBox(box, currentFactor).offset(pos) |
| 128 | + } else { |
| 129 | + box.offset(pos) |
| 130 | + } |
| 131 | + |
| 132 | + val dynamicAABB = DynamicAABB() |
| 133 | + dynamicAABB.update(renderBox) |
| 134 | + |
| 135 | + if (renderSetting != RenderSetting.Outline) { |
| 136 | + renderer.buildFilled(dynamicAABB, fillColour) |
| 137 | + } |
| 138 | + |
| 139 | + if (renderSetting != RenderSetting.Fill) { |
| 140 | + renderer.buildOutline(dynamicAABB, outlineColour) |
| 141 | + } |
| 142 | + } |
| 143 | + renderer.upload() |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + private fun getLerpBox(box: Box, factor: Float): Box { |
| 148 | + val boxCenter = Box(box.center, box.center) |
| 149 | + when (renderMode) { |
| 150 | + RenderMode.Out -> { |
| 151 | + return lerp(boxCenter, box, factor.toDouble()) |
| 152 | + } |
| 153 | + |
| 154 | + RenderMode.In -> { |
| 155 | + return lerp(box, boxCenter, factor.toDouble()) |
| 156 | + } |
| 157 | + |
| 158 | + RenderMode.InOut -> { |
| 159 | + return if (factor >= 0.5f) { |
| 160 | + lerp(boxCenter, box, (factor.toDouble() - 0.5) * 2) |
| 161 | + } else { |
| 162 | + lerp(box, boxCenter, factor.toDouble() * 2) |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + RenderMode.OutIn -> { |
| 167 | + return if (factor >= 0.5f) { |
| 168 | + lerp(box, boxCenter, (factor.toDouble() - 0.5) * 2) |
| 169 | + } else { |
| 170 | + lerp(boxCenter, box, factor.toDouble() * 2) |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + else -> { |
| 175 | + return box |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + fun SafeContext.interpolateProgress(min: Double = 0.0, max: Double = 1.0) = |
| 181 | + transform(interaction.currentBreakingProgress.toDouble(), 0.0, 1.0, min, max) |
| 182 | +} |
0 commit comments