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");
}
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);
}
Aggregations