Skip to content

Commit

Permalink
Try compatible Quilt
Browse files Browse the repository at this point in the history
fix #25, fix #28
  • Loading branch information
james58899 committed Jul 17, 2022
1 parent 0b0ccc5 commit aba1837
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package one.oktw.mixin.hack;

import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.server.ServerLoginNetworkAddon;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.jetbrains.annotations.Nullable;
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.callback.CallbackInfo;

import java.util.concurrent.ThreadLocalRandom;

import static one.oktw.VelocityLib.PLAYER_INFO_CHANNEL;
import static one.oktw.VelocityLib.PLAYER_INFO_PACKET;

Expand All @@ -20,11 +23,15 @@ public class ServerLoginNetworkHandler_EarlySendPacket {
@Shadow
@Nullable GameProfile profile;

@Shadow
@Final
public ClientConnection connection;

@Inject(method = "onHello", at = @At(value = "HEAD"), cancellable = true)
private void skipKeyPacket(LoginHelloC2SPacket packet, CallbackInfo ci) {
if (profile != null && profile.isComplete()) return; // Already receive profile form velocity.

((ServerLoginNetworkAddon) ((NetworkHandlerExtensions) this).getAddon()).sendPacket(PLAYER_INFO_CHANNEL, PLAYER_INFO_PACKET);
connection.send(new LoginQueryRequestS2CPacket(ThreadLocalRandom.current().nextInt(), PLAYER_INFO_CHANNEL, PLAYER_INFO_PACKET));
ci.cancel();
}
}

0 comments on commit aba1837

Please sign in to comment.