Skip to content

Commit

Permalink
Config setting for adding a dedicated illegal disconnect button to th…
Browse files Browse the repository at this point in the history
…e menu screen
  • Loading branch information
0xTas committed Nov 7, 2024
1 parent 28135a1 commit 66438e9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/main/java/dev/stardust/Stardust.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,6 +29,8 @@ public class Stardust extends MeteorAddon {
public static Setting<Boolean> greenSplashTextSetting = new BoolSetting.Builder().build();
public static Setting<Boolean> rotateSplashTextSetting = new BoolSetting.Builder().build();
public static Setting<Boolean> directConnectButtonSetting = new BoolSetting.Builder().build();
public static Setting<Boolean> illegalDisconnectButtonSetting = new BoolSetting.Builder().build();
public static Setting<IllegalDisconnectMethod> illegalDisconnectMethodSetting = new EnumSetting.Builder<IllegalDisconnectMethod>().defaultValue(IllegalDisconnectMethod.Slot).build();

@Override
public void onInitialize() {
Expand All @@ -52,30 +57,46 @@ 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.")
.defaultValue(false)
.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<IllegalDisconnectMethod>()
.name("illegal-disconnect-method")
.description("The method to use to cause the server to kick you.")
.defaultValue(IllegalDisconnectMethod.Interact)
.build()
);

LOG.info("<✨> Stardust initialized.");
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java
Original file line number Diff line number Diff line change
@@ -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);
}
35 changes: 35 additions & 0 deletions src/main/java/dev/stardust/mixin/GameMenuScreenMixin.java
Original file line number Diff line number Diff line change
@@ -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] <[email protected]>
**/
@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);
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/dev/stardust/util/StardustUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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] <[email protected]>
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/stardust.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"AnvilScreenAccessor",
"BookEditScreenMixin",
"GameOptionsAccessor",
"GameMenuScreenMixin",
"MinecraftClientMixin",
"MusicTrackerAccessor",
"NarratorManagerMixin",
Expand All @@ -42,6 +43,7 @@
"PlayerEntityMixin",
"GoatHornItemMixin",
"LivingEntityMixin",
"ClientConnectionAccessor",
"FireworkRocketEntityMixin",
"AnvilScreenHandlerAccessor",
"PlayerMoveC2SPacketAccessor",
Expand Down

0 comments on commit 66438e9

Please sign in to comment.