use of net.runelite.cache.fs.Storage 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.Storage 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.Storage 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;
}
}
}
use of net.runelite.cache.fs.Storage in project runelite by runelite.
the class NpcManager method load.
public void load() throws IOException {
NpcLoader loader = new NpcLoader();
Storage storage = store.getStorage();
Index index = store.getIndex(IndexType.CONFIGS);
Archive archive = index.getArchive(ConfigType.NPC.getId());
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
for (FSFile f : files.getFiles()) {
NpcDefinition npc = loader.load(f.getFileId(), f.getContents());
npcs.add(npc);
}
}
use of net.runelite.cache.fs.Storage in project runelite by runelite.
the class ArchiveRequestHandler method handleRequest.
private void handleRequest(ChannelHandlerContext ctx, int index, int archiveId) throws IOException {
logger.info("Client {} requests index {} archive {}", ctx.channel().remoteAddress(), index, archiveId);
Index i = store.findIndex(index);
assert i != null;
Archive archive = i.getArchive(archiveId);
assert archive != null;
Storage storage = store.getStorage();
// is compressed, includes length and type
byte[] packed = storage.loadArchive(archive);
if (packed == null) {
logger.warn("Missing archive {}/{}", index, archiveId);
// is it possible to notify the client of an error with this?
return;
}
byte compression = packed[0];
int compressedSize = Ints.fromBytes(packed[1], packed[2], packed[3], packed[4]);
// size the client expects the data to be
int expectedSize = // compression type
1 + // compressed size
4 + compressedSize + (compression != CompressionType.NONE ? 4 : 0);
if (packed.length != expectedSize) {
// the update server will never have it
assert packed.length - expectedSize == 2 : "packed length != expected size";
packed = Arrays.copyOf(packed, packed.length - 2);
}
ArchiveResponsePacket response = new ArchiveResponsePacket();
response.setIndex(index);
response.setArchive(archiveId);
response.setData(packed);
ctx.writeAndFlush(response);
}
Aggregations