Search in sources :

Example 1 with InterfaceLoader

use of net.runelite.cache.definitions.loaders.InterfaceLoader 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 2 with InterfaceLoader

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

the class InterfaceSaverTest method testSave.

@Test
public void testSave() throws Exception {
    File base = StoreLocation.LOCATION;
    try (Store store = new Store(base)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.INTERFACES);
        Archive archive = index.getArchive(149);
        byte[] archiveData = storage.loadArchive(archive);
        ArchiveFiles files = archive.getFiles(archiveData);
        FSFile file = files.findFile(0);
        byte[] contents = file.getContents();
        InterfaceDefinition def = new InterfaceLoader().load(0, contents);
        byte[] b = new InterfaceSaver().save(def);
        assertArrayEquals(contents, b);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) InterfaceLoader(net.runelite.cache.definitions.loaders.InterfaceLoader) InterfaceDefinition(net.runelite.cache.definitions.InterfaceDefinition) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) FSFile(net.runelite.cache.fs.FSFile) Test(org.junit.Test)

Aggregations

InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)2 InterfaceLoader (net.runelite.cache.definitions.loaders.InterfaceLoader)2 Archive (net.runelite.cache.fs.Archive)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 FSFile (net.runelite.cache.fs.FSFile)2 Index (net.runelite.cache.fs.Index)2 Storage (net.runelite.cache.fs.Storage)2 File (java.io.File)1 Store (net.runelite.cache.fs.Store)1 Test (org.junit.Test)1