Skip to content

Commit

Permalink
Try to fix compression
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 12, 2022
1 parent 81e08a3 commit 88f37b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ishland.raknetfabric.mixin.compat.fabricapi;

import com.ishland.raknetfabric.mixin.access.IClientConnection;
import net.minecraft.network.ClientConnection;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -23,15 +24,21 @@ public class MixinServerLoginNetworkAddon {
@SuppressWarnings("DefaultAnnotationParam")
@Dynamic("Pseudo")
@Inject(method = "sendCompressionPacket()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", ordinal = 0, shift = At.Shift.AFTER, remap = true), remap = false)
private void setupDummyCompressionImmediately(CallbackInfo info) throws Throwable {
try {
this.connection.setCompressionThreshold(Integer.MAX_VALUE, false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method: ");
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, Integer.MAX_VALUE);
}
private void setupDummyCompressionImmediately(CallbackInfo info) {
((IClientConnection) this.connection).getChannel().eventLoop().execute(() -> {
try {
try {
this.connection.setCompressionThreshold(512, false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method: ");
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, 512);
}
} catch (Throwable t) {
t.printStackTrace();
}
});
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ishland.raknetfabric.mixin.server;

import com.ishland.raknetfabric.mixin.access.IClientConnection;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -18,14 +19,20 @@ public class MixinServerLoginNetworkHandler {

@Inject(method = "acceptPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", ordinal = 0, shift = At.Shift.AFTER))
private void setupDummyCompressionImmediately(CallbackInfo ci) throws Throwable {
try {
this.connection.setCompressionThreshold(Integer.MAX_VALUE, false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method");
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, Integer.MAX_VALUE);
}
((IClientConnection) this.connection).getChannel().eventLoop().execute(() -> {
try {
try {
this.connection.setCompressionThreshold(512, false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method: ");
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, 512);
}
} catch (Throwable t) {
t.printStackTrace();
}
});
}

}

0 comments on commit 88f37b5

Please sign in to comment.