Skip to content

Commit

Permalink
autodisable (CCBlueX#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
be4dev authored Jul 26, 2023
1 parent 8c8c761 commit dc28fb4
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.network;

import net.ccbluex.liquidbounce.config.Choice;
import net.ccbluex.liquidbounce.event.ChunkLoadEvent;
import net.ccbluex.liquidbounce.event.ChunkUnloadEvent;
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.*;
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiExploit;
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleNoRotateSet;
import net.ccbluex.liquidbounce.utils.aiming.Rotation;
Expand Down Expand Up @@ -119,6 +117,14 @@ private GameStateChangeS2CPacket.Reason onGameStateChange(final GameStateChangeS
}
}

@Inject(method = "onHealthUpdate", at = @At("RETURN"))
private void injectHealthUpdate(HealthUpdateS2CPacket packet, CallbackInfo ci) {
EventManager.INSTANCE.callEvent(new HealthUpdateEvent(packet.getHealth(), packet.getFood(), packet.getSaturation()));
if (packet.getHealth() == 0) {
EventManager.INSTANCE.callEvent(new DeathEvent());
}
}

@Inject(method = "onPlayerPositionLook", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setVelocity(DDD)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void injectNoRotateSet(final PlayerPositionLookS2CPacket packet, final CallbackInfo ci, final PlayerEntity playerEntity, final Vec3d vec3d, final boolean bl, final boolean bl2, final boolean bl3, final double d, final double e, final double f, final double g, final double h, final double i) {
final float j = packet.getYaw();
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/net/ccbluex/liquidbounce/event/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ class EntityMarginEvent(val entity: Entity, var margin: Float) : Event()

// Entity events bound to client-user entity

@Nameable("HealthUpdate")
class HealthUpdateEvent(Health: Float, Food: Int, Saturation: Float): Event()

@Nameable("Death")
class DeathEvent: Event()

@Nameable("playerTick")
class PlayerTickEvent : Event()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ object CommandManager : Iterable<Command> {
addCommand(CommandXRay.createCommand())
addCommand(CommandEnemy.createCommand())
addCommand(CommandConfig.createCommand())
addCommand(CommandAutoDisable.createCommand())

// creative commands
addCommand(CommandItemRename.createCommand())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2023 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.command.commands.client

import net.ccbluex.liquidbounce.features.command.Command
import net.ccbluex.liquidbounce.features.command.CommandException
import net.ccbluex.liquidbounce.features.command.builder.CommandBuilder
import net.ccbluex.liquidbounce.features.command.builder.ParameterBuilder
import net.ccbluex.liquidbounce.features.module.ModuleManager
import net.ccbluex.liquidbounce.features.module.modules.world.ModuleAutoDisable
import net.ccbluex.liquidbounce.utils.client.*
import net.minecraft.util.Formatting
import kotlin.math.ceil
import kotlin.math.roundToInt

object CommandAutoDisable {

fun createCommand(): Command {
return CommandBuilder
.begin("AutoDisable")
.hub()
.subcommand(
CommandBuilder
.begin("add")
.parameter(
ParameterBuilder
.begin<String>("name")
.verifiedBy(ParameterBuilder.STRING_VALIDATOR)
.autocompletedWith(ModuleManager::autoComplete)
.required()
.build()
)
.handler { command, args ->
val name = args[0] as String
val module = ModuleManager.find { it.name.equals(name, true) }
?: throw CommandException(command.result("moduleNotFound", name))

if (!ModuleAutoDisable.listOfModules.add(module)) {
throw CommandException(command.result("ModuleIsPresent", name))
}

chat(regular(command.result("moduleAdded", variable(module.name))))
}
.build()
)
.subcommand(
CommandBuilder
.begin("remove")
.parameter(
ParameterBuilder
.begin<String>("name")
.verifiedBy(ParameterBuilder.STRING_VALIDATOR)
.autocompletedWith { ModuleManager.autoComplete(it) { mod -> mod.bind != -1 } }
.required()
.build()
)
.handler { command, args ->
val name = args[0] as String
val module = ModuleManager.find { it.name.equals(name, true) }
?: throw CommandException(command.result("moduleNotFound", name))

if (!ModuleAutoDisable.listOfModules.remove(module)) {
throw CommandException(command.result("ModuleIsMissing", name))
}

chat(
regular(
command.result(
"moduleRemoved",
variable(module.name)
)
)
)
}
.build()
)
.subcommand(
CommandBuilder
.begin("list")
.parameter(
ParameterBuilder
.begin<Int>("page")
.verifiedBy(ParameterBuilder.INTEGER_VALIDATOR)
.optional()
.build()
)
.handler { command, args ->
val page = if (args.size > 1) {
args[0] as Int
} else {
1
}.coerceAtLeast(1)

val modules = ModuleAutoDisable.listOfModules.sortedBy { it.name }

if (modules.isEmpty()) {
throw CommandException(command.result("noBindings"))
}

// Max page
val maxPage = ceil(modules.size / 8.0).roundToInt()
if (page > maxPage) {
throw CommandException(command.result("pageNumberTooLarge", maxPage))
}

// Print out bindings
chat(command.result("bindings").styled { it.withColor(Formatting.RED).withBold(true) })
chat(regular(command.result("page", variable("$page / $maxPage"))))

val iterPage = 8 * page
for (module in modules.subList(iterPage - 8, iterPage.coerceAtMost(modules.size))) {
chat(
"> ".asText()
.styled { it.withColor(Formatting.GOLD) }
.append(module.name + " (")
.styled { it.withColor(Formatting.GRAY) }
.append(
keyName(module.bind).asText()
.styled { it.withColor(Formatting.DARK_GRAY).withBold(true) }
)
.append(")")
.styled { it.withColor(Formatting.GRAY) }
)
}
}
.build()
)
.subcommand(
CommandBuilder
.begin("clear")
.handler { command, _ ->
ModuleAutoDisable.listOfModules.let { list ->
list.forEach {
list.remove(it)
}
}
chat(command.result("modulesCleared"))
}
.build()
)
.build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleXRay,

// World
ModuleAutoDisable,
ModuleAutoFarm,
ModuleAutoTool,
ModuleChestAura,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ModuleBlink : Module("Blink", Category.PLAYER) {

override fun enable() {
if (ModuleBadWifi.enabled) {
enabled = false // Doesn't disable the module for some reason
ModuleBadWifi.enabled = false

notification("Compatibility error", "Blink is incompatible with BadWIFI", NotificationEvent.Severity.ERROR)
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2023 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.module.modules.world

import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleKillAura
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleFly
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoClip
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSpeed
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleBlink
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable
import net.ccbluex.liquidbounce.utils.block.*
import net.ccbluex.liquidbounce.utils.client.notification
import net.ccbluex.liquidbounce.utils.entity.eyes
import net.ccbluex.liquidbounce.utils.entity.getNearestPoint
import net.minecraft.block.*
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
import net.minecraft.util.Hand
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Box
import net.minecraft.util.math.Vec3d
import net.minecraft.world.RaycastContext

/**
* AutoFarm module
*
* Automatically farms stuff for you.
*/
object ModuleAutoDisable : Module("AutoDisable", Category.WORLD) {
val listOfModules = arrayListOf<Module>(ModuleFly, ModuleSpeed, ModuleNoClip, ModuleKillAura)
val onFlag by boolean("OnFlag", false)
val onDeath by boolean("OnDeath", false)

val worldChangesHandler = handler<PacketEvent> {
if (it.packet is PlayerPositionLookS2CPacket && onFlag) {
autoDisabled("flag")
}
}

val deathHandler = handler<DeathEvent> {
if (onDeath)
autoDisabled("your death")
}

fun autoDisabled(reason: String) {
listOfModules.forEach {
it.enabled = false
}
notification("Notifier", "Disabled modules due to $reason", NotificationEvent.Severity.INFO)
}
}

0 comments on commit dc28fb4

Please sign in to comment.