| 1 | /*
|
| 2 | * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
|
| 3 | *
|
| 4 | * Copyright (c) 2015 - 2026 CCBlueX
|
| 5 | *
|
| 6 | * LiquidBounce is free software: you can redistribute it and/or modify
|
| 7 | * it under the terms of the GNU General Public License as published by
|
| 8 | * the Free Software Foundation, either version 3 of the License, or
|
| 9 | * (at your option) any later version.
|
| 10 | *
|
| 11 | * LiquidBounce is distributed in the hope that it will be useful,
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 | * GNU General Public License for more details.
|
| 15 | *
|
| 16 | * You should have received a copy of the GNU General Public License
|
| 17 | * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
|
| 18 | */
|
| 19 |
|
| 20 | package net.ccbluex.liquidbounce.injection.mixins.minecraft.entity;
|
| 21 |
|
| 22 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 23 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 24 | import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
| 25 | import net.ccbluex.liquidbounce.event.EventManager;
|
| 26 | import net.ccbluex.liquidbounce.event.events.PlayerSafeWalkEvent;
|
| 27 | import net.ccbluex.liquidbounce.features.command.commands.ingame.fakeplayer.FakePlayer;
|
| 28 | import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleAutoWeapon;
|
| 29 | import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleKeepSprint;
|
| 30 | import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsNoGround;
|
| 31 | import net.ccbluex.liquidbounce.features.module.modules.exploit.ModuleAntiReducedDebugInfo;
|
| 32 | import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoClip;
|
| 33 | import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint;
|
| 34 | import net.ccbluex.liquidbounce.features.module.modules.player.ModuleReach;
|
| 35 | import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallNoGround;
|
| 36 | import net.ccbluex.liquidbounce.features.module.modules.render.hitfx.ModuleHitFX;
|
| 37 | import net.ccbluex.liquidbounce.features.module.modules.world.ModuleNoSlowBreak;
|
| 38 | import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
|
| 39 | import net.ccbluex.liquidbounce.utils.aiming.features.MovementCorrection;
|
| 40 | import net.minecraft.sounds.SoundEvent;
|
| 41 | import net.minecraft.sounds.SoundEvents;
|
| 42 | import net.minecraft.sounds.SoundSource;
|
| 43 | import net.minecraft.world.damagesource.DamageSource;
|
| 44 | import net.minecraft.world.entity.Entity;
|
| 45 | import net.minecraft.world.entity.player.Player;
|
| 46 | import org.spongepowered.asm.mixin.Mixin;
|
| 47 | import org.spongepowered.asm.mixin.Shadow;
|
| 48 | import org.spongepowered.asm.mixin.Unique;
|
| 49 | import org.spongepowered.asm.mixin.injection.At;
|
| 50 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 51 | import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
| 52 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 53 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 54 | import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
| 55 |
|
| 56 | @Mixin(Player.class)
|
| 57 | public abstract class MixinPlayer extends MixinLivingEntity {
|
| 58 |
|
| 59 | @Shadow
|
| 60 | public abstract void tick();
|
| 61 |
|
| 62 | @Shadow
|
| 63 | public abstract SoundSource getSoundSource();
|
| 64 |
|
| 65 | /**
|
| 66 | * Hook safe walk event
|
| 67 | */
|
| 68 | @ModifyReturnValue(method = "isStayingOnGroundSurface", at = @At("RETURN"))
|
| 69 | private boolean hookSafeWalk(boolean original) {
|
| 70 | final var event = EventManager.INSTANCE.callEvent(new PlayerSafeWalkEvent());
|
| 71 | return original || event.isSafeWalk();
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Hook velocity rotation modification
|
| 76 | * <p>
|
| 77 | * There are a few velocity changes when attacking an entity, which could be easily detected by anti-cheats when a different server-side rotation is applied.
|
| 78 | */
|
| 79 | @ModifyExpressionValue(method = {"causeExtraKnockback",
|
| 80 | "doSweepAttack"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getYRot()F"))
|
| 81 | private float hookFixRotation(float original) {
|
| 82 | if (!liquid_bounce$isClientPlayer()) {
|
| 83 | return original;
|
| 84 | }
|
| 85 |
|
| 86 | var rotationManager = RotationManager.INSTANCE;
|
| 87 | var rotation = rotationManager.getCurrentRotation();
|
| 88 | var rotationTarget = rotationManager.getActiveRotationTarget();
|
| 89 |
|
| 90 | if (rotationTarget == null || rotationTarget.getMovementCorrection() == MovementCorrection.OFF || rotation == null) {
|
| 91 | return original;
|
| 92 | }
|
| 93 |
|
| 94 | return rotation.yRot();
|
| 95 | }
|
| 96 |
|
| 97 | @Inject(method = "isReducedDebugInfo", at = @At("HEAD"), cancellable = true)
|
| 98 | private void injectReducedDebugInfo(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
|
| 99 | if (ModuleAntiReducedDebugInfo.INSTANCE.getRunning()) {
|
| 100 | callbackInfoReturnable.setReturnValue(false);
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | @Inject(method = "isMobilityRestricted", at = @At("HEAD"), cancellable = true)
|
| 105 | private void hookSprintIgnoreBlindness(CallbackInfoReturnable<Boolean> cir) {
|
| 106 | if (liquid_bounce$isClientPlayer() && ModuleSprint.INSTANCE.getShouldIgnoreBlindness()) {
|
| 107 | cir.setReturnValue(false);
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | @Inject(method = "tick", at = @At(value = "INVOKE",
|
| 112 | target = "Lnet/minecraft/world/entity/player/Player;isSpectator()Z",
|
| 113 | ordinal = 1,
|
| 114 | shift = At.Shift.BEFORE))
|
| 115 | private void hookNoClip(CallbackInfo ci) {
|
| 116 | var clip = ModuleNoClip.INSTANCE;
|
| 117 | if (!this.noPhysics && clip.getRunning() && !clip.paused()) {
|
| 118 | this.noPhysics = true;
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 | @ModifyExpressionValue(method = "getDestroySpeed", at = @At(value = "INVOKE",
|
| 123 | target = "Lnet/minecraft/world/entity/player/Player;hasEffect(Lnet/minecraft/core/Holder;)Z"))
|
| 124 | private boolean injectFatigueNoSlow(boolean original) {
|
| 125 | if (liquid_bounce$isClientPlayer() && ModuleNoSlowBreak.getMiningFatigue()) {
|
| 126 | return false;
|
| 127 | }
|
| 128 |
|
| 129 | return original;
|
| 130 | }
|
| 131 |
|
| 132 |
|
| 133 | @ModifyExpressionValue(method = "getDestroySpeed", at = @At(value = "INVOKE",
|
| 134 | target = "Lnet/minecraft/world/entity/player/Player;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"))
|
| 135 | private boolean injectWaterNoSlow(boolean original) {
|
| 136 | if (liquid_bounce$isClientPlayer() && ModuleNoSlowBreak.getWater()) {
|
| 137 | return false;
|
| 138 | }
|
| 139 |
|
| 140 | return original;
|
| 141 | }
|
| 142 |
|
| 143 | @ModifyExpressionValue(method = "getDestroySpeed", at = @At(value = "INVOKE",
|
| 144 | target = "Lnet/minecraft/world/entity/player/Player;onGround()Z"))
|
| 145 | private boolean injectOnAirNoSlow(boolean original) {
|
| 146 | if (liquid_bounce$isClientPlayer()) {
|
| 147 | if (ModuleNoSlowBreak.getOnAir()) {
|
| 148 | return true;
|
| 149 | }
|
| 150 |
|
| 151 | if (NoFallNoGround.INSTANCE.getRunning()) {
|
| 152 | return false;
|
| 153 | }
|
| 154 |
|
| 155 | if (CriticalsNoGround.INSTANCE.getRunning()) {
|
| 156 | return false;
|
| 157 | }
|
| 158 | }
|
| 159 |
|
| 160 | return original;
|
| 161 | }
|
| 162 |
|
| 163 | @ModifyArgs(method = "causeExtraKnockback", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;multiply(DDD)Lnet/minecraft/world/phys/Vec3;"))
|
| 164 | private void hookSlowVelocity(Args args) {
|
| 165 | if (liquid_bounce$isClientPlayer() && ModuleKeepSprint.INSTANCE.getRunning()) {
|
| 166 | double motion = ModuleKeepSprint.INSTANCE.getMotion();
|
| 167 | args.set(0, motion); // x
|
| 168 | args.set(2, motion); // z
|
| 169 | }
|
| 170 | }
|
| 171 |
|
| 172 | /**
|
| 173 | * for: attack, pierce
|
| 174 | */
|
| 175 | @WrapWithCondition(method = "causeExtraKnockback", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setSprinting(Z)V", ordinal = 0))
|
| 176 | private boolean hookSlowVelocity(Player instance, boolean b) {
|
| 177 | if (liquid_bounce$isClientPlayer()) {
|
| 178 | ModuleKeepSprint.INSTANCE.setSprinting(b);
|
| 179 | return !ModuleKeepSprint.INSTANCE.getRunning() || b;
|
| 180 | }
|
| 181 |
|
| 182 | return true;
|
| 183 | }
|
| 184 |
|
| 185 | @ModifyExpressionValue(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSprinting()Z"))
|
| 186 | private boolean hookSlowVelocity(boolean original) {
|
| 187 | if (liquid_bounce$isClientPlayer() && ModuleKeepSprint.INSTANCE.getRunning()) {
|
| 188 | return ModuleKeepSprint.INSTANCE.getSprinting();
|
| 189 | }
|
| 190 |
|
| 191 | return original;
|
| 192 | }
|
| 193 |
|
| 194 | @ModifyReturnValue(method = "entityInteractionRange", at = @At("RETURN"))
|
| 195 | private double hookEntityInteractionRange(double original) {
|
| 196 | if (liquid_bounce$isClientPlayer() && ModuleReach.INSTANCE.getRunning()) {
|
| 197 | return ModuleReach.INSTANCE.getEntity().getInteractionRange();
|
| 198 | }
|
| 199 |
|
| 200 | return original;
|
| 201 | }
|
| 202 |
|
| 203 | @ModifyReturnValue(method = "blockInteractionRange", at = @At("RETURN"))
|
| 204 | private double hookBlockInteractionRange(double original) {
|
| 205 | if (liquid_bounce$isClientPlayer() && ModuleReach.INSTANCE.getRunning()) {
|
| 206 | return ModuleReach.INSTANCE.getBlockRangeIncrease() + original;
|
| 207 | }
|
| 208 |
|
| 209 | return original;
|
| 210 | }
|
| 211 |
|
| 212 | @ModifyExpressionValue(method = "getCurrentItemAttackStrengthDelay", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getAttributeValue(Lnet/minecraft/core/Holder;)D"))
|
| 213 | private double hookAutoWeaponAttackSpeed(double original) {
|
| 214 | if (liquid_bounce$isClientPlayer() && ModuleReach.INSTANCE.getRunning()) {
|
| 215 | return original;
|
| 216 | }
|
| 217 |
|
| 218 | return ModuleAutoWeapon.INSTANCE.getAttackSpeed(original);
|
| 219 | }
|
| 220 |
|
| 221 | /*
|
| 222 | * Sadly, mixins don't allow capturing parameters when redirecting,
|
| 223 | * so there needs to be an extra injection for every sound.
|
| 224 | */
|
| 225 | @Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;playServerSideSound(Lnet/minecraft/sounds/SoundEvent;)V", ordinal = 0))
|
| 226 | private void hookPlaySound(Entity target, CallbackInfo ci) {
|
| 227 | if (!ModuleHitFX.INSTANCE.getRunning()) {
|
| 228 | liquid_bounce$playSoundIfFakePlayer(target, SoundEvents.PLAYER_ATTACK_KNOCKBACK);
|
| 229 | }
|
| 230 | }
|
| 231 |
|
| 232 | @Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;playServerSideSound(Lnet/minecraft/sounds/SoundEvent;)V", ordinal = 1))
|
| 233 | private void hookPlaySound1(Entity target, CallbackInfo ci) {
|
| 234 | if (!ModuleHitFX.INSTANCE.getRunning()) {
|
| 235 | liquid_bounce$playSoundIfFakePlayer(target, SoundEvents.PLAYER_ATTACK_NODAMAGE);
|
| 236 | }
|
| 237 | }
|
| 238 |
|
| 239 | @Inject(method = "attackVisualEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;playServerSideSound(Lnet/minecraft/sounds/SoundEvent;)V", ordinal = 0))
|
| 240 | private void hookPlaySound2(Entity target, boolean criticalHit, boolean sweeping, boolean cooldownPassed, boolean pierce, float enchantDamage, CallbackInfo ci) {
|
| 241 | if (!ModuleHitFX.INSTANCE.getRunning()) {
|
| 242 | liquid_bounce$playSoundIfFakePlayer(target, SoundEvents.PLAYER_ATTACK_CRIT);
|
| 243 | }
|
| 244 |
|
| 245 | }
|
| 246 |
|
| 247 | @Inject(method = "attackVisualEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;playServerSideSound(Lnet/minecraft/sounds/SoundEvent;)V", ordinal = 1))
|
| 248 | private void hookPlaySound3(Entity target, boolean criticalHit, boolean sweeping, boolean cooldownPassed, boolean pierce, float enchantDamage, CallbackInfo ci) {
|
| 249 | if(!ModuleHitFX.INSTANCE.getRunning()) {
|
| 250 | liquid_bounce$playSoundIfFakePlayer(target, cooldownPassed ? SoundEvents.PLAYER_ATTACK_STRONG : SoundEvents.PLAYER_ATTACK_WEAK);
|
| 251 | }
|
| 252 | }
|
| 253 |
|
| 254 | @Inject(method = "doSweepAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;playServerSideSound(Lnet/minecraft/sounds/SoundEvent;)V", ordinal = 0))
|
| 255 | private void hookPlaySound4(Entity target, float damage, DamageSource damageSource, float cooldownProgress, CallbackInfo ci) {
|
| 256 | if(!ModuleHitFX.INSTANCE.getRunning()) {
|
| 257 | liquid_bounce$playSoundIfFakePlayer(target, SoundEvents.PLAYER_ATTACK_SWEEP);
|
| 258 | }
|
| 259 | }
|
| 260 |
|
| 261 | /**
|
| 262 | * When the target is a fake player, this method will play a client side sound.
|
| 263 | */
|
| 264 | @Unique
|
| 265 | private void liquid_bounce$playSoundIfFakePlayer(Entity target, SoundEvent soundEvent) {
|
| 266 | if (target instanceof FakePlayer) {
|
| 267 | level().playSound(Player.class.cast(this), getX(), getY(), getZ(), soundEvent, getSoundSource(), 1F, 1F);
|
| 268 | }
|
| 269 | }
|
| 270 | }
|
| 271 |
|