mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-13 12:16:53 +07:00
Better access
This commit is contained in:
parent
57f9aeee86
commit
3abcdf2063
1
core/assets/scripts/base.js
Executable file
1
core/assets/scripts/base.js
Executable file
@ -0,0 +1 @@
|
||||
const extend = Java.extend
|
@ -358,3 +358,6 @@ const LiquidModule = Java.type('io.anuke.mindustry.world.modules.LiquidModule')
|
||||
const PowerModule = Java.type('io.anuke.mindustry.world.modules.PowerModule')
|
||||
const Produce = Java.type('io.anuke.mindustry.world.producers.Produce')
|
||||
const ProduceItem = Java.type('io.anuke.mindustry.world.producers.ProduceItem')
|
||||
|
||||
const extend = Java.extend
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -6,7 +6,10 @@ import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.mod.Mods.*;
|
||||
import org.graalvm.polyglot.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Scripts{
|
||||
private static final Class[] denied = {FileHandle.class, InputStream.class, File.class, Scripts.class, Files.class};
|
||||
private final Context context;
|
||||
private final String wrapper;
|
||||
|
||||
@ -15,11 +18,9 @@ public class Scripts{
|
||||
Context.Builder builder = Context.newBuilder("js").allowHostClassLookup(ClassAccess.allowedClassNames::contains);
|
||||
|
||||
HostAccess.Builder hb = HostAccess.newBuilder();
|
||||
for(Class c : ClassAccess.allowedClasses){
|
||||
hb.allowImplementations(c);
|
||||
Structs.each(hb::allowAccess, c.getConstructors());
|
||||
Structs.each(hb::allowAccess, c.getFields());
|
||||
Structs.each(hb::allowAccess, c.getMethods());
|
||||
hb.allowPublicAccess(true);
|
||||
for(Class c : denied){
|
||||
hb.denyAccess(c);
|
||||
}
|
||||
builder.allowHostAccess(hb.build());
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class ScriptStubGenerator{
|
||||
"import io.anuke.arc.collection.*;\n" +
|
||||
"//obviously autogenerated, do not touch\n" +
|
||||
"class ClassAccess{\n" +
|
||||
"\tstatic final Array<Class<?>> allowedClasses = Array.with($ALLOWED_CLASSES$);\n" +
|
||||
//"\tstatic final Array<Class<?>> allowedClasses = Array.with($ALLOWED_CLASSES$);\n" +
|
||||
"\tstatic final ObjectSet<String> allowedClassNames = ObjectSet.with($ALLOWED_CLASS_NAMES$);\n" +
|
||||
"}";
|
||||
|
||||
@ -50,6 +50,8 @@ public class ScriptStubGenerator{
|
||||
result.append("const ").append(type.getSimpleName()).append(" = ").append("Java.type('").append(type.getCanonicalName()).append("')\n");
|
||||
}
|
||||
|
||||
result.append("\n").append(new FileHandle("core/assets/scripts/base.js").readString()).append("\n");
|
||||
|
||||
//Log.info(result);
|
||||
|
||||
new FileHandle("core/assets/scripts/global.js").writeString(result.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user