From 0e44fbfb4b887346e2f053e3b735214ee74257a7 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 22 Mar 2023 15:23:57 +0100 Subject: [PATCH] Updated Via* --- .github/USAGE.md | 2 +- .../information/impl/BedrockInformation.java | 12 ++-- .../access/IPlayerPositionLookS2CPacket.java | 23 ------- .../injection/mixin/bridge/MixinDebugHud.java | 4 +- .../MixinClientPlayNetworkHandler.java | 10 --- .../MixinPlayerPositionLookS2CPacket.java | 48 ------------- .../MixinEntityPackets.java | 55 --------------- .../protocolhack/ProtocolHack.java | 8 ++- .../ViaFabricPlusBlobCacheProvider.java | 68 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 2 - 10 files changed, 86 insertions(+), 146 deletions(-) delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/viabedrock/ViaFabricPlusBlobCacheProvider.java diff --git a/.github/USAGE.md b/.github/USAGE.md index 0d951044..3574a5e2 100644 --- a/.github/USAGE.md +++ b/.github/USAGE.md @@ -1,4 +1,4 @@ -## Settings and GUI +# Settings and GUI In the multiplayer screen you will find the ViaFabricPlus button in the upper left corner by default, it is the main button,
click on it, and you will see the Protocol selection, there you can choose the Minecraft version you want to connect to,
in the upper left corner you can go to the Settings. diff --git a/src/main/java/de/florianmichael/viafabricplus/information/impl/BedrockInformation.java b/src/main/java/de/florianmichael/viafabricplus/information/impl/BedrockInformation.java index 11165442..fdfb888a 100644 --- a/src/main/java/de/florianmichael/viafabricplus/information/impl/BedrockInformation.java +++ b/src/main/java/de/florianmichael/viafabricplus/information/impl/BedrockInformation.java @@ -17,10 +17,12 @@ */ package de.florianmichael.viafabricplus.information.impl; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.definition.bedrock.storage.JoinGameStorage; import de.florianmichael.viafabricplus.definition.bedrock.ModelFormats; import de.florianmichael.viafabricplus.information.AbstractInformationGroup; +import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusBlobCacheProvider; import de.florianmichael.viafabricplus.util.ScreenUtil; import de.florianmichael.vialoadingbase.platform.ProtocolRange; import net.lenni0451.reflect.stream.RStream; @@ -28,6 +30,7 @@ import net.lenni0451.reflect.stream.field.FieldStream; import net.raphimc.viabedrock.api.BedrockProtocolVersion; import net.raphimc.viabedrock.api.chunk.BedrockChunk; import net.raphimc.viabedrock.api.model.entity.Entity; +import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider; import net.raphimc.viabedrock.protocol.storage.BlobCache; import net.raphimc.viabedrock.protocol.storage.ChunkTracker; import net.raphimc.viabedrock.protocol.storage.GameSessionStorage; @@ -35,6 +38,7 @@ import net.raphimc.viabedrock.protocol.storage.GameSessionStorage; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CompletableFuture; public class BedrockInformation extends AbstractInformationGroup { @@ -44,11 +48,11 @@ public class BedrockInformation extends AbstractInformationGroup { @Override public void applyInformation(UserConnection userConnection, List output) { - final BlobCache blobCache = userConnection.get(BlobCache.class); + final ViaFabricPlusBlobCacheProvider blobCache = (ViaFabricPlusBlobCacheProvider) Via.getManager().getProviders().get(BlobCacheProvider.class); if (blobCache != null) { - final long totalSize = blobCache.getTotalSize(); - final int blobCount = blobCache.getBlobCount(); - final int pendingCount = blobCache.getPendingCount(); + final long totalSize = blobCache.getSize(); + final int blobCount = blobCache.getBlobs().size(); + final int pendingCount = RStream.of(userConnection.get(BlobCache.class)).fields().by("pending").>>get().size(); if (totalSize != 0 || blobCount != 0 || pendingCount != 0) { output.add("Blob Cache:"); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java deleted file mode 100644 index 5973e2d6..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 . - */ -package de.florianmichael.viafabricplus.injection.access; - -public interface IPlayerPositionLookS2CPacket { - - boolean viafabricplus_isDismountVehicle(); -} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java index 83d71fc3..4a5bc147 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java @@ -52,7 +52,9 @@ public class MixinDebugHud { if (group.getProtocolRange() != null && !group.getProtocolRange().contains(ProtocolHack.getTargetVersion())) continue; final List groupInformation = new ArrayList<>(); - group.applyInformation(userConnection, groupInformation); + try { + group.applyInformation(userConnection, groupInformation); + } catch (Exception ignored) {} if (groupInformation.isEmpty()) continue; information.add(group.getProtocolRange() == null ? "General" : group.getProtocolRange().toString()); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java index 3b7d4887..58c92aa2 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java @@ -18,9 +18,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; import com.mojang.authlib.GameProfile; -import com.mojang.blaze3d.systems.RenderSystem; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.injection.access.IPlayerPositionLookS2CPacket; import de.florianmichael.viafabricplus.settings.groups.VisualSettings; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import net.minecraft.client.MinecraftClient; @@ -36,7 +34,6 @@ import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.network.ClientConnection; import net.minecraft.network.listener.ServerPlayPacketListener; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.c2s.play.KeepAliveC2SPacket; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.screen.ScreenHandler; import net.minecraft.util.math.Vec3d; @@ -154,13 +151,6 @@ public abstract class MixinClientPlayNetworkHandler { } } - @Inject(method = "onPlayerPositionLook", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER)) - public void dismountIfRequested(PlayerPositionLookS2CPacket packet, CallbackInfo ci) { - if (((IPlayerPositionLookS2CPacket) packet).viafabricplus_isDismountVehicle()) { - client.player.dismountVehicle(); - } - } - @Redirect(method = "onKeepAlive", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V")) public void forceSendKeepAlive(ClientPlayNetworkHandler instance, Packet packet, BooleanSupplier sendCondition, Duration expirationTime) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java deleted file mode 100644 index d265bea6..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 . - */ -package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.packet; - -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.injection.access.IPlayerPositionLookS2CPacket; -import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(PlayerPositionLookS2CPacket.class) -public class MixinPlayerPositionLookS2CPacket implements IPlayerPositionLookS2CPacket { - - @Unique - private boolean viafabricplus_dismountVehicle; - - @Inject(method = "(Lnet/minecraft/network/PacketByteBuf;)V", at = @At("RETURN")) - public void readDismountVehicle(PacketByteBuf buf, CallbackInfo ci) { - if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) { - viafabricplus_dismountVehicle = buf.readBoolean(); - } - } - - @Override - public boolean viafabricplus_isDismountVehicle() { - return viafabricplus_dismountVehicle; - } -} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java deleted file mode 100644 index b28be5b8..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 . - */ -package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_19_4to1_19_3; - -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; -import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; -import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; -import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets.EntityPackets; -import com.viaversion.viaversion.rewriter.EntityRewriter; -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 = EntityPackets.class, remap = false) -public abstract class MixinEntityPackets extends EntityRewriter { - - public MixinEntityPackets(Protocol1_19_4To1_19_3 protocol) { - super(protocol); - } - - @Inject(method = "registerPackets", at = @At("RETURN")) - public void fixPlayerPosition(CallbackInfo ci) { - protocol.registerClientbound(ClientboundPackets1_19_3.PLAYER_POSITION, ClientboundPackets1_19_4.PLAYER_POSITION, new PacketHandlers() { - @Override - protected void register() { - map(Type.DOUBLE); // X - map(Type.DOUBLE); // Y - map(Type.DOUBLE); // Z - map(Type.FLOAT); // Yaw - map(Type.FLOAT); // Pitch - map(Type.BYTE); // Relative arguments - map(Type.VAR_INT); // Id - map(Type.BOOLEAN); // Dismount vehicle - handling in MC - } - }, true); - } -} diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java index 068576d4..2fb2fb1f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java @@ -30,6 +30,7 @@ import de.florianmichael.viafabricplus.protocolhack.platform.ViaAprilFoolsPlatfo import de.florianmichael.viafabricplus.protocolhack.platform.ViaBedrockPlatformImpl; import de.florianmichael.viafabricplus.protocolhack.platform.ViaLegacyPlatformImpl; import de.florianmichael.viafabricplus.protocolhack.provider.*; +import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusBlobCacheProvider; import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusNettyPipelineProvider; import de.florianmichael.viafabricplus.protocolhack.provider.vialegacy.*; import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusHandItemProvider; @@ -45,6 +46,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.network.ClientConnection; import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion; import net.raphimc.viabedrock.api.BedrockProtocolVersion; +import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider; import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider; @@ -124,6 +126,8 @@ public class ProtocolHack { return MinecraftClient.getInstance().isInSingleplayer(); }); builder = builder.providers(providers -> { + providers.use(VersionProvider.class, new ViaFabricPlusVLBBaseVersionProvider()); + providers.use(MovementTransmitterProvider.class, new ViaFabricPlusMovementTransmitterProvider()); providers.use(HandItemProvider.class, new ViaFabricPlusHandItemProvider()); @@ -135,9 +139,9 @@ public class ProtocolHack { providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher()); providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider()); providers.use(ClassicCustomCommandProvider.class, new ViaFabricPlusClassicCustomCommandProvider()); - providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider()); - providers.use(VersionProvider.class, new ViaFabricPlusVLBBaseVersionProvider()); + providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider()); + providers.use(BlobCacheProvider.class, new ViaFabricPlusBlobCacheProvider()); }); builder = builder.onProtocolReload(protocolVersion -> ChangeProtocolVersionCallback.EVENT.invoker().onChangeProtocolVersion(protocolVersion)); builder.build(); diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/viabedrock/ViaFabricPlusBlobCacheProvider.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/viabedrock/ViaFabricPlusBlobCacheProvider.java new file mode 100644 index 00000000..d585af81 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/viabedrock/ViaFabricPlusBlobCacheProvider.java @@ -0,0 +1,68 @@ +/* + * 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 . + */ +package de.florianmichael.viafabricplus.protocolhack.provider.viabedrock; + +import com.viaversion.viaversion.api.connection.UserConnection; +import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider; + +import java.util.HashMap; +import java.util.Map; + +public class ViaFabricPlusBlobCacheProvider extends BlobCacheProvider { + + private final Map blobs = new HashMap<>(); + private long size; + + public ViaFabricPlusBlobCacheProvider() { + this.blobs.put(0L, new byte[0]); + } + + @Override + public byte[] addBlob(final UserConnection user, final long hash, final byte[] compressedBlob) { + synchronized (this.blobs) { + if (this.blobs.containsKey(hash)) { // In case the server overwrites a blob + size -= this.blobs.get(hash).length; + this.blobs.remove(hash); + } + size += compressedBlob.length; + return this.blobs.put(hash, compressedBlob); + } + } + + @Override + public boolean hasBlob(final UserConnection user, final long hash) { + synchronized (this.blobs) { + return this.blobs.containsKey(hash); + } + } + + @Override + public byte[] getBlob(final UserConnection user, final long hash) { + synchronized (this.blobs) { + return this.blobs.get(hash); + } + } + + public Map getBlobs() { + return blobs; + } + + public long getSize() { + return size; + } +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index bbfc05f0..fa640129 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -95,7 +95,6 @@ "fixes.minecraft.item.MixinSwordItem", "fixes.minecraft.packet.MixinChatMessageC2SPacket", "fixes.minecraft.packet.MixinPacketByteBuf", - "fixes.minecraft.packet.MixinPlayerPositionLookS2CPacket", "fixes.minecraft.packet.MixinUpdatePlayerAbilitiesC2SPacket", "fixes.minecraft.screen.MixinChatHud", "fixes.minecraft.screen.MixinChatScreen", @@ -142,7 +141,6 @@ "fixes.viaversion.protocol1_18_2to1_18.MixinProtocol1_18_2To1_18", "fixes.viaversion.protocol1_19_1to1_19.MixinProtocol1_19_1To1_19", "fixes.viaversion.protocol1_19_3to1_19_1.MixinProtocol1_19_3To1_19_1", - "fixes.viaversion.protocol1_19_4to1_19_3.MixinEntityPackets", "fixes.viaversion.protocol1_9to1_8.MixinChunk1_8Type", "fixes.viaversion.protocol1_9to1_8.MixinCommandBlockProvider", "fixes.viaversion.protocol1_9to1_8.MixinEntityPackets_6_1",