mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-06 08:18:13 +07:00
Removed script wrapper
This commit is contained in:
@ -2,6 +2,11 @@ const log = function(context, obj){
|
||||
Vars.mods.getScripts().log(context, obj ? String(obj) : "null")
|
||||
}
|
||||
|
||||
var scriptName = "base.js"
|
||||
var modName = "none"
|
||||
|
||||
const print = text => log(scriptName, text);
|
||||
|
||||
const extendContent = function(classType, name, params){
|
||||
return new JavaAdapter(classType, params, name)
|
||||
}
|
||||
|
@ -4,6 +4,11 @@ const log = function(context, obj){
|
||||
Vars.mods.getScripts().log(context, obj ? String(obj) : "null")
|
||||
}
|
||||
|
||||
var scriptName = "base.js"
|
||||
var modName = "none"
|
||||
|
||||
const print = text => log(scriptName, text);
|
||||
|
||||
const extendContent = function(classType, name, params){
|
||||
return new JavaAdapter(classType, params, name)
|
||||
}
|
||||
@ -20,61 +25,62 @@ const prov = method => new Prov(){get: method}
|
||||
const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer}))
|
||||
Call = Packages.mindustry.gen.Call
|
||||
const Calls = Call //backwards compat
|
||||
importPackage(Packages.arc)
|
||||
importPackage(Packages.arc.func)
|
||||
importPackage(Packages.arc.graphics)
|
||||
importPackage(Packages.arc.graphics.g2d)
|
||||
importPackage(Packages.arc.math)
|
||||
|
||||
importPackage(Packages.arc.math.geom)
|
||||
importPackage(Packages.arc.scene)
|
||||
importPackage(Packages.arc.scene.actions)
|
||||
importPackage(Packages.arc.scene.event)
|
||||
importPackage(Packages.arc.scene.style)
|
||||
importPackage(Packages.arc.scene.ui)
|
||||
importPackage(Packages.arc.scene.ui.layout)
|
||||
importPackage(Packages.arc.scene.utils)
|
||||
importPackage(Packages.arc.struct)
|
||||
importPackage(Packages.arc.util)
|
||||
importPackage(Packages.mindustry)
|
||||
importPackage(Packages.mindustry.ai)
|
||||
importPackage(Packages.mindustry.content)
|
||||
importPackage(Packages.mindustry.core)
|
||||
importPackage(Packages.mindustry.ctype)
|
||||
importPackage(Packages.mindustry.editor)
|
||||
importPackage(Packages.mindustry.entities)
|
||||
importPackage(Packages.mindustry.entities.bullet)
|
||||
importPackage(Packages.mindustry.entities.effect)
|
||||
importPackage(Packages.mindustry.entities.traits)
|
||||
importPackage(Packages.mindustry.entities.type)
|
||||
importPackage(Packages.mindustry.entities.type.base)
|
||||
importPackage(Packages.mindustry.entities.units)
|
||||
importPackage(Packages.mindustry.game)
|
||||
importPackage(Packages.mindustry.gen)
|
||||
importPackage(Packages.mindustry.graphics)
|
||||
importPackage(Packages.mindustry.input)
|
||||
importPackage(Packages.mindustry.maps)
|
||||
importPackage(Packages.mindustry.maps.filters)
|
||||
importPackage(Packages.mindustry.maps.generators)
|
||||
importPackage(Packages.mindustry.maps.zonegen)
|
||||
importPackage(Packages.mindustry.type)
|
||||
importPackage(Packages.mindustry.ui)
|
||||
importPackage(Packages.mindustry.ui.dialogs)
|
||||
importPackage(Packages.mindustry.ui.fragments)
|
||||
importPackage(Packages.mindustry.ui.layout)
|
||||
importPackage(Packages.mindustry.world)
|
||||
importPackage(Packages.mindustry.world.blocks)
|
||||
importPackage(Packages.mindustry.world.blocks.defense)
|
||||
importPackage(Packages.mindustry.world.blocks.defense.turrets)
|
||||
importPackage(Packages.mindustry.world.blocks.distribution)
|
||||
importPackage(Packages.mindustry.world.blocks.liquid)
|
||||
importPackage(Packages.mindustry.world.blocks.logic)
|
||||
importPackage(Packages.mindustry.world.blocks)
|
||||
importPackage(Packages.arc.scene.event)
|
||||
importPackage(Packages.arc.scene.actions)
|
||||
importPackage(Packages.mindustry.gen)
|
||||
importPackage(Packages.arc.struct)
|
||||
importPackage(Packages.mindustry.world.blocks.defense.turrets)
|
||||
importPackage(Packages.mindustry.game)
|
||||
importPackage(Packages.arc.graphics)
|
||||
importPackage(Packages.mindustry.ui.fragments)
|
||||
importPackage(Packages.mindustry.ui)
|
||||
importPackage(Packages.mindustry.world.blocks.power)
|
||||
importPackage(Packages.mindustry.world.blocks.production)
|
||||
importPackage(Packages.mindustry.world.blocks.sandbox)
|
||||
importPackage(Packages.mindustry.world.blocks.storage)
|
||||
importPackage(Packages.mindustry.world.blocks.units)
|
||||
importPackage(Packages.mindustry.world.consumers)
|
||||
importPackage(Packages.mindustry.entities.traits)
|
||||
importPackage(Packages.mindustry.entities.effect)
|
||||
importPackage(Packages.arc.math)
|
||||
importPackage(Packages.arc.scene.ui)
|
||||
importPackage(Packages.mindustry.world.blocks.defense)
|
||||
importPackage(Packages.mindustry.ctype)
|
||||
importPackage(Packages.mindustry.entities.type)
|
||||
importPackage(Packages.mindustry.world.meta)
|
||||
importPackage(Packages.arc.func)
|
||||
importPackage(Packages.mindustry.editor)
|
||||
importPackage(Packages.mindustry.entities.units)
|
||||
importPackage(Packages.mindustry.maps.filters)
|
||||
importPackage(Packages.mindustry.world)
|
||||
importPackage(Packages.arc.scene.utils)
|
||||
importPackage(Packages.mindustry.maps.generators)
|
||||
importPackage(Packages.mindustry.world.blocks.distribution)
|
||||
importPackage(Packages.mindustry.entities.bullet)
|
||||
importPackage(Packages.mindustry.content)
|
||||
importPackage(Packages.mindustry.world.meta.values)
|
||||
importPackage(Packages.mindustry.world.blocks.production)
|
||||
importPackage(Packages.arc)
|
||||
importPackage(Packages.mindustry.world.blocks.units)
|
||||
importPackage(Packages.mindustry.core)
|
||||
importPackage(Packages.mindustry.world.consumers)
|
||||
importPackage(Packages.mindustry.entities.type.base)
|
||||
importPackage(Packages.arc.scene.ui.layout)
|
||||
importPackage(Packages.mindustry.type)
|
||||
importPackage(Packages.mindustry.input)
|
||||
importPackage(Packages.mindustry.entities)
|
||||
importPackage(Packages.arc.scene.style)
|
||||
importPackage(Packages.mindustry.world.blocks.sandbox)
|
||||
importPackage(Packages.mindustry.ui.layout)
|
||||
importPackage(Packages.mindustry.maps.zonegen)
|
||||
importPackage(Packages.arc.graphics.g2d)
|
||||
importPackage(Packages.mindustry.ai)
|
||||
importPackage(Packages.mindustry.world.modules)
|
||||
importPackage(Packages.mindustry.world.blocks.storage)
|
||||
importPackage(Packages.arc.scene)
|
||||
importPackage(Packages.mindustry.maps)
|
||||
importPackage(Packages.mindustry.world.blocks.logic)
|
||||
importPackage(Packages.arc.util)
|
||||
importPackage(Packages.mindustry.world.producers)
|
||||
importPackage(Packages.mindustry)
|
||||
|
@ -1,10 +0,0 @@
|
||||
modName = "$MOD_NAME$"
|
||||
|
||||
!function(){
|
||||
|
||||
const scriptName = "$SCRIPT_NAME$"
|
||||
const print = text => log(scriptName, text);
|
||||
$CODE$
|
||||
|
||||
}();
|
||||
|
@ -21,10 +21,9 @@ public class Scripts implements Disposable{
|
||||
".awt", "socket", "classloader", "oracle", "invoke");
|
||||
private final Array<String> whitelist = Array.with("mindustry.net");
|
||||
private final Context context;
|
||||
private final String wrapper;
|
||||
private Scriptable scope;
|
||||
private boolean errored;
|
||||
private LoadedMod loadedMod = null;
|
||||
private LoadedMod currentMod = null;
|
||||
|
||||
public Scripts(){
|
||||
Time.mark();
|
||||
@ -38,7 +37,6 @@ public class Scripts implements Disposable{
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(new ScriptModuleProvider()))
|
||||
.setSandboxed(true).createRequire(context, scope).install(scope);
|
||||
wrapper = Core.files.internal("scripts/wrapper.js").readString();
|
||||
|
||||
if(!run(Core.files.internal("scripts/global.js").readString(), "global.js")){
|
||||
errored = true;
|
||||
@ -79,13 +77,17 @@ public class Scripts implements Disposable{
|
||||
}
|
||||
|
||||
public void run(LoadedMod mod, Fi file){
|
||||
loadedMod = mod;
|
||||
run(fillWrapper(file), file.name());
|
||||
loadedMod = null;
|
||||
currentMod = mod;
|
||||
run(file.readString(), file.name());
|
||||
currentMod = null;
|
||||
}
|
||||
|
||||
private boolean run(String script, String file){
|
||||
try{
|
||||
if(currentMod != null){
|
||||
//inject script info into file (TODO maybe rhino handles this?)
|
||||
context.evaluateString(scope, "modName = \"" + currentMod.name + "\"\nscriptName = \"" + file + "\"", "initscript.js", 1, null);
|
||||
}
|
||||
context.evaluateString(scope, script, file, 1, null);
|
||||
return true;
|
||||
}catch(Throwable t){
|
||||
@ -94,12 +96,6 @@ public class Scripts implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
private String fillWrapper(Fi file){
|
||||
return wrapper.replace("$SCRIPT_NAME$", loadedMod.name + "/" + file.nameWithoutExtension())
|
||||
.replace("$CODE$", file.readString())
|
||||
.replace("$MOD_NAME$", loadedMod.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
Context.exit();
|
||||
@ -114,8 +110,8 @@ public class Scripts implements Disposable{
|
||||
|
||||
@Override
|
||||
public ModuleSource loadSource(String moduleId, Scriptable paths, Object validator) throws IOException, URISyntaxException{
|
||||
if(loadedMod == null) return null;
|
||||
return loadSource(moduleId, loadedMod.root.child("scripts"), validator);
|
||||
if(currentMod == null) return null;
|
||||
return loadSource(moduleId, currentMod.root.child("scripts"), validator);
|
||||
}
|
||||
|
||||
private ModuleSource loadSource(String moduleId, Fi root, Object validator) throws URISyntaxException{
|
||||
@ -134,7 +130,7 @@ public class Scripts implements Disposable{
|
||||
Fi module = root.child(moduleId + ".js");
|
||||
if(!module.exists() || module.isDirectory()) return null;
|
||||
return new ModuleSource(
|
||||
new InputStreamReader(new ByteArrayInputStream((fillWrapper(module)).getBytes())),
|
||||
new InputStreamReader(new ByteArrayInputStream((module.readString()).getBytes())),
|
||||
null, new URI(moduleId), root.file().toURI(), validator);
|
||||
}
|
||||
}
|
||||
|
@ -30,13 +30,6 @@ public class ScriptStubGenerator{
|
||||
DataInputStream.class, DataOutputStream.class, Integer.class, Float.class, Double.class, Long.class, Boolean.class, Short.class, Byte.class, Character.class);
|
||||
Array<String> nopackage = Array.with("java.lang", "java");
|
||||
|
||||
String fileTemplate = "package mindustry.mod;\n" +
|
||||
"\nimport arc.struct.*;\n" +
|
||||
"//obviously autogenerated, do not touch\n" +
|
||||
"public class ClassAccess{\n" +
|
||||
"\tpublic static final ObjectSet<String> allowedClassNames = ObjectSet.with($ALLOWED_CLASS_NAMES$);\n" +
|
||||
"}";
|
||||
|
||||
List<ClassLoader> classLoadersList = new LinkedList<>();
|
||||
classLoadersList.add(ClasspathHelper.contextClassLoader());
|
||||
classLoadersList.add(ClasspathHelper.staticClassLoader());
|
||||
@ -73,8 +66,5 @@ public class ScriptStubGenerator{
|
||||
//Log.info(result);
|
||||
|
||||
new Fi("core/assets/scripts/global.js").writeString(result.toString());
|
||||
new Fi("core/src/mindustry/mod/ClassAccess.java").writeString(fileTemplate
|
||||
.replace("$ALLOWED_CLASSES$", classes.toString(", ", type -> type.getName() + ".class"))
|
||||
.replace("$ALLOWED_CLASS_NAMES$", classes.toString(", ", type -> "\"" + type.getName() + "\"")));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user