Configure mod bootstrap in main thread
This commit is contained in:
parent
961f2d0a8a
commit
b979227322
|
@ -69,6 +69,7 @@ dependencies {
|
||||||
implementation 'net.minecraftforge:forgespi:4.0.9'
|
implementation 'net.minecraftforge:forgespi:4.0.9'
|
||||||
gson 'com.google.code.gson:gson:2.8.8'
|
gson 'com.google.code.gson:gson:2.8.8'
|
||||||
implementation 'org.apache.logging.log4j:log4j-api:2.14.1'
|
implementation 'org.apache.logging.log4j:log4j-api:2.14.1'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-core:2.14.1'
|
||||||
implementation 'org.jetbrains:annotations:19.0.0'
|
implementation 'org.jetbrains:annotations:19.0.0'
|
||||||
implementation 'org.spongepowered:mixin:0.8.3'
|
implementation 'org.spongepowered:mixin:0.8.3'
|
||||||
implementation 'org.apache.logging.log4j:log4j-jul:2.14.1'
|
implementation 'org.apache.logging.log4j:log4j-jul:2.14.1'
|
||||||
|
|
|
@ -3,6 +3,7 @@ package io.izzel.arclight.boot.asm;
|
||||||
import cpw.mods.modlauncher.api.NamedPath;
|
import cpw.mods.modlauncher.api.NamedPath;
|
||||||
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
||||||
import io.izzel.arclight.boot.log.ArclightI18nLogger;
|
import io.izzel.arclight.boot.log.ArclightI18nLogger;
|
||||||
|
import io.izzel.arclight.boot.mod.ModBootstrap;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
@ -46,6 +47,8 @@ public class ArclightImplementer implements ILaunchPluginService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) {
|
public void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) {
|
||||||
|
// runs after TX CL built
|
||||||
|
ModBootstrap.postRun();
|
||||||
this.transformerLoader = transformerLoader;
|
this.transformerLoader = transformerLoader;
|
||||||
this.implementers.put("inventory", new InventoryImplementer());
|
this.implementers.put("inventory", new InventoryImplementer());
|
||||||
this.implementers.put("switch", SwitchTableFixer.INSTANCE);
|
this.implementers.put("switch", SwitchTableFixer.INSTANCE);
|
||||||
|
|
|
@ -42,8 +42,6 @@ public class ArclightLocator_Forge implements IModLocator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scanFile(IModFile file, Consumer<Path> pathConsumer) {
|
public void scanFile(IModFile file, Consumer<Path> pathConsumer) {
|
||||||
// runs after TX CL built
|
|
||||||
ModBootstrap.postRun();
|
|
||||||
final Function<Path, SecureJar.Status> status = p -> file.getSecureJar().verifyPath(p);
|
final Function<Path, SecureJar.Status> status = p -> file.getSecureJar().verifyPath(p);
|
||||||
try (Stream<Path> files = Files.find(file.getSecureJar().getRootPath(), Integer.MAX_VALUE, (p, a) -> p.getNameCount() > 0 && p.getFileName().toString().endsWith(".class"))) {
|
try (Stream<Path> files = Files.find(file.getSecureJar().getRootPath(), Integer.MAX_VALUE, (p, a) -> p.getNameCount() > 0 && p.getFileName().toString().endsWith(".class"))) {
|
||||||
file.setSecurityStatus(files.peek(pathConsumer).map(status).reduce((s1, s2) -> SecureJar.Status.values()[Math.min(s1.ordinal(), s2.ordinal())]).orElse(SecureJar.Status.INVALID));
|
file.setSecurityStatus(files.peek(pathConsumer).map(status).reduce((s1, s2) -> SecureJar.Status.values()[Math.min(s1.ordinal(), s2.ordinal())]).orElse(SecureJar.Status.INVALID));
|
||||||
|
|
|
@ -26,9 +26,9 @@ import java.util.Set;
|
||||||
|
|
||||||
public class ModBootstrap extends AbstractBootstrap {
|
public class ModBootstrap extends AbstractBootstrap {
|
||||||
|
|
||||||
public static record ModBoot(Configuration configuration, Thread thread, ClassLoader parent) {}
|
public static record ModBoot(Configuration configuration, ClassLoader parent) {}
|
||||||
|
|
||||||
private static volatile ModBoot modBoot;
|
private static ModBoot modBoot;
|
||||||
|
|
||||||
static void run() {
|
static void run() {
|
||||||
var plugin = Launcher.INSTANCE.environment().findLaunchPlugin("arclight_implementer");
|
var plugin = Launcher.INSTANCE.environment().findLaunchPlugin("arclight_implementer");
|
||||||
|
@ -46,12 +46,12 @@ public class ModBootstrap extends AbstractBootstrap {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static void postRun() {
|
public static void postRun() {
|
||||||
if (modBoot == null) return;
|
if (modBoot == null) return;
|
||||||
try {
|
try {
|
||||||
var conf = modBoot.configuration();
|
var conf = modBoot.configuration();
|
||||||
var parent = modBoot.parent();
|
var parent = modBoot.parent();
|
||||||
var classLoader = (ModuleClassLoader) modBoot.thread().getContextClassLoader();
|
var classLoader = (ModuleClassLoader) Thread.currentThread().getContextClassLoader();
|
||||||
var parentField = ModuleClassLoader.class.getDeclaredField("parentLoaders");
|
var parentField = ModuleClassLoader.class.getDeclaredField("parentLoaders");
|
||||||
var parentLoaders = (Map<String, ClassLoader>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(parentField));
|
var parentLoaders = (Map<String, ClassLoader>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(parentField));
|
||||||
for (var mod : conf.modules()) {
|
for (var mod : conf.modules()) {
|
||||||
|
@ -116,7 +116,7 @@ public class ModBootstrap extends AbstractBootstrap {
|
||||||
var confOffset = Unsafe.objectFieldOffset(configurationField);
|
var confOffset = Unsafe.objectFieldOffset(configurationField);
|
||||||
var oldConf = (Configuration) Unsafe.getObject(classLoader, confOffset);
|
var oldConf = (Configuration) Unsafe.getObject(classLoader, confOffset);
|
||||||
var conf = oldConf.resolveAndBind(JarModuleFinder.of(secureJar), ModuleFinder.of(), List.of(secureJar.name()));
|
var conf = oldConf.resolveAndBind(JarModuleFinder.of(secureJar), ModuleFinder.of(), List.of(secureJar.name()));
|
||||||
modBoot = new ModBoot(conf, Thread.currentThread(), classLoader);
|
modBoot = new ModBoot(conf, classLoader);
|
||||||
Unsafe.putObjectVolatile(classLoader, confOffset, conf);
|
Unsafe.putObjectVolatile(classLoader, confOffset, conf);
|
||||||
var pkgField = ModuleClassLoader.class.getDeclaredField("packageLookup");
|
var pkgField = ModuleClassLoader.class.getDeclaredField("packageLookup");
|
||||||
var packageLookup = (Map<String, ResolvedModule>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(pkgField));
|
var packageLookup = (Map<String, ResolvedModule>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(pkgField));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user