2021-12-30 13:37:05 +01:00
|
|
|
package io.gitlab.jfronny.libjf.unsafe.inject;
|
|
|
|
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
|
|
import net.fabricmc.loader.impl.launch.FabricLauncher;
|
|
|
|
import net.fabricmc.loader.impl.launch.MappingConfiguration;
|
|
|
|
import net.fabricmc.loader.impl.util.log.Log;
|
|
|
|
import net.fabricmc.loader.impl.util.log.LogCategory;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.nio.file.Path;
|
2022-05-09 22:53:54 +02:00
|
|
|
import java.util.Collection;
|
2021-12-30 13:37:05 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.jar.Manifest;
|
|
|
|
|
|
|
|
public record FabricLauncherClassUnlocker(KnotClassLoaderInterfaceAccessor classLoader) implements FabricLauncher {
|
|
|
|
static {
|
2022-04-02 22:01:29 +02:00
|
|
|
System.err.println("[libjf-unsafe-v0] Preparing to unlock classpath via reflection. This might cause issues");
|
2021-12-30 13:37:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MappingConfiguration getMappingConfiguration() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addToClassPath(Path path, String... allowedPrefixes) {
|
|
|
|
Log.debug(LogCategory.KNOT, "Adding " + path + " to classpath.");
|
|
|
|
|
2022-05-12 18:50:14 +02:00
|
|
|
classLoader.getDelegate().setAllowedPrefixes(path, allowedPrefixes);
|
|
|
|
classLoader.getDelegate().addCodeSource(path);
|
2021-12-30 13:37:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAllowedPrefixes(Path path, String... prefixes) {
|
2022-05-12 18:50:14 +02:00
|
|
|
classLoader.getDelegate().setAllowedPrefixes(path, prefixes);
|
2021-12-30 13:37:05 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 22:53:54 +02:00
|
|
|
@Override
|
|
|
|
public void setValidParentClassPath(Collection<Path> paths) {
|
|
|
|
invalidCall();
|
|
|
|
}
|
|
|
|
|
2021-12-30 13:37:05 +01:00
|
|
|
@Override
|
|
|
|
public EnvType getEnvironmentType() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isClassLoaded(String name) {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<?> loadIntoTarget(String name) throws ClassNotFoundException {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InputStream getResourceAsStream(String name) {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ClassLoader getTargetClassLoader() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte[] getClassByteArray(String name, boolean runTransformers) throws IOException {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Manifest getManifest(Path originPath) {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDevelopment() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getEntrypoint() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getTargetNamespace() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Path> getClassPath() {
|
|
|
|
return invalidCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
private <T> T invalidCall() {
|
|
|
|
throw new IllegalStateException("unlockClassPath attempted to call a method not implemented here");
|
|
|
|
}
|
|
|
|
}
|