Compare commits

...

3 commits

25 changed files with 112 additions and 98 deletions

View file

@ -1,11 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.client;
import io.github.moehreag.nonsense.loader.impl.Launcher;
import io.github.moehreag.nonsense.loader.impl.Env;
public class NonsenseClient {
public static void main(String[] args){
Launcher.run(args, Env.CLIENT);
}
}

View file

@ -1,6 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.mod;
import io.github.moehreag.nonsense.loader.api.mod.ModProperties;
public record BuiltinModProperties(String id, String name) implements ModProperties {
}

View file

@ -1,9 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.mod;
import java.util.Map;
import io.github.moehreag.nonsense.loader.api.mod.ModProperties;
import io.github.moehreag.nonsense.loader.api.mod.ModProvider;
public record BuiltinModProvider(ModProperties properties, Map<String, String> entrypoints) implements ModProvider {
}

View file

@ -1,14 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.plugin;
import io.github.moehreag.nonsense.loader.impl.LoaderImpl;
public interface NonsensePlugin extends Runnable {
default void run() {
}
default void init(LoaderImpl loader) {
}
}

View file

@ -1,11 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.server;
import io.github.moehreag.nonsense.loader.impl.Launcher;
import io.github.moehreag.nonsense.loader.impl.Env;
public class NonsenseServer {
public static void main(String[] args){
Launcher.run(args, Env.SERVER);
}
}

View file

@ -1,11 +1,11 @@
package io.github.moehreag.nonsense.loader.api; package org.ecorous.esnesnon.nonsense.loader.api;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import io.github.moehreag.nonsense.loader.impl.Env; import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
import io.github.moehreag.nonsense.loader.impl.LoaderImpl; import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin; import org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin;
public interface Loader { public interface Loader {

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package org.ecorous.esnesnon.nonsense.loader.api.env;
import lombok.Getter; import lombok.Getter;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.api.mod; package org.ecorous.esnesnon.nonsense.loader.api.mod;
public interface ModProperties { public interface ModProperties {

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.api.mod; package org.ecorous.esnesnon.nonsense.loader.api.mod;
import java.util.Map; import java.util.Map;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package org.ecorous.esnesnon.nonsense.loader.impl;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package org.ecorous.esnesnon.nonsense.loader.impl;
import java.io.*; import java.io.*;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
@ -9,15 +9,17 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import io.github.moehreag.nonsense.loader.api.Loader; import org.ecorous.esnesnon.nonsense.loader.api.Loader;
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin; import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
import org.ecorous.esnesnon.nonsense.loader.impl.launch.MixinClassloader;
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;
public class LoaderImpl implements Loader { public class LoaderImpl implements Loader {
private static final String PLUGIN_SERVICE_FILE_LOCATION = "META-INF/services/io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin"; private static final String PLUGIN_SERVICE_FILE_LOCATION = "META-INF/services/org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin";
// TODO decide this // TODO decide this
public static final String MOD_FILE_EXTENSION = ".nonsense"; public static final String MOD_FILE_EXTENSION = ".nonsense";
@ -84,24 +86,25 @@ public class LoaderImpl implements Loader {
}); });
LOGGER.info("Found plugins: \n{}", String.join("\t\n", classes)); LOGGER.info("Found plugins: \n{}", String.join("\t\n", classes));
classes.stream().map((String className) -> { for (Class<?> c : classes.stream().map((String className) -> {
try { try {
return Class.forName(className); return classloader.findClass(className);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// TODO error handling // TODO error handling
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}).filter(NonsensePlugin.class::isAssignableFrom).forEach(c -> { }).filter(NonsensePlugin.class::isAssignableFrom).toList()){
try { try {
MethodHandle ctor = MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class)); MethodHandle ctor = MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class));
NonsensePlugin plugin = (NonsensePlugin) ctor.invoke(); NonsensePlugin plugin = (NonsensePlugin) ctor.invoke();
plugins.add(plugin); plugins.add(plugin);
plugin.init(this); if (plugin.init(this)){
break;
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
LOGGER.error("Failed to instantiate plugin: ", e); LOGGER.error("Failed to instantiate plugin: ", e);
} }
}); }
} }
public String getArgument(String name){ public String getArgument(String name){

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package org.ecorous.esnesnon.nonsense.loader.impl.launch;
import java.io.File; import java.io.File;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
@ -14,10 +14,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService; import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
import org.ecorous.esnesnon.nonsense.loader.impl.mixin.NonsenseMixinService;
import lombok.Getter; import lombok.Getter;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.service.IPropertyKey; import org.spongepowered.asm.service.IPropertyKey;
@ -37,7 +36,6 @@ public class Launcher {
private final Env env; private final Env env;
public static void run(String[] args, Env env) { public static void run(String[] args, Env env) {
//Configurator.setRootLevel(Level.INFO); // TODO replace with actual log4j config
new Launcher(args, env); new Launcher(args, env);
} }
@ -63,9 +61,11 @@ public class Launcher {
MixinBootstrap.init(); MixinBootstrap.init();
try { try {
MethodHandle ctor = MethodHandles.publicLookup().findStatic(targetClassLoader.loadClass(LoaderImpl.class.getName()), "run", MethodType.methodType(void.class, String[].class, Env.class)); Class<?> clazz = targetClassLoader.findClass("impl.org.ecorous.esnesnon.nonsense.loader.LoaderImpl");
MethodHandle ctor = MethodHandles.publicLookup().findStatic(clazz, "run", MethodType.methodType(void.class, String[].class, Env.class));
ctor.invoke(args, env); ctor.invoke(args, env);
} catch (Throwable e) { } catch (Throwable e) {
// TODO
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package org.ecorous.esnesnon.nonsense.loader.impl.launch;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -15,15 +15,15 @@ public class MixinClassloader extends URLClassLoader {
super.addURL(url); super.addURL(url);
} }
public boolean isClassLoaded(String name){
return findLoadedClass(name) != null;
}
@Override @Override
public Class<?> findClass(String name) throws ClassNotFoundException { public Class<?> findClass(String name) throws ClassNotFoundException {
return super.findClass(name); return super.findClass(name);
} }
public boolean isClassLoaded(String name){
return findLoadedClass(name) != null;
}
public byte[] getClassBytes(String name) throws IOException { public byte[] getClassBytes(String name) throws IOException {
String binName = name.replace(".", "/"); String binName = name.replace(".", "/");
String path = binName.concat(".class"); String path = binName.concat(".class");
@ -34,4 +34,5 @@ public class MixinClassloader extends URLClassLoader {
} }
} }
} }

View file

@ -0,0 +1,11 @@
package org.ecorous.esnesnon.nonsense.loader.impl.launch.client;
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
public class NonsenseClient {
public static void main(String[] args){
Launcher.run(args, Env.CLIENT);
}
}

View file

@ -0,0 +1,11 @@
package org.ecorous.esnesnon.nonsense.loader.impl.launch.server;
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
public class NonsenseServer {
public static void main(String[] args){
Launcher.run(args, Env.SERVER);
}
}

View file

@ -1,6 +1,6 @@
package io.github.moehreag.nonsense.loader.impl.mixin; package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
import io.github.moehreag.nonsense.loader.impl.Launcher; import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
import org.spongepowered.asm.service.IGlobalPropertyService; import org.spongepowered.asm.service.IGlobalPropertyService;
import org.spongepowered.asm.service.IPropertyKey; import org.spongepowered.asm.service.IPropertyKey;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl.mixin; package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

View file

@ -1,6 +1,6 @@
package io.github.moehreag.nonsense.loader.impl.mixin; package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
import io.github.moehreag.nonsense.loader.impl.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;
import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual; import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual;

View file

@ -0,0 +1,6 @@
package org.ecorous.esnesnon.nonsense.loader.impl.mod;
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModProperties;
public record BuiltinModProperties(String id, String name) implements ModProperties {
}

View file

@ -0,0 +1,9 @@
package org.ecorous.esnesnon.nonsense.loader.impl.mod;
import java.util.Map;
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModProperties;
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModProvider;
public record BuiltinModProvider(ModProperties properties, Map<String, String> entrypoints) implements ModProvider {
}

View file

@ -0,0 +1,14 @@
package org.ecorous.esnesnon.nonsense.loader.impl.plugin;
import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
public interface NonsensePlugin extends Runnable {
default void run() {
}
default boolean init(LoaderImpl loader) {
return false;
}
}

View file

@ -1,8 +1,8 @@
package io.github.moehreag.nonsense.loader.impl.plugin.game; package org.ecorous.esnesnon.nonsense.loader.impl.plugin.game;
import io.github.moehreag.nonsense.loader.impl.Discovery; import org.ecorous.esnesnon.nonsense.loader.impl.Discovery;
import io.github.moehreag.nonsense.loader.impl.LoaderImpl; import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin; import org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin;
import org.ecorous.esnesnon.mojmap_patcher.MojMapPatcher; import org.ecorous.esnesnon.mojmap_patcher.MojMapPatcher;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,7 +32,13 @@ public class Minecraft implements NonsensePlugin {
private String foundMainClass; private String foundMainClass;
@Override @Override
public void init(LoaderImpl loader) { public boolean init(LoaderImpl loader) {
Path gameJar = findGame();
if (gameJar == null){
return false;
//throw new IllegalStateException("Could not find game jar!");
}
version = loader.getArgument("version"); version = loader.getArgument("version");
remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-"+version+"-remapped.jar"); remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-"+version+"-remapped.jar");
@ -58,17 +64,20 @@ public class Minecraft implements NonsensePlugin {
LOGGER.info("Found {} mods", mods.size()); LOGGER.info("Found {} mods", mods.size());
if (!Files.exists(remappedGamePath)){ if (!Files.exists(remappedGamePath)){
Path gameJar = findGame();
if (gameJar == null){
throw new IllegalStateException("Could not find game jar!");
}
try { try {
MojMapPatcher.run(version, gameJar, remappedGamePath); MojMapPatcher.run(version, gameJar, remappedGamePath);
} catch (IOException e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
try {
LoaderImpl.getInstance().getClassloader().addURL(remappedGamePath.toUri().toURL());
} catch (Throwable e) {
throw new RuntimeException(e);
}
return true;
} }
private Path findGame() { private Path findGame() {
@ -102,9 +111,10 @@ public class Minecraft implements NonsensePlugin {
Class<?> mainClass = Class.forName(foundMainClass); Class<?> mainClass = Class.forName(foundMainClass);
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
main.invoke((Object) LoaderImpl.getInstance().getArgs()); main.invoke((Object) LoaderImpl.getInstance().getArgs());
} else {
LOGGER.warn("Failed to locate main class!");
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View file

@ -1 +0,0 @@
io.github.moehreag.nonsense.loader.impl.plugin.game.Minecraft

View file

@ -0,0 +1 @@
org.ecorous.esnesnon.nonsense.loader.impl.plugin.game.Minecraft

View file

@ -1 +1 @@
io.github.moehreag.nonsense.loader.impl.mixin.NonsenseGlobalPropertyService org.ecorous.esnesnon.nonsense.loader.impl.mixin.NonsenseGlobalPropertyService