-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config setting for adding a dedicated illegal disconnect button to th…
…e menu screen
- Loading branch information
Showing
5 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/stardust/mixin/ClientConnectionAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters