Skip to content

Commit 65815fc

Browse files
committed
Merge remote-tracking branch 'origin/2.0' into lightning
# Conflicts: # common/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java
2 parents 5efefe5 + c169d9c commit 65815fc

54 files changed

Lines changed: 631 additions & 408 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-and-publish.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,21 @@ jobs:
233233
dependencies: 'fabric-api'
234234

235235
- name: Publish to API
236-
if: ${{ inputs.publish-artifacts == true && env.BUILD_UPDATE_TOKEN != '' }}
236+
if: ${{ inputs.publish-artifacts == true && env.BUILD_UPDATE_TOKEN != '' && inputs.is-release-build == false }}
237237
run: |
238238
curl -X POST \
239239
-H "Content-Type: application/json" \
240240
-H "User-Agent: GrimACBuilder/v1" \
241241
-H "Authorization: Bearer ${{ secrets.BUILD_UPDATE_TOKEN }}" \
242242
-d '{"org": "${{ github.repository_owner }}", "repository": "${{ github.event.repository.name }}", "branch": "${{ github.ref_name }}", "version": "${{ env.BUILD_VERSION }}"}' \
243243
"${{ secrets.BUILD_UPDATE_URL }}"
244+
245+
- name: Publish Release to API
246+
if: ${{ inputs.publish-artifacts == true && env.BUILD_UPDATE_TOKEN != '' && inputs.is-release-build == true }}
247+
run: |
248+
curl -X POST \
249+
-H "Content-Type: application/json" \
250+
-H "User-Agent: GrimACBuilder/v1" \
251+
-H "Authorization: Bearer ${{ secrets.BUILD_UPDATE_TOKEN }}" \
252+
-d '{"org": "${{ github.repository_owner }}", "repository": "${{ github.event.repository.name }}", "branch": "release", "version": "${{ env.BUILD_VERSION }}"}' \
253+
"${{ secrets.BUILD_UPDATE_URL }}"

common/src/main/java/ac/grim/grimac/checks/Check.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ public static boolean isTransaction(PacketTypeCommon packetType) {
176176

177177
public static boolean isAsync(PacketTypeCommon packetType) {
178178
return packetType == PacketType.Play.Client.KEEP_ALIVE
179-
|| packetType == PacketType.Play.Client.CHUNK_BATCH_ACK;
179+
|| packetType == PacketType.Play.Client.CHUNK_BATCH_ACK
180+
|| packetType == PacketType.Play.Client.RESOURCE_PACK_STATUS;
180181
}
181182

182183
public boolean isUpdate(PacketTypeCommon packetType) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ac.grim.grimac.checks.impl.badpackets;
2+
3+
import ac.grim.grimac.checks.Check;
4+
import ac.grim.grimac.checks.CheckData;
5+
import ac.grim.grimac.checks.type.PacketCheck;
6+
import ac.grim.grimac.player.GrimPlayer;
7+
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
8+
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
9+
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
@CheckData(name = "BadPacketsC", description = "Tried to wake up while not sleeping", experimental = true)
13+
public class BadPacketsC extends Check implements PacketCheck {
14+
public BadPacketsC(@NotNull GrimPlayer player) {
15+
super(player);
16+
}
17+
18+
@Override
19+
public void onPacketReceive(PacketReceiveEvent event) {
20+
if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION
21+
&& new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.LEAVE_BED
22+
&& !player.isInBed) {
23+
flagAndAlert();
24+
}
25+
}
26+
}

common/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsT.java

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
1111
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
1212
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
13+
import com.github.retrooper.packetevents.util.Vector3d;
1314
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
1415

1516
@CheckData(name = "BadPacketsT")
@@ -35,37 +36,39 @@ public void onPacketReceive(final PacketReceiveEvent event) {
3536
if (event.getPacketType().equals(PacketType.Play.Client.INTERACT_ENTITY)) {
3637
final WrapperPlayClientInteractEntity wrapper = new WrapperPlayClientInteractEntity(event);
3738
// Only INTERACT_AT actually has an interaction vector
38-
wrapper.getTarget().ifPresent(targetVector -> {
39-
final PacketEntity packetEntity = player.compensatedEntities.getEntity(wrapper.getEntityId());
40-
// Don't continue if the compensated entity hasn't been resolved
41-
if (packetEntity == null) {
42-
return;
43-
}
39+
if (wrapper.getAction() != WrapperPlayClientInteractEntity.InteractAction.INTERACT_AT) return;
40+
Vector3d targetVector = wrapper.getLocation();
41+
if (targetVector == null) return; // shouldn't ever happen, but whatever
4442

45-
// Make sure our target entity is actually a player (Player NPCs work too)
46-
if (!EntityTypes.PLAYER.equals(packetEntity.type)) {
47-
// We can't check for any entity that is not a player
48-
return;
49-
}
43+
final PacketEntity packetEntity = player.compensatedEntities.getEntity(wrapper.getEntityId());
44+
// Don't continue if the compensated entity hasn't been resolved
45+
if (packetEntity == null) {
46+
return;
47+
}
5048

51-
// Perform the interaction vector check
52-
// TODO:
53-
// 27/12/2023 - Dynamic values for more than just one entity type?
54-
// 28/12/2023 - Player-only is fine
55-
// 30/12/2023 - Expansions differ in 1.9+
56-
final float scale = (float) packetEntity.getAttributeValue(Attributes.SCALE);
57-
if (targetVector.y > (minVerticalDisplacement * scale) && targetVector.y < (maxVerticalDisplacement * scale)
58-
&& Math.abs(targetVector.x) < (maxHorizontalDisplacement * scale)
59-
&& Math.abs(targetVector.z) < (maxHorizontalDisplacement * scale)) {
60-
return;
61-
}
49+
// Make sure our target entity is actually a player (Player NPCs work too)
50+
if (!EntityTypes.PLAYER.equals(packetEntity.type)) {
51+
// We can't check for any entity that is not a player
52+
return;
53+
}
6254

63-
// Log the vector
64-
final String verbose = String.format("%.5f/%.5f/%.5f",
65-
targetVector.x, targetVector.y, targetVector.z);
66-
// We could pretty much ban the player at this point
67-
flagAndAlert(verbose);
68-
});
55+
// Perform the interaction vector check
56+
// TODO:
57+
// 27/12/2023 - Dynamic values for more than just one entity type?
58+
// 28/12/2023 - Player-only is fine
59+
// 30/12/2023 - Expansions differ in 1.9+
60+
final float scale = (float) packetEntity.getAttributeValue(Attributes.SCALE);
61+
if (targetVector.y > (minVerticalDisplacement * scale) && targetVector.y < (maxVerticalDisplacement * scale)
62+
&& Math.abs(targetVector.x) < (maxHorizontalDisplacement * scale)
63+
&& Math.abs(targetVector.z) < (maxHorizontalDisplacement * scale)) {
64+
return;
65+
}
66+
67+
// Log the vector
68+
final String verbose = String.format("%.5f/%.5f/%.5f",
69+
targetVector.x, targetVector.y, targetVector.z);
70+
// We could pretty much ban the player at this point
71+
flagAndAlert(verbose);
6972
}
7073
}
7174
}

common/src/main/java/ac/grim/grimac/checks/impl/combat/MultiInteractA.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
88
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
99
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
10+
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientAttack;
1011
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
12+
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientSpectateEntity;
1113

1214
import java.util.ArrayList;
1315

@@ -28,30 +30,43 @@ public void onPacketReceive(PacketReceiveEvent event) {
2830
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
2931
int entity = packet.getEntityId();
3032
boolean sneaking = packet.isSneaking().orElse(false);
33+
onInteract(event, entity, sneaking);
34+
}
3135

32-
if (hasInteracted && entity != lastEntity) {
33-
String verbose = "lastEntity=" + lastEntity + ", entity=" + entity
34-
+ ", lastSneaking=" + lastSneaking + ", sneaking=" + sneaking;
35-
if (!player.canSkipTicks()) {
36-
if (flagAndAlert(verbose) && shouldModifyPackets()) {
37-
event.setCancelled(true);
38-
player.onPacketCancel();
39-
}
40-
} else {
41-
flags.add(verbose);
42-
}
43-
}
36+
if (event.getPacketType() == PacketType.Play.Client.ATTACK) {
37+
WrapperPlayClientAttack packet = new WrapperPlayClientAttack(event);
38+
onInteract(event, packet.getEntityId(), lastSneaking);
39+
}
4440

45-
lastEntity = entity;
46-
lastSneaking = sneaking;
47-
hasInteracted = true;
41+
if (event.getPacketType() == PacketType.Play.Client.SPECTATE_ENTITY) {
42+
WrapperPlayClientSpectateEntity packet = new WrapperPlayClientSpectateEntity(event);
43+
onInteract(event, packet.getEntityId(), lastSneaking);
4844
}
4945

5046
if (!player.cameraEntity.isSelf() || isTickPacket(event.getPacketType())) {
5147
hasInteracted = false;
5248
}
5349
}
5450

51+
private void onInteract(PacketReceiveEvent event, int entity, boolean sneaking) {
52+
if (hasInteracted && (entity != lastEntity || sneaking != lastSneaking)) {
53+
String verbose = "lastEntity=" + lastEntity + ", entity=" + entity
54+
+ ", lastSneaking=" + lastSneaking + ", sneaking=" + sneaking;
55+
if (!player.canSkipTicks()) {
56+
if (flagAndAlert(verbose) && shouldModifyPackets()) {
57+
event.setCancelled(true);
58+
player.onPacketCancel();
59+
}
60+
} else {
61+
flags.add(verbose);
62+
}
63+
}
64+
65+
lastEntity = entity;
66+
lastSneaking = sneaking;
67+
hasInteracted = true;
68+
}
69+
5570
@Override
5671
public void onPredictionComplete(PredictionComplete predictionComplete) {
5772
if (!player.canSkipTicks()) return;

common/src/main/java/ac/grim/grimac/checks/impl/combat/MultiInteractB.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
99
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
1010
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
11-
import com.github.retrooper.packetevents.util.Vector3f;
11+
import com.github.retrooper.packetevents.util.Vector3d;
1212
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
1313

1414
import java.util.ArrayList;
1515

1616
@CheckData(name = "MultiInteractB", experimental = true)
1717
public class MultiInteractB extends Check implements PostPredictionCheck {
1818
private final ArrayList<String> flags = new ArrayList<>();
19-
private Vector3f lastPos;
20-
private boolean hasInteracted = false;
19+
private Vector3d lastPos;
20+
private boolean hasInteracted;
2121

2222
public MultiInteractB(final GrimPlayer player) {
2323
super(player);
@@ -26,11 +26,11 @@ public MultiInteractB(final GrimPlayer player) {
2626
@Override
2727
public void onPacketReceive(PacketReceiveEvent event) {
2828
if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
29-
Vector3f pos = new WrapperPlayClientInteractEntity(event).getTarget().orElse(null);
29+
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
30+
if (packet.getAction() != WrapperPlayClientInteractEntity.InteractAction.INTERACT_AT) return;
3031

31-
if (pos == null) {
32-
return;
33-
}
32+
Vector3d pos = packet.getLocation();
33+
if (pos == null) return; // shouldn't ever happen, but whatever
3434

3535
if (hasInteracted && !pos.equals(lastPos)) {
3636
String verbose = "pos=" + MessageUtil.toUnlabledString(pos) + ", lastPos=" + MessageUtil.toUnlabledString(lastPos);

0 commit comments

Comments
 (0)