blur module

blur: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Meteor Client, OfflineClient).

2 implementationsRenderRENDER

Clients with this module

Full module source: 2 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/Blur.javaJava · 280 lines · 10.2 KB

Blurs background when in GUI screens.

Settingsstrengthfade-timemeteorinventorieschatother
Blur.javaJava · Minecraft 26.2 · 280 lines · 10.2 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.render;
7
8
import com.mojang.blaze3d.GpuFormat;
9
import com.mojang.blaze3d.buffers.GpuBufferSlice;
10
import com.mojang.blaze3d.buffers.Std140Builder;
11
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
12
import com.mojang.blaze3d.pipeline.RenderPipeline;
13
import com.mojang.blaze3d.systems.RenderSystem;
14
import com.mojang.blaze3d.textures.FilterMode;
15
import com.mojang.blaze3d.textures.GpuTextureView;
16
import it.unimi.dsi.fastutil.ints.IntFloatImmutablePair;
17
import meteordevelopment.meteorclient.MeteorClient;
18
import meteordevelopment.meteorclient.events.game.ResolutionChangedEvent;
19
import meteordevelopment.meteorclient.events.render.RenderAfterWorldEvent;
20
import meteordevelopment.meteorclient.gui.WidgetScreen;
21
import meteordevelopment.meteorclient.renderer.FixedUniformStorage;
22
import meteordevelopment.meteorclient.renderer.MeshRenderer;
23
import meteordevelopment.meteorclient.renderer.MeteorRenderPipelines;
24
import meteordevelopment.meteorclient.settings.BoolSetting;
25
import meteordevelopment.meteorclient.settings.IntSetting;
26
import meteordevelopment.meteorclient.settings.Setting;
27
import meteordevelopment.meteorclient.settings.SettingGroup;
28
import meteordevelopment.meteorclient.systems.modules.Categories;
29
import meteordevelopment.meteorclient.systems.modules.Module;
30
import meteordevelopment.orbit.listeners.ConsumerListener;
31
import net.minecraft.client.gui.screens.ChatScreen;
32
import net.minecraft.client.gui.screens.Screen;
33
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
34
import net.minecraft.client.renderer.DynamicUniformStorage;
35
import org.jspecify.annotations.NonNull;
36
37
import java.nio.ByteBuffer;
38
39
public class Blur extends Module {
40
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
41
    private final SettingGroup sgScreens = settings.createGroup("Screens");
42
43
    // Strength-Levels from https://github.com/jonaburg/picom/blob/a8445684fe18946604848efb73ace9457b29bf80/src/backend/backend_common.c#L372
44
    private final IntFloatImmutablePair[] strengths = new IntFloatImmutablePair[]{
45
        IntFloatImmutablePair.of(1, 1.25f), // LVL 1
46
        IntFloatImmutablePair.of(1, 2.25f), // LVL 2
47
        IntFloatImmutablePair.of(2, 2.0f),  // LVL 3
48
        IntFloatImmutablePair.of(2, 3.0f),  // LVL 4
49
        IntFloatImmutablePair.of(2, 4.25f), // LVL 5
50
        IntFloatImmutablePair.of(3, 2.5f),  // LVL 6
51
        IntFloatImmutablePair.of(3, 3.25f), // LVL 7
52
        IntFloatImmutablePair.of(3, 4.25f), // LVL 8
53
        IntFloatImmutablePair.of(3, 5.5f),  // LVL 9
54
        IntFloatImmutablePair.of(4, 3.25f), // LVL 10
55
        IntFloatImmutablePair.of(4, 4.0f),  // LVL 11
56
        IntFloatImmutablePair.of(4, 5.0f),  // LVL 12
57
        IntFloatImmutablePair.of(4, 6.0f),  // LVL 13
58
        IntFloatImmutablePair.of(4, 7.25f), // LVL 14
59
        IntFloatImmutablePair.of(4, 8.25f), // LVL 15
60
        IntFloatImmutablePair.of(5, 4.5f),  // LVL 16
61
        IntFloatImmutablePair.of(5, 5.25f), // LVL 17
62
        IntFloatImmutablePair.of(5, 6.25f), // LVL 18
63
        IntFloatImmutablePair.of(5, 7.25f), // LVL 19
64
        IntFloatImmutablePair.of(5, 8.5f)   // LVL 20
65
    };
66
67
    // General
68
    private final Setting<Integer> strength = sgGeneral.add(new IntSetting.Builder()
69
        .name("strength")
70
        .description("How strong the blur should be.")
71
        .defaultValue(5)
72
        .min(1)
73
        .max(20)
74
        .sliderRange(1, 20)
75
        .build()
76
    );
77
78
    private final Setting<Integer> fadeTime = sgGeneral.add(new IntSetting.Builder()
79
        .name("fade-time")
80
        .description("How long the fade will last in milliseconds.")
81
        .defaultValue(100)
82
        .min(0)
83
        .sliderMax(500)
84
        .build()
85
    );
86
87
    // Screens
88
89
    private final Setting<Boolean> meteor = sgScreens.add(new BoolSetting.Builder()
90
        .name("meteor")
91
        .description("Applies blur to Meteor screens.")
92
        .defaultValue(true)
93
        .build());
94
95
    private final Setting<Boolean> inventories = sgScreens.add(new BoolSetting.Builder()
96
        .name("inventories")
97
        .description("Applies blur to inventory screens.")
98
        .defaultValue(true)
99
        .build()
100
    );
101
102
    private final Setting<Boolean> chat = sgScreens.add(new BoolSetting.Builder()
103
        .name("chat")
104
        .description("Applies blur when in chat.")
105
        .defaultValue(false)
106
        .build()
107
    );
108
109
    private final Setting<Boolean> other = sgScreens.add(new BoolSetting.Builder()
110
        .name("other")
111
        .description("Applies blur to all other screen types.")
112
        .defaultValue(true)
113
        .build()
114
    );
115
116
    private final GpuTextureView[] fbos = new GpuTextureView[6];
117
    private GpuBufferSlice[] ubos;
118
119
    private boolean enabled;
120
    private long fadeEndAt;
121
    private float previousOffset = -1;
122
123
    public Blur() {
124
        super(Categories.Render, "blur", "Blurs background when in GUI screens.");
125
126
        // Initialize fbos for the first time
127
        for (int i = 0; i < fbos.length; i++) {
128
            fbos[i] = createFbo(i);
129
        }
130
131
        // The listeners need to run even when the module is not enabled
132
        MeteorClient.EVENT_BUS.subscribe(new ConsumerListener<>(ResolutionChangedEvent.class, event -> {
133
            // Resize all fbos
134
            for (int i = 0; i < fbos.length; i++) {
135
                if (fbos[i] != null) {
136
                    fbos[i].close();
137
                }
138
139
                fbos[i] = createFbo(i);
140
            }
141
142
            // Invalidate ubos
143
            previousOffset = -1;
144
        }));
145
146
        MeteorClient.EVENT_BUS.subscribe(new ConsumerListener<>(RenderAfterWorldEvent.class, event -> onRenderAfterWorld()));
147
    }
148
149
    private GpuTextureView createFbo(int i) {
150
        double scale = 1 / Math.pow(2, i);
151
152
        int width = (int) (mc.getWindow().getWidth() * scale);
153
        int height = (int) (mc.getWindow().getHeight() * scale);
154
155
        return RenderSystem.getDevice().createTextureView(RenderSystem.getDevice().createTexture("Blur - " + i, 15, GpuFormat.RGBA8_UNORM, width, height, 1, 1));
156
    }
157
158
    private void onRenderAfterWorld() {
159
        // Enable / disable with fading
160
        boolean shouldRender = shouldRender();
161
        long time = System.currentTimeMillis();
162
163
        if (enabled) {
164
            if (!shouldRender) {
165
                if (fadeEndAt == -1) fadeEndAt = System.currentTimeMillis() + fadeTime.get();
166
167
                if (time >= fadeEndAt) {
168
                    enabled = false;
169
                    fadeEndAt = -1;
170
                }
171
            }
172
        } else {
173
            if (shouldRender) {
174
                enabled = true;
175
                fadeEndAt = System.currentTimeMillis() + fadeTime.get();
176
            }
177
        }
178
179
        if (!enabled) return;
180
181
        // Update progress
182
        double progress = 1;
183
184
        if (time < fadeEndAt) {
185
            if (shouldRender) progress = 1 - (fadeEndAt - time) / fadeTime.get().doubleValue();
186
            else progress = (fadeEndAt - time) / fadeTime.get().doubleValue();
187
        } else {
188
            fadeEndAt = -1;
189
        }
190
191
        // Update strength
192
        IntFloatImmutablePair strength = strengths[(int) ((this.strength.get() - 1) * progress)];
193
        int iterations = strength.leftInt();
194
        float offset = strength.rightFloat();
195
196
        // Update uniforms
197
        if (previousOffset != offset) {
198
            updateUniforms(offset);
199
            previousOffset = offset;
200
        }
201
202
        // Initial downsample
203
        renderToFbo(fbos[0], mc.gameRenderer.mainRenderTarget().getColorTextureView(), MeteorRenderPipelines.BLUR_DOWN, ubos[0]);
204
205
        // Downsample
206
        for (int i = 0; i < iterations; i++) {
207
            renderToFbo(fbos[i + 1], fbos[i], MeteorRenderPipelines.BLUR_DOWN, ubos[i + 1]);
208
        }
209
210
        // Upsample
211
        for (int i = iterations; i >= 1; i--) {
212
            renderToFbo(fbos[i - 1], fbos[i], MeteorRenderPipelines.BLUR_UP, ubos[i - 1]);
213
        }
214
215
        // Render output
216
        MeshRenderer.begin()
217
            .attachments(mc.gameRenderer.mainRenderTarget())
218
            .pipeline(MeteorRenderPipelines.BLUR_PASSTHROUGH)
219
            .fullscreen()
220
            .sampler("u_Texture", fbos[0], RenderSystem.getSamplerCache().getClampToEdge(FilterMode.LINEAR)) // todo ???
221
            .end();
222
    }
223
224
    private void renderToFbo(GpuTextureView targetFbo, GpuTextureView sourceTexture, RenderPipeline pipeline, GpuBufferSlice ubo) {
225
        MeshRenderer.begin()
226
            .attachments(targetFbo, null)
227
            .pipeline(pipeline)
228
            .fullscreen()
229
            .uniform("BlurData", ubo)
230
            .sampler("u_Texture", sourceTexture, RenderSystem.getSamplerCache().getClampToEdge(FilterMode.LINEAR))
231
            .end();
232
    }
233
234
    private boolean shouldRender() {
235
        if (!isActive()) return false;
236
        Screen screen = mc.gui.screen();
237
238
        if (screen instanceof WidgetScreen) return meteor.get();
239
        if (screen instanceof AbstractContainerScreen) return inventories.get();
240
        if (screen instanceof ChatScreen) return chat.get();
241
        if (screen != null) return other.get();
242
243
        return false;
244
    }
245
246
    // Uniforms
247
248
    private void updateUniforms(float offset) {
249
        UNIFORM_STORAGE.clear();
250
251
        BlurUniformData[] uboData = new BlurUniformData[6];
252
        for (int i = 0; i < uboData.length; i++) {
253
            GpuTextureView fbo = fbos[i];
254
            uboData[i] = new BlurUniformData(
255
                0.5f / fbo.getWidth(0), 0.5f / fbo.getHeight(0),
256
                offset
257
            );
258
        }
259
260
        ubos = UNIFORM_STORAGE.writeAll(uboData);
261
    }
262
263
    private static final int UNIFORM_SIZE = new Std140SizeCalculator()
264
        .putVec2()
265
        .putFloat()
266
        .get();
267
268
    private static final FixedUniformStorage<BlurUniformData> UNIFORM_STORAGE = new FixedUniformStorage<>("Meteor - Blur UBO", UNIFORM_SIZE, 6);
269
270
    private record BlurUniformData(float halfTexelSizeX, float halfTexelSizeY,
271
                                   float offset) implements DynamicUniformStorage.DynamicUniform {
272
        @Override
273
        public void write(@NonNull ByteBuffer buffer) {
274
            Std140Builder.intoBuffer(buffer)
275
                .putVec2(halfTexelSizeX, halfTexelSizeY)
276
                .putFloat(offset);
277
        }
278
    }
279
}
280
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/Blur.javaJava · 94 lines · 3.8 KB

Blurs the world behind menus and fades the blur in and out.

SettingsStrengthFade timeOwn menusInventoriesChatOther screens
Blur.javaJava · Minecraft 26.2 · 94 lines · 3.8 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.gui.GuiScreenBase;
4
import com.jellypudding.offlineclient.module.Category;
5
import com.jellypudding.offlineclient.module.Module;
6
import com.jellypudding.offlineclient.setting.BoolSetting;
7
import com.jellypudding.offlineclient.setting.NumberSetting;
8
import net.minecraft.client.gui.GuiGraphicsExtractor;
9
import net.minecraft.client.gui.screens.ChatScreen;
10
import net.minecraft.client.gui.screens.Screen;
11
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
12
import net.minecraft.client.renderer.GameRenderer;
13
14
// Reuses the game's own menu blur pass. The screen mixins ask for the blur
15
// stratum and GameRendererMixin feeds the radius in place of the video option.
16
public final class Blur extends Module {
17
18
    private static final String OWN_GUI_PACKAGE = GuiScreenBase.class.getPackageName();
19
20
    private final NumberSetting strength = new NumberSetting("Strength",
21
        "How far the blur spreads.", 5, 1, GameRenderer.MAX_BLUR_RADIUS, 1, "")
22
        .min(1).max(GameRenderer.MAX_BLUR_RADIUS);
23
    private final NumberSetting fadeTime = new NumberSetting("Fade time",
24
        "How long the blur takes to come and go.", 100, 0, 500, 10, " ms").min(0).max(2000);
25
    private final BoolSetting ownMenus = new BoolSetting("Own menus",
26
        "Blur behind the ClickGUI and the other menus of this client.", true);
27
    private final BoolSetting inventories = new BoolSetting("Inventories",
28
        "Blur behind your inventory and chests and every other container.", true);
29
    private final BoolSetting chat = new BoolSetting("Chat",
30
        "Blur behind the chat box.", false);
31
    private final BoolSetting others = new BoolSetting("Other screens",
32
        "Blur behind every other kind of screen such as the pause menu.", true);
33
34
    // How far the blur has faded in from nought to one.
35
    private float level;
36
    private long lastFrame;
37
38
    public Blur() {
39
        super("Blur", "Blurs the world behind menus and fades the blur in and out.", Category.RENDER);
40
        addSettings(strength, fadeTime, ownMenus, inventories, chat, others);
41
        searchTags("background", "menu");
42
    }
43
44
    @Override
45
    protected void onDisable() {
46
        level = 0;
47
    }
48
49
    // The radius the blur shader gets this frame. Runs once a frame before the GUI draws.
50
    public int radius(int vanilla) {
51
        if (!isEnabled()) {
52
            return vanilla;
53
        }
54
        long now = System.currentTimeMillis();
55
        float step = fadeTime.getInt() == 0 ? 1 : (now - lastFrame) / (float) fadeTime.getInt();
56
        lastFrame = now;
57
        float target = wants(mc.gui.screen()) ? 1 : 0;
58
        level = Math.clamp(level + Math.copySign(Math.min(step, 1), target - level), 0, 1);
59
        if (level == target && target == 0) {
60
            return vanilla;
61
        }
62
        return Math.max(1, Math.round(level * strength.getInt()));
63
    }
64
65
    // Whether the given screen sits on a blurred world.
66
    public boolean wants(Screen screen) {
67
        if (!isEnabled() || screen == null) {
68
            return false;
69
        }
70
        if (screen.getClass().getPackageName().startsWith(OWN_GUI_PACKAGE)) {
71
            return ownMenus.isOn();
72
        }
73
        if (screen instanceof AbstractContainerScreen<?>) {
74
            return inventories.isOn();
75
        }
76
        if (screen instanceof ChatScreen) {
77
            return chat.isOn();
78
        }
79
        return others.isOn();
80
    }
81
82
    // True whilst the blur is still fading out after a screen has closed.
83
    public boolean fadingWithoutScreen() {
84
        return isEnabled() && level > 0 && mc.gui.screen() == null;
85
    }
86
87
    // Asks for the blur pass before whatever the screen draws next.
88
    public void blurHere(GuiGraphicsExtractor context) {
89
        if (isEnabled() && level > 0) {
90
            context.blurBeforeThisStratum();
91
        }
92
    }
93
}
94