From 2098850c64f0d31e3d20b1cc3a8c281435b81519 Mon Sep 17 00:00:00 2001 From: Madis Date: Thu, 28 Jul 2022 21:20:37 +0300 Subject: An attempt --- .../nochatreports/core/NoReportsConfig.java | 48 +++++++++++++++++++--- .../mixins/client/MixinChatListener.java | 19 +++++++-- .../mixins/client/MixinGuiMessageTag.java | 2 +- .../mixins/client/MixinToastComponent.java | 2 +- 4 files changed, 59 insertions(+), 12 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java index 3aaad30..8f46afa 100644 --- a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java +++ b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java @@ -40,9 +40,11 @@ public class NoReportsConfig { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static NoReportsConfig INSTANCE; private boolean demandOnClient = true, demandOnServer = false, enableDebugLog = false, - convertToGameMessage = false, showServerSafety = true, suppressVanillaSecurityNotices = true, + convertToGameMessage = false, showServerSafety = true, hideYellowChatIndicators = true, + + hideRedChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true, alwaysHideReportButton = false, versionEasterEgg = true, disableTelemetry = true, - showReloadButton = true; + showReloadButton = true; private List whitelistedServers; private static NoReportsConfig getInstance() { @@ -177,17 +179,51 @@ public class NoReportsConfig { } /** - * @return True if vanilla's Chat Trust Status indicators and "Chat messages can't be verified" - * toast should be removed.

+ * @return True if vanilla's unsigned messages trust indicator should be removed.

* * This is true by default. * * @see MixinChatListener#onEvaluateTrustLevel + */ + + public static boolean hideRedChatIndicators() { + return getInstance().hideRedChatIndicators; + } + + /** + * @return True if vanilla's modified/hidden messages trust indicator should be removed.

+ * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + + public static boolean hideYellowChatIndicators() { + return getInstance().hideYellowChatIndicators; + } + + /** + * @return True if vanilla's modified/hidden messages trust indicator should be removed.

+ * + * This is true by default. + * + * @see com.aizistral.nochatreports.mixins.client.MixinGuiMessageTag#onSystem + */ + + public static boolean hideGrayChatIndicators() { + return getInstance().hideGrayChatIndicators; + } + + /** + * @return True if "Chat messages can't be verified" toast should be removed.

+ * + * This is true by default. + * * @see MixinToastComponent#onAddToast */ - public static boolean suppressVanillaSecurityNotices() { - return getInstance().suppressVanillaSecurityNotices; + public static boolean hideWarningToast() { + return getInstance().hideWarningToast; } /** diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java index 47e16bf..d3f0494 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java @@ -2,9 +2,9 @@ package com.aizistral.nochatreports.mixins.client; import java.time.Instant; import java.util.Base64; +import java.util.UUID; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -13,17 +13,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.aizistral.nochatreports.NoChatReports; import com.aizistral.nochatreports.core.NoReportsConfig; -import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.multiplayer.chat.ChatListener; import net.minecraft.client.multiplayer.chat.ChatTrustLevel; -import net.minecraft.network.chat.ChatSender; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.PlayerChatMessage; @Mixin(ChatListener.class) public class MixinChatListener { + @Inject(method = "isSenderLocalPlayer", at = @At("RETURN")) + private boolean isSenderLocalPlayer(UUID uuid, CallbackInfoReturnable cir) { + return cir.getReturnValue(); + } + /** * @reason Removes "Not Secure" and "Modified" statuses of chat messages. They ultimately * server no purpose but to annoy the user and scare them away from servers that actually @@ -34,9 +37,17 @@ public class MixinChatListener { @Inject(method = "evaluateTrustLevel", at = @At("HEAD"), cancellable = true) private void onEvaluateTrustLevel(PlayerChatMessage playerChatMessage, Component component, PlayerInfo playerInfo, Instant instant, CallbackInfoReturnable info) { - if (NoReportsConfig.suppressVanillaSecurityNotices()) { + + if (this.isSenderLocalPlayer(playerChatMessage.signer().profileId(), null)){ info.setReturnValue(ChatTrustLevel.SECURE); } + else { + var evaluate = ChatTrustLevel.evaluate(playerChatMessage, component, playerInfo, instant); + if((evaluate == ChatTrustLevel.NOT_SECURE || evaluate == ChatTrustLevel.BROKEN_CHAIN) && NoReportsConfig.hideRedChatIndicators()) + info.setReturnValue(ChatTrustLevel.SECURE); + if((evaluate == ChatTrustLevel.FILTERED || evaluate == ChatTrustLevel.MODIFIED) && NoReportsConfig.hideYellowChatIndicators()) + info.setReturnValue(ChatTrustLevel.SECURE); + } // Debug never dies if (NoReportsConfig.isDebugLogEnabled()) { diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java index cac9460..b65706c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java @@ -21,7 +21,7 @@ public class MixinGuiMessageTag { @Inject(method = "system", at = @At("HEAD"), cancellable = true) private static void onSystem(CallbackInfoReturnable info) { - if (NoReportsConfig.suppressVanillaSecurityNotices()) { + if (NoReportsConfig.hideGrayChatIndicators()) { info.setReturnValue(null); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java index 239f5df..36cfe7e 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java @@ -17,7 +17,7 @@ public class MixinToastComponent { @Inject(method = "addToast", at = @At("HEAD"), cancellable = true) private void onAddToast(Toast toast, CallbackInfo info) { - if (NoReportsConfig.suppressVanillaSecurityNotices()) + if (NoReportsConfig.hideWarningToast()) if (toast instanceof SystemToast sys && sys.getToken() == SystemToastIds.UNSECURE_SERVER_WARNING) { info.cancel(); } -- cgit v1.2.3