Search in sources :

Example 31 with Archive

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

the class DiskStorageTest method testSaveArchive.

@Test
public void testSaveArchive() throws Exception {
    File file = folder.newFolder();
    DiskStorage storage = new DiskStorage(file);
    Archive archive;
    Archive archive2;
    try (Store store = new Store(storage)) {
        Index index = store.addIndex(0);
        archive = index.addArchive(0);
        archive2 = index.addArchive(1);
        FileData[] fileData = new FileData[1];
        archive.setFileData(fileData);
        fileData[0] = new FileData();
        FileData[] fileData2 = new FileData[1];
        archive2.setFileData(fileData2);
        fileData2[0] = new FileData();
        byte[] data = "test".getBytes();
        Container container = new Container(archive.getCompression(), -1);
        container.compress(data, null);
        byte[] compressedData = container.data;
        storage.saveArchive(archive, compressedData);
        container = new Container(archive.getCompression(), 42);
        container.compress(data, null);
        compressedData = container.data;
        archive2.setRevision(42);
        storage.saveArchive(archive2, compressedData);
        store.save();
    }
    storage = new DiskStorage(file);
    try (Store store = new Store(storage)) {
        store.load();
        Index index = store.findIndex(0);
        Archive archive2_1 = index.getArchive(0);
        Archive archive2_2 = index.getArchive(1);
        byte[] comprsesedData = storage.loadArchive(archive2_1);
        byte[] data = archive2_1.decompress(comprsesedData);
        assertArrayEquals("test".getBytes(), data);
        assertEquals(archive.getCrc(), archive2_1.getCrc());
        assertEquals(archive.getRevision(), archive2_1.getRevision());
        comprsesedData = storage.loadArchive(archive2_2);
        data = archive2_2.decompress(comprsesedData);
        assertArrayEquals("test".getBytes(), data);
        assertEquals(archive2.getCrc(), archive2_2.getCrc());
        assertEquals(archive2.getRevision(), archive2_2.getRevision());
    }
}
Also used : Container(net.runelite.cache.fs.Container) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Example 32 with Archive

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

the class ItemManager method load.

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

Example 33 with Archive

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

the class MapImageDumper method loadUnderlays.

private void loadUnderlays(Store store) throws IOException {
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.CONFIGS);
    Archive archive = index.getArchive(ConfigType.UNDERLAY.getId());
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    for (FSFile file : files.getFiles()) {
        UnderlayLoader loader = new UnderlayLoader();
        UnderlayDefinition underlay = loader.load(file.getFileId(), file.getContents());
        underlays.put(underlay.getId(), underlay);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) Index(net.runelite.cache.fs.Index) UnderlayLoader(net.runelite.cache.definitions.loaders.UnderlayLoader) FSFile(net.runelite.cache.fs.FSFile)

Example 34 with Archive

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

the class MapImageDumper method loadOverlays.

private void loadOverlays(Store store) throws IOException {
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.CONFIGS);
    Archive archive = index.getArchive(ConfigType.OVERLAY.getId());
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    for (FSFile file : files.getFiles()) {
        OverlayLoader loader = new OverlayLoader();
        OverlayDefinition overlay = loader.load(file.getFileId(), file.getContents());
        overlays.put(overlay.getId(), overlay);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) Index(net.runelite.cache.fs.Index) OverlayLoader(net.runelite.cache.definitions.loaders.OverlayLoader) FSFile(net.runelite.cache.fs.FSFile)

Example 35 with Archive

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

the class MapImageDumper method loadSprites.

private void loadSprites() throws IOException {
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.SPRITES);
    final int mapsceneHash = Djb2.hash("mapscene");
    for (Archive a : index.getArchives()) {
        byte[] contents = a.decompress(storage.loadArchive(a));
        SpriteLoader loader = new SpriteLoader();
        SpriteDefinition[] sprites = loader.load(a.getArchiveId(), contents);
        for (SpriteDefinition sprite : sprites) {
            if (sprite.getHeight() <= 0 || sprite.getWidth() <= 0) {
                continue;
            }
            if (a.getNameHash() == mapsceneHash) {
                BufferedImage spriteImage = new BufferedImage(sprite.getWidth(), sprite.getHeight(), BufferedImage.TYPE_INT_ARGB);
                spriteImage.setRGB(0, 0, sprite.getWidth(), sprite.getHeight(), sprite.getPixels(), 0, sprite.getWidth());
                // scale image down so it fits
                Image scaledImage = spriteImage.getScaledInstance(MAPICON_MAX_WIDTH, MAPICON_MAX_HEIGHT, 0);
                assert scaledMapIcons.containsKey(sprite.getFrame()) == false;
                scaledMapIcons.put(sprite.getFrame(), scaledImage);
            }
        }
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) Index(net.runelite.cache.fs.Index) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

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