This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Shadow/src/main/java/net/shadow/client/mixin/ClientConnectionMixin.java

46 lines
1.8 KiB
Java
Raw Normal View History

2022-03-13 01:56:03 +01:00
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
2022-03-10 00:28:36 +01:00
package net.shadow.client.mixin;
2021-12-18 20:04:57 +01:00
2022-02-03 22:17:39 +01:00
import io.netty.channel.ChannelHandlerContext;
2021-12-18 20:04:57 +01:00
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import net.minecraft.network.listener.PacketListener;
2022-04-19 17:00:27 -05:00
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket;
2022-03-10 00:28:36 +01:00
import net.shadow.client.feature.module.ModuleRegistry;
import net.shadow.client.feature.module.impl.misc.AntiPacketKick;
import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.Events;
import net.shadow.client.helper.event.events.PacketEvent;
2021-12-18 20:04:57 +01:00
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2022-03-05 01:59:31 +01:00
@Mixin(ClientConnection.class)
public class ClientConnectionMixin {
2021-12-18 20:04:57 +01:00
@Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true)
2022-04-02 19:28:56 -05:00
private static <T extends PacketListener> void dispatchPacketGet(Packet<T> packet, PacketListener listener, CallbackInfo ci) {
2021-12-18 20:04:57 +01:00
if (Events.fireEvent(EventType.PACKET_RECEIVE, new PacketEvent(packet))) {
ci.cancel();
}
}
2022-03-05 01:59:31 +01:00
@Inject(method = "exceptionCaught", at = @At("HEAD"), cancellable = true)
2022-04-02 19:28:56 -05:00
public void catchException(ChannelHandlerContext context, Throwable ex, CallbackInfo ci) {
2022-02-03 22:17:39 +01:00
if (ModuleRegistry.getByClass(AntiPacketKick.class).isEnabled()) {
ci.cancel();
}
}
2022-03-05 01:59:31 +01:00
@Inject(method = "send(Lnet/minecraft/network/Packet;)V", cancellable = true, at = @At("HEAD"))
2022-04-02 19:28:56 -05:00
public void dispatchPacketSend(Packet<?> packet, CallbackInfo ci) {
2021-12-18 20:04:57 +01:00
if (Events.fireEvent(EventType.PACKET_SEND, new PacketEvent(packet))) {
ci.cancel();
}
}
}