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.UrlUtil; 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.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; import java.util.Collection; import java.util.List; import java.util.jar.Manifest; public record FabricLauncherClassUnlocker(KnotClassLoaderInterfaceAccessor classLoader) implements FabricLauncher { static { System.err.println("[libjf-unsafe-v0] Preparing to unlock classpath via reflection. This might cause issues"); } @Override public MappingConfiguration getMappingConfiguration() { return invalidCall(); } @Override public void addToClassPath(Path path, String... allowedPrefixes) { Log.debug(LogCategory.KNOT, "Adding " + path + " to classpath."); try { URL url = UrlUtil.asUrl(path); classLoader.getDelegate().setAllowedPrefixes(url, allowedPrefixes); classLoader.addURL(url); } catch (MalformedURLException e) { throw new RuntimeException(e); } } @Override public void setAllowedPrefixes(Path path, String... prefixes) { try { classLoader.getDelegate().setAllowedPrefixes(UrlUtil.asUrl(path), prefixes); } catch (MalformedURLException e) { throw new RuntimeException(e); } } @Override public void setValidParentClassPath(Collection paths) { invalidCall(); } @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 getClassPath() { return invalidCall(); } private T invalidCall() { throw new IllegalStateException("unlockClassPath attempted to call a method not implemented here"); } }