mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-16 10:55:39 +01:00
Don't send resource pack validation packets in main thread (1.20.3 -> 1.20.2)
This commit is contained in:
parent
5762a0578f
commit
b731ff7925
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
|
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
|
||||||
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
||||||
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
||||||
@ -30,18 +32,23 @@ import net.minecraft.client.network.ClientCommonNetworkHandler;
|
|||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.listener.ServerPacketListener;
|
import net.minecraft.network.listener.ServerPacketListener;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
|
import net.minecraft.network.packet.c2s.common.ResourcePackStatusC2SPacket;
|
||||||
import net.minecraft.network.packet.s2c.common.CommonPingS2CPacket;
|
import net.minecraft.network.packet.s2c.common.CommonPingS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
|
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.raphimc.vialoader.util.VersionEnum;
|
import net.raphimc.vialoader.util.VersionEnum;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
@ -63,6 +70,15 @@ public abstract class MixinClientCommonNetworkHandler {
|
|||||||
@Final
|
@Final
|
||||||
protected ClientConnection connection;
|
protected ClientConnection connection;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Nullable
|
||||||
|
private static URL getParsedResourcePackUrl(String url) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private URL viaFabricPlus$lastValidatedUrl;
|
||||||
|
|
||||||
@Redirect(method = "onKeepAlive", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;send(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V"))
|
@Redirect(method = "onKeepAlive", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;send(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V"))
|
||||||
private void forceSendKeepAlive(ClientCommonNetworkHandler instance, Packet<? extends ServerPacketListener> packet, BooleanSupplier sendCondition, Duration expiry) {
|
private void forceSendKeepAlive(ClientCommonNetworkHandler instance, Packet<? extends ServerPacketListener> packet, BooleanSupplier sendCondition, Duration expiry) {
|
||||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
|
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
|
||||||
@ -101,4 +117,24 @@ public abstract class MixinClientCommonNetworkHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "onResourcePackSend", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void validateUrlInNetworkThread(ResourcePackSendS2CPacket packet, CallbackInfo ci) {
|
||||||
|
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
|
||||||
|
viaFabricPlus$lastValidatedUrl = getParsedResourcePackUrl(packet.url());
|
||||||
|
if (viaFabricPlus$lastValidatedUrl == null) {
|
||||||
|
this.connection.send(new ResourcePackStatusC2SPacket(packet.id(), ResourcePackStatusC2SPacket.Status.INVALID_URL));
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@WrapOperation(method = "onResourcePackSend", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;getParsedResourcePackUrl(Ljava/lang/String;)Ljava/net/URL;"))
|
||||||
|
private URL useLastValidatedUrl(String url, Operation<URL> original) {
|
||||||
|
if (viaFabricPlus$lastValidatedUrl != null) {
|
||||||
|
return viaFabricPlus$lastValidatedUrl;
|
||||||
|
} else {
|
||||||
|
return original.call(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user