Search in sources :

Example 1 with ScriptLoader

use of net.runelite.cache.definitions.loaders.ScriptLoader in project runelite by runelite.

the class DisassemblerTest method test.

@Test
public void test() throws IOException {
    File outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(StoreLocation.LOCATION)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.CLIENTSCRIPT);
        ScriptLoader loader = new ScriptLoader();
        for (Archive archive : index.getArchives()) {
            byte[] contents = archive.decompress(storage.loadArchive(archive));
            if (contents == null) {
                continue;
            }
            ScriptDefinition script = loader.load(0, contents);
            File outFile = new File(outDir, archive.getArchiveId() + ".rs2asm");
            Disassembler disassembler = new Disassembler();
            String out = disassembler.disassemble(script);
            Files.write(out.getBytes(), outFile);
            ++count;
        }
    }
    logger.info("Dumped {} scripts to {}", count, outDir);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ScriptDefinition(net.runelite.cache.definitions.ScriptDefinition) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) ScriptLoader(net.runelite.cache.definitions.loaders.ScriptLoader) Test(org.junit.Test)

Example 2 with ScriptLoader

use of net.runelite.cache.definitions.loaders.ScriptLoader 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 ScriptLoader (net.runelite.cache.definitions.loaders.ScriptLoader)2 Test (org.junit.Test)2 File (java.io.File)1 Archive (net.runelite.cache.fs.Archive)1 Index (net.runelite.cache.fs.Index)1 Storage (net.runelite.cache.fs.Storage)1 Store (net.runelite.cache.fs.Store)1 Instructions (net.runelite.cache.script.Instructions)1 Assembler (net.runelite.cache.script.assembler.Assembler)1