| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Licensed under the GNU General Public License v3.0.
|
| 6 | */
|
| 7 |
|
| 8 | package combatant.client.mixins;
|
| 9 |
|
| 10 | import com.mojang.blaze3d.systems.GpuSurface;
|
| 11 | import combatant.client.features.module.modules.combat.*;
|
| 12 | import net.minecraft.client.FramerateLimiter;
|
| 13 | import net.minecraft.client.Minecraft;
|
| 14 | import net.minecraft.client.main.GameConfig;
|
| 15 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 16 | import net.minecraft.client.player.LocalPlayer;
|
| 17 | import net.minecraft.core.BlockPos;
|
| 18 | import net.minecraft.core.Direction;
|
| 19 | import net.minecraft.util.Mth;
|
| 20 | import net.minecraft.world.entity.Entity;
|
| 21 | import net.minecraft.world.entity.LivingEntity;
|
| 22 | import net.minecraft.world.entity.player.Player;
|
| 23 | import net.minecraft.world.item.ItemStack;
|
| 24 | import net.minecraft.world.phys.BlockHitResult;
|
| 25 | import net.minecraft.world.phys.EntityHitResult;
|
| 26 | import net.minecraft.world.phys.Vec3;
|
| 27 | import org.spongepowered.asm.mixin.Final;
|
| 28 | import org.spongepowered.asm.mixin.Mixin;
|
| 29 | import org.spongepowered.asm.mixin.Shadow;
|
| 30 | import org.spongepowered.asm.mixin.Unique;
|
| 31 | import org.spongepowered.asm.mixin.injection.At;
|
| 32 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 33 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 34 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 35 | import combatant.client.events.Events;
|
| 36 | import combatant.client.events.impl.CrosshairTargetUpdateEvent;
|
| 37 | import combatant.client.features.gui.chat.BetterChatStoreManager;
|
| 38 | import combatant.client.features.module.ModuleManager;
|
| 39 | import combatant.client.features.module.Modules;
|
| 40 | import combatant.client.features.module.modules.movement.Timer;
|
| 41 | import combatant.client.features.module.modules.player.NoDelay;
|
| 42 | import combatant.client.features.module.modules.player.NoInteract;
|
| 43 | import combatant.client.features.module.modules.visuals.Freecam;
|
| 44 | import combatant.client.features.module.modules.visuals.ViewModel;
|
| 45 | import combatant.client.features.relations.StaffTracker;
|
| 46 | import combatant.client.render.helpers.TickDelta;
|
| 47 | import combatant.client.render.helpers.PlayerHeadRenderer;
|
| 48 | import combatant.client.util.player.PlayerSkinResolver;
|
| 49 | import combatant.client.util.combat.AntiBotTracker;
|
| 50 | import combatant.client.util.session.SessionChanger;
|
| 51 | import combatant.client.util.session.MinecraftGameConfigHolder;
|
| 52 |
|
| 53 | @Mixin(Minecraft.class)
|
| 54 | public class MinecraftMixin implements MinecraftGameConfigHolder {
|
| 55 |
|
| 56 | @Shadow
|
| 57 | @Final
|
| 58 | private GpuSurface windowSurface;
|
| 59 |
|
| 60 | @Unique
|
| 61 | private GameConfig combatant$gameConfig;
|
| 62 |
|
| 63 | @Inject(method = "<init>", at = @At("RETURN"))
|
| 64 | private void combatant$captureGameConfig(GameConfig config, CallbackInfo ci) {
|
| 65 | this.combatant$gameConfig = config;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public GameConfig combatant$getGameConfig() {
|
| 70 | return combatant$gameConfig;
|
| 71 | }
|
| 72 |
|
| 73 | @Unique
|
| 74 | private static BlockHitResult combatant$miss(Vec3 pos) {
|
| 75 | return new BlockHitResult(
|
| 76 | pos,
|
| 77 | Direction.UP,
|
| 78 | BlockPos.ZERO,
|
| 79 | false
|
| 80 | );
|
| 81 | }
|
| 82 |
|
| 83 | @Unique
|
| 84 | private static void combatant$guardSingleplayerSaveWithAltUsername() {
|
| 85 | SessionChanger.restoreSingleplayerJoinSessionForDisconnect();
|
| 86 | }
|
| 87 |
|
| 88 | @Inject(method = "startUseItem", at = @At("HEAD"), cancellable = true)
|
| 89 | private void fastThrow(CallbackInfo ci) {
|
| 90 | NoDelay noDelay = Modules.get(NoDelay.class);
|
| 91 | if (noDelay != null && noDelay.handleFastUse()) {
|
| 92 | ci.cancel();
|
| 93 | return;
|
| 94 | }
|
| 95 |
|
| 96 | AutoBow autoBow = Modules.get(AutoBow.class);
|
| 97 | if (autoBow != null && autoBow.shouldCancelVanillaDoItemUse()) {
|
| 98 | ci.cancel();
|
| 99 | }
|
| 100 | }
|
| 101 |
|
| 102 | @Inject(
|
| 103 | method = "handleKeybinds",
|
| 104 | at = @At("HEAD")
|
| 105 | )
|
| 106 | private void spearassist$blockAttackInput(CallbackInfo ci) {
|
| 107 | Minecraft mc = Minecraft.getInstance();
|
| 108 | if (mc.player == null) return;
|
| 109 |
|
| 110 | SpearAssist assist = Modules.get(SpearAssist.class);
|
| 111 | if (assist == null || !assist.isEnabled() || !assist.respectCooldownEnabled()) {
|
| 112 | return;
|
| 113 | }
|
| 114 |
|
| 115 | ItemStack stack = mc.player.getMainHandItem();
|
| 116 | if (!SpearAssist.isSpear(stack)) return;
|
| 117 |
|
| 118 | float cooldown = mc.player.getAttackStrengthScale(0.0F);
|
| 119 | if (cooldown < 0.99F) {
|
| 120 | // ВАЖНО: гасим сам ввод
|
| 121 | mc.options.keyAttack.setDown(false);
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | @Inject(method = "handleKeybinds", at = @At("TAIL"))
|
| 126 | private void combatant$autobow$finishInputCycle(CallbackInfo ci) {
|
| 127 | AutoBow autoBow = Modules.get(AutoBow.class);
|
| 128 | if (autoBow != null && autoBow.isEnabled()) {
|
| 129 | autoBow.onInputCycleHandled();
|
| 130 | }
|
| 131 | }
|
| 132 |
|
| 133 | @Inject(method = "shouldEntityAppearGlowing", at = @At("HEAD"), cancellable = true)
|
| 134 | private void combatant$disablePvpGlow(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
| 135 | if (!(entity instanceof Player)) return;
|
| 136 | PvpCooldowns mod = Modules.get(PvpCooldowns.class);
|
| 137 | if (mod == null || !mod.shouldHideTargetGlow()) return;
|
| 138 | cir.setReturnValue(false);
|
| 139 | }
|
| 140 |
|
| 141 |
|
| 142 | // === КУРСОР ДЛЯ CLICKGUI ===
|
| 143 |
|
| 144 | @Inject(method = "continueAttack", at = @At("HEAD"), cancellable = true)
|
| 145 | private void onHandleBlockBreaking(boolean breaking, CallbackInfo ci) {
|
| 146 | Minecraft client = Minecraft.getInstance();
|
| 147 | LocalPlayer player = client.player;
|
| 148 | if (player == null) return;
|
| 149 |
|
| 150 | // Hitbox должен работать даже при ломании блоков: не блокируем vanilla логику
|
| 151 | Hitbox hitbox = Modules.get(Hitbox.class);
|
| 152 | if (hitbox != null && hitbox.isEnabled()) {
|
| 153 | return;
|
| 154 | }
|
| 155 |
|
| 156 | boolean attackKeyPressed = client.options.keyAttack.isDown();
|
| 157 |
|
| 158 | AutoAttack autoAttack = Modules.get(AutoAttack.class);
|
| 159 | boolean blockByAutoAttack = autoAttack != null
|
| 160 | && autoAttack.isEnabled()
|
| 161 | && !autoAttack.isAutoMode()
|
| 162 | && autoAttack.shouldBlockBreaking();
|
| 163 | boolean shouldBlockBreaking = blockByAutoAttack;
|
| 164 |
|
| 165 | if (shouldBlockBreaking && attackKeyPressed) {
|
| 166 |
|
| 167 | // блокируем ломание
|
| 168 | ci.cancel();
|
| 169 |
|
| 170 | if (client.gameMode != null)
|
| 171 | client.gameMode.stopDestroyBlock();
|
| 172 |
|
| 173 | // имитация удара
|
| 174 | }
|
| 175 | }
|
| 176 |
|
| 177 | @Inject(method = "startAttack", at = @At("HEAD"), cancellable = true)
|
| 178 | private void onDoAttack(CallbackInfoReturnable<Boolean> cir) {
|
| 179 | AttributeSwap attributeSwap = Modules.get(AttributeSwap.class);
|
| 180 | if (attributeSwap != null && attributeSwap.isEnabled() && attributeSwap.handleManualAttack()) {
|
| 181 | cir.setReturnValue(true);
|
| 182 | cir.cancel();
|
| 183 | return;
|
| 184 | }
|
| 185 |
|
| 186 | AutoAttack autoAttack = Modules.get(AutoAttack.class);
|
| 187 | if (autoAttack != null && autoAttack.isEnabled()) {
|
| 188 | cir.setReturnValue(false);
|
| 189 | cir.cancel();
|
| 190 | }
|
| 191 | }
|
| 192 |
|
| 193 | @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;ZZ)V", at = @At("HEAD"))
|
| 194 | private void combatant$betterChat$saveOnDisconnect(net.minecraft.client.gui.screens.Screen screen, boolean transferring, boolean bl, CallbackInfo ci) {
|
| 195 | combatant$guardSingleplayerSaveWithAltUsername();
|
| 196 | if (!transferring) {
|
| 197 | PlayerHeadRenderer.clearSessionCache();
|
| 198 | PlayerSkinResolver.clearAll();
|
| 199 | }
|
| 200 | try {
|
| 201 | BetterChatStoreManager.flushAll();
|
| 202 | } catch (Throwable ignored) {
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 | @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;ZZ)V", at = @At("TAIL"))
|
| 207 | private void combatant$sessionRestoreAfterDisconnect(net.minecraft.client.gui.screens.Screen screen, boolean transferring, boolean bl, CallbackInfo ci) {
|
| 208 | SessionChanger.restoreDeferredSessionAfterDisconnect();
|
| 209 | }
|
| 210 |
|
| 211 | @Inject(method = "pick", at = @At("HEAD"), cancellable = true)
|
| 212 | private void onUpdateCrosshairTarget(float tickDelta, CallbackInfo ci) {
|
| 213 | Minecraft mc = Minecraft.getInstance();
|
| 214 | if (mc.player == null || mc.level == null) return;
|
| 215 |
|
| 216 | var fc = Modules.get(Freecam.class);
|
| 217 |
|
| 218 | // =========================================================
|
| 219 | // FREECAM
|
| 220 | // =========================================================
|
| 221 | if (fc != null && fc.isEnabled()) {
|
| 222 |
|
| 223 | // позиция и направление FREECAM
|
| 224 | Vec3 start = new Vec3(
|
| 225 | Mth.lerp(tickDelta, fc.camPosPrev.x, fc.camPos.x),
|
| 226 | Mth.lerp(tickDelta, fc.camPosPrev.y, fc.camPos.y),
|
| 227 | Mth.lerp(tickDelta, fc.camPosPrev.z, fc.camPos.z)
|
| 228 | );
|
| 229 |
|
| 230 | float yawRad = -fc.camYaw * ((float) Math.PI / 180F);
|
| 231 | float pitchRad = -fc.camPitch * ((float) Math.PI / 180F);
|
| 232 |
|
| 233 | Vec3 dir = new Vec3(
|
| 234 | Mth.sin(yawRad) * Mth.cos(pitchRad),
|
| 235 | Mth.sin(pitchRad),
|
| 236 | Mth.cos(yawRad) * Mth.cos(pitchRad)
|
| 237 | );
|
| 238 |
|
| 239 | // ===============================
|
| 240 | // FREECAM + NO INTERACT
|
| 241 | // ===============================
|
| 242 | if (!fc.allowInteract()) {
|
| 243 | mc.hitResult = combatant$miss(start);
|
| 244 | mc.crosshairPickEntity = null;
|
| 245 | ci.cancel();
|
| 246 | return;
|
| 247 | }
|
| 248 |
|
| 249 | // ===============================
|
| 250 | // FREECAM + INTERACT
|
| 251 | // ===============================
|
| 252 |
|
| 253 | // Reach (FREECAM)
|
| 254 | Reach reachModule = Modules.get(Reach.class);
|
| 255 | if (reachModule != null && reachModule.isEnabled()) {
|
| 256 | EntityHitResult hit = reachModule.raycastEntities(
|
| 257 | mc.player, start, dir
|
| 258 | );
|
| 259 |
|
| 260 | if (hit != null && hit.getEntity() instanceof LivingEntity target && target.isAlive()) {
|
| 261 | mc.hitResult = hit;
|
| 262 | mc.crosshairPickEntity = target;
|
| 263 | ci.cancel();
|
| 264 | return;
|
| 265 | }
|
| 266 | }
|
| 267 |
|
| 268 | // Blocks (FREECAM)
|
| 269 | double reach = mc.player.blockInteractionRange();
|
| 270 | Vec3 end = start.add(dir.scale(reach));
|
| 271 |
|
| 272 | BlockHitResult bhr = mc.level.clip(new net.minecraft.world.level.ClipContext(
|
| 273 | start, end,
|
| 274 | net.minecraft.world.level.ClipContext.Block.OUTLINE,
|
| 275 | net.minecraft.world.level.ClipContext.Fluid.NONE,
|
| 276 | mc.player
|
| 277 | ));
|
| 278 |
|
| 279 | mc.hitResult = bhr;
|
| 280 | mc.crosshairPickEntity = null;
|
| 281 | ci.cancel();
|
| 282 | return;
|
| 283 | }
|
| 284 |
|
| 285 | Reach reachModule = Modules.get(Reach.class);
|
| 286 | if (reachModule != null && reachModule.isEnabled()) {
|
| 287 | EntityHitResult entityHit = reachModule.raycastEntities(mc.player);
|
| 288 | if (entityHit != null && entityHit.getEntity() instanceof LivingEntity target && target.isAlive()) {
|
| 289 | mc.hitResult = entityHit;
|
| 290 | mc.crosshairPickEntity = target;
|
| 291 | ci.cancel();
|
| 292 | }
|
| 293 | }
|
| 294 | }
|
| 295 |
|
| 296 | @Inject(method = "pick", at = @At("RETURN"))
|
| 297 | private void combatant$dispatchCrosshairTargetEvent(float tickDelta, CallbackInfo ci) {
|
| 298 | Minecraft mc = Minecraft.getInstance();
|
| 299 | if (mc.player == null || mc.level == null) return;
|
| 300 |
|
| 301 | CrosshairTargetUpdateEvent event = new CrosshairTargetUpdateEvent(
|
| 302 | tickDelta,
|
| 303 | mc.hitResult,
|
| 304 | mc.crosshairPickEntity
|
| 305 | );
|
| 306 | Events.BUS.post(event);
|
| 307 | mc.hitResult = event.getHitResult();
|
| 308 | mc.crosshairPickEntity = event.getTargetedEntity();
|
| 309 | }
|
| 310 |
|
| 311 | @Inject(method = "pick", at = @At("RETURN"))
|
| 312 | private void noInteract$afterRaycast(float tickDelta, CallbackInfo ci) {
|
| 313 | Minecraft mc = Minecraft.getInstance();
|
| 314 | if (mc.player == null || mc.level == null) return;
|
| 315 |
|
| 316 | NoInteract noInteract = Modules.get(NoInteract.class);
|
| 317 | if (noInteract == null || !noInteract.shouldBlockBlockInteraction()) return;
|
| 318 |
|
| 319 | var hit = mc.hitResult;
|
| 320 | if (hit instanceof EntityHitResult) return;
|
| 321 |
|
| 322 | Vec3 camPos = mc.player.getEyePosition(tickDelta);
|
| 323 | mc.hitResult = new BlockHitResult(
|
| 324 | camPos,
|
| 325 | Direction.UP,
|
| 326 | BlockPos.ZERO,
|
| 327 | false
|
| 328 | );
|
| 329 | mc.crosshairPickEntity = null;
|
| 330 | }
|
| 331 |
|
| 332 | @Inject(method = "disconnect", at = @At("HEAD"))
|
| 333 | private void freecam$onDisconnect(CallbackInfo ci) {
|
| 334 | Freecam fc = Modules.get(Freecam.class);
|
| 335 | if (fc != null && fc.isEnabled()) {
|
| 336 | fc.toggle();
|
| 337 | }
|
| 338 | }
|
| 339 |
|
| 340 | @Inject(method = "setLevel", at = @At("HEAD"))
|
| 341 | private void freecam$onJoinWorld(ClientLevel world, CallbackInfo ci) {
|
| 342 | Freecam fc = Modules.get(Freecam.class);
|
| 343 | if (fc != null && fc.isEnabled()) {
|
| 344 | fc.toggle();
|
| 345 | }
|
| 346 | }
|
| 347 |
|
| 348 | @Inject(method = "setLevel", at = @At("TAIL"))
|
| 349 | private void combatant$captureSingleplayerJoinSession(ClientLevel world, CallbackInfo ci) {
|
| 350 | if (world == null) {
|
| 351 | SessionChanger.clearSingleplayerJoinSession();
|
| 352 | } else {
|
| 353 | SessionChanger.captureSingleplayerJoinSession();
|
| 354 | }
|
| 355 | }
|
| 356 |
|
| 357 | @Inject(method = "clearDownloadedResourcePacks", at = @At("HEAD"))
|
| 358 | private void combatant$onDisconnected(CallbackInfo ci) {
|
| 359 | StaffTracker.resetAll();
|
| 360 | AntiBotTracker.INSTANCE.reset();
|
| 361 | }
|
| 362 |
|
| 363 | @Inject(
|
| 364 | method = "renderFrame",
|
| 365 | at = @At(
|
| 366 | value = "INVOKE",
|
| 367 | target = "Lnet/minecraft/client/DeltaTracker$Timer;advanceRealTime(J)V",
|
| 368 | shift = At.Shift.AFTER
|
| 369 | )
|
| 370 | )
|
| 371 | private void combatant$frameModulesAfterRenderTick(boolean tick, CallbackInfo ci) {
|
| 372 | ModuleManager.frameAll(TickDelta.frameDeltaTicks());
|
| 373 | }
|
| 374 |
|
| 375 | @Inject(
|
| 376 | method = "renderFrame",
|
| 377 | at = @At(
|
| 378 | value = "INVOKE_STRING",
|
| 379 | target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V",
|
| 380 | args = "ldc=frameLimiter",
|
| 381 | shift = At.Shift.AFTER
|
| 382 | )
|
| 383 | )
|
| 384 | private void combatant$paceImmediateNoVsync(boolean tick, CallbackInfo ci) {
|
| 385 | Minecraft mc = (Minecraft) (Object) this;
|
| 386 | if (mc == null || mc.options == null || mc.getWindow() == null || windowSurface == null) {
|
| 387 | return;
|
| 388 | }
|
| 389 | if (Boolean.TRUE.equals(mc.options.enableVsync().get())) {
|
| 390 | return;
|
| 391 | }
|
| 392 | if (windowSurface.currentConfiguration().isEmpty()
|
| 393 | || windowSurface.currentConfiguration().get().presentMode() != GpuSurface.PresentMode.IMMEDIATE) {
|
| 394 | return;
|
| 395 | }
|
| 396 |
|
| 397 | int configuredLimit = mc.gameRenderer.gameRenderState().framerateLimit;
|
| 398 | if (configuredLimit < 260) {
|
| 399 | return;
|
| 400 | }
|
| 401 |
|
| 402 | int refreshRate = mc.getWindow().getRefreshRate();
|
| 403 | int targetFps = combatant$immediatePacingTarget(refreshRate);
|
| 404 | FramerateLimiter.limitDisplayFPS(targetFps);
|
| 405 | }
|
| 406 |
|
| 407 | @Unique
|
| 408 | private static int combatant$immediatePacingTarget(int refreshRate) {
|
| 409 | int base = refreshRate > 0 ? refreshRate : 120;
|
| 410 | return Mth.clamp(base * 2, 120, 360);
|
| 411 | }
|
| 412 |
|
| 413 | @Inject(method = "getTickTargetMillis", at = @At("RETURN"), cancellable = true)
|
| 414 | private void combatant$applyTimer(float millis, CallbackInfoReturnable<Float> cir) {
|
| 415 | float mult = Timer.getTickTimer();
|
| 416 | if (mult <= 0.0001f) return;
|
| 417 | if (Math.abs(mult - 1.0f) < 0.0001f) return;
|
| 418 | float base = cir.getReturnValue();
|
| 419 | cir.setReturnValue(base / mult);
|
| 420 | }
|
| 421 |
|
| 422 | @Inject(method = "isLevelRunningNormally", at = @At("HEAD"), cancellable = true)
|
| 423 | private void combatant$skipPlayerDependentTicksWithoutPlayer(CallbackInfoReturnable<Boolean> cir) {
|
| 424 | Minecraft mc = Minecraft.getInstance();
|
| 425 | if (mc.level != null && mc.player == null) {
|
| 426 | cir.setReturnValue(false);
|
| 427 | }
|
| 428 | }
|
| 429 | @Inject(method = "reloadResourcePacks()Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"))
|
| 430 | private void combatant$viewModel$resourceReload(CallbackInfoReturnable<java.util.concurrent.CompletableFuture<Void>> cir) {
|
| 431 | java.util.concurrent.CompletableFuture<Void> future = cir.getReturnValue();
|
| 432 | if (future == null) return;
|
| 433 |
|
| 434 | future.thenRun(() -> Minecraft.getInstance().execute(() -> {
|
| 435 | ViewModel viewModel = Modules.get(ViewModel.class);
|
| 436 | if (viewModel != null) viewModel.onHmiResourceReload();
|
| 437 | }));
|
| 438 | }
|
| 439 |
|
| 440 | }
|
| 441 |
|