Support for Android java mods

This commit is contained in:
Anuken
2020-09-25 14:21:30 -04:00
parent 85d32cd510
commit 2cc93924f1
4 changed files with 39 additions and 13 deletions

View File

@@ -14,10 +14,18 @@ import mindustry.type.*;
import mindustry.ui.dialogs.*;
import rhino.*;
import java.net.*;
import static mindustry.Vars.*;
public interface Platform{
/** Dynamically loads a jar file. */
default Class<?> loadJar(Fi jar, String mainClass) throws Exception{
URLClassLoader classLoader = new URLClassLoader(new URL[]{jar.file().toURI().toURL()}, ClassLoader.getSystemClassLoader());
return classLoader.loadClass(mainClass);
}
/** Steam: Update lobby visibility.*/
default void updateLobby(){}
@@ -121,7 +129,7 @@ public interface Platform{
}
/**
* Show a file chooser for multiple file types. Only supported on desktop.
* Show a file chooser for multiple file types.
* @param cons Selection listener
* @param extensions File extensions to filter
*/

View File

@@ -25,7 +25,6 @@ import mindustry.type.*;
import mindustry.ui.*;
import java.io.*;
import java.net.*;
import static mindustry.Vars.*;
@@ -634,12 +633,11 @@ public class Mods implements Loadable{
//make sure the main class exists before loading it; if it doesn't just don't put it there
if(mainFile.exists()){
//mobile versions don't support class mods
if(mobile){
throw new IllegalArgumentException("Java class mods are not supported on mobile.");
if(ios){
throw new IllegalArgumentException("Java class mods are not supported on iOS.");
}
URLClassLoader classLoader = new URLClassLoader(new URL[]{sourceFile.file().toURI().toURL()}, ClassLoader.getSystemClassLoader());
Class<?> main = classLoader.loadClass(mainClass);
Class<?> main = platform.loadJar(sourceFile, mainClass);
metas.put(main, meta);
mainMod = (Mod)main.getDeclaredConstructor().newInstance();
}else{

View File

@@ -33,7 +33,7 @@ public class CrashSender{
+ "OS: " + System.getProperty("os.name") + " x" + (OS.is64Bit ? "64" : "32") + "\n"
+ "Java Version: " + System.getProperty("java.version") + "\n"
+ "Java Architecture: " + System.getProperty("sun.arch.data.model") + "\n"
+ mods.list().size + " Mods: " + mods.list().toString(", ", mod -> mod.name + ":" + mod.meta.version)
+ mods.list().size + " Mods: " + (mods.list().isEmpty() ? "none" : mods.list().toString(", ", mod -> mod.name + ":" + mod.meta.version))
+ "\n\n" + error;
}