Search in sources :

Example 1 with Archive

use of net.runelite.cache.fs.Archive in project ostracker by OSTracker.

the class RemoteCache method download.

public void download(Store store) throws IOException, ExecutionException, InterruptedException {
    FileResult indicesFile = downloadFile(255, 255);
    ByteBuf buffer = Unpooled.wrappedBuffer(indicesFile.getContents());
    int indexCount = indicesFile.getContents().length / 8;
    for (int i = 0; i < indexCount; i++) {
        int crc = buffer.readInt();
        int revision = buffer.readInt();
        Index index = store.findIndex(i);
        if (index == null) {
            LOGGER.info("Index " + i + " does not exist locally, downloading..");
        } else if (index.getRevision() != revision) {
            LOGGER.info(MessageFormat.format("Index {0} has the wrong revision (local: {1}, remote: {2})", i, index.getRevision(), revision));
        } else {
            LOGGER.info("Index " + i + " is up to date");
            continue;
        }
        LOGGER.info("Downloading index " + i);
        FileResult indexFile = downloadFile(255, i);
        LOGGER.info("Done downloading index " + i);
        if (indexFile.getCrc() != crc) {
            LOGGER.error("Crc mismatch between downloaded file and expected checksum for index " + i);
            continue;
        }
        Index oldIndex = null;
        if (index != null) {
            store.removeIndex(index);
            oldIndex = index;
        }
        index = store.addIndex(i);
        index.readIndexData(indexFile.getContents());
        index.setCrc(crc);
        LOGGER.info("Index " + i + " has " + index.getArchives().size() + " archives");
        for (Archive archive : index.getArchives()) {
            Archive oldArchive = null;
            if (oldIndex != null) {
                oldArchive = oldIndex.getArchive(archive.getArchiveId());
            }
            if (oldArchive == null || oldArchive.getRevision() != archive.getRevision()) {
                LOGGER.info(MessageFormat.format("Archive {0} in index {1} is out of date, downloading..", archive.getArchiveId(), i));
                FileResult archiveFile = downloadFile(i, archive.getArchiveId(), false);
                archive.setData(archiveFile.getCompressedData());
            } else {
                LOGGER.info(MessageFormat.format("Archive {0} in index {1} is up to date", archive.getArchiveId(), i));
                if (oldArchive.getData() != null) {
                    archive.setData(oldArchive.getData());
                } else {
                    archive.loadContents(oldArchive.saveContents());
                    archive.setCompression(oldArchive.getCompression());
                }
            }
        }
    }
}
Also used : Archive(net.runelite.cache.fs.Archive) FileResult(net.runelite.cache.downloader.FileResult) Index(net.runelite.cache.fs.Index) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with Archive

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

the class ItemSpriteFactoryTest method test.

@Test
@Ignore
public void test() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        ItemManager itemManager = new ItemManager(store);
        itemManager.load();
        ModelProvider modelProvider = new ModelProvider() {

            @Override
            public ModelDefinition provide(int modelId) throws IOException {
                Index models = store.getIndex(IndexType.MODELS);
                Archive archive = models.getArchive(modelId);
                byte[] data = archive.decompress(store.getStorage().loadArchive(archive));
                ModelDefinition inventoryModel = new ModelLoader().load(modelId, data);
                return inventoryModel;
            }
        };
        SpriteManager spriteManager = new SpriteManager(store);
        spriteManager.load();
        TextureManager textureManager = new TextureManager(store);
        textureManager.load();
        for (ItemDefinition itemDef : itemManager.getItems()) {
            if (itemDef.name == null || itemDef.name.equalsIgnoreCase("null")) {
                continue;
            }
            try {
                BufferedImage sprite = ItemSpriteFactory.createSprite(itemManager, modelProvider, spriteManager, textureManager, itemDef.id, 1, 1, 3153952, false);
                File out = new File(outDir, itemDef.id + ".png");
                BufferedImage img = sprite;
                ImageIO.write(img, "PNG", out);
                ++count;
            } catch (Exception ex) {
                log.warn("error dumping item {}", itemDef.id, ex);
            }
        }
    }
    log.info("Dumped {} item images to {}", count, outDir);
}
Also used : Archive(net.runelite.cache.fs.Archive) ItemManager(net.runelite.cache.ItemManager) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) SpriteManager(net.runelite.cache.SpriteManager) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) TextureManager(net.runelite.cache.TextureManager) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Archive

use of net.runelite.cache.fs.Archive 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 4 with Archive

use of net.runelite.cache.fs.Archive 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 5 with Archive

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

Aggregations

Archive (net.runelite.cache.fs.Archive)41 Index (net.runelite.cache.fs.Index)38 Storage (net.runelite.cache.fs.Storage)34 Store (net.runelite.cache.fs.Store)21 File (java.io.File)19 Test (org.junit.Test)19 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)18 FSFile (net.runelite.cache.fs.FSFile)18 IOException (java.io.IOException)6 FileData (net.runelite.cache.index.FileData)4 Container (net.runelite.cache.fs.Container)3 BufferedImage (java.awt.image.BufferedImage)2 CacheClient (net.runelite.cache.client.CacheClient)2 FramemapDefinition (net.runelite.cache.definitions.FramemapDefinition)2 InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)2 InventoryDefinition (net.runelite.cache.definitions.InventoryDefinition)2 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)2 LocationsDefinition (net.runelite.cache.definitions.LocationsDefinition)2 MapDefinition (net.runelite.cache.definitions.MapDefinition)2 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)2