crash fix bugs fixed yipee!!!

This commit is contained in:
NotCoded committed 2024-06-01 20:36:08 +02:00
1 parent cb7600b140
commit bf3e5d8719
3 files changed
+72 -1

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ yarn_mappings=1.16_combat-6+build.2
loader_version=0.14.21
# Mod Properties
mod_version=1.0.3
mod_version=1.0.4
maven_group=com.nexia
archives_base_name=gato-anticheat
@@ -41,11 +41,14 @@ public class GatoAntiCheat implements ModInitializer {
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
if (player instanceof ServerPlayer serverPlayer) {
/*
if (!serverPlayer.swinging) {
PlayerDetectionEvent.NOSWING.invoker().onNoSwingDetection(player, entity);
return InteractionResult.FAIL;
}
*/
if (!CombatUtil.allowReach(serverPlayer, entity)) {
PlayerDetectionEvent.REACH.invoker().onReachDetection(player, entity);
return InteractionResult.FAIL;
@@ -2,6 +2,8 @@ package com.nexia.gatoanticheat.mixin;
import com.nexia.gatoanticheat.events.PlayerDetectionEvent;
import com.nexia.gatoanticheat.players.CombatUtil;
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
@@ -60,4 +62,70 @@ public class ServerGamePacketListenerMixin {
}
}
@Unique private static final String[] ABUSABLE_SEQUENCES = { "@", "[", "nbt", "=", "{", "}", "]" };
@Inject(method = "handleCustomCommandSuggestions", at = @At("HEAD"), cancellable = true)
private void fixSuggestionsCrash(ServerboundCommandSuggestionPacket serverboundCommandSuggestionPacket, CallbackInfo ci) {
final String text = serverboundCommandSuggestionPacket.getCommand();
int length = text.length();
if(this.player.hasPermissions(2)) return;
if (length > 256) {
ci.cancel();
return;
}
if (length > 64) {
final int index = text.indexOf(' ');
if (index == -1 || index >= 64) {
ci.cancel();
return;
}
}
for (String sequence : ABUSABLE_SEQUENCES) {
if (text.contains(sequence)) {
ci.cancel();
return;
}
}
}
@Inject(method = "handleContainerClick", cancellable = true, at = @At("HEAD"))
private void fixContainerCrash(ServerboundContainerClickPacket clickPacket, CallbackInfo ci) {
int containerId = clickPacket.getContainerId();
int slot = clickPacket.getSlotNum();
if (containerId < 0 || containerId > 10 && containerId != 40 && containerId != 99) {
ci.cancel();
return;
}
if (slot != -999 && slot != -1) {
if (slot < 0) {
ci.cancel();
}
return;
}
if (containerId == 40) {
ci.cancel();
return;
}
switch (clickPacket.getClickType()) {
case SWAP, PICKUP_ALL -> ci.cancel();
case THROW -> {
if (slot == -1) {
ci.cancel();
}
}
case QUICK_MOVE -> {
if (slot == -999) {
ci.cancel();
}
}
}
}
}