use of net.runelite.http.service.cache.beans.CacheEntry 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());
}
use of net.runelite.http.service.cache.beans.CacheEntry 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());
}
use of net.runelite.http.service.cache.beans.CacheEntry 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];
}
use of net.runelite.http.service.cache.beans.CacheEntry in project runelite by runelite.
the class XteaService method submit.
@RequestMapping(method = POST)
public void submit(@RequestBody XteaRequest xteaRequest) {
try (Connection con = sql2o.beginTransaction()) {
CacheEntry cache = cacheService.findMostRecent();
if (cache == null) {
throw new InternalServerErrorException("No most recent cache");
}
Query query = con.createQuery("insert into xtea (region, rev, key1, key2, key3, key4) " + "values (:region, :rev, :key1, :key2, :key3, :key4)");
for (XteaKey key : xteaRequest.getKeys()) {
int region = key.getRegion();
int[] keys = key.getKeys();
XteaEntry xteaEntry = findLatestXtea(con, region);
if (keys.length != 4) {
throw new IllegalArgumentException("Key length must be 4");
}
// already have these?
if (xteaEntry != null && xteaEntry.getKey1() == keys[0] && xteaEntry.getKey2() == keys[1] && xteaEntry.getKey3() == keys[2] && xteaEntry.getKey4() == keys[3]) {
continue;
}
if (!checkKeys(cache, region, keys)) {
continue;
}
query.addParameter("region", region).addParameter("rev", xteaRequest.getRevision()).addParameter("key1", keys[0]).addParameter("key2", keys[1]).addParameter("key3", keys[2]).addParameter("key4", keys[3]).addToBatch();
}
query.executeBatch();
con.commit();
}
}
use of net.runelite.http.service.cache.beans.CacheEntry 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;
}
Aggregations