[unsafe] Fix classpath unlocking and use classPathIsolationBypassClasses. Will need to test changes without it now
This commit is contained in:
parent
d14d063eef
commit
30ebdf1402
|
@ -23,10 +23,11 @@ allprojects {
|
|||
source sourceSets.testmod
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If dev startup fails, add:
|
||||
// -Dfabric.debug.classPathIsolationBypassClasses=io/gitlab/jfronny/libjf
|
||||
runConfigs.configureEach {
|
||||
vmArgs "-Dfabric.debug.classPathIsolationBypassClasses=io/gitlab/jfronny/libjf"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation("com.terraformersmc:modmenu:3.1.0")
|
||||
|
@ -45,4 +46,4 @@ subprojects {
|
|||
|
||||
sourceSets {
|
||||
testmod
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,4 @@ modrinth_optional_dependencies=P7dR8mSH
|
|||
curseforge_id=482600
|
||||
curseforge_optional_dependencies=fabric-api
|
||||
|
||||
commons_version=2022.5.9+20-3-39
|
||||
commons_version=2022.5.10+15-34-20
|
|
@ -1,6 +1,5 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl;
|
||||
|
||||
import io.gitlab.jfronny.commons.throwable.Coerce;
|
||||
import io.gitlab.jfronny.gson.JsonElement;
|
||||
import io.gitlab.jfronny.gson.JsonObject;
|
||||
import io.gitlab.jfronny.gson.stream.JsonWriter;
|
||||
|
|
|
@ -5,14 +5,11 @@ import com.mojang.brigadier.arguments.*;
|
|||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import io.gitlab.jfronny.commons.throwable.Coerce;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
|
||||
import io.gitlab.jfronny.commons.throwable.Try;
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
|
||||
import io.gitlab.jfronny.libjf.config.api.ConfigInstance;
|
||||
import io.gitlab.jfronny.libjf.config.api.Entry;
|
||||
import io.gitlab.jfronny.libjf.config.api.EntryInfo;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
|
|
|
@ -4,10 +4,8 @@ import io.gitlab.jfronny.commons.throwable.Try;
|
|||
import io.gitlab.jfronny.commons.tuple.Tuple;
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.config.api.ConfigInstance;
|
||||
import io.gitlab.jfronny.libjf.config.api.Entry;
|
||||
import io.gitlab.jfronny.libjf.config.api.EntryInfo;
|
||||
import io.gitlab.jfronny.libjf.config.api.WidgetFactory;
|
||||
import io.gitlab.jfronny.libjf.config.impl.EntryInfoImpl;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
|
@ -113,7 +111,6 @@ public class EntryInfoWidgetBuilder {
|
|||
done.active = state.knownStates.stream().allMatch(st -> st.inLimits);
|
||||
|
||||
if (inLimits) {
|
||||
//Coerce.consumer(info::setValue).addHandler(e -> {}).accept(isNumber ? (T) value : (T) currentInput);
|
||||
state.cachedValue = isNumber ? (T) value : (T) currentInput;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ public class JfLanguageAdapter implements LanguageAdapter {
|
|||
public native <T> T create(net.fabricmc.loader.api.ModContainer mod, String value, Class<T> type);
|
||||
|
||||
static {
|
||||
Logger.registerFactory(FLLogger::new); // Reset in mixin plugin
|
||||
Set<Flags.BooleanFlag> flags = Flags.getBoolFlags("unsafe.unlock");
|
||||
if (flags.stream().map(Flags.BooleanFlag::value).reduce(false, (left, right) -> left || right)) {
|
||||
SafeLog.warn("Unlocking classpath due to: " + flags.stream().map(Flags.BooleanFlag::source).collect(Collectors.joining(", ")));
|
||||
|
@ -24,7 +25,6 @@ public class JfLanguageAdapter implements LanguageAdapter {
|
|||
}
|
||||
HiddenAnnotationExclusionStrategy.register();
|
||||
GsonHolder.register();
|
||||
Logger.registerFactory(FLLogger::new); // Reset in mixin plugin
|
||||
DynamicEntry.execute("libjf:preEarly", UltraEarlyInit.class, s -> s.instance().init());
|
||||
DynamicEntry.execute("libjf:early", UltraEarlyInit.class, s -> s.instance().init());
|
||||
SafeLog.info("LibJF unsafe init completed");
|
||||
|
|
|
@ -3,14 +3,11 @@ 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;
|
||||
|
@ -30,22 +27,13 @@ public record FabricLauncherClassUnlocker(KnotClassLoaderInterfaceAccessor class
|
|||
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);
|
||||
}
|
||||
classLoader.getDelegate().setAllowedPrefixes(path, allowedPrefixes);
|
||||
classLoader.getDelegate().addCodeSource(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowedPrefixes(Path path, String... prefixes) {
|
||||
try {
|
||||
classLoader.getDelegate().setAllowedPrefixes(UrlUtil.asUrl(path), prefixes);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
classLoader.getDelegate().setAllowedPrefixes(path, prefixes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,21 +2,32 @@ package io.gitlab.jfronny.libjf.unsafe.inject;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public record KnotClassDelegateAccessor(Object delegate) {
|
||||
private static final Method addCodeSourceMethod;
|
||||
private static final Method setAllowedPrefixesMethod;
|
||||
static {
|
||||
try {
|
||||
Class<?> klazz = Class.forName("net.fabricmc.loader.impl.launch.knot.KnotClassDelegate");
|
||||
setAllowedPrefixesMethod = klazz.getDeclaredMethod("setAllowedPrefixes", URL.class, String[].class);
|
||||
addCodeSourceMethod = klazz.getDeclaredMethod("addCodeSource", Path.class);
|
||||
addCodeSourceMethod.setAccessible(true);
|
||||
setAllowedPrefixesMethod = klazz.getDeclaredMethod("setAllowedPrefixes", Path.class, String[].class);
|
||||
setAllowedPrefixesMethod.setAccessible(true);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new IllegalStateException("Could not build accessor for class delegate. This version of fabric is likely not yet supported", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowedPrefixes(URL url, String... prefixes) {
|
||||
public void addCodeSource(Path url) {
|
||||
try {
|
||||
addCodeSourceMethod.invoke(delegate, url);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IllegalStateException("Could not invoke addURL on class loader. This version of fabric is likely not yet supported", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowedPrefixes(Path url, String... prefixes) {
|
||||
try {
|
||||
setAllowedPrefixesMethod.invoke(delegate, url, prefixes);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
|
|
|
@ -2,16 +2,12 @@ package io.gitlab.jfronny.libjf.unsafe.inject;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
public record KnotClassLoaderInterfaceAccessor(ClassLoader loader) {
|
||||
private static final Method addURLMethod;
|
||||
private static final Method getDelegateMethod;
|
||||
static {
|
||||
try {
|
||||
Class<?> klazz = Class.forName("net.fabricmc.loader.impl.launch.knot.KnotClassLoaderInterface");
|
||||
addURLMethod = klazz.getDeclaredMethod("addURL", URL.class);
|
||||
addURLMethod.setAccessible(true);
|
||||
Class<?> klazz = Class.forName("net.fabricmc.loader.impl.launch.knot.KnotClassLoader");
|
||||
getDelegateMethod = klazz.getDeclaredMethod("getDelegate");
|
||||
getDelegateMethod.setAccessible(true);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
|
@ -19,14 +15,6 @@ public record KnotClassLoaderInterfaceAccessor(ClassLoader loader) {
|
|||
}
|
||||
}
|
||||
|
||||
public void addURL(URL url) {
|
||||
try {
|
||||
addURLMethod.invoke(loader, url);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IllegalStateException("Could not invoke addURL on class loader. This version of fabric is likely not yet supported", e);
|
||||
}
|
||||
}
|
||||
|
||||
public KnotClassDelegateAccessor getDelegate() {
|
||||
try {
|
||||
return new KnotClassDelegateAccessor(getDelegateMethod.invoke(loader));
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"custom": {
|
||||
"libjf": {
|
||||
"asm.export": true,
|
||||
"asm.log": true
|
||||
"asm.log": true,
|
||||
"unsafe.unlock": true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue