From 4353ebfa7fda226d91c5c043518f1dcd97d7bd3e Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:39:56 +0200 Subject: [PATCH] Fill ViaVersion platform dump data --- build.gradle | 10 ++++ .../java/net/raphimc/viaproxy/ViaProxy.java | 1 + .../viaproxy/protocolhack/ProtocolHack.java | 3 +- .../protocolhack/impl/ViaProxyVLInjector.java | 49 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/raphimc/viaproxy/protocolhack/impl/ViaProxyVLInjector.java diff --git a/build.gradle b/build.gradle index 8a9c47b..d83b2b1 100644 --- a/build.gradle +++ b/build.gradle @@ -122,6 +122,7 @@ sourceSets { main { classTokenReplacer { property("\${version}", project.version) + property("\${impl_version}", "git-${project.name}-${project.version}:${project.latestCommitHash()}") } } } @@ -210,3 +211,12 @@ tasks.register("java8Jar", DowngradeJarTask) { copyRuntimeClasses = false }.get().dependsOn("build") build.finalizedBy("java8Jar") + +String latestCommitHash() { + def stdout = new ByteArrayOutputStream() + exec { + commandLine "git", "rev-parse", "--short", "HEAD" + standardOutput = stdout + } + return stdout.toString().trim() +} diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index bafba89..d33bb97 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -59,6 +59,7 @@ import java.lang.instrument.Instrumentation; public class ViaProxy { public static final String VERSION = "${version}"; + public static final String IMPL_VERSION = "${impl_version}"; private static Instrumentation instrumentation; public static SaveManager saveManager; diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/ProtocolHack.java b/src/main/java/net/raphimc/viaproxy/protocolhack/ProtocolHack.java index 4f1609c..44fdc99 100644 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/ProtocolHack.java +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/ProtocolHack.java @@ -24,6 +24,7 @@ import net.raphimc.vialoader.impl.platform.ViaBedrockPlatformImpl; import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.events.ProtocolHackInitEvent; +import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVLInjector; import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVLLoader; import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaLegacyPlatformImpl; import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaVersionPlatformImpl; @@ -38,7 +39,7 @@ public class ProtocolHack { public static void init() { patchConfigs(); final Supplier[] platformSuppliers = PluginManager.EVENT_MANAGER.call(new ProtocolHackInitEvent(ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaProxyViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]); - ViaLoader.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVLLoader(), null, null, platformSuppliers); + ViaLoader.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVLLoader(), new ViaProxyVLInjector(), null, platformSuppliers); } private static void patchConfigs() { diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/impl/ViaProxyVLInjector.java b/src/main/java/net/raphimc/viaproxy/protocolhack/impl/ViaProxyVLInjector.java new file mode 100644 index 0000000..6b3dce6 --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/impl/ViaProxyVLInjector.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.protocolhack.impl; + +import com.viaversion.viaversion.libs.gson.JsonArray; +import com.viaversion.viaversion.libs.gson.JsonObject; +import net.raphimc.vialoader.impl.viaversion.VLInjector; +import net.raphimc.viaproxy.ViaProxy; +import net.raphimc.viaproxy.plugins.PluginManager; +import net.raphimc.viaproxy.plugins.ViaProxyPlugin; + +public class ViaProxyVLInjector extends VLInjector { + + @Override + public JsonObject getDump() { + final JsonObject root = new JsonObject(); + + root.addProperty("version", ViaProxy.VERSION); + root.addProperty("impl_version", ViaProxy.IMPL_VERSION); + + final JsonArray plugins = new JsonArray(); + for (ViaProxyPlugin plugin : PluginManager.getPlugins()) { + final JsonObject pluginObj = new JsonObject(); + pluginObj.addProperty("name", plugin.getName()); + pluginObj.addProperty("version", plugin.getVersion()); + pluginObj.addProperty("author", plugin.getAuthor()); + plugins.add(pluginObj); + } + root.add("plugins", plugins); + + return root; + } + +}