summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorAizistral2026-11-18 15:15:55 +0100
committerAizistral2026-11-18 15:15:55 +0100
commit86089b97082db3e071dd7c4f5bce22fc0a20a7cd (patch)
treee2485c2d7197a7eda614c295ea2cfa8820ea1681 /src/main/java
parent72a4e0aba81820b12fe245c476a3ca9e81aaf415 (diff)
Discontinue chat encryption support
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/NCRClient.java2
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/config/ClothConfigIntegration.java18
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/config/NCRConfig.java8
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/config/NCRConfigEncryption.java189
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java78
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java9
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryption.java25
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryptor.java43
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryption.java25
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryptor.java30
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryption.java93
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryptor.java113
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryption.java25
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryptor.java37
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryption.java56
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryptor.java70
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/Encryption.java59
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/encryption/Encryptor.java182
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/gui/EncryptionButton.java40
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java283
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/gui/EncryptionWarningScreen.java43
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/gui/UnsafeServerScreen.java6
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java75
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatListener.java8
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatScreen.java53
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinGuiMessageTagIcon.java47
26 files changed, 11 insertions, 1606 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/common/NCRClient.java b/src/main/java/com/aizistral/nochatreports/common/NCRClient.java
index 524cfe0..7f5d177 100644
--- a/src/main/java/com/aizistral/nochatreports/common/NCRClient.java
+++ b/src/main/java/com/aizistral/nochatreports/common/NCRClient.java
@@ -92,7 +92,7 @@ public class NCRClient {
chatScr.init(mc, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight());
}
- chatScr.handleChatInput(NCRConfig.getEncryption().getLastMessage(), false);
+ chatScr.handleChatInput(ServerSafetyState.getLastMessage(), false);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/common/config/ClothConfigIntegration.java b/src/main/java/com/aizistral/nochatreports/common/config/ClothConfigIntegration.java
index 96bce48..d65d191 100644
--- a/src/main/java/com/aizistral/nochatreports/common/config/ClothConfigIntegration.java
+++ b/src/main/java/com/aizistral/nochatreports/common/config/ClothConfigIntegration.java
@@ -156,24 +156,6 @@ public final class ClothConfigIntegration {
.setSaveConsumer(newValue -> NCRConfig.getClient().verifiedIconOffsetY = newValue)
.build());
- // Warning for showEncryptionButton
- client.addEntry(entryBuilder.startTextDescription(Component.translatable("gui.NoChatReports.showEncryptionButtonWarning"))
- .build());
-
- // Set an option for showEncryptionButton
- client.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showEncryptionButton"), NCRConfig.getEncryption().showEncryptionButton)
- .setDefaultValue(true)
- .setTooltip(makeTooltip("option.NoChatReports.showEncryptionButton.tooltip"))
- .setSaveConsumer(newValue -> NCRConfig.getEncryption().showEncryptionButton = newValue)
- .build());
-
- // Set an option for showEncryptionIndicators
- client.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showEncryptionIndicators"), NCRConfig.getEncryption().showEncryptionIndicators)
- .setDefaultValue(true)
- .setTooltip(makeTooltip("option.NoChatReports.showEncryptionIndicators.tooltip"))
- .setSaveConsumer(newValue -> NCRConfig.getEncryption().showEncryptionIndicators = newValue)
- .build());
-
// Set an option for showServerSafety
client.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showServerSafety"), NCRConfig.getClient().showServerSafety)
.setDefaultValue(true)
diff --git a/src/main/java/com/aizistral/nochatreports/common/config/NCRConfig.java b/src/main/java/com/aizistral/nochatreports/common/config/NCRConfig.java
index 3074ad8..14289d4 100644
--- a/src/main/java/com/aizistral/nochatreports/common/config/NCRConfig.java
+++ b/src/main/java/com/aizistral/nochatreports/common/config/NCRConfig.java
@@ -14,7 +14,6 @@ public final class NCRConfig {
private static NCRConfigCommon common = null;
private static NCRConfigClient client = null;
private static NCRServerPreferences serverPreferences = null;
- private static NCRConfigEncryption encryption = null;
private NCRConfig() {
throw new IllegalStateException("Can't touch this");
@@ -34,11 +33,6 @@ public final class NCRConfig {
return checkLoaded(() -> serverPreferences);
}
- @Environment(EnvType.CLIENT)
- public static NCRConfigEncryption getEncryption() {
- return checkLoaded(() -> encryption);
- }
-
private static <T extends JSONConfig> T checkLoaded(Supplier<T> config) {
if (config.get() == null) {
load();
@@ -53,7 +47,6 @@ public final class NCRConfig {
if (NCRCore.getProvider().isOnClient()) {
client = JSONConfig.loadConfig(NCRConfigClient.class, NCRConfigClient::new, NCRConfigClient.FILE_NAME);
serverPreferences = JSONConfig.loadConfig(NCRServerPreferences.class, NCRServerPreferences::new, NCRServerPreferences.FILE_NAME);
- encryption = JSONConfig.loadConfig(NCRConfigEncryption.class, NCRConfigEncryption::new, NCRConfigEncryption.FILE_NAME);
}
save();
@@ -65,7 +58,6 @@ public final class NCRConfig {
if (NCRCore.getProvider().isOnClient()) {
checkLoaded(() -> client).saveFile();
checkLoaded(() -> serverPreferences).saveFile();
- checkLoaded(() -> encryption).saveFile();
}
Path readme = JSONConfig.CONFIG_DIR.resolve("NoChatReports/README.md");
diff --git a/src/main/java/com/aizistral/nochatreports/common/config/NCRConfigEncryption.java b/src/main/java/com/aizistral/nochatreports/common/config/NCRConfigEncryption.java
deleted file mode 100644
index 0ef0751..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/config/NCRConfigEncryption.java
+++ /dev/null
@@ -1,189 +0,0 @@
-package com.aizistral.nochatreports.common.config;
-
-import java.security.InvalidKeyException;
-import java.util.List;
-import java.util.Optional;
-
-import com.aizistral.nochatreports.common.encryption.Encryption;
-import com.aizistral.nochatreports.common.encryption.Encryptor;
-
-public class NCRConfigEncryption extends JSONConfig {
- protected static final String FILE_NAME = "NoChatReports/NCR-Encryption.json";
- protected boolean skipWarning = false, enableEncryption = false, encryptPublic = true,
- showEncryptionButton = true, showEncryptionIndicators = true;
- protected String encryptionKey = Encryption.AES_CFB8.getDefaultKey(), encryptionPassphrase = "",
- algorithmName = Encryption.AES_CFB8.getName();
- protected List<String> encryptableCommands = List.of("msg:1", "w:1", "whisper:1", "tell:1", "r:0", "dm:1",
- "me:0", "m:1", "t:1", "pm:1", "emsg:1", "epm:1", "etell:1", "ewhisper:1", "message:1", "reply:0");
- private transient Encryption algorithm;
- private transient boolean isValid = false;
- private transient String lastMessage = "???";
-
- protected NCRConfigEncryption() {
- super(FILE_NAME);
- }
-
- @Override
- public NCRConfigEncryption getDefault() {
- return new NCRConfigEncryption();
- }
-
- @Override
- protected void uponLoad() {
- this.algorithm = Encryption.getRegistered().stream().filter(e -> e.getName().equals(this.algorithmName))
- .findFirst().orElse(Encryption.AES_CFB8);
- this.validate();
- }
-
- private void validate() {
- this.isValid = this.algorithm.validateKey(this.encryptionKey);
- }
-
- public void toggleEncryption() {
- this.enableEncryption = !this.enableEncryption;
- this.saveFile();
- }
-
- public void setAlgorithm(Encryption encryption) {
- this.algorithm = encryption;
- this.algorithmName = encryption.getName();
- this.validate();
- this.saveFile();
- }
-
- public void setEncryptionKey(String key) {
- this.encryptionKey = key;
- this.validate();
- this.saveFile();
- }
-
- public void setEncryptionPassphrase(String pass) {
- this.encryptionPassphrase = pass;
- this.saveFile();
- }
-
- public void setEncryptPublic(boolean encryptPublic) {
- this.encryptPublic = encryptPublic;
- this.saveFile();
- }
-
- public void disableWarning() {
- this.skipWarning = true;
- }
-
- public boolean isWarningDisabled() {
- return this.skipWarning;
- }
-
- public boolean isEnabled() {
- return this.enableEncryption;
- }
-
- public String getEncryptionKey() {
- return this.encryptionKey;
- }
-
- public String getEncryptionPassphrase() {
- return this.encryptionPassphrase;
- }
-
- public boolean isValid() {
- return this.isValid;
- }
-
- public boolean shouldEncryptPublic() {
- return this.encryptPublic;
- }
-
- public boolean showEncryptionIndicators() {
- return this.showEncryptionIndicators;
- }
-
- public boolean isEnabledAndValid() {
- return this.isEnabled() && this.isValid();
- }
-
- public Encryption getAlgorithm() {
- return this.algorithm;
- }
-
- public boolean shouldEncrypt(String message) {
- return this.isEnabledAndValid() && this.getEncryptionStartIndex(message) != -1;
- }
-
- public boolean showEncryptionButton() {
- return this.showEncryptionButton;
- }
-
- public int getEncryptionStartIndex(String message) {
- if (!message.startsWith("/"))
- return this.encryptPublic ? 0 : -1;
- else {
- for (String rule : this.encryptableCommands) {
- String[] splat = rule.split(":");
-
- if (splat.length != 2)
- throw new IllegalArgumentException("Invalid encryptable command definition: " + rule
- + ", in file: " + FILE_NAME);
-
- String cmd = splat[0];
- String args = splat[1];
- int argnum = 0;
-
- try {
- argnum = Integer.valueOf(args);
- } catch (NumberFormatException ex) {
- throw new IllegalArgumentException("Invalid encryptable command definition: " + rule
- + ", in file: " + FILE_NAME);
- }
-
- String prefix = "/(" + cmd + "|.*:" + cmd + ") .*";
- if (message.matches(prefix)) {
- splat = message.split(" ", 2);
- char[] array = splat[1].toCharArray();
-
- for (int i = 0; i < array.length; i++) {
- char ch = array[i];
- if (argnum > 0) {
- if (ch == ' ') {
- argnum--;
- }
- continue;
- } else {
- int index = i + splat[0].length() + 1;
- return index < message.length() ? index : -1;
- }
- }
- } else {
- continue;
- }
- }
-
- return -1;
- }
- }
-
- public void setLastMessage(String lastMessage) {
- this.lastMessage = lastMessage;
- }
-
- public String getLastMessage() {
- return this.lastMessage;
- }
-
- /**
- * @return Chat encryptor, if encryption is enabled and user specified valid key in config.
- */
-
- public Optional<Encryptor<?>> getEncryptor() {
- if (!this.isEnabledAndValid())
- return Optional.empty();
-
- try {
- return Optional.of(this.algorithm.getProcessor(this.encryptionKey));
- } catch (InvalidKeyException ex) {
- throw new RuntimeException(ex); // shouldn't happen due to prior validation
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java b/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java
deleted file mode 100644
index d770525..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/core/EncryptionUtil.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.aizistral.nochatreports.common.core;
-
-import java.util.Optional;
-
-import com.aizistral.nochatreports.common.NCRCore;
-import com.aizistral.nochatreports.common.config.NCRConfig;
-import com.aizistral.nochatreports.common.encryption.Encryptor;
-
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.ComponentContents;
-import net.minecraft.network.chat.MutableComponent;
-import net.minecraft.network.chat.contents.LiteralContents;
-import net.minecraft.network.chat.contents.TranslatableContents;
-
-public class EncryptionUtil {
-
- public static Optional<Component> tryDecrypt(Component component) {
- var optional = NCRConfig.getEncryption().getEncryptor();
- if (optional.isEmpty())
- return Optional.empty();
-
- Encryptor<?> encryption = optional.get();
- Component copy = recreate(component);
- ComponentContents contents = copy.getContents();
-
- return Optional.ofNullable(tryDecrypt(copy, encryption) ? copy : null);
- }
-
- public static boolean tryDecrypt(Component component, Encryptor<?> encryptor) {
- boolean decryptedSiblings = false;
- for (Component sibling : component.getSiblings()) {
- if (tryDecrypt(sibling, encryptor)) {
- decryptedSiblings = true;
- }
- }
-
- if (component.getContents() instanceof LiteralContents literal) {
- var decrypted = tryDecrypt(literal.text(), encryptor);
-
- if (decrypted.isPresent()) {
- ((MutableComponent)component).contents = new LiteralContents(decrypted.get());
- return true;
- }
- } else if (component.getContents() instanceof TranslatableContents translatable) {
- for (Object arg : translatable.args) {
- if (arg instanceof MutableComponent mutable) {
- if (tryDecrypt(mutable, encryptor)) {
- decryptedSiblings = true;
- }
- }
- }
- }
-
- return decryptedSiblings;
- }
-
- public static Optional<String> tryDecrypt(String message, Encryptor<?> encryptor) {
- try {
- String messageCopy = message.replace(':', ' ');
- String[] splat = messageCopy.contains(" ") ? messageCopy.split(" ") : new String[] { messageCopy };
- String decryptable = splat[splat.length-1];
-
- String decrypted = encryptor.decrypt(decryptable);
-
- if (decrypted.startsWith("#%"))
- return Optional.of(message.substring(0, message.length() - decryptable.length()) + decrypted.substring(2, decrypted.length()));
- else
- return Optional.empty();
- } catch (Exception ex) {
- return Optional.empty();
- }
- }
-
- public static Component recreate(Component component) {
- return Component.Serializer.fromJson(Component.Serializer.toStableJson(component));
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java
index 366811f..4b056ff 100644
--- a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java
+++ b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java
@@ -26,6 +26,7 @@ public final class ServerSafetyState {
private static final AtomicBoolean ALLOW_CHAT_SIGNING = new AtomicBoolean(false);
private volatile static ServerSafetyLevel current = ServerSafetyLevel.UNDEFINED;
private volatile static ServerAddress lastServer = null;
+ private volatile static String lastMessage = "???";
public static void updateCurrent(ServerSafetyLevel level) {
current = level;
@@ -83,6 +84,14 @@ public final class ServerSafetyState {
lastServer = address;
}
+ public static String getLastMessage() {
+ return lastMessage;
+ }
+
+ public static void setLastMessage(String message) {
+ lastMessage = message;
+ }
+
public static void scheduleResetAction(Runnable action) {
RESET_ACTIONS.add(action);
}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryption.java
deleted file mode 100644
index 9908ec8..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryption.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-
-public class AESCFB8Encryption extends AESEncryption {
-
- protected AESCFB8Encryption() {
- super("CFB8", "NoPadding", true);
- }
-
- @Override
- public AESCFB8Encryptor getProcessor(String key) throws InvalidKeyException {
- return new AESCFB8Encryptor(key);
- }
-
- @Override
- public AESCFB8Encryptor getRandomProcessor() {
- try {
- return this.getProcessor(this.getRandomKey());
- } catch (InvalidKeyException ex) {
- throw new RuntimeException(ex);
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryptor.java
deleted file mode 100644
index 682cb91..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESCFB8Encryptor.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.nio.ByteBuffer;
-import java.security.InvalidKeyException;
-import java.security.spec.AlgorithmParameterSpec;
-import java.util.Random;
-
-import javax.crypto.SecretKey;
-import javax.crypto.spec.IvParameterSpec;
-
-import net.minecraft.util.Tuple;
-
-public class AESCFB8Encryptor extends AESEncryptor<AESCFB8Encryption> {
-
- protected AESCFB8Encryptor(String key) throws InvalidKeyException {
- super(key, Encryption.AES_CFB8);
- }
-
- protected AESCFB8Encryptor(SecretKey key, String mode, String padding, boolean iv) throws InvalidKeyException {
- super(key, Encryption.AES_CFB8);
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> generateIV() throws UnsupportedOperationException {
- long nonce = RANDOM.nextLong();
- byte[] iv = new byte[16];
- new Random(nonce).nextBytes(iv);
- return new Tuple<>(new IvParameterSpec(iv), ByteBuffer.allocate(8).putLong(nonce).array());
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> splitIV(byte[] message) throws UnsupportedOperationException {
- ByteBuffer buffer = ByteBuffer.wrap(message);
- int size = buffer.capacity();
- long nonce = buffer.getLong();
- byte[] encrypted = new byte[size - 8];
- buffer.get(encrypted);
- byte[] iv = new byte[16];
- new Random(nonce).nextBytes(iv);
- return new Tuple<>(new IvParameterSpec(iv), encrypted);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryption.java
deleted file mode 100644
index 1c12c51..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryption.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-
-public class AESECBEncryption extends AESEncryption {
-
- protected AESECBEncryption() {
- super("ECB", "PKCS5Padding", false);
- }
-
- @Override
- public AESECBEncryptor getProcessor(String key) throws InvalidKeyException {
- return new AESECBEncryptor(key);
- }
-
- @Override
- public AESECBEncryptor getRandomProcessor() {
- try {
- return this.getProcessor(this.getRandomKey());
- } catch (InvalidKeyException ex) {
- throw new RuntimeException(ex);
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryptor.java
deleted file mode 100644
index aa1f864..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESECBEncryptor.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-import java.security.spec.AlgorithmParameterSpec;
-
-import javax.crypto.SecretKey;
-
-import net.minecraft.util.Tuple;
-
-public class AESECBEncryptor extends AESEncryptor<AESECBEncryption> {
-
- protected AESECBEncryptor(String key) throws InvalidKeyException {
- super(key, Encryption.AES_ECB);
- }
-
- protected AESECBEncryptor(SecretKey key, String mode, String padding, boolean iv) throws InvalidKeyException {
- super(key, Encryption.AES_ECB);
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> generateIV() throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> splitIV(byte[] message) throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryption.java
deleted file mode 100644
index 91cd92a..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryption.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.util.Random;
-
-import javax.crypto.KeyGenerator;
-import javax.crypto.SecretKey;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import net.minecraft.util.StringUtil;
-
-public abstract class AESEncryption extends Encryption {
- private final String mode, padding;
- private final boolean requiresIV;
-
- protected AESEncryption(String mode, String padding, boolean requiresIV) {
- super("aes_" + mode.toLowerCase() + "_base64", "AES/" + mode + "+Base64");
- this.mode = mode;
- this.padding = padding;
- this.requiresIV = requiresIV;
- }
-
- @Override
- public String getRandomKey() {
- try {
- KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
- keyGenerator.init(128);
- SecretKey key = keyGenerator.generateKey();
-
- return BASE64_ENCODER.encodeToString(key.getEncoded());
- } catch (NoSuchAlgorithmException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public String getDefaultKey() {
- return "blfrngArk3chG6wzncOZ5A==";
- }
-
- @Override
- public boolean supportsPassphrases() {
- return true;
- }
-
- @Override
- public String getPassphraseKey(String passphrase) {
- try {
- byte[] salt = new byte[16];
- new Random(1738389128127L).nextBytes(salt);
-
- KeySpec spec = new PBEKeySpec(passphrase.toCharArray(), salt, 65536, 128); // AES-128
- SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
- byte[] key = factory.generateSecret(spec).getEncoded();
-
- return BASE64_ENCODER.encodeToString(new SecretKeySpec(key, "AES").getEncoded());
- } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public boolean validateKey(String key) {
- if (StringUtil.isNullOrEmpty(key))
- return false;
-
- try {
- this.getProcessor(key);
- } catch (InvalidKeyException ex) {
- return false;
- }
-
- return true;
- }
-
- public String getMode() {
- return this.mode;
- }
-
- public String getPadding() {
- return this.padding;
- }
-
- public boolean requiresIV() {
- return this.requiresIV;
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryptor.java
deleted file mode 100644
index 7e71d91..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESEncryptor.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import static javax.crypto.Cipher.DECRYPT_MODE;
-import static javax.crypto.Cipher.ENCRYPT_MODE;
-
-import java.nio.ByteBuffer;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.spec.AlgorithmParameterSpec;
-
-import javax.crypto.AEADBadTagException;
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-
-import net.minecraft.util.Tuple;
-
-public abstract class AESEncryptor<T extends AESEncryption> extends Encryptor<T> {
- private final T encryption;
- private final SecretKey key;
- private final Cipher encryptor, decryptor;
- private final boolean useIV;
-
- protected AESEncryptor(String key, T encryption) throws InvalidKeyException {
- this(new SecretKeySpec(decodeBinaryKey(key), "AES"), encryption);
- }
-
- protected AESEncryptor(SecretKey key, T encryption) throws InvalidKeyException {
- this.encryption = encryption;
- this.useIV = encryption.requiresIV();
- String mode = encryption.getMode();
- String padding = encryption.getPadding();
-
- try {
- this.key = key;
-
- Cipher encryptor = Cipher.getInstance(this.key.getAlgorithm() + "/" + mode + "/" + padding);
- if (this.useIV) {
- encryptor.init(ENCRYPT_MODE, this.key, this.generateIV().getA());
- } else {
- encryptor.init(ENCRYPT_MODE, this.key);
-
- }
- this.encryptor = encryptor;
-
- Cipher decryptor = Cipher.getInstance(this.key.getAlgorithm() + "/" + mode + "/" + padding);
- if (this.useIV) {
- decryptor.init(DECRYPT_MODE, this.key, this.generateIV().getA());
- } else {
- decryptor.init(DECRYPT_MODE, this.key);
- }
- this.decryptor = decryptor;
- } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) {
- throw new RuntimeException(ex);
- } catch (InvalidAlgorithmParameterException ex) {
- throw new InvalidKeyException(ex);
- }
- }
-
- @Override
- public String encrypt(String message) {
- try {
- if (this.useIV) {
- var tuple = this.generateIV();
-
- this.encryptor.init(ENCRYPT_MODE, this.key, tuple.getA());
- byte[] encrypted = this.encryptor.doFinal(toBytes(message));
-
- return encodeBase64R(ByteBuffer.allocate(encrypted.length + tuple.getB().length).put(tuple.getB())
- .put(encrypted).array());
- } else
- return encodeBase64R(this.encryptor.doFinal(toBytes(message)));
- } catch (IllegalBlockSizeException | BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public String decrypt(String message) {
- try {
- if (this.useIV) {
- var tuple = this.splitIV(decodeBase64RBytes(message));
-
- this.decryptor.init(DECRYPT_MODE, this.key, tuple.getA());
- return fromBytes(this.decryptor.doFinal(tuple.getB()));
- } else
- return fromBytes(this.decryptor.doFinal(decodeBase64RBytes(message)));
- } catch (AEADBadTagException ex) {
- return "???";
- } catch (IllegalBlockSizeException | BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public String getKey() {
- return encodeBinaryKey(this.key.getEncoded());
- }
-
- @Override
- public T getAlgorithm() {
- return this.encryption;
- }
-
- protected abstract Tuple<AlgorithmParameterSpec, byte[]> generateIV() throws UnsupportedOperationException;
-
- protected abstract Tuple<AlgorithmParameterSpec, byte[]> splitIV(byte[] message) throws UnsupportedOperationException;
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryption.java
deleted file mode 100644
index d94b6fc..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryption.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-
-public class AESGCMEncryption extends AESEncryption {
-
- protected AESGCMEncryption() {
- super("GCM", "NoPadding", true);
- }
-
- @Override
- public AESGCMEncryptor getProcessor(String key) throws InvalidKeyException {
- return new AESGCMEncryptor(key);
- }
-
- @Override
- public AESGCMEncryptor getRandomProcessor() {
- try {
- return this.getProcessor(this.getRandomKey());
- } catch (InvalidKeyException ex) {
- throw new RuntimeException(ex);
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryptor.java
deleted file mode 100644
index f91a0ab..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/AESGCMEncryptor.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.nio.ByteBuffer;
-import java.security.InvalidKeyException;
-import java.security.spec.AlgorithmParameterSpec;
-
-import javax.crypto.SecretKey;
-import javax.crypto.spec.GCMParameterSpec;
-
-import net.minecraft.util.Tuple;
-
-public class AESGCMEncryptor extends AESEncryptor<AESGCMEncryption> {
-
- protected AESGCMEncryptor(String key) throws InvalidKeyException {
- super(key, Encryption.AES_GCM);
- }
-
- protected AESGCMEncryptor(SecretKey key) throws InvalidKeyException {
- super(key, Encryption.AES_GCM);
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> generateIV() throws UnsupportedOperationException {
- byte[] iv = new byte[12];
- RANDOM.nextBytes(iv);
- return new Tuple<>(new GCMParameterSpec(96, iv), iv);
- }
-
- @Override
- protected Tuple<AlgorithmParameterSpec, byte[]> splitIV(byte[] message) throws UnsupportedOperationException {
- byte[] iv = new byte[12];
- byte[] msg = new byte[message.length - 12];
- ByteBuffer.wrap(message).get(iv).get(msg);
- return new Tuple<>(new GCMParameterSpec(96, iv), msg);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryption.java
deleted file mode 100644
index 27a1261..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryption.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-import java.security.SecureRandom;
-
-public class CaesarEncryption extends Encryption {
-
- protected CaesarEncryption() {
- super("caesar", "Caesar");
- }
-
- @Override
- public String getRandomKey() {
- return String.valueOf(1 + new SecureRandom().nextInt(1024));
- }
-
- @Override
- public String getDefaultKey() {
- return "3";
- }
-
- @Override
- public boolean supportsPassphrases() {
- return false;
- }
-
- @Override
- public String getPassphraseKey(String passphrase) throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean validateKey(String key) {
- try {
- int value = Integer.valueOf(key);
- return value > 0 && value < 1025;
- } catch (NumberFormatException ex) {
- return false;
- }
- }
-
- @Override
- public CaesarEncryptor getProcessor(String key) throws InvalidKeyException {
- return new CaesarEncryptor(key);
- }
-
- @Override
- public CaesarEncryptor getRandomProcessor() {
- try {
- return this.getProcessor(this.getRandomKey());
- } catch (InvalidKeyException ex) {
- throw new RuntimeException(ex);
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryptor.java
deleted file mode 100644
index 7eb8010..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/CaesarEncryptor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-
-public class CaesarEncryptor extends Encryptor<CaesarEncryption> {
- private static final char PARAGRAPH = '\u00a7', PARAGRAPH_PLACEHOLDER = '\uffef',
- DELETE = '\u007f', DELETE_PLACEHOLDER = '\ufff0';
- private final int shift;
-
- protected CaesarEncryptor(int shift) throws InvalidKeyException {
- if (!Encryption.CAESAR.validateKey(String.valueOf(shift)))
- throw new InvalidKeyException();
- this.shift = shift;
- }
-
- protected CaesarEncryptor(String key) throws InvalidKeyException {
- this.shift = fromString(key);
- }
-
- @Override
- public String encrypt(String message) {
- char[] chars = ensureUTF8(message).toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- chars[i] = (char) (chars[i] + this.shift);
-
- if (chars[i] == PARAGRAPH) {
- chars[i] = PARAGRAPH_PLACEHOLDER;
- } else if (chars[i] == DELETE) {
- chars[i] = DELETE_PLACEHOLDER;
- }
- }
-
- return new String(chars);
- }
-
- @Override
- public String decrypt(String message) {
- char[] chars = ensureUTF8(message).toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- if (chars[i] == PARAGRAPH_PLACEHOLDER) {
- chars[i] = PARAGRAPH;
- } else if (chars[i] == DELETE_PLACEHOLDER) {
- chars[i] = DELETE;
- }
-
- chars[i] = (char) (chars[i] - this.shift);
- }
-
- return new String(chars);
- }
-
- @Override
- public CaesarEncryption getAlgorithm() {
- return Encryption.CAESAR;
- }
-
- @Override
- public String getKey() {
- return String.valueOf(this.shift);
- }
-
- private static int fromString(String key) throws InvalidKeyException {
- if (!Encryption.CAESAR.validateKey(key))
- throw new InvalidKeyException(key);
- return Integer.valueOf(key);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/Encryption.java b/src/main/java/com/aizistral/nochatreports/common/encryption/Encryption.java
deleted file mode 100644
index 259d89d..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/Encryption.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.security.InvalidKeyException;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.List;
-
-public abstract class Encryption {
- private static final List<Encryption> REGISTERED = new ArrayList<>();
- protected static final Base64.Encoder BASE64_ENCODER = Base64.getEncoder();
- protected static final Base64.Decoder BASE64_DECODER = Base64.getDecoder();
-
- public static final AESCFB8Encryption AES_CFB8 = new AESCFB8Encryption();
- public static final AESGCMEncryption AES_GCM = new AESGCMEncryption();
- public static final AESECBEncryption AES_ECB = new AESECBEncryption();
- public static final CaesarEncryption CAESAR = new CaesarEncryption();
-
- private final String id, name;
-
- protected Encryption(String id, String name) {
- this.id = id;
- this.name = name;
-
- if (REGISTERED.stream().filter(e -> e.getID().equals(id) || e.getName().equals(name))
- .findAny().isPresent())
- throw new IllegalStateException("Duplicate encryption algorithm registered! ID: " + this.getID() +
- ", Name: " + this.getName());
-
- REGISTERED.add(this);
- }
-
- public String getID() {
- return this.id;
- }
-
- public String getName() {
- return this.name;
- }
-
- public abstract String getRandomKey();
-
- public abstract String getDefaultKey();
-
- public abstract boolean supportsPassphrases();
-
- public abstract String getPassphraseKey(String passphrase) throws UnsupportedOperationException;
-
- public abstract boolean validateKey(String key);
-
- public abstract Encryptor<?> getProcessor(String key) throws InvalidKeyException;
-
- public abstract Encryptor<?> getRandomProcessor();
-
- public static List<Encryption> getRegistered() {
- return Collections.unmodifiableList(REGISTERED);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/encryption/Encryptor.java b/src/main/java/com/aizistral/nochatreports/common/encryption/Encryptor.java
deleted file mode 100644
index 61718a4..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/encryption/Encryptor.java
+++ /dev/null
@@ -1,182 +0,0 @@
-package com.aizistral.nochatreports.common.encryption;
-
-import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.SecureRandom;
-import java.util.Arrays;
-
-import it.unimi.dsi.fastutil.chars.Char2CharArrayMap;
-import it.unimi.dsi.fastutil.chars.Char2CharMap;
-import it.unimi.dsi.fastutil.chars.Char2CharMaps;
-
-public abstract class Encryptor<T extends Encryption> {
- protected static final SecureRandom RANDOM = new SecureRandom();
- protected static final Char2CharMap BASE64R_SHIFTS = createBase64RShifts();
- protected static final Char2CharMap BASE64R_SHIFTS_REVERSE = createBase64RShiftsReverse();
-
- protected Encryptor() {
- // NO-OP
- }
-
- public abstract String encrypt(String message);
-
- public abstract String decrypt(String message);
-
- public abstract T getAlgorithm();
-
- public abstract String getKey();
-
- protected static String shiftBase64R(String string) {
- char[] chars = ensureUTF8(string).toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- chars[i] = BASE64R_SHIFTS.get(chars[i]);
- }
-
- return new String(chars);
- }
-
- protected static String unshiftBase64R(String string) {
- char[] chars = ensureUTF8(string).toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- chars[i] = BASE64R_SHIFTS_REVERSE.get(chars[i]);
- }
-
- return new String(chars);
- }
-
- protected static byte[] toBytes(String string) {
- return string.getBytes(StandardCharsets.UTF_8);
- }
-
- protected static String fromBytes(byte[] bytes) {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-
- protected static String ensureUTF8(String string) {
- return fromBytes(toBytes(string));
- }
-
- protected static String encodeBase64R(String string) {
- return encodeBase64R(toBytes(string));
- }
-
- protected static String encodeBase64R(byte[] bytes) {
- return shiftBase64R(fromBytes(Encryption.BASE64_ENCODER.encode(bytes)));
- }
-
- protected static byte[] encodeBase64RBytes(String string) {
- return toBytes(encodeBase64R(toBytes(string)));
- }
-
- protected static String decodeBase64R(String string) {
- return fromBytes(decodeBase64RBytes(string));
- }
-
- protected static byte[] decodeBase64RBytes(String string) {
- return Encryption.BASE64_DECODER.decode(toBytes(unshiftBase64R(string)));
- }
-
- protected static String encodeBinaryKey(byte[] key) {
- return fromBytes(Encryption.BASE64_ENCODER.encode(key));
- }
-
- protected static byte[] decodeBinaryKey(String key) throws InvalidKeyException {
- try {
- return Encryption.BASE64_DECODER.decode(toBytes(key));
- } catch (Exception ex) {
- throw new InvalidKeyException(ex);
- }
- }
-
- protected static byte[] mergeBytes(byte[] array1, byte[] array2) {
- byte[] result = Arrays.copyOf(array1, array1.length + array2.length);
- System.arraycopy(array2, 0, result, array1.length, array2.length);
- return result;
- }
-
- private static Char2CharMap createBase64RShiftsReverse() {
- Char2CharMap map = createBase64RShifts();
- Char2CharMap reverse = new Char2CharArrayMap(64);
-
- for (char ch : map.keySet()) {
- reverse.put(map.get(ch), ch);
- }
-
- return Char2CharMaps.unmodifiable(reverse);
- }
-
- private static Char2CharMap createBase64RShifts() {
- Char2CharMap map = new Char2CharArrayMap(64);
-
- map.put('A', '!');
- map.put('B', '"');
- map.put('C', '#');
- map.put('D', '$');
- map.put('E', '%');
- map.put('F', '¼');
- map.put('G', '\'');
- map.put('H', '(');
- map.put('I', ')');
- map.put('J', ',');
- map.put('K', '-');
- map.put('L', '.');
- map.put('M', ':');
- map.put('N', ';');
- map.put('O', '<');
- map.put('P', '=');
- map.put('Q', '>');
- map.put('R', '?');
- map.put('S', '@');
- map.put('T', '[');
- map.put('U', '\\');
- map.put('V', ']');
- map.put('W', '^');
- map.put('X', '_');
- map.put('Y', '`');
- map.put('Z', '{');
- map.put('a', '|');
- map.put('b', '}');
- map.put('c', '~');
- map.put('d', '¡');
- map.put('e', '¢');
- map.put('f', '£');
- map.put('g', '¤');
- map.put('h', '¥');
- map.put('i', '¦');
- map.put('j', '¨');
- map.put('k', '©');
- map.put('l', 'ª');
- map.put('m', '«');
- map.put('n', '¬');
- map.put('o', '®');
- map.put('p', '¯');
- map.put('q', '°');
- map.put('r', '±');
- map.put('s', '²');
- map.put('t', '³');
- map.put('u', 'µ');
- map.put('v', '¶');
- map.put('w', '·');
- map.put('x', '×');
- map.put('y', '¹');
- map.put('z', 'º');
- map.put('0', '0');
- map.put('1', '1');
- map.put('2', '2');
- map.put('3', '3');
- map.put('4', '4');
- map.put('5', '5');
- map.put('6', '6');
- map.put('7', '7');
- map.put('8', '8');
- map.put('9', '9');
- map.put('+', '+');
- map.put('/', '»');
- map.put('=', '¿');
-
- return Char2CharMaps.unmodifiable(map);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionButton.java b/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionButton.java
deleted file mode 100644
index 44d286f..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionButton.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.aizistral.nochatreports.common.gui;
-
-import com.aizistral.nochatreports.common.config.NCRConfig;
-
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
-
-public class EncryptionButton extends AdvancedImageButton {
-
- public EncryptionButton(int x, int y, int xSize, int ySize, int xTexStart, int yTexStart, int yStateDiff,
- ResourceLocation texture, int textureWidth, int textureHeight, OnPress onPress, Component name, Screen parent) {
- super(x, y, xSize, ySize, xTexStart, yTexStart, yStateDiff, texture, textureWidth, textureHeight, onPress, name, parent);
- }
-
- @Override
- public boolean mouseClicked(double x, double y, int i) {
- if (!this.active || !this.visible)
- return false;
-
- if (i == 1 && this.clicked(x, y)) {
- this.playDownSound(Minecraft.getInstance().getSoundManager());
- this.openEncryptionConfig();
- return true;
- }
-
- return super.mouseClicked(x, y, i);
- }
-
- public void openEncryptionConfig() {
- if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled()
- && !NCRConfig.getEncryption().isEnabledAndValid()) {
- Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this.parent));
- } else {
- Minecraft.getInstance().setScreen(new EncryptionConfigScreen(this.parent));
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java b/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java
deleted file mode 100644
index c0cdb47..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package com.aizistral.nochatreports.common.gui;
-
-import java.util.Objects;
-
-import com.aizistral.nochatreports.common.config.NCRConfig;
-import com.aizistral.nochatreports.common.config.NCRConfigEncryption;
-import com.aizistral.nochatreports.common.encryption.Encryption;
-import com.mojang.blaze3d.systems.RenderSystem;
-import com.mojang.blaze3d.vertex.PoseStack;
-
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.client.gui.Font;
-import net.minecraft.client.gui.components.Button;
-import net.minecraft.client.gui.components.Checkbox;
-import net.minecraft.client.gui.components.CycleButton;
-import net.minecraft.client.gui.components.EditBox;
-import net.minecraft.client.gui.components.ImageButton;
-import net.minecraft.client.gui.components.MultiLineLabel;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.CommonComponents;
-import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraft.util.StringUtil;
-
-@Environment(EnvType.CLIENT)
-public class EncryptionConfigScreen extends Screen {
- private static final ResourceLocation ENCRYPTION_ICONS = new ResourceLocation("nochatreports", "textures/gui/encryption_gui_icons.png");
- private static final Component HEADER = Component.translatable("gui.nochatreports.encryption_config.header");
- private static final Component KEY_DESC = Component.translatable("gui.nochatreports.encryption_config.key_desc");
- private static final Component PASS_DESC = Component.translatable("gui.nochatreports.encryption_config.passphrase_desc");
- private static final Component VALIDATION_OK = Component.translatable("gui.nochatreports.encryption_config.validation_ok");
- private static final Component VALIDATION_FAILED = Component.translatable("gui.nochatreports.encryption_config.validation_failed");
- private static final Component DICE_TOOLTIP = Component.translatable("gui.nochatreports.encryption_config.dice_tooltip");
- private static final Component PASS_NOT_ALLOWED = Component.translatable("gui.nochatreports.encryption_config.pass_not_allowed");
- private static final Component ENCRYPT_PUBLIC = Component.translatable("gui.nochatreports.encryption_config.encrypt_public");
-
- private static final int FIELDS_Y_START = 45;
- private final Screen previous;
- private CustomEditBox keyField, passField;
- private ImageButton validationIcon;
- private CycleButton<Encryption> algorithmButton;
- private MultiLineLabel keyDesc = MultiLineLabel.EMPTY, passDesc = MultiLineLabel.EMPTY;
- protected Checkbox encryptPublicCheck;
- private boolean settingPassKey = false;
-
- public EncryptionConfigScreen(Screen previous) {
- super(CommonComponents.EMPTY);
- this.previous = previous;
- }
-
- private NCRConfigEncryption getConfig() {
- return NCRConfig.getEncryption();
- }
-
- @Override
- protected void init() {
- this.clearWidgets();
- super.init();
-
- int w = (int) (this.width * (this.hugeGUI() ? 0.9 : 0.7));
-
- this.keyDesc = MultiLineLabel.create(this.font, KEY_DESC, w - 5);
- int keyDescSpace = (this.keyDesc.getLineCount() + 1) * this.getLineHeight();
-
- this.passDesc = MultiLineLabel.create(this.font, PASS_DESC, w - 5);
- int passDescSpace = (this.passDesc.getLineCount() + 1) * this.getLineHeight();
-
- w -= 52;
-
- this.keyField = new CustomEditBox(this.font, (this.width - w)/2 - 2, (this.hugeGUI() ? 25 : FIELDS_Y_START) + keyDescSpace - 15,
- w, 18, CommonComponents.EMPTY);
- this.keyField.setMaxLength(512);
- this.keyField.setResponder(this::onKeyUpdate);
- this.addWidget(this.keyField);
-
- var button = new AdvancedImageButton(this.keyField.getX() + this.keyField.getWidth() - 15, this.keyField.getY() + 3, 12,
- 12, 0, 0, 0, ENCRYPTION_ICONS, 64, 64, btn -> {}, Component.empty(), this);
- button.setTooltip(new AdvancedTooltip(() -> this.validationIcon != null &&
- this.validationIcon.yTexStart == 0 ? VALIDATION_OK : VALIDATION_FAILED).setMaxWidth(250));
- button.active = false;
- button.visible = true;
-
- this.addRenderableOnly(this.validationIcon = button);
-
- button = new AdvancedImageButton(this.keyField.getX() - 22, this.keyField.getY() - 0, 18, 18, 0,
- 28, 0, ENCRYPTION_ICONS, 64, 64, btn -> {}, Component.empty(), this);
- button.active = false;
- button.visible = true;
-
- this.addRenderableOnly(button);
-
- button = new AdvancedImageButton(this.keyField.getX() + this.keyField.getWidth() + 4, this.keyField.getY() - 1, 23, 20, 41,
- 24, 20, ENCRYPTION_ICONS, 64, 64, btn -> {
- this.unfocusFields();
- this.keyField.setValue(this.algorithmButton.getValue().getRandomKey());
- }, Component.empty(), this);
- button.setTooltip(new AdvancedTooltip(DICE_TOOLTIP).setMaxWidth(250));
- button.active = true;
- button.visible = true;
-
- this.addRenderableWidget(button);
-
- w += 25;
-
- this.passField = new CustomEditBox(this.font, (this.width - w)/2 + 11, this.keyField.getY() +
- this.keyField.getHeight() + passDescSpace + (this.hugeGUI() ? -3 : 13), w, 18, CommonComponents.EMPTY);
- this.passField.setMaxLength(512);
- this.passField.setResponder(this::onPassphraseUpdate);
- this.addWidget(this.passField);
-
- button = new AdvancedImageButton(this.passField.getX() - 22, this.passField.getY() - 0, 18, 18, 0,
- 46, 0, ENCRYPTION_ICONS, 64, 64, btn -> {}, Component.empty(), this);
- button.active = false;
- button.visible = true;
-
- this.addRenderableOnly(button);
-
- int checkWidth = this.font.width(ENCRYPT_PUBLIC);
- this.encryptPublicCheck = new Checkbox(this.width / 2 - checkWidth / 2 - 8, this.passField.getY() + 24, checkWidth + 24, 20,
- ENCRYPT_PUBLIC, NCRConfig.getEncryption().shouldEncryptPublic());
- this.addRenderableWidget(this.encryptPublicCheck);
-
- this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, btn -> {
- this.onDone();
- this.onClose();
- }).pos(this.width / 2 + 4, this.passField.getY() + 48).size(219, 20).build());
-
- CycleButton<Encryption> cycle = CycleButton.<Encryption>builder(value -> {
- return Component.translatable("gui.nochatreports.encryption_config.algorithm",
- Component.translatable("algorithm.nochatreports." + value.getID() + ".name"));
- }).withValues(Encryption.getRegistered()).displayOnlyValue().withInitialValue(this.getConfig()
- .getAlgorithm()).withTooltip(value -> new AdvancedTooltip(Component.translatable(
- "algorithm.nochatreports." + value.getID())).setMaxWidth(250))
- .create(this.width / 2 - 4 - 218, this.passField.getY() + 48, 218, 20, CommonComponents.EMPTY,
- (cycleButton, value) -> {
- this.unfocusFields();
- this.onAlgorithmUpdate(value);
- });
-
- this.addRenderableWidget(this.algorithmButton = cycle);
-
- this.onAlgorithmUpdate(this.algorithmButton.getValue());
-
- if (!StringUtil.isNullOrEmpty(this.getConfig().getEncryptionPassphrase())) {
- this.passField.setValue(this.getConfig().getEncryptionPassphrase());
- } else if (!StringUtil.isNullOrEmpty(this.getConfig().getEncryptionKey())) {
- if (!Objects.equals(this.getConfig().getEncryptionKey(), this.algorithmButton.getValue()
- .getDefaultKey())) {
- this.keyField.setValue(this.getConfig().getEncryptionKey());
- } else {
- this.keyField.setValue("");
- }
- }
- }
-
- @Override
- public void render(PoseStack poseStack, int i, int j, float f) {
- if (!this.passField.isActive()) {
- if (this.passField.isFocused()) {
- this.passField.setFocused(false);
- }
- this.passField.setEditable(false);
- }
-
- this.renderBackground(poseStack);
- Screen.drawCenteredString(poseStack, this.font, HEADER, this.width / 2, this.hugeGUI() ? 8 : 16, 0xFFFFFF);
-
- this.keyDesc.renderLeftAligned(poseStack, this.keyField.getX() - 20, (this.hugeGUI() ? 25 : FIELDS_Y_START), this.getLineHeight(), 0xFFFFFF);
-
- this.keyField.render(poseStack, i, j, f);
-
- this.passDesc.renderLeftAligned(poseStack, this.passField.getX() - 20, this.keyField.getY() + this.keyField.getHeight() + (this.hugeGUI() ? 12 : 28),
- this.getLineHeight(), 0xFFFFFF);
-
- this.passField.render(poseStack, i, j, f);
-
- // if (this.algorithmButton != null && this.algorithmButton.isMouseOver(i, j)) {
- // this.renderTooltip(poseStack, this.algorithmButton.getTooltip(), i, j);
- // }
-
- super.render(poseStack, i, j, f);
-
- if (StringUtil.isNullOrEmpty(this.keyField.getValue()) && !this.keyField.isFocused()) {
- Screen.drawString(poseStack, this.font,
- Component.translatable("gui.nochatreports.encryption_config.default_key",
- this.algorithmButton.getValue().getDefaultKey()), this.keyField.getX() + 4,
- this.keyField.getY() + 5, 0x999999);
- }
-
- if (!this.passField.active) {
- Screen.drawString(poseStack, this.font, PASS_NOT_ALLOWED, this.passField.getX() + 4,
- this.passField.getY() + 5, 0x999999);
- RenderSystem.setShaderTexture(0, ENCRYPTION_ICONS);
- RenderSystem.enableDepthTest();
- blit(poseStack, this.passField.getX() - 20, this.passField.getY() + 3, 50, 0, 14, 13, 64, 64);
- }
- }
-
- private int getLineHeight() {
- if (this.hugeGUI())
- return (int) (this.minecraft.font.lineHeight * 1.5) + 1;
- else
- return this.minecraft.font.lineHeight * 2;
- }
-
- @Override
- public void tick() {
- this.keyField.tick();
- }
-
- private void onKeyUpdate(String key) {
- if (!this.settingPassKey) {
- this.passField.setValue("");
- }
-
- if (!StringUtil.isNullOrEmpty(key)) {
- this.validationIcon.yTexStart = this.algorithmButton.getValue().validateKey(key) ? 0 : 12;
- } else {
- this.validationIcon.yTexStart = 0;
- }
- }
-
- private void onPassphraseUpdate(String pass) {
- Encryption encryption = this.algorithmButton.getValue();
-
- this.settingPassKey = true;
- if (!StringUtil.isNullOrEmpty(pass)) {
- if (encryption.supportsPassphrases()) {
- this.keyField.setValue(encryption.getPassphraseKey(pass));
- }
- } else {
- this.onKeyUpdate(this.keyField.getValue());
- }
- this.settingPassKey = false;
- }
-
- private void onAlgorithmUpdate(Encryption encryption) {
- if (!encryption.supportsPassphrases()) {
- this.passField.setFocused(false);
- this.passField.setEditable(this.passField.active = false);
- this.onKeyUpdate(this.keyField.getValue());
- } else {
- this.passField.setEditable(this.passField.active = true);
- this.onPassphraseUpdate(this.passField.getValue());
- }
- }
-
- private void unfocusFields() {
- this.keyField.setFocused(false);
- this.passField.setFocused(false);
- }
-
- private void onDone() {
- var config = NCRConfig.getEncryption();
- var encryption = this.algorithmButton.getValue();
- config.setAlgorithm(encryption);
- config.setEncryptionKey(!StringUtil.isNullOrEmpty(this.keyField.getValue()) ? this.keyField.getValue()
- : encryption.getDefaultKey());
- config.setEncryptPublic(this.encryptPublicCheck.selected());
- }
-
- private boolean hugeGUI() {
- return this.height <= 1080 / 4;
- }
-
- @Override
- public void onClose() {
- this.minecraft.setScreen(this.previous);
- }
-
- private static class CustomEditBox extends EditBox {
- public CustomEditBox(Font font, int i, int j, int k, int l, Component component) {
- super(font, i, j, k, l, component);
- }
-
- @Override
- public void setFocused(boolean bl) {
- super.setFocused(bl);
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionWarningScreen.java b/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionWarningScreen.java
deleted file mode 100644
index 954c6f3..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionWarningScreen.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.aizistral.nochatreports.common.gui;
-
-import com.aizistral.nochatreports.common.config.NCRConfig;
-
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.ChatFormatting;
-import net.minecraft.client.gui.components.Button;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-
-@Environment(EnvType.CLIENT)
-public class EncryptionWarningScreen extends TriageWarningScreen {
- private static final Component TITLE = Component.translatable("gui.nochatreports.encryption_warning.header").withStyle(ChatFormatting.BOLD);
- private static final Component CONTENT = Component.translatable("gui.nochatreports.encryption_warning.contents");
- private static final Component CHECK = Component.translatable("gui.nochatreports.encryption_warning.check");
- private static final String WIKI_LINK = "https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/To-Encrypt-or-Not-to-Encrypt";
- private static boolean sessionSeen = false;
-
- public EncryptionWarningScreen(Screen previous) {
- super(TITLE, CONTENT, CHECK, WIKI_LINK, previous);
- }
-
- @Override
- protected void onProceed(Button button) {
- this.minecraft.setScreen(new EncryptionConfigScreen(this.previous));
- if (this.stopShowing.selected()) {
- NCRConfig.getEncryption().disableWarning();
- }
-
- sessionSeen = true;
- }
-
- @Override
- protected void onBack(Button button) {
- this.minecraft.setScreen(this.previous);
- }
-
- public static boolean seenOnThisSession() {
- return sessionSeen;
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/UnsafeServerScreen.java b/src/main/java/com/aizistral/nochatreports/common/gui/UnsafeServerScreen.java
index 239b23b..a46ce21 100644
--- a/src/main/java/com/aizistral/nochatreports/common/gui/UnsafeServerScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/common/gui/UnsafeServerScreen.java
@@ -41,12 +41,6 @@ public final class UnsafeServerScreen extends AdaptiveWarningScreen {
}).bounds(this.width / 2 - 155 + 160, i, 150, 20).build());
}
- private void resendLastMessage() {
- if (this.previous instanceof ChatScreen chat) {
- chat.handleChatInput(NCRConfig.getEncryption().getLastMessage(), false);
- }
- }
-
public static void setHideThisSession(boolean hide) {
hideThisSession = hide;
}
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
deleted file mode 100644
index 273ea57..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.aizistral.nochatreports.common.mixins.client;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.At.Shift;
-
-import com.aizistral.nochatreports.common.NCRCore;
-import com.aizistral.nochatreports.common.config.NCRConfig;
-import com.aizistral.nochatreports.common.core.EncryptionUtil;
-
-import org.spongepowered.asm.mixin.injection.ModifyArg;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
-
-import net.minecraft.ChatFormatting;
-import net.minecraft.client.GuiMessageTag;
-import net.minecraft.client.gui.components.ChatComponent;
-import net.minecraft.network.chat.CommonComponents;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.FormattedText;
-
-@Mixin(ChatComponent.class)
-public class MixinChatComponent {
- private static final GuiMessageTag.Icon ENCRYPTED_ICON = GuiMessageTag.Icon.valueOf("CHAT_NCR_ENCRYPTED");
- private boolean lastMessageEncrypted;
- private Component lastMessageOriginal;
-
- @ModifyVariable(method = "addRecentChat", at = @At("HEAD"), argsOnly = true)
- private String onAddRecentChat(String message) {
- if (NCRConfig.getEncryption().isEnabledAndValid())
- return NCRConfig.getEncryption().getLastMessage();
- else
- return message;
- }
-
- @ModifyVariable(method = "addMessage(Lnet/minecraft/network/chat/Component;"
- + "Lnet/minecraft/network/chat/MessageSignature;ILnet/minecraft/client/GuiMessageTag;Z)V",
- at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ComponentRenderUtils;"
- + "wrapComponents(Lnet/minecraft/network/chat/FormattedText;ILnet/minecraft/client/gui/Font;"
- + ")Ljava/util/List;", ordinal = 0, shift = Shift.AFTER), 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;"
- + "Lnet/minecraft/network/chat/MessageSignature;ILnet/minecraft/client/GuiMessageTag;Z)V",
- at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ComponentRenderUtils;"
- + "wrapComponents(Lnet/minecraft/network/chat/FormattedText;I"
- + "Lnet/minecraft/client/gui/Font;)Ljava/util/List;", ordinal = 0))
- private FormattedText modifyGUIMessage(FormattedText msg) {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NCRCore.LOGGER.info("Adding chat message, structure: " +
- Component.Serializer.toStableJson((Component) msg));
- }
-
- var decrypted = EncryptionUtil.tryDecrypt((Component) msg);
-
- decrypted.ifPresentOrElse(component -> {
- this.lastMessageOriginal = EncryptionUtil.recreate((Component) msg);
- this.lastMessageEncrypted = true;
- }, () -> this.lastMessageEncrypted = false);
-
- return this.lastMessageEncrypted ? decrypted.get() : 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 88d9809..eb000cb 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
@@ -8,14 +8,12 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.aizistral.nochatreports.common.NCRClient;
import com.aizistral.nochatreports.common.NCRCore;
import com.aizistral.nochatreports.common.config.NCRConfig;
-import com.aizistral.nochatreports.common.core.EncryptionUtil;
import com.aizistral.nochatreports.common.core.ServerSafetyLevel;
import com.aizistral.nochatreports.common.core.ServerSafetyState;
import com.aizistral.nochatreports.common.core.SigningMode;
@@ -108,10 +106,4 @@ public class MixinChatListener {
}
}
- @ModifyVariable(method = "narrateChatMessage(Lnet/minecraft/network/chat/ChatType$Bound;"
- + "Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), argsOnly = true)
- private Component decryptNarratedMessage(Component msg) {
- return EncryptionUtil.tryDecrypt(msg).orElse(msg);
- }
-
}
diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatScreen.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatScreen.java
index dde43c3..597c958 100644
--- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatScreen.java
@@ -15,13 +15,9 @@ import com.aizistral.nochatreports.common.core.ServerSafetyState;
import com.aizistral.nochatreports.common.core.SigningMode;
import com.aizistral.nochatreports.common.gui.AdvancedImageButton;
import com.aizistral.nochatreports.common.gui.AdvancedTooltip;
-import com.aizistral.nochatreports.common.gui.EncryptionButton;
-import com.aizistral.nochatreports.common.gui.EncryptionWarningScreen;
import com.aizistral.nochatreports.common.gui.GUIShenanigans;
-import com.aizistral.nochatreports.common.gui.TooltipHelper;
import net.minecraft.ChatFormatting;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
@@ -31,7 +27,6 @@ import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
-import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
@@ -44,7 +39,6 @@ import net.minecraft.resources.ResourceLocation;
@Mixin(ChatScreen.class)
public abstract class MixinChatScreen extends Screen {
private static final ResourceLocation CHAT_STATUS_ICONS = new ResourceLocation("nochatreports", "textures/gui/chat_status_icons_extended.png");
- private static final ResourceLocation ENCRYPTION_BUTTON = new ResourceLocation("nochatreports", "textures/gui/encryption_toggle_button.png");
private ImageButton safetyStatusButton;
@Shadow
protected EditBox input;
@@ -85,19 +79,7 @@ public abstract class MixinChatScreen extends Screen {
@Inject(method = "normalizeChatMessage", at = @At("RETURN"), cancellable = true)
public void onBeforeMessage(String original, CallbackInfoReturnable<String> info) {
String message = info.getReturnValue();
- NCRConfig.getEncryption().setLastMessage(message);
-
- if (!message.isEmpty() && !Screen.hasControlDown() && NCRConfig.getEncryption().shouldEncrypt(message)) {
- NCRConfig.getEncryption().getEncryptor().ifPresent(e -> {
- int index = NCRConfig.getEncryption().getEncryptionStartIndex(message);
- String noencrypt = message.substring(0, index);
- String encrypt = message.substring(index, message.length());
-
- if (encrypt.length() > 0) {
- info.setReturnValue(noencrypt + e.encrypt("#%" + encrypt));
- }
- });
- }
+ ServerSafetyState.setLastMessage(message);
}
@Inject(method = "init", at = @At("HEAD"))
@@ -166,39 +148,6 @@ public abstract class MixinChatScreen extends Screen {
this.addRenderableWidget(this.safetyStatusButton);
buttonX -= 25;
}
-
- if (!NCRConfig.getEncryption().showEncryptionButton())
- return;
-
- int xStart = !NCRConfig.getEncryption().isValid() ? 40 : (NCRConfig.getEncryption().isEnabled() ? 0 : 20);
-
- var button = new EncryptionButton(buttonX, this.height - 37, 20, 20, xStart,
- 0, 20, ENCRYPTION_BUTTON, 64, 64, btn -> {
- if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled()
- && !NCRConfig.getEncryption().isEnabled()) {
- Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this));
- } else if (NCRConfig.getEncryption().isValid()) {
- NCRConfig.getEncryption().toggleEncryption();
- ((EncryptionButton)btn).xTexStart = NCRConfig.getEncryption().isEnabledAndValid() ? 0 : 20;
- } else {
- ((EncryptionButton)btn).openEncryptionConfig();
- }
- }, Component.empty(), this);
- button.setTooltip(new AdvancedTooltip(() -> {
- if (NCRConfig.getEncryption().isValid())
- return Component.translatable("gui.nochatreports.encryption_tooltip", Language.getInstance()
- .getOrDefault("gui.nochatreports.encryption_state_" + (NCRConfig.getEncryption()
- .isEnabledAndValid() ? "on" : "off")),
- TooltipHelper.getCtrl().withStyle(ChatFormatting.BOLD, ChatFormatting.UNDERLINE));
- else
- return Component.translatable("gui.nochatreports.encryption_tooltip_invalid", Language.getInstance()
- .getOrDefault("gui.nochatreports.encryption_state_" + (NCRConfig.getEncryption()
- .isEnabledAndValid() ? "on" : "off")));
- }).setMaxWidth(250));
- button.active = true;
- button.visible = true;
-
- this.addRenderableWidget(button);
}
@Inject(method = "tick", at = @At("RETURN"))
diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinGuiMessageTagIcon.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinGuiMessageTagIcon.java
deleted file mode 100644
index 2f6e656..0000000
--- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinGuiMessageTagIcon.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.aizistral.nochatreports.common.mixins.client;
-
-import java.util.Arrays;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Mutable;
-import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.gen.Invoker;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import com.mojang.blaze3d.systems.RenderSystem;
-import com.mojang.blaze3d.vertex.PoseStack;
-
-import net.minecraft.client.GuiMessageTag;
-import net.minecraft.client.GuiMessageTag.Icon;
-import net.minecraft.client.gui.GuiComponent;
-import net.minecraft.resources.ResourceLocation;
-
-@Mixin(GuiMessageTag.Icon.class)
-public abstract class MixinGuiMessageTagIcon {
- private static final ResourceLocation TEXTURE_NCR = new ResourceLocation("nochatreports", "textures/gui/encrypted_tag.png");
- @Shadow(aliases = "field_39768") @Mutable static Icon[] $VALUES;
-
- @Invoker("<init>")
- static Icon create(String name, int ordinal, int u, int v, int width, int height) {
- throw new IllegalStateException("Invoker transformation failed");
- }
-
- @Inject(method = "draw", at = @At("HEAD"), cancellable = true)
- public void onDraw(PoseStack stack, int x, int y, CallbackInfo info) {
- if (((Icon)(Object)this).name().equals("CHAT_NCR_ENCRYPTED")) {
- RenderSystem.setShaderTexture(0, TEXTURE_NCR);
- GuiComponent.blit(stack, x, y, 0, 0, 9, 9, 9, 9);
- info.cancel();
- }
- }
-
- static {
- var ordinal = $VALUES.length;
- var values = Arrays.copyOf($VALUES, ordinal + 1);
- values[ordinal] = create("CHAT_NCR_ENCRYPTED", ordinal, 9, 0, 9, 9);
- $VALUES = values;
- }
-
-}