Search in sources :

Example 1 with ArchiveEntry

use of net.runelite.http.service.cache.beans.ArchiveEntry 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 2 with ArchiveEntry

use of net.runelite.http.service.cache.beans.ArchiveEntry in project runelite by runelite.

the class CacheController method listArchives.

@RequestMapping("{cacheId}/{indexId}")
public List<CacheArchive> listArchives(@PathVariable int cacheId, @PathVariable int indexId) {
    CacheEntry cache = cacheService.findCache(cacheId);
    if (cache == null) {
        throw new NotFoundException();
    }
    IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId);
    if (indexEntry == null) {
        throw new NotFoundException();
    }
    List<ArchiveEntry> archives = cacheService.findArchivesForIndex(indexEntry);
    return archives.stream().map(archive -> new CacheArchive(archive.getArchiveId(), archive.getNameHash(), archive.getRevision())).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Cache(net.runelite.http.api.cache.Cache) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ImageIO(javax.imageio.ImageIO) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) ItemLoader(net.runelite.cache.definitions.loaders.ItemLoader) FSFile(net.runelite.cache.fs.FSFile) IndexType(net.runelite.cache.IndexType) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) NpcLoader(net.runelite.cache.definitions.loaders.NpcLoader) BufferedImage(java.awt.image.BufferedImage) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) Container(net.runelite.cache.fs.Container) IOException(java.io.IOException) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) CacheIndex(net.runelite.http.api.cache.CacheIndex) CacheArchive(net.runelite.http.api.cache.CacheArchive) ConfigType(net.runelite.cache.ConfigType) ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) ItemSpriteFactory(net.runelite.cache.item.ItemSpriteFactory) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ResponseEntity(org.springframework.http.ResponseEntity) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) CacheArchive(net.runelite.http.api.cache.CacheArchive) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ArchiveEntry

use of net.runelite.http.service.cache.beans.ArchiveEntry 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 4 with ArchiveEntry

use of net.runelite.http.service.cache.beans.ArchiveEntry in project runelite by runelite.

the class CacheController method findConfig.

private ArchiveEntry findConfig(ConfigType config) {
    CacheEntry cache = cacheService.findMostRecent();
    if (cache == null) {
        throw new NotFoundException();
    }
    IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.CONFIGS.getNumber());
    if (indexEntry == null) {
        throw new NotFoundException();
    }
    ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, config.getId());
    if (archiveEntry == null) {
        throw new NotFoundException();
    }
    return archiveEntry;
}
Also used : NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry)

Example 5 with ArchiveEntry

use of net.runelite.http.service.cache.beans.ArchiveEntry in project runelite by runelite.

the class CacheController method getObject.

@RequestMapping("object/{objectId}")
public ObjectDefinition getObject(@PathVariable int objectId) throws IOException {
    ArchiveEntry archiveEntry = findConfig(ConfigType.OBJECT);
    ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
    if (archiveFiles == null) {
        throw new NotFoundException();
    }
    FSFile file = archiveFiles.findFile(objectId);
    if (file == null) {
        throw new NotFoundException();
    }
    ObjectDefinition objectdef = new ObjectLoader().load(objectId, file.getContents());
    return objectdef;
}
Also used : ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) FSFile(net.runelite.cache.fs.FSFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArchiveEntry (net.runelite.http.service.cache.beans.ArchiveEntry)11 NotFoundException (net.runelite.http.service.util.exception.NotFoundException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)6 FSFile (net.runelite.cache.fs.FSFile)6 CacheEntry (net.runelite.http.service.cache.beans.CacheEntry)6 IndexEntry (net.runelite.http.service.cache.beans.IndexEntry)6 IOException (java.io.IOException)3 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)3 SpriteLoader (net.runelite.cache.definitions.loaders.SpriteLoader)3 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)2 NpcDefinition (net.runelite.cache.definitions.NpcDefinition)2 ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)2 TextureDefinition (net.runelite.cache.definitions.TextureDefinition)2 ItemLoader (net.runelite.cache.definitions.loaders.ItemLoader)2 ModelLoader (net.runelite.cache.definitions.loaders.ModelLoader)2 NpcLoader (net.runelite.cache.definitions.loaders.NpcLoader)2 ObjectLoader (net.runelite.cache.definitions.loaders.ObjectLoader)2