Search in sources :

Example 1 with Storage

use of net.runelite.cache.fs.Storage 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 Storage

use of net.runelite.cache.fs.Storage in project runelite by runelite.

the class InventoryManager method load.

public void load() throws IOException {
    InventoryLoader loader = new InventoryLoader();
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.CONFIGS);
    Archive archive = index.getArchive(ConfigType.INV.getId());
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    for (FSFile file : files.getFiles()) {
        InventoryDefinition inv = loader.load(file.getFileId(), file.getContents());
        inventories.add(inv);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) Index(net.runelite.cache.fs.Index) InventoryLoader(net.runelite.cache.definitions.loaders.InventoryLoader) InventoryDefinition(net.runelite.cache.definitions.InventoryDefinition) FSFile(net.runelite.cache.fs.FSFile)

Example 3 with Storage

use of net.runelite.cache.fs.Storage in project runelite by runelite.

the class InterfaceManager method load.

public void load() throws IOException {
    InterfaceLoader loader = new InterfaceLoader();
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.INTERFACES);
    int max = index.getArchives().stream().mapToInt(a -> a.getArchiveId()).max().getAsInt();
    interfaces = new InterfaceDefinition[max + 1][];
    for (Archive archive : index.getArchives()) {
        int archiveId = archive.getArchiveId();
        byte[] archiveData = storage.loadArchive(archive);
        ArchiveFiles files = archive.getFiles(archiveData);
        InterfaceDefinition[] ifaces = interfaces[archiveId];
        if (ifaces == null) {
            ifaces = interfaces[archiveId] = new InterfaceDefinition[archive.getFileData().length];
        }
        for (FSFile file : files.getFiles()) {
            int fileId = file.getFileId();
            int widgetId = (archiveId << 16) + fileId;
            InterfaceDefinition iface = loader.load(widgetId, file.getContents());
            ifaces[fileId] = iface;
        }
    }
}
Also used : InterfaceLoader(net.runelite.cache.definitions.loaders.InterfaceLoader) Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) InterfaceDefinition(net.runelite.cache.definitions.InterfaceDefinition) Index(net.runelite.cache.fs.Index) FSFile(net.runelite.cache.fs.FSFile)

Example 4 with Storage

use of net.runelite.cache.fs.Storage in project runelite by runelite.

the class NpcManager method load.

public void load() throws IOException {
    NpcLoader loader = new NpcLoader();
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.CONFIGS);
    Archive archive = index.getArchive(ConfigType.NPC.getId());
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    for (FSFile f : files.getFiles()) {
        NpcDefinition npc = loader.load(f.getFileId(), f.getContents());
        npcs.add(npc);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) NpcLoader(net.runelite.cache.definitions.loaders.NpcLoader) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) Index(net.runelite.cache.fs.Index) FSFile(net.runelite.cache.fs.FSFile)

Example 5 with Storage

use of net.runelite.cache.fs.Storage in project runelite by runelite.

the class ArchiveRequestHandler method handleRequest.

private void handleRequest(ChannelHandlerContext ctx, int index, int archiveId) throws IOException {
    logger.info("Client {} requests index {} archive {}", ctx.channel().remoteAddress(), index, archiveId);
    Index i = store.findIndex(index);
    assert i != null;
    Archive archive = i.getArchive(archiveId);
    assert archive != null;
    Storage storage = store.getStorage();
    // is compressed, includes length and type
    byte[] packed = storage.loadArchive(archive);
    if (packed == null) {
        logger.warn("Missing archive {}/{}", index, archiveId);
        // is it possible to notify the client of an error with this?
        return;
    }
    byte compression = packed[0];
    int compressedSize = Ints.fromBytes(packed[1], packed[2], packed[3], packed[4]);
    // size the client expects the data to be
    int expectedSize = // compression type
    1 + // compressed size
    4 + compressedSize + (compression != CompressionType.NONE ? 4 : 0);
    if (packed.length != expectedSize) {
        // the update server will never have it
        assert packed.length - expectedSize == 2 : "packed length != expected size";
        packed = Arrays.copyOf(packed, packed.length - 2);
    }
    ArchiveResponsePacket response = new ArchiveResponsePacket();
    response.setIndex(index);
    response.setArchive(archiveId);
    response.setData(packed);
    ctx.writeAndFlush(response);
}
Also used : Archive(net.runelite.cache.fs.Archive) Storage(net.runelite.cache.fs.Storage) DiskStorage(net.runelite.cache.fs.jagex.DiskStorage) Index(net.runelite.cache.fs.Index) ArchiveResponsePacket(net.runelite.protocol.api.update.ArchiveResponsePacket)

Aggregations

Archive (net.runelite.cache.fs.Archive)34 Storage (net.runelite.cache.fs.Storage)34 Index (net.runelite.cache.fs.Index)33 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)18 FSFile (net.runelite.cache.fs.FSFile)18 Store (net.runelite.cache.fs.Store)18 File (java.io.File)17 Test (org.junit.Test)17 IOException (java.io.IOException)4 FramemapDefinition (net.runelite.cache.definitions.FramemapDefinition)2 InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)2 InventoryDefinition (net.runelite.cache.definitions.InventoryDefinition)2 LocationsDefinition (net.runelite.cache.definitions.LocationsDefinition)2 MapDefinition (net.runelite.cache.definitions.MapDefinition)2 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)2 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)2 UnderlayDefinition (net.runelite.cache.definitions.UnderlayDefinition)2 FramemapLoader (net.runelite.cache.definitions.loaders.FramemapLoader)2 InterfaceLoader (net.runelite.cache.definitions.loaders.InterfaceLoader)2 InventoryLoader (net.runelite.cache.definitions.loaders.InventoryLoader)2