From daf663633b65a0be18468661ec8d452101c28312 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 20 Mar 2023 20:54:11 +0100 Subject: [PATCH] started with 1.19.4 fixes --- .../v1_19_4/DismountRequestTracker.java | 37 ++++++++++++ .../MixinClientPlayNetworkHandler.java | 17 ++++++ .../entity/MixinClientPlayerEntity.java | 13 ++++ .../MixinEntityPackets.java | 59 +++++++++++++++++++ .../MixinProtocol1_19_4to1_19_3.java | 35 +++++++++++ .../screen/ProtocolSelectionScreen.java | 1 + .../screen/settings/SettingsScreen.java | 1 + src/main/resources/viafabricplus.mixins.json | 20 ++++--- 8 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java create 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/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java b/src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java new file mode 100644 index 00000000..2375fa74 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java @@ -0,0 +1,37 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.definition.v1_19_4; + +import com.viaversion.viaversion.api.connection.StoredObject; +import com.viaversion.viaversion.api.connection.UserConnection; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedDeque; + +public class DismountRequestTracker extends StoredObject { + + private final Queue dismountRequests = new ConcurrentLinkedDeque<>(); + + public DismountRequestTracker(UserConnection user) { + super(user); + } + + public Queue getDismountRequests() { + return dismountRequests; + } +} 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 08d82433..5136370a 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,7 +18,10 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; import com.mojang.authlib.GameProfile; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.settings.groups.VisualSettings; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; @@ -67,6 +70,8 @@ public abstract class MixinClientPlayNetworkHandler { @Shadow public abstract void onEntityVelocityUpdate(EntityVelocityUpdateS2CPacket packet); + @Shadow @Final private ClientConnection connection; + @Inject(method = "", at = @At("RETURN")) public void fixPlayerListOrdering(MinecraftClient client, Screen screen, ClientConnection connection, ServerInfo serverInfo, GameProfile profile, WorldSession worldSession, CallbackInfo ci) { if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_1)) { @@ -146,6 +151,18 @@ 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 (ViaLoadingBase.getClassWrapper().getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19_4)) return; + + if (connection.channel.hasAttr(ProtocolHack.LOCAL_VIA_CONNECTION)) { + final UserConnection userConnection = connection.channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get(); + if (userConnection.get(DismountRequestTracker.class).getDismountRequests().poll().equals(Boolean.TRUE)) { + client.player.dismountVehicle(); + } + } + } + @Redirect(method = "onServerMetadata", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/ServerMetadataS2CPacket;isSecureChatEnforced()Z")) public boolean removeSecureChatWarning(ServerMetadataS2CPacket instance) { return instance.isSecureChatEnforced() || VisualSettings.INSTANCE.disableSecureChatWarning.getValue(); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java index 30c47e69..fa232490 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java @@ -205,6 +205,19 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity } } + @Redirect(method = "autoJump", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;inverseSqrt(F)F")) + public float useFastInverse(float x) { + if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) { + final float var1 = 0.5F * x; + int var2 = Float.floatToIntBits(x); + var2 = 1597463007 - (var2 >> 1); + x = Float.intBitsToFloat(var2); + + return x * (1.5F - var1 * x * x); + } + return MathHelper.inverseSqrt(x); + } + @Override public int getArmor() { if (VisualSettings.INSTANCE.emulateArmorHud.getValue()) { 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 new file mode 100644 index 00000000..6598c118 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java @@ -0,0 +1,59 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; +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(EntityPackets.class) +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 + handler(wrapper -> { + final boolean dismountVehicle = wrapper.read(Type.BOOLEAN); + wrapper.user().get(DismountRequestTracker.class).getDismountRequests().add(dismountVehicle); + }); + } + }, true); + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java new file mode 100644 index 00000000..405067b3 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java @@ -0,0 +1,35 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.connection.UserConnection; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; +import de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; +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(Protocol1_19_4To1_19_3.class) +public class MixinProtocol1_19_4to1_19_3 { + + @Inject(method = "init", at = @At("RETURN")) + public void hookDismountRequestTracker(UserConnection user, CallbackInfo ci) { + user.put(new DismountRequestTracker(user)); + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java index f4407cab..181d75fa 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java @@ -72,6 +72,7 @@ public class ProtocolSelectionScreen extends Screen { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + this.renderBackground(matrices); super.render(matrices, mouseX, mouseY, delta); matrices.push(); diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java index 12bdef2b..f0351419 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java @@ -65,6 +65,7 @@ public class SettingsScreen extends Screen { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + this.renderBackground(matrices); super.render(matrices, mouseX, mouseY, delta); matrices.push(); diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 741cec36..a5717417 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -15,6 +15,9 @@ "bridge.MixinDebugHud", "bridge.MixinDownloadingTerrainScreen", "bridge.MixinOptionsScreen", + "fixes.jsonwebtoken.MixinClasses", + "fixes.jsonwebtoken.MixinDefaultCompressionCodecResolver", + "fixes.jsonwebtoken.MixinDefaultJwtParserBuilder", "fixes.minecraft.MixinBipedEntityModel", "fixes.minecraft.MixinCamera", "fixes.minecraft.MixinClientPlayerInteractionManager", @@ -93,6 +96,7 @@ "fixes.minecraft.packet.MixinChatMessageC2SPacket", "fixes.minecraft.packet.MixinPacketByteBuf", "fixes.minecraft.packet.MixinUpdatePlayerAbilitiesC2SPacket", + "fixes.minecraft.screen.MixinChatHud", "fixes.minecraft.screen.MixinChatScreen", "fixes.minecraft.screen.MixinCommandBlockScreen", "fixes.minecraft.screen.MixinConnectScreen_1", @@ -102,7 +106,6 @@ "fixes.minecraft.screen.MixinGameModeSelectionScreen_GameModeSelection", "fixes.minecraft.screen.MixinJigsawBlockScreen", "fixes.minecraft.screen.MixinStructureBlockScreen_1", - "fixes.minecraft.screen.MixinChatHud", "fixes.minecraft.screen.merchant.MixinMerchantScreen", "fixes.minecraft.screen.merchant.MixinMerchantScreenHandler", "fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot", @@ -110,6 +113,8 @@ "fixes.minecraft.screen.screenhandler.MixinScreenHandler", "fixes.sodium.MixinChunkTracker", "fixes.viaaprilfools.MixinProtocol1_16to20w14infinite", + "fixes.viabedrock.MixinBedrockProtocol", + "fixes.viabedrock.MixinJoinPackets", "fixes.vialegacy.MixinClassicProtocolExtension", "fixes.vialegacy.MixinClientboundPacketsc0_30cpe", "fixes.vialegacy.MixinExtensionProtocolMetadataStorage", @@ -140,14 +145,13 @@ "fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9", "fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8", "fixes.viaversion.protocol1_9to1_8.MixinMovementTracker", - "fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread", - "fixes.jsonwebtoken.MixinClasses", - "fixes.jsonwebtoken.MixinDefaultCompressionCodecResolver", - "fixes.jsonwebtoken.MixinDefaultJwtParserBuilder", - "fixes.viabedrock.MixinBedrockProtocol", - "fixes.viabedrock.MixinJoinPackets" + "fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread" ], "injectors": { "defaultRequire": 1 - } + }, + "mixins": [ + "fixes.viaversion.protocol1_19_4to1_19_3.MixinEntityPackets", + "fixes.viaversion.protocol1_19_4to1_19_3.MixinProtocol1_19_4to1_19_3" + ] }