| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.mixin;
|
| 7 |
|
| 8 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 9 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 10 | import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
| 11 | import com.llamalad7.mixinextras.sugar.Local;
|
| 12 | import meteordevelopment.meteorclient.MeteorClient;
|
| 13 | import meteordevelopment.meteorclient.events.entity.player.DoAttackEvent;
|
| 14 | import meteordevelopment.meteorclient.events.entity.player.DoItemUseEvent;
|
| 15 | import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent;
|
| 16 | import meteordevelopment.meteorclient.events.game.GameLeftEvent;
|
| 17 | import meteordevelopment.meteorclient.events.game.ResolutionChangedEvent;
|
| 18 | import meteordevelopment.meteorclient.events.game.ResourcePacksReloadedEvent;
|
| 19 | import meteordevelopment.meteorclient.events.world.TickEvent;
|
| 20 | import meteordevelopment.meteorclient.mixininterface.IMinecraft;
|
| 21 | import meteordevelopment.meteorclient.mixininterface.IVec3;
|
| 22 | import meteordevelopment.meteorclient.systems.config.Config;
|
| 23 | import meteordevelopment.meteorclient.systems.modules.Modules;
|
| 24 | import meteordevelopment.meteorclient.systems.modules.misc.InventoryTweaks;
|
| 25 | import meteordevelopment.meteorclient.systems.modules.player.FastUse;
|
| 26 | import meteordevelopment.meteorclient.systems.modules.player.Multitask;
|
| 27 | import meteordevelopment.meteorclient.systems.modules.render.ESP;
|
| 28 | import meteordevelopment.meteorclient.systems.modules.render.Freecam;
|
| 29 | import meteordevelopment.meteorclient.systems.modules.world.HighwayBuilder;
|
| 30 | import meteordevelopment.meteorclient.utils.Utils;
|
| 31 | import meteordevelopment.meteorclient.utils.misc.CPSUtils;
|
| 32 | import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
|
| 33 | import meteordevelopment.meteorclient.utils.network.OnlinePlayers;
|
| 34 | import net.minecraft.client.Minecraft;
|
| 35 | import net.minecraft.client.Options;
|
| 36 | import net.minecraft.client.gui.screens.Screen;
|
| 37 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 38 | import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
| 39 | import net.minecraft.client.player.LocalPlayer;
|
| 40 | import net.minecraft.client.renderer.GameRenderer;
|
| 41 | import net.minecraft.util.profiling.Profiler;
|
| 42 | import net.minecraft.world.entity.Entity;
|
| 43 | import net.minecraft.world.entity.player.Player;
|
| 44 | import net.minecraft.world.item.ItemStack;
|
| 45 | import net.minecraft.world.phys.HitResult;
|
| 46 | import org.jspecify.annotations.Nullable;
|
| 47 | import org.meteordev.starscript.Script;
|
| 48 | import org.objectweb.asm.Opcodes;
|
| 49 | import org.spongepowered.asm.mixin.Final;
|
| 50 | import org.spongepowered.asm.mixin.Mixin;
|
| 51 | import org.spongepowered.asm.mixin.Shadow;
|
| 52 | import org.spongepowered.asm.mixin.Unique;
|
| 53 | import org.spongepowered.asm.mixin.injection.At;
|
| 54 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 55 | import org.spongepowered.asm.mixin.injection.ModifyArg;
|
| 56 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 57 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 58 |
|
| 59 | import java.util.concurrent.CompletableFuture;
|
| 60 |
|
| 61 | @Mixin(value = Minecraft.class, priority = 1001)
|
| 62 | public abstract class MinecraftMixin implements IMinecraft {
|
| 63 | @Unique
|
| 64 | private boolean startUseItemCalled;
|
| 65 | @Unique
|
| 66 | private boolean rightClick;
|
| 67 | @Unique
|
| 68 | private long lastTime;
|
| 69 | @Unique
|
| 70 | private boolean firstFrame;
|
| 71 |
|
| 72 | @Shadow
|
| 73 | public ClientLevel level;
|
| 74 | @Shadow
|
| 75 | @Final
|
| 76 | public Options options;
|
| 77 |
|
| 78 | @Shadow
|
| 79 | protected abstract void startUseItem();
|
| 80 |
|
| 81 | @Shadow
|
| 82 | @Nullable
|
| 83 | public MultiPlayerGameMode gameMode;
|
| 84 |
|
| 85 | @Shadow
|
| 86 | private int rightClickDelay;
|
| 87 |
|
| 88 | @Shadow
|
| 89 | @Nullable
|
| 90 | public LocalPlayer player;
|
| 91 |
|
| 92 | @Shadow
|
| 93 | protected abstract void continueAttack(boolean down);
|
| 94 |
|
| 95 | @Unique
|
| 96 | private boolean freecamSet = false;
|
| 97 |
|
| 98 | @Final
|
| 99 | @Shadow
|
| 100 | public GameRenderer gameRenderer;
|
| 101 |
|
| 102 | @Shadow
|
| 103 | protected abstract void pick(float partialTicks);
|
| 104 |
|
| 105 | @Shadow
|
| 106 | public abstract Entity getCameraEntity();
|
| 107 |
|
| 108 | @Inject(method = "<init>", at = @At("TAIL"))
|
| 109 | private void onInit(CallbackInfo ci) {
|
| 110 | MeteorClient.INSTANCE.onInitializeClient();
|
| 111 | firstFrame = true;
|
| 112 | }
|
| 113 |
|
| 114 | @Inject(at = @At("HEAD"), method = "tick")
|
| 115 | private void onPreTick(CallbackInfo ci) {
|
| 116 | OnlinePlayers.update();
|
| 117 |
|
| 118 | startUseItemCalled = false;
|
| 119 |
|
| 120 | Profiler.get().push(MeteorClient.MOD_ID + "_pre_update");
|
| 121 | MeteorClient.EVENT_BUS.post(TickEvent.Pre.get());
|
| 122 | Profiler.get().pop();
|
| 123 |
|
| 124 | if (rightClick && !startUseItemCalled && gameMode != null) startUseItem();
|
| 125 | rightClick = false;
|
| 126 | }
|
| 127 |
|
| 128 | @Inject(at = @At("TAIL"), method = "tick")
|
| 129 | private void onTick(CallbackInfo ci) {
|
| 130 | Profiler.get().push(MeteorClient.MOD_ID + "_post_update");
|
| 131 | MeteorClient.EVENT_BUS.post(TickEvent.Post.get());
|
| 132 | Profiler.get().pop();
|
| 133 | }
|
| 134 |
|
| 135 | @Inject(method = "startAttack", at = @At("HEAD"), cancellable = true)
|
| 136 | private void onStartAttack(CallbackInfoReturnable<Boolean> cir) {
|
| 137 | CPSUtils.onAttack();
|
| 138 | if (MeteorClient.EVENT_BUS.post(DoAttackEvent.get()).isCancelled()) cir.cancel();
|
| 139 | }
|
| 140 |
|
| 141 | @Inject(method = "startUseItem", at = @At("HEAD"))
|
| 142 | private void onStartUseItem(CallbackInfo ci) {
|
| 143 | startUseItemCalled = true;
|
| 144 | }
|
| 145 |
|
| 146 | @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;ZZ)V", at = @At("HEAD"))
|
| 147 | private void onDisconnect(Screen screen, boolean keepResourcePacks, boolean stopSound, CallbackInfo ci) {
|
| 148 | if (level != null) {
|
| 149 | MeteorClient.EVENT_BUS.post(GameLeftEvent.get());
|
| 150 | }
|
| 151 | }
|
| 152 |
|
| 153 | @Inject(method = "startUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isItemEnabled(Lnet/minecraft/world/flag/FeatureFlagSet;)Z"))
|
| 154 | private void onStartUseItemHand(CallbackInfo ci, @Local(name = "heldItem") ItemStack heldItem) {
|
| 155 | FastUse fastUse = Modules.get().get(FastUse.class);
|
| 156 | if (fastUse.isActive()) {
|
| 157 | rightClickDelay = fastUse.getItemUseCooldown(heldItem);
|
| 158 | }
|
| 159 | }
|
| 160 |
|
| 161 | @Inject(method = "startUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/InteractionHand;values()[Lnet/minecraft/world/InteractionHand;"), cancellable = true)
|
| 162 | private void onStartUseItemBeforeHands(CallbackInfo ci) {
|
| 163 | if (MeteorClient.EVENT_BUS.post(DoItemUseEvent.get()).isCancelled()) ci.cancel();
|
| 164 | }
|
| 165 |
|
| 166 | @ModifyExpressionValue(method = "startUseItem", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1, opcode = Opcodes.GETFIELD))
|
| 167 | private HitResult startUseItemMinecraftClientCrosshairTargetProxy(HitResult original) {
|
| 168 | return MeteorClient.EVENT_BUS.post(ItemUseCrosshairTargetEvent.get(original)).target;
|
| 169 | }
|
| 170 |
|
| 171 | @ModifyReturnValue(method = "reloadResourcePacks(ZLnet/minecraft/client/GameLoadCookie;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"))
|
| 172 | private CompletableFuture<Void> onReloadResourcePacksNewCompletableFuture(CompletableFuture<Void> original) {
|
| 173 | return original.thenRun(() -> MeteorClient.EVENT_BUS.post(ResourcePacksReloadedEvent.get()));
|
| 174 | }
|
| 175 |
|
| 176 | @ModifyArg(method = "updateTitle", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/Window;setTitle(Ljava/lang/String;)V"))
|
| 177 | private String setTitle(String original) {
|
| 178 | if (Config.get() == null || !Config.get().customWindowTitle.get()) return original;
|
| 179 |
|
| 180 | String customTitle = Config.get().customWindowTitleText.get();
|
| 181 | Script script = MeteorStarscript.compile(customTitle);
|
| 182 |
|
| 183 | if (script != null) {
|
| 184 | String title = MeteorStarscript.run(script);
|
| 185 | if (title != null) customTitle = title;
|
| 186 | }
|
| 187 |
|
| 188 | return customTitle;
|
| 189 | }
|
| 190 |
|
| 191 | // Have to add this condition if we want to draw back a bow using packets, without it getting cancelled by vanilla code
|
| 192 | @WrapWithCondition(method = "handleKeybinds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;releaseUsingItem(Lnet/minecraft/world/entity/player/Player;)V"))
|
| 193 | private boolean wrapStopUsing(MultiPlayerGameMode instance, Player player) {
|
| 194 | return HB$stopUsingItem();
|
| 195 | }
|
| 196 |
|
| 197 | @Unique
|
| 198 | private boolean HB$stopUsingItem() {
|
| 199 | HighwayBuilder b = Modules.get().get(HighwayBuilder.class);
|
| 200 | return !b.isActive() || !b.drawingBow;
|
| 201 | }
|
| 202 |
|
| 203 | @Inject(method = "resizeGui", at = @At("TAIL"))
|
| 204 | private void onResizeGui(CallbackInfo ci) {
|
| 205 | MeteorClient.EVENT_BUS.post(ResolutionChangedEvent.get());
|
| 206 | }
|
| 207 |
|
| 208 | // Time delta
|
| 209 |
|
| 210 | @Inject(method = "runTick", at = @At("HEAD"))
|
| 211 | private void onRunTick(CallbackInfo ci) {
|
| 212 | long time = System.currentTimeMillis();
|
| 213 |
|
| 214 | if (firstFrame) {
|
| 215 | lastTime = time;
|
| 216 | firstFrame = false;
|
| 217 | }
|
| 218 |
|
| 219 | Utils.frameTime = (time - lastTime) / 1000.0;
|
| 220 | lastTime = time;
|
| 221 | }
|
| 222 |
|
| 223 | // Multitask
|
| 224 |
|
| 225 | @ModifyExpressionValue(method = "startUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;isDestroying()Z"))
|
| 226 | private boolean startUseItemModifyIsBreakingBlock(boolean original) {
|
| 227 | return !Modules.get().isActive(Multitask.class) && original;
|
| 228 | }
|
| 229 |
|
| 230 | @ModifyExpressionValue(method = "continueAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isUsingItem()Z"))
|
| 231 | private boolean continueAttackModifyIsUsingItem(boolean original) {
|
| 232 | return !Modules.get().isActive(Multitask.class) && original;
|
| 233 | }
|
| 234 |
|
| 235 | @ModifyExpressionValue(method = "handleKeybinds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isUsingItem()Z", ordinal = 0))
|
| 236 | private boolean handleKeybindsModifyIsUsingItem(boolean original) {
|
| 237 | return !Modules.get().get(Multitask.class).attackingEntities() && original;
|
| 238 | }
|
| 239 |
|
| 240 | @Inject(method = "handleKeybinds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isUsingItem()Z", ordinal = 0, shift = At.Shift.BEFORE))
|
| 241 | private void handleKeybindsInjectStopUsingItem(CallbackInfo ci) {
|
| 242 | if (Modules.get().get(Multitask.class).attackingEntities() && player.isUsingItem()) {
|
| 243 | if (!options.keyUse.isDown() && HB$stopUsingItem()) gameMode.releaseUsingItem(player);
|
| 244 | //noinspection StatementWithEmptyBody
|
| 245 | while (options.keyUse.consumeClick()) ;
|
| 246 | }
|
| 247 | }
|
| 248 |
|
| 249 | // Glow esp
|
| 250 |
|
| 251 | @ModifyReturnValue(method = "shouldEntityAppearGlowing", at = @At("RETURN"))
|
| 252 | private boolean shouldEntityAppearGlowingModifyIsOutline(boolean original, Entity entity) {
|
| 253 | ESP esp = Modules.get().get(ESP.class);
|
| 254 | if (esp == null) return original;
|
| 255 | if (!esp.isGlow() || esp.shouldSkip(entity)) return original;
|
| 256 |
|
| 257 | return esp.getColor(entity) != null || original;
|
| 258 | }
|
| 259 |
|
| 260 |
|
| 261 | // faster inputs
|
| 262 |
|
| 263 | @Unique
|
| 264 | private boolean isBreaking = false;
|
| 265 |
|
| 266 | @WrapWithCondition(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;handleKeybinds()V"))
|
| 267 | private boolean wrapHandleInputEvents(Minecraft instance) {
|
| 268 | return !Modules.get().get(InventoryTweaks.class).frameInput();
|
| 269 | }
|
| 270 |
|
| 271 | @WrapWithCondition(method = "handleKeybinds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;continueAttack(Z)V"))
|
| 272 | private boolean wrapHandleBlockBreaking(Minecraft instance, boolean down) {
|
| 273 | isBreaking = down;
|
| 274 | return !Modules.get().get(InventoryTweaks.class).frameInput();
|
| 275 | }
|
| 276 |
|
| 277 | @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;handleKeybinds()V", shift = At.Shift.AFTER))
|
| 278 | private void afterHandleInputEvents(CallbackInfo ci) {
|
| 279 | if (!Modules.get().get(InventoryTweaks.class).frameInput()) return;
|
| 280 |
|
| 281 | continueAttack(isBreaking);
|
| 282 | isBreaking = false;
|
| 283 | }
|
| 284 |
|
| 285 | // Interface
|
| 286 |
|
| 287 | @Override
|
| 288 | public void meteor$rightClick() {
|
| 289 | rightClick = true;
|
| 290 | }
|
| 291 |
|
| 292 | // Freecam
|
| 293 | @Inject(method = "pick", at = @At("HEAD"), cancellable = true)
|
| 294 | private void updateTargetedEntityInvoke(float partialTicks, CallbackInfo ci) {
|
| 295 | Freecam freecam = Modules.get().get(Freecam.class);
|
| 296 | boolean highwayBuilder = Modules.get().isActive(HighwayBuilder.class);
|
| 297 |
|
| 298 | if ((freecam.isActive() || highwayBuilder) && this.getCameraEntity() != null && !freecamSet) {
|
| 299 | ci.cancel();
|
| 300 | Entity cameraE = this.getCameraEntity();
|
| 301 |
|
| 302 | double x = cameraE.getX();
|
| 303 | double y = cameraE.getY();
|
| 304 | double z = cameraE.getZ();
|
| 305 | double lastX = cameraE.xo;
|
| 306 | double lastY = cameraE.yo;
|
| 307 | double lastZ = cameraE.zo;
|
| 308 | float yaw = cameraE.getYRot();
|
| 309 | float pitch = cameraE.getXRot();
|
| 310 | float lastYaw = cameraE.yRotO;
|
| 311 | float lastPitch = cameraE.xRotO;
|
| 312 |
|
| 313 | if (highwayBuilder) {
|
| 314 | cameraE.setYRot(this.gameRenderer.mainCamera().yRot());
|
| 315 | cameraE.setXRot(this.gameRenderer.mainCamera().xRot());
|
| 316 | } else {
|
| 317 | ((IVec3) cameraE.position()).meteor$set(freecam.pos.x, freecam.pos.y - cameraE.getEyeHeight(cameraE.getPose()), freecam.pos.z);
|
| 318 | cameraE.xo = freecam.prevPos.x;
|
| 319 | cameraE.yo = freecam.prevPos.y - cameraE.getEyeHeight(cameraE.getPose());
|
| 320 | cameraE.zo = freecam.prevPos.z;
|
| 321 | cameraE.setYRot(freecam.yaw);
|
| 322 | cameraE.setXRot(freecam.pitch);
|
| 323 | cameraE.yRotO = freecam.lastYaw;
|
| 324 | cameraE.xRotO = freecam.lastPitch;
|
| 325 | }
|
| 326 |
|
| 327 | freecamSet = true;
|
| 328 | pick(partialTicks);
|
| 329 | freecamSet = false;
|
| 330 |
|
| 331 | ((IVec3) cameraE.position()).meteor$set(x, y, z);
|
| 332 | cameraE.xo = lastX;
|
| 333 | cameraE.yo = lastY;
|
| 334 | cameraE.zo = lastZ;
|
| 335 | cameraE.setYRot(yaw);
|
| 336 | cameraE.setXRot(pitch);
|
| 337 | cameraE.yRotO = lastYaw;
|
| 338 | cameraE.xRotO = lastPitch;
|
| 339 | }
|
| 340 | }
|
| 341 | }
|
| 342 |
|