mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-01 13:23:50 +01:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
1c46b09449
@ -73,7 +73,7 @@ public class ViaProxy {
|
|||||||
final IClassProvider classProvider = new GuavaClassPathProvider();
|
final IClassProvider classProvider = new GuavaClassPathProvider();
|
||||||
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
||||||
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
||||||
transformerManager.addBytecodeTransformer(new Java17ToJava8(classProvider));
|
transformerManager.addBytecodeTransformer(new Java17ToJava8(classProvider).addWhitelistedPackage("com.mojang"));
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
||||||
if (instrumentation != null) {
|
if (instrumentation != null) {
|
||||||
|
@ -24,6 +24,7 @@ import org.objectweb.asm.Opcodes;
|
|||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.tree.*;
|
import org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -33,17 +34,32 @@ public class Java17ToJava8 implements IBytecodeTransformer {
|
|||||||
private static final char BSM_ARG_CONSTANT = '\u0002';
|
private static final char BSM_ARG_CONSTANT = '\u0002';
|
||||||
|
|
||||||
private final IClassProvider classProvider;
|
private final IClassProvider classProvider;
|
||||||
|
private final int nativeClassVersion;
|
||||||
|
private final List<String> whitelistedPackages = new ArrayList<>();
|
||||||
|
|
||||||
public Java17ToJava8(final IClassProvider classProvider) {
|
public Java17ToJava8(final IClassProvider classProvider) {
|
||||||
this.classProvider = classProvider;
|
this.classProvider = classProvider;
|
||||||
|
|
||||||
|
final String classVersion = System.getProperty("java.class.version");
|
||||||
|
final String[] versions = classVersion.split("\\.");
|
||||||
|
final int majorVersion = Integer.parseInt(versions[0]);
|
||||||
|
final int minorVersion = Integer.parseInt(versions[1]);
|
||||||
|
this.nativeClassVersion = minorVersion << 16 | majorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Java17ToJava8 addWhitelistedPackage(final String packageName) {
|
||||||
|
this.whitelistedPackages.add(packageName);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] transform(String className, byte[] bytecode) {
|
public byte[] transform(String className, byte[] bytecode) {
|
||||||
if (!className.startsWith("com.mojang") && !className.startsWith("org.geysermc")) return null;
|
for (String whitelistedPackage : this.whitelistedPackages) {
|
||||||
|
if (!className.startsWith(whitelistedPackage)) return null;
|
||||||
|
}
|
||||||
|
|
||||||
ClassNode classNode = ASMUtils.fromBytes(bytecode);
|
final ClassNode classNode = ASMUtils.fromBytes(bytecode);
|
||||||
if (classNode.version <= Opcodes.V1_8) return null;
|
if (classNode.version <= this.nativeClassVersion) return null;
|
||||||
|
|
||||||
classNode.version = Opcodes.V1_8;
|
classNode.version = Opcodes.V1_8;
|
||||||
this.makePublic(classNode);
|
this.makePublic(classNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user