Skip to content

Commit b5c8fba

Browse files
committed
NiceWurst ESP Fix
1 parent aa8d7c3 commit b5c8fba

File tree

5 files changed

+312
-35
lines changed

5 files changed

+312
-35
lines changed

src/main/java/net/wurstclient/WurstRenderLayers.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public enum WurstRenderLayers
6767
"wurst:quads", 1536, false, true, WurstShaderPipelines.QUADS,
6868
RenderLayer.MultiPhaseParameters.builder().build(false));
6969

70+
/**
71+
* Similar to {@link RenderLayer#getDebugQuads()}, but without back-face
72+
* culling.
73+
*/
74+
public static final RenderLayer.MultiPhase QUADS_NO_CULLING =
75+
RenderLayer.of("wurst:quads_no_culling", 1536, false, true,
76+
WurstShaderPipelines.QUADS_NO_CULLING,
77+
RenderLayer.MultiPhaseParameters.builder().build(false));
78+
7079
/**
7180
* Similar to {@link RenderLayer#getDebugQuads()}, but with culling enabled
7281
* and no depth test.

src/main/java/net/wurstclient/WurstShaderPipelines.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public enum WurstShaderPipelines
8080
.withDepthTestFunction(DepthTestFunction.LEQUAL_DEPTH_TEST)
8181
.build());
8282

83+
/**
84+
* Similar to the DEBUG_QUADS ShaderPipeline, but with no back-face culling.
85+
*/
86+
public static final RenderPipeline QUADS_NO_CULLING = RenderPipelines
87+
.register(RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET)
88+
.withLocation(
89+
Identifier.of("wurst:pipeline/wurst_quads_no_culling"))
90+
.withCull(false)
91+
.withDepthTestFunction(DepthTestFunction.LEQUAL_DEPTH_TEST)
92+
.build());
93+
8394
/**
8495
* Similar to the DEBUG_QUADS ShaderPipeline, but with culling enabled
8596
* and no depth test.

src/main/java/net/wurstclient/nicewurst/NiceWurstModule.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
import java.util.Set;
1919
import java.util.TreeMap;
2020

21+
import net.minecraft.client.render.Camera;
22+
import net.minecraft.client.render.RenderLayer;
23+
import net.minecraft.util.hit.BlockHitResult;
24+
import net.minecraft.util.hit.HitResult;
25+
import net.minecraft.util.math.BlockPos;
26+
import net.minecraft.util.math.Vec3d;
27+
import net.minecraft.world.RaycastContext;
2128
import net.wurstclient.Category;
2229
import net.wurstclient.Feature;
2330
import net.wurstclient.WurstClient;
@@ -28,6 +35,7 @@
2835
import net.wurstclient.other_feature.OtfList;
2936
import net.wurstclient.other_feature.OtherFeature;
3037
import net.wurstclient.events.UpdateListener;
38+
import net.wurstclient.WurstRenderLayers;
3139

3240
public final class NiceWurstModule
3341
{
@@ -53,6 +61,10 @@ public final class NiceWurstModule
5361
"net.wurstclient.hacks.PortalEspHack",
5462
"net.wurstclient.hacks.SearchHack",
5563
"net.wurstclient.hacks.TridentEspHack");
64+
private static final Set<String> ENTITY_OVERLAY_CALLERS =
65+
Set.of("net.wurstclient.hacks.MobEspHack");
66+
private static final Set<String> TRACER_VISIBILITY_EXCEPTIONS =
67+
Set.of("net.wurstclient.hacks.WaypointsHack");
5668

5769
private static boolean applied;
5870

@@ -138,6 +150,9 @@ public static boolean enforceDepthTest(boolean originalDepthTest)
138150
if(originalDepthTest || !isActive())
139151
return originalDepthTest;
140152

153+
if(isEntityOverlayCall())
154+
return originalDepthTest;
155+
141156
for(StackTraceElement element : Thread.currentThread().getStackTrace())
142157
{
143158
if(DEPTH_TEST_CALLERS.contains(element.getClassName()))
@@ -147,6 +162,99 @@ public static boolean enforceDepthTest(boolean originalDepthTest)
147162
return originalDepthTest;
148163
}
149164

165+
public static RenderLayer.MultiPhase enforceDepthTest(
166+
RenderLayer.MultiPhase originalLayer)
167+
{
168+
if(!isActive() || originalLayer == null)
169+
return originalLayer;
170+
171+
if(isEntityOverlayCall())
172+
return originalLayer;
173+
174+
if(originalLayer == WurstRenderLayers.ESP_QUADS)
175+
return WurstRenderLayers.QUADS;
176+
177+
if(originalLayer == WurstRenderLayers.ESP_QUADS_NO_CULLING)
178+
return WurstRenderLayers.QUADS_NO_CULLING;
179+
180+
if(originalLayer == WurstRenderLayers.ESP_LINES)
181+
return WurstRenderLayers.LINES;
182+
183+
if(originalLayer == WurstRenderLayers.ESP_LINE_STRIP)
184+
return WurstRenderLayers.LINE_STRIP;
185+
186+
return originalLayer;
187+
}
188+
189+
public static boolean shouldEnforceTracerVisibility()
190+
{
191+
if(!isActive())
192+
return false;
193+
194+
for(StackTraceElement element : Thread.currentThread().getStackTrace())
195+
{
196+
if(TRACER_VISIBILITY_EXCEPTIONS.contains(element.getClassName()))
197+
return false;
198+
}
199+
200+
return true;
201+
}
202+
203+
public static boolean shouldRenderTarget(Vec3d target)
204+
{
205+
if(!isActive() || target == null)
206+
return true;
207+
208+
if(WurstClient.MC.world == null || WurstClient.MC.player == null)
209+
return true;
210+
211+
Camera camera = WurstClient.MC.gameRenderer.getCamera();
212+
if(camera == null)
213+
return true;
214+
215+
Vec3d from = camera.getPos();
216+
if(from == null)
217+
return true;
218+
219+
if(from.squaredDistanceTo(target) < 1e-6)
220+
return true;
221+
222+
RaycastContext context =
223+
new RaycastContext(from, target, RaycastContext.ShapeType.COLLIDER,
224+
RaycastContext.FluidHandling.NONE, WurstClient.MC.player);
225+
HitResult hit = WurstClient.MC.world.raycast(context);
226+
if(hit == null || hit.getType() == HitResult.Type.MISS)
227+
return true;
228+
229+
if(hit.getType() != HitResult.Type.BLOCK)
230+
return true;
231+
232+
BlockPos hitPos = ((BlockHitResult)hit).getBlockPos();
233+
BlockPos targetPos = BlockPos.ofFloored(target);
234+
if(hitPos.equals(targetPos))
235+
return true;
236+
237+
double targetDistSq = from.squaredDistanceTo(target);
238+
double hitDistSq = hit.getPos().squaredDistanceTo(from);
239+
return hitDistSq >= targetDistSq - 1e-3;
240+
}
241+
242+
public static boolean shouldOverlayEntityShapes()
243+
{
244+
return isActive() && isEntityOverlayCall();
245+
}
246+
247+
private static boolean isEntityOverlayCall()
248+
{
249+
for(StackTraceElement element : Thread.currentThread().getStackTrace())
250+
{
251+
if(ENTITY_OVERLAY_CALLERS.contains(element.getClassName()))
252+
return true;
253+
}
254+
255+
return false;
256+
}
257+
150258
private static void filterHackList(HackList hackList)
151259
{
152260
TreeMap<String, Hack> hackMap = getHackMap(hackList);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.minecraft.client.render.Tessellator;
3232
import net.minecraft.client.render.VertexConsumer;
3333
import net.minecraft.client.util.math.MatrixStack;
34+
import net.wurstclient.nicewurst.NiceWurstModule;
3435

3536
/**
3637
* An abstraction of Minecraft 1.21.5's new {@code GpuBuffer} system that makes
@@ -111,18 +112,21 @@ public void draw(MatrixStack matrixStack, RenderLayer.MultiPhase layer,
111112
if(vertexBuffer == null)
112113
return;
113114

115+
RenderLayer.MultiPhase effectiveLayer =
116+
NiceWurstModule.enforceDepthTest(layer);
117+
114118
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
115119
modelViewStack.pushMatrix();
116120
modelViewStack.mul(matrixStack.peek().getPositionMatrix());
117121

118-
layer.startDrawing();
122+
effectiveLayer.startDrawing();
119123
GpuBufferSlice gpuBufferSlice = RenderSystem.getDynamicUniforms().write(
120124
RenderSystem.getModelViewMatrix(),
121125
new Vector4f(red, green, blue, alpha), new Vector3f(),
122126
RenderSystem.getTextureMatrix(), RenderSystem.getShaderLineWidth());
123127

124-
Framebuffer framebuffer = layer.phases.target.get();
125-
RenderPipeline pipeline = layer.pipeline;
128+
Framebuffer framebuffer = effectiveLayer.phases.target.get();
129+
RenderPipeline pipeline = effectiveLayer.pipeline;
126130
GpuBuffer indexBuffer = shapeIndexBuffer.getIndexBuffer(indexCount);
127131

128132
try(RenderPass renderPass =
@@ -140,7 +144,7 @@ public void draw(MatrixStack matrixStack, RenderLayer.MultiPhase layer,
140144
renderPass.drawIndexed(0, 0, indexCount, 1);
141145
}
142146

143-
layer.endDrawing();
147+
effectiveLayer.endDrawing();
144148
modelViewStack.popMatrix();
145149
}
146150

0 commit comments

Comments
 (0)