forked from cev-api/Wurst7-CevAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogoutSpotsHack.java
More file actions
360 lines (336 loc) · 11 KB
/
Copy pathLogoutSpotsHack.java
File metadata and controls
360 lines (336 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks;
import com.mojang.blaze3d.vertex.PoseStack;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import net.minecraft.client.gui.Font;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.waypoints.Waypoint;
import net.wurstclient.waypoints.WaypointDimension;
@SearchTags({"logout spots", "logouts"})
public final class LogoutSpotsHack extends Hack
implements UpdateListener, RenderListener
{
public static record MapSpot(AABB box, String dimKey)
{}
private static final class Entry
{
final String name;
final AABB box;
final String dimKey;
final long createdAtMs;
Entry(String n, AABB b, String dim, long createdAtMs)
{
name = n;
box = b;
dimKey = dim;
this.createdAtMs = createdAtMs;
}
}
private final ColorSetting sideColor = new ColorSetting("Side color",
"Box sides color.", new Color(64, 128, 255, 64));
private final ColorSetting lineColor = new ColorSetting("Line color",
"Box outline color.", new Color(64, 128, 255, 192));
private final SliderSetting scale =
new SliderSetting("Name scale", 1.0, 0.5, 3.0, 0.1,
net.wurstclient.settings.SliderSetting.ValueDisplay.DECIMAL);
private final net.wurstclient.settings.CheckboxSetting showTracers =
new net.wurstclient.settings.CheckboxSetting("Show tracers", true);
private final net.wurstclient.settings.CheckboxSetting tracerFlash =
new net.wurstclient.settings.CheckboxSetting("Tracer flash",
"Make tracers pulse with a smooth fade.", false);
private final net.wurstclient.settings.CheckboxSetting addAsWaypoint =
new net.wurstclient.settings.CheckboxSetting(
"Add logout spot as waypoint", false);
private static final int INFINITE_LIFETIME_MARKER = 121;
private final SliderSetting spotLifetimeMinutes = new SliderSetting(
"Spot lifetime (minutes)", 60, 1, INFINITE_LIFETIME_MARKER, 1,
net.wurstclient.settings.SliderSetting.ValueDisplay.INTEGER
.withLabel(INFINITE_LIFETIME_MARKER, "Infinite"));
private final Map<UUID, Entry> spots = new HashMap<>();
private List<PlayerInfo> lastList = List.of();
private Map<UUID, Player> lastPlayers = Map.of();
private final Map<UUID, java.util.UUID> spotToWaypoint = new HashMap<>();
private String lastServerKey = "unknown";
public LogoutSpotsHack()
{
super("LogoutSpots");
setCategory(Category.INTEL);
addSetting(sideColor);
addSetting(lineColor);
addSetting(scale);
addSetting(showTracers);
addSetting(tracerFlash);
addSetting(spotLifetimeMinutes);
addSetting(addAsWaypoint);
}
public List<MapSpot> getMapaSpots()
{
return spots.values().stream().map(e -> new MapSpot(e.box, e.dimKey))
.toList();
}
public int getMapaLineColor()
{
return lineColor.getColorI(0xFF);
}
@Override
protected void onEnable()
{
clearAllSpots();
lastServerKey = resolveServerKey();
snapshot();
EVENTS.add(UpdateListener.class, this);
EVENTS.add(RenderListener.class, this);
}
@Override
protected void onDisable()
{
EVENTS.remove(UpdateListener.class, this);
EVENTS.remove(RenderListener.class, this);
clearAllSpots();
}
@Override
public void onUpdate()
{
String serverKeyNow = resolveServerKey();
if(!serverKeyNow.equals(lastServerKey))
{
clearAllSpots();
lastList = List.of();
lastPlayers = Map.of();
lastServerKey = serverKeyNow;
}
if(MC.getConnection() == null || MC.level == null)
return;
var nowList = MC.getConnection().getOnlinePlayers();
// Compare previous and current tab lists so we still catch logouts
// when someone else joins during the same tick.
var lastMap = new HashMap<UUID, PlayerInfo>();
for(var e : lastList)
lastMap.put(e.getProfile().id(), e);
var nowMap = new HashMap<UUID, PlayerInfo>();
for(var e : nowList)
nowMap.put(e.getProfile().id(), e);
for(var id : lastMap.keySet())
if(!nowMap.containsKey(id))
{
Player p = lastPlayers.get(id);
if(p != null)
{
AABB b = p.getBoundingBox();
long now = System.currentTimeMillis();
spots.put(id, new Entry(p.getName().getString(), b,
currentDimKey(), now));
// Optionally add a temporary waypoint for this logout spot
if(addAsWaypoint.isChecked()
&& WURST.getHax().waypointsHack != null)
{
Waypoint w =
new Waypoint(java.util.UUID.randomUUID(), now);
w.setName("Logout: " + p.getName().getString());
w.setIcon("skull");
w.setColor(0xFF88CCFF);
w.setPos(new net.minecraft.core.BlockPos((int)p.getX(),
(int)p.getY(), (int)p.getZ()));
// set waypoint dimension based on current world
w.setDimension(mapDimKeyToWaypointDim(currentDimKey()));
w.setActionWhenNear(Waypoint.ActionWhenNear.DELETE);
w.setActionWhenNearDistance(4);
w.setLines(showTracers.isChecked());
// add as temporary waypoint via WaypointsHack API
java.util.UUID wpUuid = WURST.getHax().waypointsHack
.addTemporaryWaypoint(w);
spotToWaypoint.put(id, wpUuid);
}
}
}
snapshot();
// cull rejoined players
if(MC.level != null)
{
for(Player p : MC.level.players())
{
spots.remove(p.getUUID());
removeTemporaryWaypoint(p.getUUID());
}
}
int lifetimeMinutes = spotLifetimeMinutes.getValueI();
if(lifetimeMinutes < INFINITE_LIFETIME_MARKER && !spots.isEmpty())
{
long lifetimeMs = lifetimeMinutes * 60_000L;
long cutoff = System.currentTimeMillis() - lifetimeMs;
Iterator<Map.Entry<UUID, Entry>> it = spots.entrySet().iterator();
while(it.hasNext())
{
var entry = it.next();
if(entry.getValue().createdAtMs <= cutoff)
{
removeTemporaryWaypoint(entry.getKey());
it.remove();
}
}
}
}
private String currentDimKey()
{
if(MC.level == null)
return "overworld";
return MC.level.dimension().identifier().getPath();
}
private void snapshot()
{
if(MC.getConnection() != null)
lastList = new java.util.ArrayList<>(
MC.getConnection().getOnlinePlayers());
var map = new HashMap<UUID, Player>();
if(MC.level != null)
{
for(Player p : MC.level.players())
map.put(p.getUUID(), p);
}
lastPlayers = map;
}
private String resolveServerKey()
{
ServerData info = MC.getCurrentServer();
if(info != null)
{
if(info.ip != null && !info.ip.isEmpty())
return info.ip.replace(':', '_');
if(info.isRealm())
return "realms_" + (info.name == null ? "" : info.name);
if(info.name != null && !info.name.isEmpty())
return "server_" + info.name;
}
if(MC.hasSingleplayerServer())
return "singleplayer";
return "unknown";
}
private void clearAllSpots()
{
if(!spotToWaypoint.isEmpty() && WURST.getHax().waypointsHack != null)
{
for(java.util.UUID wp : new ArrayList<>(spotToWaypoint.values()))
WURST.getHax().waypointsHack.removeTemporaryWaypoint(wp);
}
spotToWaypoint.clear();
spots.clear();
}
private void removeTemporaryWaypoint(UUID playerId)
{
java.util.UUID wp = spotToWaypoint.remove(playerId);
if(wp != null && WURST.getHax().waypointsHack != null)
WURST.getHax().waypointsHack.removeTemporaryWaypoint(wp);
}
@Override
public void onRender(PoseStack matrices, float partialTicks)
{
if(spots.isEmpty())
return;
String curDim = currentDimKey();
int sides = sideColor.getColorI(0x40);
int lines = lineColor.getColorI(0xFF);
var boxes = new java.util.ArrayList<AABB>();
for(var e : spots.values())
if(e.dimKey.equals(curDim))
boxes.add(e.box);
if(boxes.isEmpty())
return;
RenderUtils.drawSolidBoxes(matrices, boxes, sides, false);
RenderUtils.drawOutlinedBoxes(matrices, boxes, lines, false);
// (Optional) draw tracers to centers
if(showTracers.isChecked())
{
var ends = boxes.stream().map(AABB::getCenter).toList();
int tracerColor = lines;
if(tracerFlash.isChecked())
tracerColor = RenderUtils.flashColor(tracerColor);
RenderUtils.drawTracers(matrices, partialTicks, ends, tracerColor,
false);
}
for(var e : spots.values())
{
if(!e.dimKey.equals(curDim))
continue;
var c = e.box.getCenter();
drawWorldLabel(matrices, e.name, c.x, e.box.maxY + 0.5, c.z,
0xFFFFFFFF, scale.getValueF());
}
}
private void drawWorldLabel(PoseStack matrices, String text, double x,
double y, double z, int argb, float scale)
{
matrices.pushPose();
net.minecraft.world.phys.Vec3 cam =
net.wurstclient.util.RenderUtils.getCameraPos();
net.minecraft.world.phys.Vec3 target =
new net.minecraft.world.phys.Vec3(x, y, z);
net.minecraft.world.phys.Vec3 dir = target.subtract(cam);
double dist = dir.length();
double lx = x;
double ly = y;
double lz = z;
if(dist > 1.0)
{
double anchor = Math.min(dist, 12.0);
net.minecraft.world.phys.Vec3 anchored =
cam.add(dir.scale(anchor / dist));
lx = anchored.x;
ly = anchored.y;
lz = anchored.z;
}
matrices.translate(lx - cam.x, ly - cam.y, lz - cam.z);
// Face the camera (billboard)
var camEntity = MC.getCameraEntity();
if(camEntity != null)
{
matrices.mulPose(
com.mojang.math.Axis.YP.rotationDegrees(-camEntity.getYRot()));
matrices.mulPose(
com.mojang.math.Axis.XP.rotationDegrees(camEntity.getXRot()));
}
matrices.mulPose(com.mojang.math.Axis.YP.rotationDegrees(180.0F));
float s = 0.025F * net.wurstclient.util.RenderUtils
.getCappedWorldLabelScale(scale, dist);
matrices.scale(s, -s, s);
Font tr = MC.font;
float w = tr.width(text) / 2F;
int bg = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
var matrix = matrices.last().pose();
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, 0, argb,
false, matrix, null, Font.DisplayMode.SEE_THROUGH, bg, 0xF000F0);
matrices.popPose();
}
private WaypointDimension mapDimKeyToWaypointDim(String dimKey)
{
return switch(dimKey == null ? "overworld" : dimKey)
{
case "overworld" -> WaypointDimension.OVERWORLD;
case "nether" -> WaypointDimension.NETHER;
case "end" -> WaypointDimension.END;
default -> WaypointDimension.OVERWORLD;
};
}
}