Search in sources :

Example 1 with ScriptSaver

use of net.runelite.cache.definitions.savers.ScriptSaver in project runelite by runelite.

the class AssembleMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    RuneLiteInstructions instructions = new RuneLiteInstructions();
    instructions.init();
    Assembler assembler = new Assembler(instructions);
    ScriptSaver saver = new ScriptSaver();
    int count = 0;
    File scriptOut = new File(outputDirectory, Integer.toString(IndexType.CLIENTSCRIPT.getNumber()));
    scriptOut.mkdirs();
    for (File scriptFile : scriptDirectory.listFiles((dir, name) -> name.endsWith(".rs2asm"))) {
        log.debug("Assembling " + scriptFile);
        try (FileInputStream fin = new FileInputStream(scriptFile)) {
            ScriptDefinition script = assembler.assemble(fin);
            byte[] packedScript = saver.save(script);
            File targetFile = new File(scriptOut, Integer.toString(script.getId()));
            Files.write(packedScript, targetFile);
            // Copy hash file
            File hashFile = new File(scriptDirectory, Files.getNameWithoutExtension(scriptFile.getName()) + ".hash");
            if (hashFile.exists()) {
                Files.copy(hashFile, new File(scriptOut, Integer.toString(script.getId()) + ".hash"));
            } else if (// Scripts >=10000 are RuneLite scripts, so they shouldn't have a .hash
            script.getId() < 10000) {
                throw new MojoExecutionException("Unable to find hash file for " + scriptFile);
            }
            ++count;
        } catch (IOException ex) {
            throw new MojoFailureException("unable to open file", ex);
        }
    }
    log.info("Assembled " + count + " scripts");
}
Also used : ScriptDefinition(net.runelite.cache.definitions.ScriptDefinition) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ScriptSaver(net.runelite.cache.definitions.savers.ScriptSaver) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Assembler(net.runelite.cache.script.assembler.Assembler) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ScriptDefinition (net.runelite.cache.definitions.ScriptDefinition)1 ScriptSaver (net.runelite.cache.definitions.savers.ScriptSaver)1 Assembler (net.runelite.cache.script.assembler.Assembler)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1