diff --git a/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java b/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java index b1b22e5a..e379f9c6 100644 --- a/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java +++ b/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java @@ -43,11 +43,20 @@ public static boolean tryDecrypt(Component component, Encryptor encryptor) { return true; } } else if (component.getContents() instanceof TranslatableContents translatable) { - for (Object arg : translatable.args) { + for (int i = 0; i < translatable.args.length; i++) { + Object arg = translatable.args[i]; + if (arg instanceof MutableComponent mutable) { if (tryDecrypt(mutable, encryptor)) { decryptedSiblings = true; } + } else if (arg instanceof String str) { + var decrypted = tryDecrypt(str, encryptor); + + if (decrypted.isPresent()) { + translatable.args[i] = decrypted.get(); + decryptedSiblings = true; + } } } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java index 544ad619..1d8e15a5 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; import net.minecraft.ChatFormatting; +import net.minecraft.client.GuiMessage; import net.minecraft.client.GuiMessageTag; import net.minecraft.client.gui.components.ChatComponent; import net.minecraft.core.RegistryAccess; @@ -33,41 +34,42 @@ private String onAddRecentChat(String message) { return message; } - @ModifyVariable(method = "addMessage(Lnet/minecraft/network/chat/Component;" - + "Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/GuiMessageTag;)V", - at = @At(value = "HEAD"), argsOnly = true) - private synchronized GuiMessageTag modifyGUITag(GuiMessageTag tag) { - if (!NCRConfig.getEncryption().showEncryptionIndicators() || !this.lastMessageEncrypted) - return tag; - - this.lastMessageEncrypted = false; - Component tooltip = Component.empty().append(Component.translatable("tag.nochatreports.encrypted", - Component.literal(NCRConfig.getEncryption().getAlgorithm().getName()) - .withStyle(ChatFormatting.BOLD))).append(CommonComponents.NEW_LINE).append( - Component.translatable("tag.nochatreports.encrypted_original", - this.lastMessageOriginal)); - - return new GuiMessageTag(0x8B3EC7, ENCRYPTED_ICON, tooltip, "Encrypted"); - } - - @ModifyArg(index = 0, method = "addMessage(Lnet/minecraft/network/chat/Component;" + @ModifyVariable(index = -1, method = "addMessage(Lnet/minecraft/network/chat/Component;" + "Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/GuiMessageTag;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ChatComponent;" + "logChatMessage(Lnet/minecraft/client/GuiMessage;)V", ordinal = 0, shift = Shift.BEFORE)) - private FormattedText modifyGUIMessage(FormattedText msg) { + private GuiMessage modifyGUIMessage(GuiMessage msg) { if (NCRConfig.getCommon().enableDebugLog()) { NCRCore.LOGGER.info("Adding chat message, structure: " + - Component.Serializer.toJson((Component) msg, RegistryAccess.EMPTY)); + Component.Serializer.toJson(msg.content(), RegistryAccess.EMPTY)); } - var decrypted = EncryptionUtil.tryDecrypt((Component) msg); + var decrypted = EncryptionUtil.tryDecrypt(msg.content()); decrypted.ifPresentOrElse(component -> { - this.lastMessageOriginal = EncryptionUtil.recreate((Component) msg); + this.lastMessageOriginal = EncryptionUtil.recreate(msg.content()); this.lastMessageEncrypted = true; }, () -> this.lastMessageEncrypted = false); - return this.lastMessageEncrypted ? decrypted.get() : msg; + if (this.lastMessageEncrypted) { + this.lastMessageEncrypted = false; + + Component decryptedComponent = decrypted.get(); + GuiMessageTag newTag = msg.tag(); + + if (NCRConfig.getEncryption().showEncryptionIndicators()) { + Component tooltip = Component.empty().append(Component.translatable("tag.nochatreports.encrypted", + Component.literal(NCRConfig.getEncryption().getAlgorithm().getName()) + .withStyle(ChatFormatting.BOLD))).append(CommonComponents.NEW_LINE).append( + Component.translatable("tag.nochatreports.encrypted_original", + this.lastMessageOriginal)); + + newTag = new GuiMessageTag(0x8B3EC7, ENCRYPTED_ICON, tooltip, "Encrypted"); + } + + return new GuiMessage(msg.addedTime(), decryptedComponent, msg.signature(), newTag); + } else + return msg; } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatListener.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatListener.java index 7c5371d0..abed585a 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatListener.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatListener.java @@ -103,7 +103,7 @@ private void onEvaluateTrustLevel(PlayerChatMessage playerChatMessage, Component // Debug never dies if (NCRConfig.getCommon().enableDebugLog()) { NCRCore.LOGGER.info("Received message: {}, from: {}, signature: {}", - Component.Serializer.toJson(playerChatMessage.unsignedContent(), RegistryAccess.EMPTY), + Component.Serializer.toJson(playerChatMessage.decoratedContent(), RegistryAccess.EMPTY), playerChatMessage.link().sender(), Base64.getEncoder().encodeToString(playerChatMessage.signature() != null ? playerChatMessage.signature().bytes() : new byte[0])); } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinConnectScreen.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinConnectScreen.java index d89d9ae4..f938b733 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinConnectScreen.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinConnectScreen.java @@ -14,6 +14,7 @@ import net.minecraft.client.gui.screens.ConnectScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.client.multiplayer.TransferState; import net.minecraft.client.multiplayer.resolver.ServerAddress; @Mixin(ConnectScreen.class) @@ -27,7 +28,7 @@ public class MixinConnectScreen { @Inject(method = "startConnecting", at = @At("HEAD")) private static void onStartConnecting(Screen screen, Minecraft minecraft, ServerAddress serverAddress, - @Nullable ServerData serverData, boolean quickplay, CallbackInfo info) { + @Nullable ServerData serverData, boolean quickplay, @Nullable TransferState transferState, CallbackInfo info) { if (!NCRConfig.getClient().enableMod()) return; diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandPacket.java b/src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandSignedPacket.java similarity index 81% rename from src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandPacket.java rename to src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandSignedPacket.java index 055404d0..e115ddc5 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandPacket.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/server/MixinServerboundChatCommandSignedPacket.java @@ -8,9 +8,10 @@ import net.minecraft.commands.arguments.ArgumentSignatures; import net.minecraft.network.chat.MessageSignature; import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; +import net.minecraft.network.protocol.game.ServerboundChatCommandSignedPacket; -@Mixin(ServerboundChatCommandPacket.class) -public class MixinServerboundChatCommandPacket { +@Mixin(ServerboundChatCommandSignedPacket.class) +public class MixinServerboundChatCommandSignedPacket { /** * @reason Same as {@link MixinServerboundChatPacket#onGetSignature}. diff --git a/src/main/resources/mixins/common/nochatreports.mixins.json b/src/main/resources/mixins/common/nochatreports.mixins.json index ff8877fd..76fa5daa 100644 --- a/src/main/resources/mixins/common/nochatreports.mixins.json +++ b/src/main/resources/mixins/common/nochatreports.mixins.json @@ -10,7 +10,7 @@ "server.MixinServerCommonPacketListenerImpl", "server.MixinPlayerList", "server.MixinServerboundChatSessionUpdatePacket", - "server.MixinServerboundChatCommandPacket" + "server.MixinServerboundChatCommandSignedPacket" ], "client": [ "client.MixinOptions",