Compare commits
No commits in common. "ab7977c1f3496b187d8a7ba8e85b326d4324a4f0" and "0b55824be0a04ada708b2884db914d6f294c76e1" have entirely different histories.
ab7977c1f3
...
0b55824be0
|
@ -1,11 +1,11 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.api;
|
package io.github.moehreag.nonsense.loader.api;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
|
import io.github.moehreag.nonsense.loader.impl.Env;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
|
import io.github.moehreag.nonsense.loader.impl.LoaderImpl;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin;
|
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin;
|
||||||
|
|
||||||
public interface Loader {
|
public interface Loader {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.api.mod;
|
package io.github.moehreag.nonsense.loader.api.mod;
|
||||||
|
|
||||||
public interface ModProperties {
|
public interface ModProperties {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.api.mod;
|
package io.github.moehreag.nonsense.loader.api.mod;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl;
|
package io.github.moehreag.nonsense.loader.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.api.env;
|
package io.github.moehreag.nonsense.loader.impl;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.launch;
|
package io.github.moehreag.nonsense.loader.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
@ -14,9 +14,10 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
|
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +63,9 @@ public class Launcher {
|
||||||
MixinBootstrap.init();
|
MixinBootstrap.init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = targetClassLoader.findClass("impl.org.ecorous.esnesnon.nonsense.loader.LoaderImpl");
|
MethodHandle ctor = MethodHandles.publicLookup().findStatic(targetClassLoader.loadClass(LoaderImpl.class.getName()), "run", MethodType.methodType(void.class, String[].class, Env.class));
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl;
|
package io.github.moehreag.nonsense.loader.impl;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
@ -9,17 +9,15 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.api.Loader;
|
import io.github.moehreag.nonsense.loader.api.Loader;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.api.env.Env;
|
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin;
|
||||||
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/org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin";
|
private static final String PLUGIN_SERVICE_FILE_LOCATION = "META-INF/services/io.github.moehreag.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";
|
||||||
|
|
||||||
|
@ -86,25 +84,24 @@ 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));
|
||||||
|
|
||||||
for (Class<?> c : classes.stream().map((String className) -> {
|
classes.stream().map((String className) -> {
|
||||||
try {
|
try {
|
||||||
return classloader.findClass(className);
|
return Class.forName(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).toList()){
|
}).filter(NonsensePlugin.class::isAssignableFrom).forEach(c -> {
|
||||||
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);
|
||||||
if (plugin.init(this)){
|
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){
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.launch;
|
package io.github.moehreag.nonsense.loader.impl;
|
||||||
|
|
||||||
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,5 +34,4 @@ public class MixinClassloader extends URLClassLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
package io.github.moehreag.nonsense.loader.impl.mixin;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
|
import io.github.moehreag.nonsense.loader.impl.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;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
package io.github.moehreag.nonsense.loader.impl.mixin;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
|
@ -1,6 +1,6 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.mixin;
|
package io.github.moehreag.nonsense.loader.impl.mixin;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.launch.Launcher;
|
import io.github.moehreag.nonsense.loader.impl.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;
|
|
@ -0,0 +1,6 @@
|
||||||
|
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 {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
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 {
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
package org.ecorous.esnesnon.nonsense.loader.impl.plugin.game;
|
package io.github.moehreag.nonsense.loader.impl.plugin.game;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.Discovery;
|
import io.github.moehreag.nonsense.loader.impl.Discovery;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
|
import io.github.moehreag.nonsense.loader.impl.LoaderImpl;
|
||||||
import org.ecorous.esnesnon.nonsense.loader.impl.plugin.NonsensePlugin;
|
import io.github.moehreag.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,13 +32,7 @@ public class Minecraft implements NonsensePlugin {
|
||||||
private String foundMainClass;
|
private String foundMainClass;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(LoaderImpl loader) {
|
public void 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");
|
||||||
|
|
||||||
|
@ -64,20 +58,17 @@ 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 (Throwable e) {
|
} catch (IOException 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() {
|
||||||
|
@ -111,10 +102,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
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 {
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
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 {
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1 @@
|
||||||
|
io.github.moehreag.nonsense.loader.impl.plugin.game.Minecraft
|
|
@ -1 +0,0 @@
|
||||||
org.ecorous.esnesnon.nonsense.loader.impl.plugin.game.Minecraft
|
|
|
@ -1 +1 @@
|
||||||
org.ecorous.esnesnon.nonsense.loader.impl.mixin.NonsenseGlobalPropertyService
|
io.github.moehreag.nonsense.loader.impl.mixin.NonsenseGlobalPropertyService
|
Loading…
Reference in a new issue