Cleaned up classic extension base

Fixed critical SRV resolving issues
This commit is contained in:
FlorianMichael 2023-09-10 23:49:51 +02:00
parent 087ab76960
commit f1cbda15e2
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
18 changed files with 48 additions and 187 deletions

View File

@ -26,7 +26,7 @@ import de.florianmichael.viafabricplus.base.settings.SettingsSystem;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.definition.account.BedrockAccountHandler;
import de.florianmichael.viafabricplus.definition.account.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.definition.classic.protocol.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.information.InformationSystem;
import de.florianmichael.viafabricplus.mappings.CharacterMappings;
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;

View File

@ -140,22 +140,6 @@ public class ClientsideFixes {
});
}
/**
* Parses a server address and returns a {@link ServerAddress} object that is compatible with the specified version
*
* @param version The version to use
* @param address The address to parse
* @return The parsed {@link ServerAddress}
*/
public static ServerAddress parse(VersionEnum version, String address) {
final ServerAddress modern = ServerAddress.parse(address);
if (LEGACY_SRV_RESOLVE.contains(version) && !modern.equals(ServerAddress.INVALID)) {
final var addressParts = address.split(":");
return new ServerAddress(addressParts[0], addressParts.length > 1 ? Integer.parseInt(addressParts[1]) : 25565);
}
return modern;
}
/**
* Returns the sync task for the specified uuid and removes it from the list
*

View File

@ -1,45 +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 <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.definition.classic;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.Window;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicProgressStorage;
public class ClassicProgressRenderer {
public static void renderProgress(final DrawContext context) {
if (MinecraftClient.getInstance().getNetworkHandler() == null) return;
final UserConnection connection = ProtocolHack.getMainUserConnection();
if (connection == null) return;
final ClassicProgressStorage classicProgressStorage = connection.get(ClassicProgressStorage.class);
if (classicProgressStorage == null) return;
final Window window = MinecraftClient.getInstance().getWindow();
context.drawCenteredTextWithShadow(
MinecraftClient.getInstance().textRenderer,
"[ViaFabricPlus] " + classicProgressStorage.status,
window.getScaledWidth() / 2,
window.getScaledHeight() / 2 - 30,
-1
);
}
}

View File

@ -15,7 +15,7 @@
* 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 de.florianmichael.viafabricplus.definition.classic.protocol;
package de.florianmichael.viafabricplus.definition.classic;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;

View File

@ -15,7 +15,7 @@
* 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 de.florianmichael.viafabricplus.definition.classic.protocol;
package de.florianmichael.viafabricplus.definition.classic;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.screen.ClassicItemSelectionScreen;

View File

@ -1,38 +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 <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.definition.classic.ClassicProgressRenderer;
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConnectScreen;
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(ConnectScreen.class)
public class MixinConnectScreen {
@Inject(method = "render", at = @At("RETURN"))
public void renderClassicProgress(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (!GeneralSettings.INSTANCE.showClassicLoadingProgressInConnectScreen.getValue()) return;
ClassicProgressRenderer.renderProgress(context);
}
}

View File

@ -21,6 +21,7 @@ import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.network.AllowedAddressResolver;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import net.raphimc.vialoader.util.VersionEnum;
@ -33,6 +34,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import java.net.InetSocketAddress;
import java.util.Optional;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Mixin(targets = "net.minecraft.client.gui.screen.ConnectScreen$1")
public class MixinConnectScreen_1 {
@ -46,17 +48,21 @@ public class MixinConnectScreen_1 {
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
public Object mapSocketAddress(Optional<InetSocketAddress> instance) {
if (ClientsideFixes.LEGACY_SRV_RESOLVE.contains(ProtocolHack.getTargetVersion())) {
return new InetSocketAddress(field_33737.getAddress(), field_33737.getPort());
final var original = instance.orElse(null); // original invoke
if (field_40415 != null) {
// Handle forced version system
final VersionEnum forcedVersion = ((IServerInfo) field_40415).viafabricplus_forcedVersion();
if (forcedVersion != null) {
ProtocolHack.getForcedVersions().put(original, forcedVersion);
ChangeProtocolVersionCallback.EVENT.invoker().onChangeProtocolVersion(forcedVersion);
}
}
final InetSocketAddress address = instance.get();
if (field_40415 == null) return address;
final VersionEnum forcedVersion = ((IServerInfo) field_40415).viafabricplus_forcedVersion();
if (forcedVersion != null) {
ProtocolHack.getForcedVersions().put(address, forcedVersion);
ChangeProtocolVersionCallback.EVENT.invoker().onChangeProtocolVersion(forcedVersion);
if (ClientsideFixes.LEGACY_SRV_RESOLVE.contains(ProtocolHack.getTargetVersion())) {
final var direct = AllowedAddressResolver.DEFAULT.addressResolver.resolve(this.field_33737).orElse(null);
if (direct != null) return direct.getInetSocketAddress();
}
return address;
return original; // original invoke
}
}

View File

@ -17,22 +17,38 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.definition.classic.ClassicProgressRenderer;
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.util.ChatUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicProgressStorage;
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(DownloadingTerrainScreen.class)
public class MixinDownloadingTerrainScreen {
@SuppressWarnings("DataFlowIssue")
@Mixin(targets = { "net.minecraft.client.gui.screen.DownloadingTerrainScreen", "net.minecraft.client.gui.screen.ConnectScreen" })
public class MixinDownloadingTerrainScreenAndConnectScreen extends Screen {
public MixinDownloadingTerrainScreenAndConnectScreen(Text title) {
super(title);
}
@Inject(method = "render", at = @At("RETURN"))
public void renderClassicProgress(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (!GeneralSettings.INSTANCE.showClassicLoadingProgressInConnectScreen.getValue()) return;
if (GeneralSettings.INSTANCE.showClassicLoadingProgressInConnectScreen.getValue()) {
if (client.getNetworkHandler() == null) return;
ClassicProgressRenderer.renderProgress(context);
final var connection = ProtocolHack.getMainUserConnection();
if (connection == null) return;
final var classicProgressStorage = connection.get(ClassicProgressStorage.class);
if (classicProgressStorage == null) return;
context.drawCenteredTextWithShadow(client.textRenderer, ChatUtil.prefixText(classicProgressStorage.status), width / 2, height / 2 - 30, -1);
}
}
}

View File

@ -17,21 +17,15 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen;
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.text.Text;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MultiplayerScreen.class)
@ -55,17 +49,4 @@ public class MixinMultiplayerScreen extends Screen {
this.addDrawableChild(builder.size(98, 20).build());
}
@Unique
private ServerInfo viafabricplus_lastConnect;
@Inject(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD"))
public void track(ServerInfo entry, CallbackInfo ci) {
viafabricplus_lastConnect = entry;
}
@Redirect(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;"))
public ServerAddress doOwnParse(String address) {
return ClientsideFixes.parse(ProtocolHack.getTargetVersion(viafabricplus_lastConnect), address);
}
}

View File

@ -1,42 +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 <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;
import com.google.common.net.HostAndPort;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.lenni0451.reflect.stream.RStream;
import net.minecraft.client.network.MultiplayerServerListPinger;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MultiplayerServerListPinger.class)
public class MixinMultiplayerServerListPinger {
@Inject(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AllowedAddressResolver;resolve(Lnet/minecraft/client/network/ServerAddress;)Ljava/util/Optional;"), locals = LocalCapture.CAPTURE_FAILHARD)
public void mapParsing(ServerInfo entry, Runnable saver, CallbackInfo ci, ServerAddress serverAddress) {
final var remapped = ClientsideFixes.parse(ProtocolHack.getTargetVersion(entry), serverAddress.hostAndPort.toString());
RStream.of(serverAddress).fields().filter(HostAndPort.class).by(0).set(RStream.of(remapped).fields().filter(HostAndPort.class).by(0).get());
}
}

View File

@ -17,7 +17,7 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
import de.florianmichael.viafabricplus.definition.classic.protocol.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

View File

@ -17,7 +17,7 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
import de.florianmichael.viafabricplus.definition.classic.protocol.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.ClientboundPacketsc0_30cpe;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

View File

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
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 de.florianmichael.viafabricplus.definition.classic.protocol.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.model.WeatherTypes;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ClientboundPacketsc0_28;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ServerboundPacketsc0_28;

View File

@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets;
import de.florianmichael.viafabricplus.definition.classic.protocol.ClassicWorldHeightInjection;
import de.florianmichael.viafabricplus.definition.classic.ClassicWorldHeightInjection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

View File

@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
import de.florianmichael.viafabricplus.definition.classic.protocol.ClassicWorldHeightInjection;
import de.florianmichael.viafabricplus.definition.classic.ClassicWorldHeightInjection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

View File

@ -107,7 +107,7 @@ public class BetaCraftScreen extends VFPScreen {
@Override
public void mappedMouseClicked(double mouseX, double mouseY, int button) {
final ServerAddress serverAddress = ClientsideFixes.parse(ProtocolHack.getTargetVersion(), server.host() + ":" + server.port());
final ServerAddress serverAddress = ServerAddress.parse(server.host() + ":" + server.port());
final ServerInfo entry = new ServerInfo(server.name(), serverAddress.getAddress(), false);
ConnectScreen.connect(MinecraftClient.getInstance().currentScreen, MinecraftClient.getInstance(), serverAddress, entry, false);

View File

@ -12,6 +12,7 @@ accessible field net/minecraft/network/ClientConnection EPOLL_CLIENT_IO_GROUP Ln
accessible field net/minecraft/network/ClientConnection LOCAL_CLIENT_IO_GROUP Lnet/minecraft/util/Lazy;
accessible field net/minecraft/client/gui/screen/GameMenuScreen exitButton Lnet/minecraft/client/gui/widget/ButtonWidget;
accessible field net/minecraft/client/font/FontStorage$GlyphPair MISSING Lnet/minecraft/client/font/FontStorage$GlyphPair;
accessible field net/minecraft/client/network/AllowedAddressResolver addressResolver Lnet/minecraft/client/network/AddressResolver;
accessible method net/minecraft/screen/GenericContainerScreenHandler <init> (Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;I)V
accessible method net/minecraft/client/font/FontStorage$GlyphPair <init> (Lnet/minecraft/client/font/Glyph;Lnet/minecraft/client/font/Glyph;)V

View File

@ -8,10 +8,9 @@
"base.MixinClientConnection",
"base.MixinClientConnection_1",
"base.MixinClientLoginNetworkHandler",
"base.MixinConnectScreen",
"base.MixinConnectScreen_1",
"base.MixinDebugHud",
"base.MixinDownloadingTerrainScreen",
"base.MixinDownloadingTerrainScreenAndConnectScreen",
"base.MixinMain",
"base.MixinMinecraftClient",
"base.MixinMultiplayerScreen",
@ -33,7 +32,6 @@
"fixes.minecraft.MixinInGameHud",
"fixes.minecraft.MixinItemRenderer",
"fixes.minecraft.MixinMinecraftClient",
"fixes.minecraft.MixinMultiplayerServerListPinger",
"fixes.minecraft.MixinPendingUpdateManager",
"fixes.minecraft.MixinPlayerEntityRenderer",
"fixes.minecraft.MixinPlayerPublicKey_PublicKeyData",