Rise 5.99 Freelook module 2 files, 275 lines

Rise 5.99 Freelook: Full Source Analysis

Freelook is a ghost-category camera module that decouples the rendered view from the server-visible rotation.

dev/rise/module/impl/ghost/Freelook.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Packets This Module Uses

Analysis

Overview

Freelook is a ghost-category camera module that decouples the rendered view from the server-visible rotation. While the bound key is held it steals the mouse deltas that vanilla would fold into rotationYaw and rotationPitch, accumulates them into its own lastYaw and lastPitch fields through the vanilla sensitivity gain curve, and forces third-person view. The player's actual rotation never changes, so the C03 look stream is frozen at the enable-time values and every attack-side rotation check sees a perfectly static stream. The comment in the source is explicit about the intent: looking around in vanilla third person changes the wire rotation and legit players get flagged by rotation checks while doing it, and this module exists to prevent that. The only packet interaction is receive-side: an S08 teleport with a forced look re-anchors the camera origin so the view does not snap back after the vanilla handler applies the new look.

Camera versus wire rotation

The split is the whole design. onEnable snapshots rotationYaw, rotationPitch and the third-person view mode; onRender2DEvent, which fires every render frame, reads mc.mouseHelper.deltaX and deltaY, scales them by f1 = (mouseSensitivity * 0.6 + 0.2)^3 * 1.5, the vanilla mouse-look gain curve, and adds them to lastYaw and lastPitch with the pitch clamped to +-90 degrees. None of that touches the player's rotation fields, so the server-side look, and every C03 look field derived from it, stays constant for as long as the module is held. handleInput() returns the enabled state so the fork's EntityRenderer can skip the normal mouse-look path and drive the third-person camera from the module's fields instead; the 5.99 snapshot has no net/minecraft tree to show that hook, but the contract is unambiguous. Because 1.8 getMouseOver ray-traces from the player rotation rather than the camera, Freelook grants no aim advantage: it is a pure awareness tool.

S08 re-anchor

The single packet handler runs on the receive side. When an S08PacketPlayerPosLook arrives with a forced look, the vanilla handler writes its yaw and pitch into the player rotation and the client replies with a C06 ack. The module reads the same values and stores them as the new originalYaw and originalPitch, so the camera origin follows the forced look and the view does not snap back to a stale anchor after a teleport or set-back. The packet itself is neither cancelled nor modified, so the ack flow and the server-side teleport ledger behave exactly as vanilla.

Lifecycle

The module is hold-to-activate: onRender2DEvent toggles itself off whenever the key is released or no key is bound, which is what makes the accumulation loop self-terminating. onDisable restores the original rotation and the previous third-person view mode, so the camera returns exactly to where it was. The Invert Pitch setting negates the snapshot pitch on enable, flipping the camera's vertical origin. The mouse-delta accumulation runs per render frame rather than per tick, so camera speed scales with framerate, a client-side artifact that never reaches the wire.

source Freelook.java

Freelook.java71 lines · JavaOriginal ↗
1
package dev.rise.module.impl.ghost;
2
3
import dev.rise.Rise;
4
import dev.rise.event.impl.packet.PacketReceiveEvent;
5
import dev.rise.event.impl.render.Render2DEvent;
6
import dev.rise.module.Module;
7
import dev.rise.module.api.ModuleInfo;
8
import dev.rise.module.enums.Category;
9
import dev.rise.setting.impl.BooleanSetting;
10
import net.minecraft.network.play.server.S08PacketPlayerPosLook;
11
import net.minecraft.util.MathHelper;
12
import org.lwjgl.input.Keyboard;
13
14
import java.util.Objects;
15
16
/**
17
 * @author Hazsi
18
 */
19
@ModuleInfo(name = "Freelook", description = "Allows you to look around in third person", category = Category.LEGIT)
20
public class Freelook extends Module {
21
22
    public BooleanSetting invertPitch = new BooleanSetting("Invert Pitch", this, false);
23
24
    private int previousPerspective;
25
    public float originalYaw, originalPitch, lastYaw, lastPitch;
26
27
    public void onEnable() {
28
        previousPerspective = mc.gameSettings.thirdPersonView;
29
        originalYaw = lastYaw = mc.thePlayer.rotationYaw;
30
        originalPitch = lastPitch = mc.thePlayer.rotationPitch;
31
32
        if (invertPitch.isEnabled()) lastPitch *= -1;
33
    }
34
35
    public void onDisable() {
36
        mc.thePlayer.rotationYaw = originalYaw;
37
        mc.thePlayer.rotationPitch = originalPitch;
38
        mc.gameSettings.thirdPersonView = previousPerspective;
39
    }
40
41
    public void onRender2DEvent(final Render2DEvent event) {
42
        if (this.getKeyBind() == Keyboard.KEY_NONE || !Keyboard.isKeyDown(this.getKeyBind())) {
43
            toggleModule();
44
            return;
45
        }
46
47
        this.mc.mouseHelper.mouseXYChange();
48
        final float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
49
        final float f1 = (float) (f * f * f * 1.5);
50
        lastYaw += (float) (this.mc.mouseHelper.deltaX * f1);
51
        lastPitch -= (float) (this.mc.mouseHelper.deltaY * f1);
52
53
        lastPitch = MathHelper.clamp_float(lastPitch, -90, 90);
54
        mc.gameSettings.thirdPersonView = 1;
55
    }
56
57
    public boolean handleInput() {
58
        return Objects.requireNonNull(Rise.INSTANCE.getModuleManager().getModule("Freelook")).isEnabled();
59
    }
60
61
    // Can you believe Vape doesn't have this??
62
    // No, I'm serious, you ban if you flag while in perspective/freelook.
63
    public void onPacketReceive(final PacketReceiveEvent event) {
64
        if (event.getPacket() instanceof S08PacketPlayerPosLook) {
65
            S08PacketPlayerPosLook wrapper = (S08PacketPlayerPosLook) event.getPacket();
66
67
            originalYaw = wrapper.getYaw();
68
            originalPitch = wrapper.getPitch();
69
        }
70
    }
71
}

What this file does

The module file: the enable and disable snapshots, the per-frame mouse accumulation with the vanilla sensitivity curve and the +-90 pitch clamp, the hold-to-activate self-toggle, the handleInput() suppression contract for the fork's EntityRenderer, and the S08 receive handler that re-anchors the camera origin to a server-forced look. It also carries the Invert Pitch setting.

source Module.java (event-handler base)

Module.java204 lines · JavaOriginal ↗
1
package dev.rise.module;
2
3
import dev.rise.Rise;
4
import dev.rise.event.impl.motion.PostMotionEvent;
5
import dev.rise.event.impl.motion.PreMotionEvent;
6
import dev.rise.event.impl.motion.TeleportEvent;
7
import dev.rise.event.impl.other.*;
8
import dev.rise.event.impl.packet.PacketReceiveEvent;
9
import dev.rise.event.impl.packet.PacketSendEvent;
10
import dev.rise.event.impl.render.*;
11
import dev.rise.module.api.ModuleInfo;
12
import dev.rise.notifications.NotificationType;
13
import dev.rise.setting.Setting;
14
import dev.rise.setting.impl.BooleanSetting;
15
import dev.rise.util.InstanceAccess;
16
import dev.rise.util.math.MathUtil;
17
import lombok.Getter;
18
import lombok.Setter;
19
20
import java.awt.*;
21
import java.util.ArrayList;
22
import java.util.List;
23
import java.util.Objects;
24
import java.util.concurrent.ThreadLocalRandom;
25
26
/**
27
 * This is the super class for all of the modules.
28
 * This class includes all the necessary methods and functions for a module.
29
 *
30
 * @author Tecnio
31
 * @since 02/12/2021
32
 */
33
34
@Getter
35
@Setter
36
public abstract class Module implements InstanceAccess {
37
38
    private boolean enabled;
39
    private int keyBind;
40
41
    //RenderPosition
42
    public float renderX, renderY;
43
44
    public float sizeInGui;
45
    public boolean expanded;
46
    public float clickGuiOpacity;
47
    public float descOpacityInGui = 1;
48
    public boolean hidden = false;
49
50
    //Module Settings
51
    public List<Setting> settings = new ArrayList<>();
52
53
    private ModuleInfo moduleInfo;
54
55
    public Module() {
56
        if (this.getClass().isAnnotationPresent(ModuleInfo.class)) {
57
            this.moduleInfo = this.getClass().getAnnotation(ModuleInfo.class);
58
        } else {
59
            throw new RuntimeException("ModuleInfo annotation not found on " + this.getClass().getSimpleName());
60
        }
61
62
        keyBind = getModuleInfo().defaultKey();
63
    }
64
65
    public boolean toggleModule() {
66
        enabled = !enabled;
67
68
        if (enabled) onEnable();
69
        else onDisable();
70
71
        renderX = mc.displayWidth;
72
        renderY = -mc.displayHeight;
73
74
        Rise.INSTANCE.getModuleManager().setEdited(true);
75
76
        if (((BooleanSetting) Objects.requireNonNull(Rise.INSTANCE.getModuleManager().
77
                getSetting("Interface", "Show Notifications on Toggle"))).isEnabled() && !getModuleInfo().name().equals("ClickGui") && !getModuleInfo().name().equals("Freelook")) {
78
            Rise.INSTANCE.getNotificationManager().registerNotification(
79
                    (enabled ? "Enabled" : "Disabled") + " " + getModuleInfo().name(), 2000, NotificationType.NOTIFICATION);
80
        }
81
82
        return enabled;
83
    }
84
85
    public boolean toggleNoEvent() {
86
        enabled = !enabled;
87
        return enabled;
88
    }
89
90
    protected void onEnable() {
91
    }
92
93
    protected void onDisable() {
94
    }
95
96
    public Setting getSetting(final String name) {
97
        for (final Setting setting : settings) {
98
            if (setting.name.equalsIgnoreCase(name)) {
99
                return setting;
100
            }
101
        }
102
103
        return null;
104
    }
105
    public Setting getSettingAlternative(final String name) {
106
        for (final Setting setting : settings) {
107
            final String comparingName = setting.name.replaceAll(" ", "");
108
109
            if (comparingName.equalsIgnoreCase(name)) {
110
                return setting;
111
            }
112
        }
113
114
        return null;
115
    }
116
117
    protected double randomDouble(final double min, final double max) {
118
        return ThreadLocalRandom.current().nextDouble(min, max);
119
    }
120
121
    protected int randomInt(final int min, final int max) {
122
        return ThreadLocalRandom.current().nextInt(min, max);
123
    }
124
125
    protected double random() {
126
        return ThreadLocalRandom.current().nextDouble(1);
127
    }
128
129
    /**
130
     * Event methods are here and can be overridden from subclasses for event listening.
131
     */
132
    public void onPreMotion(final PreMotionEvent event) {
133
    }
134
135
    public void onPostMotion(final PostMotionEvent event) {
136
    }
137
138
    public void onMove(final MoveEvent event) {
139
    }
140
141
142
    public void onPacketReceive(final PacketReceiveEvent event) {
143
    }
144
145
    public void onPacketSend(final PacketSendEvent event) {
146
    }
147
148
    public void onStrafe(final StrafeEvent event) {
149
    }
150
151
    public void onShader3DEvent(final Shader3DEvent event) {
152
    }
153
154
    public void onRender3DEvent(final Render3DEvent event) {
155
    }
156
157
    public void onRender2DEvent(final Render2DEvent event) {
158
    }
159
160
    public void onCanPlaceBlockEvent(final CanPlaceBlockEvent event) {
161
    }
162
163
    public void onBlockBreak(final BlockBreakEvent event) {
164
    }
165
166
    public void onAttackEvent(final AttackEvent event) {
167
    }
168
169
    public void onMoveButton(final MoveButtonEvent event) {
170
    }
171
172
    public void onKey(final KeyEvent event) {
173
    }
174
175
    public void onUpdateAlwaysInGui() {
176
    }
177
178
    public void onUpdateAlways() {
179
    }
180
181
    public void onBlur(final BlurEvent event) {
182
    }
183
184
    public void onFadingOutline(final FadingOutlineEvent event) {
185
    }
186
187
    public void onPreBlur(final PreBlurEvent event) {
188
    }
189
190
    public void onOpenGUI(final OpenGUIEvent event) {
191
    }
192
193
    public void onWorldChanged(final WorldChangedEvent event) {
194
    }
195
196
    public void onUpdate(final UpdateEvent event) {
197
    }
198
199
    public void onBlockCollide(final BlockCollideEvent event) {
200
    }
201
202
    public void onTeleportEvent(final TeleportEvent event) {
203
    }
204
}

What this file does

The base class defines the lifecycle every Rise 5.99 module uses: toggleModule() calls the overridden onEnable and onDisable, getKeyBind() supplies the key code the hold-to-activate check reads, and the default no-op handlers for onPacketReceive and onRender2DEvent show how Freelook's overrides slot into the event dispatch. The 204-line file is the wiring contract behind the module's handler set.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat fight Angle (rotation-window scoring)

Angle.java255 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.fight;
16
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.UUID;
21
22
import org.bukkit.ChatColor;
23
import org.bukkit.Location;
24
import org.bukkit.entity.Entity;
25
import org.bukkit.entity.Player;
26
27
import fr.neatmonster.nocheatplus.actions.ParameterName;
28
import fr.neatmonster.nocheatplus.checks.Check;
29
import fr.neatmonster.nocheatplus.checks.CheckType;
30
import fr.neatmonster.nocheatplus.checks.ViolationData;
31
import fr.neatmonster.nocheatplus.permissions.Permissions;
32
import fr.neatmonster.nocheatplus.players.IPlayerData;
33
import fr.neatmonster.nocheatplus.utilities.StringUtil;
34
import fr.neatmonster.nocheatplus.utilities.TickTask;
35
import fr.neatmonster.nocheatplus.utilities.math.TrigUtil;
36
37
/**
38
 * A check used to verify if the player isn't using a forcefield in order to attack multiple entities at the same time.
39
 * 
40
 * Thanks @asofold for the original idea!
41
 */
42
public class Angle extends Check {
43
  
44
45
  private final List<String> tags = new LinkedList<String>();
46
47
48
    public static class AttackLocation {
49
        public final double x, y, z;
50
        /** Yaw of the attacker. */
51
        public final float yaw;
52
        public long time;
53
        public final UUID damagedId;
54
        /** Squared distance to the last location (0 if none given). */
55
        public final double distSqLast;
56
        /** Difference in yaw to the last location (0 if none given). */
57
        public final double yawDiffLast;
58
        /** Time difference to the last location (0 if none given). */
59
        public final long timeDiff;
60
        /** If the id differs from the last damaged entity (true if no lastLoc is given). */
61
        public final boolean idDiffLast;
62
        public AttackLocation(final Location loc, final UUID damagedId, final long time, final AttackLocation lastLoc) {
63
            x = loc.getX();
64
            y = loc.getY();
65
            z = loc.getZ();
66
            yaw = loc.getYaw();
67
            this.time = time;
68
            this.damagedId = damagedId;
69
70
            if (lastLoc != null) {
71
                distSqLast = TrigUtil.distanceSquared(x, y, z, lastLoc.x, lastLoc.y, lastLoc.z);
72
                yawDiffLast = TrigUtil.yawDiff(yaw, lastLoc.yaw);
73
                timeDiff = Math.max(0L, time - lastLoc.time);
74
                idDiffLast = !damagedId.equals(lastLoc.damagedId);
75
            } 
76
            else {
77
                distSqLast = 0.0;
78
                yawDiffLast = 0f;
79
                timeDiff = 0L;
80
                idDiffLast = true;
81
            }
82
        }
83
    }
84
    
85
    /** Used to also monitor lag-time */
86
    public static long maxTimeDiff = 1000L;
87
88
89
    /**
90
     * Instantiates a new angle check.
91
     */
92
    public Angle() {
93
        super(CheckType.FIGHT_ANGLE);
94
    }
95
96
97
    /**
98
     * The Angle check.
99
     * @param player
100
     * @param loc Location of the player.
101
     * @param worldChanged
102
     * @param data
103
     * @param cc
104
     * @return
105
     */
106
    public boolean check(final Player player, final Location loc, 
107
                         final Entity damagedEntity, final boolean worldChanged, 
108
                         final FightData data, final FightConfig cc, final IPlayerData pData) {
109
110
        if (worldChanged) {
111
            data.angleHits.clear();
112
        }
113
114
        boolean cancel = false;
115
        tags.clear();
116
117
        // Quick check for expiration of all entries.
118
        final long time = System.currentTimeMillis();
119
        AttackLocation lastLoc = data.angleHits.isEmpty() ? null : data.angleHits.getLast();
120
        if (lastLoc != null && time - lastLoc.time > maxTimeDiff) {
121
            data.angleHits.clear();
122
            lastLoc = null;
123
        }
124
125
        // Add the new location.
126
        data.angleHits.add(new AttackLocation(loc, damagedEntity.getUniqueId(), System.currentTimeMillis(), lastLoc));
127
128
        // Calculate the sums of differences.
129
        double deltaMove = 0D;
130
        long deltaTime = 0L;
131
        float deltaYaw = 0f;
132
        int deltaSwitchTarget = 0;
133
        final Iterator<AttackLocation> it = data.angleHits.iterator();
134
        while (it.hasNext()) {
135
            final AttackLocation refLoc = it.next();
136
            if (time - refLoc.time > maxTimeDiff) {
137
                it.remove();
138
                continue;
139
            }
140
            deltaMove += refLoc.distSqLast;
141
            final double yawDiff = Math.abs(refLoc.yawDiffLast);
142
            deltaYaw += yawDiff;
143
            deltaTime += refLoc.timeDiff;
144
            if (refLoc.idDiffLast && yawDiff > 30.0) {
145
                // TODO: Configurable sensitivity ? Scale with yawDiff?
146
                deltaSwitchTarget += 1;
147
            }
148
        }
149
150
        // Check if there is enough data present.
151
        if (data.angleHits.size() < 2) {
152
            return false;
153
        }
154
155
        final double n = (double) (data.angleHits.size() - 1);
156
157
        // Let's calculate the average move.
158
        double averageMove = deltaMove / n;
159
        // Adjust to server-sided lag
160
        averageMove *= TickTask.getLag(maxTimeDiff, true);
161
162
        // And the average time elapsed.
163
        double averageTime = (double) deltaTime / n;
164
        // Adjust to server-sided lag
165
        averageTime *= TickTask.getLag(maxTimeDiff, true);
166
167
        // And the average yaw delta.
168
        double averageYaw = (double) deltaYaw / n;
169
        // Adjust to server-sided lag
170
        averageYaw /= TickTask.getLag(maxTimeDiff, true);
171
172
        // Average target switching.
173
        double averageSwitching = (double) deltaSwitchTarget / n;
174
        // Adjust to server-sided lag
175
        averageSwitching /= TickTask.getLag(maxTimeDiff, true);
176
177
        // Declare the variables.
178
        double violation = 0.0;
179
        double violationMove = 0.0;
180
        double violationTime = 0.0;
181
        double violationYaw = 0.0;
182
        double violationSwitchSpeed = 0.0;
183
184
        // If the average move is between 0 and 0.2 block(s), add it to the violation.
185
        if (averageMove >= 0.0 && averageMove < 0.2D) {
186
            violationMove += 20.0 * (0.2 - averageMove) / 0.2;
187
            tags.add("avgmove");
188
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
189
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgMove: " + averageMove + " avgMove VL: " + violationMove + "/" + cc.angleMove);
190
            }
191
        }
192
193
        // If the average time elapsed is between 0 and 150 millisecond(s), add it to the violation.
194
        if (averageTime >= 0.0 && averageTime < 150.0) {
195
            violationTime += 30.0 * (150.0 - averageTime) / 150.0;
196
            tags.add("avgtime");
197
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
198
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgTime: " + averageTime + " avgTime VL: " + violationTime + "/" + cc.angleTime);
199
            }
200
        }
201
202
        // If the average difference of yaw is superior to 50 degrees, add it to the violation.
203
        if (averageYaw > 50.0) {
204
            violationYaw += 30.0 * averageYaw / 180.0;
205
            tags.add("avgyaw");
206
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
207
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgYaw: " + averageYaw + " avgYaw VL: " + violationYaw + "/" + cc.angleYaw);
208
            }
209
        }
210
        
211
        // Check for too quick target switch speed
212
        if (averageSwitching > 0.0) {
213
            violationSwitchSpeed += 20.0 * averageSwitching;
214
            tags.add("switchspeed");
215
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
216
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgSwitch: " + averageSwitching + " avgSwitch VL: " + violationSwitchSpeed + "/" + cc.angleSwitch);
217
            }
218
        }
219
220
221
        if (violationMove > cc.angleMove) {
222
            violation = violationMove;
223
            data.angleVL += violation;
224
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
225
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
226
            cancel = executeActions(vd).willCancel();
227
        }
228
        else if (violationTime > cc.angleTime) {
229
            violation = violationTime;
230
            data.angleVL += violation;
231
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
232
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
233
            cancel = executeActions(vd).willCancel();
234
        }
235
        else if (violationYaw > cc.angleYaw) {
236
            violation = violationYaw;
237
            data.angleVL += violation;
238
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
239
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
240
            cancel = executeActions(vd).willCancel();
241
        } 
242
        else if (violationSwitchSpeed > cc.angleSwitch) {
243
            violation = violationSwitchSpeed;
244
            data.angleVL += violation;
245
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
246
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
247
            cancel = executeActions(vd).willCancel();
248
        } 
249
        else {
250
            // Reward the player by lowering their violation level.
251
            data.angleVL *= 0.98D;  
252
        }
253
        return cancel;
254
    }
255
}

How it counteracts this module

NCP's fight Angle chains AttackLocation entries over a 1000ms maxTimeDiff window and accumulates the yaw deltas between consecutive attacks. The frozen C03 look makes every delta zero, so angleVL never rises, and at the stock thresholds in this tree (move 100, time 150, yaw 60, switch 50) even active aim streams rarely trip the check. Freelook is therefore invisible to it twice over: the module was built precisely to keep the wire rotation static, and the check is dormant by default. The same frozen stream is what makes the module safe against every attack-side rotation check.

anticheat AimbotHeuristic (click-gated mouse analysis)

AimbotHeuristic.java164 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.look;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.CustomCheck;
23
import me.islandscout.hawk.check.Cancelless;
24
import me.islandscout.hawk.event.*;
25
import me.islandscout.hawk.util.Debug;
26
import me.islandscout.hawk.util.MathPlus;
27
import org.bukkit.entity.Player;
28
import org.bukkit.util.Vector;
29
30
import java.util.*;
31
32
/**
33
 * AimbotHeuristic exploits flaws in aim-bot cheats by
34
 * analyzing mouse movement patterns during interaction. Although
35
 * easily bypassed, it catches a significant number of cheaters.
36
 * Caution is advised since this check may false flag during
37
 * certain circumstances. This check should only be used as a
38
 * hint that the player might be cheating.
39
 */
40
public class AimbotHeuristic extends CustomCheck implements Cancelless {
41
42
    private final Map<UUID, List<Vector>> mouseMoves;
43
    private final Map<UUID, List<Long>> clickTimes;
44
45
    private static final int MOVES_PER_SAMPLE = 4; //must be greater than 0
46
    private final int MOVES_AFTER_HIT;
47
    private final boolean DEBUG;
48
49
    public AimbotHeuristic() {
50
        super("aimbotheuristic", false, -1, 5, 0.99, 5000, "&7%player% failed aimbot (heuristic), VL %vl%", null);
51
        mouseMoves = new HashMap<>();
52
        clickTimes = new HashMap<>();
53
54
        MOVES_AFTER_HIT = MOVES_PER_SAMPLE - MOVES_PER_SAMPLE / 2;
55
56
        DEBUG = (boolean) customSetting("debug", "", false);
57
    }
58
59
    public void check(Event e) {
60
        if (e instanceof MoveEvent) {
61
            processMove((MoveEvent) e);
62
        } else if (e instanceof InteractEntityEvent || e instanceof InteractWorldEvent) {
63
            processClick(e);
64
        }
65
    }
66
67
    private void processMove(MoveEvent e) {
68
        Player p = e.getPlayer();
69
        HawkPlayer pp = e.getHawkPlayer();
70
        UUID uuid = p.getUniqueId();
71
72
        List<Vector> lastMoves = mouseMoves.getOrDefault(uuid, new ArrayList<>());
73
        Vector mouseMove = new Vector(e.getTo().getYaw() - e.getFrom().getYaw(), e.getTo().getPitch() - e.getFrom().getPitch(), 0);
74
75
        lastMoves.add(mouseMove);
76
        //make size 1 bigger so that we can get the move before
77
        //the first move that we check
78
        if(lastMoves.size() > MOVES_PER_SAMPLE + 1) {
79
            lastMoves.remove(0);
80
        }
81
        mouseMoves.put(uuid, lastMoves);
82
83
        if(clickedXMovesBefore(MOVES_AFTER_HIT, pp)) {
84
            double minSpeed = Double.MAX_VALUE;
85
            double maxSpeed = 0D;
86
            double maxAngle = 0D;
87
            for(int i = 1; i < lastMoves.size(); i++) {
88
                Vector lastMouseMove = lastMoves.get(i - 1);
89
                Vector currMouseMove = lastMoves.get(i);
90
                double speed = currMouseMove.length();
91
                double lastSpeed = lastMouseMove.length();
92
                double angle = (lastSpeed != 0 && lastSpeed != 0) ? MathPlus.angle(lastMouseMove, currMouseMove) : 0D;
93
                if(Double.isNaN(angle))
94
                    angle = 0D;
95
                maxSpeed = Math.max(speed, maxSpeed);
96
                minSpeed = Math.min(speed, minSpeed);
97
                maxAngle = Math.max(angle, maxAngle);
98
99
                //stutter
100
                if(maxSpeed - minSpeed > 4 && minSpeed < 0.01 && maxAngle < 0.1 && lastSpeed > 1) { //this lastSpeed check eliminates a false positive
101
                    if(DEBUG) {
102
                        p.sendMessage("AimbotHeuristic: A");
103
                    }
104
                    punishEm(pp, e);
105
                }
106
                //twitching or zig zags
107
                else if(speed > 20 && lastSpeed > 20 && angle > 2.86) {
108
                    if(DEBUG) {
109
                        p.sendMessage("AimbotHeuristic: B");
110
                    }
111
                    punishEm(pp, e);
112
                }
113
                //jump discontinuity
114
                else if(speed - lastSpeed < -30 && angle > 0.8) {
115
                    if(DEBUG) {
116
                        p.sendMessage("AimbotHeuristic: C");
117
                    }
118
                    punishEm(pp, e);
119
                }
120
                else {
121
                    reward(pp);
122
                }
123
            }
124
        }
125
    }
126
127
    private boolean clickedXMovesBefore(long x, HawkPlayer pp) {
128
        List<Long> clickTimess = clickTimes.getOrDefault(pp.getUuid(), new ArrayList<>());
129
        long time = pp.getCurrentTick() - x;
130
        for(int i = 0; i < clickTimess.size(); i++) {
131
            if(time == clickTimess.get(i)) {
132
                clickTimess.remove(i);
133
                return true;
134
            }
135
        }
136
        return false;
137
    }
138
139
    private void processClick(Event e) {
140
        UUID uuid = e.getPlayer().getUniqueId();
141
        List<Long> clickTimess = clickTimes.getOrDefault(uuid, new ArrayList<>());
142
        long currTick = e.getHawkPlayer().getCurrentTick();
143
        if(!clickTimess.contains(currTick))
144
            clickTimess.add(e.getHawkPlayer().getCurrentTick());
145
146
        //memory leak fail-safe, if necessary?
147
        for(int i = clickTimess.size() - 1; i >= 0; i--) {
148
            if(currTick - clickTimess.get(i) > MOVES_PER_SAMPLE + 1)
149
                clickTimess.remove(i);
150
        }
151
152
        clickTimes.put(uuid, clickTimess);
153
    }
154
155
    private void punishEm(HawkPlayer pp, MoveEvent e) {
156
        punish(pp, false, e);
157
    }
158
159
    @Override
160
    public void removeData(Player p) {
161
        mouseMoves.remove(p.getUniqueId());
162
        clickTimes.remove(p.getUniqueId());
163
    }
164
}

How it counteracts this module

Hawk's AimbotHeuristic samples mouse-move vectors and only scores them around interactions: InteractEntityEvent or InteractWorldEvent arm the click window. Its three branches need real motion, a stutter requires maxSpeed minus minSpeed over 4 with minSpeed under 0.01, a twitch requires consecutive speeds over 20 degrees per move with an angle over 2.86 radians, and a jump requires a speed drop over 30 with a sharp angle. Freelook's zero-delta stream satisfies none of them, and a user who only looks around without attacking never arms the click window at all. It is an honest boundary, not a counter.

anticheat KillAura (attack-side direction)

KillAura.java114 lines · Java
1
package me.vrekt.arc.check.combat;
2
3
import me.vrekt.arc.Arc;
4
import me.vrekt.arc.check.Check;
5
import me.vrekt.arc.check.CheckType;
6
import me.vrekt.arc.data.combat.FightData;
7
import me.vrekt.arc.utilties.LocationHelper;
8
import org.bukkit.ChatColor;
9
import org.bukkit.entity.Entity;
10
import org.bukkit.entity.Player;
11
import org.bukkit.util.Vector;
12
13
public class KillAura extends Check {
14
15
    private double maxAngle, maxReach;
16
    private int maxSwingTime, maxAttacks, maxAttackPackets;
17
18
    public KillAura() {
19
        super(CheckType.KILLAURA);
20
21
        maxAngle = Arc.getCheckManager().getValueDouble(CheckType.KILLAURA, "max-direction-angle");
22
        maxSwingTime = Arc.getCheckManager().getValueInt(CheckType.KILLAURA, "max-swing-time");
23
        maxReach = Arc.getCheckManager().getValueDouble(CheckType.KILLAURA, "max-reach");
24
        maxAttacks = Arc.getCheckManager().getValueInt(CheckType.KILLAURA, "max-attacks");
25
        maxAttackPackets = Arc.getCheckManager().getValueInt(CheckType.KILLAURA, "max-attack-packets");
26
27
    }
28
29
    public boolean check(FightData data, Player player) {
30
        result.reset();
31
32
        Entity last = data.getLastAttackedEntity();
33
        Entity entity = data.getAttackedEntity();
34
35
        // Calculate angle stuff.
36
        Vector playerLocation = player.getLocation().toVector();
37
        Vector entityLocation = entity.getLocation().toVector();
38
        double angle = entityLocation.subtract(playerLocation).angle(player.getLocation().getDirection());
39
40
        if (last != null && !entity.equals(last)) {
41
            // check the angle between the two entities
42
            Vector lastLocation = last.getLocation().toVector();
43
            double angleToLast = lastLocation.subtract(playerLocation).angle(player.getLocation().getDirection());
44
            double angleDifference = Math.abs(angleToLast - angle);
45
            double distanceDifference = LocationHelper.distance(last.getLocation(), entity.getLocation());
46
            if (angleDifference > maxAngle && distanceDifference <= maxReach) {
47
                getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(Multi)");
48
                result.set(checkViolation(player, "Angle difference greater than allowed. a=" + angleDifference + " e=" + maxAngle));
49
            }
50
        }
51
52
        // check yaw difference.
53
        if (angle > maxAngle) {
54
            getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(Direction)");
55
            result.set(checkViolation(player, "Angle distance greater than allowed. a=" + angle + " e=" + maxAngle));
56
        }
57
58
        // check swing time.
59
        long time = System.currentTimeMillis() - data.getLastArmSwing();
60
        if (time > maxSwingTime) {
61
            getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(NoSwing)");
62
            result.set(checkViolation(player, "Player did not swing their arm in time."));
63
        }
64
65
        // distance to entity excluding knockback.
66
        double distance = LocationHelper.distance(player.getLocation(), entity.getLocation().subtract(entity.getVelocity()));
67
        // check for reach
68
        if (distance > maxReach) {
69
            getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(Reach)");
70
            result.set(checkViolation(player, "Entity is out of players range. d=" + distance + " e=" + maxReach));
71
        }
72
73
        // check max attacks
74
        if (data.getLastAttackCheck() == 0) {
75
            data.setLastAttackCheck(System.currentTimeMillis());
76
        }
77
        long lastAttack = System.currentTimeMillis() - data.getLastAttackCheck();
78
        if (lastAttack >= 1000) {
79
            // check if we exceeded the max attacks in the last second.
80
            int totalAttacks = data.getTotalAttacks();
81
            if (totalAttacks > maxAttacks) {
82
                getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(Speed)");
83
                result.set(checkViolation(player, "Attacking too fast. a=" + totalAttacks + " e=" + maxAttacks));
84
            }
85
            // reset data for next check.
86
            data.setTotalAttacks(0);
87
            data.setLastAttackCheck(System.currentTimeMillis());
88
        }
89
90
        getCheck().setCheckName("KillAura");
91
        return result.failed();
92
    }
93
94
    public boolean checkFrequency(FightData data, Player player) {
95
        if (data.getLastAttackCheck() == 0) {
96
            data.setLastAttackCheck(System.currentTimeMillis());
97
            return false;
98
        }
99
100
        long time = System.currentTimeMillis() - data.getLastAttackCheck();
101
        if (time >= 1000) {
102
            data.setLastAttackCheck(System.currentTimeMillis());
103
            int totalPackets = data.getAttackPackets();
104
            if (totalPackets > maxAttackPackets) {
105
                data.setAttackPackets(0);
106
                getCheck().setCheckName("Kill Aura " + ChatColor.GRAY + "(Speed)");
107
                return checkViolation(player, "Attacking too fast a=" + totalPackets + " e=" + maxAttackPackets);
108
            }
109
        }
110
111
        return false;
112
    }
113
114
}

How it counteracts this module

Arc v2's KillAura Direction sub-check computes the angle between the entity vector and the player's look direction and punishes when it exceeds max-direction-angle, default 1.2 radians in config.yml, while the reach sub-check measures center distance minus victim velocity against max-reach 4.2. Because Freelook never changes the server-visible rotation, the attack geometry the server computes is exactly what vanilla aim produces; there is no off-axis component to score. The module is aim-neutral by construction, which is the honest reason no attack-side check can bite.

anticheat TeleportQueue (S08 ack ledger)

TeleportQueue.java370 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net.model;
16
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.concurrent.locks.Lock;
20
import java.util.concurrent.locks.ReentrantLock;
21
22
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
23
24
/**
25
 * Queue outgoing teleport locations (DataPacketFlying), in order to cancel
26
 * other moving until the client acknowledges previous teleport locations. In
27
 * fact this might only queue a single location.
28
 * 
29
 * @author asofold
30
 *
31
 */
32
public class TeleportQueue {
33
34
    public static enum AckResolution {
35
        /** Waiting for ACK. */
36
        WAITING,
37
        /** Packet is ACK. */
38
        ACK,
39
        /** Not waiting for an ACK. */
40
        IDLE
41
    }
42
43
    public static class AckReference {
44
        public int lastOutgoingId = Integer.MIN_VALUE;
45
        /**
46
         * The maximum of confirmed ids. Once lastOutgoingId is reached, we
47
         * assume all teleports are done. Until then this id may get adjusted if
48
         * lower than lastOutgoingId. Note that the id will be circling within 0
49
         * to Integer.MAX_VALUE - 1, systematically increasing until back to 0,
50
         * thus this value can be greater than lastOutGoingId, which should be
51
         * treated as 'bad luck', resetting this to Integer.MIN_VALUE.
52
         */
53
        public int maxConfirmedId = Integer.MIN_VALUE;
54
    }
55
56
    // TODO: Consider passing a reentrant lock in the constructor (e.g. one lock per NetData).
57
    private final Lock lock = new ReentrantLock();
58
59
    /** Validated outgoing teleport locations, expected to be confirmed by the client. */
60
    private final LinkedList<CountableLocation> expectIncoming = new LinkedList<CountableLocation>();
61
    /** Location from a Bukkit event, which we expect an outgoing teleport for. */
62
    private DataLocation expectOutgoing = null;
63
64
    private long maxAge = 4000; // TODO: configurable
65
    private int maxQueueSize = 60; // TODO: configurable
66
67
    /**
68
     * Queried from the primary thread (read only), reset with outgoing
69
     * teleport.
70
     */
71
    private CountableLocation lastAck = null;
72
73
    private AckReference lastAckReference = new AckReference();
74
75
    /**
76
     * Maximum age in milliseconds, older entries expire.
77
     * @return
78
     */
79
    public long getMaxAge() {
80
        return maxAge;
81
    }
82
83
    /**
84
     * The last confirmed teleport location (read-only by primary thread),
85
     * resets with outgoing teleport.
86
     * 
87
     * @return
88
     */
89
    public CountableLocation getLastAck() {
90
        return lastAck;
91
    }
92
93
    /**
94
     * Get the reference of the last ack, not resetting, but updating with
95
     * incoming acks. This always is the same object, it might only by updated
96
     * on a successful ACK, depending on what's needed (current use is to cancel
97
     * packets on processAck returning WAITING).
98
     * 
99
     * @return
100
     */
101
    public AckReference getLastAckReference() {
102
        return lastAckReference;
103
    }
104
105
    /**
106
     * Compact diagnostic snapshot for NET_MOVING false-positive analysis.
107
     */
108
    public String getDebugState(final long now) {
109
        final StringBuilder builder = new StringBuilder(300);
110
        lock.lock();
111
        builder.append("expectOutgoing=").append(expectOutgoing == null ? "none" : expectOutgoing.toString());
112
        builder.append(",expectIncomingSize=").append(expectIncoming.size());
113
        if (!expectIncoming.isEmpty()) {
114
            builder.append(",incomingFirst=").append(formatCountable(expectIncoming.getFirst(), now));
115
            builder.append(",incomingLast=").append(formatCountable(expectIncoming.getLast(), now));
116
        }
117
        builder.append(",lastAck=").append(lastAck == null ? "none" : formatCountable(lastAck, now));
118
        builder.append(",ackRef=lastOutgoing:").append(lastAckReference.lastOutgoingId)
119
                .append("/maxConfirmed:").append(lastAckReference.maxConfirmedId);
120
        builder.append(",maxAge=").append(maxAge);
121
        lock.unlock();
122
        return builder.toString();
123
    }
124
125
    private String formatCountable(final CountableLocation ref, final long now) {
126
        final StringBuilder builder = new StringBuilder(160);
127
        builder.append(ref.toString());
128
        builder.append(",age=");
129
        builder.append(now >= ref.time ? now - ref.time : -(ref.time - now));
130
        return builder.toString();
131
    }
132
133
    /**
134
     * Call for Bukkit events (expect this packet to be sent).<br>
135
     * TODO: The method name is misleading, as this also should be called with
136
     * expected outgoing packet.
137
     * 
138
     * @param packetData
139
     */
140
    public void onTeleportEvent(final double x, final double y, final double z, final float yaw, final float pitch) {
141
        lock.lock();
142
        lastAck = null;
143
        expectOutgoing = new DataLocation(x, y, z, yaw, pitch);
144
        lock.unlock();
145
    }
146
147
    /**
148
     * Call for outgoing teleport packets. Lazily checks for expiration and max
149
     * queue size. Update teleportId (Integer.MIN_VALUE means that it isn't
150
     * provided).
151
     * 
152
     * @param x
153
     * @param y
154
     * @param z
155
     * @param yaw
156
     * @param pitch
157
     * @param teleportId
158
     * @return
159
     */
160
    public CountableLocation onOutgoingTeleport(final double x, final double y, final double z, 
161
            final float yaw, final float pitch, final int teleportId) {
162
        CountableLocation res = null;
163
        final long time = System.currentTimeMillis();
164
        lock.lock();
165
        lastAckReference.lastOutgoingId = teleportId;
166
        if (lastAckReference.maxConfirmedId > lastAckReference.lastOutgoingId) {
167
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE; // Some data loss accepted here.
168
        }
169
        // Only register this location, if it matches the location from a Bukkit event.
170
        if (expectOutgoing != null) {
171
            if (expectOutgoing.isSamePosAndLook(x, y, z, yaw, pitch)) {
172
                // Add to queue.
173
                if (!expectIncoming.isEmpty()) {
174
                    // Lazy expiration check.
175
                    final Iterator<CountableLocation> it = expectIncoming.iterator();
176
                    while (it.hasNext()) {
177
                        final CountableLocation ref = it.next();
178
                        if (time < ref.time) {
179
                            // Time ran backwards. Force keep entries.
180
                            ref.time = time;
181
                        }
182
                        else if (time - maxAge > ref.time) {
183
                            it.remove();
184
                        } else {
185
                            break;
186
                        }
187
                    }
188
                    if (!expectIncoming.isEmpty()) {
189
                        final CountableLocation last = expectIncoming.getLast();
190
                        if (last.isSamePosAndLook(x, y, z, yaw, pitch)) {
191
                            last.time = time;
192
                            last.count ++;
193
                            last.teleportId = teleportId;
194
                            res = last;
195
                        }
196
                    }
197
                }
198
                // Add a new entry, if not merged with last.
199
                if (res == null) {
200
                    res = new CountableLocation(x, y, z, yaw, pitch, 1, time, teleportId);
201
                    expectIncoming.addLast(res);
202
                    // Don't exceed maxQueueSize.
203
                    if (expectIncoming.size() > maxQueueSize) {
204
                        expectIncoming.removeFirst();
205
                    }
206
                }
207
            }
208
            // Reset in any case.
209
            expectOutgoing = null;
210
        }
211
        lock.unlock();
212
        return res;
213
    }
214
215
    /**
216
     * Process ack on receiving a 'confirm teleport' packet.
217
     * 
218
     * @param teleportId
219
     * @return YES, if this teleport id is explicitly matched (not necessarily
220
     *         the latest one), MAYBE if it's a unique id smaller than than
221
     *         maxConfirmedId. NO, if it's not a valid ack - it could be some
222
     *         other special condition, like Integer overflow, or timeout.
223
     */
224
    public AlmostBoolean processAck(final int teleportId) {
225
        /*
226
         * Return values are subject to change, e.g.: (ACK_LATEST_POS),
227
         * ACK_LATEST_ID, ACK_OUTDATED_POS, ACK_OUTDATED_ID, UNKNOWN
228
         */
229
        if (teleportId == Integer.MIN_VALUE) {
230
            // Could consider to return MAYBE for not knowing, needs elaborating on context and use cases.
231
            return AlmostBoolean.NO;
232
        }
233
        lock.lock();
234
        if (teleportId == lastAckReference.lastOutgoingId) {
235
            lastAckReference.maxConfirmedId = teleportId;
236
            // Abort here for efficiency.
237
            expectIncoming.clear();
238
            lock.unlock();
239
            return AlmostBoolean.YES;
240
        }
241
        AlmostBoolean ackState = AlmostBoolean.NO;
242
        final Iterator<CountableLocation> it = expectIncoming.iterator();
243
        while (it.hasNext()) {
244
            final CountableLocation ref = it.next();
245
            // No expiration checks here.
246
            if (ref.teleportId == teleportId) {
247
                // Match an outdated id.
248
                // Remove all preceding older entries and this one.
249
                while (ref != expectIncoming.getFirst()) {
250
                    expectIncoming.removeFirst();
251
                }
252
                expectIncoming.removeFirst();
253
                // The count doesn't count anymore.
254
                ref.count = 0;
255
                ackState = AlmostBoolean.YES;
256
                break;
257
            }
258
        }
259
        // Update lastAckReference only if within the safe area.
260
        if (teleportId < lastAckReference.lastOutgoingId 
261
                && teleportId > lastAckReference.maxConfirmedId) {
262
            // Allow update.
263
            lastAckReference.maxConfirmedId = teleportId;
264
            if (ackState == AlmostBoolean.NO) {
265
                // Adjust to maybe, as long as the id is increasing within unique range.
266
                ackState = AlmostBoolean.MAYBE;
267
            }
268
        }
269
        else {
270
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE;
271
        }
272
        lock.unlock();
273
        return ackState;
274
    }
275
276
    /**
277
     * Accept a movement packet that matches the teleport location from a Bukkit
278
     * event before ProtocolLib has observed the matching outgoing position.
279
     */
280
    public boolean consumeExpectedOutgoingPosition(final DataPacketFlying packetData) {
281
        if (packetData == null || !packetData.hasPos) {
282
            return false;
283
        }
284
        lock.lock();
285
        final boolean match = expectOutgoing != null && expectOutgoing.isSamePos(packetData);
286
        if (match) {
287
            expectOutgoing = null;
288
        }
289
        lock.unlock();
290
        return match;
291
    }
292
293
    /**
294
     * Test if the move is an ACK move (or no ACK is expected), adjust internals
295
     * if necessary.
296
     * 
297
     * @param packetData
298
     * @return ACK, if the packet matches an expected ACK position. IDLE, if no
299
     *         ACK is expected or on timeout. CANCEL, if still waiting for an
300
     *         ACK.
301
     */
302
    public AckResolution processAck(final DataPacketFlying packetData) {
303
        // Check packet.
304
        if (!packetData.hasPos || !packetData.hasLook) {
305
            // Applies, if we don't have a teleport-confirm event.
306
            return AckResolution.IDLE;
307
        }
308
        // Check queue.
309
        final AckResolution res;
310
311
        lock.lock();
312
        if (expectIncoming.isEmpty()) {
313
            res = AckResolution.IDLE;
314
        } else {
315
            res = getAckResolution(packetData);
316
        }
317
        lock.unlock();
318
319
        return res;
320
    }
321
322
    /**
323
     * Check queue (lock is handled outside of this method). Does check for
324
     * expiration of entries. Must only be called under lock.
325
     * 
326
     * @param packetData
327
     * @return
328
     */
329
    private AckResolution getAckResolution(final DataPacketFlying packetData) {
330
        // Iterate from oldest to newest.
331
        final Iterator<CountableLocation> it = expectIncoming.iterator();
332
        while (it.hasNext()) {
333
            final CountableLocation ref = it.next();
334
            if (packetData.time - maxAge >= ref.time) {
335
                it.remove();
336
            }
337
            else if (packetData.isSamePosAndLook(ref)) {
338
                // Match.
339
                // Remove all preceding older entries.
340
                while (ref != expectIncoming.getFirst()) {
341
                    expectIncoming.removeFirst();
342
                }
343
                // Decrease count and remove the matching entry if count is down to 0.
344
                if (--ref.count <= 0) { // (Lots of safety margin.)
345
                    expectIncoming.removeFirst(); // Do not use the iterator here.
346
                }
347
                lastAck = ref;
348
                return AckResolution.ACK;
349
            }
350
            else {
351
                // Skip until match or none found.
352
                // TODO: Consider settings like maxSkipCount or strictly return WAITING.
353
                if (packetData.time < ref.time) {
354
                    // Time ran backwards, update to now.
355
                    ref.time = packetData.time;
356
                }
357
            }
358
        }
359
        // No match.
360
        return expectIncoming.isEmpty() ? AckResolution.IDLE : AckResolution.WAITING;
361
    }
362
363
    public void clear() {
364
        lock.lock();
365
        expectIncoming.clear();
366
        expectOutgoing = null;
367
        lock.unlock();
368
    }
369
370
}

How it counteracts this module

The S08 re-anchor is the module's only packet interaction, and it is read-only. TeleportQueue records each server teleport, matches the follow-up C06 by isSamePosAndLook, and ages unmatched entries out after 4000ms. Since Freelook neither cancels nor rewrites the S08, the ack matching sees an unmodified vanilla flow and the ledger never leaves the IDLE state on the module's account. This entry documents that the receive-side handler has no server-visible effect.

← Back to Analysis Hub