-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Impl/src/main/java/dev/brighten/anticheat/utils/ExponentialMovingAverage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.brighten.anticheat.utils; | ||
|
||
public class ExponentialMovingAverage { | ||
private double alpha; | ||
private Double oldValue; | ||
public ExponentialMovingAverage(double alpha) { | ||
this.alpha = alpha; | ||
} | ||
|
||
public double average(double value) { | ||
if (oldValue == null) { | ||
oldValue = value; | ||
return value; | ||
} | ||
double newValue = oldValue + alpha * (value - oldValue); | ||
oldValue = newValue; | ||
return newValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Regular/src/main/java/dev/brighten/anticheat/check/impl/packets/TimerB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.brighten.anticheat.check.impl.packets; | ||
|
||
import cc.funkemunky.api.tinyprotocol.packet.in.WrappedInFlyingPacket; | ||
import cc.funkemunky.api.tinyprotocol.packet.in.WrappedInTransactionPacket; | ||
import cc.funkemunky.api.tinyprotocol.packet.out.WrappedOutPositionPacket; | ||
import cc.funkemunky.api.utils.MathUtils; | ||
import cc.funkemunky.api.utils.math.RollingAverage; | ||
import cc.funkemunky.api.utils.objects.evicting.EvictingList; | ||
import dev.brighten.anticheat.Kauri; | ||
import dev.brighten.anticheat.check.api.Cancellable; | ||
import dev.brighten.anticheat.check.api.Check; | ||
import dev.brighten.anticheat.check.api.CheckInfo; | ||
import dev.brighten.anticheat.check.api.Packet; | ||
import dev.brighten.anticheat.utils.ExponentialMovingAverage; | ||
import dev.brighten.anticheat.utils.MiscUtils; | ||
import dev.brighten.api.check.CheckType; | ||
import lombok.val; | ||
|
||
@CheckInfo(name = "Timer (B)", description = "Checks the rate of packets coming in.", | ||
checkType = CheckType.BADPACKETS, vlToFlag = 4, developer = true) | ||
@Cancellable | ||
public class TimerB extends Check { | ||
|
||
private int ticks, buffer; | ||
private ExponentialMovingAverage average = new ExponentialMovingAverage(50); | ||
private long lastFlying = System.currentTimeMillis(); | ||
|
||
@Packet | ||
public void onPacket(WrappedInFlyingPacket packet, long current) { | ||
|
||
double avg = average.average(current - lastFlying); | ||
|
||
debug("std=%v.5", avg); | ||
lastFlying = current; | ||
} | ||
} |