From 02488b4289dc5f69b2beda43e67da2c9152b5dd2 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:15:46 +0700 Subject: [PATCH] imposter HClient :troll: --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 2 + .../mixin/ClientPlayNetworkHandlerMixin.java | 6 +- .../chipmunkmod/modules/CommandCore.java | 4 +- .../chipmunkmod/modules/KaboomCheck.java | 98 +++++++++++++++++++ 4 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index d27a818..7438ebe 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -1,6 +1,7 @@ package land.chipmunk.chipmunkmod; import com.google.gson.GsonBuilder; +import land.chipmunk.chipmunkmod.modules.KaboomCheck; import land.chipmunk.chipmunkmod.modules.Players; import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter; import net.fabricmc.api.ModInitializer; @@ -44,6 +45,7 @@ public class ChipmunkMod implements ModInitializer { } Players.INSTANCE.init(); + KaboomCheck.INSTANCE.init(); LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index cd8b339..9cd2470 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -3,12 +3,9 @@ package land.chipmunk.chipmunkmod.mixin; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.*; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientDynamicRegistryType; -import net.minecraft.client.network.PlayerListEntry; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.registry.CombinedDynamicRegistries; import net.minecraft.resource.featuretoggle.FeatureSet; @@ -18,8 +15,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Iterator; - @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { @Shadow private FeatureSet enabledFeatures; @@ -29,6 +24,7 @@ public class ClientPlayNetworkHandlerMixin { private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) { final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures); + KaboomCheck.INSTANCE.onJoin(); CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess); SelfCare.INSTANCE.init(); LoopCrouch.INSTANCE.init(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index e08dfc1..2c141c9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -56,7 +56,9 @@ public class CommandCore { final BlockPos relEnd = relativeArea.end(); final String command = String.format( - "fill %s %s %s %s %s %s command_block", + KaboomCheck.INSTANCE.isKaboom() ? + "fill %s %s %s %s %s %s repeating_command_block replace" : + "fill %s %s %s %s %s %s command_block", relStart.getX() + origin.getX(), relStart.getY() + origin.getY(), relStart.getZ() + origin.getZ(), diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java new file mode 100644 index 0000000..1eebfc4 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java @@ -0,0 +1,98 @@ +package land.chipmunk.chipmunkmod.modules; + +import land.chipmunk.chipmunkmod.listeners.Listener; +import land.chipmunk.chipmunkmod.listeners.ListenerManager; +import lombok.Getter; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket; +import net.minecraft.network.packet.s2c.play.TitleS2CPacket; + +import java.util.Timer; +import java.util.TimerTask; + +public class KaboomCheck extends Listener { + public static final String TITLE_START_TEXT = "Welcome to "; + public static final String TITLE_END_TEXT = "!"; + + public static final String SUBTITLE_START_TEXT = "Free OP"; + + @Getter private boolean isKaboom = false; + + private boolean hasKaboomTitle = false; + private boolean hasKaboomSubtitle = false; + + private Timer timer = null; + + private final MinecraftClient client; + + public static final KaboomCheck INSTANCE = new KaboomCheck(MinecraftClient.getInstance()); + + public KaboomCheck (MinecraftClient client) { + this.client = client; + + ListenerManager.addListener(this); + } + + public void init () {} + + public void onJoin () { + final TimerTask task = new TimerTask() { + public void run () { + tick(); + } + }; + + if (timer != null) cleanup(); + + timer = new Timer(); + + timer.schedule(task, 50, 50); + } + + private void tick () { + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + if (networkHandler == null) cleanup(); + + if (hasKaboomTitle && hasKaboomSubtitle) isKaboom = true; + } + + private void cleanup () { + if (timer == null) return; + + isKaboom = false; + hasKaboomTitle = false; + hasKaboomSubtitle = false; + + timer.purge(); + timer.cancel(); + } + + @Override + public void packetReceived(Packet packet) { + if (packet instanceof TitleS2CPacket) packetReceived((TitleS2CPacket) packet); + else if (packet instanceof SubtitleS2CPacket) packetReceived((SubtitleS2CPacket) packet); + } + + // TODO: move this to a util class + private String stripSectionSigns (String text) { + return text.replaceAll("ยง.", ""); + } + + public void packetReceived(TitleS2CPacket packet) { + final String stripped = stripSectionSigns(packet.getTitle().getString()); + + if ( + stripped.startsWith(TITLE_START_TEXT) && + stripped.endsWith(TITLE_END_TEXT) + ) hasKaboomTitle = true; + } + + public void packetReceived(SubtitleS2CPacket packet) { + final String stripped = stripSectionSigns(packet.getSubtitle().getString()); + + if (stripped.startsWith(SUBTITLE_START_TEXT)) hasKaboomSubtitle = true; + } +}