Co-authored-by: FlorianMichael <florian.michael07@gmail.com>
This commit is contained in:
RaphiMC 2025-02-19 21:24:24 +01:00
parent 4e2e010b2d
commit e7ea6c1529
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94
2 changed files with 62 additions and 0 deletions
src/main/java/net/raphimc/viaproxy
injection/mixins
protocoltranslator/viaproxy

View file

@ -0,0 +1,46 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2025 RK_01/RaphiMC 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 net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.storage.ConfigurationState;
import net.raphimc.viaproxy.ViaProxy;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = ConfigurationState.class, remap = false)
public abstract class MixinConfigurationState {
@Inject(method = "addPacketToQueue", at = @At("HEAD"), cancellable = true)
private void cancelQueuedPackets(PacketWrapper wrapper, boolean clientbound, CallbackInfo ci) {
// Dirty workaround for https://github.com/ViaVersion/ViaVersion/issues/4308 where queued packets
// without set packet type cause a disconnect after sent in play state, even when delayed until the client
// has transitioned to the play state as well. This is *very* bad as in worst will cause data loss and other
// issues but /shrug for now.
if (ViaProxy.getConfig().shouldWorkAroundConfigStatePacketQueue() && clientbound && wrapper.getPacketType() == null) {
final int unmappedId = wrapper.getId();
if (unmappedId == ClientboundPackets1_19_4.CONTAINER_CLOSE.getId() || unmappedId == ClientboundPackets1_19_4.CHUNKS_BIOMES.getId() || unmappedId == ClientboundPackets1_19_4.SET_ENTITY_MOTION.getId()) {
ci.cancel();
}
}
}
}

View file

@ -183,6 +183,13 @@ public class ViaProxyConfig {
})
private boolean fakeAcceptResourcePacks = false;
@Option("workaround-config-state-packet-queue")
@Description({
"Fixes https://github.com/ViaVersion/ViaVersion/issues/4308 where the config state packet queue causes a disconnect sometimes.",
"It's recommended to only enable this if you are experiencing issues with the config state packet queue (See above issue)."
})
private boolean workAroundConfigStatePacketQueue = false;
public static ViaProxyConfig create(final File configFile) {
final ConfigLoader<ViaProxyConfig> configLoader = new ConfigLoader<>(ViaProxyConfig.class);
configLoader.getConfigOptions().setResetInvalidOptions(true).setRewriteConfig(true).setCommentSpacing(1);
@ -478,6 +485,15 @@ public class ViaProxyConfig {
this.save();
}
public boolean shouldWorkAroundConfigStatePacketQueue() {
return this.workAroundConfigStatePacketQueue;
}
public void setWorkAroundConfigStatePacketQueue(final boolean workAroundConfigStatePacketQueue) {
this.workAroundConfigStatePacketQueue = workAroundConfigStatePacketQueue;
this.save();
}
@Validator("target-version")
private ProtocolVersion validateTargetVersion(final ProtocolVersion targetVersion) {
if (targetVersion == null) {