From 66438e980f81b73ce7e0b1d1718550764952e789 Mon Sep 17 00:00:00 2001 From: 0xTas Date: Wed, 25 Sep 2024 21:34:11 -0700 Subject: [PATCH] Config setting for adding a dedicated illegal disconnect button to the menu screen --- src/main/java/dev/stardust/Stardust.java | 27 +++++++++-- .../mixin/ClientConnectionAccessor.java | 14 ++++++ .../stardust/mixin/GameMenuScreenMixin.java | 35 +++++++++++++++ .../java/dev/stardust/util/StardustUtil.java | 45 +++++++++++++++++++ src/main/resources/stardust.mixins.json | 2 + 5 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java create mode 100644 src/main/java/dev/stardust/mixin/GameMenuScreenMixin.java diff --git a/src/main/java/dev/stardust/Stardust.java b/src/main/java/dev/stardust/Stardust.java index 6da7b0a..7f9a1f8 100644 --- a/src/main/java/dev/stardust/Stardust.java +++ b/src/main/java/dev/stardust/Stardust.java @@ -13,7 +13,10 @@ import meteordevelopment.meteorclient.commands.Commands; import meteordevelopment.meteorclient.addons.MeteorAddon; import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.systems.config.Config; +import meteordevelopment.meteorclient.settings.SettingGroup; +import dev.stardust.util.StardustUtil.IllegalDisconnectMethod; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.Category; @@ -26,6 +29,8 @@ public class Stardust extends MeteorAddon { public static Setting greenSplashTextSetting = new BoolSetting.Builder().build(); public static Setting rotateSplashTextSetting = new BoolSetting.Builder().build(); public static Setting directConnectButtonSetting = new BoolSetting.Builder().build(); + public static Setting illegalDisconnectButtonSetting = new BoolSetting.Builder().build(); + public static Setting illegalDisconnectMethodSetting = new EnumSetting.Builder().defaultValue(IllegalDisconnectMethod.Slot).build(); @Override public void onInitialize() { @@ -52,9 +57,10 @@ public void onInitialize() { Modules.get().add(new SignHistorian()); Modules.get().add(new AutoDyeShulkers()); Modules.get().add(new AutoDrawDistance()); + SettingGroup sgStardust = Config.get().settings.createGroup("Stardust"); // See SplashTextRendererMixin.java - greenSplashTextSetting = Config.get().settings.getGroup("Visual").add( + greenSplashTextSetting = sgStardust.add( new BoolSetting.Builder() .name("Green Splash Text") .description(">Makes the title splash texts green.") @@ -62,20 +68,35 @@ public void onInitialize() { .build() ); // See TitleScreenMixin.java - rotateSplashTextSetting = Config.get().settings.getGroup("Visual").add( + rotateSplashTextSetting = sgStardust.add( new BoolSetting.Builder() .name("Rotate Splash Text") .description("Picks a new random splash text every 20 seconds.") .defaultValue(false) .build() ); - directConnectButtonSetting = Config.get().settings.getGroup("Visual").add( + directConnectButtonSetting = sgStardust.add( new BoolSetting.Builder() .name("Direct Connect Button") .description("Adds a button to the main menu that directly connects you to 2b2t.org") .defaultValue(false) .build() ); + // See GameMenuScreenMixin.java + illegalDisconnectButtonSetting = sgStardust.add( + new BoolSetting.Builder() + .name("illegal-disconnect-button") + .description("Adds a button to the main menu that forces the server to kick you when pressed.") + .defaultValue(false) + .build() + ); + illegalDisconnectMethodSetting = sgStardust.add( + new EnumSetting.Builder() + .name("illegal-disconnect-method") + .description("The method to use to cause the server to kick you.") + .defaultValue(IllegalDisconnectMethod.Interact) + .build() + ); LOG.info("<✨> Stardust initialized."); } diff --git a/src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java b/src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java new file mode 100644 index 0000000..47ad807 --- /dev/null +++ b/src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java @@ -0,0 +1,14 @@ +package dev.stardust.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.jetbrains.annotations.Nullable; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.PacketCallbacks; +import net.minecraft.network.ClientConnection; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ClientConnection.class) +public interface ClientConnectionAccessor { + @Invoker("sendImmediately") + void invokeSendImmediately(Packet packet, @Nullable PacketCallbacks callbacks); +} diff --git a/src/main/java/dev/stardust/mixin/GameMenuScreenMixin.java b/src/main/java/dev/stardust/mixin/GameMenuScreenMixin.java new file mode 100644 index 0000000..36cbc93 --- /dev/null +++ b/src/main/java/dev/stardust/mixin/GameMenuScreenMixin.java @@ -0,0 +1,35 @@ +package dev.stardust.mixin; + +import dev.stardust.Stardust; +import net.minecraft.text.Text; +import dev.stardust.util.StardustUtil; +import org.spongepowered.asm.mixin.Mixin; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.gui.screen.Screen; +import org.spongepowered.asm.mixin.injection.At; +import net.minecraft.client.gui.widget.GridWidget; +import org.spongepowered.asm.mixin.injection.Inject; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.screen.GameMenuScreen; +import static meteordevelopment.meteorclient.MeteorClient.mc; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * @author Tas [0xTas] + **/ +@Mixin(GameMenuScreen.class) +public class GameMenuScreenMixin extends Screen { + protected GameMenuScreenMixin(Text title) { + super(title); + } + + @Inject(method = "initWidgets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget;refreshPositions()V")) + private void addIllegalDisconnectButton(CallbackInfo ci, @Local GridWidget.Adder adder) { + if (Stardust.illegalDisconnectButtonSetting.get() && !mc.isInSingleplayer()) { + adder.add(ButtonWidget.builder(Text.literal("§cIllegal Disconnect"), button -> { + button.active = false; + StardustUtil.illegalDisconnect(false, Stardust.illegalDisconnectMethodSetting.get()); + }).width(204).build(), 2); + } + } +} diff --git a/src/main/java/dev/stardust/util/StardustUtil.java b/src/main/java/dev/stardust/util/StardustUtil.java index e802189..d995f47 100644 --- a/src/main/java/dev/stardust/util/StardustUtil.java +++ b/src/main/java/dev/stardust/util/StardustUtil.java @@ -2,17 +2,28 @@ import java.awt.*; import java.io.File; +import java.time.Instant; import dev.stardust.Stardust; +import net.minecraft.util.Hand; import net.minecraft.text.Text; import net.minecraft.text.Style; import net.minecraft.item.Items; import net.minecraft.item.ItemStack; import net.minecraft.text.ClickEvent; import net.minecraft.text.MutableText; +import net.minecraft.network.packet.Packet; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.enchantment.Enchantments; +import net.minecraft.network.packet.c2s.play.*; import io.netty.util.internal.ThreadLocalRandom; +import meteordevelopment.meteorclient.utils.Utils; +import dev.stardust.mixin.ClientConnectionAccessor; +import static meteordevelopment.meteorclient.MeteorClient.mc; +import meteordevelopment.meteorclient.systems.modules.Modules; +import net.minecraft.network.encryption.NetworkEncryptionUtils; +import meteordevelopment.meteorclient.systems.modules.misc.AutoReconnect; +import meteordevelopment.meteorclient.mixin.ClientPlayNetworkHandlerAccessor; /** * @author Tas [@0xTas] @@ -251,4 +262,38 @@ public static void openFile(MinecraftClient mc, String fileName) { } } } + + public enum IllegalDisconnectMethod { + Slot, Chat, Interact, Movement, SequenceBreak + } + + public static void illegalDisconnect(boolean disableAutoReconnect, IllegalDisconnectMethod illegalDisconnectMethod) { + if (!Utils.canUpdate()) return; + if (disableAutoReconnect) disableAutoReconnect(); + + Packet illegalPacket = null; + switch (illegalDisconnectMethod) { + case Slot -> illegalPacket = new UpdateSelectedSlotC2SPacket(-69); + case Chat -> illegalPacket = new ChatMessageC2SPacket( + "§", + Instant.now(), + NetworkEncryptionUtils.SecureRandomUtil.nextLong(), + null, + ((ClientPlayNetworkHandlerAccessor) mc.getNetworkHandler()).getLastSeenMessagesCollector().collect().update() + ); + case Interact -> illegalPacket = PlayerInteractEntityC2SPacket.interact(mc.player, false, Hand.MAIN_HAND); + case Movement -> illegalPacket = new PlayerMoveC2SPacket.PositionAndOnGround(Double.NaN, 69, Double.NaN, false); + case SequenceBreak -> illegalPacket = new PlayerInteractItemC2SPacket(Hand.MAIN_HAND, -420); + } + if (illegalPacket != null) ((ClientConnectionAccessor) mc.getNetworkHandler().getConnection()).invokeSendImmediately( + illegalPacket, null + ); + } + + public static void disableAutoReconnect() { + Modules mods = Modules.get(); + if (mods == null) return; + AutoReconnect atrc = mods.get(AutoReconnect.class); + if (atrc.isActive()) atrc.toggle(); + } } diff --git a/src/main/resources/stardust.mixins.json b/src/main/resources/stardust.mixins.json index 839357e..1968ee3 100644 --- a/src/main/resources/stardust.mixins.json +++ b/src/main/resources/stardust.mixins.json @@ -17,6 +17,7 @@ "AnvilScreenAccessor", "BookEditScreenMixin", "GameOptionsAccessor", + "GameMenuScreenMixin", "MinecraftClientMixin", "MusicTrackerAccessor", "NarratorManagerMixin", @@ -42,6 +43,7 @@ "PlayerEntityMixin", "GoatHornItemMixin", "LivingEntityMixin", + "ClientConnectionAccessor", "FireworkRocketEntityMixin", "AnvilScreenHandlerAccessor", "PlayerMoveC2SPacketAccessor",