Search in sources :

Example 1 with InterfaceDefinition

use of net.runelite.cache.definitions.InterfaceDefinition in project runelite by runelite.

the class InterfaceManager method export.

public void export(File out) throws IOException {
    out.mkdirs();
    for (InterfaceDefinition[] defs : interfaces) {
        if (defs == null) {
            continue;
        }
        for (InterfaceDefinition def : defs) {
            if (def == null) {
                continue;
            }
            InterfaceExporter exporter = new InterfaceExporter(def);
            File folder = new File(out, "" + (def.id >>> 16));
            folder.mkdirs();
            File targ = new File(folder, (def.id & 0xffff) + ".json");
            exporter.exportTo(targ);
        }
    }
}
Also used : InterfaceDefinition(net.runelite.cache.definitions.InterfaceDefinition) InterfaceExporter(net.runelite.cache.definitions.exporters.InterfaceExporter) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile)

Example 2 with InterfaceDefinition

use of net.runelite.cache.definitions.InterfaceDefinition in project runelite by runelite.

the class InterfaceManager method java.

public void java(File java) throws IOException {
    System.setProperty("line.separator", "\n");
    java.mkdirs();
    File targ = new File(java, "InterfaceID.java");
    try (PrintWriter fw = new PrintWriter(targ)) {
        fw.println("/* This file is automatically generated. Do not edit. */");
        fw.println("package net.runelite.api;");
        fw.println("");
        fw.println("public final class InterfaceID {");
        for (InterfaceDefinition[] defs : interfaces) {
            if (defs == null) {
                continue;
            }
            for (InterfaceDefinition def : defs) {
                if (def == null || def.name == null || def.name.equalsIgnoreCase("NULL")) {
                    continue;
                }
                String name = namer.name(def.name, def.id);
                if (name == null) {
                    continue;
                }
                fw.println("	public static final int " + name + " = " + def.id + ";");
            }
        }
        fw.println("}");
    }
}
Also used : InterfaceDefinition(net.runelite.cache.definitions.InterfaceDefinition) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) PrintWriter(java.io.PrintWriter)

Example 3 with InterfaceDefinition

use of net.runelite.cache.definitions.InterfaceDefinition 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 InterfaceDefinition

use of net.runelite.cache.definitions.InterfaceDefinition in project runelite by runelite.

the class InterfaceLoader method load.

public InterfaceDefinition load(int id, byte[] b) {
    InterfaceDefinition iface = new InterfaceDefinition();
    iface.id = id;
    if (b[0] == -1) {
        method3252(iface, new InputStream(b));
    } else {
        method3251(iface, new InputStream(b));
    }
    return iface;
}
Also used : InputStream(net.runelite.cache.io.InputStream) InterfaceDefinition(net.runelite.cache.definitions.InterfaceDefinition)

Example 5 with InterfaceDefinition

use of net.runelite.cache.definitions.InterfaceDefinition 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)5 FSFile (net.runelite.cache.fs.FSFile)4 File (java.io.File)3 InterfaceLoader (net.runelite.cache.definitions.loaders.InterfaceLoader)2 Archive (net.runelite.cache.fs.Archive)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 Index (net.runelite.cache.fs.Index)2 Storage (net.runelite.cache.fs.Storage)2 PrintWriter (java.io.PrintWriter)1 InterfaceExporter (net.runelite.cache.definitions.exporters.InterfaceExporter)1 Store (net.runelite.cache.fs.Store)1 InputStream (net.runelite.cache.io.InputStream)1 Test (org.junit.Test)1