Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: FlorianMichael <[email protected]>
  • Loading branch information
RaphiMC and FlorianMichael committed Feb 19, 2025
1 parent 4e2e010 commit e7ea6c1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -478,6 +485,15 @@ public void setFakeAcceptResourcePacks(final boolean fakeAcceptResourcePacks) {
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) {
Expand Down

0 comments on commit e7ea6c1

Please sign in to comment.