use of net.runelite.cache.fs.Index in project ostracker by OSTracker.
the class RemoteCache method download.
public void download(Store store) throws IOException, ExecutionException, InterruptedException {
FileResult indicesFile = downloadFile(255, 255);
ByteBuf buffer = Unpooled.wrappedBuffer(indicesFile.getContents());
int indexCount = indicesFile.getContents().length / 8;
for (int i = 0; i < indexCount; i++) {
int crc = buffer.readInt();
int revision = buffer.readInt();
Index index = store.findIndex(i);
if (index == null) {
LOGGER.info("Index " + i + " does not exist locally, downloading..");
} else if (index.getRevision() != revision) {
LOGGER.info(MessageFormat.format("Index {0} has the wrong revision (local: {1}, remote: {2})", i, index.getRevision(), revision));
} else {
LOGGER.info("Index " + i + " is up to date");
continue;
}
LOGGER.info("Downloading index " + i);
FileResult indexFile = downloadFile(255, i);
LOGGER.info("Done downloading index " + i);
if (indexFile.getCrc() != crc) {
LOGGER.error("Crc mismatch between downloaded file and expected checksum for index " + i);
continue;
}
Index oldIndex = null;
if (index != null) {
store.removeIndex(index);
oldIndex = index;
}
index = store.addIndex(i);
index.readIndexData(indexFile.getContents());
index.setCrc(crc);
LOGGER.info("Index " + i + " has " + index.getArchives().size() + " archives");
for (Archive archive : index.getArchives()) {
Archive oldArchive = null;
if (oldIndex != null) {
oldArchive = oldIndex.getArchive(archive.getArchiveId());
}
if (oldArchive == null || oldArchive.getRevision() != archive.getRevision()) {
LOGGER.info(MessageFormat.format("Archive {0} in index {1} is out of date, downloading..", archive.getArchiveId(), i));
FileResult archiveFile = downloadFile(i, archive.getArchiveId(), false);
archive.setData(archiveFile.getCompressedData());
} else {
LOGGER.info(MessageFormat.format("Archive {0} in index {1} is up to date", archive.getArchiveId(), i));
if (oldArchive.getData() != null) {
archive.setData(oldArchive.getData());
} else {
archive.loadContents(oldArchive.saveContents());
archive.setCompression(oldArchive.getCompression());
}
}
}
}
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class ItemSpriteFactoryTest method test.
@Test
@Ignore
public void test() throws IOException {
File base = StoreLocation.LOCATION, outDir = folder.newFolder();
int count = 0;
try (Store store = new Store(base)) {
store.load();
ItemManager itemManager = new ItemManager(store);
itemManager.load();
ModelProvider modelProvider = new ModelProvider() {
@Override
public ModelDefinition provide(int modelId) throws IOException {
Index models = store.getIndex(IndexType.MODELS);
Archive archive = models.getArchive(modelId);
byte[] data = archive.decompress(store.getStorage().loadArchive(archive));
ModelDefinition inventoryModel = new ModelLoader().load(modelId, data);
return inventoryModel;
}
};
SpriteManager spriteManager = new SpriteManager(store);
spriteManager.load();
TextureManager textureManager = new TextureManager(store);
textureManager.load();
for (ItemDefinition itemDef : itemManager.getItems()) {
if (itemDef.name == null || itemDef.name.equalsIgnoreCase("null")) {
continue;
}
try {
BufferedImage sprite = ItemSpriteFactory.createSprite(itemManager, modelProvider, spriteManager, textureManager, itemDef.id, 1, 1, 3153952, false);
File out = new File(outDir, itemDef.id + ".png");
BufferedImage img = sprite;
ImageIO.write(img, "PNG", out);
++count;
} catch (Exception ex) {
log.warn("error dumping item {}", itemDef.id, ex);
}
}
}
log.info("Dumped {} item images to {}", count, outDir);
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class DisassemblerTest method test.
@Test
public void test() throws IOException {
File outDir = folder.newFolder();
int count = 0;
try (Store store = new Store(StoreLocation.LOCATION)) {
store.load();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CLIENTSCRIPT);
ScriptLoader loader = new ScriptLoader();
for (Archive archive : index.getArchives()) {
byte[] contents = archive.decompress(storage.loadArchive(archive));
if (contents == null) {
continue;
}
ScriptDefinition script = loader.load(0, contents);
File outFile = new File(outDir, archive.getArchiveId() + ".rs2asm");
Disassembler disassembler = new Disassembler();
String out = disassembler.disassemble(script);
Files.write(out.getBytes(), outFile);
++count;
}
}
logger.info("Dumped {} scripts to {}", count, outDir);
}
use of net.runelite.cache.fs.Index in project runelite by runelite.
the class InventoryManager method load.
public void load() throws IOException {
InventoryLoader loader = new InventoryLoader();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CONFIGS);
Archive archive = index.getArchive(ConfigType.INV.getId());
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
for (FSFile file : files.getFiles()) {
InventoryDefinition inv = loader.load(file.getFileId(), file.getContents());
inventories.add(inv);
}
}
use of net.runelite.cache.fs.Index 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;
}
}
}
Aggregations