From a86ec29c10b07f71d1214160f7c2cddd77144063 Mon Sep 17 00:00:00 2001
From: RaphiMC <50594595+RaphiMC@users.noreply.github.com>
Date: Sat, 4 Mar 2023 21:52:58 +0100
Subject: [PATCH] Updated Via*
---
build.gradle | 2 +-
.../transformer/VersionEnumTransformer.java | 49 +++++++++++++++++++
.../viaproxy/plugins/PluginManager.java | 5 ++
3 files changed, 55 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/net/raphimc/viaproxy/injection/transformer/VersionEnumTransformer.java
diff --git a/build.gradle b/build.gradle
index b0ff107..098dac2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -68,7 +68,7 @@ dependencies {
include "com.viaversion:viarewind-core:2.0.3-SNAPSHOT"
include "net.raphimc:ViaLegacy:2.2.8"
include "net.raphimc:ViaAprilFools:2.0.5"
- include("net.raphimc:ViaProtocolHack:2.1.6") {
+ include("net.raphimc:ViaProtocolHack:2.1.9") {
exclude group: "org.slf4j", module: "slf4j-api"
}
diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/VersionEnumTransformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/VersionEnumTransformer.java
new file mode 100644
index 0000000..f3fae3b
--- /dev/null
+++ b/src/main/java/net/raphimc/viaproxy/injection/transformer/VersionEnumTransformer.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
+ * 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 net.raphimc.viaproxy.injection.transformer;
+
+import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
+import net.lenni0451.classtransform.annotations.CTransformer;
+import net.lenni0451.classtransform.annotations.injection.COverride;
+import net.raphimc.viaprotocolhack.util.VersionEnum;
+import net.raphimc.viaproxy.plugins.PluginManager;
+import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
+
+@CTransformer(VersionEnum.class)
+public abstract class VersionEnumTransformer {
+
+ @COverride
+ private static ProtocolVersion getViaBedrockProtocol(final String name) {
+ try {
+ Class> clazz = null;
+ for (ViaProxyPlugin plugin : PluginManager.getPlugins()) {
+ try {
+ clazz = Class.forName("net.raphimc.viabedrock.api.BedrockProtocolVersion", true, plugin.getClass().getClassLoader());
+ break;
+ } catch (Throwable ignored) {
+ }
+ }
+ if (clazz != null) {
+ return (ProtocolVersion) clazz.getField(name).get(null);
+ }
+ } catch (Throwable ignored) {
+ }
+ return ProtocolVersion.unknown;
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viaproxy/plugins/PluginManager.java b/src/main/java/net/raphimc/viaproxy/plugins/PluginManager.java
index 3ec3177..65075e7 100644
--- a/src/main/java/net/raphimc/viaproxy/plugins/PluginManager.java
+++ b/src/main/java/net/raphimc/viaproxy/plugins/PluginManager.java
@@ -27,6 +27,7 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -38,6 +39,10 @@ public class PluginManager {
private static final File PLUGINS_DIR = new File("plugins");
private static final List PLUGINS = new ArrayList<>();
+ public static List getPlugins() {
+ return Collections.unmodifiableList(PLUGINS);
+ }
+
public static void loadPlugins() {
if (!PLUGINS_DIR.exists() || !PLUGINS_DIR.isDirectory()) {
if (!PLUGINS_DIR.mkdirs()) {