Search in sources :

Example 6 with ArchiveFiles

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

the class CacheController method getItemImage.

@RequestMapping(path = "item/{itemId}/image", produces = "image/png")
public ResponseEntity<byte[]> getItemImage(@PathVariable int itemId, @RequestParam(defaultValue = "1") int quantity, @RequestParam(defaultValue = "1") int border, @RequestParam(defaultValue = "3153952") int shadowColor) throws IOException {
    final CacheEntry cache = cacheService.findMostRecent();
    ItemProvider itemProvider = new ItemProvider() {

        @Override
        public ItemDefinition provide(int itemId) {
            try {
                return getItem(itemId);
            } catch (IOException ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    ModelProvider modelProvider = new ModelProvider() {

        @Override
        public ModelDefinition provide(int modelId) throws IOException {
            IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.MODELS.getNumber());
            ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, modelId);
            byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
            return new ModelLoader().load(modelId, archiveData);
        }
    };
    SpriteProvider spriteProvider = new SpriteProvider() {

        @Override
        public SpriteDefinition provide(int spriteId, int frameId) {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, spriteId);
                byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
                SpriteDefinition[] defs = new SpriteLoader().load(spriteId, archiveData);
                return defs[frameId];
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    TextureProvider textureProvider2 = new TextureProvider() {

        @Override
        public TextureDefinition[] provide() {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.TEXTURES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, 0);
                ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
                TextureLoader loader = new TextureLoader();
                TextureDefinition[] defs = new TextureDefinition[archiveFiles.getFiles().size()];
                int i = 0;
                for (FSFile file : archiveFiles.getFiles()) {
                    TextureDefinition def = loader.load(file.getFileId(), file.getContents());
                    defs[i++] = def;
                }
                return defs;
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    BufferedImage itemImage = ItemSpriteFactory.createSprite(itemProvider, modelProvider, spriteProvider, textureProvider2, itemId, quantity, border, shadowColor, false);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    ImageIO.write(itemImage, "png", bao);
    return ResponseEntity.ok(bao.toByteArray());
}
Also used : ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) IOException(java.io.IOException) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) BufferedImage(java.awt.image.BufferedImage) FSFile(net.runelite.cache.fs.FSFile) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ArchiveFiles

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

the class SpriteService method getSprite.

public SpriteDefinition getSprite(int spriteId, int frameId) throws IOException {
    CacheEntry cache = cacheService.findMostRecent();
    if (cache == null) {
        return null;
    }
    IndexEntry index = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber());
    if (index == null) {
        return null;
    }
    ArchiveEntry archive = cacheService.findArchiveForIndex(index, spriteId);
    if (archive == null) {
        return null;
    }
    ArchiveFiles files = cacheService.getArchiveFiles(archive);
    if (files == null) {
        return null;
    }
    FSFile file = files.getFiles().get(0);
    byte[] contents = file.getContents();
    SpriteDefinition[] sprite = new SpriteLoader().load(archive.getArchiveId(), contents);
    if (frameId < 0 || frameId >= sprite.length) {
        return null;
    }
    return sprite[frameId];
}
Also used : ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) FSFile(net.runelite.cache.fs.FSFile)

Example 8 with ArchiveFiles

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

Example 9 with ArchiveFiles

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

the class VarbitDumper 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.VARBIT.getId());
        byte[] archiveData = storage.loadArchive(archive);
        ArchiveFiles files = archive.getFiles(archiveData);
        for (FSFile file : files.getFiles()) {
            VarbitLoader loader = new VarbitLoader();
            VarbitDefinition varbit = loader.load(file.getFileId(), file.getContents());
            Files.write(gson.toJson(varbit), new File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} varbits to {}", count, outDir);
}
Also used : VarbitDefinition(net.runelite.cache.definitions.VarbitDefinition) Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) VarbitLoader(net.runelite.cache.definitions.loaders.VarbitLoader) FSFile(net.runelite.cache.fs.FSFile) Test(org.junit.Test)

Example 10 with ArchiveFiles

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

the class WorldMapDumperTest 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.WORLDMAP);
        // there is also archive 1/2, but their data format is not this
        Archive archive = index.getArchive(0);
        byte[] archiveData = storage.loadArchive(archive);
        ArchiveFiles files = archive.getFiles(archiveData);
        for (FSFile file : files.getFiles()) {
            WorldMapLoader loader = new WorldMapLoader();
            WorldMapDefinition def = loader.load(file.getContents(), file.getFileId());
            Files.write(gson.toJson(def), new File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} world map data to {}", count, outDir);
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) WorldMapDefinition(net.runelite.cache.definitions.WorldMapDefinition) 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) WorldMapLoader(net.runelite.cache.definitions.loaders.WorldMapLoader) Test(org.junit.Test)

Aggregations

ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)24 FSFile (net.runelite.cache.fs.FSFile)24 Archive (net.runelite.cache.fs.Archive)18 Index (net.runelite.cache.fs.Index)18 Storage (net.runelite.cache.fs.Storage)18 File (java.io.File)9 Store (net.runelite.cache.fs.Store)9 Test (org.junit.Test)9 ArchiveEntry (net.runelite.http.service.cache.beans.ArchiveEntry)5 NotFoundException (net.runelite.http.service.util.exception.NotFoundException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)2 InventoryDefinition (net.runelite.cache.definitions.InventoryDefinition)2 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)2 NpcDefinition (net.runelite.cache.definitions.NpcDefinition)2 ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)2 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)2 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)2 TextureDefinition (net.runelite.cache.definitions.TextureDefinition)2 UnderlayDefinition (net.runelite.cache.definitions.UnderlayDefinition)2