-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
116 additions
and
232 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
...on/src/main/java/me/drex/antixray/common/mixin/ClientboundChunkBatchStartPacketMixin.java
This file was deleted.
Oops, something went wrong.
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
79 changes: 37 additions & 42 deletions
79
common/src/main/java/me/drex/antixray/common/mixin/ConnectionMixin.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 |
---|---|---|
@@ -1,88 +1,83 @@ | ||
package me.drex.antixray.common.mixin; | ||
|
||
import com.google.common.collect.Queues; | ||
import io.netty.channel.Channel; | ||
import me.drex.antixray.common.util.Util; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.PacketSendListener; | ||
import net.minecraft.network.protocol.Packet; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Queue; | ||
import java.util.function.BooleanSupplier; | ||
import java.util.function.Consumer; | ||
|
||
|
||
@Mixin(Connection.class) | ||
public abstract class ConnectionMixin { | ||
|
||
@Unique | ||
private final Queue<BooleanSupplier> antiXray$isActionReady = Queues.newConcurrentLinkedQueue(); | ||
@Shadow | ||
private Channel channel; | ||
|
||
@Shadow | ||
@Final | ||
private Queue<Consumer<Connection>> pendingActions; | ||
private Queue<Object> queue; | ||
|
||
@Shadow | ||
protected abstract void sendPacket(Packet<?> $$0, PacketSendListener $$1, boolean $$2); | ||
@Shadow protected abstract void sendPacket(Packet<?> $$0, PacketSendListener $$1); | ||
|
||
/** | ||
* @author Drex | ||
* @reason Wait for chunk packets to be ready (fully obfuscated) | ||
*/ | ||
@Overwrite | ||
private void flushQueue() { | ||
assert pendingActions.size() == antiXray$isActionReady.size(); | ||
private boolean flushQueue() { | ||
if (this.channel != null && this.channel.isOpen()) { | ||
synchronized (this.pendingActions) { | ||
while (!this.antiXray$isActionReady.isEmpty() && (this.antiXray$isActionReady.peek().getAsBoolean())) { | ||
pendingActions.poll().accept((Connection) (Object) this); | ||
antiXray$isActionReady.poll(); | ||
synchronized (this.queue) { | ||
while (!this.queue.isEmpty()) { | ||
if (this.queue.peek() instanceof ConnectionPacketHolderAccessor packetAccessor) { // poll -> peek | ||
if (!Util.isReady(packetAccessor.getPacket())) { | ||
return false; // Return false if the peeked packet is a chunk packet which is not ready | ||
} else { | ||
this.queue.poll(); // poll here | ||
this.sendPacket(packetAccessor.getPacket(), packetAccessor.getListener()); // dispatch the packet | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Redirect( | ||
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;Z)V", | ||
method = "tick", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/network/Connection;sendPacket(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;Z)V" | ||
target = "Lnet/minecraft/network/Connection;flushQueue()V" | ||
) | ||
) | ||
public void redirectSendPacket(Connection instance, Packet<?> packet, PacketSendListener listener, boolean flush) { | ||
if (this.antiXray$isActionReady.isEmpty() && Util.isReady(packet)) { | ||
this.sendPacket(packet, listener, flush); | ||
} else { | ||
pendingActions.add(connection -> this.sendPacket(packet, listener, flush)); | ||
antiXray$isActionReady.add(() -> Util.isReady(packet)); | ||
} | ||
public void replaceFlushQueue(Connection connection) { | ||
// Calling our own implementation | ||
this.flushQueue(); | ||
} | ||
|
||
@Inject( | ||
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;Z)V", | ||
@Redirect( | ||
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z" | ||
target = "Lnet/minecraft/network/Connection;flushQueue()V" | ||
) | ||
) | ||
public void addToActionReadyQueue(Packet<?> packet, PacketSendListener listener, boolean flush, CallbackInfo ci) { | ||
antiXray$isActionReady.add(() -> Util.isReady(packet)); | ||
public void noop(Connection connection) { | ||
// no-op | ||
// The call to our own flushQueue method has been moved inside the previous if statement (see below) | ||
} | ||
|
||
@Inject( | ||
method = {"flushChannel", "runOnceConnected"}, | ||
@Redirect( | ||
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z" | ||
target = "Lnet/minecraft/network/Connection;isConnected()Z" | ||
) | ||
) | ||
public void addToActionReadyQueue(CallbackInfo ci) { | ||
antiXray$isActionReady.add(() -> true); | ||
public boolean redirectIfStatement(Connection connection, Packet<?> packet, PacketSendListener listener) { | ||
return connection.isConnected() && this.flushQueue() && Util.isReady(packet); | ||
} | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
common/src/main/java/me/drex/antixray/common/mixin/ConnectionPacketHolderAccessor.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,15 @@ | ||
package me.drex.antixray.common.mixin; | ||
|
||
import net.minecraft.network.PacketSendListener; | ||
import net.minecraft.network.protocol.Packet; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(targets = "net.minecraft.network.Connection$PacketHolder") | ||
public interface ConnectionPacketHolderAccessor { | ||
@Accessor("packet") | ||
Packet<?> getPacket(); | ||
|
||
@Accessor("listener") | ||
PacketSendListener getListener(); | ||
} |
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
60 changes: 0 additions & 60 deletions
60
common/src/main/java/me/drex/antixray/common/mixin/PlayerChunkSenderMixin.java
This file was deleted.
Oops, something went wrong.
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
24 changes: 0 additions & 24 deletions
24
.../java/me/drex/antixray/fabric/mixin/imm_ptl_core/ClientboundCustomPayloadPacketMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.