mixins are now working
This commit is contained in:
parent
798fc26fe4
commit
ba409f9905
|
@ -17,6 +17,7 @@ import org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||||
|
|
||||||
public class LoaderImpl implements Loader {
|
public class LoaderImpl implements Loader {
|
||||||
// TODO decide this
|
// TODO decide this
|
||||||
|
@ -64,11 +65,21 @@ public class LoaderImpl implements Loader {
|
||||||
}
|
}
|
||||||
|
|
||||||
discoverPlugins();
|
discoverPlugins();
|
||||||
|
advanceMixinState();
|
||||||
LOGGER.info("Launching...");
|
LOGGER.info("Launching...");
|
||||||
plugins.forEach(NonsensePlugin::run);
|
plugins.forEach(NonsensePlugin::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void advanceMixinState(){
|
||||||
|
try {
|
||||||
|
MethodHandle m = MethodHandles.privateLookupIn(MixinEnvironment.class, MethodHandles.lookup()).findStatic(MixinEnvironment.class, "gotoPhase", MethodType.methodType(void.class, MixinEnvironment.Phase.class));
|
||||||
|
m.invoke(MixinEnvironment.Phase.INIT);
|
||||||
|
m.invoke(MixinEnvironment.Phase.DEFAULT);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void run(String[] args, Env env) {
|
public static void run(String[] args, Env env) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.launch;
|
package org.ecorous.esnesnon.nonsense.loader.impl.launch;
|
||||||
|
|
||||||
|
import org.ecorous.esnesnon.nonsense.loader.impl.mixin.NonsenseMixinService;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -40,7 +42,7 @@ public class MixinClassLoader extends URLClassLoader {
|
||||||
if (in == null)
|
if (in == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return in.readAllBytes();
|
return NonsenseMixinService.getTransformer().transformClass(MixinEnvironment.getCurrentEnvironment(), name, in.readAllBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ public class NonsenseMixinLogger extends LoggerAdapterAbstract {
|
||||||
|
|
||||||
public NonsenseMixinLogger(String name){
|
public NonsenseMixinLogger(String name){
|
||||||
super(name);
|
super(name);
|
||||||
log = LoggerFactory.getLogger(name);
|
log = LoggerFactory.getLogger("Nonsense Loader/"+name.substring(0, 1).toUpperCase(Locale.ROOT)+name.substring(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
|
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
@ -13,13 +21,8 @@ import org.spongepowered.asm.service.*;
|
||||||
import org.spongepowered.asm.transformers.MixinClassReader;
|
import org.spongepowered.asm.transformers.MixinClassReader;
|
||||||
import org.spongepowered.asm.util.ReEntranceLock;
|
import org.spongepowered.asm.util.ReEntranceLock;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NonsenseMixinService implements IMixinService, IClassProvider, IClassBytecodeProvider, ITransformerProvider, IClassTracker {
|
public class NonsenseMixinService implements IMixinService, IClassProvider, IClassBytecodeProvider, ITransformerProvider, IClassTracker {
|
||||||
|
@Getter
|
||||||
static IMixinTransformer transformer;
|
static IMixinTransformer transformer;
|
||||||
private final ReEntranceLock lock = new ReEntranceLock(1);
|
private final ReEntranceLock lock = new ReEntranceLock(1);
|
||||||
private final ContainerHandleVirtual handle = new ContainerHandleVirtual(getName());
|
private final ContainerHandleVirtual handle = new ContainerHandleVirtual(getName());
|
||||||
|
@ -41,7 +44,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MixinEnvironment.Phase getInitialPhase() {
|
public MixinEnvironment.Phase getInitialPhase() {
|
||||||
return null;
|
return MixinEnvironment.Phase.PREINIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,7 +101,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getPlatformAgents() {
|
public Collection<String> getPlatformAgents() {
|
||||||
return List.of();
|
return Collections.singletonList("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,12 +126,12 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MixinEnvironment.CompatibilityLevel getMinCompatibilityLevel() {
|
public MixinEnvironment.CompatibilityLevel getMinCompatibilityLevel() {
|
||||||
return null;
|
return MixinEnvironment.CompatibilityLevel.JAVA_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MixinEnvironment.CompatibilityLevel getMaxCompatibilityLevel() {
|
public MixinEnvironment.CompatibilityLevel getMaxCompatibilityLevel() {
|
||||||
return null;
|
return MixinEnvironment.CompatibilityLevel.JAVA_22;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,7 +148,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
||||||
@Override
|
@Override
|
||||||
public ClassNode getClassNode(String name, boolean runTransformers) throws IOException {
|
public ClassNode getClassNode(String name, boolean runTransformers) throws IOException {
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
if (runTransformers){
|
if (runTransformers && transformer != null) {
|
||||||
bytes = transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), name,
|
bytes = transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), name,
|
||||||
Launcher.getInstance().getTargetClassLoader().getClassBytes(name));
|
Launcher.getInstance().getTargetClassLoader().getClassBytes(name));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class Minecraft implements NonsensePlugin {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}).forEachOrdered(LoaderImpl.getInstance().getClassloader()::addURL);
|
}).forEachOrdered(LoaderImpl.getInstance().getClassloader()::addURL);
|
||||||
LOGGER.info("Found {} mods", mods.size()+classpathMods.size());
|
LOGGER.info("Found {} mod(s)", mods.size()+classpathMods.size());
|
||||||
|
|
||||||
classpathMods.parallelStream().map(ModPropertiesReader::readFile).forEachOrdered(modProperties::add);
|
classpathMods.parallelStream().map(ModPropertiesReader::readFile).forEachOrdered(modProperties::add);
|
||||||
mods.parallelStream().map(ModPropertiesReader::read).forEachOrdered(opt -> opt.ifPresent(modProperties::add));
|
mods.parallelStream().map(ModPropertiesReader::read).forEachOrdered(opt -> opt.ifPresent(modProperties::add));
|
||||||
|
|
Loading…
Reference in a new issue