mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-11-14 19:15:08 -05:00
Updated ClassTransform usage
This commit is contained in:
parent
bf931dbae8
commit
1bff55024f
5 changed files with 17 additions and 16 deletions
|
@ -101,9 +101,9 @@ dependencies {
|
|||
include "org.apache.logging.log4j:log4j-core:2.20.0"
|
||||
include "org.apache.logging.log4j:log4j-slf4j-impl:2.20.0"
|
||||
include "com/mojang:authlib:3.16.29"
|
||||
include "net.lenni0451.classtransform:mixinstranslator:1.8.4"
|
||||
include "net.lenni0451.classtransform:mixinsdummy:1.8.4"
|
||||
include "net.lenni0451.classtransform:additionalclassprovider:1.8.4"
|
||||
include "net.lenni0451.classtransform:mixinstranslator:1.9.0-SNAPSHOT"
|
||||
include "net.lenni0451.classtransform:mixinsdummy:1.9.0-SNAPSHOT"
|
||||
include "net.lenni0451.classtransform:additionalclassprovider:1.9.0-SNAPSHOT"
|
||||
include "net.lenni0451:Reflect:1.1.0"
|
||||
include "net.lenni0451:LambdaEvents:2.0.3"
|
||||
include "net.raphimc.netminecraft:all:2.3.3"
|
||||
|
|
|
@ -73,7 +73,7 @@ public class ViaProxy {
|
|||
final IClassProvider classProvider = new GuavaClassPathProvider();
|
||||
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
||||
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
||||
transformerManager.addBytecodeTransformer(new Java17ToJava8(classProvider).addWhitelistedPackage("com.mojang"));
|
||||
transformerManager.addBytecodeTransformer(new Java17ToJava8(transformerManager).addWhitelistedPackage("com.mojang"));
|
||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
||||
if (instrumentation != null) {
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
*/
|
||||
package net.raphimc.viaproxy.injection;
|
||||
|
||||
import net.lenni0451.classtransform.TransformerManager;
|
||||
import net.lenni0451.classtransform.transformer.IBytecodeTransformer;
|
||||
import net.lenni0451.classtransform.utils.ASMUtils;
|
||||
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
@ -33,12 +33,12 @@ public class Java17ToJava8 implements IBytecodeTransformer {
|
|||
private static final char STACK_ARG_CONSTANT = '\u0001';
|
||||
private static final char BSM_ARG_CONSTANT = '\u0002';
|
||||
|
||||
private final IClassProvider classProvider;
|
||||
final TransformerManager transformerManager;
|
||||
private final int nativeClassVersion;
|
||||
private final List<String> whitelistedPackages = new ArrayList<>();
|
||||
|
||||
public Java17ToJava8(final IClassProvider classProvider) {
|
||||
this.classProvider = classProvider;
|
||||
public Java17ToJava8(final TransformerManager transformerManager) {
|
||||
this.transformerManager = transformerManager;
|
||||
|
||||
final String classVersion = System.getProperty("java.class.version");
|
||||
final String[] versions = classVersion.split("\\.");
|
||||
|
@ -53,7 +53,7 @@ public class Java17ToJava8 implements IBytecodeTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String className, byte[] bytecode) {
|
||||
public byte[] transform(String className, byte[] bytecode, boolean calculateStackMapFrames) {
|
||||
for (String whitelistedPackage : this.whitelistedPackages) {
|
||||
if (!className.startsWith(whitelistedPackage)) return null;
|
||||
}
|
||||
|
@ -71,7 +71,11 @@ public class Java17ToJava8 implements IBytecodeTransformer {
|
|||
this.convertMiscMethods(classNode);
|
||||
this.removeRecords(classNode);
|
||||
|
||||
return ASMUtils.toBytes(classNode, this.classProvider);
|
||||
if (calculateStackMapFrames) {
|
||||
return ASMUtils.toBytes(classNode, this.transformerManager.getClassTree(), this.transformerManager.getClassProvider());
|
||||
} else {
|
||||
return ASMUtils.toStacklessBytes(classNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void makePublic(final ClassNode classNode) {
|
||||
|
@ -195,7 +199,6 @@ public class Java17ToJava8 implements IBytecodeTransformer {
|
|||
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Collections", "unmodifiableSet", "(Ljava/util/Set;)Ljava/util/Set;"));
|
||||
}
|
||||
|
||||
|
||||
if (list.size() != 0) {
|
||||
method.instructions.insertBefore(insn, list);
|
||||
method.instructions.remove(insn);
|
||||
|
|
|
@ -72,8 +72,7 @@ public class PluginManager {
|
|||
|
||||
private static void loadAndScanJar(final File file) throws Throwable {
|
||||
URL url = file.toURI().toURL();
|
||||
URLClassProvider classProvider = new URLClassProvider(ROOT_CLASS_PROVIDER, url);
|
||||
TransformerManager transformerManager = new TransformerManager(classProvider);
|
||||
TransformerManager transformerManager = new TransformerManager(new URLClassProvider(ROOT_CLASS_PROVIDER, url));
|
||||
InjectionClassLoader loader = new InjectionClassLoader(transformerManager, PluginManager.class.getClassLoader(), url);
|
||||
InputStream viaproxyYml = loader.getResourceAsStream("viaproxy.yml");
|
||||
if (viaproxyYml == null) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a viaproxy.yml");
|
||||
|
@ -97,7 +96,7 @@ public class PluginManager {
|
|||
ViaProxyPlugin plugin = (ViaProxyPlugin) instance;
|
||||
PLUGINS.add(plugin);
|
||||
|
||||
plugin.registerTransformers(transformerManager, classProvider);
|
||||
plugin.registerTransformers(transformerManager);
|
||||
plugin.onEnable();
|
||||
Logger.LOGGER.info("Successfully loaded plugin '" + yaml.get("name") + "' by " + yaml.get("author") + " (v" + yaml.get("version") + ")");
|
||||
}
|
||||
|
|
|
@ -18,13 +18,12 @@
|
|||
package net.raphimc.viaproxy.plugins;
|
||||
|
||||
import net.lenni0451.classtransform.TransformerManager;
|
||||
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||
|
||||
public abstract class ViaProxyPlugin {
|
||||
|
||||
public abstract void onEnable();
|
||||
|
||||
public void registerTransformers(final TransformerManager transformerManager, final IClassProvider classProvider) {
|
||||
public void registerTransformers(final TransformerManager transformerManager) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue