Search in sources :

Example 1 with Assembler

use of net.runelite.cache.script.assembler.Assembler 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)

Example 2 with Assembler

use of net.runelite.cache.script.assembler.Assembler in project runelite by runelite.

the class ScriptSaverTest method testSave.

@Test
public void testSave() throws IOException {
    Instructions instructions = new Instructions();
    instructions.init();
    ScriptDefinition script = new Assembler(instructions).assemble(getClass().getResourceAsStream(SCRIPT_RESOURCE));
    byte[] saved = new ScriptSaver().save(script);
    ScriptDefinition loadedScripot = new ScriptLoader().load(42, saved);
    assertEquals(script, loadedScripot);
}
Also used : ScriptDefinition(net.runelite.cache.definitions.ScriptDefinition) Instructions(net.runelite.cache.script.Instructions) Assembler(net.runelite.cache.script.assembler.Assembler) ScriptLoader(net.runelite.cache.definitions.loaders.ScriptLoader) Test(org.junit.Test)

Aggregations

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