From 55e9c024cf259273d6928e3d6543ae9fbe97feb8 Mon Sep 17 00:00:00 2001
From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com>
Date: Sun, 26 Nov 2023 12:33:46 +0100
Subject: [PATCH] Re-add Debug Hud information list
---
.../viafabricplus/ViaFabricPlus.java | 1 -
.../injection/ViaFabricPlusMixinPlugin.java | 4 +
.../injection/access/IBlobCache.java | 28 ++++++
.../mixin/base/integration/MixinDebugHud.java | 94 ++++++++++++++++++-
.../viabedrock/MixinBedrockProtocol.java | 2 +-
.../mixin/viabedrock/MixinBlobCache.java | 42 +++++++++
.../viabedrock/MixinJoinPackets.java | 4 +-
.../viafabricplus/util/StringUtil.java | 48 ++++++++++
src/main/resources/viafabricplus.mixins.json | 7 +-
9 files changed, 222 insertions(+), 8 deletions(-)
create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/access/IBlobCache.java
rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/{fixes => }/viabedrock/MixinBedrockProtocol.java (95%)
create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBlobCache.java
rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/{fixes => }/viabedrock/MixinJoinPackets.java (96%)
create mode 100644 src/main/java/de/florianmichael/viafabricplus/util/StringUtil.java
diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
index cc5eb0cd..f849d50c 100644
--- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
+++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
@@ -48,7 +48,6 @@ import java.io.File;
* TODO | Migration v3
* - Rename all methods
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig and MixinViaLegacyConfig)
- * - Re-add Debug Hud information list
* - Fix auto detect to not be a huge mess
* - Fix MixinAbstractDonkeyEntity
* - Boats are probably broken. Check entity height offset fix
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java b/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java
index 5572f5ea..d02fa9be 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java
@@ -33,6 +33,8 @@ public class ViaFabricPlusMixinPlugin implements IMixinConfigPlugin {
private static final String MC_FIXES_PACKAGE = "fixes.minecraft.";
private static final String COMPAT_PACKAGE = "compat.";
+ public static String VFP_VERSION;
+
public static boolean DASH_LOADER_PRESENT;
public static boolean ARMOR_SKIN_PRESENT;
public static boolean IPNEXT_PRESENT;
@@ -41,6 +43,8 @@ public class ViaFabricPlusMixinPlugin implements IMixinConfigPlugin {
public void onLoad(String mixinPackage) {
final FabricLoader loader = FabricLoader.getInstance();
+ VFP_VERSION = loader.getModContainer("viafabricplus").get().getMetadata().getVersion().getFriendlyString();
+
DASH_LOADER_PRESENT = loader.isModLoaded("dashloader");
ARMOR_SKIN_PRESENT = loader.isModLoaded("armorskin");
IPNEXT_PRESENT = loader.isModLoaded("inventoryprofilesnext");
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/access/IBlobCache.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IBlobCache.java
new file mode 100644
index 00000000..60f6d871
--- /dev/null
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/access/IBlobCache.java
@@ -0,0 +1,28 @@
+/*
+ * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
+ * Copyright (C) 2021-2023 FlorianMichael/EnZaXD
+ * Copyright (C) 2023 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 .
+ */
+
+package de.florianmichael.viafabricplus.injection.access;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+public interface IBlobCache {
+
+ Map> viaFabricPlus$getPending();
+}
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/integration/MixinDebugHud.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/integration/MixinDebugHud.java
index 30cd678a..400bd170 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/integration/MixinDebugHud.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/integration/MixinDebugHud.java
@@ -19,9 +19,28 @@
package de.florianmichael.viafabricplus.injection.mixin.base.integration;
+import com.viaversion.viaversion.api.Via;
+import com.viaversion.viaversion.api.connection.ProtocolInfo;
+import com.viaversion.viaversion.api.connection.UserConnection;
+import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
+import de.florianmichael.viafabricplus.fixes.tracker.JoinGameTracker;
+import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin;
+import de.florianmichael.viafabricplus.injection.access.IBlobCache;
+import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
+import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusBlobCacheProvider;
import de.florianmichael.viafabricplus.settings.impl.GeneralSettings;
+import de.florianmichael.viafabricplus.util.ChatUtil;
+import de.florianmichael.viafabricplus.util.StringUtil;
+import net.lenni0451.reflect.stream.RStream;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
+import net.raphimc.viabedrock.protocol.data.enums.bedrock.ServerMovementModes;
+import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider;
+import net.raphimc.viabedrock.protocol.storage.BlobCache;
+import net.raphimc.viabedrock.protocol.storage.GameSessionStorage;
+import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
+import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.SeedStorage;
+import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage.EntityTracker;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -29,15 +48,88 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+@SuppressWarnings("DataFlowIssue")
@Mixin(DebugHud.class)
public abstract class MixinDebugHud {
@Inject(method = "getLeftText", at = @At("RETURN"))
public void addViaFabricPlusInformation(CallbackInfoReturnable> cir) {
- if (MinecraftClient.getInstance().isInSingleplayer() || !GeneralSettings.global().showExtraInformationInDebugHud.getValue()) return;
+ if (!GeneralSettings.global().showExtraInformationInDebugHud.getValue()) {
+ return;
+ }
+ if (MinecraftClient.getInstance().isInSingleplayer() || ProtocolHack.getTargetVersion() == ProtocolHack.NATIVE_VERSION) {
+ return;
+ }
+ final UserConnection userConnection = ProtocolHack.getPlayNetworkUserConnection();
final List information = new ArrayList<>();
+ information.add("");
+
+ // Title
+ information.add(ChatUtil.PREFIX + " " + ViaFabricPlusMixinPlugin.VFP_VERSION);
+
+ // common
+ final ProtocolInfo info = userConnection.getProtocolInfo();
+ information.add(
+ "P: " + info.getPipeline().pipes().size() +
+ " / C: " + ProtocolVersion.getProtocol(info.getProtocolVersion()) +
+ " / S: " + ProtocolVersion.getProtocol(info.getServerProtocolVersion())
+ );
+
+ // bedrock
+ final JoinGameTracker joinGameTracker = userConnection.get(JoinGameTracker.class);
+
+ if (joinGameTracker != null) {
+ final int movementMode = userConnection.get(GameSessionStorage.class).getMovementMode();
+ String movement = "Server with rewind";
+ if (movementMode == ServerMovementModes.CLIENT) {
+ movement = "Client";
+ } else if (movementMode == ServerMovementModes.SERVER) {
+ movement = "Server";
+ }
+
+ information.add("Bedrock Level: " + joinGameTracker.getLevelId() + " / Enchantment Seed: " + joinGameTracker.getEnchantmentSeed() + " / Movement: " + movement);
+ }
+ final BlobCache blobCache = userConnection.get(BlobCache.class);
+ if (blobCache != null) {
+ final var blobCacheProvider = (ViaFabricPlusBlobCacheProvider) Via.getManager().getProviders().get(BlobCacheProvider.class);
+
+ final long totalSize = blobCacheProvider.getSize();
+ final int blobCount = blobCacheProvider.getBlobs().size();
+ final int pendingCount = ((IBlobCache) blobCache).viaFabricPlus$getPending().size();
+
+ if (totalSize != 0 || blobCount != 0 || pendingCount != 0) {
+ information.add("Blob Cache: S: " + StringUtil.formatBytes(totalSize) + " / C: " + blobCount + " / Pending: " + pendingCount);
+ }
+ }
+
+ // r1_7_10
+ final EntityTracker entityTracker1_7_10 = userConnection.get(EntityTracker.class);
+ if (entityTracker1_7_10 != null) {
+ information.add(
+ "1.7 Entities: " + entityTracker1_7_10.getTrackedEntities().size() +
+ " / Virtual holograms: " + entityTracker1_7_10.getVirtualHolograms().size()
+ );
+ }
+
+ // r1_1 and bedrock
+ final SeedStorage seedStorage = userConnection.get(SeedStorage.class);
+ if (seedStorage != null) {
+ information.add("World Seed: " + seedStorage.seed);
+ } else if (joinGameTracker != null) {
+ information.add("World Seed: " + joinGameTracker.getSeed());
+ }
+
+ // c0.30cpe
+ final ExtensionProtocolMetadataStorage extensionProtocolMetadataStorage = userConnection.get(ExtensionProtocolMetadataStorage.class);
+ if (extensionProtocolMetadataStorage != null) {
+ information.add("CPE extensions: " + extensionProtocolMetadataStorage.getExtensionCount());
+ }
+
+ information.add("");
cir.getReturnValue().addAll(information);
}
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinBedrockProtocol.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBedrockProtocol.java
similarity index 95%
rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinBedrockProtocol.java
rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBedrockProtocol.java
index 6659b7bf..59b28841 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinBedrockProtocol.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBedrockProtocol.java
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-package de.florianmichael.viafabricplus.injection.mixin.fixes.viabedrock;
+package de.florianmichael.viafabricplus.injection.mixin.viabedrock;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.fixes.tracker.JoinGameTracker;
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBlobCache.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBlobCache.java
new file mode 100644
index 00000000..c315e17b
--- /dev/null
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBlobCache.java
@@ -0,0 +1,42 @@
+/*
+ * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
+ * Copyright (C) 2021-2023 FlorianMichael/EnZaXD
+ * Copyright (C) 2023 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 .
+ */
+
+package de.florianmichael.viafabricplus.injection.mixin.viabedrock;
+
+import de.florianmichael.viafabricplus.injection.access.IBlobCache;
+import net.raphimc.viabedrock.protocol.storage.BlobCache;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+@Mixin(value = BlobCache.class, remap = false)
+public class MixinBlobCache implements IBlobCache {
+
+ @Shadow
+ @Final
+ private Map> pending;
+
+ @Override
+ public Map> viaFabricPlus$getPending() {
+ return pending;
+ }
+}
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinJoinPackets.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java
similarity index 96%
rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinJoinPackets.java
rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java
index 6da7677b..eb9bdcb3 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viabedrock/MixinJoinPackets.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-package de.florianmichael.viafabricplus.injection.mixin.fixes.viabedrock;
+package de.florianmichael.viafabricplus.injection.mixin.viabedrock;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
@@ -40,7 +40,7 @@ public abstract class MixinJoinPackets {
return seed;
}
- @Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 56))
+ @Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 55))
private static Object trackLevelId(PacketWrapper instance, Type tType) throws Exception {
final Object levelId = instance.read(tType);
instance.user().get(JoinGameTracker.class).setLevelId((String) levelId);
diff --git a/src/main/java/de/florianmichael/viafabricplus/util/StringUtil.java b/src/main/java/de/florianmichael/viafabricplus/util/StringUtil.java
new file mode 100644
index 00000000..feab9e0f
--- /dev/null
+++ b/src/main/java/de/florianmichael/viafabricplus/util/StringUtil.java
@@ -0,0 +1,48 @@
+/*
+ * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
+ * Copyright (C) 2021-2023 FlorianMichael/EnZaXD
+ * Copyright (C) 2023 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 .
+ */
+
+package de.florianmichael.viafabricplus.util;
+
+import java.text.DecimalFormat;
+
+// Stolen from https://github.com/FlorianMichael/RClasses/blob/main/common/src/main/java/de/florianmichael/rclasses/common/StringUtils.java
+public class StringUtil {
+
+ /**
+ * Convention: IEC 60027-2
+ */
+ private final static String[] BYTES_UNIT = {"B", "KiB", "MiB", "GiB", "TiB"};
+ private final static DecimalFormat OPTIONAL_FORMAT = new DecimalFormat("#.##");
+
+ /**
+ * Formats a value in bytes to a human-readable format
+ *
+ * @param value The raw value in bytes
+ * @return The formatted value in bytes
+ */
+ public static String formatBytes(final long value) {
+ int index = (int) (Math.log(value) / Math.log(1024.0));
+ double data = value / Math.pow(1024.0, index);
+ if (index < 0) index = 0;
+ if (Double.isNaN(data)) data = 0;
+
+ return OPTIONAL_FORMAT.format(data) + " " + BYTES_UNIT[index];
+ }
+
+}
diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json
index a2584757..6396937f 100644
--- a/src/main/resources/viafabricplus.mixins.json
+++ b/src/main/resources/viafabricplus.mixins.json
@@ -134,8 +134,8 @@
"fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinPlayerScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinScreenHandler",
- "fixes.viabedrock.MixinBedrockProtocol",
- "fixes.viabedrock.MixinJoinPackets",
+ "viabedrock.MixinBedrockProtocol",
+ "viabedrock.MixinJoinPackets",
"fixes.vialegacy.MixinClassicProtocolExtension",
"fixes.vialegacy.MixinClientboundPacketsc0_30cpe",
"fixes.vialegacy.MixinExtensionProtocolMetadataStorage",
@@ -173,6 +173,7 @@
"fixes.minecraft.entity.MixinSkeletonHorseEntity",
"fixes.minecraft.item.MixinArmorItem",
"fixes.minecraft.item.MixinBowItem",
- "fixes.minecraft.item.MixinShearsItem"
+ "fixes.minecraft.item.MixinShearsItem",
+ "viabedrock.MixinBlobCache"
]
}