Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)
Alex said that it wasn't possible when I asked him before.
package data.scripts.world;import sun.audio.*;import java.io.*;public class MusicPlayer { private String filename; public MusicPlayer(String filename) { this.filename = filename; } public void play() { try { InputStream in = new FileInputStream(filename); AudioStream as = new AudioStream(in); AudioPlayer.player.start(as); } catch (IOException e) { e.printStackTrace(); } }}
17665 [Thread-6] ERROR com.fs.starfarer.combat.String - java.lang.RuntimeException: Error compiling [data.scripts.world.MusicPlayer]java.lang.RuntimeException: Error compiling [data.scripts.world.MusicPlayer] at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source) at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.SecurityException: File access and reflection are not allowed to scripts. at com.fs.starfarer.loading.scripts.B.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:83) at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158) at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:124) at org.codehaus.janino.UnitCompiler.loadFullyQualifiedClass(UnitCompiler.java:8729) at org.codehaus.janino.UnitCompiler.importTypeOnDemand(UnitCompiler.java:7616) at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4574) at org.codehaus.janino.UnitCompiler.access$10300(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$17.visitReferenceType(UnitCompiler.java:4442) at org.codehaus.janino.Java$ReferenceType.accept(Java.java:2020) at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4476) at org.codehaus.janino.UnitCompiler.getLocalVariable(UnitCompiler.java:1607) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2226) at org.codehaus.janino.UnitCompiler.access$3700(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$7.visitLocalVariableDeclarationStatement(UnitCompiler.java:2141) at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:1771) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2158) at org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$7.visitBlock(UnitCompiler.java:2129) at org.codehaus.janino.Java$Block.accept(Java.java:1395) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2200) at org.codehaus.janino.UnitCompiler.access$3400(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$7.visitTryStatement(UnitCompiler.java:2136) at org.codehaus.janino.Java$TryStatement.accept(Java.java:1592) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144) at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2105) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1946) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:770) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:464) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357) at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312) at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288) at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:203) at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:157) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 2 more23616 [Thread-6] INFO com.fs.profiler.Profiler - ID Calls Duration Percent23617 [Thread-6] INFO com.fs.profiler.Profiler - --------------------------------
17267 [Thread-6] ERROR com.fs.starfarer.combat.String - java.lang.RuntimeException: Error compiling [data.scripts.world.Jawa]java.lang.RuntimeException: Error compiling [data.scripts.world.Jawa] at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source) at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.SecurityException: File access and reflection are not allowed to scripts. at com.fs.starfarer.loading.scripts.B.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:83) at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158) at org.codehaus.janino.ReflectionIClass.classToIClass(ReflectionIClass.java:305) at org.codehaus.janino.ReflectionIClass.classesToIClasses(ReflectionIClass.java:320) at org.codehaus.janino.ReflectionIClass.getInterfaces2(ReflectionIClass.java:116) at org.codehaus.janino.IClass.getInterfaces(IClass.java:361) at org.codehaus.janino.UnitCompiler.getIMethods(UnitCompiler.java:6637) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6575) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6488) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3429) at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$11.visitMethodInvocation(UnitCompiler.java:2869) at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2831) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2890) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3897) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1637) at org.codehaus.janino.UnitCompiler.access$1700(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$5.visitReturnStatement(UnitCompiler.java:877) at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:1803) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1740) at org.codehaus.janino.UnitCompiler.access$1200(UnitCompiler.java:104) at org.codehaus.janino.UnitCompiler$5.visitTryStatement(UnitCompiler.java:872) at org.codehaus.janino.Java$TryStatement.accept(Java.java:1592) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888) at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:914) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1999) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:493) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357) at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312) at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288) at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:203) at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:157) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 2 more19657 [Thread-6] INFO com.fs.profiler.Profiler - ID Calls Duration Percent19657 [Thread-6] INFO com.fs.profiler.Profiler - --------------------------------
Yeah, this isn't going to work - there are some security checks in place to try to ensure mods don't do something *really bad* - like accidentally deleting the contents of your hard drive.Nice try, though I'll see about adding a way for mods to get at files in a more sandboxed way in the future.
Im just curious, what kind of music will they eventually put in the game .. in the mean time.. I listen to imperial march loop