Search in sources :

Example 16 with Index

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

the class TrackDumperTest method test.

@Test
public void test() throws IOException {
    File dumpDir1 = folder.newFolder(), dumpDir2 = folder.newFolder();
    int idx1 = 0, idx2 = 0;
    djb2.load();
    try (Store store = new Store(StoreLocation.LOCATION)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.TRACK1);
        Index index2 = store.getIndex(IndexType.TRACK2);
        for (Archive archive : index.getArchives()) {
            dumpTrackArchive(dumpDir1, storage, archive);
            ++idx1;
        }
        for (Archive archive : index2.getArchives()) {
            dumpTrackArchive(dumpDir2, storage, archive);
            ++idx2;
        }
    }
    logger.info("Dumped {} sound tracks ({} idx1, {} idx2) to {} and {}", idx1 + idx2, idx1, idx2, dumpDir1, dumpDir2);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) Test(org.junit.Test)

Example 17 with Index

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

the class DiskStorage method loadArchive.

@Override
public byte[] loadArchive(Archive archive) throws IOException {
    Index index = archive.getIndex();
    IndexFile indexFile = getIndex(index.getId());
    assert indexFile.getIndexFileId() == index.getId();
    IndexEntry entry = indexFile.read(archive.getArchiveId());
    if (entry == null) {
        logger.debug("can't read archive " + archive.getArchiveId() + " from index " + index.getId());
        return null;
    }
    assert entry.getId() == archive.getArchiveId();
    logger.trace("Loading archive {} for index {} from sector {} length {}", archive.getArchiveId(), index.getId(), entry.getSector(), entry.getLength());
    byte[] archiveData = data.read(index.getId(), entry.getId(), entry.getSector(), entry.getLength());
    return archiveData;
}
Also used : Index(net.runelite.cache.fs.Index)

Example 18 with Index

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

the class DiskStorage method saveArchive.

@Override
public void saveArchive(Archive a, byte[] archiveData) throws IOException {
    Index index = a.getIndex();
    IndexFile indexFile = getIndex(index.getId());
    assert indexFile.getIndexFileId() == index.getId();
    DataFileWriteResult res = data.write(index.getId(), a.getArchiveId(), archiveData);
    indexFile.write(new IndexEntry(indexFile, a.getArchiveId(), res.sector, res.compressedLength));
    byte compression = archiveData[0];
    int compressedSize = Ints.fromBytes(archiveData[1], archiveData[2], archiveData[3], archiveData[4]);
    // don't crc the appended revision, if it is there
    int length = // compression type
    1 + // compressed size
    4 + compressedSize + (compression != CompressionType.NONE ? 4 : 0);
    Crc32 crc = new Crc32();
    crc.update(archiveData, 0, length);
    a.setCrc(crc.getHash());
    logger.trace("Saved archive {}/{} at sector {}, compressed length {}", index.getId(), a.getArchiveId(), res.sector, res.compressedLength);
}
Also used : Crc32(net.runelite.cache.util.Crc32) Index(net.runelite.cache.fs.Index)

Example 19 with Index

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

the class TitleDumper method extract.

@Test
public void extract() throws IOException {
    File base = StoreLocation.LOCATION, outFile = folder.newFolder();
    try (Store store = new Store(base)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.BINARY);
        Archive archive = index.findArchiveByName("title.jpg");
        byte[] contents = archive.decompress(storage.loadArchive(archive));
        Files.write(outFile.toPath(), contents);
    }
    logger.info("Dumped to {}", outFile);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) Test(org.junit.Test)

Example 20 with Index

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

the class UnderlayDumper method extract.

@Test
public void extract() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        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());
            Files.write(gson.toJson(underlay), new File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} underlays to {}", count, outDir);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) Store(net.runelite.cache.fs.Store) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) Index(net.runelite.cache.fs.Index) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) UnderlayLoader(net.runelite.cache.definitions.loaders.UnderlayLoader) FSFile(net.runelite.cache.fs.FSFile) Test(org.junit.Test)

Aggregations

Index (net.runelite.cache.fs.Index)41 Archive (net.runelite.cache.fs.Archive)38 Storage (net.runelite.cache.fs.Storage)33 Store (net.runelite.cache.fs.Store)20 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)5 FileData (net.runelite.cache.index.FileData)4 ByteBuf (io.netty.buffer.ByteBuf)2 BufferedImage (java.awt.image.BufferedImage)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 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