Skip to content

Commit

Permalink
Fixed ServerSpoof (#4599)
Browse files Browse the repository at this point in the history
  • Loading branch information
19MisterX98 authored May 24, 2024
1 parent dded574 commit 2b68dd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public static class Send extends Cancellable {
private static final Send INSTANCE = new Send();

public Packet<?> packet;
public ClientConnection connection;

public static Send get(Packet<?> packet) {
public static Send get(Packet<?> packet, ClientConnection connection) {
INSTANCE.setCancelled(false);
INSTANCE.packet = packet;
INSTANCE.connection = connection;
return INSTANCE;
}
}
Expand All @@ -40,9 +42,11 @@ public static class Sent {
private static final Sent INSTANCE = new Sent();

public Packet<?> packet;
public ClientConnection connection;

public static Sent get(Packet<?> packet) {
public static Sent get(Packet<?> packet, ClientConnection connection) {
INSTANCE.packet = packet;
INSTANCE.connection = connection;
return INSTANCE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ private static void onConnect(InetSocketAddress address, boolean useEpoll, Clien

@Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;)V", cancellable = true)
private void onSendPacketHead(Packet<?> packet, PacketCallbacks callbacks, CallbackInfo ci) {
if (MeteorClient.EVENT_BUS.post(PacketEvent.Send.get(packet)).isCancelled()) {
if (MeteorClient.EVENT_BUS.post(PacketEvent.Send.get(packet, (ClientConnection) (Object) this)).isCancelled()) {
ci.cancel();
}
}

@Inject(method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;)V", at = @At("TAIL"))
private void onSendPacketTail(Packet<?> packet, @Nullable PacketCallbacks callbacks, CallbackInfo ci) {
MeteorClient.EVENT_BUS.post(PacketEvent.Sent.get(packet));
MeteorClient.EVENT_BUS.post(PacketEvent.Sent.get(packet, (ClientConnection) (Object) this));
}

@Inject(method = "exceptionCaught", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ private void onPacketSend(PacketEvent.Send event) {
if (!isActive() || !(event.packet instanceof CustomPayloadC2SPacket)) return;
Identifier id = ((CustomPayloadC2SPacket) event.packet).payload().getId().id();

if (spoofBrand.get() && id.equals(BrandCustomPayload.ID.id()))
event.packet = new CustomPayloadC2SPacket(new BrandCustomPayload(brand.get()));

if (blockChannels.get()) {
for (String channel : channels.get()) {
if (StringUtils.containsIgnoreCase(id.toString(), channel)) {
Expand All @@ -87,6 +84,14 @@ private void onPacketSend(PacketEvent.Send event) {
}
}
}

if (spoofBrand.get() && id.equals(BrandCustomPayload.ID.id())) {
CustomPayloadC2SPacket spoofedPacket = new CustomPayloadC2SPacket(new BrandCustomPayload(brand.get()));

// PacketEvent.Send doesn't trigger if we send the packet like this
event.connection.send(spoofedPacket, null, true);
event.cancel();
}
}

@EventHandler
Expand Down

0 comments on commit 2b68dd4

Please sign in to comment.