aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/mixins/MixinRenderString.java
diff options
context:
space:
mode:
authorRoseGoldIsntGay <yoavkau@gmail.com>2022-02-04 14:17:32 +0200
committerRoseGoldIsntGay <yoavkau@gmail.com>2022-02-04 14:17:32 +0200
commit20894963147ef84a7ad7d578191de69a856f6403 (patch)
tree34bf1488f2042630c595f557543d324510bd1429 /src/main/java/rosegoldaddons/mixins/MixinRenderString.java
parentf4b58abbda168b01513a5ac2ba2870bc00df7074 (diff)
downloadRGA-20894963147ef84a7ad7d578191de69a856f6403.tar.gz
RGA-20894963147ef84a7ad7d578191de69a856f6403.tar.bz2
RGA-20894963147ef84a7ad7d578191de69a856f6403.zip
2.7.1
Diffstat (limited to 'src/main/java/rosegoldaddons/mixins/MixinRenderString.java')
-rw-r--r--src/main/java/rosegoldaddons/mixins/MixinRenderString.java90
1 files changed, 78 insertions, 12 deletions
diff --git a/src/main/java/rosegoldaddons/mixins/MixinRenderString.java b/src/main/java/rosegoldaddons/mixins/MixinRenderString.java
index f7b0e8d..e4888e0 100644
--- a/src/main/java/rosegoldaddons/mixins/MixinRenderString.java
+++ b/src/main/java/rosegoldaddons/mixins/MixinRenderString.java
@@ -1,32 +1,98 @@
package rosegoldaddons.mixins;
import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.util.StringUtils;
+import org.apache.commons.codec.digest.DigestUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import rosegoldaddons.Main;
-import java.util.Map;
-
@Mixin(FontRenderer.class)
public abstract class MixinRenderString {
- @ModifyVariable(method = "renderString", at = @At(value = "FIELD"))
+ @ModifyVariable(method = "drawString(Ljava/lang/String;FFIZ)I", at = @At(value = "FIELD"))
private String replaceName(String text) {
- if(Main.configFile.wydsi && text.contains("727")) {
+ if (Main.mc.theWorld == null || Main.mc.thePlayer == null) return text;
+ if (Main.configFile.wydsi && text.contains("727")) {
text = text.replace("727", "726");
}
- if (Main.init) {
- for (Map.Entry<String, String> entry : Main.resp.entrySet()) {
- String key = entry.getKey();
- String value = entry.getValue();
-
- if (text.contains(key) && !text.contains(value)) {
- text = text.replace(key, value)+"§r";
- break;
+ if (Main.init && Main.configFile.alchsleep != 88 || Main.configFile.skiblock != 263) {
+ String[] words = stripString(text).replace(":"," ").replace("'"," ").split(" ");
+ String[] formatteds = text.replace(":"," ").replace("'"," ").split(" ");
+ for (String word : words) {
+ if (Main.hashedCache.contains(word)) continue;
+ if(Main.rankCache.containsKey(word)) {
+ String rank = getRank(text, word);
+ if(rank != null) {
+ text = text.replace(rank, Main.rankCache.get(word));
+ }
+ } else {
+ String hashed = DigestUtils.sha256Hex(word + word);
+ if (Main.ranks.containsKey(hashed)) {
+ String rank = getRank(text, word);
+ if(rank != null) {
+ Main.rankCache.put(word, Main.ranks.get(hashed));
+ System.out.println(word+":"+Main.ranks.get(hashed));
+ }
+ }
+ }
+ }
+ for (String word : words) {
+ if (Main.hashedCache.contains(word)) continue;
+ if (Main.nameCache.containsKey(word)) {
+ String[] replaces = Main.nameCache.get(word).split(" ");
+ for (String replace : replaces) {
+ for (String formatted : formatteds) {
+ if (replace.equals(formatted)) return text;
+ }
+ }
+ String color = getColorBeforeIndex(text, text.indexOf(word));
+ text = text.replace(word, Main.nameCache.get(word) + color);
+ } else {
+ String hashed = DigestUtils.sha256Hex(word + word);
+ if (Main.names.containsKey(hashed)) {
+ Main.nameCache.put(word, Main.names.get(hashed));
+ } else {
+ Main.hashedCache.add(word);
+ }
}
}
}
return text;
}
+
+ private String getRank(String str, String sub) {
+ if(!str.contains("[") || !str.contains("]")) return null;
+ if(sub.contains("[") || sub.contains("]")) return null;
+ if(str.indexOf(sub)-sub.length() >= str.indexOf("]")) return null;
+ if(str.indexOf(sub) < str.indexOf("[")) return null;
+
+ return str.substring(str.indexOf("["), str.indexOf("]")+1);
+ }
+
+ private String getColorBeforeIndex(String str, int index) {
+ String lastColor = "";
+ for (int i = 0; i < str.length(); i++) {
+ if (i == index) break;
+ if (str.charAt(i) == '§' && i + 1 < str.length() && str.charAt(i + 1) != 'r' && str.charAt(i + 1) != 'l' && str.charAt(i + 1) != 'k'
+ && str.charAt(i + 1) != 'm' && str.charAt(i + 1) != 'n' && str.charAt(i + 1) != 'o') {
+ lastColor = str.charAt(i) + "" + str.charAt(i + 1);
+ }
+ }
+ return lastColor;
+ }
+
+ private String stripString(String s) {
+ char[] nonValidatedString = StringUtils.stripControlCodes(s).toCharArray();
+ StringBuilder validated = new StringBuilder();
+
+ for (char a : nonValidatedString) {
+ if ((int) a < 127 && (int) a > 20) {
+ validated.append(a);
+ }
+ }
+
+ return validated.toString();
+ }
}