Fixed bad packets / packet order in <= 1.20.1

This commit is contained in:
FlorianMichael 2023-09-24 03:15:19 +02:00
parent f63ff90711
commit 4ce73a42e5
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.network.ClientLoginNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.login.EnterConfigurationC2SPacket;
import net.raphimc.vialoader.util.VersionEnum;
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.Redirect;
@Mixin(ClientLoginNetworkHandler.class)
public class MixinClientLoginNetworkHandler {
@Shadow @Final private ClientConnection connection;
@Redirect(method = "onSuccess", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;)V"))
public void sendPackets(ClientConnection instance, Packet<?> packet) {
// Minecraft used to send these packets when the join game packet by the server is received
if (ProtocolHack.getTargetVersion(connection.channel).isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1) && !(packet instanceof EnterConfigurationC2SPacket)) return;
instance.send(packet);
}
}

View File

@ -22,12 +22,16 @@ import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings;
import de.florianmichael.viafabricplus.injection.access.IBoatEntity;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
import net.minecraft.client.network.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.BrandCustomPayload;
import net.minecraft.network.packet.c2s.common.ClientOptionsC2SPacket;
import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.raphimc.vialoader.util.VersionEnum;
import org.slf4j.Logger;
@ -68,6 +72,17 @@ public abstract class MixinClientPlayNetworkHandler {
}
}
@Inject(method = "onGameJoin", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;setServerViewDistance(I)V", shift = At.Shift.AFTER))
public void sendBrandAndOptionPackets(GameJoinS2CPacket packet, CallbackInfo ci) {
// Counterpart from MixinClientLoginNetworkHandler
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
final var connection = this.getConnection();
connection.send(new ClientOptionsC2SPacket(MinecraftClient.getInstance().options.getSyncedOptions()));
connection.send(new CustomPayloadC2SPacket(new BrandCustomPayload(ClientBrandRetriever.getClientModName())));
}
}
@Inject(method = "onChunkLoadDistance", at = @At("RETURN"))
public void emulateSimulationDistance(ChunkLoadDistanceS2CPacket packet, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17_1)) {

View File

@ -115,6 +115,7 @@
"fixes.minecraft.item.MixinShovelItem",
"fixes.minecraft.item.MixinSwordItem",
"fixes.minecraft.network.MixinClientCommonNetworkHandler",
"fixes.minecraft.network.MixinClientLoginNetworkHandler",
"fixes.minecraft.network.MixinClientPlayNetworkHandler",
"fixes.minecraft.packet.MixinChatMessageC2SPacket",
"fixes.minecraft.packet.MixinPacketByteBuf",