mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-21 16:28:10 +01:00
Migrate to JvmDowngrader
This commit is contained in:
parent
55acce8170
commit
146d218276
41
build.gradle
41
build.gradle
@ -1,12 +1,10 @@
|
||||
import net.raphimc.javadowngrader.gradle.task.DowngradeJarTask
|
||||
|
||||
plugins {
|
||||
id "java"
|
||||
id "application"
|
||||
id "maven-publish"
|
||||
id "idea"
|
||||
id "net.raphimc.class-token-replacer" version "1.0.1"
|
||||
id "net.raphimc.java-downgrader" version "1.1.2"
|
||||
id "xyz.wagyourtail.jvmdowngrader" version "0.5.1"
|
||||
}
|
||||
|
||||
base {
|
||||
@ -20,6 +18,7 @@ base {
|
||||
|
||||
configurations {
|
||||
include
|
||||
includeJ8
|
||||
|
||||
implementation.extendsFrom include
|
||||
api.extendsFrom include
|
||||
@ -79,9 +78,9 @@ dependencies {
|
||||
include("com.mojang:authlib:3.16.29") {
|
||||
exclude group: "org.slf4j", module: "slf4j-api"
|
||||
}
|
||||
include "net.lenni0451.classtransform:mixinstranslator:1.13.1"
|
||||
include "net.lenni0451.classtransform:mixinsdummy:1.13.1"
|
||||
include "net.lenni0451.classtransform:additionalclassprovider:1.13.1"
|
||||
include "net.lenni0451.classtransform:mixinstranslator:1.14.0-SNAPSHOT"
|
||||
include "net.lenni0451.classtransform:mixinsdummy:1.14.0-SNAPSHOT"
|
||||
include "net.lenni0451.classtransform:additionalclassprovider:1.14.0-SNAPSHOT"
|
||||
include "net.lenni0451:Reflect:1.3.4"
|
||||
include "net.lenni0451:LambdaEvents:2.4.2"
|
||||
include("net.lenni0451:MCPing:1.4.1") {
|
||||
@ -95,14 +94,13 @@ dependencies {
|
||||
exclude group: "com.google.code.gson", module: "gson"
|
||||
exclude group: "org.slf4j", module: "slf4j-api"
|
||||
}
|
||||
include("net.raphimc.javadowngrader:impl-classtransform:1.1.2") {
|
||||
exclude group: "org.ow2.asm", module: "asm-commons"
|
||||
exclude group: "net.lenni0451.classtransform", module: "additionalclassprovider"
|
||||
}
|
||||
include("org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR3-SNAPSHOT") {
|
||||
exclude group: "io.netty"
|
||||
}
|
||||
include "gs.mclo:api:3.0.1"
|
||||
|
||||
includeJ8(compileOnly("xyz.wagyourtail.jvmdowngrader:jvmdowngrader:0.5.1"))
|
||||
includeJ8 "xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:0.5.1:downgraded-8"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@ -199,13 +197,22 @@ idea {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("java8Jar", DowngradeJarTask) {
|
||||
input = tasks.jar.archiveFile.get().asFile
|
||||
outputSuffix = "+java8"
|
||||
compileClassPath = sourceSets.main.compileClasspath
|
||||
copyRuntimeClasses = false
|
||||
}.get().dependsOn("build")
|
||||
build.finalizedBy("java8Jar")
|
||||
downgradeJar {
|
||||
dependsOn configurations.includeJ8
|
||||
from {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
configurations.includeJ8.collect {
|
||||
zipTree(it)
|
||||
}
|
||||
} {
|
||||
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"
|
||||
}
|
||||
|
||||
downgradeTo = JavaVersion.VERSION_1_8
|
||||
archiveClassifier = null
|
||||
archiveVersion = project.version + "+java8"
|
||||
}
|
||||
build.finalizedBy("downgradeJar")
|
||||
|
||||
String latestCommitHash() {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
|
@ -1,6 +1,7 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
maven_group=net.raphimc
|
||||
maven_name=ViaProxy
|
||||
|
@ -3,8 +3,8 @@ pluginManagement {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
name = "Lenni0451"
|
||||
url "https://maven.lenni0451.net/everything"
|
||||
name = "WagYourTail"
|
||||
url = "https://maven.wagyourtail.xyz/releases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public abstract class MixinEntityPacketRewriter1_20_5 extends EntityRewriter<Cli
|
||||
* @reason Fix interaction range and step height differences
|
||||
*/
|
||||
@Overwrite
|
||||
public void sendRangeAttributes(final UserConnection connection, final boolean creativeMode) {
|
||||
private void sendRangeAttributes(final UserConnection connection, final boolean creativeMode) {
|
||||
final PacketWrapper updateAttributes = PacketWrapper.create(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, connection);
|
||||
updateAttributes.write(Types.VAR_INT, this.tracker(connection).clientEntityId());
|
||||
if (connection.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
|
||||
|
@ -24,10 +24,12 @@ import net.lenni0451.classtransform.additionalclassprovider.LazyFileClassProvide
|
||||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
||||
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||
import net.lenni0451.reflect.stream.RStream;
|
||||
import net.raphimc.javadowngrader.impl.classtransform.JavaDowngraderTransformer;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import xyz.wagyourtail.jvmdg.Constants;
|
||||
import xyz.wagyourtail.jvmdg.runtime.ClassDowngradingAgent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
@ -93,9 +95,20 @@ public class PluginManager {
|
||||
private void loadAndScanJar(final File file) throws Throwable {
|
||||
final URL url = file.toURI().toURL();
|
||||
final TransformerManager transformerManager = new TransformerManager(new LazyFileClassProvider(Collections.singletonList(file), this.rootClassProvider));
|
||||
transformerManager.addBytecodeTransformer(new JavaDowngraderTransformer(transformerManager));
|
||||
final InjectionClassLoader loader = new InjectionClassLoader(transformerManager, PluginManager.class.getClassLoader(), url);
|
||||
final InputStream viaproxyYml = loader.getResourceAsStream("viaproxy.yml");
|
||||
final InjectionClassLoader classLoader = new InjectionClassLoader(transformerManager, PluginManager.class.getClassLoader(), url);
|
||||
|
||||
try {
|
||||
final String[] versions = System.getProperty("java.class.version").split("\\.");
|
||||
final int nativeClassVersion = Integer.parseInt(versions[0]);
|
||||
if (nativeClassVersion < Opcodes.V17) {
|
||||
System.setProperty(Constants.ALLOW_MAVEN_LOOKUP, "false");
|
||||
transformerManager.addClassFileTransformer(classLoader, new ClassDowngradingAgent());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to setup class downgrading", e);
|
||||
}
|
||||
|
||||
final InputStream viaproxyYml = classLoader.getResourceAsStream("viaproxy.yml");
|
||||
if (viaproxyYml == null) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a viaproxy.yml");
|
||||
final Map<String, Object> yaml = this.yaml.load(viaproxyYml);
|
||||
if (!yaml.containsKey("name")) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a name attribute in the viaproxy.yml");
|
||||
@ -109,14 +122,14 @@ public class PluginManager {
|
||||
|
||||
final String main = (String) yaml.get("main");
|
||||
|
||||
final Class<?> mainClass = loader.loadClass(main);
|
||||
final Class<?> mainClass = classLoader.loadClass(main);
|
||||
if (!ViaProxyPlugin.class.isAssignableFrom(mainClass)) {
|
||||
throw new IllegalStateException("Class '" + mainClass.getName() + "' from '" + file.getName() + "' does not extend ViaProxyPlugin");
|
||||
}
|
||||
final Object instance = mainClass.getDeclaredConstructor().newInstance();
|
||||
final ViaProxyPlugin plugin = (ViaProxyPlugin) instance;
|
||||
|
||||
plugin.init(loader, yaml);
|
||||
plugin.init(classLoader, yaml);
|
||||
|
||||
if (plugin.getDepends().size() > 1) {
|
||||
throw new IllegalStateException("Plugin '" + file.getName() + "' has more than one dependency. This is not supported yet.");
|
||||
@ -137,7 +150,7 @@ public class PluginManager {
|
||||
this.enablePlugin(dependPlugin);
|
||||
}
|
||||
|
||||
RStream.of(plugin.getClassLoader()).fields().by("parent").set(dependPlugin.getClassLoader());
|
||||
RStream.of(plugin.getClassLoader()).withSuper().fields().by("parent").set(dependPlugin.getClassLoader());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -17,19 +17,18 @@
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins;
|
||||
|
||||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
||||
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ViaProxyPlugin {
|
||||
|
||||
private InjectionClassLoader classLoader;
|
||||
private URLClassLoader classLoader;
|
||||
private Map<String, Object> viaProxyYaml;
|
||||
private boolean enabled;
|
||||
|
||||
final void init(final InjectionClassLoader classLoader, final Map<String, Object> viaProxyYaml) {
|
||||
final void init(final URLClassLoader classLoader, final Map<String, Object> viaProxyYaml) {
|
||||
this.classLoader = classLoader;
|
||||
this.viaProxyYaml = viaProxyYaml;
|
||||
}
|
||||
@ -68,7 +67,7 @@ public abstract class ViaProxyPlugin {
|
||||
return Collections.unmodifiableList((List<String>) this.viaProxyYaml.getOrDefault("depends", Collections.emptyList()));
|
||||
}
|
||||
|
||||
public final InjectionClassLoader getClassLoader() {
|
||||
public final URLClassLoader getClassLoader() {
|
||||
return this.classLoader;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user