Skip to content

Commit 897ed68

Browse files
committed
Updated PerformanceOverlay, GameStats, ClientChatOverlay
1 parent c9d5a31 commit 897ed68

5 files changed

Lines changed: 185 additions & 31 deletions

File tree

src/main/java/net/wurstclient/hacks/ClientChatOverlayHack.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public final class ClientChatOverlayHack extends Hack
3636
new CheckboxSetting("Only Wurst messages", false);
3737
private final CheckboxSetting extraPanelForWurstMessages =
3838
new CheckboxSetting("Extra panel for Wurst-only messages", false);
39+
private final CheckboxSetting holdTabOpensChat = new CheckboxSetting(
40+
"Hold Tab opens chat",
41+
"While held, opens vanilla chat like pressing T. Releasing Tab closes it.",
42+
false);
3943
private final TextFieldSetting forceClientKeywords = new TextFieldSetting(
4044
"Force client chat keywords",
4145
"Comma-separated keywords that force a message into client chat.", "");
@@ -77,6 +81,7 @@ public ClientChatOverlayHack()
7781
addSetting(routeToConsole);
7882
addSetting(onlyWurstMessages);
7983
addSetting(extraPanelForWurstMessages);
84+
addSetting(holdTabOpensChat);
8085
addSetting(forceClientKeywords);
8186
addSetting(forceNormalKeywords);
8287
addSetting(colorUsernames);
@@ -114,6 +119,11 @@ public boolean isExtraPanelForWurstMessages()
114119
return extraPanelForWurstMessages.isChecked();
115120
}
116121

122+
public boolean shouldHoldTabOpenChat()
123+
{
124+
return holdTabOpensChat.isChecked();
125+
}
126+
117127
public boolean matchesForceClientKeyword(String text)
118128
{
119129
return matchesAnyKeyword(text, getForceClientKeywords());

src/main/java/net/wurstclient/hud/ClientMessageOverlay.java

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public final class ClientMessageOverlay
9090
private int lastWurstY1;
9191
private int lastWurstX2;
9292
private int lastWurstY2;
93+
private boolean tabHeldForOverlay;
9394

9495
private ClientMessageOverlay()
9596
{}
@@ -228,24 +229,34 @@ public void render(GuiGraphicsExtractor context)
228229
if(hack == null || !hack.isEnabled())
229230
return;
230231

232+
handleHoldTabOpensChat(hack);
233+
231234
boolean splitWurstPanel = hack.isExtraPanelForWurstMessages();
232-
if(messages.isEmpty() && (!splitWurstPanel || wurstMessages.isEmpty()))
235+
boolean hasVanillaMessages =
236+
tabHeldForOverlay && hasVanillaChatMessages();
237+
if(messages.isEmpty() && (!splitWurstPanel || wurstMessages.isEmpty())
238+
&& !hasVanillaMessages)
233239
return;
234240

235241
float chatScale = WurstClient.MC.options.chatScale().get().floatValue();
236242
if(chatScale <= 0)
237243
return;
238244

239-
boolean chatOpen = WurstClient.MC.screen instanceof ChatScreen;
245+
boolean chatOpen =
246+
WurstClient.MC.screen instanceof ChatScreen || tabHeldForOverlay;
240247
int maxLines = hack.getMaxLines();
241248
int maxWidth = Mth.floor(
242249
ChatComponent.getWidth(WurstClient.MC.options.chatWidth().get())
243250
/ chatScale);
244251
if(maxWidth <= 0)
245252
return;
246253

247-
List<RenderLine> allLines =
248-
buildAllLines(messages, maxWidth, chatOpen || hoveredMainPanel);
254+
List<RenderLine> allLines;
255+
if(tabHeldForOverlay)
256+
allLines = buildCombinedLines(messages, maxWidth);
257+
else
258+
allLines =
259+
buildAllLines(messages, maxWidth, chatOpen || hoveredMainPanel);
249260
totalLineCount = allLines.size();
250261
int maxScroll = Math.max(0, totalLineCount - maxLines);
251262
scrollOffset = Mth.clamp(scrollOffset, 0, maxScroll);
@@ -1013,6 +1024,62 @@ private static String extractLastUsernameToken(String text)
10131024
return last;
10141025
}
10151026

1027+
private boolean hasVanillaChatMessages()
1028+
{
1029+
List<GuiMessage.Line> vanillaLines =
1030+
WurstClient.MC.gui.getChat().trimmedMessages;
1031+
return vanillaLines != null && !vanillaLines.isEmpty();
1032+
}
1033+
1034+
private List<RenderLine> buildCombinedLines(Deque<Entry> overlayMessages,
1035+
int maxWidth)
1036+
{
1037+
List<TimedRenderLine> timed = new ArrayList<>();
1038+
long nowMs = System.currentTimeMillis();
1039+
int guiTicks = WurstClient.MC.gui.getGuiTicks();
1040+
1041+
// Overlay entries (system/Wurst messages)
1042+
synchronized(overlayMessages)
1043+
{
1044+
for(Entry entry : overlayMessages)
1045+
{
1046+
Component renderComponent =
1047+
applyDefaultTextColorIfEnabled(entry.component());
1048+
List<FormattedCharSequence> wrapped =
1049+
ComponentRenderUtils.wrapComponents(renderComponent,
1050+
maxWidth, WurstClient.MC.font);
1051+
for(int i = wrapped.size() - 1; i >= 0; i--)
1052+
timed.add(
1053+
new TimedRenderLine(new RenderLine(wrapped.get(i), 255),
1054+
entry.timestamp()));
1055+
}
1056+
}
1057+
1058+
// Vanilla chat entries (player chat messages)
1059+
List<GuiMessage.Line> vanillaLines =
1060+
WurstClient.MC.gui.getChat().trimmedMessages;
1061+
if(vanillaLines != null)
1062+
for(GuiMessage.Line line : vanillaLines)
1063+
{
1064+
int tickAge = guiTicks - line.addedTime();
1065+
if(tickAge >= 0)
1066+
timed.add(
1067+
new TimedRenderLine(new RenderLine(line.content(), 255),
1068+
nowMs - tickAge * 50L));
1069+
}
1070+
1071+
// Sort newest first (matching buildAllLines order)
1072+
timed.sort((a, b) -> Long.compare(b.sortKey, a.sortKey));
1073+
1074+
List<RenderLine> result = new ArrayList<>(timed.size());
1075+
for(TimedRenderLine t : timed)
1076+
result.add(t.line);
1077+
return result;
1078+
}
1079+
1080+
private record TimedRenderLine(RenderLine line, long sortKey)
1081+
{}
1082+
10161083
private List<RenderLine> buildAllLines(Deque<Entry> source, int maxWidth,
10171084
boolean fullOpacity)
10181085
{
@@ -1379,6 +1446,32 @@ private static boolean isMouseOverPanel(GuiGraphicsExtractor context,
13791446
return mouseX >= x1 && mouseX <= x2 && mouseY >= y1 && mouseY <= y2;
13801447
}
13811448

1449+
private void handleHoldTabOpensChat(ClientChatOverlayHack hack)
1450+
{
1451+
if(WurstClient.MC == null)
1452+
return;
1453+
1454+
if(!hack.shouldHoldTabOpenChat())
1455+
{
1456+
tabHeldForOverlay = false;
1457+
return;
1458+
}
1459+
1460+
Window window = WurstClient.MC.getWindow();
1461+
if(window == null)
1462+
return;
1463+
1464+
boolean tabDown = GLFW.glfwGetKey(window.handle(),
1465+
GLFW.GLFW_KEY_TAB) == GLFW.GLFW_PRESS;
1466+
1467+
tabHeldForOverlay = tabDown;
1468+
}
1469+
1470+
public boolean isTabHeldForOverlay()
1471+
{
1472+
return tabHeldForOverlay;
1473+
}
1474+
13821475
private record Entry(Component component, long timestamp)
13831476
{}
13841477

src/main/java/net/wurstclient/hud/GameStatsHud.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,9 @@ private void commitGraphResize()
913913
private void handleDrag(GuiGraphicsExtractor context, float x, float y,
914914
float width, float height)
915915
{
916-
boolean containerOpen = MC.screen instanceof AbstractContainerScreen<?>;
917-
if(!containerOpen)
916+
boolean canEdit = MC.screen instanceof ChatScreen
917+
|| MC.screen instanceof AbstractContainerScreen<?>;
918+
if(!canEdit)
918919
{
919920
if(dragging)
920921
commitDraggedOffset();

src/main/java/net/wurstclient/util/HackPerformanceOverlay.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ public void render(GuiGraphicsExtractor graphics)
7474
return;
7575

7676
if(otf.shouldShowGraph())
77-
updateGraphSample(snapshot.rows());
77+
updateGraphSample(snapshot.allTotalMs());
7878

7979
int availableWidth = Math.max(120,
8080
scaledWidth - HORIZONTAL_MARGIN * 2 - BOX_PADDING * 2);
81-
ArrayList<String> lines =
82-
buildLines(snapshot.rows(), snapshot.usingWindowData(), otf);
81+
ArrayList<String> lines = buildLines(snapshot, otf);
8382
if(lines.isEmpty())
8483
return;
8584

@@ -135,25 +134,59 @@ public void render(GuiGraphicsExtractor graphics)
135134
}
136135
}
137136

138-
private ArrayList<String> buildLines(List<HackPerformanceTracker.Row> rows,
139-
boolean usingWindowData, PerformanceOverlayOtf otf)
137+
private ArrayList<String> buildLines(
138+
HackPerformanceTracker.ListSnapshot snapshot, PerformanceOverlayOtf otf)
140139
{
141140
ArrayList<String> lines = new ArrayList<>();
142-
String mode = usingWindowData ? "1s" : "live";
143-
lines.add("Hack Perf [" + mode + "] sort="
141+
List<HackPerformanceTracker.Row> rows = snapshot.rows();
142+
boolean usingWindowData = snapshot.usingWindowData();
143+
String mode = usingWindowData ? "1s window" : "live";
144+
lines.add("Hack Performance [" + mode + "] sort="
144145
+ (otf.getSortMode() == SortMode.PEAK_TIME ? "peak" : "total"));
145146

147+
double fps = Math.max(1, MC.getFps());
148+
double frameMs = 1000.0 / fps;
149+
double unattributedMs = Math.max(0, frameMs - snapshot.allTotalMs());
150+
lines.add("Frame " + formatMs(frameMs) + " | Hacks "
151+
+ formatMs(snapshot.allTotalMs()) + " | Other "
152+
+ formatMs(unattributedMs));
153+
lines.add("Top hacks: total " + (usingWindowData ? "ms/s" : "ms")
154+
+ " (peak callback ms)");
155+
if(snapshot.hiddenRowsTotalMs() > 0.01)
156+
lines.add("Hidden by row limit: "
157+
+ formatMs(snapshot.hiddenRowsTotalMs()));
158+
146159
for(HackPerformanceTracker.Row row : rows)
147160
{
148161
StringBuilder sb = new StringBuilder(row.name());
149-
sb.append(" | T ").append(formatMs(row.totalMs()));
150-
if(otf.shouldShowUpdate())
151-
sb.append(" U ").append(formatMs(row.updateMs()));
152-
if(otf.shouldShowRender())
153-
sb.append(" R ").append(formatMs(row.renderMs()));
154-
if(otf.shouldShowGui())
155-
sb.append(" G ").append(formatMs(row.guiMs()));
156-
sb.append(" | P ").append(formatMs(row.peakMs()));
162+
sb.append(" | ").append(formatMs(row.totalMs()));
163+
sb.append(" (peak ").append(formatMs(row.peakMs())).append(")");
164+
165+
if(otf.shouldShowUpdate() || otf.shouldShowRender()
166+
|| otf.shouldShowGui())
167+
{
168+
sb.append(" [");
169+
boolean wroteAnyBreakdown = false;
170+
if(otf.shouldShowUpdate())
171+
{
172+
sb.append("update ").append(formatMs(row.updateMs()));
173+
wroteAnyBreakdown = true;
174+
}
175+
if(otf.shouldShowRender())
176+
{
177+
if(wroteAnyBreakdown)
178+
sb.append(", ");
179+
sb.append("world ").append(formatMs(row.renderMs()));
180+
wroteAnyBreakdown = true;
181+
}
182+
if(otf.shouldShowGui())
183+
{
184+
if(wroteAnyBreakdown)
185+
sb.append(", ");
186+
sb.append("gui ").append(formatMs(row.guiMs()));
187+
}
188+
sb.append("]");
189+
}
157190
lines.add(sb.toString());
158191
}
159192

@@ -191,18 +224,14 @@ private PerformanceOverlayOtf getSettings()
191224
return WurstClient.INSTANCE.getOtfs().performanceOverlayOtf;
192225
}
193226

194-
private void updateGraphSample(List<HackPerformanceTracker.Row> rows)
227+
private void updateGraphSample(double allHackTotalMs)
195228
{
196229
long now = System.currentTimeMillis();
197230
if(now - lastGraphSampleMs < GRAPH_SAMPLE_INTERVAL_MS)
198231
return;
199232

200233
lastGraphSampleMs = now;
201-
double totalMs = 0;
202-
for(HackPerformanceTracker.Row row : rows)
203-
totalMs += row.totalMs();
204-
205-
pushGraphSample(totalMs);
234+
pushGraphSample(allHackTotalMs);
206235
}
207236

208237
private void pushGraphSample(double value)

src/main/java/net/wurstclient/util/HackPerformanceTracker.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,29 @@ public static ListSnapshot getTopRows(int maxRows, SortMode sortMode)
9090
rows.sort(Comparator.comparingDouble(Row::totalMs).reversed());
9191

9292
int limit = Math.max(1, maxRows);
93-
if(rows.size() > limit)
94-
rows = new ArrayList<>(rows.subList(0, limit));
93+
double allUpdateMs = 0;
94+
double allRenderMs = 0;
95+
double allGuiMs = 0;
96+
double allTotalMs = 0;
97+
for(Row row : rows)
98+
{
99+
allUpdateMs += row.updateMs();
100+
allRenderMs += row.renderMs();
101+
allGuiMs += row.guiMs();
102+
allTotalMs += row.totalMs();
103+
}
104+
105+
ArrayList<Row> visibleRows = rows;
106+
if(visibleRows.size() > limit)
107+
visibleRows = new ArrayList<>(visibleRows.subList(0, limit));
108+
109+
double visibleTotalMs = 0;
110+
for(Row row : visibleRows)
111+
visibleTotalMs += row.totalMs();
95112

96-
return new ListSnapshot(rows, hasCompletedWindow);
113+
return new ListSnapshot(visibleRows, hasCompletedWindow,
114+
allUpdateMs, allRenderMs, allGuiMs, allTotalMs,
115+
allTotalMs - visibleTotalMs);
97116
}
98117
}
99118

@@ -193,6 +212,8 @@ public record Row(String name, double updateMs, double renderMs,
193212
double guiMs, double totalMs, double peakMs)
194213
{}
195214

196-
public record ListSnapshot(ArrayList<Row> rows, boolean usingWindowData)
215+
public record ListSnapshot(ArrayList<Row> rows, boolean usingWindowData,
216+
double allUpdateMs, double allRenderMs, double allGuiMs,
217+
double allTotalMs, double hiddenRowsTotalMs)
197218
{}
198219
}

0 commit comments

Comments
 (0)