-
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.
Added 'Illegal Disconnect' functionality to Meteor's built-in AutoLog…
… module. Also added a config setting which adds a dedicated illegal disconnect button to the pause menu.
- Loading branch information
Showing
8 changed files
with
265 additions
and
17 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
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
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,99 @@ | ||
package dev.stardust.mixin; | ||
|
||
import dev.stardust.Stardust; | ||
import net.minecraft.text.Text; | ||
import javax.annotation.Nullable; | ||
import dev.stardust.util.StardustUtil; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import meteordevelopment.orbit.EventHandler; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import meteordevelopment.meteorclient.utils.Utils; | ||
import meteordevelopment.meteorclient.MeteorClient; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import meteordevelopment.meteorclient.settings.Setting; | ||
import meteordevelopment.meteorclient.settings.BoolSetting; | ||
import meteordevelopment.meteorclient.settings.SettingGroup; | ||
import meteordevelopment.meteorclient.systems.modules.Module; | ||
import meteordevelopment.meteorclient.systems.modules.Category; | ||
import meteordevelopment.meteorclient.events.packets.PacketEvent; | ||
import meteordevelopment.meteorclient.systems.modules.misc.AutoLog; | ||
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
* | ||
* Adds "Illegal Disconnect" functionality to Meteor's built-in AutoLog module. | ||
**/ | ||
@Mixin(value = AutoLog.class, remap = false) | ||
public abstract class AutoLogMixin extends Module { | ||
public AutoLogMixin(Category category, String name, String description) { | ||
super(category, name, description); | ||
MeteorClient.EVENT_BUS.subscribe(this); // TODO: sus | ||
} | ||
|
||
@Shadow | ||
@Final | ||
private SettingGroup sgGeneral; | ||
@Shadow | ||
@Final | ||
private Setting<Boolean> toggleOff; | ||
|
||
@Unique | ||
private boolean didLog = false; | ||
@Unique | ||
@Nullable | ||
private Text disconnectReason = null; | ||
@Unique | ||
@Nullable | ||
private Setting<Boolean> forceKick = null; | ||
|
||
@Override | ||
public void onDeactivate() { | ||
if (toggleOff.get() && didLog) { | ||
MeteorClient.EVENT_BUS.subscribe(this); | ||
} | ||
} | ||
|
||
@Inject(method = "<init>", at = @At(value = "FIELD", target = "Lmeteordevelopment/meteorclient/systems/modules/misc/AutoLog;entities:Lmeteordevelopment/meteorclient/settings/Setting;")) | ||
private void addIllegalDisconnectSetting(CallbackInfo ci) { | ||
forceKick = sgGeneral.add( | ||
new BoolSetting.Builder() | ||
.name("illegal-disconnect") | ||
.description("Tip: Change the illegal disconnect method in your Meteor config settings (Stardust category.)") | ||
.defaultValue(false) | ||
.build() | ||
); | ||
} | ||
|
||
@Inject(method = "onTick",at = @At("HEAD"), cancellable = true) | ||
private void preventNullPointerExceptions(CallbackInfo ci) { | ||
if (!Utils.canUpdate()) ci.cancel(); | ||
} | ||
|
||
@Inject(method = "disconnect", at = @At("HEAD"), cancellable = true) | ||
private void maybeForceKick(String reason, CallbackInfo ci) { | ||
if (forceKick != null && forceKick.get()) { | ||
ci.cancel(); | ||
didLog = true; | ||
if (toggleOff.get()) toggle(); | ||
disconnectReason = Text.literal("§8[§aAutoLog§8] §f" + reason); | ||
StardustUtil.illegalDisconnect(true, Stardust.illegalDisconnectMethodSetting.get()); | ||
} | ||
} | ||
|
||
@Unique | ||
@EventHandler | ||
private void onPacketReceive(PacketEvent.Receive event) { | ||
if (disconnectReason == null || !(event.packet instanceof DisconnectS2CPacket packet)) return; | ||
if (didLog) { | ||
((DisconnectS2CPacketAccessor)(Object) packet).setReason(disconnectReason); | ||
MeteorClient.EVENT_BUS.unsubscribe(this); | ||
disconnectReason = null; | ||
didLog = false; | ||
} | ||
} | ||
} |
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 javax.annotation.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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, boolean flush); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/stardust/mixin/DisconnectS2CPacketAccessor.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 net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket; | ||
|
||
@Mixin(DisconnectS2CPacket.class) | ||
public interface DisconnectS2CPacketAccessor { | ||
@Mutable | ||
@Accessor("reason") | ||
void setReason(Text reason); | ||
} |
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.