|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2026 Wurst-Imperium and contributors. |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the GNU General Public |
| 5 | + * License, version 3. If a copy of the GPL was not distributed with this |
| 6 | + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt |
| 7 | + */ |
| 8 | +package net.wurstclient.hacks; |
| 9 | + |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.LinkedHashSet; |
| 12 | +import java.util.Set; |
| 13 | +import java.util.stream.Collectors; |
| 14 | + |
| 15 | +import net.wurstclient.Category; |
| 16 | +import net.wurstclient.SearchTags; |
| 17 | +import net.wurstclient.hack.Hack; |
| 18 | +import net.wurstclient.settings.CheckboxSetting; |
| 19 | +import net.wurstclient.settings.SliderSetting; |
| 20 | +import net.wurstclient.settings.TextFieldSetting; |
| 21 | +import net.wurstclient.settings.SliderSetting.ValueDisplay; |
| 22 | + |
| 23 | +@SearchTags({"ui settings", "chat overlay", "hud", "client chat"}) |
| 24 | +public final class ClientChatOverlayHack extends Hack |
| 25 | +{ |
| 26 | + private final SliderSetting transparency = |
| 27 | + new SliderSetting("Transparency", 35, 0, 100, 1, ValueDisplay.INTEGER); |
| 28 | + private final SliderSetting fadeOutTimeSeconds = |
| 29 | + new SliderSetting("Fade-out time", 10, 1, 60, 1, ValueDisplay.INTEGER); |
| 30 | + private final CheckboxSetting routeToConsole = |
| 31 | + new CheckboxSetting("Route to game console", false); |
| 32 | + private final CheckboxSetting onlyWurstMessages = |
| 33 | + new CheckboxSetting("Only Wurst messages", false); |
| 34 | + private final TextFieldSetting forceClientKeywords = new TextFieldSetting( |
| 35 | + "Force client chat keywords", |
| 36 | + "Comma-separated keywords that force a message into client chat.", ""); |
| 37 | + private final TextFieldSetting forceNormalKeywords = new TextFieldSetting( |
| 38 | + "Force normal chat keywords", |
| 39 | + "Comma-separated keywords that force a message into normal chat.", ""); |
| 40 | + private final SliderSetting maxLines = |
| 41 | + new SliderSetting("Max lines", 10, 3, 30, 1, ValueDisplay.INTEGER); |
| 42 | + private final SliderSetting hudOffsetX = new SliderSetting("HUD X offset", |
| 43 | + 0, -320, 320, 1, ValueDisplay.INTEGER); |
| 44 | + private final SliderSetting hudOffsetY = new SliderSetting("HUD Y offset", |
| 45 | + 0, -240, 240, 1, ValueDisplay.INTEGER); |
| 46 | + |
| 47 | + public ClientChatOverlayHack() |
| 48 | + { |
| 49 | + super("ClientChatOverlay"); |
| 50 | + setCategory(Category.OTHER); |
| 51 | + addSetting(transparency); |
| 52 | + addSetting(fadeOutTimeSeconds); |
| 53 | + addSetting(routeToConsole); |
| 54 | + addSetting(onlyWurstMessages); |
| 55 | + addSetting(forceClientKeywords); |
| 56 | + addSetting(forceNormalKeywords); |
| 57 | + addSetting(maxLines); |
| 58 | + addSetting(hudOffsetX); |
| 59 | + addSetting(hudOffsetY); |
| 60 | + } |
| 61 | + |
| 62 | + public int getTransparencyPercent() |
| 63 | + { |
| 64 | + return transparency.getValueI(); |
| 65 | + } |
| 66 | + |
| 67 | + public long getFadeOutTimeMs() |
| 68 | + { |
| 69 | + return fadeOutTimeSeconds.getValueI() * 1000L; |
| 70 | + } |
| 71 | + |
| 72 | + public boolean isRoutingToConsole() |
| 73 | + { |
| 74 | + return routeToConsole.isChecked(); |
| 75 | + } |
| 76 | + |
| 77 | + public boolean isOnlyWurstMessages() |
| 78 | + { |
| 79 | + return onlyWurstMessages.isChecked(); |
| 80 | + } |
| 81 | + |
| 82 | + public boolean matchesForceClientKeyword(String text) |
| 83 | + { |
| 84 | + return matchesAnyKeyword(text, getForceClientKeywords()); |
| 85 | + } |
| 86 | + |
| 87 | + public boolean matchesForceNormalKeyword(String text) |
| 88 | + { |
| 89 | + return matchesAnyKeyword(text, getForceNormalKeywords()); |
| 90 | + } |
| 91 | + |
| 92 | + public int getMaxLines() |
| 93 | + { |
| 94 | + return maxLines.getValueI(); |
| 95 | + } |
| 96 | + |
| 97 | + public int getHudOffsetX() |
| 98 | + { |
| 99 | + return hudOffsetX.getValueI(); |
| 100 | + } |
| 101 | + |
| 102 | + public int getHudOffsetY() |
| 103 | + { |
| 104 | + return hudOffsetY.getValueI(); |
| 105 | + } |
| 106 | + |
| 107 | + public void setHudOffsets(int x, int y) |
| 108 | + { |
| 109 | + hudOffsetX.setValue(x); |
| 110 | + hudOffsetY.setValue(y); |
| 111 | + } |
| 112 | + |
| 113 | + private Set<String> getForceClientKeywords() |
| 114 | + { |
| 115 | + return parseKeywords(forceClientKeywords.getValue()); |
| 116 | + } |
| 117 | + |
| 118 | + private Set<String> getForceNormalKeywords() |
| 119 | + { |
| 120 | + return parseKeywords(forceNormalKeywords.getValue()); |
| 121 | + } |
| 122 | + |
| 123 | + private static Set<String> parseKeywords(String value) |
| 124 | + { |
| 125 | + if(value == null || value.isBlank()) |
| 126 | + return Set.of(); |
| 127 | + |
| 128 | + return Arrays.stream(value.split(",")).map(String::trim) |
| 129 | + .filter(s -> !s.isEmpty()).map(String::toLowerCase) |
| 130 | + .collect(Collectors.toCollection(LinkedHashSet::new)); |
| 131 | + } |
| 132 | + |
| 133 | + private static boolean matchesAnyKeyword(String text, Set<String> keywords) |
| 134 | + { |
| 135 | + if(text == null || text.isBlank() || keywords.isEmpty()) |
| 136 | + return false; |
| 137 | + |
| 138 | + String lower = text.toLowerCase(); |
| 139 | + for(String keyword : keywords) |
| 140 | + if(lower.contains(keyword)) |
| 141 | + return true; |
| 142 | + |
| 143 | + return false; |
| 144 | + } |
| 145 | +} |
0 commit comments