forked from cev-api/Wurst7-CevAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWardenEspHack.java
More file actions
596 lines (537 loc) · 17.8 KB
/
Copy pathWardenEspHack.java
File metadata and controls
596 lines (537 loc) · 17.8 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*
* 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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.monster.warden.AngerLevel;
import net.minecraft.world.entity.monster.warden.Warden;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.wurstclient.Category;
import net.wurstclient.hack.Hack;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.settings.EnumSetting;
import net.wurstclient.settings.SliderSetting;
import com.mojang.math.Axis;
import net.minecraft.client.gui.Font;
import net.wurstclient.util.EntityUtils;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RenderUtils.ColoredBox;
import net.wurstclient.util.RenderUtils.ColoredPoint;
/**
* Simple Warden ESP: color-coded shapes and minimal indicators.
* Uses client-side Warden state (poses, synced anger) for reliability.
*/
public final class WardenEspHack extends Hack
implements UpdateListener, RenderListener
{
// map entity id -> last known highest anger (for trend)
private final Map<Integer, Integer> lastAnger = new HashMap<>();
private final Map<Integer, Long> attackExpiry = new HashMap<>();
// detected wardens for rendering
private final List<LivingEntity> wardens = new ArrayList<>();
// debugging: last found count to log when changes occur
private int lastFoundCount = -1;
private final WardenEspStyleSetting style = new WardenEspStyleSetting();
private final CheckboxSetting fillShapes = new CheckboxSetting(
"Fill shapes", "Render filled versions of the ESP shapes.", false);
private final EnumSetting<TracerMode> tracerMode =
new EnumSetting<>("Tracers", TracerMode.values(), TracerMode.TARGETING);
private final CheckboxSetting tracerFlash = new CheckboxSetting(
"Tracer flash", "Make tracers pulse with a smooth fade.", false);
private final CheckboxSetting showTargetLabel = new CheckboxSetting(
"Target label", "Show TARGET: YOU/OTHER label.", true);
private final CheckboxSetting showSniffingPulse =
new CheckboxSetting("Sniff pulse",
"Show a brief pulsing overlay when the Warden is sniffing.", true);
private final CheckboxSetting showImminentIndicator =
new CheckboxSetting("Combat imminence",
"Show an indicator when combat/sonic attack is imminent.", true);
private final CheckboxSetting showAngerTrend =
new CheckboxSetting("Anger trend",
"Show a simple up/down indicator when anger changes.", false);
private final SliderSetting labelScale = new SliderSetting("Label scale",
1.2, 0.7, 10.0, 0.1, SliderSetting.ValueDisplay.DECIMAL);
public WardenEspHack()
{
super("WardenESP");
setCategory(Category.RENDER);
addSetting(style);
addSetting(fillShapes);
addSetting(tracerMode);
addSetting(tracerFlash);
addSetting(showTargetLabel);
addSetting(showSniffingPulse);
addSetting(showImminentIndicator);
addSetting(showAngerTrend);
addSetting(labelScale);
}
@Override
protected void onEnable()
{
EVENTS.add(UpdateListener.class, this);
EVENTS.add(RenderListener.class, this);
}
@Override
protected void onDisable()
{
EVENTS.remove(UpdateListener.class, this);
EVENTS.remove(RenderListener.class, this);
wardens.clear();
lastAnger.clear();
attackExpiry.clear();
}
@Override
public void onUpdate()
{
wardens.clear();
for(Entity e : MC.level.entitiesForRendering())
{
if(!(e instanceof LivingEntity le))
continue;
if(e.isRemoved() || (le.getHealth() <= 0))
continue;
// Prefer checking the entity type to handle mapped/obfuscated names
if(e.getType() == net.wurstclient.util.RegistryUtils
.entityType("warden"))
wardens.add(le);
}
int sz = wardens.size();
if(sz != lastFoundCount)
{
lastFoundCount = sz;
System.out.println("WardenESP: found wardens = " + sz);
}
}
@Override
public void onRender(PoseStack matrixStack, float partialTicks)
{
if(wardens.isEmpty())
return;
WardenEspStyleSetting.Shape shape = style.getShape();
boolean glowMode = shape == WardenEspStyleSetting.Shape.GLOW;
boolean drawShape =
!glowMode && shape != WardenEspStyleSetting.Shape.NONE;
boolean drawFill = drawShape && fillShapes.isChecked();
List<ColoredBox> outlineShapes = drawShape ? new ArrayList<>() : null;
List<ColoredBox> filledShapes = drawFill ? new ArrayList<>() : null;
List<ColoredPoint> tracerPoints =
tracerMode.getSelected() == TracerMode.OFF ? null
: new ArrayList<>();
for(LivingEntity w : wardens)
{
try
{
if(!(w instanceof Warden warden))
continue;
AABB lerped = EntityUtils.getLerpedBox(w, partialTicks);
// default state = CALM (green)
int color = 0xFF55FF55; // green
int anger = warden.getClientAngerLevel();
// update trend store
Integer prev = lastAnger.get(w.getId());
lastAnger.put(w.getId(), anger);
AngerLevel angerLevel = AngerLevel.byAnger(anger);
// sniffing detection
boolean sniffing = warden.getPose() == Pose.SNIFFING;
// digging/leaving detection
boolean digging = warden.getPose() == Pose.DIGGING;
boolean emerging = warden.getPose() == Pose.EMERGING;
// combat imminence: sonic boom charge / melee swing
long boomChargeTicks = warden.getBrain().getTimeUntilExpiry(
MemoryModuleType.SONIC_BOOM_SOUND_DELAY);
boolean sonicCharge = boomChargeTicks > 0;
boolean attackAnim =
warden.getAttackAnim(partialTicks) > 0.2F || warden.swinging
|| warden.attackAnimationState.isStarted();
boolean imminent = sonicCharge || attackAnim
|| warden.sonicBoomAnimationState.isStarted();
long nowTick = warden.tickCount;
if(imminent)
attackExpiry.put(w.getId(), nowTick + 100L);
long expiry = attackExpiry.getOrDefault(w.getId(), 0L);
boolean attackFlash =
nowTick <= expiry && !digging && !emerging;
// attack target detection: try direct target or brain memory
boolean lockedOnYou = false;
boolean lockedOnOther = false;
LivingEntity target = warden.getTarget();
if(target == null)
target = warden.getBrain()
.getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
boolean hasTarget = target != null;
if(hasTarget)
{
if(target == MC.player)
lockedOnYou = true;
else
lockedOnOther = true;
}
boolean locked = hasTarget || angerLevel.isAngry()
|| lockedOnYou || lockedOnOther;
boolean calm =
angerLevel == AngerLevel.CALM && !locked && !sniffing;
// determine color state from anger/sniffing
if(locked)
color = 0xFFFF5555; // red LOCKED
else if(sniffing || angerLevel == AngerLevel.AGITATED)
color = 0xFFFFAA00; // orange -> sniffing as AGITATED visual
else if(anger > 0)
color = 0xFFFFFF55; // yellow SEARCHING/AGITATED
else
color = 0xFF55FF55; // green CALM
// if digging/ leaving show blue-ish
if(digging || emerging)
color = 0xFF55FFFF;
if(attackFlash)
color = getFastPulseColor(0xFFFF5555, 0.35F);
if(drawShape)
outlineShapes.add(new ColoredBox(lerped, color));
if(filledShapes != null)
{
int fill = (color & 0x00FFFFFF) | 0x33000000;
filledShapes.add(new ColoredBox(lerped, fill));
}
if(tracerPoints != null)
{
boolean drawTracer = switch(tracerMode.getSelected())
{
case ALWAYS -> true;
case TARGETING -> hasTarget || locked || imminent;
default -> false;
};
if(drawTracer)
{
int tracerColor;
if(attackFlash)
tracerColor = getFastPulseColor(0xFFFF5555, 0.35F);
else if(lockedOnYou)
tracerColor = getPulseColor(0xFFFF5555, 0.55F);
else
tracerColor = color;
if(tracerFlash.isChecked())
tracerColor = RenderUtils.flashColor(tracerColor);
tracerPoints.add(
new ColoredPoint(lerped.getCenter(), tracerColor));
}
}
// sniffing pulsing overlay: add semi-transparent filled box
if(!glowMode && sniffing && showSniffingPulse.isChecked())
{
float pulse = (float)(0.5
+ 0.5 * Math.sin(System.currentTimeMillis() / 200.0));
int fill = ((int)(MthClamp(pulse) * 255) << 24)
| (0xFFFFAA00 & 0x00FFFFFF);
RenderUtils.drawSolidBoxes(matrixStack,
java.util.Collections.singletonList(
new ColoredBox(lerped, fill)),
false);
}
// Render text labels above the warden
float labelScaleValue = getLabelScale();
float lineSpacing = 12F * (0.9F + 0.1F * labelScaleValue);
float baseOffset = (float)(lerped.getYsize() / 2.0 + 0.55
+ 0.25 * (labelScaleValue - 1.0));
int textColor = color; // reuse box color
// top: imminent
int line = 0;
if(attackFlash && showImminentIndicator.isChecked())
{
drawWorldLabel(matrixStack, "⚠ ATTACK",
lerped.getCenter().x, lerped.getCenter().y + baseOffset,
lerped.getCenter().z, 0xFFFF5555,
1.15F * labelScaleValue, -lineSpacing * line);
line += 1;
}
// main awareness state
String mainState = "CALM";
if(locked)
mainState = "LOCKED";
else if(sniffing || angerLevel == AngerLevel.AGITATED)
mainState = "AGITATED";
else if(anger > 0)
mainState = "SEARCHING";
drawWorldLabel(matrixStack, mainState, lerped.getCenter().x,
lerped.getCenter().y + baseOffset, lerped.getCenter().z,
textColor, labelScaleValue, -lineSpacing * line);
line += 1;
// target
if((lockedOnYou || lockedOnOther)
&& showTargetLabel.isChecked())
{
String tgt = lockedOnYou ? "TARGET: YOU" : "TARGET: OTHER";
int tc = lockedOnYou
? (attackFlash ? getFastPulseColor(0xFFFF5555, 0.35F)
: getPulseColor(0xFFFF5555, 0.6F))
: 0xFFAAAAAA;
drawWorldLabel(matrixStack, tgt, lerped.getCenter().x,
lerped.getCenter().y + baseOffset, lerped.getCenter().z,
tc, 0.95F * labelScaleValue, -lineSpacing * line);
line += 1;
}
// sniffing
if(sniffing && showSniffingPulse.isChecked())
{
drawWorldLabel(matrixStack, "SNIFFING",
lerped.getCenter().x, lerped.getCenter().y + baseOffset,
lerped.getCenter().z, 0xFFFFFFAA,
0.9F * labelScaleValue, -lineSpacing * line);
line += 1;
}
// digging
if(digging || emerging)
{
String label = digging ? "DIGGING" : "EMERGING";
drawWorldLabel(matrixStack, label, lerped.getCenter().x,
lerped.getCenter().y + baseOffset, lerped.getCenter().z,
0xFF55FFFF, 0.9F * labelScaleValue,
-lineSpacing * line);
line += 1;
}
// anger trend arrow
if(showAngerTrend.isChecked() && prev != null)
{
int delta = anger - prev;
if(delta != 0)
{
Vec3 top = lerped.getCenter().add(0,
lerped.getYsize() / 2.0, 0);
Vec3 to = top.add(0, delta > 0 ? 0.6 : -0.6, 0);
int col = delta > 0 ? 0xFFFFFF55 : 0xFF55FF55;
RenderUtils.drawLine(matrixStack, top, to, col, false);
}
}
}catch(Throwable t)
{
// ignore per-entity errors
}
}
if(drawShape)
{
if(filledShapes != null && !filledShapes.isEmpty())
{
switch(shape)
{
case BOX -> RenderUtils.drawSolidBoxes(matrixStack,
filledShapes, false);
case OCTAHEDRON -> RenderUtils
.drawSolidOctahedrons(matrixStack, filledShapes, false);
default ->
{
}
}
}
if(outlineShapes != null && !outlineShapes.isEmpty())
{
switch(shape)
{
case BOX -> RenderUtils.drawOutlinedBoxes(matrixStack,
outlineShapes, false);
case OCTAHEDRON -> RenderUtils.drawOutlinedOctahedrons(
matrixStack, outlineShapes, false);
default ->
{
}
}
}
}
if(tracerPoints != null && !tracerPoints.isEmpty())
{
double lineWidth =
tracerMode.getSelected() == TracerMode.ALWAYS ? 1.8 : 2.8;
RenderUtils.drawTracers(matrixStack, partialTicks, tracerPoints,
false, lineWidth);
}
}
private void drawWorldLabel(PoseStack matrices, String text, double x,
double y, double z, int argb, float scale, float offsetPx)
{
matrices.pushPose();
Vec3 cam = RenderUtils.getCameraPos();
matrices.translate(x - cam.x, y - cam.y, z - cam.z);
var camEntity = MC.getCameraEntity();
if(camEntity != null)
{
matrices.mulPose(Axis.YP.rotationDegrees(-camEntity.getYRot()));
matrices.mulPose(Axis.XP.rotationDegrees(camEntity.getXRot()));
}
matrices.mulPose(Axis.YP.rotationDegrees(180.0F));
// Smaller when close, smoothly ramps up with distance for readability.
double dx = x - cam.x;
double dy = y - cam.y;
double dz = z - cam.z;
float distance = (float)Math.sqrt(dx * dx + dy * dy + dz * dz);
float distanceFactor = getDistanceLabelFactor(distance);
float s = 0.018F * scale * distanceFactor;
matrices.scale(s, -s, s);
matrices.translate(0, offsetPx, 0);
Font tr = MC.font;
float w = tr.width(text) / 2F;
int baseAlpha = (argb >>> 24) & 0xFF;
int bgAlpha =
(int)Math.round(MC.options.getBackgroundOpacity(0.25F) * baseAlpha);
int bg = (bgAlpha << 24);
var matrix = matrices.last().pose();
// stroke for legibility
int strokeColor =
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(tr, text, -w,
0, argb, strokeColor, matrix, Font.DisplayMode.SEE_THROUGH, bg,
0xF000F0);
matrices.popPose();
}
private static float getDistanceLabelFactor(float distance)
{
// <=4m: 30% size, >=28m: 100% size
if(distance <= 4F)
return 0.30F;
if(distance >= 28F)
return 1.00F;
return 0.30F + (distance - 4F) / 24F * 0.70F;
}
private static float MthClamp(float v)
{
if(Float.isNaN(v))
return 0F;
if(v < 0F)
return 0F;
if(v > 1F)
return 1F;
return v;
}
private float getLabelScale()
{
return (float)labelScale.getValue();
}
private static int getPulseColor(int argb, float minBrightness)
{
return getPulseColor(argb, minBrightness, 180.0);
}
private static int getFastPulseColor(int argb, float minBrightness)
{
return getPulseColor(argb, minBrightness, 90.0);
}
private static int getPulseColor(int argb, float minBrightness,
double speedMs)
{
float pulse =
(float)(0.5 + 0.5 * Math.sin(System.currentTimeMillis() / speedMs));
float t = minBrightness + (1F - minBrightness) * pulse;
int a = (argb >>> 24) & 0xFF;
int r = (argb >>> 16) & 0xFF;
int g = (argb >>> 8) & 0xFF;
int b = argb & 0xFF;
r = (int)Math.min(255, r * t);
g = (int)Math.min(255, g * t);
b = (int)Math.min(255, b * t);
return (a << 24) | (r << 16) | (g << 8) | b;
}
public Integer getGlowColor(LivingEntity entity)
{
if(!isEnabled())
return null;
if(style.getShape() != WardenEspStyleSetting.Shape.GLOW)
return null;
if(!(entity instanceof Warden warden))
return null;
if(!wardens.contains(entity))
return null;
int anger = warden.getClientAngerLevel();
AngerLevel angerLevel = AngerLevel.byAnger(anger);
boolean sniffing = warden.getPose() == Pose.SNIFFING;
boolean digging = warden.getPose() == Pose.DIGGING;
boolean emerging = warden.getPose() == Pose.EMERGING;
LivingEntity target = warden.getTarget();
if(target == null)
target = warden.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET)
.orElse(null);
boolean lockedOnYou = target == MC.player;
boolean hasTarget = target != null;
boolean locked = hasTarget || angerLevel.isAngry() || lockedOnYou;
long expiry = attackExpiry.getOrDefault(warden.getId(), 0L);
long now = warden.tickCount;
boolean attackActive = now <= expiry && !digging && !emerging;
int color = 0xFF55FF55;
if(locked)
color = 0xFFFF5555;
else if(sniffing || angerLevel == AngerLevel.AGITATED)
color = 0xFFFFAA00;
else if(anger > 0)
color = 0xFFFFFF55;
if(digging || emerging)
color = 0xFF55FFFF;
if(lockedOnYou)
color = getPulseColor(color, 0.6F);
if(attackActive)
color = getFastPulseColor(0xFFFF5555, 0.35F);
return color;
}
private enum TracerMode
{
OFF("Off"),
TARGETING("When targeting"),
ALWAYS("Always");
private final String name;
private TracerMode(String name)
{
this.name = name;
}
@Override
public String toString()
{
return name;
}
}
private static final class WardenEspStyleSetting
extends EnumSetting<WardenEspStyleSetting.Style>
{
private WardenEspStyleSetting()
{
super("ESP type", Style.values(), Style.BOX);
}
public Shape getShape()
{
return getSelected().shape;
}
enum Shape
{
NONE,
BOX,
OCTAHEDRON,
GLOW;
}
private enum Style
{
BOX("Box", Shape.BOX),
OCTAHEDRON("Octahedron", Shape.OCTAHEDRON),
GLOW("Glow", Shape.GLOW),
NONE("None", Shape.NONE);
private final String name;
private final Shape shape;
private Style(String name, Shape shape)
{
this.name = name;
this.shape = shape;
}
@Override
public String toString()
{
return name;
}
}
}
}