From 92612c6b3277622fad4f04933616387de66638db Mon Sep 17 00:00:00 2001 From: Chip <65827213+ChipmunkMC@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:00:09 -0500 Subject: [PATCH] Add a temporary patch for `Chat message validation failed` --- .../mixin/ClientConnectionMixin.java | 18 ++++++++++++++++++ .../ClientPlayNetworkHandlerAccessor.java | 11 +++++++++++ src/main/resources/chipmunkmod.mixins.json | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java new file mode 100644 index 0000000..2065cb5 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -0,0 +1,18 @@ +package land.chipmunk.chipmunkmod.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.text.Text; + +@Mixin(net.minecraft.network.ClientConnection.class) +public class ClientConnectionMixin { + @Inject(at = @At("HEAD"), method = "disconnect", cancellable = true) + public void disconnect (Text disconnectReason, CallbackInfo ci) { + if (disconnectReason == ClientPlayNetworkHandlerAccessor.chatValidationFailedText()) { + ci.cancel(); + } + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java new file mode 100644 index 0000000..22576d9 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java @@ -0,0 +1,11 @@ +package land.chipmunk.chipmunkmod.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import net.minecraft.text.Text; + +@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) +public interface ClientPlayNetworkHandlerAccessor { + @Accessor("CHAT_VALIDATION_FAILED_TEXT") + public static Text chatValidationFailedText () { throw new AssertionError(); } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 53f3e39..e36dc97 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -7,7 +7,9 @@ ], "client": [ "ChatScreenMixin", - "ChatInputSuggestorMixin" + "ChatInputSuggestorMixin", + "ClientPlayNetworkHandlerAccessor", + "ClientConnectionMixin" ], "injectors": { "defaultRequire": 1